Calculating Overlap

Overlap calculation is the simplest functionality offered through the Shape TK. These examples show how to calculate static overlap between two objects (molecules, grids or shape query). Note that static means that the two input species (ref and fit) are not moved at all. These examples simply calculate the overlap and/or other related quantities, given the input positions. Examples for performing calculations that actually optimize the alignment/overlap are considered in a separate section.

Simple Overlap

This example reads in a reference molecule and a few fit molecules and prints out the Exact overlap calculated.

Listing 1: Simple overlap using Exact Overlap

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

import openeye.oechem.*;
import openeye.oeshape.*;

public class SimpleOverlap {

    public static void main(String[] args) {
        if (args.length!=2) {
            System.out.println("SimpleOverlap <reffile> <fitfile>");
            System.exit(0);
        }

        oemolistream reffs = new oemolistream(args[0]);
        oemolistream fitfs = new oemolistream(args[1]);

        OEGraphMol refmol = new OEGraphMol();
        oechem.OEReadMolecule(reffs, refmol);
        reffs.close();

        // Prepare reference molecule for calculation
        // With default options this will remove any explicit hydrogens present
        OEOverlapPrep prep = new OEOverlapPrep();
        prep.Prep(refmol);

        // Get appropriate function to calculate exact shape
        OEExactShapeFunc shapeFunc = new OEExactShapeFunc();
        shapeFunc.SetupRef(refmol);

        OEOverlapResults res = new OEOverlapResults();
        OEGraphMol fitmol = new OEGraphMol();
        while (oechem.OEReadMolecule(fitfs, fitmol)) {
            prep.Prep(fitmol);
            shapeFunc.Overlap(fitmol, res);
            System.out.print(fitmol.GetTitle());
            System.out.println(" exact tanimoto = "+res.GetTanimoto());
        }
    }
}

Download code

SimpleOverlap.java

Adding overlap to molecules

This next example program uses the Analytic overlap method and also uses a little extra OEChem to attach the overlap scores to each molecule as SD data. This can be used to rescore a set of ROCS hits or to measure the overlap of ROCS alignments against an exclusion region in the binding site.

Listing 2: Rescoring pre-aligned structures

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

import openeye.oechem.*;
import openeye.oeshape.*;

public class Rescore {

    public static void main(String[] args) {
        if (args.length!=3) {
            System.out.println("Rescore <reffile> <rocs_hits> <output.sdf>");
            System.exit(0);
        }

        oemolistream reffs = new oemolistream(args[0]);
        oemolistream fitfs = new oemolistream(args[1]);
        oemolostream outfs = new oemolostream(args[2]);

        OEGraphMol refmol = new OEGraphMol();
        oechem.OEReadMolecule(reffs, refmol);
        reffs.close();

        // Get appropriate function to calculate analytic shape
        OEAnalyticShapeFunc shapeFunc = new OEAnalyticShapeFunc();
        shapeFunc.SetupRef(refmol);

        OEOverlapResults res = new OEOverlapResults();
        OEGraphMol fitmol = new OEGraphMol();
        while (oechem.OEReadMolecule(fitfs, fitmol)) {
            shapeFunc.Overlap(fitmol, res);
            oechem.OESetSDData(fitmol, "AnalyticTanimoto", 
                    String.valueOf(res.GetTanimoto()));
            oechem.OEWriteMolecule(outfs, fitmol);
        }
    }
}

Download code

Rescore.java

Color Overlap

This example reads in a reference molecule and a few fit molecules and prints out the Exact color score calculated. By default all color calculations are performed using the ImplicitMillsDean force field.

Listing 3: Calculating color score

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

import openeye.oechem.*;
import openeye.oeshape.*;

public class ColorOverlap {

    public static void main(String[] args) {
        if (args.length!=2) {
            System.out.println("ColorOverlap <reffile> <overlayfile>");
            System.exit(0);
        }

        oemolistream reffs = new oemolistream(args[0]);
        oemolistream fitfs = new oemolistream(args[1]);

        OEGraphMol refmol = new OEGraphMol();
        oechem.OEReadMolecule(reffs, refmol);
        reffs.close();

        // Prepare reference molecule for calculation
        // With default options this will remove any explicit 
        // hydrogens present, and add required color atoms
        OEOverlapPrep prep = new OEOverlapPrep();
        prep.Prep(refmol);

        // Get appropriate function to calculate exact color
        OEExactColorFunc colorFunc = new OEExactColorFunc();
        colorFunc.SetupRef(refmol);

        OEOverlapResults res = new OEOverlapResults();
        OEGraphMol fitmol = new OEGraphMol();
        while (oechem.OEReadMolecule(fitfs, fitmol)) {
            prep.Prep(fitmol);
            colorFunc.Overlap(fitmol, res);
            System.out.print("Fit. Title: "+fitmol.GetTitle()+" ");
            System.out.print("Color Score: "+res.GetColorScore()+" ");
        } 
    }
}

Download code

ColorOverlap.java

Adding color score to molecules

This next example uses the ImplicitMillsDean force field and the Analytic color to rescore a set of ROCS hits and add the color scores to SD tags.

Listing 4: Using color to add scores to pre-aligned 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.
*/
package openeye.examples.oeshape;

import openeye.oechem.*;
import openeye.oeshape.*;

public class ColorScore {

