Appendix: Additional Examples in Python

These are full listings of programming examples that are excerpted or offered for download, elsewhere in this book. See a full list of examples in this chapter.

Listing 1: Full listing of ActiveSiteHighlight.py.

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

import sys
from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme

###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE OEGRAPHEME DOCUMENTATION
###############################################################


class Pred6MemAromAtom(oechem.OEUnaryAtomPred):
    def __call__(self, atom):
        return atom.IsAromatic() and oechem.OEAtomIsInAromaticRingSize(atom, 6)


class Pred6MemAromBond(oechem.OEUnaryBondPred):
    def __call__(self, bond):
        return bond.IsAromatic() and oechem.OEBondIsInAromaticRingSize(bond, 6)


def OEAddHighlighting_Predicate(adisp):
    highlight = oedepict.OEHighlightByBallAndStick(oechem.OEBlueTint)
    oegrapheme.OEAddLigandHighlighting(adisp, highlight, Pred6MemAromAtom())
    oegrapheme.OEAddLigandHighlighting(adisp, highlight, Pred6MemAromBond())


def OEAddHighlighting_AtomAndBondPredicate(adisp):
    highlight = oedepict.OEHighlightByColor(oechem.OEDarkGreen)
    oegrapheme.OEAddLigandHighlighting(adisp, highlight, Pred6MemAromAtom(), Pred6MemAromBond())


def OEAddHighlighting_OEMatch(adisp):
    ligand = adisp.GetDisplayedLigand()
    subs = oechem.OESubSearch("a1aaaaa1")
    colors = oechem.OEGetVividColors()
    unique = True
    for match, color in zip(subs.Match(ligand, unique), colors):
        highlight = oedepict.OEHighlightByLasso(color)
        highlight.SetConsiderAtomLabelBoundingBox(True)
        oegrapheme.OEAddLigandHighlighting(adisp, highlight, match)


def OEAddHighlighting_OEAtomBondSet(adisp):
    ligand = adisp.GetDisplayedLigand()
    highlight = oedepict.OEHighlightByCogwheel(oechem.OEPinkTint)
    highlight.SetInnerContour(False)
    abset = oechem.OEAtomBondSet(ligand.GetAtoms(Pred6MemAromAtom()),
                                 ligand.GetBonds(Pred6MemAromBond()))

    oegrapheme.OEAddLigandHighlighting(adisp, highlight, abset)


def OEAddHighlighting_OEResidue(adisp):
    for res, color in zip(adisp.GetDisplayedResidues(), oechem.OEGetLightColors()):
        pen = oedepict.OEPen(color, color, oedepict.OEFill_On, 1.0)
        oegrapheme.OEAddResidueHighlighting(adisp, pen, res)


def ImportMolecule(filename):
    ifs = oechem.oemolistream()
    if not ifs.open(filename):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % filename)

    mol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, mol):
        oechem.OEThrow.Fatal("Unable to read molecule in %s" % filename)

    return mol


########################################################################
#
########################################################################

if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <receptor> <ligand>" % sys.argv[0])

receptor = ImportMolecule(sys.argv[1])
ligand = ImportMolecule(sys.argv[2])

asite = oechem.OEInteractionHintContainer(receptor, ligand)
asite.SetTitle(ligand.GetTitle())
oechem.OEPerceiveInteractionHints(asite)
oegrapheme.OEPrepareActiveSiteDepiction(asite)

opts = oegrapheme.OE2DActiveSiteDisplayOptions(600, 400)
adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
OEAddHighlighting_Predicate(adisp)

oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-Predicate.png", adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-Predicate.pdf", adisp)

adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
OEAddHighlighting_AtomAndBondPredicate(adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-AtomAndBondPredicate.png", adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-AtomAndBondPredicate.pdf", adisp)

adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
OEAddHighlighting_OEMatch(adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-OEMatch.png", adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-OEMatch.pdf", adisp)

adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
OEAddHighlighting_OEAtomBondSet(adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-OEAtomBondSet.png", adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-OEAtomBondSet.pdf", adisp)

adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
OEAddHighlighting_OEResidue(adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-OEResidue.png", adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-OEResidue.pdf", adisp)

Listing 2: Example of using a built-in atom annotation style

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc(N)cc(S(=O)(=O)O)c1")
oechem.OEAssignHybridization(mol)
oedepict.OEPrepareDepiction(mol)

opts = oedepict.OE2DMolDisplayOptions(350, 250, oedepict.OEScale_AutoScale)
opts.SetTitleLocation(oedepict.OETitleLocation_Hidden)
disp = oedepict.OE2DMolDisplay(mol, opts)

sp2pen = oedepict.OEPen(oechem.OEWhite, oechem.OEBlueTint, oedepict.OEFill_Off, 1.5)
glyphSP2 = oegrapheme.OEAtomGlyphCircle(sp2pen, oegrapheme.OECircleStyle_Sun, 1.2)
oegrapheme.OEAddGlyph(disp, glyphSP2, oechem.OEIsAtomHybridization(oechem.OEHybridization_sp2))

sp3pen = oedepict.OEPen(oechem.OEWhite, oechem.OEPinkTint, oedepict.OEFill_Off, 1.5)
glyphSP3 = oegrapheme.OEAtomGlyphCircle(sp3pen, oegrapheme.OECircleStyle_Eyelash, 1.2)
oegrapheme.OEAddGlyph(disp, glyphSP3, oechem.OEIsAtomHybridization(oechem.OEHybridization_sp3))

oedepict.OERenderMolecule("AnnotateAtomPredicate.png", disp)
oedepict.OERenderMolecule("AnnotateAtomPredicate.pdf", disp)

Listing 3: Example of using a built-in bond annotation style

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc(NCC)cc(CS(=O)(=O)O)c1")
oedepict.OEPrepareDepiction(mol)

opts = oedepict.OE2DMolDisplayOptions(400, 250, oedepict.OEScale_AutoScale)
opts.SetTitleLocation(oedepict.OETitleLocation_Hidden)
disp = oedepict.OE2DMolDisplay(mol, opts)

pen = oedepict.OEPen(oechem.OEDarkPurple, oechem.OEDarkPurple, oedepict.OEFill_Off, 2.0)
glyph = oegrapheme.OEBondGlyphArrow(pen, 0.5)
oegrapheme.OEAddGlyph(disp, glyph, oechem.OEIsRotor())

oedepict.OERenderMolecule("AnnotateBondPredicate.png", disp)
oedepict.OERenderMolecule("AnnotateBondPredicate.pdf", disp)

Listing 4: Example of user-defined annotation

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme


class ColorCharge(oegrapheme.OEAtomGlyphBase):
    def __init__(self, cg):
        oegrapheme.OEAtomGlyphBase.__init__(self)
        self.colorg = cg

    def RenderGlyph(self, disp, atom):
        adisp = disp.GetAtomDisplay(atom)
        if adisp is None or not adisp.IsVisible():
            return False

        charge = atom.GetPartialCharge()
        if charge == 0.0:
            return True
        color = self.colorg.GetColorAt(charge)

        pen = oedepict.OEPen()
        pen.SetForeColor(oechem.OEColor(color))
        color.SetA(100)
        pen.SetBackColor(oechem.OEColor(color))
        pen.SetFill(oedepict.OEFill_On)
        radius = disp.GetScale() / 2.5

        layer = disp.GetLayer(oedepict.OELayerPosition_Below)
        oegrapheme.OEDrawCircle(layer, oegrapheme.OECircleStyle_Simpson,
                                adisp.GetCoords(), radius, pen)

        return True

    def CreateCopy(self):
        return ColorCharge(self.colorg).__disown__()


mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "Cc1cc(cc(c1[N+](=O)[O-])F)[N+]#C")
oechem.OEMMFFAtomTypes(mol)
oechem.OEMMFF94PartialCharges(mol)

oedepict.OEPrepareDepiction(mol)

opts = oedepict.OE2DMolDisplayOptions(350, 250, oedepict.OEScale_AutoScale)
opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome)
opts.SetTitleLocation(oedepict.OETitleLocation_Hidden)
disp = oedepict.OE2DMolDisplay(mol, opts)

coloranion = oechem.OEColorStop(-1.0, oechem.OEColor(oechem.OEDarkRed))
colorcation = oechem.OEColorStop(+1.0, oechem.OEColor(oechem.OEDarkBlue))
colorg = oechem.OELinearColorGradient(coloranion, colorcation)
colorg.AddStop(oechem.OEColorStop(0.0, oechem.OEColor(oechem.OEWhite)))

colorcharge = ColorCharge(colorg)

oegrapheme.OEAddGlyph(disp, colorcharge, oechem.OEIsTrueAtom())

oedepict.OERenderMolecule("AnnotatePartialCharge.png", disp)
oedepict.OERenderMolecule("AnnotatePartialCharge.pdf", disp)

Listing 5: Full listing of bfactor2img.py.

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

#############################################################################
# Depicts the BFactor of a ligand and its environment
#############################################################################

import sys
from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme


def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oedepict.OEConfigureImageWidth(itf, 600.0)
    oedepict.OEConfigureImageHeight(itf, 600.0)
    oedepict.OEConfigure2DMolDisplayOptions(itf, oedepict.OE2DMolDisplaySetup_AromaticStyle)
    oechem.OEConfigureSplitMolComplexOptions(itf, oechem.OESplitMolComplexSetup_LigName)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    iname = itf.GetString("-complex")
    oname = itf.GetString("-out")

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    ext = oechem.OEGetFileExtension(oname)
    if not oedepict.OEIsRegisteredImageFile(ext):
        oechem.OEThrow.Fatal("Unknown image type!")

    ofs = oechem.oeofstream()
    if not ofs.open(oname):
        oechem.OEThrow.Fatal("Cannot open output file!")

    complexmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, complexmol):
        oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname)

    if not oechem.OEHasResidues(complexmol):
        oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All)

    # Separate ligand and protein

    sopts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(sopts, itf)

    ligand = oechem.OEGraphMol()
    protein = oechem.OEGraphMol()
    water = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts)

    if ligand.NumAtoms() == 0:
        oechem.OEThrow.Fatal("Cannot separate complex!")

    # Calculate average BFactor of the whole complex

    avgbfactor = GetAverageBFactor(complexmol)

    # Calculate minimum and maximum BFactor of the ligand and its environment

    minbfactor, maxbfactor = GetMinAndMaxBFactor(ligand, protein)

    # Attach to each ligand atom the average BFactor of the nearby protein atoms

    stag = "avg residue BFfactor"
    itag = oechem.OEGetTag(stag)
    SetAverageBFactorOfNearbyProteinAtoms(ligand, protein, itag)

    oechem.OEThrow.Info("Average BFactor of the complex = %+.3f" % avgbfactor)
    oechem.OEThrow.Info("Minimum BFactor of the ligand and its environment = %+.3f" % minbfactor)
    oechem.OEThrow.Info("Maximum BFactor of the ligand and its environment = %+.3f" % maxbfactor)

    # Create image

    imagewidth, imageheight = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(itf)
    image = oedepict.OEImage(imagewidth, imageheight)

    mframe = oedepict.OEImageFrame(image, imagewidth,
                                   imageheight * 0.90, oedepict.OE2DPoint(0.0, 0.0))
    lframe = oedepict.OEImageFrame(image, imagewidth, imageheight * 0.10,
                                   oedepict.OE2DPoint(0.0, imageheight * 0.90))

    opts = oedepict.OE2DMolDisplayOptions(mframe.GetWidth(), mframe.GetHeight(),
                                          oedepict.OEScale_AutoScale)
    oedepict.OESetup2DMolDisplayOptions(opts, itf)
    opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome)

    # Create BFactor color gradient

    colorg = oechem.OELinearColorGradient()
    colorg.AddStop(oechem.OEColorStop(0.0, oechem.OEDarkBlue))
    colorg.AddStop(oechem.OEColorStop(10.0, oechem.OELightBlue))
    colorg.AddStop(oechem.OEColorStop(25.0, oechem.OEYellowTint))
    colorg.AddStop(oechem.OEColorStop(50.0, oechem.OERed))
    colorg.AddStop(oechem.OEColorStop(100.0, oechem.OEDarkRose))

    # Prepare ligand for depiction

    oegrapheme.OEPrepareDepictionFrom3D(ligand)
    arcfxn = BFactorArcFxn(colorg, itag)
    for atom in ligand.GetAtoms():
        oegrapheme.OESetSurfaceArcFxn(ligand, atom, arcfxn)
    opts.SetScale(oegrapheme.OEGetMoleculeSurfaceScale(ligand, opts))

    # Render ligand and visualize BFactor

    disp = oedepict.OE2DMolDisplay(ligand, opts)
    colorbfactor = ColorLigandAtomByBFactor(colorg)
    oegrapheme.OEAddGlyph(disp, colorbfactor, oechem.OEIsTrueAtom())
    oegrapheme.OEDraw2DSurface(disp)
    oedepict.OERenderMolecule(mframe, disp)

    # Draw color gradient

    opts = oegrapheme.OEColorGradientDisplayOptions()
    opts.SetColorStopPrecision(1)
    opts.AddMarkedValue(avgbfactor)
    opts.SetBoxRange(minbfactor, maxbfactor)

    oegrapheme.OEDrawColorGradient(lframe, colorg, opts)

    oedepict.OEWriteImage(oname, image)

    return 0

#############################################################################
#
#############################################################################


def GetAverageBFactor(mol):

    sumbfactor = 0.0
    for atom in mol.GetAtoms():
        res = oechem.OEAtomGetResidue(atom)
        sumbfactor += res.GetBFactor()
    avgbfactor = sumbfactor / mol.NumAtoms()

    return avgbfactor


def ConsiderResidueAtom(atom, res):
    if atom.GetAtomicNum() == oechem.OEElemNo_H:
        return False
    if res.GetName() == "HOH":
        return False
    return True


def GetMinAndMaxBFactor(ligand, protein, maxdistance=4.0):

    minbfactor = float("inf")
    maxbfactor = float("-inf")

    # Ligand atoms
    for latom in ligand.GetAtoms(oechem.OEIsHeavy()):
        res = oechem.OEAtomGetResidue(latom)
        minbfactor = min(minbfactor, res.GetBFactor())
        maxbfactor = max(maxbfactor, res.GetBFactor())

    # Protein atoms close to ligand atoms
    nn = oechem.OENearestNbrs(protein, maxdistance)
    for latom in ligand.GetAtoms(oechem.OEIsHeavy()):
        for neigh in nn.GetNbrs(latom):
            ratom = neigh.GetBgn()
            res = oechem.OEAtomGetResidue(ratom)
            if ConsiderResidueAtom(ratom, res):
                minbfactor = min(minbfactor, res.GetBFactor())
                maxbfactor = max(maxbfactor, res.GetBFactor())

    return minbfactor, maxbfactor


