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

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

/* 
(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.
*/
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();
  }

}

Download code

DockMolecules.cs

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) 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.
*/
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

";

}

Download code

RescorePoses.cs

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.

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

/* 
(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.
*/
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");

        oeifstream rfs = new oeifstream();
        if (!rfs.open(opts.GetRefFile()))
            OEChem.OEThrow.Fatal("Unable to open " + opts.GetRefFile() + " for reading");

        oeofstream ofs = new oeofstream();
        if (!ofs.open(opts.GetOutFile()))
            OEChem.OEThrow.Fatal("Unable to open " + opts.GetOutFile() + " for writing");

        OEPosit poser = new OEPosit(positOpts);

        OEDesignUnit du = new OEDesignUnit();
        uint count = 0;
        while (OEBio.OEReadDesignUnit(rfs, du))
        {
            if (!du.HasReceptor())
                OEChem.OEThrow.Fatal("Design unit " + du.GetTitle() + " does not contain a receptor");
            poser.AddReceptor(du);
            count += 1;
        }
        if (count == 0)
            OEChem.OEThrow.Fatal("Input design unit does not contain any receptor");

        foreach (OEMol mcmol in ifs.GetOEMols())
        {
            OEChem.OEThrow.Info("posing " + mcmol.GetTitle());
            OESinglePoseResult result = new OESinglePoseResult();
            uint returnCode = poser.Dock(result, mcmol);

            if (returnCode == OEDockingReturnCode.Success)
            {
                OEDesignUnit posedDU = new OEDesignUnit(result.GetDesignUnit());
                posedDU.SetDoubleData(poser.GetName(), result.GetProbability());
                OEChem.OEThrow.Info("Receptor used: " + posedDU.GetTitle() + " pose probability: " + result.GetProbability());
                OEBio.OEWriteDesignUnit(ofs, posedDU);
            }
            else
            {
                string errMsg = OEDocking.OEDockingReturnCodeGetName(returnCode);
                OEChem.OEThrow.Warning(mcmol.GetTitle() + " : " + errMsg);
            }
        }

        ofs.close();
        ifs.close();
        rfs.close();
    }
}

Download code

PoseMolecules.cs

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

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

public class MyOptions : OEPositOptions
{
    public MyOptions() : base()
    {
        OEUIntParameter param1 = new OEUIntParameter("-numPoses", 1);
        param1.AddLegalRange("1", "20");
        param1.SetBrief("Number of poses to generate");
        _param1 = AddParameter(param1);
    }

    public uint GetNumPoses()
    {
        if (_param1.GetHasValue())
            return (uint.Parse(_param1.GetStringValue()));
        return (uint.Parse(_param1.GetStringDefault()));
    }

    OEParameter _param1;
}

public class PoseMolecules
{
    public static void Main(string[] argv)
    {
        MyOptions positOpts = new MyOptions();
        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");

        oeifstream rfs = new oeifstream();
        if (!rfs.open(opts.GetRefFile()))
            OEChem.OEThrow.Fatal("Unable to open " + opts.GetRefFile() + " for reading");

        oeofstream ofs = new oeofstream();
        if (!ofs.open(opts.GetOutFile()))
            OEChem.OEThrow.Fatal("Unable to open " + opts.GetOutFile() + " for writing");

        OEPosit poser = new OEPosit(positOpts);

        OEDesignUnit du = new OEDesignUnit();
        uint count = 0;
        while (OEBio.OEReadDesignUnit(rfs, du))
        {
            if (!du.HasReceptor())
                OEChem.OEThrow.Fatal("Design unit " + du.GetTitle() + " does not contain a receptor");
            poser.AddReceptor(du);
            count += 1;
        }
        if (count == 0)
            OEChem.OEThrow.Fatal("Input design unit does not contain any receptor");

        OEChem.OEThrow.Info("Number of conformers: " + positOpts.GetNumPoses());
        OEChem.OEThrow.Info("Best receptor pose flag: " + positOpts.GetBestReceptorPoseOnly());

        foreach (OEMol mcmol in ifs.GetOEMols())
        {
            OEChem.OEThrow.Info("posing " + mcmol.GetTitle());
            OEPositResults results = new OEPositResults();
            uint returnCode = poser.Dock(results, mcmol, positOpts.GetNumPoses());

            if (returnCode == OEDockingReturnCode.Success)
            {
                foreach (OESinglePoseResult result in results.GetSinglePoseResults())
                {
                    OEDesignUnit posedDU = new OEDesignUnit(result.GetDesignUnit());
                    posedDU.SetDoubleData(poser.GetName(), result.GetProbability());
                    OEChem.OEThrow.Info("Receptor used: " + posedDU.GetTitle() + " pose probability: " + result.GetProbability());
                    OEBio.OEWriteDesignUnit(ofs, posedDU);
                }
            }
            else
            {
                string errMsg = OEDocking.OEDockingReturnCodeGetName(returnCode);
                OEChem.OEThrow.Warning(mcmol.GetTitle() + " : " + errMsg);
            }
        }

        ofs.close();
        ifs.close();
        rfs.close();
    }
}

Download code

GenerateMultiplePose.cs

Receptor Examples

Making Receptor

The following code example shows how to make a receptor.

See also

Listing 6: Making Receptor

/* 
(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.
*/
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");

    }
  }
}

Download code

MakeReceptor.cs

Receptor Contour Volume

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

See also

Listing 7: Receptor Contour Volume

/* 
(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.
*/
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 8: Toggle Receptor Inner Contour

/* 
(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.
*/
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");
    }
  }
}

Download code

ToggleInnerContour.cs

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

/* 
(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.
*/
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");
    }
  }
}

Download code

SetOuterContourVolume.cs