OEDocking Examples

The following table lists the currently available OEDocking TK examples:

Program

Description

docking

docking molecules

rescoring

rescore docked molecules

shapefit

flexible fitting with OEShapeFit

posing

generating poses

posing_multi

posing with multiple receptors

make_receptor

making a receptor

contour_volume

receptor contour volume

inner_contour

toggle inner contour

outer_contour

set outer contour

Docking and Scoring Examples

Docking Molecules

The following code example shows how to perform docking using the OEDock object.

See also

Listing 1: Docking Molecules

#!/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 oedocking


def main(argv=[__name__]):
    dockOpts = oedocking.OEDockOptions()
    opts = oechem.OERefInputAppOptions(dockOpts, "DockMolecules", oechem.OEFileStringType_Mol3D,
                                       oechem.OEFileStringType_Mol3D, oechem.OEFileStringType_DU, "-receptor")
    if oechem.OEConfigureOpts(opts, argv, False) == oechem.OEOptsConfigureStatus_Help:
        return 0
    dockOpts.UpdateValues(opts)

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

    rfs = oechem.oeifstream()
    if not rfs.open(opts.GetRefFile()):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % opts.GetRefFile())

    ofs = oechem.oemolostream()
    if not ofs.open(opts.GetOutFile()):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % opts.GetOutFile())

    du = oechem.OEDesignUnit()
    if not oechem.OEReadDesignUnit(rfs, du):
        oechem.OEThrow.Fatal("Failed to read design unit")
    if not du.HasReceptor():
        oechem.OEThrow.Fatal("Design unit %s does not contain a receptor" % du.GetTitle())

    dock = oedocking.OEDock(dockOpts)
    dock.Initialize(du)

    for mcmol in ifs.GetOEMols():
        print("docking", mcmol.GetTitle())
        dockedMol = oechem.OEGraphMol()
        retCode = dock.DockMultiConformerMolecule(dockedMol, mcmol)
        if (retCode != oedocking.OEDockingReturnCode_Success):
            oechem.OEThrow.Fatal("Docking Failed with error code " + oedocking.OEDockingReturnCodeGetName(retCode))

        sdtag = oedocking.OEDockMethodGetName(dockOpts.GetScoreMethod())
        oedocking.OESetSDScore(dockedMol, dock, sdtag)
        dock.AnnotatePose(dockedMol)
        oechem.OEWriteMolecule(ofs, dockedMol)

    return 0


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

Download code

DockMolecules.py

Rescoring Docked Molecules

The following code example shows how to rescore previously docked molecules, using the OEScore object.

See also

Listing 2: Rescoring Docked Molecules

#!/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 oedocking


def main(argv=[__name__]):
    itf = oechem.OEInterface(InterfaceData)
    oedocking.OEScoreTypeConfigure(itf, "-score")
    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    receptor = oechem.OEDesignUnit()
    if not oechem.OEReadDesignUnit(itf.GetString("-receptor"), receptor):
        oechem.OEThrow.Fatal("Unable to read receptor")
    imstr = oechem.oemolistream()
    if not imstr.open(itf.GetString("-in")):
        oechem.OEThrow.Fatal("Unable to open input file of ligands")
    omstr = oechem.oemolostream()
    if not omstr.open(itf.GetString("-out")):
        oechem.OEThrow.Fatal("Unable to open out file for rescored ligands")

    scoreType = oedocking.OEScoreTypeGetValue(itf, "-score")
    score = oedocking.OEScore(scoreType)
    score.Initialize(receptor)

    for ligand in imstr.GetOEMols():
        if itf.GetBool("-optimize"):
            score.SystematicSolidBodyOptimize(ligand)
        score.AnnotatePose(ligand)
        sdtag = score.GetName()
        oedocking.OESetSDScore(ligand, score, sdtag)
        oechem.OESortConfsBySDTag(ligand, sdtag, score.GetHighScoresAreBetter())
        oechem.OEWriteMolecule(omstr, ligand)

    return 0


