我试图突出碳在测试分子中的位置,同时隐藏隐含的氢。这是出乎意料的复杂,因为我有两个复杂的问题,每个问题都有一个解决办法,但不相容。
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)我可以在以下条件下生成图像文件:
如果允许下列之一的话,解决方案将是很好的:
发布于 2021-01-19 21:51:28
对不起,如果我没有正确理解你的问题,但是如果氢是隐含的,你不需要直接修改摩尔对象来阻止它们的显示。您可以使用RDKit Cookbook:https://rdkit.org/docs/Cookbook.html#without-implicit-hydrogens中的代码片段
for atom in m.GetAtoms():
atom.SetProp("atomLabel", atom.GetSymbol())至于隐藏原子索引,您只需修改drawOptions如下:http://rdkit.blogspot.com/2020/04/new-drawing-options-in-202003-release.html#Atom-and-bond-indices
drawer.drawOptions().addAtomIndices = False这里有一个关于RDKit如何处理氢的更多信息:https://sourceforge.net/p/rdkit/mailman/message/36699970/
https://stackoverflow.com/questions/63676279
复制相似问题