    public static void main(String[] args) {
        if (args.length!=3) {
            System.out.println("ColorScore <reffile> <overlayfile> <outfile>");
            System.exit(0);
        }

        oemolistream reffs = new oemolistream(args[0]);
        oemolistream fitfs = new oemolistream(args[1]);
        oemolostream outfs = new oemolostream(args[2]);

        OEGraphMol refmol = new OEGraphMol();
        oechem.OEReadMolecule(reffs, refmol);
        reffs.close();

        // Prepare reference molecule for calculation
        // With default options this will add required color atoms
        OEOverlapPrep prep = new OEOverlapPrep();
        prep.Prep(refmol);

        // Get appropriate function to calculate analytic color
        OEAnalyticColorFunc colorFunc = new OEAnalyticColorFunc();
        colorFunc.SetupRef(refmol);

        OEOverlapResults res = new OEOverlapResults();
        OEGraphMol fitmol = new OEGraphMol();
        while (oechem.OEReadMolecule(fitfs, fitmol)) {
            prep.Prep(fitmol);
            colorFunc.Overlap(fitmol, res);
            oechem.OESetSDData(fitmol, "MyColorTanimoto", String.valueOf(res.GetColorTanimoto()));
            oechem.OESetSDData(fitmol, "MyColorScore",  String.valueOf(res.GetColorScore()));
            oechem.OEWriteMolecule(outfs, fitmol);

            System.out.print("Fit. Title: "+fitmol.GetTitle()+" ");
            System.out.print("Color Tanimoto: "+res.GetColorTanimoto()+" ");
            System.out.print("Color Score: "+res.GetColorScore()+" ");
        } 
    }
}

Download code

ColorScore.java

User Defined Color

As a step toward writing a complete color force field, it is possible to combine built-in rules for color atom assignment with user defined interactions. A new OEColorForceField object can be created using one of the built-in types, then the interactions can be cleared using OEColorForceField.ClearInteractions and subsequent user interactions added with OEColorForceField.AddInteraction.

For example, to use the ImplicitMillsDean atom typing rules, but to only consider donor-donor and acceptor-acceptor interactions, one can use the following:

Listing 5: Using ImplicitMillsDean with user interactions.

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

import openeye.oechem.*;
import openeye.oeshape.*;

public class UserColor {

    public static void main(String[] args) {
        if (args.length!=2) {
            System.out.println("UserColor <reffile> <overlayfile>");
            System.exit(0);
        }

        oemolistream reffs = new oemolistream(args[0]);
        oemolistream fitfs = new oemolistream(args[1]);

        OEGraphMol refmol = new OEGraphMol();
        oechem.OEReadMolecule(reffs, refmol);
        reffs.close();

        // Modify ImplicitMillsDean color force field by
        // adding user defined color interactions
        OEColorForceField cff = new OEColorForceField();
        cff.Init(OEColorFFType.ImplicitMillsDean);
        cff.ClearInteractions();
        int donorType = cff.GetType("donor");
        int accepType = cff.GetType("acceptor");
        cff.AddInteraction(donorType, donorType, "gaussian", -1.0f, 1.0f);
        cff.AddInteraction(accepType, accepType, "gaussian", -1.0f, 1.0f);

        // Prepare reference molecule for calculation
        // With default options this will add required color atoms
        // Set the modified color force field for addignment
        OEOverlapPrep prep = new OEOverlapPrep();
        prep.SetColorForceField(cff);
        prep.Prep(refmol);

        // Get appropriate function to calculate exact color
        // Set appropriate options to use the user defined color
        OEColorOptions options = new OEColorOptions();
        options.SetColorForceField(cff);
        OEExactColorFunc colorFunc = new OEExactColorFunc(options);
        colorFunc.SetupRef(refmol);

        OEOverlapResults res = new OEOverlapResults();
        OEGraphMol fitmol = new OEGraphMol();
        while (oechem.OEReadMolecule(fitfs, fitmol)) {
            prep.Prep(fitmol);
            colorFunc.Overlap(fitmol, res);
            System.out.print("Fit. Title: "+fitmol.GetTitle()+" ");
            System.out.println("Color TAnimoto: "+res.GetColorTanimoto());
        } 
    }
}

Download code

UserColor.java

Shape and Color Overlap

This example reads in a reference molecule and a few fit molecules and prints out both the shape overlap and the color score calculated. By default the OEOverlapFunc uses the Grid shape and Exact color.

Listing 6: Calculating both shape and color overlap

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

import openeye.oechem.*;
import openeye.oeshape.*;

public class OverlapColor {

    public static void main(String[] args) {
        if (args.length!=2) {
            System.out.println("OverlapColor <reffile> <fitfile>");
            System.exit(0);
        }

        oemolistream reffs = new oemolistream(args[0]);
        oemolistream fitfs = new oemolistream(args[1]);

        OEGraphMol refmol = new OEGraphMol();
        oechem.OEReadMolecule(reffs, refmol);
        reffs.close();

        // Prepare reference molecule for calculation
        // With default options this will remove any explicit hydrogens present
        OEOverlapPrep prep = new OEOverlapPrep();
        prep.Prep(refmol);

        // Get appropriate function to calculate both shape and color
        // By default the OEOverlapFunc contains OEGridShapeFunc for shape 
        // and OEExactColorFunc for color
        OEOverlapFunc func = new OEOverlapFunc();
        func.SetupRef(refmol);

        OEOverlapResults res = new OEOverlapResults();
        OEGraphMol fitmol = new OEGraphMol();
        while (oechem.OEReadMolecule(fitfs, fitmol)) {
            prep.Prep(fitmol);
            func.Overlap(fitmol, res);
            System.out.print(fitmol.GetTitle());
            System.out.println(" tanimoto combo = "+res.GetTanimotoCombo());
            System.out.println(" shape tanimoto = "+res.GetTanimoto());
            System.out.println(" color tanimoto = "+res.GetColorTanimoto());
        }
    }
}

Download code

OverlapColor.java

ROCS

The high-level OEROCS provides the simplest way to maximize shape and/or color between two objects. OEROCS uses the same shape and color functions as used for static overlap calculation, but optimizes the overlap between the reference and the fit objects. By default both shape and color optimization is performed, with shape estimated with the Grid method and color estimated with the Exact method.

