Docking with Python

Это пример использования ODDT (http://jcheminf.springeropen.com/articles/10.1186/s13321-015-0078-2) для проведения докинга и визуализации в брфузере Перед запуском Ipython Notebook сделайте следующие шаги :

export PATH=${PATH}:/home/preps/golovin/miniconda2/bin
source activate oddt
jupyter notebook --no-browser
In [1]:
from IPython.display import Image
import ipywidgets
from ipywidgets.widgets import HBox
import numpy as np

from IPython.display import SVG


#import rdkit.RDConfig
#rdkit.RDConfig.RDDataDir='/home/preps/golovin/rdkit/usr/share/RDKit/Data/'


import oddt
import oddt.docking


#from rdkit.Chem import Draw
#from rdkit.Chem.Draw import IPythonConsole


import simpletraj

import nglview
In [31]:
# lets define adaptors for 3d viewer

class oddt_trajectory(nglview.Structure, nglview.Trajectory):
    ext = "pdb"  # or gro, cif, mol2, sdf
    params = {}  # loading options passed to NGL
    def __init__(self,prot,mol,res):
        self.prot = prot
        self.mol = mol
        self.res = res
    def get_structure_string(self):
        out=''
        for l in (self.prot.write('pdb')+self.mol.write('pdb')).split('\n'):
            if 'ATOM' in l or 'HETATM' in l:
                out+= l + '\n'
        return out
    def get_coordinates_list( self, index ):
        return self.prot.coords.flatten().tolist() + self.res[index].coords.flatten().tolist()
        #    coors 
        # return list of coordinates in Angstrom for the frame at the given index
        #return [x1, y1, z1, x2, y2, z2]
    def get_frame_count( self ):
        return len(self.res)  # return number of frames
    


class ob_structure(nglview.Structure):
    ext = 'pdb'
    params = {}
    def __init__(self,m):
        self.m=m
    def get_structure_string(self):
        return self.m.write('pdb')

def show_ob_structure(m, **kwargs):
  
    extension = 'pdb'
    structure = nglview.OBStructure(m)
    return nglview.NGLWidget(structure, **kwargs)

def show_ob_traj(p,l,r, **kwargs):

    extension = 'pdb'
    structure_trajectory = nglview.ODDTTrajectory(p,l,r)
    return nglview.NGLWidget(structure_trajectory, **kwargs)

    
nglview.ODDTTrajectory=oddt_trajectory 
nglview.OBStructure = ob_structure
nglview.show_ob_structure=show_ob_structure
In [32]:
#create objects for ligand(s) and protein

mol = oddt.toolkit.readstring('smi', 'c1cccc(O)c1')

if not mol.OBMol.Has3D(): 
    mol.make3D(forcefield='mmff94', steps=150)
    mol.localopt()
    print mol.energy
    mol.removeh()
    mol.OBMol.AddPolarHydrogens()

prot = oddt.toolkit.readfile('pdb','/tmp/1lmp.pdb').next()

# some print

print prot.protein, prot.molwt 

print mol, mol.molwt

mol
0.0
False 14145.94808
c1cccc(O)c1	
 94.11124
Out[32]:
Multiple Molecules - Open Babel DepictionOH
In [4]:
#create docking object
dock_obj= oddt.docking.AutodockVina.autodock_vina(
    protein=prot,size=(20,20,20),center=(42.0,48.0,30.0),
    executable='/usr/bin/vina',autocleanup=False, num_modes=20)
In [6]:
# do docking
res = dock_obj.dock([mol],prot)
In [28]:
# show 3D results
pres = [
     {"type": "ball+stick", "params": {
        "sele": "all"
    }}
]


w3 = show_ob_traj(prot,res[0],res)
w3.representations = pres
w3
In [29]:
# print some data
for r in res:
     print "%8.3f%8.3f\n" %(float(r.data['vina_rmsd_ub']),float(r.data['vina_affinity']))
     
   0.000  -3.900

   2.550  -3.800

   2.345  -3.700

   3.769  -3.700

   3.844  -3.600

   3.790  -3.600

   7.185  -3.500

   6.215  -3.500

   4.108  -3.400

In [30]:
# print docking params
" ".join(dock_obj.params)
Out[30]:
'--center_x 42.0 --center_y 48.0 --center_z 30.0 --size_x 20 --size_y 20 --size_z 20 --cpu 1 --exhaustiveness 8 --num_modes 20 --energy_range 3'
In [ ]: