Coverage for biobb_vs/vina/autodock_vina_run.py: 86%
28 statements
« prev ^ index » next coverage.py v7.18.0, created at 2026-12-03 15:52 +0000
« prev ^ index » next coverage.py v7.18.0, created at 2026-12-03 15:52 +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, launcher
7from biobb_common.tools import file_utils as fu
10class AutoDockVinaRun(BiobbObject):
11 """
12 | biobb_vs AutoDockVinaRun
13 | Wrapper of the AutoDock Vina software.
14 | 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.
16 Args:
17 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).
18 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).
19 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).
20 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).
21 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).
22 properties (dic - Python dictionary object containing the tool parameters, not input/output files):
23 * **cpu** (*int*) - (1) [1~1000|1] the number of CPUs to use.
24 * **exhaustiveness** (*int*) - (8) [1~10000|1] exhaustiveness of the global search (roughly proportional to time).
25 * **num_modes** (*int*) - (9) [1~1000|1] maximum number of binding modes to generate.
26 * **min_rmsd** (*int*) - (1) [1~1000|1] minimum RMSD between output poses.
27 * **energy_range** (*int*) - (3) [1~1000|1] maximum energy difference between the best binding mode and the worst one displayed (kcal/mol).
28 * **binary_path** (*string*) - ('vina') path to vina in your local computer.
29 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
30 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
31 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
32 * **container_path** (*str*) - (None) Container path definition.
33 * **container_image** (*str*) - ('biocontainers/autodock-vina:v1.1.2-5b1-deb_cv1') Container image definition.
34 * **container_volume_path** (*str*) - ('/tmp') Container volume path definition.
35 * **container_user_id** (*str*) - (None) Container user_id definition.
36 * **container_shell_path** (*str*) - ('/bin/bash') Path to default shell inside the container.
38 Examples:
39 This is a use example of how to use the building block from Python::
41 from biobb_vs.vina.autodock_vina_run import autodock_vina_run
42 prop = {
43 'binary_path': 'vina'
44 }
45 autodock_vina_run(input_ligand_pdbqt_path='/path/to/myLigand.pdbqt',
46 input_receptor_pdbqt_path='/path/to/myReceptor.pdbqt',
47 input_box_path='/path/to/myBox.pdb',
48 output_pdbqt_path='/path/to/newStructure.pdbqt',
49 output_log_path='/path/to/newLog.log',
50 properties=prop)
52 Info:
53 * wrapped_software:
54 * name: Autodock Vina
55 * version: >=1.2.3
56 * license: Apache-2.0
57 * ontology:
58 * name: EDAM
59 * schema: http://edamontology.org/EDAM.owl
61 """
63 def __init__(
64 self,
65 input_ligand_pdbqt_path: str,
66 input_receptor_pdbqt_path: str,
67 input_box_path: str,
68 output_pdbqt_path: str,
69 output_log_path: Optional[str] = None,
70 properties: Optional[dict] = None,
71 **kwargs,
72 ) -> None:
73 super().__init__(**locals())
75 def calculate_box(self, box_file_path):
76 """Read the box center and the box edge lengths from the REMARK line of a box PDB file.
78 The SIZE field is the full edge length of the box, matching what AutoDock Vina
79 expects in --size_x/y/z.
80 """
81 with open(box_file_path, "r") as box_file:
82 for line in box_file:
83 line = line.rstrip(os.linesep)
84 if line.startswith("REMARK BOX CENTER"):
85 fields = line.split()
86 center = fields[3:6]
87 size = fields[-3:]
88 return list(
89 map(
90 str,
91 [
92 center[0],
93 center[1],
94 center[2],
95 size[0],
96 size[1],
97 size[2],
98 ],
99 )
100 )
101 msg = self.__class__.__name__ + ": No 'REMARK BOX CENTER' line found in the input box file: %s" % box_file_path
102 fu.log(msg, self.out_log)
103 raise SystemExit(msg)
105 def run(self) -> None:
106 """Execute the :class:`AutoDockVinaRun_run <vina.autodock_vina_run.AutoDockVinaRun_run>` vina.autodock_vina_run.AutoDockVinaRun_run object."""
108 # calculating box position and size
109 x0, y0, z0, sidex, sidey, sidez = self.calculate_box(
110 self.io_dict["in"]["input_box_path"]
111 )
113 # create cmd
114 self.cmd = [
115 self.binary_path,
116 "--ligand",
117 self.stage_io_dict["in"]["input_ligand_pdbqt_path"],
118 "--receptor",
119 self.stage_io_dict["in"]["input_receptor_pdbqt_path"],
120 "--center_x=" + x0,
121 "--center_y=" + y0,
122 "--center_z=" + z0,
123 "--size_x=" + sidex,
124 "--size_y=" + sidey,
125 "--size_z=" + sidez,
126 "--cpu",
127 str(self.cpu),
128 "--exhaustiveness",
129 str(self.exhaustiveness),
130 "--num_modes",
131 str(self.num_modes),
132 "--min_rmsd",
133 str(self.min_rmsd),
134 "--energy_range",
135 str(self.energy_range),
136 "--out",
137 self.stage_io_dict["out"]["output_pdbqt_path"],
138 "--verbosity",
139 "1",
140 ]
141 if self.stage_io_dict["out"].get("output_log_path"):
142 self.cmd.extend([">", self.stage_io_dict["out"]["output_log_path"]])
144 # Run Biobb block
145 self.run_biobb()
148autodock_vina_run = launcher(AutoDockVinaRun)
151if __name__ == "__main__":
152 AutoDockVinaRun.main()