def SetAverageBFactorOfNearbyProteinAtoms(ligand, protein, itag, maxdistance=4.0):

    nn = oechem.OENearestNbrs(protein, maxdistance)
    for latom in ligand.GetAtoms(oechem.OEIsHeavy()):
        sumbfactor = 0.0
        neighs = []
        for neigh in nn.GetNbrs(latom):
            ratom = neigh.GetBgn()
            res = oechem.OEAtomGetResidue(ratom)
            if ConsiderResidueAtom(ratom, res):
                sumbfactor += res.GetBFactor()
                neighs.append(ratom)

        avgbfactor = 0.0
        if len(neighs) > 0:
            avgbfactor = sumbfactor / len(neighs)
        latom.SetDoubleData(itag, avgbfactor)

#############################################################################
#
#############################################################################


class BFactorArcFxn(oegrapheme.OESurfaceArcFxnBase):
    def __init__(self, colorg, itag):
        oegrapheme.OESurfaceArcFxnBase.__init__(self)
        self.colorg = colorg
        self.itag = itag

    def __call__(self, image, arc):
        adisp = arc.GetAtomDisplay()
        if adisp is None or not adisp.IsVisible():
            return False

        atom = adisp.GetAtom()
        if atom is None:
            return False

        avgresiduebfactor = atom.GetDoubleData(self.itag)
        if avgresiduebfactor == 0.0:
            return True
        color = self.colorg.GetColorAt(avgresiduebfactor)

        pen = oedepict.OEPen(color, color, oedepict.OEFill_Off, 5.0)

        center = arc.GetCenter()
        bAngle = arc.GetBgnAngle()
        eAngle = arc.GetEndAngle()
        radius = arc.GetRadius()

        oegrapheme.OEDrawDefaultSurfaceArc(image, center, bAngle, eAngle, radius, pen)

        return True

    def CreateCopy(self):
        return BFactorArcFxn(self.colorg, self.itag).__disown__()

#############################################################################
#
#############################################################################


class ColorLigandAtomByBFactor(oegrapheme.OEAtomGlyphBase):
    def __init__(self, colorg):
        oegrapheme.OEAtomGlyphBase.__init__(self)
        self.colorg = colorg

    def RenderGlyph(self, disp, atom):
        adisp = disp.GetAtomDisplay(atom)
        if adisp is None or not adisp.IsVisible():
            return False

        res = oechem.OEAtomGetResidue(atom)
        bfactor = res.GetBFactor()
        color = self.colorg.GetColorAt(bfactor)

        pen = oedepict.OEPen(color, color, oedepict.OEFill_On, 1.0)
        radius = disp.GetScale() / 3.0

        layer = disp.GetLayer(oedepict.OELayerPosition_Below)
        oegrapheme.OEDrawCircle(layer, oegrapheme.OECircleStyle_Default,
                                adisp.GetCoords(), radius, pen)
        return True

    def CreateCopy(self):
        return ColorLigandAtomByBFactor(self.colorg).__disown__()

#############################################################################
# INTERFACE
#############################################################################


InterfaceData = '''
!BRIEF [-complex] <input> [-out] <output pdf>

!CATEGORY "input/output options :"

  !PARAMETER -complex
    !ALIAS -c
    !TYPE string
    !KEYLESS 1
    !REQUIRED true
    !VISIBILITY simple
    !BRIEF Input filename of the protein complex
  !END

  !PARAMETER -out
    !ALIAS -o
    !TYPE string
    !REQUIRED true
    !KEYLESS 2
    !VISIBILITY simple
    !BRIEF Output filename
  !END

!END
'''

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Listing 6: Full listing of complex2img.py.

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

#############################################################################
# Depicts the interactions of an active site
#############################################################################

import sys
from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme


def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oedepict.OEConfigureImageWidth(itf, 900.0)
    oedepict.OEConfigureImageHeight(itf, 600.0)
    oedepict.OEConfigure2DMolDisplayOptions(itf, oedepict.OE2DMolDisplaySetup_AromaticStyle)
    oechem.OEConfigureSplitMolComplexOptions(itf, oechem.OESplitMolComplexSetup_LigName)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    iname = itf.GetString("-complex")
    oname = itf.GetString("-out")

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    ext = oechem.OEGetFileExtension(oname)
    if not oedepict.OEIsRegisteredImageFile(ext):
        oechem.OEThrow.Fatal("Unknown image type!")

    ofs = oechem.oeofstream()
    if not ofs.open(oname):
        oechem.OEThrow.Fatal("Cannot open output file!")

    complexmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, complexmol):
        oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname)

    if not oechem.OEHasResidues(complexmol):
        oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All)

    # Separate ligand and protein

    sopts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(sopts, itf)

    ligand = oechem.OEGraphMol()
    protein = oechem.OEGraphMol()
    water = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    pfilter = sopts.GetProteinFilter()
    wfilter = sopts.GetWaterFilter()
    sopts.SetProteinFilter(oechem.OEOrRoleSet(pfilter, wfilter))
    sopts.SetWaterFilter(oechem.OEMolComplexFilterFactory(
                         oechem.OEMolComplexFilterCategory_Nothing))

    oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts)

    if ligand.NumAtoms() == 0:
        oechem.OEThrow.Fatal("Cannot separate complex!")

    # Perceive interactions

    asite = oechem.OEInteractionHintContainer(protein, ligand)
    if not asite.IsValid():
        oechem.OEThrow.Fatal("Cannot initialize active site!")
    asite.SetTitle(ligand.GetTitle())

    oechem.OEPerceiveInteractionHints(asite)

    oegrapheme.OEPrepareActiveSiteDepiction(asite)

    # Depict active site with interactions

    width, height = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(itf)
    image = oedepict.OEImage(width, height)

    cframe = oedepict.OEImageFrame(image, width * 0.80, height, oedepict.OE2DPoint(0.0, 0.0))
    lframe = oedepict.OEImageFrame(image, width * 0.20, height,
                                   oedepict.OE2DPoint(width * 0.80, 0.0))

    opts = oegrapheme.OE2DActiveSiteDisplayOptions(cframe.GetWidth(), cframe.GetHeight())
    oedepict.OESetup2DMolDisplayOptions(opts, itf)

    adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
    oegrapheme.OERenderActiveSite(cframe, adisp)

    lopts = oegrapheme.OE2DActiveSiteLegendDisplayOptions(10, 1)
    oegrapheme.OEDrawActiveSiteLegend(lframe, adisp, lopts)

    oedepict.OEWriteImage(oname, image)

    return 0


#############################################################################
# INTERFACE
#############################################################################

InterfaceData = '''
!BRIEF [-complex] <input> [-out] <output image>

!CATEGORY "input/output options :"

  !PARAMETER -complex
    !ALIAS -c
    !TYPE string
    !KEYLESS 1
    !REQUIRED true
    !VISIBILITY simple
    !BRIEF Input filename of the protein complex
  !END

  !PARAMETER -out
    !ALIAS -o
    !TYPE string
    !REQUIRED true
    !KEYLESS 2
    !VISIBILITY simple
    !BRIEF Output filename
  !END

!END
'''

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Listing 7: Depicting partial charges using property map

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme


def SetPartialCharge(mol, tagname):
    oechem.OEMMFFAtomTypes(mol)
    oechem.OEMMFF94PartialCharges(mol)

    tag = oechem.OEGetTag(tagname)
    for atom in mol.GetAtoms():
        atom.SetData(tag, atom.GetPartialCharge())


mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "Cc1cc(cc(c1[N+](=O)[O-])F)[N+]#C")
oedepict.OEPrepareDepiction(mol)

tagname = "PartialCharge"
SetPartialCharge(mol, tagname)

