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

/*
(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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEBio;
using OpenEye.OEDocking;

public class DockMolecules
{
  public static void Main(string[] argv)
  {
    OEDockOptions dockOpts = new OEDockOptions();
    OERefInputAppOptions opts = new OERefInputAppOptions(dockOpts, "DockMolecules", OEFileStringType.Mol3D,
            OEFileStringType.Mol3D, OEFileStringType.DU, "-receptor");

    oemolistream ifs = new oemolistream();
    if (!ifs.open(opts.GetInFile()))
      OEChem.OEThrow.Fatal("Unable to open " + opts.GetInFile() + " for reading");
    oemolostream ofs = new oemolostream();
    if (!ofs.open(opts.GetOutFile()))
      OEChem.OEThrow.Fatal("Unable to open " + opts.GetOutFile() + " for writing");
    oeifstream rfs = new oeifstream();
    if (!rfs.open(opts.GetRefFile()))
      OEChem.OEThrow.Fatal("Unable to open " + opts.GetRefFile() + " for reading");

    OEDesignUnit du = new OEDesignUnit();
    if (!OEBio.OEReadDesignUnit(opts.GetRefFile(), du))
      OEChem.OEThrow.Fatal("Failed to read design unit ");
    if (!du.HasReceptor())
      OEChem.OEThrow.Fatal("Design unit " + du.GetTitle() + " does not contain a receptor");

    OEDock dock = new OEDock(dockOpts);
    dock.Initialize(du);

    foreach (OEMol mcmol in ifs.GetOEMols())
    {
      Console.WriteLine("docking {0}\n", mcmol.GetTitle());
      OEGraphMol dockedMol = new OEGraphMol();
      uint retCode = dock.DockMultiConformerMolecule(dockedMol, mcmol);
      if (retCode != OEDockingReturnCode.Success)
      {
        OEChem.OEThrow.Error("Docking failed with error code " + OEDocking.OEDockingReturnCodeGetName(retCode));
      }
      String sdtag = OEDocking.OEDockMethodGetName(dockOpts.GetScoreMethod());
      OEDocking.OESetSDScore(dockedMol, dock, sdtag);
      dock.AnnotatePose(dockedMol);
      OEChem.OEWriteMolecule(ofs, dockedMol);
    }
    ofs.close();
    ifs.close();
  }

}

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

/*
(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.
*/
using System;
using System.Threading;

using OpenEye.OEChem;
using OpenEye.OEBio;
using OpenEye.OEDocking;

public class RescorePoses 
{
    private void rescore(OEInterface itf) 
    {
    OEDesignUnit receptor = new OEDesignUnit();
    if (!OEBio.OEReadDesignUnit(itf.GetString("-receptor"), receptor))
    {
      OEChem.OEThrow.Fatal("Unable to read receptor");
    }
    
        oemolistream imstr = new oemolistream();
        if (!imstr.open(itf.GetString("-in")))
        {
            OEChem.OEThrow.Fatal("Unable to open input file of ligands");
        }

        oemolostream omstr = new oemolostream();
        if (!omstr.open(itf.GetString("-out")))
        {
            OEChem.OEThrow.Fatal("Unable to open out file for rescored ligands");
        }

        uint scoreType = OEDocking.OEScoreTypeGetValue(itf, "-score");
        OEScore score = new OEScore(scoreType);
        score.Initialize(receptor);

        OEMol ligand = new OEMol();
        bool optimize = itf.GetBool("-optimize");
        while (OEChem.OEReadMolecule(imstr, ligand))
        {
            if (optimize)
            {
                score.SystematicSolidBodyOptimize(ligand);
            }
            score.AnnotatePose(ligand);
            String sdtag = score.GetName();
            OEDocking.OESetSDScore(ligand, score, sdtag);
            OEChem.OESortConfsBySDTag(ligand, sdtag, score.GetHighScoresAreBetter());
            OEChem.OEWriteMolecule(omstr, ligand);
        }
    }

    public static void Main(string [] argv) 
    {
        RescorePoses app = new RescorePoses();
        OEInterface itf = new OEInterface();
        OEChem.OEConfigure(itf, InterfaceData);
        OEDocking.OEScoreTypeConfigure(itf, "-score");
        if (OEChem.OEParseCommandLine(itf, argv, "RescorePoses.exe"))
        {
            // Start the application in a thread with a larger
            //  stack size.  Currently annotating ligands requires
            //  more stack than normal operations.
            Thread T = new Thread(() => app.rescore(itf), 8000000);
            T.Start();
        }
    }

    private static string 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

";

}

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

