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.
*/
package openeye.examples.oedocking;

import java.net.URL;
import openeye.oechem.*;
import openeye.oebio.*;
import openeye.oedocking.*;

public class DockMolecules {

    public static void main(String[] args) {

        OEDockOptions dockOpts = new OEDockOptions();
        
        OERefInputAppOptions opts = new OERefInputAppOptions(dockOpts, "DockMolecules", OEFileStringType.Mol3D,
            OEFileStringType.Mol3D, OEFileStringType.DU, "-receptor");

        if (oechem.OEConfigureOpts(opts, args, false) == OEOptsConfigureStatus.Help)
            System.exit(0);

        dockOpts.UpdateValues(opts);

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

        OEMol mol = new OEMol();
        while (oechem.OEReadMolecule(ifs, mol)) {

            System.err.format("docking %s\n", mol.GetTitle());
            OEGraphMol dockedMol = new OEGraphMol();
            int retCode = dock.DockMultiConformerMolecule(dockedMol, mol);
            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.
*/
package openeye.examples.oedocking;

import java.net.URL;
import openeye.oechem.*;
import openeye.oebio.*;
import 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");
        }

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

        OEMol ligand = new OEMol();
        boolean 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);
        }
        omstr.close();
        imstr.close();
    }

    public static void main(String argv[]) {
        RescorePoses app = new RescorePoses();
        URL fileURL = app.getClass().getResource("RescorePoses.txt");

        try {
            OEInterface itf = new OEInterface();
            oechem.OEConfigureFromURL(itf, fileURL);
            oedocking.OEScoreTypeConfigure(itf, "-score");
            if (oechem.OEParseCommandLine(itf, argv)) {
                app.rescore(itf);
            }
        } catch (java.io.IOException e) {
            System.err.println("Unable to open interface file");
        }
    }
}

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.
*/
package openeye.examples.oedocking;

import java.net.URL;
import openeye.oechem.*;
import openeye.oebio.*;
import openeye.oedocking.*;

public class PoseMolecules {

    public static void main(String[] args) {

        OEPositOptions positOpts = new OEPositOptions();
        OERefInputAppOptions opts = new OERefInputAppOptions(positOpts, "PoseMolecules", OEFileStringType.Mol3D,
            OEFileStringType.DU, OEFileStringType.DU, "-receptor");

        if (oechem.OEConfigureOpts(opts, args, false) == OEOptsConfigureStatus.Help)
            System.exit(0);

        positOpts.UpdateValues(opts);

        oemolistream ifs = new oemolistream(opts.GetInFile());
        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);

        OEMol mcmol = new OEMol();
        while (oechem.OEReadMolecule(ifs, mcmol)) {
            System.err.format("posing %s\n", mcmol.GetTitle());
            OESinglePoseResult result = new OESinglePoseResult();
            int returnCode = poser.Dock(result, mcmol);

            if (returnCode == OEDockingReturnCode.Success) {
                OEDesignUnit posedDU = new OEDesignUnit(result.GetDesignUnit());
                posedDU.SetDoubleData(poser.GetName(), result.GetProbability());
                oebio.OEWriteDesignUnit(ofs, posedDU);
            }
            else {
                oechem.OEThrow.Warning("Docking failed for molecule " +
                    mcmol.GetTitle() + " with return code " + Integer.toString(returnCode));
            }
        }
        ofs.close();
        ifs.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.
*/
package openeye.examples.oedocking;

import java.net.URL;

import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;

import openeye.oechem.*;
import openeye.oebio.*;
import openeye.oedocking.*;

public class PoseMolsMultiReceptor {

