drawing - 如何绘制正确显示键角的多环芳烃的子结构?
问题描述
感谢您阅读我的问题。
假设我有一个多环芳烃(我们称之为“母分子”),如下所示:
smile = "c1ccc2ocnc2c1"
mol = Chem.MolFromSmiles(smile)
当我绘制母体分子的子结构时,我注意到子结构中的键角与母体分子中的键角不同。以下是我使用的代码:
from rdkit import Chem
from rdkit.Chem.Draw import rdMolDraw2D
from IPython.display import SVG
smile_1 = 'c(cc)cc'
smile_2 = 'n(co)c(c)c'
m1 = Chem.MolFromSmiles(smile_1,sanitize=False)
Chem.SanitizeMol(m1, sanitizeOps=(Chem.SanitizeFlags.SANITIZE_ALL^Chem.SanitizeFlags.SANITIZE_KEKULIZE^Chem.SanitizeFlags.SANITIZE_SETAROMATICITY))
m2 = Chem.MolFromSmiles(smile_2,sanitize=False)
Chem.SanitizeMol(m2, sanitizeOps=(Chem.SanitizeFlags.SANITIZE_ALL^Chem.SanitizeFlags.SANITIZE_KEKULIZE^Chem.SanitizeFlags.SANITIZE_SETAROMATICITY))
mols = [m1, m2]
smiles = ["smile_1", "smile_2"]
molsPerRow=2
subImgSize=(200, 200)
nRows = len(mols) // molsPerRow
if len(mols) % molsPerRow:
nRows += 1
fullSize = (molsPerRow * subImgSize[0], nRows * subImgSize[1])
d2d = rdMolDraw2D.MolDraw2DSVG(fullSize[0], fullSize[1], subImgSize[0], subImgSize[1])
d2d.drawOptions().prepareMolsBeforeDrawing=False
d2d.DrawMolecules(mols, legends=smiles)
d2d.FinishDrawing()
SVG(d2d.GetDrawingText())
结果如下图:
可以看出,子结构中的几个键之间的角度与母体分子不同。
有没有办法绘制与母分子具有相同键角的子结构?任何帮助是极大的赞赏。
解决方案
您可以将父级的原始位置设置为子结构。
from rdkit import Chem
from rdkit.Chem.Draw import IPythonConsole
from rdkit.Chem import rdDepictor
rdDepictor.SetPreferCoordGen(True)
def getNiceSub(parent, sub):
# Get the coordinates of parent (also need to built a conformer)
mol = Chem.MolFromSmiles(parent)
rdDepictor.Compute2DCoords(mol)
# Get the coordinates of substructure to built a conformer
substruct = Chem.MolFromSmiles(sub, sanitize=False)
rdDepictor.Compute2DCoords(substruct)
# Get the index of the matched atoms
ms = mol.GetSubstructMatch(substruct)
# Get the positions of the matched atoms
conf1 = mol.GetConformer()
p = [list(conf1.GetAtomPosition(x)) for x in ms]
# Set the original positions of parent to substructure
conf2 = substruct.GetConformer()
for n in range(len(ms)):
conf2.SetAtomPosition(n, p[n])
return substruct
parent = 'c1ccc2ocnc2c1'
substructer = 'n(co)c(c)c'
nicesub = getNiceSub(parent, substructer)
父母
子结构
推荐阅读
- php - php字符串日期到日期时间格式
- tkinter - 如何使 tkinter 下拉以在 python 3 中保存数据?
- javascript - Observables - Angular - .map 不起作用,但 .subscribe 可以
- python - 将获取图像索引并返回其颜色的函数
- c# - Linq 挑战:将这段代码从方法链转换为标准 Linq
- c# - 将 C# 函数转换为 Swift 4.2
- ruby - Ruby 的 rest-client 如何为 OAuth 2 工作?
- ios - React Native iphone 5视图问题
- sql-server - 如何将表名称定义为@variable 并选择它
- r - 如何捕获变量名称的 R Shiny 文本输入以进行分析