Skip to content

Commit

Permalink
Read the Docs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gbayarri committed Sep 15, 2023
1 parent 5bd33b7 commit 5bc6338
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 60 deletions.
2 changes: 1 addition & 1 deletion biobb_cmip/cmip/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = "cmip"
__all__ = ["cmip_titration", "cmip_run", "cmip_prepare_structure", "cmip_prepare_pdb", "cmip_ignore_residues"]
__all__ = ["cmip_titration", "cmip_run", "cmip_prepare_structure", "cmip_prepare_pdb", "cmip_ignore_residues"]
2 changes: 1 addition & 1 deletion biobb_cmip/cmip/cmip_ignore_residues.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def launch(self) -> int:
return 0

if not self.ignore_all and not self.residue_list:
fu.log(f"Residue_list is empty and ignore_all is false nothing will be done.", self.out_log, self.global_log)
fu.log("Residue_list is empty and ignore_all is false nothing will be done.", self.out_log, self.global_log)
shutil.copyfile(self.io_dict["in"]["input_cmip_pdb_path"], self.io_dict["out"]["output_cmip_pdb_path"])
return self.return_code

Expand Down
Empty file modified biobb_cmip/cmip/cmip_prepare_structure.py
100644 → 100755
Empty file.
1 change: 0 additions & 1 deletion biobb_cmip/cmip/cmip_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def __init__(self, input_pdb_path: str, input_probe_pdb_path: str = None, output
@launchlogger
def launch(self) -> int:
"""Execute the :class:`Cmip <cmip.cmip.Cmip>` object."""
tmp_files = []

# Setup Biobb
if self.check_restart():
Expand Down
2 changes: 0 additions & 2 deletions biobb_cmip/cmip/cmip_titration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
"""Module containing the Titration class and the command line interface."""
import os
import argparse
import shutil
from pathlib import Path
from biobb_common.generic.biobb_object import BiobbObject
from biobb_common.configuration import settings
from biobb_common.tools import file_utils as fu
from biobb_common.tools.file_utils import launchlogger
from biobb_common.command_wrapper import cmd_wrapper
from biobb_cmip.cmip.common import create_params_file
from biobb_cmip.cmip.common import params_preset
from biobb_cmip.cmip.common import get_pdb_total_charge
Expand Down
52 changes: 29 additions & 23 deletions biobb_cmip/cmip/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _get_grid_from_text(cmip_log_path: Union[str, Path], external: bool = False)
int_match = re.match(r"Grid units:\s+([-+]?(?:\d*\.\d+|\d+))\s+([-+]?(?:\d*\.\d+|\d+))\s+([-+]?(?:\d*\.\d+|\d+))", line.strip())
if int_match:
grid_params['INT'] = float(int_match.group(1)), float(int_match.group(2)), float(int_match.group(3))
cen_match = re.match(r"Grid center:\s+([-+]?(?:\d*\.\d+|\d+))\s+([-+]?(?:\d*\.\d+|\d+))\s+([-+]?(?:\d*\.\d+|\d+))",line.strip())
cen_match = re.match(r"Grid center:\s+([-+]?(?:\d*\.\d+|\d+))\s+([-+]?(?:\d*\.\d+|\d+))\s+([-+]?(?:\d*\.\d+|\d+))", line.strip())
if cen_match:
grid_params['CEN'] = float(cen_match.group(1)), float(cen_match.group(2)), float(cen_match.group(3))
dim_match = re.match(r"Grid density:\s+([-+]?(?:\d*\.\d+|\d+))\s+([-+]?(?:\d*\.\d+|\d+))\s+([-+]?(?:\d*\.\d+|\d+))", line.strip())
Expand Down Expand Up @@ -86,7 +86,7 @@ def _get_grid_from_key_value(cmip_log_path: Union[str, Path], external: bool = F
int_match = re.match(r"spacing=\s+([-+]?(?:\d*\.\d+|\d+))\s*,\s*([-+]?(?:\d*\.\d+|\d+))\s*,\s*([-+]?(?:\d*\.\d+|\d+))", line.strip())
if int_match:
grid_params['INT'] = float(int_match.group(1)), float(int_match.group(2)), float(int_match.group(3))
cen_match = re.match(r"center=\s+([-+]?(?:\d*\.\d+|\d+))\s*,\s*([-+]?(?:\d*\.\d+|\d+))\s*,\s*([-+]?(?:\d*\.\d+|\d+))",line.strip())
cen_match = re.match(r"center=\s+([-+]?(?:\d*\.\d+|\d+))\s*,\s*([-+]?(?:\d*\.\d+|\d+))\s*,\s*([-+]?(?:\d*\.\d+|\d+))", line.strip())
if cen_match:
grid_params['CEN'] = float(cen_match.group(1)), float(cen_match.group(2)), float(cen_match.group(3))
dim_match = re.match(r"dim=\s+([-+]?(?:\d*\.\d+|\d+))\s*,\s*([-+]?(?:\d*\.\d+|\d+))\s*,\s*([-+]?(?:\d*\.\d+|\d+))", line.strip())
Expand All @@ -97,7 +97,6 @@ def _get_grid_from_key_value(cmip_log_path: Union[str, Path], external: bool = F
return origin, size, grid_params



def create_unique_file_path(parent_dir: Union[str, Path] = None, extension: str = None) -> str:
if not parent_dir:
parent_dir = Path.cwd
Expand Down Expand Up @@ -198,14 +197,14 @@ def __init__(self, fname):
continue
data = line.split()
r = Residue(data)
self.RData[r.id]=r
self.RData[r.id] = r
self.nres = len(self.RData)

def getParams(self, resid, atid):
if resid+':'+atid in self.RData:
return self.RData[resid+':'+atid]
else:
print("WARNING: atom not found in library (",resid+':'+atid,')')
print("WARNING: atom not found in library (", resid+':'+atid, ')')
return {}


Expand Down Expand Up @@ -248,7 +247,7 @@ def get_pdb_charges(input_pdb_filename: str, residue_library_path: str = None) -

def get_pdb_cmip_elements_canonical(input_pdb_filename: str, residue_library_path: str = None) -> List:
if not residue_library_path:
residue_library_path = str(Path(__file__).parent.joinpath("dat","aa.lib").resolve())
residue_library_path = str(Path(__file__).parent.joinpath("dat", "aa.lib").resolve())

aaLib = ResiduesDataLib(residue_library_path)
print("{} residue/atom pairs loaded from {}".format(aaLib.nres, residue_library_path))
Expand Down Expand Up @@ -316,7 +315,7 @@ def params_grid(grid_type: str, readgrid: int = 0, perfill: float = 0.8,
# cmip, titration, pbsolvation = 2, >3

grid_dict = {}
grid_dict[f"readgrid"] = f"{readgrid}"
grid_dict["readgrid"] = f"{readgrid}"

if grid_type in ['pb_interaction_energy', 'mip_pos', 'mip_neu', 'mip_neg', 'docking']:
grid_dict['grid_cen'] = f"CENX={grid_cen[0]},CENY={grid_cen[1]},CENZ={grid_cen[2]}"
Expand All @@ -335,7 +334,7 @@ def params_preset(execution_type: str) -> Dict[str, str]:
probe_grid_dict = {}
execution_type = execution_type.strip()
if execution_type == 'titration':
grid_dict = params_grid(grid_type=execution_type, readgrid=2, perfill=0.8, grid_int=(0.5, 0.5, 0.5) )
grid_dict = params_grid(grid_type=execution_type, readgrid=2, perfill=0.8, grid_int=(0.5, 0.5, 0.5))
params_dict = {
'title': 'Titration',
'tipcalc': 1,
Expand All @@ -356,11 +355,11 @@ def params_preset(execution_type: str) -> Dict[str, str]:
'irest': 0,
'orest': 0,
'coorfmt': 2,
'dields': 2,
'dields': 2,
'cubeoutput': 1,
'fvdw': 0.8,
'carmip': 1,
'tipatmip' : "'OW'"
'tipatmip': "'OW'"
}
elif execution_type == 'mip_neu':
grid_dict = params_grid(grid_type=execution_type, readgrid=2)
Expand All @@ -371,11 +370,11 @@ def params_preset(execution_type: str) -> Dict[str, str]:
'irest': 0,
'orest': 0,
'coorfmt': 2,
'dields': 2,
'dields': 2,
'cubeoutput': 1,
'fvdw': 0.8,
'carmip': 0,
'tipatmip' : "'OW'"
'tipatmip': "'OW'"
}
elif execution_type == 'mip_neg':
grid_dict = params_grid(grid_type=execution_type, readgrid=2)
Expand All @@ -386,13 +385,13 @@ def params_preset(execution_type: str) -> Dict[str, str]:
'irest': 0,
'orest': 0,
'coorfmt': 2,
'dields': 2,
'dields': 2,
'cubeoutput': 1,
'fvdw': 0.8,
'carmip': -1,
'tipatmip' : "'OW'"
'tipatmip': "'OW'"
}
#TODO 'carmip': 1,
# TODO 'carmip': 1,
# wat: tipcalc: 1 + titration: 'inifoc': 2, 'cutfoc': -0.5, 'focus': 1, 'ninter': 10,
elif execution_type == 'solvation':
grid_dict = params_grid(grid_type=execution_type, readgrid=2, perfill=0.2,
Expand All @@ -404,13 +403,13 @@ def params_preset(execution_type: str) -> Dict[str, str]:
'irest': 0,
'orest': 0,
'coorfmt': 2,
'cubeoutput': 1, 'vdw': 0, 'pbelec': 1,
'cubeoutput': 1, 'vdw': 0, 'pbelec': 1,
'novdwgrid': 1, 'solvenergy': 1, 'dielc': 1, 'dielsol': 80
}

elif execution_type == 'pb_interaction_energy':
grid_dict = params_grid(grid_type=execution_type, readgrid= 2)
probe_grid_dict = probe_params_grid(probe_id= 0, readgrid= 2, pbfocus= 1, perfill= 0.6,
grid_dict = params_grid(grid_type=execution_type, readgrid=2)
probe_grid_dict = probe_params_grid(probe_id=0, readgrid=2, pbfocus=1, perfill=0.6,
grid_int=(1.5, 1.5, 1.5))

# TODO Check for external box file or parameters
Expand All @@ -425,7 +424,7 @@ def params_preset(execution_type: str) -> Dict[str, str]:
}

elif execution_type == 'docking':
grid_dict = params_grid(grid_type=execution_type, readgrid= 2)
grid_dict = params_grid(grid_type=execution_type, readgrid=2)

params_dict = {
'title': 'Docking Mehler Solmajer dielectric',
Expand Down Expand Up @@ -474,7 +473,8 @@ def read_params_file(input_params_path: str) -> Dict[str, str]:
params_dict['title']: input_params_file.readline()
for line in input_params_file:
line = line.replace(' ', '')
if line.startswith('&'): continue
if line.startswith('&'):
continue
param_list = line.split(',')
for param in param_list:
param_key, param_value = param.split("=")
Expand Down Expand Up @@ -504,13 +504,13 @@ def read_params_file(input_params_path: str) -> Dict[str, str]:
def write_params_file(output_params_path: str, params_dict: Mapping[str, str]) -> str:
with open(output_params_path, 'w') as output_params_file:
output_params_file.write(f"{params_dict.pop('title', 'Untitled')}\n")
output_params_file.write(f"&cntrl\n")
output_params_file.write("&cntrl\n")
for params_key, params_value in params_dict.items():
if params_key in ['grid_int', 'grid_cen', 'grid_dim', 'grid_int0', 'grid_cen0', 'grid_dim0']:
output_params_file.write(f" {params_value}\n")
else:
output_params_file.write(f" {params_key} = {params_value}\n")
output_params_file.write(f"&end\n")
output_params_file.write("&end\n")
return output_params_path


Expand Down Expand Up @@ -539,6 +539,7 @@ def create_params_file(output_params_path: str, input_params_path: str = None,

return write_params_file(output_params_path, params_dict)


def mark_residues(residue_list: Sequence[str], input_cmip_pdb_path: str, output_cmip_pdb_path: str, out_log: logging.Logger = None, global_log: logging.Logger = None) -> None:
"""Marks using an "X" before the atom type all the residues in *residue_list* and writes the result in *output_cmip_pdb_path*.
Expand All @@ -548,7 +549,7 @@ def mark_residues(residue_list: Sequence[str], input_cmip_pdb_path: str, output_
global_log (:obj:`logging.Logger`): global log object.
"""
if not residue_list:
fu.log(f"Empty residue_list all residues will be marked", out_log, global_log)
fu.log("Empty residue_list all residues will be marked", out_log, global_log)
else:
fu.log(f"Residue list: {residue_list}", out_log, global_log)

Expand All @@ -572,11 +573,13 @@ def mark_residues(residue_list: Sequence[str], input_cmip_pdb_path: str, output_
if unused_residues:
fu.log(f"The following residues where present in the residue_list and have not been marked: {unused_residues}", out_log, global_log)


def _mark_pdb_atom(line: str) -> str:
line = list(line)
line.insert(64, 'X')
return ''.join(line)


def _get_residue_code_in_list(input_residue, residue_list):
if not residue_list:
return None
Expand All @@ -597,11 +600,14 @@ def _get_residue_code_in_list(input_residue, residue_list):
def _get_residue_code(line: str) -> str:
return _get_chain(line)+":"+_get_resnum(line)


def _get_chain(line: str) -> str:
return line[21].upper()


def _get_resnum(line: str) -> str:
return line[22:27].strip()


def _is_atom(line: str) -> str:
return line[0:6].strip().upper() in ["ATOM", "HETATM"]
84 changes: 79 additions & 5 deletions biobb_cmip/docs/source/command_line.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@ Command:
```python
cmip_prepare_pdb -h
```
/bin/sh: cmip_prepare_pdb: command not found
usage: cmip_prepare_pdb [-h] [-c CONFIG] -i INPUT_PDB_PATH -o OUTPUT_CMIP_PDB_PATH

Model the missing atoms in the backbone of a PDB structure.

optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
This file can be a YAML file, JSON file or JSON string

required arguments:
-i INPUT_PDB_PATH, --input_pdb_path INPUT_PDB_PATH
Input PDB file name
-o OUTPUT_CMIP_PDB_PATH, --output_cmip_pdb_path OUTPUT_CMIP_PDB_PATH
Output PDB file name
### I / O Arguments
Syntax: input_argument (datatype) : Definition

Expand Down Expand Up @@ -63,7 +76,20 @@ Command:
```python
cmip_ignore_residues -h
```
/bin/sh: cmip_ignore_residues: command not found
usage: cmip_ignore_residues [-h] [-c CONFIG] -i INPUT_CMIP_PDB_PATH -o OUTPUT_CMIP_PDB_PATH

Mark residues which charges will be ignored in the CMIP potential calculations.

optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
This file can be a YAML file, JSON file or JSON string

required arguments:
-i INPUT_CMIP_PDB_PATH, --input_cmip_pdb_path INPUT_CMIP_PDB_PATH
Input PDB file name
-o OUTPUT_CMIP_PDB_PATH, --output_cmip_pdb_path OUTPUT_CMIP_PDB_PATH
Output PDB file name
### I / O Arguments
Syntax: input_argument (datatype) : Definition

Expand Down Expand Up @@ -112,7 +138,20 @@ Command:
```python
cmip_titration -h
```
/bin/sh: cmip_titration: command not found
usage: cmip_titration [-h] [-c CONFIG] --input_pdb_path INPUT_PDB_PATH --output_pdb_path OUTPUT_PDB_PATH [--input_vdw_params_path INPUT_VDW_PARAMS_PATH] [--input_params_path INPUT_PARAMS_PATH]

Wrapper of the CMIP Titration module.

optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
This file can be a YAML file, JSON file or JSON string
--input_vdw_params_path INPUT_VDW_PARAMS_PATH
--input_params_path INPUT_PARAMS_PATH

required arguments:
--input_pdb_path INPUT_PDB_PATH
--output_pdb_path OUTPUT_PDB_PATH
### I / O Arguments
Syntax: input_argument (datatype) : Definition

Expand Down Expand Up @@ -214,7 +253,30 @@ Command:
```python
cmip_run -h
```
/bin/sh: cmip_run: command not found
usage: cmip_run [-h] [-c CONFIG] --input_pdb_path INPUT_PDB_PATH [--input_probe_pdb_path INPUT_PROBE_PDB_PATH] [--output_pdb_path OUTPUT_PDB_PATH] [--output_grd_path OUTPUT_GRD_PATH] [--output_cube_path OUTPUT_CUBE_PATH] [--output_rst_path OUTPUT_RST_PATH] [--output_byat_path OUTPUT_BYAT_PATH] [--output_log_path OUTPUT_LOG_PATH] [--input_vdw_params_path INPUT_VDW_PARAMS_PATH] [--input_params_path INPUT_PARAMS_PATH] [--output_json_box_path OUTPUT_JSON_BOX_PATH] [--output_json_external_box_path OUTPUT_JSON_EXTERNAL_BOX_PATH] [--input_json_box_path INPUT_JSON_BOX_PATH] [--input_json_external_box_path INPUT_JSON_EXTERNAL_BOX_PATH]

Wrapper of the CMIP cmip module.

optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
This file can be a YAML file, JSON file or JSON string
--input_probe_pdb_path INPUT_PROBE_PDB_PATH
--output_pdb_path OUTPUT_PDB_PATH
--output_grd_path OUTPUT_GRD_PATH
--output_cube_path OUTPUT_CUBE_PATH
--output_rst_path OUTPUT_RST_PATH
--output_byat_path OUTPUT_BYAT_PATH
--output_log_path OUTPUT_LOG_PATH
--input_vdw_params_path INPUT_VDW_PARAMS_PATH
--input_params_path INPUT_PARAMS_PATH
--output_json_box_path OUTPUT_JSON_BOX_PATH
--output_json_external_box_path OUTPUT_JSON_EXTERNAL_BOX_PATH
--input_json_box_path INPUT_JSON_BOX_PATH
--input_json_external_box_path INPUT_JSON_EXTERNAL_BOX_PATH

required arguments:
--input_pdb_path INPUT_PDB_PATH
### I / O Arguments
Syntax: input_argument (datatype) : Definition

Expand Down Expand Up @@ -325,7 +387,19 @@ Command:
```python
cmip_prepare_structure -h
```
/bin/sh: cmip_prepare_structure: command not found
usage: cmip_prepare_structure [-h] [-c CONFIG] --input_pdb_path INPUT_PDB_PATH --output_cmip_pdb_path OUTPUT_CMIP_PDB_PATH [--input_topology_path INPUT_TOPOLOGY_PATH]

Wrapper of the cmip prepare_structure module.

optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
This file can be a YAML file, JSON file or JSON string
--input_topology_path INPUT_TOPOLOGY_PATH

required arguments:
--input_pdb_path INPUT_PDB_PATH
--output_cmip_pdb_path OUTPUT_CMIP_PDB_PATH
### I / O Arguments
Syntax: input_argument (datatype) : Definition

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ def test_cmip_ignore_residues(self):
cmip_ignore_residues(properties=self.properties, **self.paths)
assert fx.not_empty(self.paths['output_cmip_pdb_path'])
assert fx.equal(self.paths['output_cmip_pdb_path'], self.paths['ref_output_ignore_residues_pdb_path'])


2 changes: 0 additions & 2 deletions biobb_cmip/test/unitests/test_cmip/test_cmip_prepare_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ def test_cmip_prepare_pdb(self):
cmip_prepare_pdb(properties=self.properties, **self.paths)
assert fx.not_empty(self.paths['output_cmip_pdb_path'])
assert fx.equal(self.paths['output_cmip_pdb_path'], self.paths['ref_output_prepare_structure_pdb_path'])


2 changes: 1 addition & 1 deletion biobb_cmip/test/unitests/test_cmip/test_cmip_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def test_cmip_run_energy(self):
# assert fx.not_empty(self.paths['output_cube_path'])
# assert fx.not_empty(self.paths['output_grd_path'])
# assert fx.equal(self.paths['output_grd_path'], self.paths['ref_output_cmip_mip_grd_path'])
# assert fx.equal(self.paths['output_cube_path'], self.paths['ref_output_cmip_mip_cube_path'])
# assert fx.equal(self.paths['output_cube_path'], self.paths['ref_output_cmip_mip_cube_path'])
2 changes: 1 addition & 1 deletion biobb_cmip/test/unitests/test_cmip/test_cmip_run_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ def test_cmip_run_energy(self):
# assert fx.not_empty(self.paths['output_cube_path'])
# assert fx.not_empty(self.paths['output_grd_path'])
# assert fx.equal(self.paths['output_grd_path'], self.paths['ref_output_cmip_mip_grd_path'])
# assert fx.equal(self.paths['output_cube_path'], self.paths['ref_output_cmip_mip_cube_path'])
# assert fx.equal(self.paths['output_cube_path'], self.paths['ref_output_cmip_mip_cube_path'])
Loading

0 comments on commit 5bc6338

Please sign in to comment.