OEDrawSVGToggleTextΒΆ

Attention

PRELIMINARY-IMAGE This is a preliminary API until 2018.Feb and may be improved based on user feedback. It is currently available in C++ and Python.

bool OEDrawSVGToggleText(OE2DMolDisplay &disp, const OE2DAtomDisplay *adisp,
                        const std::string &text, const OEFont &font)

bool OEDrawSVGToggleText(OE2DMolDisplay &disp, const OE2DBondDisplay *bdisp,
                        const std::string &text, const OEFont &font)

Creates and interactive effect in .svg images. The given text will appear / disappear when clicking at the position defined by the given atom / bond display.

Note

This functionality is only available for .svg image format. In other image formats the given text will be rendered to the given position permanently.

The generated svg image should be included into and HTML page with the SVG MIME type.

<object data="<imagename>.svg" type="image/svg+xml"></object>
disp
The OE2DMolDisplay object that holds the data necessary to depict the molecule with which it is initialized.
adisp
The OE2DAtomDisplay object that defines where the text will appear.
bdisp
The OE2DBondDisplay object that defines where the text will appear.
text
The text that appears/disappears on mouse clicks.
font
The graphical properties of the font used to draw the text.
#!/usr/bin/env python
from openeye.oechem import *
from openeye.oedepict import *

width, height = 400, 200
image = OEImage(width, height)

mol = OEGraphMol()
smiles = "Cc1cccnc1/C=C/[C@H](C(=O)O)O"
OESmilesToMol(mol, smiles)
OEPrepareDepiction(mol)

opts = OE2DMolDisplayOptions(width, height, OEScale_AutoScale)
opts.SetMargins(10)
disp = OE2DMolDisplay(mol, opts)

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

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

OERenderMolecule("ToggleAtomText.svg", disp)

Download code

ToggleAtomText.py

click on any atoms

Example of using the OEDrawSVGToggleText function for atom positions

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

width, height = 400, 200
image = OEImage(width, height)

mol = OEGraphMol()
smiles = "Cc1cccnc1/C=C/[C@H](C(=O)O)O"
OESmilesToMol(mol, smiles)
OEPrepareDepiction(mol)

opts = OE2DMolDisplayOptions(width, height, OEScale_AutoScale)
opts.SetMargins(10)
disp = OE2DMolDisplay(mol, opts)

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

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

OERenderMolecule("ToggleBondText.svg", disp)

Download code

ToggleBondText.py

click on the middle of any bonds

Example of using the OEDrawSVGToggleText function for bond positions

See also