Depicting a Molecule with Various Styles

Problem

You want to depict a molecule with various styles.

Table 1. Gallery of molecule depictions using different styles (click on any image below)
../_images/depiction-default.png ../_images/depiction-aromatic-style.png ../_images/depiction-atom-color-style.png ../_images/depiction-super-atom-style.png
../_images/depiction-atom-stereo-style.png ../_images/depiction-bond-stereo-style.png ../_images/depiction-title.png ../_images/depiction-border.png
../_images/depiction-atom-idx.png ../_images/depiction-bond-idx.png ../_images/depiction-atom-prop.png ../_images/depiction-bond-prop.png

The examples below generate interactive .svg images These svg images should be included into and HTML page with the SVG MIME type.

<object data="<imagename>.svg" type="image/svg+xml"></object>
Table 2. Gallery of interactive molecule depictions in SVG (click on any image below)
../_images/depiction-hover-atom.png ../_images/depiction-hover-bond.png ../_images/depiction-toggle-atom.png ../_images/depiction-toggle-bond.png

Ingredients

Difficulty Level

../_images/chilly1.png

Solution

Default

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule("depiction-default.png", disp)

Download code

depiction-default.py

../_images/depiction-default1.png

See also

Aromaticity Style

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetAromaticStyle(oedepict.OEAromaticStyle_Circle)
disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule("depiction-aromatic-style.png", disp)
../_images/depiction-aromatic-style1.png

Atom Color Style

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_BlackCPK)
disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule("depiction-atom-color-style.png", disp)
../_images/depiction-atom-color-style1.png

Super Atom Style

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetSuperAtomStyle(oedepict.OESuperAtomStyle_All)
disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule("depiction-super-atom-style.png", disp)
../_images/depiction-super-atom-style1.png

Atom Stereo Style

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
stereostyle = oedepict.OEAtomStereoStyle_Display_All
stereostyle |= oedepict.OEAtomStereoStyle_HashWedgeStyle_Standard
opts.SetAtomStereoStyle(stereostyle)
disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule("depiction-atom-stereo-style.png", disp)
../_images/depiction-atom-stereo-style1.png

Bond Stereo Style

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetBondStereoStyle(oedepict.OEBondStereoStyle_Display_All)
disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule("depiction-bond-stereo-style.png", disp)
../_images/depiction-bond-stereo-style1.png

Title Style

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetTitleLocation(oedepict.OETitleLocation_Bottom)

fonttype = oedepict.OEFontFamily_Default
fontstyle = oedepict.OEFontStyle_Bold | oedepict.OEFontStyle_Italic
fontalign = oedepict.OEAlignment_Center
fontsize = 10
font = oedepict.OEFont(fonttype, fontstyle, fontsize, fontalign, oechem.OERoyalBlue)
opts.SetTitleFont(font)

disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule("depiction-title.png", disp)

Download code

depiction-title.py

../_images/depiction-title1.png

Border Style

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
disp = oedepict.OE2DMolDisplay(mol, opts)

layer = disp.GetLayer(oedepict.OELayerPosition_Below)
lightred = oechem.OEColor(255, 235, 235)  # R, G, B
mediumred = oechem.OEColor(225, 55, 55)   # R, G, B
linewidth = 6.0
pen = oedepict.OEPen(lightred, mediumred, oedepict.OEFill_On, linewidth)
cornersize = 30
oedepict.OEDrawCurvedBorder(layer, pen, cornersize)

oedepict.OERenderMolecule("depiction-border.png", disp)

Download code

depiction-border.py

../_images/depiction-border1.png

See also

Display Atom Index

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx())
disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule("depiction-atom-idx.png", disp)

Download code

depiction-atom-idx.py

../_images/depiction-atom-idx1.png

Display Bond Index

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetBondPropertyFunctor(oedepict.OEDisplayBondIdx())
disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule("depiction-bond-idx.png", disp)

Download code

depiction-bond-idx.py

../_images/depiction-atom-idx1.png

Display Atom Property

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict


class LabelAtomTopology(oedepict.OEDisplayAtomPropBase):
    def __init__(self):
        oedepict.OEDisplayAtomPropBase.__init__(self)

    def __call__(self, atom):
        if atom.IsInRing():
            return "R"
        return "C"

    def CreateCopy(self):
        copy = LabelAtomTopology()
        return copy.__disown__()


mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)

opts.SetAtomPropertyFunctor(LabelAtomTopology())

fonttype = oedepict.OEFontFamily_Default
fontstyle = oedepict.OEFontStyle_Bold
fontalign = oedepict.OEAlignment_Center
fontsize = 10
font = oedepict.OEFont(fonttype, fontstyle, fontsize, fontalign, oechem.OEDarkRed)
opts.SetAtomPropLabelFont(font)

disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule("depiction-atom-prop.png", disp)

Download code

depiction-atom-prop.py

../_images/depiction-atom-prop1.png

Display Bond Property

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict


class LabelBondTopology(oedepict.OEDisplayBondPropBase):
    def __init__(self):
        oedepict.OEDisplayBondPropBase.__init__(self)

    def __call__(self, bond):
        if bond.IsAromatic():
            return "a"
        return ""

    def CreateCopy(self):
        copy = LabelBondTopology()
        return copy.__disown__()


mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)

opts.SetBondPropertyFunctor(LabelBondTopology())

fonttype = oedepict.OEFontFamily_Default
fontstyle = oedepict.OEFontStyle_Bold
fontalign = oedepict.OEAlignment_Center
fontsize = 10
font = oedepict.OEFont(fonttype, fontstyle, fontsize, fontalign, oechem.OEDarkBlue)
opts.SetBondPropLabelFont(font)

disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule("depiction-bond-prop.png", disp)

Download code

depiction-bond-prop.py

../_images/depiction-bond-prop1.png

Hover Atom Property

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetMargins(7.5)
disp = oedepict.OE2DMolDisplay(mol, opts)

family = oedepict.OEFontFamily_Default
fstyle = oedepict.OEFontStyle_Default
font = oedepict.OEFont(family, fstyle, 12, oedepict.OEAlignment_Center, oechem.OEDarkRed)

for adisp in disp.GetAtomDisplays():
    atom = adisp.GetAtom()
    hovertext = "atom idx=%s" % atom.GetIdx()
    oedepict.OEDrawSVGHoverText(disp, adisp, hovertext, font)

oedepict.OERenderMolecule("depiction-hover-atom.svg", disp)

Download code

depiction-hover-atom.py

hover over any atoms

../_images/depiction-hover-atom.svg

See also

Hover Bond Property

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetMargins(7.5)
disp = oedepict.OE2DMolDisplay(mol, opts)

family = oedepict.OEFontFamily_Default
fstyle = oedepict.OEFontStyle_Default
font = oedepict.OEFont(family, fstyle, 12, oedepict.OEAlignment_Center, oechem.OEDarkRed)

for bdisp in disp.GetBondDisplays():
    bond = bdisp.GetBond()
    hovertext = "bond idx=%s" % bond.GetIdx()
    oedepict.OEDrawSVGHoverText(disp, bdisp, hovertext, font)

oedepict.OERenderMolecule("depiction-hover-bond.svg", disp)

Download code

depiction-hover-bond.py

hover over the middle of any bonds

../_images/depiction-hover-bond.svg

See also

Toggle Atom Property

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetMargins(7.5)
disp = oedepict.OE2DMolDisplay(mol, opts)

family = oedepict.OEFontFamily_Default
fstyle = oedepict.OEFontStyle_Default
font = oedepict.OEFont(family, fstyle, 12, oedepict.OEAlignment_Center, oechem.OEDarkRed)

for adisp in disp.GetAtomDisplays():
    atom = adisp.GetAtom()
    toggletext = "atom idx=%s" % atom.GetIdx()
    oedepict.OEDrawSVGToggleText(disp, adisp, toggletext, font)

oedepict.OERenderMolecule("depiction-toggle-atom.svg", disp)

Download code

depiction-toggle-atom.py

click on any atoms

../_images/depiction-toggle-atom.svg

See also

Toggle Bond Property

#!/usr/bin/env python3
from openeye import oechem
from openeye import oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C/C=C\C1CCc2cc[nH]c2[C@@H]1C(=O)O molecule")
oedepict.OEPrepareDepiction(mol)

width, height, scale = 300, 200, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetMargins(7.5)
disp = oedepict.OE2DMolDisplay(mol, opts)

family = oedepict.OEFontFamily_Default
fstyle = oedepict.OEFontStyle_Default
font = oedepict.OEFont(family, fstyle, 12, oedepict.OEAlignment_Center, oechem.OEDarkRed)

for bdisp in disp.GetBondDisplays():
    bond = bdisp.GetBond()
    toggletext = "bond idx=%s" % bond.GetIdx()
    oedepict.OEDrawSVGToggleText(disp, bdisp, toggletext, font)

oedepict.OERenderMolecule("depiction-toggle-bond.svg", disp)

Download code

depiction-toggle-bond.py

click on middle of any bonds

../_images/depiction-toggle-bond.svg

See also

See also in OEChem TK manual

API

See also in OEDepict TK manual

Theory

API