InterfaceData = """
!PARAMETER -receptor
  !ALIAS -rec
  !TYPE string
  !REQUIRED true
  !LEGAL_VALUE *.oedu
  !BRIEF A receptor file the poses pass to the -in flag will be scored against
!END

!PARAMETER -in
  !TYPE string
  !REQUIRED true
  !BRIEF Input molecule file with poses to rescore
!END

!PARAMETER -out
  !TYPE string
  !REQUIRED true
  !BRIEF Rescored molecules will be written to this file
!END

!PARAMETER -optimize
  !ALIAS -opt
  !TYPE bool
  !DEFAULT false
  !BRIEF Optimize molecules before rescoring
!END
"""


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

Download code

RescorePoses.py

OEShapeFit Examples

Flexible Overlay Optimization with OEShapeFit API

The following code example shows how to flexibly fit input multi conformer molecules in the design unit that contains bound ligand and get the score using the OEShapeFit and OEShapeFitResults objects.

Listing 3: Flexible fitting with OEShapeFit

#!/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.

# This example reads in a reference molecule and a few fit
# molecules, performs overlay optimization, sorts the results
# in Tanimoto order, and shows the single best result.
# With the default options, OEOverlay optimizes both shape and color.


import sys

from openeye import oechem
from openeye import oeshape
from openeye import oedocking


def main(argv=[__name__]):
    overlayOpts = oedocking.OEShapeFitOptions()
    opts = oechem.OERefInputAppOptions(overlayOpts, "ShapeFit", oechem.OEFileStringType_Mol3D,
                                       oechem.OEFileStringType_Mol3D, oechem.OEFileStringType_DU, "-receptor")
    if oechem.OEConfigureOpts(opts, argv, False) == oechem.OEOptsConfigureStatus_Help:
        return 0
    overlayOpts.UpdateValues(opts)

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

    rfs = oechem.oeifstream()
    if not rfs.open(opts.GetRefFile()):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % opts.GetRefFile())

    ofs = oechem.oemolostream()
    if not ofs.open(opts.GetOutFile()):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % opts.GetOutFile())

    receptor = oechem.OEDesignUnit()
    oechem.OEReadDesignUnit(rfs, receptor)
    print("Ref. Title:", receptor.GetTitle())

    shapefit = oedocking.OEShapeFit(overlayOpts)
    shapefit.SetupRef(receptor)

    for fitmol in ifs.GetOEMols():
        results = shapefit.Fit(fitmol)
        for res, conf in zip(results, fitmol.GetConfs()):
            print("Fit Title: %-4s Score: %.2f"
                  % (fitmol.GetTitle(), res.GetScore()))
            oechem.OESetSDData(conf, "Score", "%.2f" % res.GetScore())
        oechem.OEWriteMolecule(ofs, fitmol)


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

Download code

ShapeFit.py

POSIT Examples

Generating Poses with POSIT

The following code example shows how to generate a single pose for each input ligand using the OEPosit object.

See also

Listing 4: Generating Poses with POSIT

#!/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 oedocking


def main(argv=[__name__]):
    positOpts = oedocking.OEPositOptions()
    opts = oechem.OERefInputAppOptions(positOpts, "PoseMolecules", oechem.OEFileStringType_Mol3D,
                                       oechem.OEFileStringType_DU, oechem.OEFileStringType_DU, "-receptor")
    if oechem.OEConfigureOpts(opts, argv, False) == oechem.OEOptsConfigureStatus_Help:
        return 0
    positOpts.UpdateValues(opts)

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

    rfs = oechem.oeifstream()
    if not rfs.open(opts.GetRefFile()):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % opts.GetRefFile())

    ofs = oechem.oeofstream()
    if not ofs.open(opts.GetOutFile()):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % opts.GetOutFile())

    poser = oedocking.OEPosit(positOpts)
    du = oechem.OEDesignUnit()
    count = 0
    while oechem.OEReadDesignUnit(rfs, du):
        if not du.HasReceptor():
            oechem.OEThrow.Fatal("Design unit %s does not contain a receptor" % du.GetTitle())
        poser.AddReceptor(du)
        count += 1
    if count == 0:
        oechem.OEThrow.Fatal("Receptor input does not contain any design unit")

    for mcmol in ifs.GetOEMols():
        oechem.OEThrow.Info("posing %s" % mcmol.GetTitle())
        result = oedocking.OESinglePoseResult()
        ret_code = poser.Dock(result, mcmol)

        if ret_code == oedocking.OEDockingReturnCode_Success:
            posedDU = result.GetDesignUnit()
            posedDU.SetDoubleData(poser.GetName(), result.GetProbability())
            oechem.OEThrow.Info("Receptor used: %s pose probability: %f" % (posedDU.GetTitle(), result.GetProbability()))
            oechem.OEWriteDesignUnit(ofs, posedDU)
        else:
            errMsg = oedocking.OEDockingReturnCodeGetName(ret_code)
            oechem.OEThrow.Warning("%s: %s" % (mcmol.GetTitle(), errMsg))
    return 0


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

