我试图突出测试分子中的碳位置,同时隐藏隐含的氢。这出乎意料地复杂,因为我有两个复合问题,每个问题都有解决方案,但不兼容。
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)
我可以在以下条件下生成图像文件:
- 我没有提供突出显示的原子列表 - 这在这里不是首发,这是重点。
- 我没有隐藏隐含的氢——这“很好……我猜”,除了在大型结构中,这会创建一个巨大且不可读的支架。
如果它允许以下之一,则解决方案会很棒:
- 简单地不在结构中渲染 1H,而是在 mol 文件中保留它们的存在(用于索引)
- 在不显示原子图编号的情况下渲染图像- 如果不删除它们,找不到如何执行此操作。