Coverage for biobb_model / model / fix_altlocs.py: 87%
38 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 FixAltLocs 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
10from biobb_model.model.common import _from_string_to_list
13class FixAltLocs(BiobbObject):
14 """
15 | biobb_model FixAltLocs
16 | Fix alternate locations from residues.
17 | Fix alternate locations using the altlocs list or occupancy.
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/3ebp.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_altloc.pdb>`_. Accepted formats: pdb (edam:format_1476).
22 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
23 * **altlocs** (*list*) - (None) List of alternate locations to fix. Format: ["A339:A", "A171:B", "A768:A"]; where for each residue the format is as follows: "<chain><residue id>:<chosen alternate location>". If empty, no action will be executed.
24 * **modeller_key** (*str*) - (None) Modeller license key.
25 * **binary_path** (*str*) - ("check_structure") Path to the check_structure executable binary.
26 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
27 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
28 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
30 Examples:
31 This is a use example of how to use the building block from Python::
33 from biobb_model.model.fix_altlocs import fix_altlocs
34 prop = { 'altlocs': ['A339:A', 'A171:B', 'A768:A'] }
35 fix_altlocs(input_pdb_path='/path/to/myStructure.pdb',
36 output_pdb_path='/path/to/newStructure.pdb',
37 properties=prop)
39 Info:
40 * wrapped_software:
41 * name: In house
42 * license: Apache-2.0
43 * ontology:
44 * name: EDAM
45 * schema: http://edamontology.org/EDAM.owl
46 """
48 def __init__(
49 self,
50 input_pdb_path: str,
51 output_pdb_path: str,
52 properties: Optional[dict] = None,
53 **kwargs,
54 ) -> None:
55 properties = properties or {}
57 # Call parent class constructor
58 super().__init__(properties)
59 self.locals_var_dict = locals().copy()
61 # Input/Output files
62 self.io_dict = {
63 "in": {"input_pdb_path": input_pdb_path},
64 "out": {"output_pdb_path": output_pdb_path},
65 }
67 # Properties specific for BB
68 self.binary_path = properties.get("binary_path", "check_structure")
69 self.altlocs = _from_string_to_list(properties.get("altlocs", None))
70 self.modeller_key = properties.get("modeller_key")
72 # Check the properties
73 self.check_properties(properties)
74 self.check_arguments()
76 @launchlogger
77 def launch(self) -> int:
78 """Execute the :class:`FixAltLocs <model.fix_altlocs.FixAltLocs>` object."""
80 # Setup Biobb
81 if self.check_restart():
82 return 0
83 self.stage_files()
85 self.cmd = [
86 self.binary_path,
87 "-i",
88 self.stage_io_dict["in"]["input_pdb_path"],
89 "-o",
90 self.stage_io_dict["out"]["output_pdb_path"],
91 "--force_save",
92 "--non_interactive",
93 "altloc",
94 "--select",
95 ]
97 if self.altlocs:
98 self.cmd.append(",".join(self.altlocs))
99 else:
100 self.cmd.append("occupancy")
102 if self.modeller_key:
103 self.cmd.insert(1, self.modeller_key)
104 self.cmd.insert(1, "--modeller_key")
106 # Run Biobb block
107 self.run_biobb()
109 # Copy files to host
110 self.copy_to_host()
112 # Remove temporal files
113 self.remove_tmp_files()
115 self.check_arguments(output_files_created=True, raise_exception=False)
116 return self.return_code
119def fix_altlocs(
120 input_pdb_path: str,
121 output_pdb_path: str,
122 properties: Optional[dict] = None,
123 **kwargs,
124) -> int:
125 """Create :class:`FixAltLocs <model.fix_altlocs.FixAltLocs>` class and
126 execute the :meth:`launch() <model.fix_altlocs.FixAltLocs.launch>` method."""
127 return FixAltLocs(**dict(locals())).launch()
130fix_altlocs.__doc__ = FixAltLocs.__doc__
131main = FixAltLocs.get_main(fix_altlocs, "Fix alternate locations from residues")
133if __name__ == "__main__":
134 main()