Download code

PoseMolecules.py

Generating Multiple Poses with POSIT

The following code example shows how to generate multiple poses for each input ligand, using the OEPosit object.

See also

Listing 5: Posit for Generating Multiple Poses for each Ligand

#!/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 oedocking


class MyOptions(oedocking.OEPositOptions):
    def __init__(self):
        oedocking.OEPositOptions.__init__(self)
        param1 = oechem.OEUIntParameter("-numPoses", 1)
        param1.AddLegalRange("1", "20")
        param1.SetBrief("Number of poses to generate")
        self._param1 = self.AddParameter(param1)
        pass

    def GetNumPoses(self):
        if self._param1.GetHasValue():
            return int(self._param1.GetStringValue())
        return int(self._param1.GetStringDefault())

def main(argv=[__name__]):
    positOpts = MyOptions()
    opts = oechem.OERefInputAppOptions(positOpts, "PoseMolecules", oechem.OEFileStringType_Mol3D,
                                       oechem.OEFileStringType_DU, oechem.OEFileStringType_DU, "-receptor")
    if oechem.OEConfigureOpts(opts, argv, False) == oechem.OEOptsConfigureStatus_Help:
        return 0
    positOpts.UpdateValues(opts)

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

    rfs = oechem.oeifstream()
    if not rfs.open(opts.GetRefFile()):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % opts.GetRefFile())

    ofs = oechem.oeofstream()
    if not ofs.open(opts.GetOutFile()):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % opts.GetOutFile())

    poser = oedocking.OEPosit(positOpts)
    du = oechem.OEDesignUnit()
    count = 0
    while oechem.OEReadDesignUnit(rfs, du):
        if not du.HasReceptor():
            oechem.OEThrow.Fatal("Design unit %s does not contain a receptor" % du.GetTitle())
        poser.AddReceptor(du)
        count += 1
    if count == 0:
        oechem.OEThrow.Fatal("Receptor input does not contain any design unit")

    oechem.OEThrow.Info("Number of conformers: %d" % positOpts.GetNumPoses())
    oechem.OEThrow.Info("Best Receptor pose flag: %s" % positOpts.GetBestReceptorPoseOnly())
    
    for mcmol in ifs.GetOEMols():
        oechem.OEThrow.Info("posing %s" % mcmol.GetTitle())
        results = oedocking.OEPositResults()
        ret_code = poser.Dock(results, mcmol, positOpts.GetNumPoses())

        if ret_code == oedocking.OEDockingReturnCode_Success:
            for result in results.GetSinglePoseResults():
                posedDU = result.GetDesignUnit()
                posedDU.SetDoubleData(poser.GetName(), result.GetProbability())
                oechem.OEThrow.Info("Receptor used: %s pose probability: %f" % (posedDU.GetTitle(), result.GetProbability()))
                oechem.OEWriteDesignUnit(ofs, posedDU)
        else:
            errMsg = oedocking.OEDockingReturnCodeGetName(ret_code)
            oechem.OEThrow.Warning("%s: %s" % (mcmol.GetTitle(), errMsg))
    return 0

    

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

Download code

GenerateMultiplePose.py

Receptor Examples

Making Receptor

The following code example shows how to make a receptor.

See also

Listing 6: Making Receptor

#!/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 oedocking


def main(argv=[__name__]):
    recOpts = oedocking.OEMakeReceptorOptions()
    opts = oechem.OESimpleAppOptions(recOpts, "MakeReceptor", oechem.OEFileStringType_DU, oechem.OEFileStringType_DU)
    if oechem.OEConfigureOpts(opts, argv, False) == oechem.OEOptsConfigureStatus_Help:
        return 0
    recOpts.UpdateValues(opts)

    ifs = oechem.oeifstream()
    if not ifs.open(opts.GetInFile()):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % opts.GetInFile())

    ofs = oechem.oeofstream()
    if not ofs.open(opts.GetOutFile()):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % opts.GetOutFile())

    du = oechem.OEDesignUnit()
    while oechem.OEReadDesignUnit(ifs, du):
        if oedocking.OEMakeReceptor(du, recOpts):
            oechem.OEWriteDesignUnit(ofs, du)
        else:
            oechem.OEThrow.Warning("%s: %s" % (du.GetTitle(), "Failed to make receptor"))
    return 0


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