The fit object is not moved during the optimization. Part of the results returned from the calculation are the transform required to move the fit object into the final orientation. The results also contain a copy of the fit molecule conformer(s) in its final orientation.

A helper function OEROCSOverlay is created for the most simple usage of the functionality that performs optimizations between a set of conformers and returns the best hit.

Best Hit

This example reads in a reference molecule and a fit molecule, performs overlay optimization, finds the best hit conformer and prints it out in final orientation.

Listing 7: Finding best hit conformer pair

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

import openeye.oechem.*;
import openeye.oeshape.*;

public class BestHit {

    public static void main(String[] args) {
        if (args.length!=3) {
            System.out.println("BestHit <reffile> <fitfile> <outfile>");
            System.exit(0);
        }

        oemolistream reffs = new oemolistream(args[0]);
        oemolistream fitfs = new oemolistream(args[1]);
        oemolostream outfs = new oemolostream(args[2]);

        OEMol refmol = new OEMol();
        oechem.OEReadMolecule(reffs, refmol);
        reffs.close();

        OEMol fitmol = new OEMol();
        oechem.OEReadMolecule(fitfs, fitmol);
        fitfs.close();

        OEROCSResult res = new OEROCSResult();
        oeshape.OEROCSOverlay(res, refmol, fitmol);
        OEMolBase outmol = res.GetOverlayConf();

        oechem.OEWriteMolecule(outfs, outmol);
        System.out.println("Tanimoto combo = "+res.GetTanimotoCombo());
    }
}

Download code

BestHit.java

Top Hits

This example reads in a reference molecule and a few fit molecules, performs overlay optimization, finds the few top hits, and prints them out in final orientation.

Listing 8: Finding top ROCS hits

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

import openeye.oechem.*;
import openeye.oeshape.*;

public class TopHits {

    public static void main(String[] args) {
        if (args.length!=4) {
            System.out.println("TopHits <reffile> <fitfile> <outfile> <nhits>");
            System.exit(0);
        }

        oemolistream reffs = new oemolistream(args[0]);
        oemolistream fitfs = new oemolistream(args[1]);
        oemolostream outfs = new oemolostream(args[2]);
        int nhits = Integer.parseInt(args[3]);

        OEMol refmol = new OEMol();
        oechem.OEReadMolecule(reffs, refmol);
        reffs.close();

        // Setup OEROCS with specified number of best hits
        OEROCSOptions options = new OEROCSOptions();
        options.SetNumBestHits(nhits);
        OEROCS rocs = new OEROCS(options);
        rocs.SetDatabase(fitfs);

        for (OEROCSResult res : rocs.Overlay(refmol))
        {
            OEGraphMol outmol = new OEGraphMol(res.GetOverlayConf());
            oechem.OEWriteMolecule(outfs, outmol);
            System.out.println(" title = "+outmol.GetTitle());
            System.out.println(" tanimoto combo = "+res.GetTanimotoCombo());
        }
    }
}

Download code

TopHits.java

Top Hits with Multiple Conformers

This example repeats the Top Hits example above but fixes the number of hits to 3 and asks for multiple best conformers for each hit reported.

Listing 9: Finding top ROCS hits with multiple conformers

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

import openeye.oechem.*;
import openeye.oeshape.*;

public class TopHitsConf {

    public static void main(String[] args) {
        if (args.length!=4) {
            System.out.println("TopHitsConf <reffile> <fitfile> <outfile> <confsperhit>");
            System.exit(0);
        }

        oemolistream reffs = new oemolistream(args[0]);
        oemolistream fitfs = new oemolistream(args[1]);
        oemolostream outfs = new oemolostream(args[2]);
        int nconfs = Integer.parseInt(args[3]);

        OEMol refmol = new OEMol();
        oechem.OEReadMolecule(reffs, refmol);
        reffs.close();

        // Setup OEROCS with specified number of best hits
        OEROCSOptions options = new OEROCSOptions();
        options.SetNumBestHits(3);
        options.SetConfsPerHit(nconfs);
        OEROCS rocs = new OEROCS(options);
        rocs.SetDatabase(fitfs);

        for (OEROCSResult res : rocs.Overlay(refmol))
        {
            OEMol outmol = new OEMol(res.GetOverlayConfs());
            oechem.OEWriteMolecule(outfs, outmol);
            System.out.println(" title = "+outmol.GetTitle());
            System.out.println(" tanimoto combo = "+res.GetTanimotoCombo());
        }
    }
}

Download code

TopHitsConf.java

Overlay Optimization

The methods OEOverlay and OEMultiRefOverlay, compared to OEROCS, allow setting up a reference system and process overlay optimization of multiple fit molecules. Another difference is that both OEOverlay and OEMultiRefOverlay, in addition to providing the best overlay score, also give access to all the results obtained during an overlay optimization. Methods OEOverlay and OEMultiRefOverlay, which provide all results, should be used only when such a rigorous amount of resulting data is desired.

Best Optimization Result

This example reads in a reference molecule and a few fit molecules, performs overlay optimization, and returns only the best result per reference to fit molecule overlay optimization.

Listing 10: Getting the best scores from OEMultiRefOverlay.

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

package openeye.examples.oeshape;

import openeye.oechem.*;
import openeye.oeshape.*;

public class OverlayBestRes {

