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[0].ToBinary())
probe = Chem.Mol(mols[1].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[0]
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[0]
probe = mols[1]
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.
https://nbviewer.jupyter.org/gist/iwatobipen/cef48aabcbd10e12ac23a12b7994ebd0
Are you Ok? Did you get an accident? That’s very unfortunate. I’m not doing Cheminformatics frequently but your posts inspire me a lot. I hope you get better soon. お大事に!
Thanks. I’m getting well. No problem ;)
Hi, Thanks for sharing your code. Did you try this code in google Colab?
Not yet. I’ve never tried to install pymol in google colab. ;)
hi sir, can know what ” algs = aligner.GetSubshapeAlignments(ref, refShape, probe, probeShape, builder)” this code does and why you assumed ” alg = algs[0]” as the shape distance.