Coverage for biobb_model/model/fix_side_chain.py: 67%
51 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-28 11:32 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-28 11:32 +0000
1#!/usr/bin/env python3
3"""Module containing the FixSideChain class and the command line interface."""
5import argparse
6from typing import Optional
8from biobb_common.configuration import settings
9from biobb_common.generic.biobb_object import BiobbObject
10from biobb_common.tools import file_utils as fu
11from biobb_common.tools.file_utils import launchlogger
13from biobb_model.model.common import modeller_installed
16class FixSideChain(BiobbObject):
17 """
18 | biobb_model FixSideChain
19 | Class to model the missing atoms in amino acid side chains of a PDB.
20 | Model the missing atoms in amino acid side chains of a PDB using `biobb_structure_checking <https://anaconda.org/bioconda/biobb_structure_checking>`_ if the use_modeller property is added the `Modeller suite <https://salilab.org/modeller/>`_ will also be used to rebuild the missing atoms.
22 Args:
23 input_pdb_path (str): Input PDB file path. File type: input. `Sample file <https://github.com/bioexcel/biobb_model/raw/master/biobb_model/test/data/model/2ki5.pdb>`_. Accepted formats: pdb (edam:format_1476).
24 output_pdb_path (str): Output PDB file path. File type: output. `Sample file <https://github.com/bioexcel/biobb_model/raw/master/biobb_model/test/reference/model/output_pdb_path.pdb>`_. Accepted formats: pdb (edam:format_1476).
25 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
26 * **use_modeller** (*bool*) - (False) Use `Modeller suite <https://salilab.org/modeller/>`_ to rebuild the missing side chain atoms.
27 * **modeller_key** (*str*) - (None) Modeller license key.
28 * **binary_path** (*str*) - ("check_structure") Path to the check_structure executable binary.
29 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
30 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
31 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
33 Examples:
34 This is a use example of how to use the building block from Python::
36 from biobb_model.model.fix_side_chain import fix_side_chain
37 prop = { 'use_modeller': True }
38 fix_side_chain(input_pdb_path='/path/to/myStructure.pdb',
39 output_pdb_path='/path/to/newStructure.pdb',
40 properties=prop)
42 Info:
43 * wrapped_software:
44 * name: In house
45 * license: Apache-2.0
46 * ontology:
47 * name: EDAM
48 * schema: http://edamontology.org/EDAM.owl
49 """
51 def __init__(
52 self,
53 input_pdb_path: str,
54 output_pdb_path: str,
55 properties: Optional[dict] = None,
56 **kwargs,
57 ) -> None:
58 properties = properties or {}
60 # Call parent class constructor
61 super().__init__(properties)
62 self.locals_var_dict = locals().copy()
64 # Input/Output files
65 self.io_dict = {
66 "in": {"input_pdb_path": input_pdb_path},
67 "out": {"output_pdb_path": output_pdb_path},
68 }
70 # Properties specific for BB
71 self.binary_path = properties.get("binary_path", "check_structure")
72 self.use_modeller = properties.get("use_modeller", False)
73 self.modeller_key = properties.get("modeller_key")
75 # Check the properties
76 self.check_properties(properties)
77 self.check_arguments()
79 @launchlogger
80 def launch(self) -> int:
81 """Execute the :class:`FixSideChain <model.fix_side_chain.FixSideChain>` object."""
83 # Setup Biobb
84 if self.check_restart():
85 return 0
86 self.stage_files()
88 # Create command line
89 self.cmd = [
90 self.binary_path,
91 "-i",
92 self.stage_io_dict["in"]["input_pdb_path"],
93 "-o",
94 self.stage_io_dict["out"]["output_pdb_path"],
95 "--force_save",
96 "fixside",
97 "--fix",
98 "ALL",
99 ]
101 if self.modeller_key:
102 self.cmd.insert(1, self.modeller_key)
103 self.cmd.insert(1, "--modeller_key")
105 if self.use_modeller:
106 if modeller_installed(self.out_log, self.global_log):
107 self.cmd.append("--rebuild")
108 else:
109 fu.log(
110 "Modeller is not installed --rebuild option can not be used proceeding without using it",
111 self.out_log,
112 self.global_log,
113 )
115 # Run Biobb block
116 self.run_biobb()
118 # Copy files to host
119 self.copy_to_host()
121 # Remove temporal files
122 # self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")])
123 self.remove_tmp_files()
125 self.check_arguments(output_files_created=True, raise_exception=False)
126 return self.return_code
129def fix_side_chain(
130 input_pdb_path: str,
131 output_pdb_path: str,
132 properties: Optional[dict] = None,
133 **kwargs,
134) -> int:
135 """Create :class:`FixSideChain <model.fix_side_chain.FixSideChain>` class and
136 execute the :meth:`launch() <model.fix_side_chain.FixSideChain.launch>` method."""
137 return FixSideChain(
138 input_pdb_path=input_pdb_path,
139 output_pdb_path=output_pdb_path,
140 properties=properties,
141 **kwargs,
142 ).launch()
144 fix_side_chain.__doc__ = FixSideChain.__doc__
147def main():
148 parser = argparse.ArgumentParser(
149 description="Model the missing atoms in amino acid side chains of a PDB.",
150 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999),
151 )
152 parser.add_argument(
153 "-c",
154 "--config",
155 required=False,
156 help="This file can be a YAML file, JSON file or JSON string",
157 )
159 # Specific args of each building block
160 required_args = parser.add_argument_group("required arguments")
161 required_args.add_argument(
162 "-i", "--input_pdb_path", required=True, help="Input PDB file name"
163 )
164 required_args.add_argument(
165 "-o", "--output_pdb_path", required=True, help="Output PDB file name"
166 )
168 args = parser.parse_args()
169 config = args.config if args.config else None
170 properties = settings.ConfReader(config=config).get_prop_dic()
172 # Specific call of each building block
173 fix_side_chain(
174 input_pdb_path=args.input_pdb_path,
175 output_pdb_path=args.output_pdb_path,
176 properties=properties,
177 )
180if __name__ == "__main__":
181 main()