Coverage for biobb_model/model/fix_amides.py: 70%
44 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-13 17:26 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-13 17:26 +0000
1#!/usr/bin/env python3
3"""Module containing the FixAmides class and the command line interface."""
4import argparse
5from biobb_common.generic.biobb_object import BiobbObject
6from biobb_common.configuration import settings
7from biobb_common.tools.file_utils import launchlogger
10class FixAmides(BiobbObject):
11 """
12 | biobb_model FixAmides
13 | Fix amide groups from residues.
14 | Flip the clashing amide groups to avoid clashes.
16 Args:
17 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).
18 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).
19 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
20 * **modeller_key** (*str*) - (None) Modeller license key.
21 * **binary_path** (*str*) - ("check_structure") Path to the check_structure executable binary.
22 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
23 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
25 Examples:
26 This is a use example of how to use the building block from Python::
28 from biobb_model.model.fix_amides import fix_amides
29 prop = { 'restart': False }
30 fix_amides(input_pdb_path='/path/to/myStructure.pdb',
31 output_pdb_path='/path/to/newStructure.pdb',
32 properties=prop)
34 Info:
35 * wrapped_software:
36 * name: In house
37 * license: Apache-2.0
38 * ontology:
39 * name: EDAM
40 * schema: http://edamontology.org/EDAM.owl
41 """
43 def __init__(self, input_pdb_path: str, output_pdb_path: str, properties: dict = None, **kwargs) -> None:
44 properties = properties or {}
46 # Call parent class constructor
47 super().__init__(properties)
48 self.locals_var_dict = locals().copy()
50 # Input/Output files
51 self.io_dict = {
52 "in": {"input_pdb_path": input_pdb_path},
53 "out": {"output_pdb_path": output_pdb_path}
54 }
56 # Properties specific for BB
57 self.binary_path = properties.get('binary_path', 'check_structure')
58 self.modeller_key = properties.get('modeller_key')
60 # Check the properties
61 self.check_properties(properties)
62 self.check_arguments()
64 @launchlogger
65 def launch(self) -> int:
66 """Execute the :class:`FixAmides <model.fix_amides.FixAmides>` object."""
68 # Setup Biobb
69 if self.check_restart():
70 return 0
71 self.stage_files()
73 self.cmd = [self.binary_path,
74 '-i', self.stage_io_dict["in"]["input_pdb_path"],
75 '-o', self.stage_io_dict["out"]["output_pdb_path"],
76 '--force_save',
77 'amide', '--fix', 'All']
79 if self.modeller_key:
80 self.cmd.insert(1, self.modeller_key)
81 self.cmd.insert(1, '--modeller_key')
83 # Run Biobb block
84 self.run_biobb()
86 # Copy files to host
87 self.copy_to_host()
89 # Remove temporal files
90 self.tmp_files.extend([self.stage_io_dict.get("unique_dir")])
91 self.remove_tmp_files()
93 self.check_arguments(output_files_created=True, raise_exception=False)
94 return self.return_code
97def fix_amides(input_pdb_path: str, output_pdb_path: str, properties: dict = None, **kwargs) -> int:
98 """Create :class:`FixAmides <model.fix_amides.FixAmides>` class and
99 execute the :meth:`launch() <model.fix_amides.FixAmides.launch>` method."""
100 return FixAmides(input_pdb_path=input_pdb_path,
101 output_pdb_path=output_pdb_path,
102 properties=properties, **kwargs).launch()
105def main():
106 parser = argparse.ArgumentParser(description="Flip the clashing amide groups to avoid clashes.",
107 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999))
108 parser.add_argument('-c', '--config', required=False, help="This file can be a YAML file, JSON file or JSON string")
110 # Specific args of each building block
111 required_args = parser.add_argument_group('required arguments')
112 required_args.add_argument('-i', '--input_pdb_path', required=True, help="Input PDB file name")
113 required_args.add_argument('-o', '--output_pdb_path', required=True, help="Output PDB file name")
115 args = parser.parse_args()
116 config = args.config if args.config else None
117 properties = settings.ConfReader(config=config).get_prop_dic()
119 # Specific call of each building block
120 fix_amides(input_pdb_path=args.input_pdb_path,
121 output_pdb_path=args.output_pdb_path,
122 properties=properties)
125if __name__ == '__main__':
126 main()