To align rdkitmol object to given scaffold, GenerateDepictionMatching2DStructure is useful to do that. But, somedays ago I asked my colleague that the function could not adjust bond length when scaffold which is read from sdf and it has different bond length of RDKit’s default settings.
I found useful information in rdkit-discuss about rdMolTransforms.
rdMolTransforms.TransformConformer method can change bond length, but all bonds length are changed.
So I considered how to solve the problem. At first, I tried to use rdTransform.SetBondlength method, however the function could not apply the bond in the ring.
So I defined original function to do it. Here is my example code.
At first, I made simple scaffold and changed bond length of the scaffold.
Now I could get pretty scaffold. ;)
Write the molecule to SD File.
writer = Chem.SDWriter('scaf.sdf') writer.write(scaf) writer.close()
Then I made new molecule to align.
mol = Chem.MolFromSmiles('Nc1ccc(C)cc1')
Next, load scaffold and align without bond length adjustment.
scaf = Chem.SDMolSupplier('scaf.sdf') cpmol = copy.deepcopy(mol) AllChem.GenerateDepictionMatching2DStructure(cpmol, scaf) cpmol
Now I could get strange image…
To fix the issue I defined following function.
fdef bondnormalize(mol, temp): AllChem.Compute2DCoords(mol) ref_bond = mol.GetBonds() ref_length = rdMolTransforms.GetBondLength(mol.GetConformer(), ref_bond.GetBeginAtomIdx(),ref_bond.GetEndAtomIdx() ) prob_bond = temp.GetBonds() prob_length = rdMolTransforms.GetBondLength(temp.GetConformer(), prob_bond.GetBeginAtomIdx(),prob_bond.GetEndAtomIdx() ) ratio = ref_length / prob_length tm = np.zeros((4,4), np.double) for i in range(3): tm[i,i] = ratio rdMolTransforms.TransformConformer(temp.GetConformer(), tm) AllChem.GenerateDepictionMatching2DStructure(mol, temp) return mol
Check the function.
Wow it worked well.
It is rare case that reader would like to do like that. RDKit has many function for chemoinformatics. It really fun!.
Today’s code can read from following URL.
Any comments and advices are highly appreciate.