我试图突出测试分子中的碳位置,同时隐藏隐含的氢。这出乎意料地复杂,因为我有两个复合问题,每个问题都有一个解决方案,但不兼容
from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import rdMolDraw2D
from rdkit.Chem.Draw import IPythonConsole
from IPython.display import SVG
import rdkit
Molblock = 'molblock information here'
mx = Chem.MolFromMolBlock(Molblock,sanitize=False)# this molblock already provides an atom map, which I must remove to keep from displaying all assignments in the final image
def remove_atom_indices(mol):
for a in mol.GetAtoms():
a.SetAtomMapNum(0)
remove_atom_indices(mx) # remove atom indicies, to keep them from being displayed - can this be passed as an arg?
highlight = [96,89,113] # locations of atoms I wish to highlight, fetched from indicies which are now removed
drawer = rdMolDraw2D.MolDraw2DSVG(500,500) # I want to actually see this with eyeballs
# mx=Chem.RemoveHs(mx) #this does not work - assuming it rewrtires the indicies and is now incompatable when they are removed
drawer.DrawMolecule(mx,highlightAtoms=highlight)
drawer.FinishDrawing()
svg = drawer.GetDrawingText().replace('svg:','')
SVG(svg)
我可以在以下条件下获取并生成图像文件:
如果能够满足以下条件之一,则解决方案将非常好:
抱歉,如果我没有正确理解你的问题,但是如果氢是隐式的,你不需要直接修改mol对象来阻止它们显示。您可以使用RDKit手册中的这段代码:https://rdkit.org/docs/Cookbook.html#without-implicit-hydrogens
至于隐藏原子索引,您可以像这样修改
drawOptions
:http://rdkit.blogspot.com/2020/04/new-drawing-options-in-202003-release.html#Atom-and-bond-indices这里有一个关于RDKit如何处理氢的更多信息的线程:https://sourceforge.net/p/rdkit/mailman/message/36699970/
相关问题 更多 >
编程相关推荐