from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import rdMolTransforms
# Read molecule from smiles string
mol = Chem.MolFromSmiles('N1CCNCC1')
# Get all bonds in the molecule
bonds = [(x.GetBeginAtomIdx(), x.GetEndAtomIdx()) for x in mol.GetBonds()]
# [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 0)]
# Compute 2D coordinates
AllChem.Compute2DCoords(mol)
conf = mol.GetConformer()
# Get a torsion angle between atoms 0, 1 & 2
rdMolTransforms.GetAngleDeg(conf, 0, 1, 2)
# 119.99999999999999
# Get a dihedral angle between atoms 0, 1, 2 & 3
rdMolTransforms.GetDihedralDeg(c, 0, 1, 2, 3)
# -0.0 (obviously 0 as the molecule has no 3D coordinates)
要从分子中获取角度,它必须至少有二维坐标,rdkit无法从XYZ文件构造分子,但可以读取字符串。你知道吗
如果需要,你可以generate 3D coordinates的分子,或者你可以读取分子与三维坐标使用SDF文件或类似的。软件openbabel可以将XYZ转换成SDF
相关问题 更多 >
编程相关推荐