Coverage for biobb_vs / vina / autodock_vina_run.py: 95%
55 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-22 13:24 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-22 13:24 +0000
1#!/usr/bin/env python3
3"""Module containing the AutoDockVinaRun class and the command line interface."""
4import os
5from typing import Optional
6from biobb_common.generic.biobb_object import BiobbObject
7from biobb_common.tools.file_utils import launchlogger
8from biobb_vs.vina.common import check_input_path, check_output_path
11class AutoDockVinaRun(BiobbObject):
12 """
13 | biobb_vs AutoDockVinaRun
14 | Wrapper of the AutoDock Vina software.
15 | This class performs docking of the ligand to a set of grids describing the target protein via the `AutoDock Vina <http://vina.scripps.edu/index.html>`_ software.
17 Args:
18 input_ligand_pdbqt_path (str): Path to the input PDBQT ligand. File type: input. `Sample file <https://github.com/bioexcel/biobb_vs/raw/master/biobb_vs/test/data/vina/vina_ligand.pdbqt>`_. Accepted formats: pdbqt (edam:format_1476).
19 input_receptor_pdbqt_path (str): Path to the input PDBQT receptor. File type: input. `Sample file <https://github.com/bioexcel/biobb_vs/raw/master/biobb_vs/test/data/vina/vina_receptor.pdbqt>`_. Accepted formats: pdbqt (edam:format_1476).
20 input_box_path (str): Path to the PDB containig the residues belonging to the binding site. File type: input. `Sample file <https://github.com/bioexcel/biobb_vs/raw/master/biobb_vs/test/data/vina/vina_box.pdb>`_. Accepted formats: pdb (edam:format_1476).
21 output_pdbqt_path (str): Path to the output PDBQT file. File type: output. `Sample file <https://github.com/bioexcel/biobb_vs/raw/master/biobb_vs/test/reference/vina/ref_output_vina.pdbqt>`_. Accepted formats: pdbqt (edam:format_1476).
22 output_log_path (str) (Optional): Path to the log file. File type: output. `Sample file <https://github.com/bioexcel/biobb_vs/raw/master/biobb_vs/test/reference/vina/ref_output_vina.log>`_. Accepted formats: log (edam:format_2330).
23 properties (dic - Python dictionary object containing the tool parameters, not input/output files):
24 * **cpu** (*int*) - (1) [1~1000|1] the number of CPUs to use.
25 * **exhaustiveness** (*int*) - (8) [1~10000|1] exhaustiveness of the global search (roughly proportional to time).
26 * **num_modes** (*int*) - (9) [1~1000|1] maximum number of binding modes to generate.
27 * **min_rmsd** (*int*) - (1) [1~1000|1] minimum RMSD between output poses.
28 * **energy_range** (*int*) - (3) [1~1000|1] maximum energy difference between the best binding mode and the worst one displayed (kcal/mol).
29 * **binary_path** (*string*) - ('vina') path to vina in your local computer.
30 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
31 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
32 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
33 * **container_path** (*str*) - (None) Container path definition.
34 * **container_image** (*str*) - ('biocontainers/autodock-vina:v1.1.2-5b1-deb_cv1') Container image definition.
35 * **container_volume_path** (*str*) - ('/tmp') Container volume path definition.
36 * **container_working_dir** (*str*) - (None) Container working directory definition.
37 * **container_user_id** (*str*) - (None) Container user_id definition.
38 * **container_shell_path** (*str*) - ('/bin/bash') Path to default shell inside the container.
40 Examples:
41 This is a use example of how to use the building block from Python::
43 from biobb_vs.vina.autodock_vina_run import autodock_vina_run
44 prop = {
45 'binary_path': 'vina'
46 }
47 autodock_vina_run(input_ligand_pdbqt_path='/path/to/myLigand.pdbqt',
48 input_receptor_pdbqt_path='/path/to/myReceptor.pdbqt',
49 input_box_path='/path/to/myBox.pdb',
50 output_pdbqt_path='/path/to/newStructure.pdbqt',
51 output_log_path='/path/to/newLog.log',
52 properties=prop)
54 Info:
55 * wrapped_software:
56 * name: Autodock Vina
57 * version: >=1.2.3
58 * license: Apache-2.0
59 * ontology:
60 * name: EDAM
61 * schema: http://edamontology.org/EDAM.owl
63 """
65 def __init__(
66 self,
67 input_ligand_pdbqt_path,
68 input_receptor_pdbqt_path,
69 input_box_path,
70 output_pdbqt_path,
71 output_log_path=None,
72 properties=None,
73 **kwargs,
74 ) -> None:
75 properties = properties or {}
77 # Call parent class constructor
78 super().__init__(properties)
79 self.locals_var_dict = locals().copy()
81 # Input/Output files
82 self.io_dict = {
83 "in": {
84 "input_ligand_pdbqt_path": input_ligand_pdbqt_path,
85 "input_receptor_pdbqt_path": input_receptor_pdbqt_path,
86 "input_box_path": input_box_path,
87 },
88 "out": {
89 "output_pdbqt_path": output_pdbqt_path,
90 "output_log_path": output_log_path,
91 },
92 }
94 # Properties specific for BB
95 self.cpu = properties.get("cpu", 1)
96 self.exhaustiveness = properties.get("exhaustiveness", 8)
97 self.num_modes = properties.get("num_modes", 9)
98 self.min_rmsd = properties.get("min_rmsd", 1)
99 self.energy_range = properties.get("energy_range", 3)
100 self.binary_path = properties.get("binary_path", "vina")
101 self.properties = properties
103 # Check the properties
104 self.check_properties(properties)
105 self.check_arguments()
107 def check_data_params(self, out_log, err_log):
108 """Checks all the input/output paths and parameters"""
109 self.io_dict["in"]["input_ligand_pdbqt_path"] = check_input_path(
110 self.io_dict["in"]["input_ligand_pdbqt_path"],
111 "input_ligand_pdbqt_path",
112 self.out_log,
113 self.__class__.__name__,
114 )
115 self.io_dict["in"]["input_receptor_pdbqt_path"] = check_input_path(
116 self.io_dict["in"]["input_receptor_pdbqt_path"],
117 "input_receptor_pdbqt_path",
118 self.out_log,
119 self.__class__.__name__,
120 )
121 self.io_dict["in"]["input_box_path"] = check_input_path(
122 self.io_dict["in"]["input_box_path"],
123 "input_box_path",
124 self.out_log,
125 self.__class__.__name__,
126 )
127 self.io_dict["out"]["output_pdbqt_path"] = check_output_path(
128 self.io_dict["out"]["output_pdbqt_path"],
129 "output_pdbqt_path",
130 False,
131 self.out_log,
132 self.__class__.__name__,
133 )
134 self.io_dict["out"]["output_log_path"] = check_output_path(
135 self.io_dict["out"]["output_log_path"],
136 "output_log_path",
137 True,
138 self.out_log,
139 self.__class__.__name__,
140 )
142 def calculate_box(self, box_file_path):
143 with open(box_file_path, "r") as box_file:
144 for line in box_file:
145 line = line.rstrip(os.linesep)
146 if line.startswith("REMARK BOX CENTER"):
147 fields = line.split()
148 center = fields[3:6]
149 size = fields[-3:]
150 return list(
151 map(
152 str,
153 [
154 center[0],
155 center[1],
156 center[2],
157 size[0],
158 size[1],
159 size[2],
160 ],
161 )
162 )
163 return list(map(str, [0, 0, 0, 0, 0, 0]))
165 @launchlogger
166 def launch(self) -> int:
167 """Execute the :class:`AutoDockVinaRun_run <vina.autodock_vina_run.AutoDockVinaRun_run>` vina.autodock_vina_run.AutoDockVinaRun_run object."""
169 # check input/output paths and parameters
170 self.check_data_params(self.out_log, self.err_log)
172 # Setup Biobb
173 if self.check_restart():
174 return 0
175 self.stage_files()
177 # calculating box position and size
178 x0, y0, z0, sidex, sidey, sidez = self.calculate_box(
179 self.io_dict["in"]["input_box_path"]
180 )
182 # in case ligand or receptor end with END, remove last line
183 # check_input_autodock(self.io_dict["in"]["input_ligand_pdbqt_path"], self.out_log)
184 # check_input_autodock(self.io_dict["in"]["input_receptor_pdbqt_path"], self.out_log)
186 # create cmd
187 self.cmd = [
188 self.binary_path,
189 "--ligand",
190 self.stage_io_dict["in"]["input_ligand_pdbqt_path"],
191 "--receptor",
192 self.stage_io_dict["in"]["input_receptor_pdbqt_path"],
193 "--center_x=" + x0,
194 "--center_y=" + y0,
195 "--center_z=" + z0,
196 "--size_x=" + sidex,
197 "--size_y=" + sidey,
198 "--size_z=" + sidez,
199 "--cpu",
200 str(self.cpu),
201 "--exhaustiveness",
202 str(self.exhaustiveness),
203 "--num_modes",
204 str(self.num_modes),
205 "--min_rmsd",
206 str(self.min_rmsd),
207 "--energy_range",
208 str(self.energy_range),
209 "--out",
210 self.stage_io_dict["out"]["output_pdbqt_path"],
211 "--verbosity",
212 "1",
213 ">",
214 self.stage_io_dict["out"]["output_log_path"],
215 ]
217 # Run Biobb block
218 self.run_biobb()
220 # Copy files to host
221 self.copy_to_host()
223 # remove temporary folder(s)
224 self.remove_tmp_files()
226 self.check_arguments(output_files_created=True, raise_exception=False)
228 return self.return_code
231def autodock_vina_run(
232 input_ligand_pdbqt_path: str,
233 input_receptor_pdbqt_path: str,
234 input_box_path: str,
235 output_pdbqt_path: str,
236 output_log_path: Optional[str] = None,
237 properties: Optional[dict] = None,
238 **kwargs,
239) -> int:
240 """Create the :class:`AutoDockVinaRun <vina.autodock_vina_run.AutoDockVinaRun>` class and
241 execute the :meth:`launch() <vina.autodock_vina_run.AutoDockVinaRun.launch>` method."""
242 return AutoDockVinaRun(**dict(locals())).launch()
245autodock_vina_run.__doc__ = AutoDockVinaRun.__doc__
246main = AutoDockVinaRun.get_main(autodock_vina_run, "Prepares input ligand for an Autodock Vina Virtual Screening.")
249if __name__ == "__main__":
250 main()