width, height = 450, 350
opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale)
opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome)
opts.SetTitleLocation(oedepict.OETitleLocation_Hidden)
opts.SetScale(oegrapheme.OEGetMoleculeSurfaceScale(mol, opts))
disp = oedepict.OE2DMolDisplay(mol, opts)

propmap = oegrapheme.OE2DPropMap(opts.GetBackgroundColor())
propmap.SetNegativeColor(oechem.OEDarkRed)
propmap.SetPositiveColor(oechem.OEDarkBlue)
propmap.Render(disp, tagname)

oedepict.OERenderMolecule("Draw2DPropMapPartialCharge.png", disp)
oedepict.OERenderMolecule("Draw2DPropMapPartialCharge.pdf", disp)

Listing 8: Example of user-defined surface drawing

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme


class AtomColorArcFxn(oegrapheme.OESurfaceArcFxnBase):
    def __call__(self, image, arc):
        adisp = arc.GetAtomDisplay()
        if adisp is None or not adisp.IsVisible():
            return False

        color = adisp.GetLabelFont().GetColor()
        pen = oedepict.OEPen(color, color, oedepict.OEFill_Off, 1.0)

        center = arc.GetCenter()
        radius = arc.GetRadius()
        bgnAngle = arc.GetBgnAngle()
        endAngle = arc.GetEndAngle()

        oegrapheme.OEDrawEyelashSurfaceArc(image, center, bgnAngle, endAngle, radius, pen)
        return True


def Draw2DSurface(image, mol):

    oedepict.OEPrepareDepiction(mol)

    opts = oedepict.OE2DMolDisplayOptions(image.GetWidth(), image.GetHeight(),
                                          oedepict.OEScale_AutoScale)
    opts.SetTitleLocation(oedepict.OETitleLocation_Hidden)
    opts.SetScale(oegrapheme.OEGetMoleculeSurfaceScale(mol, opts))

    arcfxn = AtomColorArcFxn()
    for atom in mol.GetAtoms():
        oegrapheme.OESetSurfaceArcFxn(mol, atom, arcfxn)

    disp = oedepict.OE2DMolDisplay(mol, opts)
    oegrapheme.OEDraw2DSurface(disp)
    oedepict.OERenderMolecule(image, disp)



mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "OC(=O)c1cnc(c(Cl)c1)-c2ccccc2")

imagewidth, imageheight = 350.0, 250.0
image = oedepict.OEImage(imagewidth, imageheight)
Draw2DSurface(image, mol)

oedepict.OEWriteImage("Draw2DSurfaceUserDefined.png", image)
oedepict.OEWriteImage("Draw2DSurfaceUserDefined.pdf", image)

Listing 9: Example of drawing 2D surface with various radii

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme


def DrawSurfaces(image, mol):

    oechem.OEAssignCovalentRadii(mol)
    minradius = oechem.OEGetCovalentRadius(oechem.OEElemNo_H)

    radiusScales = oechem.OEDoubleVector(mol.GetMaxAtomIdx(), 0.0)
    maxrscale = float("-inf")

    for atom in mol.GetAtoms():
        rscale = (atom.GetRadius() - minradius) + oegrapheme.OESurfaceArcScale_Minimum
        radiusScales[atom.GetIdx()] = rscale
        maxrscale = max(maxrscale, rscale)

    opts = oedepict.OE2DMolDisplayOptions(image.GetWidth(), image.GetHeight(),
                                          oedepict.OEScale_AutoScale)
    opts.SetTitleLocation(oedepict.OETitleLocation_Hidden)
    opts.SetScale(oegrapheme.OEGetMoleculeSurfaceScale(mol, opts, maxrscale))

    disp = oedepict.OE2DMolDisplay(mol, opts)

    layer = disp.GetLayer(oedepict.OELayerPosition_Below)

    penA = oedepict.OEPen(oechem.OELightGrey, oechem.OELightGrey, oedepict.OEFill_Off, 2.0,
                          oedepict.OEStipple_ShortDash)
    arcfxnA = oegrapheme.OEDefaultArcFxn(penA)

    for arc in oegrapheme.OEGet2DSurfaceArcs(disp, oegrapheme.OESurfaceArcScale_Minimum):
        arcfxnA(layer, arc)

    penB = oedepict.OEPen(oechem.OEGrey, oechem.OEGrey, oedepict.OEFill_Off, 2.0)
    arcfxnB = oegrapheme.OEDefaultArcFxn(penB)

    for arc in oegrapheme.OEGet2DSurfaceArcs(disp, radiusScales):
        arcfxnB(layer, arc)

    oedepict.OERenderMolecule(image, disp)


mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc(sc1CCl)Br")
oedepict.OEPrepareDepiction(mol)

imagewidth, imageheight = 300.0, 240.0
image = oedepict.OEImage(imagewidth, imageheight)
DrawSurfaces(image, mol)

oedepict.OEWriteImage("Draw2DSurfaceVariousRadii.png", image)
oedepict.OEWriteImage("Draw2DSurfaceVariousRadii.pdf", image)

Listing 10: Full listing of DrawActiveSiteLegend.py.

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

import sys
from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme

###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE GRAPHEME DOCUMENTATION
###############################################################


def ImportMolecule(filename):

    ifs = oechem.oemolistream()
    if not ifs.open(filename):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % filename)

    mol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, mol):
        oechem.OEThrow.Fatal("Unable to read molecule in %s" % filename)

    return mol


if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <receptor> <ligand>" % sys.argv[0])

receptor = ImportMolecule(sys.argv[1])
ligand = ImportMolecule(sys.argv[2])

asite = oechem.OEInteractionHintContainer(receptor, ligand)
oechem.OEPerceiveInteractionHints(asite)
oegrapheme.OEPrepareActiveSiteDepiction(asite)

adisp = oegrapheme.OE2DActiveSiteDisplay(asite, oegrapheme.OE2DActiveSiteDisplayOptions(400, 400))

# initializing adisp OE2DActiveSiteDisplay object

rows, cols = 2, 4
opts = oegrapheme.OE2DActiveSiteLegendDisplayOptions(rows, cols)

image = oedepict.OEImage(600, 150)
oegrapheme.OEDrawActiveSiteLegend(image, adisp, opts)
oedepict.OEWriteImage("DrawActiveSiteLegend.png", image)
oedepict.OEWriteImage("DrawActiveSiteLegend.pdf", image)

Listing 11: Full listing of DrawColorForceFieldLegend.py.

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oedepict
from openeye import oegrapheme
from openeye import oeshape

###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE GRAPHEME DOCUMENTATION
###############################################################

cff = oeshape.OEColorForceField()
cff.Init(oeshape.OEColorFFType_ImplicitMillsDean)
cffdisp = oegrapheme.OEColorForceFieldDisplay(cff)

rows, cols = 2, 3
opts = oegrapheme.OEColorForceFieldLegendDisplayOptions(rows, cols)

image = oedepict.OEImage(450, 150)
oegrapheme.OEDrawColorForceFieldLegend(image, cffdisp, opts)
oedepict.OEWriteImage("DrawColorForceFieldLegend.png", image)
oedepict.OEWriteImage("DrawColorForceFieldLegend.pdf", image)

Listing 12: Full listing of DrawColorGradient.py.

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme

colorg = oechem.OELinearColorGradient(oechem.OEColorStop(0.0, oechem.OEYellow))
colorg.AddStop(oechem.OEColorStop(+1.0, oechem.OEOrange))
colorg.AddStop(oechem.OEColorStop(-1.0, oechem.OEGreen))

