Coverage for biobb_model/model/fix_chirality.py: 68%
44 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 FixChirality 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.file_utils import launchlogger
13class FixChirality(BiobbObject):
14 """
15 | biobb_model FixChirality
16 | Fix chirality errors of residues.
17 | Fix stereochemical errors in residue side-chains changing It's chirality.
19 Args:
20 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/5s2z.pdb>`_. Accepted formats: pdb (edam:format_1476).
21 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_amide_pdb_path.pdb>`_. Accepted formats: pdb (edam:format_1476).
22 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
23 * **modeller_key** (*str*) - (None) Modeller license key.
24 * **binary_path** (*str*) - ("check_structure") Path to the check_structure executable binary.
25 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
26 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
27 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
29 Examples:
30 This is a use example of how to use the building block from Python::
32 from biobb_model.model.fix_chirality import fix_chirality
33 prop = { 'restart': False }
34 fix_chirality(input_pdb_path='/path/to/myStructure.pdb',
35 output_pdb_path='/path/to/newStructure.pdb',
36 properties=prop)
38 Info:
39 * wrapped_software:
40 * name: In house
41 * license: Apache-2.0
42 * ontology:
43 * name: EDAM
44 * schema: http://edamontology.org/EDAM.owl
45 """
47 def __init__(
48 self,
49 input_pdb_path: str,
50 output_pdb_path: str,
51 properties: Optional[dict] = None,
52 **kwargs,
53 ) -> None:
54 properties = properties or {}
56 # Call parent class constructor
57 super().__init__(properties)
58 self.locals_var_dict = locals().copy()
60 # Input/Output files
61 self.io_dict = {
62 "in": {"input_pdb_path": input_pdb_path},
63 "out": {"output_pdb_path": output_pdb_path},
64 }
66 # Properties specific for BB
67 self.binary_path = properties.get("binary_path", "check_structure")
68 self.modeller_key = properties.get("modeller_key")
70 # Check the properties
71 self.check_properties(properties)
72 self.check_arguments()
74 @launchlogger
75 def launch(self) -> int:
76 """Execute the :class:`FixChirality <model.fix_amides.FixChirality>` object."""
78 # Setup Biobb
79 if self.check_restart():
80 return 0
81 self.stage_files()
83 # Create command line
84 self.cmd = [
85 self.binary_path,
86 "-i",
87 self.stage_io_dict["in"]["input_pdb_path"],
88 "-o",
89 self.stage_io_dict["out"]["output_pdb_path"],
90 "--force_save",
91 "chiral",
92 "--fix",
93 "All",
94 ]
96 if self.modeller_key:
97 self.cmd.insert(1, self.modeller_key)
98 self.cmd.insert(1, "--modeller_key")
100 # Run Biobb block
101 self.run_biobb()
103 # Copy files to host
104 self.copy_to_host()
106 # Remove temporal files
107 # self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")])
108 self.remove_tmp_files()
110 self.check_arguments(output_files_created=True, raise_exception=False)
111 return self.return_code
114def fix_chirality(
115 input_pdb_path: str,
116 output_pdb_path: str,
117 properties: Optional[dict] = None,
118 **kwargs,
119) -> int:
120 """Create :class:`FixChirality <model.fix_amides.FixChirality>` class and
121 execute the :meth:`launch() <model.fix_amides.FixChirality.launch>` method."""
122 return FixChirality(
123 input_pdb_path=input_pdb_path,
124 output_pdb_path=output_pdb_path,
125 properties=properties,
126 **kwargs,
127 ).launch()
129 fix_chirality.__doc__ = FixChirality.__doc__
132def main():
133 parser = argparse.ArgumentParser(
134 description="Fix stereochemical errors in residues changing It's chirality.",
135 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999),
136 )
137 parser.add_argument(
138 "-c",
139 "--config",
140 required=False,
141 help="This file can be a YAML file, JSON file or JSON string",
142 )
144 # Specific args of each building block
145 required_args = parser.add_argument_group("required arguments")
146 required_args.add_argument(
147 "-i", "--input_pdb_path", required=True, help="Input PDB file name"
148 )
149 required_args.add_argument(
150 "-o", "--output_pdb_path", required=True, help="Output PDB file name"
151 )
153 args = parser.parse_args()
154 config = args.config if args.config else None
155 properties = settings.ConfReader(config=config).get_prop_dic()
157 # Specific call of each building block
158 fix_chirality(
159 input_pdb_path=args.input_pdb_path,
160 output_pdb_path=args.output_pdb_path,
161 properties=properties,
162 )
165if __name__ == "__main__":
166 main()