Depicting a Molecule with Various Styles updated

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

Note

Examples in Table 1 require OpenEye toolkits version 2015.Feb or later.

Examples in Table 2 require OpenEye toolkits version 2017.Jun or later.

Difficulty Level

../_images/chilly1.png

Solution

Default

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

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

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

Download code

depiction-default.py

../_images/depiction-default1.png

See also

Aromaticity Style

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

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

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

Atom Color Style

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

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

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

Super Atom Style

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

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

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

Atom Stereo Style

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

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

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

Bond Stereo Style

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

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

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

Title Style

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


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

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

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

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

Download code

depiction-title.py

../_images/depiction-title1.png

Border Style

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

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

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

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

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.oechem import *
from openeye.oedepict import *

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

width, height = 300, 200
opts = OE2DMolDisplayOptions(width, height, OEScale_AutoScale)
opts.SetAtomPropertyFunctor(OEDisplayAtomIdx())
disp = OE2DMolDisplay(mol, opts)
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.oechem import *
from openeye.oedepict import *

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

width, height = 300, 200
opts = OE2DMolDisplayOptions(width, height, OEScale_AutoScale)
opts.SetBondPropertyFunctor(OEDisplayBondIdx())
disp = OE2DMolDisplay(mol, opts)
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.oechem import *
from openeye.oedepict import *


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

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

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


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

width, height = 300, 200
opts = OE2DMolDisplayOptions(width, height, OEScale_AutoScale)

opts.SetAtomPropertyFunctor(LabelAtomTopology())

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

disp = OE2DMolDisplay(mol, opts)
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.oechem import *
from openeye.oedepict import *


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

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

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


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

width, height = 300, 200
opts = OE2DMolDisplayOptions(width, height, OEScale_AutoScale)

opts.SetBondPropertyFunctor(LabelBondTopology())

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

disp = OE2DMolDisplay(mol, opts)
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.oechem import *
from openeye.oedepict import *

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

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

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

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

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.oechem import *
from openeye.oedepict import *

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

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

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

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

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.oechem import *
from openeye.oedepict import *

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

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

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

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

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.oechem import *
from openeye.oedepict import *

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

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

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

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

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 Manual

API

See Also in OEDepict Manual

Theory

API