Coverage for biobb_model / model / fix_side_chain.py: 82%
40 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-22 13:18 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-22 13:18 +0000
1#!/usr/bin/env python3
3"""Module containing the FixSideChain class and the command line interface."""
5from typing import Optional
7from biobb_common.generic.biobb_object import BiobbObject
8from biobb_common.tools import file_utils as fu
9from biobb_common.tools.file_utils import launchlogger
11from biobb_model.model.common import modeller_installed
14class FixSideChain(BiobbObject):
15 """
16 | biobb_model FixSideChain
17 | Class to model the missing atoms in amino acid side chains of a PDB.
18 | 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.
20 Args:
21 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).
22 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).
23 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
24 * **use_modeller** (*bool*) - (False) Use `Modeller suite <https://salilab.org/modeller/>`_ to rebuild the missing side chain atoms.
25 * **modeller_key** (*str*) - (None) Modeller license key.
26 * **binary_path** (*str*) - ("check_structure") Path to the check_structure executable binary.
27 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
28 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
29 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
31 Examples:
32 This is a use example of how to use the building block from Python::
34 from biobb_model.model.fix_side_chain import fix_side_chain
35 prop = { 'use_modeller': True }
36 fix_side_chain(input_pdb_path='/path/to/myStructure.pdb',
37 output_pdb_path='/path/to/newStructure.pdb',
38 properties=prop)
40 Info:
41 * wrapped_software:
42 * name: In house
43 * license: Apache-2.0
44 * ontology:
45 * name: EDAM
46 * schema: http://edamontology.org/EDAM.owl
47 """
49 def __init__(
50 self,
51 input_pdb_path: str,
52 output_pdb_path: str,
53 properties: Optional[dict] = None,
54 **kwargs,
55 ) -> None:
56 properties = properties or {}
58 # Call parent class constructor
59 super().__init__(properties)
60 self.locals_var_dict = locals().copy()
62 # Input/Output files
63 self.io_dict = {
64 "in": {"input_pdb_path": input_pdb_path},
65 "out": {"output_pdb_path": output_pdb_path},
66 }
68 # Properties specific for BB
69 self.binary_path = properties.get("binary_path", "check_structure")
70 self.use_modeller = properties.get("use_modeller", False)
71 self.modeller_key = properties.get("modeller_key")
73 # Check the properties
74 self.check_properties(properties)
75 self.check_arguments()
77 @launchlogger
78 def launch(self) -> int:
79 """Execute the :class:`FixSideChain <model.fix_side_chain.FixSideChain>` object."""
81 # Setup Biobb
82 if self.check_restart():
83 return 0
84 self.stage_files()
86 # Create command line
87 self.cmd = [
88 self.binary_path,
89 "-i",
90 self.stage_io_dict["in"]["input_pdb_path"],
91 "-o",
92 self.stage_io_dict["out"]["output_pdb_path"],
93 "--force_save",
94 "fixside",
95 "--fix",
96 "ALL",
97 ]
99 if self.modeller_key:
100 self.cmd.insert(1, self.modeller_key)
101 self.cmd.insert(1, "--modeller_key")
103 if self.use_modeller:
104 if modeller_installed(self.out_log, self.global_log):
105 self.cmd.append("--rebuild")
106 else:
107 fu.log(
108 "Modeller is not installed --rebuild option can not be used proceeding without using it",
109 self.out_log,
110 self.global_log,
111 )
113 # Run Biobb block
114 self.run_biobb()
116 # Copy files to host
117 self.copy_to_host()
119 # Remove temporal files
120 self.remove_tmp_files()
122 self.check_arguments(output_files_created=True, raise_exception=False)
123 return self.return_code
126def fix_side_chain(
127 input_pdb_path: str,
128 output_pdb_path: str,
129 properties: Optional[dict] = None,
130 **kwargs,
131) -> int:
132 """Create :class:`FixSideChain <model.fix_side_chain.FixSideChain>` class and
133 execute the :meth:`launch() <model.fix_side_chain.FixSideChain.launch>` method."""
134 return FixSideChain(**dict(locals())).launch()
137fix_side_chain.__doc__ = FixSideChain.__doc__
138main = FixSideChain.get_main(fix_side_chain, "Model the missing atoms in amino acid side chains of a PDB.")
140if __name__ == "__main__":
141 main()