Coverage for biobb_haddock/haddock_restraints/haddock3_passive_from_active.py: 83%
54 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 Haddock3PassiveFromActive class and the command line interface."""
5from typing import Optional
6from biobb_common.generic.biobb_object import BiobbObject
7from biobb_common.tools.file_utils import launchlogger
8from biobb_common.tools import file_utils as fu
11class Haddock3PassiveFromActive(BiobbObject):
12 """
13 | biobb_haddock Haddock3PassiveFromActive
14 | Wrapper class for the Haddock3-Restraints passive_from_active module.
15 | `Haddock3-Restraints passive_from_active <https://www.bonvinlab.org/haddock3/clients/haddock.clis.restraints.passive_from_active.html>`_ given a list of active_residues and a PDB structure, it will return a list of surface exposed passive residues within a radius (6.5Å by default) from the active residues.
17 Args:
18 input_pdb_path (str): Path to the input PDB structure file. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock_restraints/1A2P_ch.pdb>`_. Accepted formats: pdb (edam:format_1476).
19 output_actpass_path (str): Path to the output file with list of passive residues. File type: output. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/reference/haddock_restraints/1A2P_manual_actpass.txt>`_. Accepted formats: txt (edam:format_2330), dat (edam:format_2330), list (edam:format_2330), out (edam:format_2330).
20 input_active_list_path (str) (Optional): Path to the input file with list of active residues. File type: input. Accepted formats: txt (edam:format_2330), dat (edam:format_2330), list (edam:format_2330).
21 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
22 * **active_list** (*str*) - ('') List of active residues as a comma-separated string. Required if input_active_list_path is not provided.
23 * **chain_id** (*str*) - (None) Chain ID to consider when calculating passive residues.
24 * **surface_list_path** (*str*) - ("") Path to file with list of surface residues to filter.
25 * **radius** (*float*) - (6.5) Radius in Angstroms to look for surface residues around active ones.
26 * **binary_path** (*str*) - ("haddock3-restraints") Path to the haddock3-restraints executable binary.
27 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
28 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
29 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
30 * **container_path** (*str*) - (None) Path to the binary executable of your container.
31 * **container_image** (*str*) - (None) Container Image identifier.
32 * **container_volume_path** (*str*) - ("/data") Path to an internal directory in the container.
33 * **container_working_dir** (*str*) - (None) Path to the internal CWD in the container.
34 * **container_user_id** (*str*) - (None) User number id to be mapped inside the container.
35 * **container_shell_path** (*str*) - ("/bin/bash") Path to the binary executable of the container shell.
37 Examples:
38 This is a use example of how to use the building block from Python::
40 from biobb_haddock.haddock_restraints.haddock3_passive_from_active import haddock3_passive_from_active
41 haddock3_passive_from_active(
42 input_pdb_path='/path/to/structure.pdb',
43 input_active_list_path='/path/to/active_residues.txt',
44 output_actpass_path='/path/to/actpass.tbl.txt',
45 properties={
46 'chain_id': 'A',
47 'radius': 6.5
48 }
49 )
51 Info:
52 * wrapped_software:
53 * name: Haddock3-restraints
54 * version: 2025.5
55 * license: Apache-2.0
56 * ontology:
57 * name: EDAM
58 * schema: http://edamontology.org/EDAM.owl
59 """
61 def __init__(
62 self,
63 input_pdb_path: str,
64 output_actpass_path: str,
65 input_active_list_path: Optional[str] = None,
66 properties: Optional[dict] = None,
67 **kwargs,
68 ) -> None:
69 properties = properties or {}
71 # Call parent class constructor
72 super().__init__(properties)
73 self.locals_var_dict = locals().copy()
75 # Input/Output files
76 self.io_dict = {
77 "in": {
78 "input_pdb_path": input_pdb_path
79 },
80 "out": {
81 "output_actpass_path": output_actpass_path
82 },
83 }
85 # Add input_active_list_path to io_dict if provided
86 if input_active_list_path:
87 self.io_dict["in"]["input_active_list_path"] = input_active_list_path
89 # Properties specific for BB
90 self.active_list = properties.get("active_list", "")
91 self.chain_id = properties.get("chain_id", None)
92 self.surface_list_path = properties.get("surface_list_path", "")
93 self.radius = properties.get("radius", 6.5)
94 self.binary_path = properties.get("binary_path", "haddock3-restraints")
96 # Check that either input_active_list_path or active_list is provided
97 if not input_active_list_path and not self.active_list:
98 raise ValueError(
99 "Either input_active_list_path or active_list property must be provided")
101 # Check the properties
102 self.check_init(properties)
104 # If surface_list_path is provided overwrite the active_list
105 if self.surface_list_path:
106 with open(self.surface_list_path, "r") as surface_file:
107 self.active_list = surface_file.read()
109 @launchlogger
110 def launch(self) -> int:
111 """Execute the :class:`Haddock3PassiveFromActive <biobb_haddock.haddock_restraints.haddock3_passive_from_active>` object."""
113 # Setup Biobb
114 if self.check_restart():
115 return 0
116 self.stage_files()
118 # Build command line
119 # haddock3-restraints passive_from_active <pdb_file> <active_list> [-c <chain_id>] [-s <surface_list>] [-r <radius>]
120 self.cmd = [
121 self.binary_path,
122 "passive_from_active",
123 self.stage_io_dict['in']['input_pdb_path'],
124 self.active_list
125 ]
127 # Add optional parameters
128 if self.chain_id:
129 self.cmd.extend(["-c", self.chain_id])
131 if self.surface_list_path:
132 self.cmd.extend(
133 ["-s", self.stage_io_dict['in']['surface_list_path']])
135 # Radius not in this version
136 # self.cmd.extend(["-r", str(self.radius)])
138 # Redirect output to the output file
139 self.cmd.append(">")
140 self.cmd.append(self.stage_io_dict['out']['output_actpass_path'])
141 self.cmd.append("2>&1")
143 # Run Biobb block
144 self.run_biobb()
146 # Remove deprecation warning if present
147 with open(self.stage_io_dict['out']['output_actpass_path'], 'r') as file:
148 lines = file.readlines()
149 fu.log('Result: ' + '\n'.join(lines), self.out_log, self.global_log)
150 with open(self.stage_io_dict['out']['output_actpass_path'], 'w') as file:
151 file.write(self.active_list.replace(",", " ")+"\n")
152 if lines and "DEPRECATION NOTICE" in lines[0]:
153 file.writelines(lines[1:])
154 else:
155 file.writelines(lines)
157 # Copy files to host
158 self.copy_to_host()
160 # Remove temporal files
161 self.remove_tmp_files()
163 return self.return_code
166def haddock3_passive_from_active(
167 input_pdb_path: str,
168 output_actpass_path: str,
169 input_active_list_path: Optional[str] = None,
170 properties: Optional[dict] = None,
171 **kwargs,
172) -> int:
173 """Create :class:`Haddock3PassiveFromActive <biobb_haddock.haddock_restraints.haddock3_passive_from_active>` class and
174 execute the :meth:`launch() <biobb_haddock.haddock_restraints.haddock3_passive_from_active.launch>` method."""
175 return Haddock3PassiveFromActive(**dict(locals())).launch()
178haddock3_passive_from_active.__doc__ = Haddock3PassiveFromActive.__doc__
179main = Haddock3PassiveFromActive.get_main(
180 haddock3_passive_from_active,
181 "Wrapper of the Haddock3-Restraints passive_from_active module."
182)
185if __name__ == "__main__":
186 main()