我需要找到一个由smiles字符串(或.xyz文件)列出的分子中所有可能键合和原子之间的角度列表。

2024-06-16 00:55:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图发展力场,为了做到这一点,我需要一个列表,所有可能的键,角度和二面体在一个分子从微笑字符串oe.xyz文件。你知道吗

有没有可能用RDkit来做呢?如果是,怎么做?你知道吗


Tags: 文件字符串列表分子oe角度rdkitxyz
1条回答
网友
1楼 · 发布于 2024-06-16 00:55:17

要从分子中获取角度,它必须至少有二维坐标,rdkit无法从XYZ文件构造分子,但可以读取字符串。你知道吗

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)

如果需要,你可以generate 3D coordinates的分子,或者你可以读取分子与三维坐标使用SDF文件或类似的。软件openbabel可以将XYZ转换成SDF

相关问题 更多 >