    public static void main(String[] args) {
        if (args.length!=2) {
            System.out.println("OverlayBestRes <reffile> <fitfile>");
            System.exit(0);
        }

        oemolistream reffs = new oemolistream(args[0]);
        oemolistream fitfs = new oemolistream(args[1]);

        OEMol refmol = new OEMol();
        oechem.OEReadMolecule(reffs, refmol);
        reffs.close();
        System.out.print("Ref. title: "+refmol.GetTitle()+" ");
        System.out.println("Num Confs: "+refmol.NumConfs());

        // Prepare reference molecule for calculation
        // With default options this will remove any explicit 
        // hydrogens present and add color atoms
        OEOverlapPrep prep = new OEOverlapPrep();
        prep.Prep(refmol);

        OEMultiRefOverlay overlay = new OEMultiRefOverlay(); 
        overlay.SetupRef(refmol);

        OEMol fitmol = new OEMol();
        while (oechem.OEReadMolecule(fitfs, fitmol)) {
            prep.Prep(fitmol);
            OEBestOverlayScore score = new OEBestOverlayScore();
            overlay.BestOverlay(score, fitmol, new OEHighestTanimoto());

            System.out.print("Fit. title: "+fitmol.GetTitle()+" ");
            System.out.print("FitConfIdx: "+score.GetFitConfIdx()+" ");
            System.out.print("RefConfIdx: "+score.GetRefConfIdx()+" ");
            System.out.println("Tanimoto Combo: "+score.GetTanimotoCombo());      
        }
        fitfs.close();
    }
}

Download code

OverlayBestRes.java

All Optimization Results

This example repeats the above, but uses Overlay to obtain all the results.

A single Overlay calculation will return N results, where N is the number of ref conformers times the number of fit conformers times the number of starting positions for each pair. So comparing 2 molecules with 10 conformers each could return 400 or more results.

There are two helper classes designed solely to contain these results and to make it easy to extract all or just the desired subset. OEBestOverlayResults holds the results of a single pair of conformers. It contains a set of OEBestOverlayScore objects, one for each starting position.

This example uses 2 iterators to show all the results.

Listing 11: Getting all the scores from OEMultiRefOverlay.

