Coverage for biobb_model/model/fix_amides.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 FixAmides 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 FixAmides(BiobbObject):
14 """
15 | biobb_model FixAmides
16 | Fix amide groups from residues.
17 | Flip the clashing amide groups to avoid clashes.
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://raw.githubusercontent.com/bioexcel/biobb_model/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_amides import fix_amides
33 prop = { 'restart': False }
34 fix_amides(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:`FixAmides <model.fix_amides.FixAmides>` object."""
78 # Setup Biobb
79 if self.check_restart():
80 return 0
81 self.stage_files()
83 self.cmd = [
84 self.binary_path,
85 "-i",
86 self.stage_io_dict["in"]["input_pdb_path"],
87 "-o",
88 self.stage_io_dict["out"]["output_pdb_path"],
89 "--force_save",
90 "amide",
91 "--fix",
92 "All",
93 ]
95 if self.modeller_key:
96 self.cmd.insert(1, self.modeller_key)
97 self.cmd.insert(1, "--modeller_key")
99 # Run Biobb block
100 self.run_biobb()
102 # Copy files to host
103 self.copy_to_host()
105 # Remove temporal files
106 # self.tmp_files.extend([self.stage_io_dict.get("unique_dir", "")])
107 self.remove_tmp_files()
109 self.check_arguments(output_files_created=True, raise_exception=False)
110 return self.return_code
113def fix_amides(
114 input_pdb_path: str,
115 output_pdb_path: str,
116 properties: Optional[dict] = None,
117 **kwargs,
118) -> int:
119 """Create :class:`FixAmides <model.fix_amides.FixAmides>` class and
120 execute the :meth:`launch() <model.fix_amides.FixAmides.launch>` method."""
121 return FixAmides(
122 input_pdb_path=input_pdb_path,
123 output_pdb_path=output_pdb_path,
124 properties=properties,
125 **kwargs,
126 ).launch()
128 fix_amides.__doc__ = FixAmides.__doc__
131def main():
132 parser = argparse.ArgumentParser(
133 description="Flip the clashing amide groups to avoid clashes.",
134 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999),
135 )
136 parser.add_argument(
137 "-c",
138 "--config",
139 required=False,
140 help="This file can be a YAML file, JSON file or JSON string",
141 )
143 # Specific args of each building block
144 required_args = parser.add_argument_group("required arguments")
145 required_args.add_argument(
146 "-i", "--input_pdb_path", required=True, help="Input PDB file name"
147 )
148 required_args.add_argument(
149 "-o", "--output_pdb_path", required=True, help="Output PDB file name"
150 )
152 args = parser.parse_args()
153 config = args.config if args.config else None
154 properties = settings.ConfReader(config=config).get_prop_dic()
156 # Specific call of each building block
157 fix_amides(
158 input_pdb_path=args.input_pdb_path,
159 output_pdb_path=args.output_pdb_path,
160 properties=properties,
161 )
164if __name__ == "__main__":
165 main()