Coverage for biobb_haddock/haddock/flex_ref.py: 86%
36 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-03 15:55 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-03 15:55 +0000
1#!/usr/bin/env python3
3"""Module containing the HADDOCK3 FlexRef class and the command line interface."""
5from os.path import abspath
6from typing import Optional
7import biobb_haddock.haddock.common as common
10class FlexRef(common.HaddockStepBase):
11 """
12 | biobb_haddock FlexRef
13 | Wrapper class for the HADDOCK3 FlexRef module.
14 | The FlexRef module.`HADDOCK3 FlexRef module <https://www.bonvinlab.org/haddock3/modules/refinement/haddock.modules.refinement.flexref.html>`_ computes a flexible refinement over selected structures.
16 Args:
17 input_haddock_wf_data (dir): Path to the input directory containing all the current Haddock workflow data. File type: input. `Sample file <https://github.com/bioexcel/biobb_haddock/raw/master/biobb_haddock/test/data/haddock/haddock_wf_data_topology.zip>`_. Accepted formats: directory (edam:format_1915).
18 output_haddock_wf_data (dir): Path to the output directory containing all the current Haddock workflow data. File type: output. `Sample file <https://github.com/bioexcel/biobb_haddock/raw/master/biobb_haddock/test/data/haddock/haddock_wf_data_emref.zip>`_. Accepted formats: directory (edam:format_1915).
19 refinement_output_zip_path (str) (Optional): Path to the output PDB file collection in zip format. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/reference/haddock/ref_rigidbody.zip>`_. Accepted formats: zip (edam:format_3987).
20 ambig_restraints_table_path (str) (Optional): Path to the input TBL file containing a list of ambiguous restraints for docking. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock/e2a-hpr_air.tbl>`_. Accepted formats: tbl (edam:format_2330).
21 unambig_restraints_table_path (str) (Optional): Path to the input TBL file containing a list of unambiguous restraints for docking. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock/e2a-hpr_air.tbl>`_. Accepted formats: tbl (edam:format_2330).
22 hb_restraints_table_path (str) (Optional): Path to the input TBL file containing a list of hydrogen bond restraints for docking. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock/e2a-hpr_air.tbl>`_. Accepted formats: tbl (edam:format_2330).
23 haddock_config_path (str) (Optional): Haddock configuration CFG file path. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock/run.cfg>`_. Accepted formats: cfg (edam:format_1476).
24 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
25 * **cfg** (*dict*) - ({}) Haddock configuration options specification.
26 * **global_cfg** (*dict*) - ({"postprocess": False}) `Global configuration options <https://www.bonvinlab.org/haddock3-user-manual/global_parameters.html>`_ specification.
27 * **binary_path** (*str*) - ("haddock") Path to the haddock haddock executable binary.
28 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
29 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
30 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
31 * **container_path** (*str*) - (None) Path to the binary executable of your container.
32 * **container_image** (*str*) - (None) Container Image identifier.
33 * **container_volume_path** (*str*) - ("/data") Path to an internal directory in the container.
34 * **container_working_dir** (*str*) - (None) Path to the internal CWD in the container.
35 * **container_user_id** (*str*) - (None) User number id to be mapped inside the container.
36 * **container_shell_path** (*str*) - ("/bin/bash") Path to the binary executable of the container shell.
39 Examples:
40 This is a use example of how to use the building block from Python::
42 from biobb_haddock.haddock.flex_ref import flex_ref
43 prop = { 'binary_path': 'haddock' }
44 flex_ref(input_haddock_wf_data='/path/to/myInputData',
45 output_haddock_wf_data='/path/to/myOutputData',
46 properties=prop)
48 Info:
49 * wrapped_software:
50 * name: HADDOCK3
51 * version: 2025.5
52 * license: Apache-2.0
53 * ontology:
54 * name: EDAM
55 * schema: http://edamontology.org/EDAM.owl
56 """
58 def __init__(
59 self,
60 input_haddock_wf_data: str,
61 output_haddock_wf_data: str,
62 refinement_output_zip_path: Optional[str] = None,
63 ambig_restraints_table_path: Optional[str] = None,
64 unambig_restraints_table_path: Optional[str] = None,
65 hb_restraints_table_path: Optional[str] = None,
66 haddock_config_path: Optional[str] = None,
67 properties: Optional[dict] = None,
68 **kwargs,
69 ) -> None:
70 properties = properties or {}
72 # Call parent class constructor
73 super().__init__(properties)
74 self.locals_var_dict = locals().copy()
76 # Input/Output files
77 self.io_dict = {
78 "in": {
79 "input_haddock_wf_data": input_haddock_wf_data,
80 "ambig_restraints_table_path": ambig_restraints_table_path,
81 "unambig_restraints_table_path": unambig_restraints_table_path,
82 "hb_restraints_table_path": hb_restraints_table_path,
83 "haddock_config_path": haddock_config_path,
84 },
85 "out": {
86 "output_haddock_wf_data": output_haddock_wf_data,
87 "refinement_output_zip_path": refinement_output_zip_path,
88 },
89 }
91 # Properties specific for BB
92 self.haddock_step_name = "flexref"
93 # Handle configuration options from propierties
94 self.cfg = {k: v for k, v in properties.get("cfg", dict()).items()}
95 # Handle configuration options from arguments
96 if ambig_restraints_table_path:
97 self.cfg["ambig_fname"] = ambig_restraints_table_path
98 if unambig_restraints_table_path:
99 self.cfg["unambig_fname"] = unambig_restraints_table_path
100 if hb_restraints_table_path:
101 self.cfg["hbond_fname"] = hb_restraints_table_path
102 # Global HADDOCK configuration options
103 self.global_cfg = properties.get("global_cfg", dict(postprocess=False))
104 # Properties specific for BB
105 self.binary_path = properties.get("binary_path", "haddock3")
106 # Check the properties
107 self.check_init(properties)
109 def _handle_config_arguments(self):
110 """Handle configuration options from arguments."""
111 if self.io_dict["in"].get("ambig_restraints_table_path"):
112 self.cfg["ambig_fname"] = abspath(self.stage_io_dict["in"].get("ambig_restraints_table_path"))
113 if self.io_dict["in"].get("unambig_restraints_table_path"):
114 self.cfg["unambig_fname"] = abspath(self.stage_io_dict["in"].get("unambig_restraints_table_path"))
115 if self.io_dict["in"].get("hb_restraints_table_path"):
116 self.cfg["hbond_fname"] = abspath(self.stage_io_dict["in"].get("hb_restraints_table_path"))
118 def _handle_step_output(self):
119 """Handle how the output files from the step are copied to host."""
120 if refinement_output_zip_path := self.io_dict["out"].get("refinement_output_zip_path"):
121 self.copy_step_output(
122 lambda path: path.match(self.haddock_step_name + r"*.pdb*"),
123 refinement_output_zip_path
124 )
127def flex_ref(
128 input_haddock_wf_data: str,
129 output_haddock_wf_data: str,
130 refinement_output_zip_path: Optional[str] = None,
131 ambig_restraints_table_path: Optional[str] = None,
132 unambig_restraints_table_path: Optional[str] = None,
133 hb_restraints_table_path: Optional[str] = None,
134 haddock_config_path: Optional[str] = None,
135 properties: Optional[dict] = None,
136 **kwargs,
137) -> int:
138 """Create :class:`FlexRef <biobb_haddock.haddock.flex_ref>` class and
139 execute the :meth:`launch() <biobb_haddock.haddock.flex_ref.launch>` method."""
140 # Launch method inherited from HaddockStepBase
141 return FlexRef(**dict(locals())).launch()
144flex_ref.__doc__ = FlexRef.__doc__
145main = FlexRef.get_main(flex_ref, "Wrapper of the HADDOCK3 FlexRef module.")
148if __name__ == "__main__":
149 main()