I need to walk with crutches additional two weeks but getting better ;) I hope I would like to start running as soon as possible….
I posted about rdkit shape-it implementation before. I think it’s really useful open source package because it works very fast and can use as python library. It means that you can use shape-it on jupyter notebook. BTW, as rdkitter know that RDKit already has shape based alignment function.
So today I compared these result with CDK2.sdf data set.
At first I launch pymol with -R option which launch pymol as means server mode for communicate from rdkit. Then conduct shape based align with native rdkit function.
The first step is making SubshapeBuilder object and generate shape object of reference and probe molecules. Then align these molecules with SubshapeAligner object. It take few seconds and after the code, I could get algs object. It contain list of shape based alignment results. To visualize aligned molecule, calling AllChem.TransformMol with transform matrix.
from rdkit import Chem from rdkit.Chem import AllChem from rdkit.Chem import Draw from rdkit.Chem.Draw import IPythonConsole from rdkit.Chem import PyMol from rdkit.Chem.Subshape import SubshapeAligner, SubshapeBuilder, SubshapeObjects mols = [m for m in Chem.SDMolSupplier('cdk2.sdf')] for m in mols: molid = m.GetProp('id') m.SetProp('_Name', molid) #_Name prop is required for align with shape-it v = PyMol.MolViewer() ref = Chem.Mol(mols.ToBinary()) probe = Chem.Mol(mols.ToBinary()) AllChem.CanonicalizeConformer(ref.GetConformer()) builder = SubshapeBuilder.SubshapeBuilder() builder.gridDims = (20.,20.,10) builder.gridSpacing=0.5 builder.winRad = 4. refShape = builder.GenerateSubshapeShape(ref) probeShape = builder.GenerateSubshapeShape(probe) aligner = SubshapeAligner.SubshapeAligner() algs = aligner.GetSubshapeAlignments(ref, refShape, probe, probeShape, builder) alg = algs AllChem.TransformMol(probe, alg.transform) newprobeShape = builder(probe) v.DeleteAll() v.ShowMol(ref, name='ref', showOnly=False) SubshapeObjects.DisplaySubshape(v, refShape, 'ref_Shape') v.server.do('set transparency=0.5') v.ShowMol(probe, name='probe', showOnly=False) SubshapeObjects.DisplaySubshape(v, newprobeShape, 'prob_Shape') v.server.do('set transparency=0.5') v.GetPNG()
Finally I could get following image from pymol. It well aligned.
Next, I tried to align and visualize molecules with rdkit-shape-it.
It seems really simple to align molecules with this library. The code is below.
import sys import os sys.path.append('/home/iwatobipen/src/shape-it/pyshapeit') import cpyshapeit mols = [m for m in Chem.SDMolSupplier('cdk2.sdf')] ref = mols probe = mols AllChem.CanonicalizeConformer(ref.GetConformer()) builder2 = SubshapeBuilder.SubshapeBuilder() builder2.gridDims = (20.,20.,10) builder2.gridSpacing=0.5 builder2.winRad = 4. refShape = builder2.GenerateSubshapeShape(ref) probeShape = builder2.GenerateSubshapeShape(probe) score = cpyshapeit.AlignMol(ref, probe) v.DeleteAll() v.ShowMol(ref, name='ref', showOnly=False) SubshapeObjects.DisplaySubshape(v, refShape, 'ref_Shape') v.server.do('set transparency=0.5') v.ShowMol(probe, name='probe', showOnly=False) SubshapeObjects.DisplaySubshape(v, newprobeShape, 'prob_Shape') v.server.do('set transparency=0.5') v.GetPNG()
After running the code shown above, I could get following image.
Shape tanimoto from rdkit native function was 0.83 and from shape-it was 0.77. So RDKit native function seems work better than current rdkit-shape-it but it works slow compared to shape-it. So I think it’s better to use shape-it if we need to align lots of molecules but we should use rdkit shape align when we need to align few molecules. And the result indicates that there is space of improvement of performance of shape-it.
I uploaded today’s code on my gist. Any advice, suggestion, comments will be greatly appreciated.
Here is a today’s code.