image = oedepict.OEImage(400, 100)
oegrapheme.OEDrawColorGradient(image, colorg)
oedepict.OEWriteImage("DrawColorGradient.png", image)
oedepict.OEWriteImage("DrawColorGradient.pdf", image)

Listing 13: Example of complex surface drawing

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

import sys
from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme


def ImportMolecule(filename):

    ifs = oechem.oemolistream()
    if not ifs.open(filename):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % filename)

    mol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, mol):
        oechem.OEThrow.Fatal("Unable to read molecule in %s" % filename)

    oechem.OEAssignBondiVdWRadii(mol)
    oechem.OESuppressHydrogens(mol)

    return mol


if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <receptor> <ligand>" % sys.argv[0])

receptor = ImportMolecule(sys.argv[1])
ligand = ImportMolecule(sys.argv[2])

oegrapheme.OEAddComplexSurfaceArcs(ligand, receptor)

oegrapheme.OEPrepareDepictionFrom3D(ligand)

width, height = 450, 350
opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale)
opts.SetScale(oegrapheme.OEGetMoleculeSurfaceScale(ligand, opts))

disp = oedepict.OE2DMolDisplay(ligand, opts)
oegrapheme.OEDraw2DSurface(disp)

oedepict.OERenderMolecule("DrawComplexSurface.png", disp)
oedepict.OERenderMolecule("DrawComplexSurface.pdf", disp)

Listing 14:

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

import sys
from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme


def ImportMolecule(filename):

    ifs = oechem.oemolistream()
    if not ifs.open(filename):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % filename)

    mol = oechem.OEGraphMol()
    oechem.OEReadMolecule(ifs, mol)

    oechem.OEAssignBondiVdWRadii(mol)
    oechem.OESuppressHydrogens(mol)

    return mol


def DrawSurfaceArc(image, depth, arc, pen):
    edgeAngle = 5.0
    patternAngle = 5.0
    minPatternWidthRatio = 0.05
    maxPatternWidthRatio = 0.10 * depth
    patternDirection = oegrapheme.OEPatternDirection_Outside
    oegrapheme.OEDrawSunSurfaceArc(image, arc.GetCenter(), arc.GetBgnAngle(), arc.GetEndAngle(),
                                   arc.GetRadius(), pen, edgeAngle,
                                   patternDirection, patternAngle,
                                   minPatternWidthRatio, maxPatternWidthRatio)


class SolventArcFxn(oegrapheme.OESurfaceArcFxnBase):
    def __call__(self, image, arc):
        pen = oedepict.OEPen(oechem.OELightGrey, oechem.OELightGrey)
        pen.SetLineWidth(0.5)
        oegrapheme.OEDrawDefaultSurfaceArc(image, arc.GetCenter(), arc.GetBgnAngle(),
                                           arc.GetEndAngle(), arc.GetRadius(), pen)
        return True


class BuriedArcFxn(oegrapheme.OESurfaceArcFxnBase):
    def __call__(self, image, arc):
        pen = oedepict.OEPen(oechem.OEGrey, oechem.OEGrey)
        pen.SetLineWidth(2.0)
        oegrapheme.OEDrawDefaultSurfaceArc(image, arc.GetCenter(), arc.GetBgnAngle(),
                                           arc.GetEndAngle(), arc.GetRadius(), pen)
        return True


class CavityArcFxn(oegrapheme.OEComplexSurfaceArcFxnBase):
    def __call__(self, image, arc):
        pen = oedepict.OEPen(oechem.OEBlack, oechem.OEBlack)
        pen.SetLineWidth(2.0)
        DrawSurfaceArc(image, self.GetDepth(), arc, pen)
        return True


class VoidArcFxn(oegrapheme.OEComplexSurfaceArcFxnBase):
    def __call__(self, image, arc):
        pen = oedepict.OEPen(oechem.OEDarkGrey, oechem.OEDarkGrey)
        pen.SetLineWidth(2.0)
        DrawSurfaceArc(image, self.GetDepth(), arc, pen)
        return True


if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <receptor> <ligand>" % sys.argv[0])

receptor = ImportMolecule(sys.argv[1])
ligand = ImportMolecule(sys.argv[2])

width, height = 450, 350
image = oedepict.OEImage(width, height)

sfxn = SolventArcFxn()
bfxn = BuriedArcFxn()
cfxn = CavityArcFxn()
vfxn = VoidArcFxn()
oegrapheme.OEAddComplexSurfaceArcs(ligand, receptor, sfxn, bfxn, cfxn, vfxn)

oegrapheme.OEPrepareDepictionFrom3D(ligand)
opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale)
opts.SetScale(oegrapheme.OEGetMoleculeSurfaceScale(ligand, opts))

disp = oedepict.OE2DMolDisplay(ligand, opts)
oegrapheme.OEDraw2DSurface(disp)
oedepict.OERenderMolecule(image, disp)

oedepict.OERenderMolecule("DrawComplexSurfaceUserDefined.png", disp)
oedepict.OERenderMolecule("DrawComplexSurfaceUserDefined.pdf", disp)

Listing 15: Full listing of DrawIridium.py.

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

import sys
from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme


###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE GRAPHEME DOCUMENTATION
###############################################################


if len(sys.argv) != 2:
    oechem.OEThrow.Usage("%s <design unit>" % sys.argv[0])

filename = sys.argv[1]
du = oechem.OEDesignUnit()
if not oechem.OEReadDesignUnit(filename, du):
    oechem.OEThrow.Fatal("Cannot read design unit!")

image = oedepict.OEImage(250, 250)

oegrapheme.OEDrawIridiumData(image, du)
oedepict.OEDrawBorder(image, oedepict.OELightGreyPen)
oedepict.OEWriteImage("DrawIridiumData.svg", image)
oedepict.OEWriteImage("DrawIridiumData.pdf", image)

Listing 16: Example of drawing multiple 2D surfaces

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme


def Draw2DSurface(disp, atompred, radius, color):

    penA = oedepict.OEPen(color, color, oedepict.OEFill_Off, 2.0)
    arcfxnA = oegrapheme.OEDefaultArcFxn(penA)

    penB = oedepict.OEPen(oechem.OELightGrey, oechem.OELightGrey, oedepict.OEFill_Off, 2.0,
                          oedepict.OEStipple_ShortDash)
    arcfxnB = oegrapheme.OEDefaultArcFxn(penB)

    layer = disp.GetLayer(oedepict.OELayerPosition_Below)

    for adisp in disp.GetAtomDisplays():
        for arc in oegrapheme.OEGet2DSurfaceArcs(disp, adisp, radius):
            if atompred(adisp.GetAtom()):
                arcfxnA(layer, arc)
            else:
                arcfxnB(layer, arc)


def Draw2DSurfaces(image, mol):

    oedepict.OEPrepareDepiction(mol)

    opts = oedepict.OE2DMolDisplayOptions(image.GetWidth(), image.GetHeight(),
                                          oedepict.OEScale_AutoScale)
    opts.SetTitleLocation(oedepict.OETitleLocation_Hidden)
    opts.SetScale(oegrapheme.OEGetMoleculeSurfaceScale(mol, opts, 1.50))

    disp = oedepict.OE2DMolDisplay(mol, opts)

    Draw2DSurface(disp, oechem.OEHasAtomicNum(oechem.OEElemNo_C), 1.00, oechem.OEBlack)
    Draw2DSurface(disp, oechem.OEHasAtomicNum(oechem.OEElemNo_N), 1.25, oechem.OEDarkBlue)
    Draw2DSurface(disp, oechem.OEHasAtomicNum(oechem.OEElemNo_O), 1.50, oechem.OEDarkRed)

    oedepict.OERenderMolecule(image, disp)


mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc(N)ccc1O")

imagewidth, imageheight = 300.0, 260.0
image = oedepict.OEImage(imagewidth, imageheight)
Draw2DSurfaces(image, mol)

oedepict.OEWriteImage("DrawMultiple2DSurfaces.png", image)
oedepict.OEWriteImage("DrawMultiple2DSurfaces.pdf", image)

Listing 17: Full listing of DrawPeptide.py. :noindent:

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme


ifs = oechem.oemolistream()
flavor = (oechem.OEIFlavor_Generic_Default | oechem.OEIFlavor_FASTA_EmbeddedSMILES)

ifs.SetFlavor(oechem.OEFormat_FASTA, flavor)
ifs.SetFormat(oechem.OEFormat_FASTA)

fasta = """>
FAVS[[R4]COCC(C(=O)O)Cc1ccccc1]"""

ifs.openstring(fasta)
mol = oechem.OEGraphMol()
oechem.OEReadMolecule(ifs, mol)

image = oedepict.OEImage(400, 250)

opts = oegrapheme.OEPeptideDisplayOptions()
opts.SetInteractive(True)
oegrapheme.OEDrawPeptide(image, mol, opts)
oedepict.OEWriteImage("DrawPeptide.svg", image)
oedepict.OEWriteImage("DrawPeptide.pdf", image)

Listing 18: Full listing of DrawResidues.py. :noindent:

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

import sys
from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme


if len(sys.argv) != 2:
    oechem.OEThrow.Usage("%s <pdb>" % sys.argv[0])

ifs = oechem.oemolistream()
if not ifs.open(sys.argv[1]):
    oechem.OEThrow.Fatal("Unable to open %s for reading" % sys.argv[1])

mol = oechem.OEGraphMol()
if not oechem.OEReadMolecule(ifs, mol):
    oechem.OEThrow.Fatal("Unable to read molecule in %s" % sys.argv[1])

image = oedepict.OEImage(400, 250)

interactive = True
oegrapheme.OEDrawResidues(image, mol, interactive)
oedepict.OEWriteImage("DrawResidues.svg", image)
oedepict.OEWriteImage("DrawResidues.pdf", image)

Listing 19: Full listing of DrawROCSScores.py. :noindent:

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme

image = oedepict.OEImage(200, 150)
scores = oechem.OEDoubleVector([0.75, 0.25, 0.50])
oegrapheme.OEDrawROCSScores(image, scores)
oedepict.OEWriteImage("DrawROCSScores.png", image)
oedepict.OEWriteImage("DrawROCSScores.pdf", image)

Listing 20: Full listing of OE2DPropMap_SetProperties.py.

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme

###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE GRAPHEME DOCUMENTATION
###############################################################


def DepictPropMap(propmap, mol, tagname, basefilename):

    width, height = 350, 250
    opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale)
    opts.SetTitleLocation(oedepict.OETitleLocation_Bottom)
    opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome)

    disp = oedepict.OE2DMolDisplay(mol, opts)
    below = disp.GetLayer(oedepict.OELayerPosition_Below)
    propmap.Render(below, disp, tagname)

    oedepict.OERenderMolecule(basefilename + ".png", disp)
    oedepict.OERenderMolecule(basefilename + ".pdf", disp)


def SetPartialCharge(mol, tagname):
    oechem.OEMMFFAtomTypes(mol)
    oechem.OEMMFF94PartialCharges(mol)

    tag = oechem.OEGetTag(tagname)
    for atom in mol.GetAtoms():
        atom.SetData(tag, atom.GetPartialCharge())


mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "Cc1cc(cc(c1[N+](=O)[O-])F)CC[N+]#C")

tagname = "PartialCharge"
SetPartialCharge(mol, tagname)

oedepict.OEPrepareDepiction(mol)

########################################################################
#
########################################################################

propmap = oegrapheme.OE2DPropMap()
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_Default")

propmap = oegrapheme.OE2DPropMap()
propmap.SetNegativeColor(oechem.OEDarkGreen)
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetNegativeColor")

propmap = oegrapheme.OE2DPropMap()
propmap.SetMinValue(0.0)
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetMinValue")

propmap = oegrapheme.OE2DPropMap()
propmap.SetPositiveColor(oechem.OEDarkGreen)
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetPositiveColor")

propmap = oegrapheme.OE2DPropMap()
propmap.SetMaxValue(0.0)
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetMaxValue")

propmap = oegrapheme.OE2DPropMap()
font = oedepict.OEFont()
font.SetStyle(oedepict.OEFontStyle_Bold)
font.SetColor(oechem.OEDarkBlue)
propmap.SetLegendFont(font)
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetLegendFont")

propmap = oegrapheme.OE2DPropMap()
propmap.SetLegendFontScale(1.5)
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetLegendFontScale")

propmap = oegrapheme.OE2DPropMap()
propmap.SetLegendLocation(oegrapheme.OELegendLocation_Left)
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetLegendLocation")

propmap = oegrapheme.OE2DPropMap()
propmap.SetResolution(5)
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetResolution")

propmap = oegrapheme.OE2DPropMap()
propmap.SetRadiusRatio(0.75)
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetRadiusRatio")

Listing 21: Full listing of OEColorGradientDispOpts.py.

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme

###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE GRAPHEME DOCUMENTATION
###############################################################


def DepictColorGradient(colorg, opts, basefilename):

    width, height = 400, 100
    image = oedepict.OEImage(width, height)
    oegrapheme.OEDrawColorGradient(image, colorg, opts)

    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)

########################################################################
#
########################################################################


width, height = 400, 100
image = oedepict.OEImage(width, height)

colorg = oechem.OELinearColorGradient(oechem.OEColorStop(0.0, oechem.OEYellow))
colorg.AddStop(oechem.OEColorStop(+1.0, oechem.OEOrange))
colorg.AddStop(oechem.OEColorStop(-1.0, oechem.OEGreen))
opts = oegrapheme.OEColorGradientDisplayOptions()
oegrapheme.OEDrawColorGradient(image, colorg)
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_Default")

opts = oegrapheme.OEColorGradientDisplayOptions()
font = oedepict.OEFont()
font.SetColor(oechem.OEDarkGreen)
font.SetStyle(oedepict.OEFontStyle_Bold)
opts.SetColorStopLabelFont(font)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetColorStopLabelFont")

opts = oegrapheme.OEColorGradientDisplayOptions()
opts.SetColorStopLabelFontScale(0.5)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetColorStopLabelFontScale")

opts = oegrapheme.OEColorGradientDisplayOptions()
opts.SetColorStopPrecision(4)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetColorStopPrecision")

opts = oegrapheme.OEColorGradientDisplayOptions()
opts.SetColorStopVisibility(False)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetColorStopVisibility")

opts = oegrapheme.OEColorGradientDisplayOptions()
opts.SetBoxRange(-0.5, 0.5)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetBoxRange")

opts = oegrapheme.OEColorGradientDisplayOptions()
opts.SetBoxRange(-0.5, 0.5)
pen = oedepict.OEPen(oechem.OEBlack, oechem.OEBlack, oedepict.OEFill_On,
                     2.0, oedepict.OEStipple_ShortDash)
opts.SetBoxRangePen(pen)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetBoxRangePen")

opts = oegrapheme.OEColorGradientDisplayOptions()
opts.AddMarkedValue(0.20)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_AddMarkedValue")

opts = oegrapheme.OEColorGradientDisplayOptions()
markedvalues = oechem.OEDoubleVector([0.20, 0.70, 0.72])
opts.AddMarkedValues(markedvalues)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_AddMarkedValues")

