Coverage for biobb_model/model/fix_chirality.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 FixChirality 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 FixChirality(BiobbObject):
11 """
12 | biobb_model FixChirality
13 | Fix chirality errors of residues.
14 | Fix stereochemical errors in residue side-chains changing It's chirality.
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://github.com/bioexcel/biobb_model/raw/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_chirality import fix_chirality
29 prop = { 'restart': False }
30 fix_chirality(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:`FixChirality <model.fix_amides.FixChirality>` object."""
68 # Setup Biobb
69 if self.check_restart():
70 return 0
71 self.stage_files()
73 # Create command line
74 self.cmd = [self.binary_path,
75 '-i', self.stage_io_dict["in"]["input_pdb_path"],
76 '-o', self.stage_io_dict["out"]["output_pdb_path"],
77 '--force_save', 'chiral',
78 '--fix', 'All']
80 if self.modeller_key:
81 self.cmd.insert(1, self.modeller_key)
82 self.cmd.insert(1, '--modeller_key')
84 # Run Biobb block
85 self.run_biobb()
87 # Copy files to host
88 self.copy_to_host()
90 # Remove temporal files
91 self.tmp_files.extend([self.stage_io_dict.get("unique_dir")])
92 self.remove_tmp_files()
94 self.check_arguments(output_files_created=True, raise_exception=False)
95 return self.return_code
98def fix_chirality(input_pdb_path: str, output_pdb_path: str, properties: dict = None, **kwargs) -> int:
99 """Create :class:`FixChirality <model.fix_amides.FixChirality>` class and
100 execute the :meth:`launch() <model.fix_amides.FixChirality.launch>` method."""
101 return FixChirality(input_pdb_path=input_pdb_path,
102 output_pdb_path=output_pdb_path,
103 properties=properties, **kwargs).launch()
106def main():
107 parser = argparse.ArgumentParser(description="Fix stereochemical errors in residues changing It's chirality.",
108 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999))
109 parser.add_argument('-c', '--config', required=False, help="This file can be a YAML file, JSON file or JSON string")
111 # Specific args of each building block
112 required_args = parser.add_argument_group('required arguments')
113 required_args.add_argument('-i', '--input_pdb_path', required=True, help="Input PDB file name")
114 required_args.add_argument('-o', '--output_pdb_path', required=True, help="Output PDB file name")
116 args = parser.parse_args()
117 config = args.config if args.config else None
118 properties = settings.ConfReader(config=config).get_prop_dic()
120 # Specific call of each building block
121 fix_chirality(input_pdb_path=args.input_pdb_path,
122 output_pdb_path=args.output_pdb_path,
123 properties=properties)
126if __name__ == '__main__':
127 main()