OEDocking Examples

The following table lists the currently available OEDocking TK examples:

Program

Description

docking

docking molecules

rescoring

rescore docked molecules

posing

generating poses

posing_multi

posing with multiple receptors

make_receptor

making a receptor

contour_volume

recepotr 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) 2017 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye 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 OpenEye 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 OpenEye 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))

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) 2017 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye 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 OpenEye 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 OpenEye 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))

POSIT Examples

Generating Poses with POSIT

The following code example shows how to generate poses using the OEPosit object.

See also

Listing 3: Generating Poses with POSIT

#!/usr/bin/env python
# (C) 2017 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye 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 OpenEye 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 OpenEye 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())

    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())

    poser = oedocking.OEPosit(positOpts)
    poser.AddReceptor(du)

    for mcmol in ifs.GetOEMols():
        print("posing", 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.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))

POSIT with Multiple Receptors

The following code example shows how to generate poses, against multiple receptors, using the OEPosit object.

See also

Listing 4: POSIT with Multiple Receptors

#!/usr/bin/env python
# (C) 2017 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye 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 OpenEye 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 OpenEye 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)
    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    ifs = oechem.oemolistream(itf.GetString("-in"))
    ofs = oechem.oeofstream(itf.GetString("-out"))

    receptors = []
    for receptor_filename in itf.GetStringList("-receptors"):
        du = oechem.OEDesignUnit()
        if not oechem.OEReadDesignUnit(receptor_filename, du):
            oechem.OEThrow.Fatal("Unable to read receptor from %s" %
                                 receptor_filename)
        receptors.append(du)

    poser = oedocking.OEPosit()
    for receptor in receptors:
        poser.AddReceptor(receptor)

    for mcmol in ifs.GetOEMols():
        print("posing", 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.OEWriteDesignUnit(ofs, posedDU)
        else:
            errMsg = oedocking.OEDockingReturnCodeGetName(ret_code)
            oechem.OEThrow.Warning("%s: %s" % (mcmol.GetTitle(), errMsg))
    return 0


InterfaceData = """
!PARAMETER -receptors
  !ALIAS -rec
  !TYPE string
  !LIST true
  !REQUIRED true
  !LEGAL_VALUE *.oedu
  !BRIEF A receptor file for posing the input molecules against.
!END

!PARAMETER -in
  !TYPE string
  !REQUIRED true
  !BRIEF Multiconformer file of molecules to be posed.
!END

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

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

Receptor Examples

Making Receptor

The following code example shows how to make a receptor.

See also

Listing 5: Making Receptor

#!/usr/bin/env python
# (C) 2017 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye 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 OpenEye 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 OpenEye 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))

Receptor Contour Volume

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

See also

Listing 6: Receptor Contour Volume

#!/usr/bin/env python
# (C) 2017 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye 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 OpenEye 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 OpenEye 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 7: Toggle Receptor Inner Contour

#!/usr/bin/env python
# (C) 2017 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye 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 OpenEye 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 OpenEye 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))

Set Receptor Contour Volume

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

See also

Listing 8: Set Receptor Contour Volume

#!/usr/bin/env python
# (C) 2017 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye 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 OpenEye 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 OpenEye 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))