Michal Krompiec
2013-10-22 12:42:33 UTC
Hello, I am trying to use the new functionality for manipulation of
dihedral angles in a function similar to OpenBabel's obrotate tool.
But it doesn't work: I get a ValueError exception. Here is an example
that replicates the error:
from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import rdMolTransforms
mol=Chem.MolFromSmiles('c2ccsc2c1sccc1') #2,2'-bithiophene
mol=Chem.AddHs(mol)
AllChem.EmbedMolecule(mol)
sp=Chem.MolFromSmarts("c2([H])ccsc2c1sccc1")
atoms=(5,6,7,8)
newangle=180.0
maplist = mol.GetSubstructMatches(sp)
if (len(maplist)>0):
for match in maplist :
a=[]
for i in range (0,4) :
a.append(match[atoms[i]])
angle=rdMolTransforms.GetDihedralDeg(mol.GetConformer(), a[0],
a[1], a[2], a[3])
print("angle between atoms {}".format(a)+" is
{}".format(angle))
print("trying to set to the same angle")
rdMolTransforms.SetDihedralDeg(mol.GetConformer(), a[0], a[1],
a[2], a[3], angle) #if you comment this line out
print("trying to set to another angle")
rdMolTransforms.SetDihedralDeg(mol.GetConformer(), a[0], a[1],
a[2], a[3], newangle) #this one will crash as well
angle=rdMolTransforms.GetDihedralDeg(mol.GetConformer(), a[0],
a[1], a[2], a[3])
print("angle between atoms {}".format(a)+" is
{}".format(angle))
Best wishes,
Michal Krompiec
dihedral angles in a function similar to OpenBabel's obrotate tool.
But it doesn't work: I get a ValueError exception. Here is an example
that replicates the error:
from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import rdMolTransforms
mol=Chem.MolFromSmiles('c2ccsc2c1sccc1') #2,2'-bithiophene
mol=Chem.AddHs(mol)
AllChem.EmbedMolecule(mol)
sp=Chem.MolFromSmarts("c2([H])ccsc2c1sccc1")
atoms=(5,6,7,8)
newangle=180.0
maplist = mol.GetSubstructMatches(sp)
if (len(maplist)>0):
for match in maplist :
a=[]
for i in range (0,4) :
a.append(match[atoms[i]])
angle=rdMolTransforms.GetDihedralDeg(mol.GetConformer(), a[0],
a[1], a[2], a[3])
print("angle between atoms {}".format(a)+" is
{}".format(angle))
print("trying to set to the same angle")
rdMolTransforms.SetDihedralDeg(mol.GetConformer(), a[0], a[1],
a[2], a[3], angle) #if you comment this line out
print("trying to set to another angle")
rdMolTransforms.SetDihedralDeg(mol.GetConformer(), a[0], a[1],
a[2], a[3], newangle) #this one will crash as well
angle=rdMolTransforms.GetDihedralDeg(mol.GetConformer(), a[0],
a[1], a[2], a[3])
print("angle between atoms {}".format(a)+" is
{}".format(angle))
Best wishes,
Michal Krompiec