  private void pose(OEInterface itf) {
      OEPosit poser = new OEPosit();

      for (String receptor_filename : itf.GetStringList("-receptors")) {

        OEDesignUnit du = new OEDesignUnit();
        if (!oebio.OEReadDesignUnit(receptor_filename, du)){
          oechem.OEThrow.Fatal("Unable to read receptor");
        }
        poser.AddReceptor(du);
      }

      oemolistream imstr = new oemolistream(itf.GetString("-in"));
      oeofstream ostr = new oeofstream(itf.GetString("-out"));
      OEMol mcmol = new OEMol();
      while (oechem.OEReadMolecule(imstr, mcmol)) {
        System.err.format("posing %s\n", mcmol.GetTitle());
        OESinglePoseResult result = new OESinglePoseResult();
        int returnCode = poser.Dock(result, mcmol);

        if (returnCode == OEDockingReturnCode.Success) {
          OEDesignUnit posedDU = new OEDesignUnit(result.GetDesignUnit());
          posedDU.SetDoubleData(poser.GetName(), result.GetProbability());
          oebio.OEWriteDesignUnit(ostr, posedDU);
        }
        else
          oechem.OEThrow.Warning("Docking failed for molecule " +
            mcmol.GetTitle() + " with return code " + Integer.toString(returnCode));
      }
      imstr.close();
      ostr.close();
    }

    public static void main(String argv[]) {
        PoseMolsMultiReceptor app = new PoseMolsMultiReceptor();
        URL fileURL = app.getClass().getResource("PoseMolsMultiReceptor.txt");

        try {
            OEInterface itf = new OEInterface();
            oechem.OEConfigureFromURL(itf, fileURL);
            if (oechem.OEParseCommandLine(itf, argv)) {
                app.pose(itf);
            }
        } catch (java.io.IOException e) {
            System.err.println("Unable to open interface file");
        }
    }
  }

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.
*/
package openeye.examples.oedocking;

import openeye.oechem.*;
import openeye.oedocking.*;
import openeye.oebio.*;

public class MakeReceptor {

    public static void main(String[] args) {
        OEMakeReceptorOptions recOpts = new OEMakeReceptorOptions();
        OESimpleAppOptions opts = new OESimpleAppOptions(recOpts, "MakeReceptor", OEFileStringType.DU, OEFileStringType.DU);

        if (oechem.OEConfigureOpts(opts, args, false) == OEOptsConfigureStatus.Help)
            System.exit(0);

        recOpts.UpdateValues(opts);

        oeifstream ifs = new oeifstream(opts.GetInFile());
        oeofstream ofs = new oeofstream(opts.GetOutFile());
        OEDesignUnit du = 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");

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

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.
*/
package openeye.examples.oedocking;

import openeye.oechem.*;
import openeye.oebio.*;
import 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();

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

        System.err.format("%.2f cubic Angstroms\n", 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.
*/
package openeye.examples.oedocking;

import openeye.oechem.*;
import openeye.oebio.*;
import openeye.oedocking.*;

public class ToggleInnerContour {
    static {
        oechem.OEThrow.SetStrict(true);
    }

    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");


        OEReceptor receptor = du.GetReceptor();

        float 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 (!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.
*/
package openeye.examples.oedocking;

import java.util.ArrayList;
import java.util.Collections;
import openeye.oechem.*;
import openeye.oebio.*;
import 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");

        OEReceptor receptor = du.GetReceptor();

        float outerContourVolume = Float.valueOf(argv[1].trim()).floatValue();

        OEFloatGrid negativeImagePotential = receptor.GetNegativeImageGrid();

        ArrayList<Float> gridElement = new ArrayList<Float>();
        for (int i=0;i < negativeImagePotential.GetSize(); i++) {
            gridElement.add(negativeImagePotential.GetValue(i));
        }
        Collections.sort(gridElement, Collections.reverseOrder());

        float outerContourLevel = gridElement.get(gridElement.size()-1);
        float countToVolume = (float)Math.pow(negativeImagePotential.GetSpacing(),3);
        int ilevel = Math.round(outerContourVolume / countToVolume);
        if (ilevel < gridElement.size()) {
            outerContourLevel = gridElement.get(ilevel);
        }

        receptor.SetOuterContourLevel(outerContourLevel);

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