Depicting 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 an 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

🌶️

Solution

Default

"""Code snippet for customizing style of molecule depiction."""

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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)

Download code

depiction-default.py

../_images/depiction-default.png

See also

Aromaticity Style

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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)
../_images/depiction-aromatic-style.png

Atom Color Style

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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)
../_images/depiction-atom-color-style.png

Super Atom Style

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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)
../_images/depiction-super-atom-style.png

Atom Stereo Style

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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)
stereo_style = oedepict.OEAtomStereoStyle_Display_All
stereo_style |= oedepict.OEAtomStereoStyle_HashWedgeStyle_Standard
opts.SetAtomStereoStyle(stereo_style)
disp = oedepict.OE2DMolDisplay(mol, opts)
../_images/depiction-atom-stereo-style.png

Bond Stereo Style

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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)
../_images/depiction-bond-stereo-style.png

Title Style

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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)

font_type = oedepict.OEFontFamily_Default
font_style = oedepict.OEFontStyle_Bold | oedepict.OEFontStyle_Italic
font_align = oedepict.OEAlignment_Center
font_size = 10
font = oedepict.OEFont(font_type, font_style, font_size, font_align, oechem.OERoyalBlue)
opts.SetTitleFont(font)

disp = oedepict.OE2DMolDisplay(mol, opts)

Download code

depiction-title.py

../_images/depiction-title.png

Border Style

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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)

Download code

depiction-border.py

../_images/depiction-border.png

See also

Display Atom Index

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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)

Download code

depiction-atom-idx.py

../_images/depiction-atom-idx.png

Display Bond Index

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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)

Download code

depiction-bond-idx.py

../_images/depiction-atom-idx.png

Display Atom Property

from openeye import oechem, oedepict


class LabelAtomTopology(oedepict.OEDisplayAtomPropBase):
    """Functor to assign labels to displayed atoms."""

    def __init__(self) -> None:
        """Initialize functor."""
        oedepict.OEDisplayAtomPropBase.__init__(self)

    def __call__(self, atom: oechem.OEAtomBase) -> str:
        """Assign label."""
        if atom.IsInRing():
            return "R"
        return "C"

    def CreateCopy(self):  # noqa: ANN201, N802
        """Copy constructor."""
        copy = LabelAtomTopology()
        return copy.__disown__()


mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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())

font_type = oedepict.OEFontFamily_Default
font_style = oedepict.OEFontStyle_Bold
font_align = oedepict.OEAlignment_Center

Download code

depiction-atom-prop.py

../_images/depiction-atom-prop.png

Display Bond Property

from openeye import oechem, oedepict


class LabelBondTopology(oedepict.OEDisplayBondPropBase):
    """Functor to assign labels to displayed bonds."""

    def __init__(self) -> None:
        """Initialize functor."""
        oedepict.OEDisplayBondPropBase.__init__(self)

    def __call__(self, bond: oechem.OEBondBase) -> str:
        """Assign label."""
        if bond.IsAromatic():
            return "a"
        return ""

    def CreateCopy(self):  # noqa: ANN201, N802
        """Copy constructor."""
        copy = LabelBondTopology()
        return copy.__disown__()


mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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())

font_type = oedepict.OEFontFamily_Default
font_style = oedepict.OEFontStyle_Bold
font_align = oedepict.OEAlignment_Center

Download code

depiction-bond-prop.py

../_images/depiction-bond-prop.png

Hover Atom Property

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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
font_style = oedepict.OEFontStyle_Default
font = oedepict.OEFont(
    family, font_style, 12, oedepict.OEAlignment_Center, oechem.OEDarkRed
)

for atom_disp in disp.GetAtomDisplays():
    atom = atom_disp.GetAtom()
    hover_text = f"atom idx={atom.GetIdx()}"

Download code

depiction-hover-atom.py

hover over any atoms

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

See also

Hover Bond Property

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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 bond_disp in disp.GetBondDisplays():
    bond = bond_disp.GetBond()
    hover_text = f"bond idx={bond.GetIdx()}"

Download code

depiction-hover-bond.py

hover over the middle of any bonds

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

See also

Toggle Atom Property

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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 atom_disp in disp.GetAtomDisplays():
    atom = atom_disp.GetAtom()
    toggle_text = f"atom idx={atom.GetIdx()}"

Download code

depiction-toggle-atom.py

click on any atoms

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

See also

Toggle Bond Property

from openeye import oechem, oedepict

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, r"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
font_style = oedepict.OEFontStyle_Default
font = oedepict.OEFont(
    family, font_style, 12, oedepict.OEAlignment_Center, oechem.OEDarkRed
)

for bond_disp in disp.GetBondDisplays():
    bond = bond_disp.GetBond()
    toggle_text = f"bond idx={bond.GetIdx()}"

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