I am trying to highlight carbon positions in a test molecule while hiding the implicit hydrogens. This is unexpectedly complicated, as I have two compounding problems which each have a solution, but are incompatible.
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)
I can get generate image files under the following conditions:
- I do not provide a highlight atoms list - which is a non-starter here, that is the main point.
- I do not hide the implicit hydrogens - which is "fine...I guess" except that in large structures, this creates a massive and unreadable scaffold.
A solution would be great if it allowed for one of the following:
- Simply not render the 1H in the structure, but retain their presence in the mol file (for indexing)
- Render the image without displaying the atom map numbers - cannot find how to do this without removing them.