opts = oegrapheme.OEColorGradientDisplayOptions()
opts.AddMarkedValue(0.0)
markedvalues = oechem.OEDoubleVector([0.5, 0.75])
opts.SetMarkedValues(markedvalues)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetMarkedValues")

opts = oegrapheme.OEColorGradientDisplayOptions()
markedvalues = oechem.OEDoubleVector([0.20, 0.70, 0.72])
opts.AddMarkedValues(markedvalues)
opts.SetMarkedValuePrecision(1)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetMarkedValuePrecision")

opts = oegrapheme.OEColorGradientDisplayOptions()
markedvalues = oechem.OEDoubleVector([0.20, 0.70, 0.72])
opts.AddMarkedValues(markedvalues)
pen = oedepict.OEPen(oechem.OEBlack, oechem.OEDarkGreen, oedepict.OEFill_On,
                     2.0, oedepict.OEStipple_ShortDash)
opts.SetMarkedValuePen(pen)
oegrapheme.OEDrawColorGradient(image, colorg, opts)
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_SetMarkedValuePen")

opts = oegrapheme.OEColorGradientDisplayOptions()
opts.AddLabel(oegrapheme.OEColorGradientLabel(-1.0, "dissimilar"))
opts.AddLabel(oegrapheme.OEColorGradientLabel(+1.0, "similar"))
oegrapheme.OEDrawColorGradient(image, colorg, opts)
DepictColorGradient(colorg, opts, "OEColorGradientDisplayOptions_AddLabel")

Listing 22: Full listing of OEPeptideDispOpts_SetOpts.py.

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme

###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE OEDEPICT DOCUMENTATION
###############################################################


def DepictPeptide(opts, smiles, basefilename):

    mol = oechem.OEGraphMol()
    oechem.OESmilesToMol(mol, smiles)
    oedepict.OEPrepareDepiction(mol)

    image = oedepict.OEImage(400, 200)
    oegrapheme.OEDrawPeptide(image, mol, opts)

    oedepict.OEWriteImage(basefilename + ".svg", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)
    oedepict.OEWriteImage(basefilename + ".png", image)


smiles = "CCC(C)[C@H]1C(=O)N[C@@H](C(=O)N[C@H](C(=O)N[C@@H](C(=O)N[C@H](C(=O)NCCCC[C@@H]" \
         "(C(=O)N[C@@H](C(=O)N1)CCCN)NC(=O)[C@H](C(C)CC)NC(=O)[C@@H](CCC(=O)O)NC(=O)[C@H]" \
         "(CC(C)C)NC(=O)C2CSC(=N2)NC(C(C)CC)N)CC(=O)N)CC(=O)O)CC3=CN=C[NH]3)Cc4ccccc4 bacitracin"

opts = oegrapheme.OEPeptideDisplayOptions()
DepictPeptide(opts, smiles, "OEPeptideDisplayOptions_Default")

opts = oegrapheme.OEPeptideDisplayOptions()
opts.SetLabelStyle(oegrapheme.OEPeptideLabelStyle_SingleLetter)
DepictPeptide(opts, smiles, "OEPeptideDisplayOptions_SetLabelStyle")

opts = oegrapheme.OEPeptideDisplayOptions()
opts.SetInteractive(True)
DepictPeptide(opts, smiles, "OEPeptideDisplayOptions_SetInteractive")

opts = oegrapheme.OEPeptideDisplayOptions()
opts.SetInteractive(True)
opts.SetAminoAcidScale(0.75)
DepictPeptide(opts, smiles, "OEPeptideDisplayOptions_SetAminoAcidScale")

Listing 23: Full listing of RenderBFactorMap.py.

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.


import sys
from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme

###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE GRAPHEME DOCUMENTATION
###############################################################


def ImportMolecule(filename):

    ifs = oechem.oemolistream()
    if not ifs.open(filename):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % filename)

    mol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, mol):
        oechem.OEThrow.Fatal("Unable to read molecule in %s" % filename)

    return mol


if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <receptor> <ligand>" % sys.argv[0])

protein = ImportMolecule(sys.argv[1])
ligand = ImportMolecule(sys.argv[2])

asite = oechem.OEInteractionHintContainer(protein, ligand)
oechem.OEPerceiveInteractionHints(asite)
oegrapheme.OEPrepareActiveSiteDepiction(asite)

image = oedepict.OEImage(800.0, 600.0)

opts = oegrapheme.OE2DActiveSiteDisplayOptions(image.GetWidth(), image.GetHeight())
opts.SetRenderInteractiveLegend(True)
adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)

oegrapheme.OERenderBFactorMap(image, adisp)
oedepict.OEWriteImage("RenderBFactorMap.svg", image)
oedepict.OEWriteImage("RenderBFactorMap.pdf", image)

# initialize OE2DActiveSiteDisplay

cgimage = oedepict.OEImage(300.0, 100.0)
oegrapheme.OEDrawBFactorMapLegend(cgimage, adisp)
oedepict.OEWriteImage("DrawBFactorMapLegend.png", cgimage)
oedepict.OEWriteImage("DrawBFactorMapLegend.pdf", cgimage)

Listing 24: Full listing of shapeoverlap2pdf.py.

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

#############################################################################
# Depicts shape and color overlap between a 3D reference structure and
# a sets of 3D fit molecules. The molecules have to be pre-aligned.
# The first molecule is expected be the reference.
#############################################################################

import sys
from openeye import oechem
from openeye import oedepict
from openeye import oegrapheme
from openeye import oeshape