Download code

MakeReceptor.py

Receptor Contour Volume

The following code example shows how to estimate a receptor outer contour volume.

See also

Listing 7: Receptor Contour Volume

#!/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


def main(argv=[__name__]):
    if len(sys.argv) != 2:
        oechem.OEThrow.Usage("ReceptorOuterContourVolume.py <receptor>")

    du = oechem.OEDesignUnit()
    if not oechem.OEReadDesignUnit(argv[1], du):
        oechem.OEThrow.Fatal("Unable to open receptor design unit file")

    if not du.HasReceptor():
        oechem.OEThrow.Fatal("Design unit %s does not have a receptor" % du.GetTitle())

    receptor = du.GetReceptor()
    negativeImagePotential = receptor.GetNegativeImageGrid()
    outerContourLevel = receptor.GetOuterContourLevel()

    outerCount = 0
    for i in range(negativeImagePotential.GetSize()):
        if negativeImagePotential[i] >= outerContourLevel:
            outerCount += 1

    countToVolume = pow(negativeImagePotential.GetSpacing(), 3)

    print(outerCount * countToVolume, " cubic angstroms")


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

Toggle Receptor Inner Contour

The following code example shows how to toggle receptor contour volume.

See also

Listing 8: Toggle Receptor Inner Contour

#!/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


def main(argv=[__name__]):
    if len(argv) != 2:
        oechem.OEThrow.Usage("ToggleInterContour.py <receptor>")

    du = oechem.OEDesignUnit()
    if not oechem.OEReadDesignUnit(argv[1], du):
        oechem.OEThrow.Fatal("Cannot read receptor du file")

    if not du.HasReceptor():
        oechem.OEThrow.Fatal("Design unit %s does not have a receptor" % du.GetTitle())

    receptor = du.GetReceptor()
    innerContourLevel = receptor.GetInnerContourLevel()
    receptor.SetInnerContourLevel(-innerContourLevel)

    if innerContourLevel > 0.0:
        oechem.OEThrow.Info("Toggling inner contour off")
    else:
        oechem.OEThrow.Info("Toggling inner contour on")

    if not oechem.OEWriteDesignUnit(argv[1], du):
        oechem.OEThrow.Fatal("Unable to write receptor")


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

Download code

ToggleInnerContour.py

Set Receptor Contour Volume

The following code example shows how to change the receptor outer contour volume.

See also

Listing 9: Set Receptor Contour Volume

#!/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


def main(argv=[__name__]):
    if len(argv) != 3:
        oechem.OEThrow.Usage("SetOuterContourVolume.py <receptor> <volume>")

    du = oechem.OEDesignUnit()
    if not oechem.OEReadDesignUnit(argv[1], du):
        oechem.OEThrow.Fatal("Unable to open receptor design unit file")

    if not du.HasReceptor():
        oechem.OEThrow.Fatal("Design unit %s does not have a receptor" % du.GetTitle())

    outerContourVolume = float(argv[2])

    receptor = du.GetReceptor()
    negativeImagePotential = receptor.GetNegativeImageGrid()

    gridElement = []
    for i in range(negativeImagePotential.GetSize()):
        gridElement.append(negativeImagePotential[i])

    gridElement.sort()
    gridElement.reverse()

    countToVolume = pow(negativeImagePotential.GetSpacing(), 3)
    ilevel = int((outerContourVolume / countToVolume) + 0.5)

    outerContourLevel = gridElement[-1]
    if ilevel < len(gridElement):
        outerContourLevel = gridElement[ilevel]

    receptor.SetOuterContourLevel(outerContourLevel)

    if not oechem.OEWriteDesignUnit(argv[1], du):
        oechem.OEThrow.Fatal("Unable to write updated receptor")


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

Download code

SetOuterContourVolume.py