Coverage for biobb_haddock/haddock_restraints/haddock_interface.py: 0%
36 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-13 14:55 +0000
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-13 14:55 +0000
1#!/usr/bin/env python3
3"""Module containing the haddock 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
10class HaddockRestrainInterface(BiobbObject):
11 """
12 | biobb_haddock HaddockRestrainInterface
13 | Wrapper class for the Haddock-Restraints interface module.
14 | `Haddock-Restraints interface <https://www.bonvinlab.org/haddock-restraints/interface.html>`_ lists residues in the interface based on a cutoff distance.
16 Args:
17 input_pdb_path (str): Path to the input PDB structure to analyze. File type: input. `Sample file <https://raw.githubusercontent.com/bioexcel/biobb_haddock/master/biobb_haddock/test/data/haddock_restraints/4G6K_clean.pdb>`_. Accepted formats: pdb (edam:format_1476).
18 output_txt_path (str): Path to the output text file with the list of interface residues. File type: output. Accepted formats: txt (edam:format_2330).
19 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
20 * **cutoff** (*float*) - (4.0) Cutoff distance in Angstroms for interface residues calculation.
21 * **binary_path** (*str*) - ("haddock3-restraints") Path to the HADDOCK3 restraints 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.
24 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
25 * **container_path** (*str*) - (None) Path to the binary executable of your container.
26 * **container_image** (*str*) - (None) Container Image identifier.
27 * **container_volume_path** (*str*) - ("/data") Path to an internal directory in the container.
28 * **container_working_dir** (*str*) - (None) Path to the internal CWD in the container.
29 * **container_user_id** (*str*) - (None) User number id to be mapped inside the container.
30 * **container_shell_path** (*str*) - ("/bin/bash") Path to the binary executable of the container shell.
33 Examples:
34 This is a use example of how to use the building block from Python::
36 from biobb_haddock.haddock_restraints.haddock_interface import haddock_interface
37 haddock_interface(
38 input_pdb_path='/path/to/structure.pdb',
39 output_txt_path='/path/to/interface_residues.txt',
40 properties={'cutoff': 5.0}
41 )
43 Info:
44 * wrapped_software:
45 * name: Haddock3-restraints
46 * version: 2025.5
47 * license: Apache-2.0
48 * ontology:
49 * name: EDAM
50 * schema: http://edamontology.org/EDAM.owl
51 """
53 def __init__(
54 self,
55 input_pdb_path: str,
56 output_txt_path: str,
57 properties: Optional[dict] = None,
58 **kwargs,
59 ) -> None:
60 properties = properties or {}
62 # Call parent class constructor
63 super().__init__(properties)
64 self.locals_var_dict = locals().copy()
66 # Input/Output files
67 self.io_dict = {
68 "in": {
69 "input_pdb_path": input_pdb_path
70 },
71 "out": {
72 "output_txt_path": output_txt_path,
73 },
74 }
76 # Properties specific for BB
77 self.binary_path = properties.get("binary_path", "haddock-restraints")
78 self.cutoff = properties.get("cutoff", 4.0)
80 # Check the properties
81 self.check_init(properties)
83 @launchlogger
84 def launch(self) -> int:
85 """Execute the :class:`Haddock3RestrainInterface <biobb_haddock.haddock_restraints.haddock_interface>` object."""
87 # Setup Biobb
88 if self.check_restart():
89 return 0
90 self.stage_files()
92 # haddock3-restraints interface <structure> <cutoff>
93 self.cmd = [self.binary_path, "interface",
94 self.stage_io_dict['in']['input_pdb_path'],
95 str(self.cutoff)]
97 self.cmd.append(">")
98 self.cmd.append(self.stage_io_dict['out']['output_txt_path'])
99 self.cmd.append("2>&1")
101 # Run Biobb block
102 self.run_biobb()
104 # Open the file and sort the lines so the output is always the same
105 with open(self.stage_io_dict['out']['output_txt_path'], 'r') as f:
106 lines = f.readlines()
107 lines.sort()
108 with open(self.stage_io_dict['out']['output_txt_path'], 'w') as f:
109 f.writelines(lines)
111 # Copy files to host
112 self.copy_to_host()
114 # Remove temporal files
115 self.remove_tmp_files()
117 return self.return_code
120def haddock_interface(
121 input_pdb_path: str,
122 output_txt_path: str,
123 properties: Optional[dict] = None,
124 **kwargs,
125) -> int:
126 """Create :class:`Haddock3RestrainInterface <biobb_haddock.haddock_restraints.haddock_interface>` class and
127 execute the :meth:`launch() <biobb_haddock.haddock_restraints.haddock_interface.launch>` method."""
128 return HaddockRestrainInterface(**dict(locals())).launch()
131haddock_interface.__doc__ = HaddockRestrainInterface.__doc__
132main = HaddockRestrainInterface.get_main(haddock_interface, "Wrapper of the HADDOCK3 interface module.")
135if __name__ == "__main__":
136 main()