Substructure matching in RdKit generally highlights the matched component in red color over the original molecule. The code for achieving the same is as follows.

# MWE for a Jupyter notebook: 
from rdkit import Chem
from rdkit.Chem.Draw import IPythonConsole
from rdkit.Chem.Draw import rdDepictor

IPythonConsole.molSize = (250,200)
from rdkit.Chem import AllChem

# additional import:
from rdkit.Chem import Draw

# ----
smi = 'CCC1NC(=O)C(C(O)C(C)CCCC(=O)OC)N(C)C(=O)C(C(C)C)N(C)C(=O)C(CC(C)C)N(C)C(=O)C(CC(C)C)N(C)C(=O)C(C)NC(=O)C(C)NC(=O)C(CC(C)C)N(C)C(=O)C(C(C)C)NC(=O)C(CC(C)C)N(C)C(=O)CN(C)C1=O'
core = Chem.MolFromSmiles('C1C(=O)NCC(=O)NCC(=O)NCC(=O)NCC(=O)NCC(=O)NCC(=O)NCC(=O)NCC(=O)NCC(=O)NCC(=O)N1')

newm = Chem.MolFromSmiles(smi)


Source of the code

Here, if we want to highlight different heteroatoms (like N and O) with different colors, what would be the best way??


For clarification purposes. The requirement is to change the color of the highlight and not the color of the font of the atoms.

  • 3
    $\begingroup$ For future reference: Please enclose snippets of code by three grave characters. Not only will code be visible as such, without unwanted line breaks applied to normal text, there will be (language specific) syntax highlighting, too. And it would be better to present a self-sufficient minimal working example (MWE), like e.g. in posts on tex.se. $\endgroup$
    – Buttonwood
    Nov 30 '21 at 12:27
  • $\begingroup$ chemistry.stackexchange.com/questions/160056/… $\endgroup$
    – user119527
    Dec 4 '21 at 11:42

If you scale the visual representation of the molecule, i.e. replace the current definition of the image by

IPythonConsole.molSize = (400,400)

instead of (250,250), you see that the Dreiding-model like colour scheme is applied as anticipated (oxygen red, nitrogen blue, etc.):

enter image description here

It might be a little bit difficult to discern from the rosé transparent highlight (especially for oxygen) since the «core structure» you defined runs all around the cyclic peptide.

  • $\begingroup$ In addition, you can also change the color of the highlight: IPythonConsole.drawOptions.setHighlightColour((0.8,0.8,0.8)) $\endgroup$
    – rapelpy
    Nov 30 '21 at 17:22
  • $\begingroup$ Thanks. I am able to see that the atoms font color have changed. But the overlying red color is still the same. Is it possible to give varying color of highlight based on atom??? $\endgroup$ Nov 30 '21 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.