/*
(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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEBio;
using OpenEye.OEDocking;

public class PoseMolecules
{
  public static void Main(string[] argv)
  {
    OEPositOptions positOpts = new OEPositOptions();
    OERefInputAppOptions opts = new OERefInputAppOptions(positOpts, "PoseMolecules", OEFileStringType.Mol3D,
        OEFileStringType.DU, OEFileStringType.DU, "-receptor");

    if (OEChem.OEConfigureOpts(opts, argv, false) == OEOptsConfigureStatus.Help)
      Environment.Exit(1);

    positOpts.UpdateValues(opts);

    oemolistream ifs = new oemolistream();
    if (!ifs.open(opts.GetInFile()))
      OEChem.OEThrow.Fatal("Unable to open " + opts.GetInFile() + " for reading");
    oeofstream ofs = new oeofstream(opts.GetOutFile());
    OEDesignUnit du = new OEDesignUnit();
    if (!OEBio.OEReadDesignUnit(opts.GetRefFile(), du))
      OEChem.OEThrow.Fatal("Failed to read design unit ");
    if (!du.HasReceptor())
      OEChem.OEThrow.Fatal("Design unit " + du.GetTitle() + " does not contain a receptor");

    OEPosit poser = new OEPosit(positOpts);
    poser.AddReceptor(du);


    foreach (OEMol mcmol in ifs.GetOEMols())
    {
      Console.WriteLine("posing {0}\n", mcmol.GetTitle());
      OESinglePoseResult result = new OESinglePoseResult();
      uint return_code = poser.Dock(result, mcmol);

      if (return_code == OEDockingReturnCode.Success)
      {
        OEDesignUnit posedDU = new OEDesignUnit(result.GetDesignUnit());
        posedDU.SetDoubleData(poser.GetName(), result.GetProbability());
        OEBio.OEWriteDesignUnit(ofs, posedDU);
      }
      else
        OEChem.OEThrow.Info(string.Format(
                              "Failed to pose ligand {0}: reason {1}",
                              mcmol.GetTitle(),
                              OEDocking.OEDockingReturnCodeGetName(return_code)
                              ));

    }
    ofs.close();
  }
}

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

/*
(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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEBio;
using OpenEye.OEDocking;

public class PoseMolecules
{
    private void Pose (OEInterface itf)
    {
      OEPosit poser = new OEPosit();
      foreach (string receptor_filename in itf.GetStringList("-receptors"))
      {
      OEDesignUnit receptor = new OEDesignUnit();
      if (!OEBio.OEReadDesignUnit(receptor_filename, receptor))
        OEChem.OEThrow.Fatal("Unable to read receptor");
      poser.AddReceptor(receptor);
      }

    oemolistream imstr = new oemolistream (itf.GetString ("-in"));
    oeofstream ostr = new oeofstream(itf.GetString("-out"));
    foreach (OEMol mcmol in imstr.GetOEMols ())
        {
            Console.WriteLine ("posing {0}\n", mcmol.GetTitle ());
            OESinglePoseResult result = new OESinglePoseResult();

            uint return_code = poser.Dock(result, mcmol);

      if (return_code == OEDockingReturnCode.Success)
      {
        OEDesignUnit posedDU = new OEDesignUnit(result.GetDesignUnit());
        posedDU.SetDoubleData(poser.GetName(), result.GetProbability());
        OEBio.OEWriteDesignUnit(ostr, posedDU);
      } else
        OEChem.OEThrow.Info(string.Format(
                              "Failed to pose ligand {0}: reason {1}",
                              mcmol.GetTitle(),
                              OEDocking.OEDockingReturnCodeGetName(return_code)
                              ));

        }
        ostr.close ();
    }

    public static void Main (string[] argv)
    {
        PoseMolecules app = new PoseMolecules ();
        OEInterface itf = new OEInterface ();
        OEChem.OEConfigure(itf, InterfaceData);

        if (OEChem.OEParseCommandLine (itf, argv, "PoseMolecules.exe"))
        {
            app.Pose (itf);
        }
    }

    private static string 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 docked.
!END

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

Receptor Examples

Making Receptor

The following code example shows how to make a receptor.

See also

Listing 5: Making Receptor

/*
(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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEBio;
using OpenEye.OEDocking;

public class MakeReceptor
{
  public static void Main(string[] argv)
  {
    OEMakeReceptorOptions recOpts = new OEMakeReceptorOptions();
    OESimpleAppOptions opts = new OESimpleAppOptions(recOpts, "MakeReceptor", OEFileStringType.DU, OEFileStringType.DU);

    if (OEChem.OEConfigureOpts(opts, argv, false) == OEOptsConfigureStatus.Help)
      Environment.Exit(1);

    recOpts.UpdateValues(opts);

    oeifstream ifs = new oeifstream(opts.GetInFile());
    oeofstream ofs = new oeofstream(opts.GetOutFile());
    
    OEDesignUnit du = new OEDesignUnit();
    OEDesignUnit receptor = new OEDesignUnit();
    while (OEBio.OEReadDesignUnit(ifs, du))
    {
      if (OEDocking.OEMakeReceptor(du, recOpts))
        OEBio.OEWriteDesignUnit(ofs, du);
      else
        OEChem.OEThrow.Fatal(du.GetTitle() + " failed to make a receptor");

    }
  }
}

Receptor Contour Volume

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

See also

Listing 6: Receptor Contour Volume

/*
(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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEBio;
using OpenEye.OEDocking;

public class ReceptorOuterContourVolume 
{
    public static void Main(string [] argv) 
    {
        if (argv.Length != 1)
        {
            OEChem.OEThrow.Usage("ReceptorOuterContourVolume <receptor>");
        }

        OEDesignUnit du = new OEDesignUnit();

    if (!OEBio.OEReadDesignUnit(argv[0], du))
      OEChem.OEThrow.Fatal(argv[0] + " is not a valid receptor.");
    if (!du.HasReceptor())
      OEChem.OEThrow.Fatal("Design unit " + du.GetTitle() + " does not contain a receptor");
    OEReceptor receptor = du.GetReceptor();
    OEFloatGrid negativeImagePotential = receptor.GetNegativeImageGrid();
    float outerContourLevel = receptor.GetOuterContourLevel();

        uint outerCount = 0;
        for (uint i=0; i<negativeImagePotential.GetSize();++i)
        {
            if (negativeImagePotential.GetValue(i) >= outerContourLevel)
            {
                outerCount += 1;
            }
        }
        double countToVolume = Math.Pow(negativeImagePotential.GetSpacing(),3);

        Console.WriteLine("{0} cubic Angstroms", outerCount * countToVolume);
    }
}

Toggle Receptor Inner Contour

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

See also

Listing 7: Toggle Receptor Inner Contour

/*
(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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEBio;
using OpenEye.OEDocking;

public class ToggleInnerContour
{
  public static void Main(string[] argv)
  {
    if (argv.Length != 1)
    {
      OEChem.OEThrow.Usage("ToggleInnerContour <receptor>");
    }

    OEDesignUnit du = new OEDesignUnit();
    if (!OEBio.OEReadDesignUnit(argv[0], du))
      OEChem.OEThrow.Fatal("Unable to open receptor du file");

    if (!du.HasReceptor())
      OEChem.OEThrow.Fatal("Design unit " + du.GetTitle() + " does not contain a receptor");

    OpenEye.OEBio.OEReceptor receptor = du.GetReceptor();
    float innerContourLevel = receptor.GetInnerContourLevel();
    receptor.SetInnerContourLevel(-innerContourLevel);
    
    if (innerContourLevel > 0.0f)
    {
      Console.WriteLine("Toggling inner contour off");
    }
    else
    {
      Console.WriteLine("Toggling inner contour on");
    }

    if (!OEBio.OEWriteDesignUnit(argv[0], du))
    {

      OEChem.OEThrow.Fatal("Unable to write updated receptor");
    }
  }
}

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

/*
(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.
*/
using System;
using System.Collections.Generic;
using OpenEye.OEChem;
using OpenEye.OEBio;
using OpenEye.OEDocking;

