Coverage for biobb_model / model / fix_chirality.py: 88%
33 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 FixChirality class and the command line interface."""
5from typing import Optional
7from biobb_common.generic.biobb_object import BiobbObject
8from biobb_common.tools.file_utils import launchlogger
11class FixChirality(BiobbObject):
12 """
13 | biobb_model FixChirality
14 | Fix chirality errors of residues.
15 | Fix stereochemical errors in residue side-chains changing It's chirality.
17 Args:
18 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).
19 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).
20 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
21 * **modeller_key** (*str*) - (None) Modeller license key.
22 * **binary_path** (*str*) - ("check_structure") Path to the check_structure executable binary.
23 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
24 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
25 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
27 Examples:
28 This is a use example of how to use the building block from Python::
30 from biobb_model.model.fix_chirality import fix_chirality
31 prop = { 'restart': False }
32 fix_chirality(input_pdb_path='/path/to/myStructure.pdb',
33 output_pdb_path='/path/to/newStructure.pdb',
34 properties=prop)
36 Info:
37 * wrapped_software:
38 * name: In house
39 * license: Apache-2.0
40 * ontology:
41 * name: EDAM
42 * schema: http://edamontology.org/EDAM.owl
43 """
45 def __init__(
46 self,
47 input_pdb_path: str,
48 output_pdb_path: str,
49 properties: Optional[dict] = None,
50 **kwargs,
51 ) -> None:
52 properties = properties or {}
54 # Call parent class constructor
55 super().__init__(properties)
56 self.locals_var_dict = locals().copy()
58 # Input/Output files
59 self.io_dict = {
60 "in": {"input_pdb_path": input_pdb_path},
61 "out": {"output_pdb_path": output_pdb_path},
62 }
64 # Properties specific for BB
65 self.binary_path = properties.get("binary_path", "check_structure")
66 self.modeller_key = properties.get("modeller_key")
68 # Check the properties
69 self.check_properties(properties)
70 self.check_arguments()
72 @launchlogger
73 def launch(self) -> int:
74 """Execute the :class:`FixChirality <model.fix_amides.FixChirality>` object."""
76 # Setup Biobb
77 if self.check_restart():
78 return 0
79 self.stage_files()
81 # Create command line
82 self.cmd = [
83 self.binary_path,
84 "-i",
85 self.stage_io_dict["in"]["input_pdb_path"],
86 "-o",
87 self.stage_io_dict["out"]["output_pdb_path"],
88 "--force_save",
89 "chiral",
90 "--fix",
91 "All",
92 ]
94 if self.modeller_key:
95 self.cmd.insert(1, self.modeller_key)
96 self.cmd.insert(1, "--modeller_key")
98 # Run Biobb block
99 self.run_biobb()
101 # Copy files to host
102 self.copy_to_host()
104 # Remove temporal files
105 self.remove_tmp_files()
107 self.check_arguments(output_files_created=True, raise_exception=False)
108 return self.return_code
111def fix_chirality(
112 input_pdb_path: str,
113 output_pdb_path: str,
114 properties: Optional[dict] = None,
115 **kwargs,
116) -> int:
117 """Create :class:`FixChirality <model.fix_amides.FixChirality>` class and
118 execute the :meth:`launch() <model.fix_amides.FixChirality.launch>` method."""
119 return FixChirality(**dict(locals())).launch()
122fix_chirality.__doc__ = FixChirality.__doc__
123main = FixChirality.get_main(fix_chirality, "Fix stereochemical errors in residues changing It's chirality.")
125if __name__ == "__main__":
126 main()