Skip to content

Commit

Permalink
Fix bug #5
Browse files Browse the repository at this point in the history
  • Loading branch information
mwojcikowski committed Jul 13, 2015
1 parent 2b27ca5 commit e2d0640
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions oddt/docking/autodock_vina.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,41 @@
from oddt import toolkit

class autodock_vina(object):
def __init__(self, protein=None, size=(10,10,10), center=(0,0,0), auto_ligand=None, exhaustivness=8, num_modes=9, energy_range=3, seed=None, prefix_dir='/tmp', n_cpu=1, executable=None, autocleanup=True):
def __init__(self, protein=None, auto_ligand=None, size=(10,10,10), center=(0,0,0), exhaustivness=8, num_modes=9, energy_range=3, seed=None, prefix_dir='/tmp', n_cpu=1, executable=None, autocleanup=True):
"""Autodock Vina docking engine, which extends it's capabilities: automatic box (autocentering on ligand).
Parameters
----------
protein: oddt.toolkit.Molecule object (default=None)
Protein object to be used while generating descriptors.
auto_ligand: oddt.toolkit.Molecule object or string (default=None)
Ligand use to center the docking box. Either ODDT molecule or a file (opened based on extesion and read to ODDT molecule). Box is centered on geometric center of molecule.
size: tuple, shape=[3] (default=(10,10,10))
Dimentions of docking box (in Angstroms)
center: tuple, shape=[3] (default=(0,0,0))
The center of docking box in cartesian space.
auto_ligand: oddt.toolkit.Molecule object or string (default=None)
Ligand use to center the docking box. Either ODDT molecule or a file (opened based on extesion and read to ODDT molecule). Box is centered on geometric center of molecule.
exhaustiveness: int (default=8)
Exhaustiveness parameter of Autodock Vina
num_modes: int (default=9)
Number of conformations generated by Autodock Vina
energy_range: int (default=3)
Energy range cutoff for Autodock Vina
seed: int or None (default=None)
Random seed for Autodock Vina
prefix_dir: string (default=/tmp)
Temporary directory for Autodock Vina files
executable: string or None (default=None)
Autodock Vina executable location in the system. It's realy necessary if autodetection fails.
autocleanup: bool (default=True)
Should the docking engine clean up after execution?
"""
Expand All @@ -67,11 +67,11 @@ def __init__(self, protein=None, size=(10,10,10), center=(0,0,0), auto_ligand=No
self.version = subprocess.check_output([self.executable, '--version']).split(' ')[2]
self.autocleanup = autocleanup
self.cleanup_dirs = set()

# share protein to class
if protein:
self.set_protein(protein)

#pregenerate common Vina parameters
self.params = []
self.params = self.params + ['--center_x', str(self.center[0]), '--center_y', str(self.center[1]), '--center_z', str(self.center[2])]
Expand All @@ -82,21 +82,21 @@ def __init__(self, protein=None, size=(10,10,10), center=(0,0,0), auto_ligand=No
self.params = self.params + ['--seed', str(seed)]
self.params = self.params + ['--num_modes', str(num_modes)]
self.params = self.params + ['--energy_range', str(energy_range)]

@property
def tmp_dir(self):
if not self._tmp_dir:
self._tmp_dir = mkdtemp(dir = self.dir, prefix='autodock_vina_')
self.cleanup_dirs.add(self._tmp_dir)
return self._tmp_dir

@tmp_dir.setter
def tmp_dir(self, value):
self._tmp_dir = value

def set_protein(self, protein):
"""Change protein to dock to.
Parameters
----------
protein: oddt.toolkit.Molecule object
Expand All @@ -119,21 +119,21 @@ def set_protein(self, protein):
# write protein to file
self.protein_file = self.tmp_dir + '/protein.pdbqt'
self.protein.write('pdbqt', self.protein_file, opt={'r':None,}, overwrite=True)

def score(self, ligands, protein = None, single = False):
"""Automated scoring procedure.
Parameters
----------
ligands: iterable of oddt.toolkit.Molecule objects
Ligands to score
protein: oddt.toolkit.Molecule object or None
Protein object to be used. If None, then the default one is used, else the protein is new default.
single: bool (default=False)
A flag to indicate single ligand scoring (performance reasons (eg. there is no need for subdirectory for one ligand)
Returns
-------
ligands : array of oddt.toolkit.Molecule objects
Expand All @@ -154,21 +154,21 @@ def score(self, ligands, protein = None, single = False):
output_array.append(ligand)
rmtree(ligand_dir)
return output_array

def dock(self, ligands, protein = None, single = False):
"""Automated docking procedure.
Parameters
----------
ligands: iterable of oddt.toolkit.Molecule objects
Ligands to dock
protein: oddt.toolkit.Molecule object or None
Protein object to be used. If None, then the default one is used, else the protein is new default.
single: bool (default=False)
A flag to indicate single ligand docking (performance reasons (eg. there is no need for subdirectory for one ligand)
Returns
-------
ligands : array of oddt.toolkit.Molecule objects
Expand Down Expand Up @@ -196,19 +196,19 @@ def dock(self, ligands, protein = None, single = False):
output_array.append(clone)
rmtree(ligand_dir)
return output_array

def clean(self):
for d in self.cleanup_dirs:
rmtree(d)

def parse_vina_scoring_output(output):
"""Function parsing Autodock Vina scoring output to a dictionary
Parameters
----------
output : string
Autodock Vina standard ouptud (STDOUT).
Returns
-------
out : dict
Expand All @@ -223,15 +223,15 @@ def parse_vina_scoring_output(output):
m[1] = m[1].replace('(kcal/mol)','')
out['vina_'+m[0].lower()] = float(m[1])
return out

def parse_vina_docking_output(output):
"""Function parsing Autodock Vina docking output to a dictionary
Parameters
----------
output : string
Autodock Vina standard ouptud (STDOUT).
Returns
-------
out : dict
Expand All @@ -244,4 +244,3 @@ def parse_vina_docking_output(output):
s = line.split()
out.append({'vina_affinity': s[1], 'vina_rmsd_lb': s[2], 'vina_rmsd_ub': s[3]})
return out

0 comments on commit e2d0640

Please sign in to comment.