/* 
(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, and uses 2 iterators to
// show all the results.
// With the default options, OEOverlay optimizes both shape and color.

package openeye.examples.oeshape;

import openeye.oechem.*;
import openeye.oeshape.*;

public class OverlayAllRes {

    public static void main(String[] args) {
        if (args.length!=2) {
            System.out.println("OverlayAllRes <reffile> <fitfile>");
            System.exit(0);
        }

        oemolistream reffs = new oemolistream(args[0]);
        oemolistream fitfs = new oemolistream(args[1]);

        OEMol refmol = new OEMol();
        oechem.OEReadMolecule(reffs, refmol);
        reffs.close();
        System.out.print("Ref. title: "+refmol.GetTitle()+" ");
        System.out.println("Num Confs: "+refmol.NumConfs());

        // Prepare reference molecule for calculation
        // With default options this will remove any explicit 
        // hydrogens present and add color atoms
        OEOverlapPrep prep = new OEOverlapPrep();
        prep.Prep(refmol);          

        OEMultiRefOverlay overlay = new OEMultiRefOverlay();      
        overlay.SetupRef(refmol);

        OEMol fitmol = new OEMol();
        while (oechem.OEReadMolecule(fitfs, fitmol)) {
            System.out.print("Fit. title: "+fitmol.GetTitle()+" ");
            System.out.println("Num Confs: "+fitmol.NumConfs());

            prep.Prep(fitmol);
            int resCount=0;

            // double loop over results and scores to obtain all scores
            for (OEBestOverlayResults res : overlay.Overlay(fitmol)) {
                for (OEBestOverlayScore score : res.GetScores()) {
                    System.out.print("FitConfIdx: "+score.GetFitConfIdx()+" ");
                    System.out.print("RefConfIdx: "+score.GetRefConfIdx()+" ");
                    System.out.println("Tanimoto Combo: "+score.GetTanimotoCombo());
                    ++resCount;
                }
            }
            System.out.println(resCount+" results returned.");
        }
        fitfs.close();  
    }
}

Download code

OverlayAllRes.java

Manipulating all results

This example repeats the above to access all overlay results, and shows how to navigate through the results to extract a specific set. Here, the OESortOverlayScores function is used to turn the double iterator as shown in the example above into a single iterator of OEBestOverlayScore. Note that the third argument is a functor used to sort the list, such that in this next example, we get one OEBestOverlayScore for each pair of conformers, and they are returned in Tanimoto order.

OEOverlay or OEMultiRefOverlay does not actually move the fit molecule. Part of OEBestOverlayScore is the rotation matrix and translation matrix necessary to move the fit molecule into the final overlap position. (Note well: the rotation matrix is left-multiplied so can be regarded as left-handed.) This example also shows how to apply these transformations. The OpenEye standard is rotation then translation, but as a convenience, OEBestOverlayScore has OEBestOverlayScore.Transform method that will apply the transforms in the proper order.

This example keeps the user specified number of scores, aligns each fit conformer to the ref conformer it was overlaid on, and then write the pair to an output file. If SD or OEB is used as the output file type, then scores will also be stored in SD tags.

Listing 12: Writing few aligned structures from OEMultiRefOverlay.

/* 
(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, shows the user specified number of 
// results, and saves the overlayed structures.
// With the default options, OEOverlay optimizes both shape and color.

package openeye.examples.oeshape;

import openeye.oechem.*;
import openeye.oeshape.*;

public class OverlayStruct {

    public static void main(String[] args) {
        if (args.length!=4) {
            System.out.println("OverlayStruct <reffile> <fitfile> <out.sdf> <keepsize>");
            System.exit(0);
        }

        oemolistream reffs = new oemolistream(args[0]);
        oemolistream fitfs = new oemolistream(args[1]);
        oemolostream outfs = new oemolostream(args[2]);
        int keepsize = Integer.parseInt(args[3]);

        OEMol refmol = new OEMol();
        oechem.OEReadMolecule(reffs, refmol);
        System.out.print("Ref. title: "+refmol.GetTitle()+" ");
        System.out.println("Num Confs: "+refmol.NumConfs());
        reffs.close();

        // Prepare reference molecule for calculation
        // With default options this will remove any explicit 
        // hydrogens present and add color atoms
        OEOverlapPrep prep = new OEOverlapPrep();
        prep.Prep(refmol);

        OEMultiRefOverlay overlay = new OEMultiRefOverlay();
        overlay.SetupRef(refmol);

        OEMol fitmol = new OEMol();
        while (oechem.OEReadMolecule(fitfs, fitmol)) {
            System.out.print("Fit. title: "+fitmol.GetTitle()+" ");
            System.out.println("Num Confs: "+fitmol.NumConfs());       

            prep.Prep(fitmol);
            int resCount=0;

            // Sort all scores according to highest tanimoto 
            OEBestOverlayScoreIter scoreiter = new OEBestOverlayScoreIter();
            oeshape.OESortOverlayScores(scoreiter, overlay.Overlay(fitmol), new OEHighestTanimoto());

            for (OEBestOverlayScore score : scoreiter) {
                OEGraphMol outmol = new OEGraphMol(fitmol.GetConf(new OEHasConfIdx(score.GetFitConfIdx())));
                score.Transform(outmol);

                oechem.OESetSDData(outmol, "RefConfIdx", String.valueOf(score.GetRefConfIdx()));
                oechem.OESetSDData(outmol, "Tanimoto Combo", String.valueOf(score.GetTanimotoCombo()));

                oechem.OEWriteConstMolecule(outfs, refmol.GetConf(new OEHasConfIdx(score.GetRefConfIdx())));
                oechem.OEWriteConstMolecule(outfs, outmol);

                ++resCount;

                // Break at the user specified size
                if (resCount==keepsize)
                    break;
            }
            System.out.println(resCount+" results returned.");   
        }
        fitfs.close();
        outfs.close();   
    }
}

Download code

OverlayStruct.java

Working with Shape Query

This section of examples shows the use of a OEShapeQuery, and performs calculations where a shape query is used as the reference system instead of a molecule as the reference.

Creating a shape query

This examples shows how to create a simple shape query that combines a molecule with gaussians. In this example, the molecule is added in the query to define shape, and color is added separately in terms to gaussians. The created query is then saved in a file.

Listing 13: Creating a shape query.

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

import java.net.URL;
import openeye.oechem.*;
import openeye.oeshape.*;

public class CreateQuery {

    public static void main(String[] args) {
        OESimpleAppOptions opts = new OESimpleAppOptions("CreateQuery", OEFileStringType.Mol3D, "sq");
        if (oechem.OEConfigureOpts(opts, args, false) == OEOptsConfigureStatus.Help)
            System.exit(0);

        oemolistream ifs = new oemolistream();
        if (!ifs.open(opts.GetInFile()))
            oechem.OEThrow.Fatal("Unable to open " + opts.GetInFile() + " for reading");

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

        OEColorForceField cff = new OEColorForceField();
        cff.Init(OEColorFFType.ImplicitMillsDean);

        OEGraphMol mol = new OEGraphMol();
        while (oechem.OEReadMolecule(ifs, mol))
        {
            OEShapeQuery query = new OEShapeQuery();
            if (oeshape.OEMol2Query(query, mol, cff))
                oeshape.OEWriteShapeQuery(ofs, query);
            else
                oechem.OEThrow.Warning("Failed to create query from: " + mol.GetTitle());
        }

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

Download code

CreateQuery.java

Overlap with shape query

This example reads in a reference shape query and a few fit molecules and prints out both the shape overlap and the color score calculated. By default the OEOverlapFunc uses the Grid shape and Exact color.

Listing 14: Overlap with a shape query

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

import openeye.oechem.*;
import openeye.oeshape.*;

public class OverlapQuery {

    public static void main(String[] args) {
        if (args.length!=2) {
            System.out.println("OverlapQuery <queryfile> <fitfile>");
            System.exit(0);
        }

        String ext = oechem.OEGetFileExtension(args[0]);
        if (!ext.equals("sq"))
            oechem.OEThrow.Fatal("Requires a shape query .sq input file format");

        OEShapeQuery query = new OEShapeQuery();
        oeshape.OEReadShapeQuery(args[0], query);

        // Get appropriate function to calculate both shape and color
        // By default the OEOverlapFunc contains OEGridShapeFunc for shape
        // and OEExactColorFunc for color
        OEOverlapFunc func = new OEOverlapFunc();
        func.SetupRef(query);

        OEOverlapResults res = new OEOverlapResults();
        oemolistream fitfs = new oemolistream(args[1]);
        OEOverlapPrep prep = new OEOverlapPrep();
        OEGraphMol fitmol = new OEGraphMol();
        while (oechem.OEReadMolecule(fitfs, fitmol)) {
            prep.Prep(fitmol);
            func.Overlap(fitmol, res);
            System.out.print(fitmol.GetTitle());
            System.out.println(" tanimoto combo = "+res.GetTanimotoCombo());
            System.out.println(" shape tanimoto = "+res.GetTanimoto());
            System.out.println(" color tanimoto = "+res.GetColorTanimoto());
        }
    }
}

Download code

OverlapQuery.java

Top hit against shape query

This example reads in a reference query and a few fit molecules, performs overlay optimization, finds the few top hits, and prints them out in final orientation.

Listing 15: Finding top ROCS hits against a query

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

import openeye.oechem.*;
import openeye.oeshape.*;

public class TopHitsQuery {

    public static void main(String[] args) {
        if (args.length!=4) {
            System.out.println("TopHitsQuery <queryfile> <fitfile> <outfile> <nhits>");
            System.exit(0);
        }

        String ext = oechem.OEGetFileExtension(args[0]);
        if (!ext.equals("sq"))
            oechem.OEThrow.Fatal("Requires a shape query .sq input file format");

        oemolistream fitfs = new oemolistream(args[1]);
        oemolostream outfs = new oemolostream(args[2]);
        int nhits = Integer.parseInt(args[3]);

        OEShapeQuery query = new OEShapeQuery();
        oeshape.OEReadShapeQuery(args[0], query);

        // Setup OEROCS with specified number of best hits
        OEROCSOptions options = new OEROCSOptions();
        options.SetNumBestHits(nhits);
        OEROCS rocs = new OEROCS(options);
        rocs.SetDatabase(fitfs);

        for (OEROCSResult res : rocs.Overlay(query))
        {
            OEGraphMol outmol = new OEGraphMol(res.GetOverlayConf());
            oechem.OEWriteMolecule(outfs, outmol);
            System.out.println(" title = "+outmol.GetTitle());
            System.out.println(" tanimoto combo = "+res.GetTanimotoCombo());
        }
    }
}

Download code

TopHitsQuery.java

Shape from Hermite expansion

Using Hermite expansion we can obtain two functionalities: expand a molecule into Hermite representation and compare two molecules that are in the Hermite representation by computing their shape-Tanimoto coefficient. We illustrate both functionalities below with two examples.

Hermite expansion

In this example we input a molecule, set the level of Hermite expansion using NPolyMax variable, determine the optimal parameters for \(\lambda_x, \lambda_y, \lambda_z\), and perform the computation of the Hermite expansion. At the end we output the resulting Hermite representation of the molecule as a grid, using CreateGrid method of the OEHermite class. The user can vary NPolyMax from low numbers, like 4 or 5, to higher numbers like 10–30 and observe convergence of the shape. Which value to use in practice depends on the size of the input molecule. Input molecule can be drug-like as well as a protein.

Listing 16: Expanding a molecular shape into Hermite polynomials

/* 
(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 molecule and performs Hermite expansion of
//that molecule to a given order in the NPolyMax parameter and outputs
//the resulting Hermite approximated shape to a grid.

package openeye.examples.oeshape;

import openeye.oechem.*;
import openeye.oeshape.*;
import openeye.oegrid.*;
import java.net.URL;
import java.io.IOException;
import java.util.Vector;

public class HermiteExpansion {
    public static void main(String[] args) {
        URL fileURL = HermiteExpansion.class.getResource("HermiteExpansion.txt");
        OEInterface itf = null;
        try {
            itf = new OEInterface(fileURL, "HermiteExpansion", args);
        } catch(IOException e) {
            oechem.OEThrow.Fatal("Unable to open itf file");
        }

        // Get the input parameters from the OEInterface

        int NPolyMax = itf.GetInt("-NPolyMax");
        float gridspacing = itf.GetFloat("-gridspacing");
        String ifname = itf.GetString("-inputfile");
        String ofname = itf.GetString("-outputgrid");

        oemolistream ifs = new oemolistream();

        if (!ifs.open(ifname)) {
            oechem.OEThrow.Fatal("Unable to open " + ifname + " for reading");
        }


        if (!ofname.endsWith(".grd")) {
            oechem.OEThrow.Fatal("Output grid file extension hast to be '.grd' ");
        }   

        OEMol mol = new OEMol();

        if (!oechem.OEReadMolecule(ifs, mol)) {
            oechem.OEThrow.Fatal("Unable to read molecule in " + ifname);
        }

        OEOverlapPrep prep = new OEOverlapPrep();
        prep.SetAssignColor(false);
        prep.Prep(mol);    


        OETrans transfm = new OETrans();
        oeshape.OEOrientByMomentsOfInertia(mol, transfm);

        OEHermiteOptions hermiteoptions = new OEHermiteOptions();
        hermiteoptions.SetNPolyMax(NPolyMax);
        hermiteoptions.SetUseOptimalLambdas(true);

        OEHermite hermite = new OEHermite(hermiteoptions);

        if (!hermite.Setup(mol)) {
            oechem.OEThrow.Fatal("Was not able to Setup the molecule for the OEHermite class.");
        }

        OEHermiteOptions hopts = hermite.GetOptions();

        System.out.println("Best lambdas found X=" 
                            + String.valueOf(hopts.GetLambdaX()) + "  Y="
                            + String.valueOf(hopts.GetLambdaY()) + "  Z="
                            + String.valueOf(hopts.GetLambdaZ()));

        System.out.println("Hermite self-overlap =" + String.valueOf(hermite.GetSelfOverlap()));
        
        Vector<Double> coeffs = new  Vector<Double>();
        hermite.GetCoefficients(coeffs);

        String NPolyMaxstring = String.valueOf(NPolyMax);

        System.out.println("Hermite coefficients f_{l,m,n} in the following order l = 0..."
              + NPolyMaxstring + ", m = 0..." + NPolyMaxstring+"-l, n = " + NPolyMaxstring + "-l-m :");

        String coeff_str=coeffs.toString();

        System.out.println(coeff_str);

        OEScalarGrid grid = new OEScalarGrid();

        hermite.CreateGrid(grid, gridspacing, transfm);

        if (!oegrid.OEWriteGrid(ofname, grid)){
            oechem.OEThrow.Fatal("Unable to write grid file");
        }

    }

    
}

Download code

HermiteExpansion.java

Hermite Tanimoto comparison of shape

In the second example below, we set up two molecules and compute the Tanimoto shape similarity coefficient, using Hermite expansion. The Hermite prep parameter NPolyMax_MAX is used to vary the NPolyMax parameter and compute the shape-Tanimoto coefficient. First molecule in the reference input file is used versus all molecules in the fit input file. Results are attached as SD data to the moved fit molecule, as dictated by Hermite overlay, and sent to the output file. One can observe convergence of the Hermite Tanimoto coefficients as the level of expansion becomes more accurate.

Listing 17: Calculating shape Tanimoto using Hermite expansion

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

package openeye.examples.oeshape;

import openeye.oechem.*;
import openeye.oeshape.*;
import openeye.oegrid.*;
import java.net.URL;
import java.io.IOException;


public class HermiteTanimoto {
    public static void main(String[] args) {

        URL fileURL = HermiteTanimoto.class.getResource("HermiteTanimoto.txt");
        OEInterface itf = null;
        try {
            itf = new OEInterface(fileURL, "HermiteTanimoto", args);
        } catch(IOException e) {
            oechem.OEThrow.Fatal("Unable to open itf file");
        }

        int NPolyMax_MAX = itf.GetInt("-NPolyMax_MAX");
        String ifrefname = itf.GetString("-inputreffile");
        String iffitname = itf.GetString("-inputfitfile");
        String ofname = itf.GetString("-outputfile");

        oemolistream ifsref = new oemolistream();
        oemolistream ifsfit = new oemolistream();
        oemolostream ofs = new oemolostream();

        if (!ifsref.open(ifrefname)){
            oechem.OEThrow.Fatal("Unable to open " + ifrefname + " file for reading" );
        }

        if (!ifsfit.open(iffitname)){
            oechem.OEThrow.Fatal("Unable to open " + iffitname + " file for reading" );
        }

        OEMol refmol = new OEMol();
        OEMol fitmol = new OEMol();

        if (!oechem.OEReadMolecule(ifsref, refmol)){
            oechem.OEThrow.Fatal("Unable to read molecule in " + ifrefname + " file");
        }

        OEOverlapPrep prep = new OEOverlapPrep();
        prep.SetAssignColor(false);
        prep.Prep(refmol);
        OETrans reftransfm = new OETrans();
        oeshape.OEOrientByMomentsOfInertia(refmol, reftransfm);

        if (!ofs.open(ofname)){
            oechem.OEThrow.Fatal("Unable to open " + ofname + " file for writing");
        }

        int idx = 0;
        OETrans transfm = new OETrans();
        while (oechem.OEReadMolecule(ifsfit, fitmol)){
            OEMol fitmol_copy = new OEMol(fitmol);
            System.out.println("Working on the fit molecule with idx = " + String.valueOf(idx) + "...");

            fitmol = fitmol_copy;
            prep.Prep(fitmol);
            oeshape.OEOrientByMomentsOfInertia(fitmol, transfm);

            OEHermiteOptions hermiteoptionsref = new OEHermiteOptions();
            hermiteoptionsref.SetNPolyMax(NPolyMax_MAX);
            hermiteoptionsref.SetUseOptimalLambdas(true);

            OEHermiteOptions hermiteoptionsfit = new OEHermiteOptions();
            hermiteoptionsfit.SetNPolyMax(NPolyMax_MAX);
            hermiteoptionsfit.SetUseOptimalLambdas(true);

            OEShapeOptions shape_options = new OEShapeOptions();
            OEHermiteShapeFunc hermiteshapeoverlap = new OEHermiteShapeFunc(shape_options, hermiteoptionsref, hermiteoptionsfit);

            OEOverlayOptions options = new OEOverlayOptions();
            options.SetOverlapFunc(hermiteshapeoverlap);
            OEOverlay overlay = new OEOverlay(options);
            overlay.SetupRef(refmol);

            OEBestOverlayScoreIter scoreiter = new OEBestOverlayScoreIter();
            oeshape.OESortOverlayScores(scoreiter, overlay.Overlay(new OEMol(fitmol)), new OEHighestTanimoto());

            double hermitetanimoto = -1.0;
            for (OEBestOverlayScore score : scoreiter) {
                hermitetanimoto = score.GetTanimoto();
                score.Transform(fitmol);
            }

            // Transform from the inertial frame to the original reference mol frame
            reftransfm.Transform(fitmol);

            System.out.println("Hermite Tanimoto = " + String.valueOf(hermitetanimoto));

            oechem.OESetSDData(fitmol, "HermiteTanimoto_"+String.valueOf(NPolyMax_MAX), String.valueOf(hermitetanimoto));
            oechem.OEWriteMolecule(ofs, fitmol);
            idx += 1;
        }
        ofs.flush();
        ofs.close();
    }
}

Download code

HermiteTanimoto.java

Flexible Overlay with Shape, Color, and Forcefield

By incorporating Forcefield into the overlay optimization alongside Shape and Color, molecular flexibility can be introduced to the input fit molecule conformers. The flexible overlay optimization approach maintains rigidity in the reference molecule conformer while allowing for flexibility in the fit molecules. To illustrate the functionality of flexible overlay, we provide two examples. Note that, the default settings for the OEFlexiOverlay perform optimization on both Shape and Color overlap while also considering intra-molecular forcefield.

It is important to note that when running flexible overlay optimization of a molecule against itself, the user should not expect to obtain a tanimotocombo value of 2.0. This is because the fit molecules undergo flexible optimization, which includes intra-molecular force field, and thus may result in some deviation from 2.0.

Flexible Overlay

In this example, Flexible overlay optimization of the fit molecules is performed against a single reference molecule conformer. Results of flexible overlay of all of the fit molecule conformers are reported and saved.

Flexible Best Overlay

In this example, Flexible overlay optimization of the fit molecules is performed against a single reference molecule conformer. The best overlaid conformers and the corresponding results are reported and saved.

Advanced Examples

Calculating NxN scores

There are times when you want to have all the pairwise scores among a set of molecules. Maintaining this 2D matrix of scores is more complicated than the single set of scores from the ref vs. set of fit molecules examples shown above.

This example takes a set of molecules and performs all the pairwise shape optimizations with OEBestOverlay. It outputs a spreadsheet of the scores.

Listing 20: Calculating NxN scores.

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

import openeye.oechem.*;
import openeye.oeshape.*;
import java.io.*;
import java.text.DecimalFormat;

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

    private static FileOutputStream csv;
    private static PrintWriter csvfile;
    private static DecimalFormat df = new DecimalFormat("#.##");

    private String roundOff(float score) {
        return df.format(score);
    }

    private void oneConf(OEConfBase conf, OEOverlapPrep prep, String filename) {
        csvfile.print(conf.GetTitle() + "_" + conf.GetIdx());
        OEMol refmol = new OEMol(conf);

        OEOverlayOptions options = new OEOverlayOptions();
        options.SetOverlapFunc(new OEGridShapeFunc());
        OEOverlay overlay = new OEOverlay();
        overlay.SetupRef(refmol);

        oemolistream bfs = new oemolistream(filename);
        OEMol fitmol = new OEMol();
        while (oechem.OEReadMolecule(bfs, fitmol)) {
            prep.Prep(fitmol);
            OEBestOverlayResultsIter resiter = overlay.Overlay(fitmol);
            OEBestOverlayScoreIter scoreiter = new OEBestOverlayScoreIter();
            oeshape.OESortOverlayScores(scoreiter, resiter, new OEHighestTanimoto(), 1, true);
            for (OEBestOverlayScore score : scoreiter) {
                csvfile.print("," + roundOff(score.GetTanimoto()));
            }
        }
    }

    private void genHeader(String filename) {
        csvfile.print("name");
        oemolistream ifs = new oemolistream(filename);
        OEMol mol = new OEMol();
        while (oechem.OEReadMolecule(ifs, mol)) {
            System.out.println(mol.GetTitle());
            for (OEConfBase conf : mol.GetConfs()) {
                csvfile.print("," + conf.GetTitle() + "_" + conf.GetIdx());
            }
        }
        ifs.close();
        csvfile.println();
    }

    private void openCSV(String csvfilename) {
        try {
            csv = new FileOutputStream(csvfilename);
            csvfile = new PrintWriter(csv);
        } catch (FileNotFoundException e) {
            System.err.println("Unable to open output file " + csvfilename);
        }
    }

    public void nxn(String filename, String csvfilename) {
        openCSV(csvfilename);
        genHeader(filename);
        OEOverlapPrep prep = new OEOverlapPrep();
        prep.SetAssignColor(false);
        oemolistream afs = new oemolistream(filename);
        OEMol molA = new OEMol();
        while (oechem.OEReadMolecule(afs, molA)) {
            prep.Prep(molA);
            for (OEConfBase conf : molA.GetConfs()) {
                oneConf(conf, prep, filename);
            }
        }
        csvfile.close();
        afs.close();
    }

    public static void main(String[] args) {
        if (args.length != 2) {
            System.out.println("NxNShape <infile> <csvfile>");
            System.exit(0);
        }
        NxNShape app = new NxNShape();
        app.nxn(args[0], args[1]);
    }
}

Download code

NxNShape.java

Calculating shape characteristics

While most functionality in the Shape Toolkit involves comparison of pairs of molecules, there are a few fundamental properties that can be calculated for a single molecule. All of these calculations are done using the same basic Gaussian description of a molecule as described above.

The simplest property to calculate is volume, using OECalcVolume.

In addition to simple volume calculations, the steric multipoles of a molecule can also be calculated. See section OECalcShapeMultipoles.

This next example demonstrates the calculation of volume and shape multipoles.

Listing 21: Calculating shape properties.

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

import openeye.oechem.*;
import openeye.oeshape.*;

public class ShapeProps {

    public static void main(String[] args) {
        if (args.length!=1) {
            System.out.println("ShapeProps <infile>");
            System.exit(0);
        }

        oemolistream ifs = new oemolistream(args[0]);

        OEGraphMol mol = new OEGraphMol();

        while (oechem.OEReadMolecule(ifs,mol)) {
            System.out.println("              Title: "+mol.GetTitle());
            System.out.println("             Volume: "+oeshape.OECalcVolume(mol));
            System.out.println("Volume: (without H): "+
                    oeshape.OECalcVolume(mol, false));

            float [] smult = new float[14];
            oeshape.OECalcShapeMultipoles(mol, smult);

            System.out.println("  Steric multipoles:");
            System.out.println("           monopole: "+smult[0]);
            System.out.println("        quadrupoles: "+ 
                    smult[1]+" "+smult[2]+" "+smult[3]);
            System.out.println("          octopoles:");
            System.out.println("                xxx: "+smult[4]+
                    " yyy: "+smult[5]+" zzz: "+smult[6]);
            System.out.println("                xxy: "+smult[7]+
                    " xxz: "+smult[8]+" yyx: "+smult[9]);
            System.out.println("                yyz: "+smult[10]+
                    " zzx: "+smult[11]+" zzy: "+smult[12]);
            System.out.println("                xyz: "+smult[13]);

            System.out.println("");
        }
        ifs.close();
    }
}

Download code

ShapeProps.java

Calculating excluded volume

This code demonstrates how to use the Shape toolkit to do an overlay to a crystallographic ligand, then calculate the overlap of the database molecule to the cognate protein. The output includes a new score Rescore which is the ShapeTanimotoCombo penalized by the fraction overlap.

A description of the command line interface can be obtained by executing the program with the –help argument.

prompt> java ExcludeVolume --help

will generate the following output:

-q : Query file name
-e : Protein to use as exclusion volume
-d : Database file name
-o : Output file name

Download code

ExcludeVolume.java and ExcludeVolume.txt interface file