def main(argv=[__name__]):

    itf = oechem.OEInterface(InterfaceData)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    iname = itf.GetString("-in")
    oname = itf.GetString("-out")
    maxhits = itf.GetInt("-maxhits")

    ext = oechem.OEGetFileExtension(oname)
    if not oedepict.OEIsRegisteredMultiPageImageFile(ext):
        oechem.OEThrow.Fatal("Unknown multipage image type!")

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Cannot open input molecule file!")

    refmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, refmol):
        oechem.OEThrow.Fatal("Cannot read reference molecule!")

    ropts = oedepict.OEReportOptions(3, 1)
    ropts.SetHeaderHeight(40.0)
    ropts.SetFooterHeight(20.0)
    report = oedepict.OEReport(ropts)

    cff = oeshape.OEColorForceField()
    cff.Init(oeshape.OEColorFFType_ImplicitMillsDean)
    cffdisplay = oegrapheme.OEColorForceFieldDisplay(cff)

    qopts = GetShapeQueryDisplayOptions()
    sopts = GetShapeOverlapDisplayOptions()
    copts = GetColorOverlapDisplayOptions()

    refdisp = oegrapheme.OEShapeQueryDisplay(refmol, cff, qopts)

    dots = oechem.OEDots(100, 10, "shape overlaps")

    for fitmol in ifs.GetOEGraphMols():

        if maxhits > 0 and dots.GetCounts() >= maxhits:
            break
        dots.Update()

        maincell = report.NewCell()

        grid = oedepict.OEImageGrid(maincell, 1, 3)
        grid.SetMargins(5.0)
        grid.SetCellGap(5.0)

        # TITLE + SCORE GRAPH + QUERY
        cell = grid.GetCell(1, 1)
        cellw, cellh = cell.GetWidth(), cell.GetHeight()

        font = oedepict.OEFont(oedepict.OEFontFamily_Default, oedepict.OEFontStyle_Bold, 10,
                               oedepict.OEAlignment_Left, oechem.OEBlack)
        pos = oedepict.OE2DPoint(10.0, 10.0)
        cell.DrawText(pos, fitmol.GetTitle(), font, cell.GetWidth())

        rframe = oedepict.OEImageFrame(cell, cellw, cellh * 0.35,
                                       oedepict.OE2DPoint(0.0, cellh * 0.10))
        mframe = oedepict.OEImageFrame(cell, cellw, cellh * 0.50,
                                       oedepict.OE2DPoint(0.0, cellh * 0.50))

        RenderScoreRadial(rframe, fitmol)
        oegrapheme.OERenderShapeQuery(mframe, refdisp)

        font = oedepict.OEFont(oedepict.OEFontFamily_Default, oedepict.OEFontStyle_Bold, 8,
                               oedepict.OEAlignment_Center, oechem.OEGrey)
        pos = oedepict.OE2DPoint(20.0, 10.0)
        mframe.DrawText(pos, "query", font)
        oedepict.OEDrawCurvedBorder(mframe, oedepict.OELightGreyPen, 10.0)

        odisp = oegrapheme.OEShapeOverlapDisplay(refdisp, fitmol, sopts, copts)

        # SHAPE OVERLAP
        cell = grid.GetCell(1, 2)
        oegrapheme.OERenderShapeOverlap(cell, odisp)
        RenderScore(cell, fitmol, "ROCS_ShapeTanimoto", "Shape Tanimoto")

        # COLOR OVERLAP
        cell = grid.GetCell(1, 3)
        oegrapheme.OERenderColorOverlap(cell, odisp)
        RenderScore(cell, fitmol, "ROCS_ColorTanimoto", "Color Tanimoto")

        oedepict.OEDrawCurvedBorder(maincell, oedepict.OELightGreyPen, 10.0)

    dots.Total()

    cffopts = oegrapheme.OEColorForceFieldLegendDisplayOptions(1, 6)
    for header in report.GetHeaders():
        oegrapheme.OEDrawColorForceFieldLegend(header, cffdisplay, cffopts)
        oedepict.OEDrawCurvedBorder(header, oedepict.OELightGreyPen, 10.0)

    font = oedepict.OEFont(oedepict.OEFontFamily_Default, oedepict.OEFontStyle_Default, 12,
                           oedepict.OEAlignment_Center, oechem.OEBlack)
    for idx, footer in enumerate(report.GetFooters()):
        oedepict.OEDrawTextToCenter(footer, "-" + str(idx + 1) + "-", font)

    oedepict.OEWriteReport(oname, report)

    return 0


def AddCommonDisplayOptions(opts):
    opts.SetTitleLocation(oedepict.OETitleLocation_Hidden)
    opts.SetAtomLabelFontScale(1.5)
    pen = oedepict.OEPen(oechem.OEBlack, oechem.OEBlack, oedepict.OEFill_Off, 1.5)
    opts.SetDefaultBondPen(pen)


def GetShapeQueryDisplayOptions():

    qopts = oegrapheme.OEShapeQueryDisplayOptions()
    AddCommonDisplayOptions(qopts)
    arcpen = oedepict.OEPen(oedepict.OELightGreyPen)
    qopts.SetSurfaceArcFxn(oegrapheme.OEDefaultArcFxn(arcpen))
    qopts.SetDepictOrientation(oedepict.OEDepictOrientation_Square)
    return qopts


def GetShapeOverlapDisplayOptions():

    sopts = oegrapheme.OEShapeOverlapDisplayOptions()
    AddCommonDisplayOptions(sopts)
    arcpen = oedepict.OEPen(oechem.OEGrey, oechem.OEGrey, oedepict.OEFill_Off, 1.0, 0x1111)
    sopts.SetQuerySurfaceArcFxn(oegrapheme.OEDefaultArcFxn(arcpen))
    sopts.SetOverlapColor(oechem.OEColor(110, 110, 190))

    return sopts


def GetColorOverlapDisplayOptions():

    copts = oegrapheme.OEColorOverlapDisplayOptions()
    AddCommonDisplayOptions(copts)
    arcpen = oedepict.OEPen(oechem.OEGrey, oechem.OEGrey, oedepict.OEFill_Off, 1.0, 0x1111)
    copts.SetQuerySurfaceArcFxn(oegrapheme.OEDefaultArcFxn(arcpen))

    return copts


def GetScore(mol, sdtag):

    if oechem.OEHasSDData(mol, sdtag):
        return float(oechem.OEGetSDData(mol, sdtag))
    return 0.0


def RenderScoreRadial(image, mol):

    sscore = max(min(GetScore(mol, "ROCS_ShapeTanimoto"), 1.0), 0.00)
    cscore = max(min(GetScore(mol, "ROCS_ColorTanimoto"), 1.0), 0.00)
    if sscore > 0.0 or cscore > 0.0:
        scores = oechem.OEDoubleVector([sscore, cscore])
        oegrapheme.OEDrawROCSScores(image, scores)


def RenderScore(image, mol, sdtag, label):

    score = GetScore(mol, sdtag)
    if score == 0.0:
        return

    w, h = image.GetWidth(), image.GetHeight()
    frame = oedepict.OEImageFrame(image, w, h * 0.10, oedepict.OE2DPoint(0.0, h * 0.90))
    font = oedepict.OEFont(oedepict.OEFontFamily_Default, oedepict.OEFontStyle_Default, 9,
                           oedepict.OEAlignment_Center, oechem.OEBlack)
    oedepict.OEDrawTextToCenter(frame, label + " = " + str(score), font)


#############################################################################
# INTERFACE
#############################################################################

InterfaceData = '''
!BRIEF [-in] <input> [-out] <output pdf>

!CATEGORY "input/output options:" 0

  !PARAMETER -in
    !ALIAS -i
    !TYPE string
    !REQUIRED true
    !KEYLESS 1
    !VISIBILITY simple
    !BRIEF Input molecule filename
    !DETAIL
         The first molecule in the file is expected to be the reference
         molecule
  !END

  !PARAMETER -out
    !ALIAS -o
    !TYPE string
    !REQUIRED true
    !KEYLESS 2
    !VISIBILITY simple
    !BRIEF Output image filename
  !END

!END

!CATEGORY "general options:" 1

  !PARAMETER -maxhits
    !ALIAS -mhits
    !TYPE int
    !REQUIRED false
    !DEFAULT 0
    !LEGAL_RANGE 0 500
    !VISIBILITY simple
    !BRIEF Maximum number of hits depicted
    !DETAIL
            The default of 0 means there is no limit.
  !END

!END
'''

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Listing 25: Full listing of SVGMarkResidues.py.

#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.


import sys
from openeye import oechem
from openeye import oegrapheme

###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE GRAPHEME DOCUMENTATION
###############################################################


def ImportMolecule(filename):

    ifs = oechem.oemolistream()
    if not ifs.open(filename):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % filename)

    mol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, mol):
        oechem.OEThrow.Fatal("Unable to read molecule in %s" % filename)

    return mol


if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <receptor> <ligand>" % sys.argv[0])

protein = ImportMolecule(sys.argv[1])
ligand = ImportMolecule(sys.argv[2])

asite = oechem.OEInteractionHintContainer(protein, ligand)
oechem.OEPerceiveInteractionHints(asite)
oegrapheme.OEPrepareActiveSiteDepiction(asite)


opts = oegrapheme.OE2DActiveSiteDisplayOptions(800.0, 600.0)
opts.SetResidueSVGMarkupFunctor(oegrapheme.OEResidueSVGStandardMarkup())
adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)

oegrapheme.OERenderActiveSite("SVGMarkResidues.svg", adisp)