public class SetOuterContourVolume
{
  public static void Main(string[] argv)
  {
    if (argv.Length != 2)
    {
      OEChem.OEThrow.Usage("SetOuterContourVolume <receptor> <volume>");
    }

    OEDesignUnit du = new OEDesignUnit();
    if (!OEBio.OEReadDesignUnit(argv[0], du))
      OEChem.OEThrow.Fatal("Unable to open receptor file");
    if (!du.HasReceptor())
      OEChem.OEThrow.Fatal("Design unit " + du.GetTitle() + " does not contain a receptor");

    OpenEye.OEBio.OEReceptor receptor = du.GetReceptor();

    float outerContourVolume = float.Parse(argv[1]);

    OEFloatGrid negativeImagePotential = receptor.GetNegativeImageGrid();

    List<float> gridElement = new List<float>();
    for (uint i = 0; i < negativeImagePotential.GetSize(); i++)
    {
      gridElement.Add(negativeImagePotential.GetValue(i));
    }
    gridElement.Sort();
    gridElement.Reverse();

    float outerContourLevel = gridElement[gridElement.Count - 1];
    float countToVolume = (float)Math.Pow(negativeImagePotential.GetSpacing(), 3);
    int ilevel = (int)Math.Round(outerContourVolume / countToVolume);
    if (ilevel < gridElement.Count)
    {
      outerContourLevel = gridElement[ilevel];
    }

    receptor.SetOuterContourLevel(outerContourLevel);

    if (!OEBio.OEWriteDesignUnit(argv[0], du))
    {
      OEChem.OEThrow.Fatal("Unable to write updated receptor");
    }
  }
}