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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class SimpleOverlap
{
public static void Main(string [] args)
{
if (args.Length != 2)
OEChem.OEThrow.Usage("UserColor <reffile> <fitfile>");
oemolistream reffs = new oemolistream(args[0]);
oemolistream fitfs = new oemolistream(args[1]);
OEGraphMol refmol = new OEGraphMol();
OEChem.OEReadMolecule(reffs, refmol);
// 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();
foreach (OEGraphMol fitmol in fitfs.GetOEGraphMols())
{
prep.Prep(fitmol);
shapeFunc.Overlap(fitmol, res);
Console.WriteLine("{0} exact tanimoto = {1}",
fitmol.GetTitle(), res.GetTanimoto());
}
}
}
Download code
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class Rescore
{
public static void Main(string [] args)
{
if (args.Length != 3)
OEChem.OEThrow.Usage("Rescore <reffile> <rocs_hits> <output.sdf>");
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);
// Get appropriate function to calculate analytic shape
OEAnalyticShapeFunc shapeFunc = new OEAnalyticShapeFunc();
shapeFunc.SetupRef(refmol);
OEOverlapResults res = new OEOverlapResults();
foreach (OEGraphMol fitmol in fitfs.GetOEGraphMols())
{
shapeFunc.Overlap(fitmol, res);
OEChem.OESetSDData(fitmol, "AnalyticTanimoto", Convert.ToString(res.GetTanimoto()));
OEChem.OEWriteMolecule(outfs, fitmol);
}
}
}
Download code
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class ColorOverlap
{
public static void Main(string [] args)
{
if (args.Length != 2)
OEChem.OEThrow.Usage("UserColor <reffile> <overlayfile>");
oemolistream reffs = new oemolistream(args[0]);
oemolistream fitfs = new oemolistream(args[1]);
OEGraphMol refmol = new OEGraphMol();
OEChem.OEReadMolecule(reffs, refmol);
// 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();
foreach (OEGraphMol fitmol in fitfs.GetOEGraphMols())
{
prep.Prep(fitmol);
colorFunc.Overlap(fitmol, res);
Console.WriteLine("{0} color score = {1}",
fitmol.GetTitle(), res.colorscore);
}
}
}
Download code
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class ColorScore
{
public static void Main(string [] args)
{
if (args.Length != 3)
OEChem.OEThrow.Usage("ColorScore <reffile> <rocs_hits_file> <output.sdf>");
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);
// 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();
foreach (OEGraphMol fitmol in fitfs.GetOEGraphMols())
{
prep.Prep(fitmol);
colorFunc.Overlap(fitmol, res);
OEChem.OESetSDData(fitmol, "MyColorTanimoto", Convert.ToString(res.GetColorTanimoto()));
OEChem.OESetSDData(fitmol, "MyColorScore", Convert.ToString(res.GetColorScore()));
OEShape.OERemoveColorAtoms(fitmol);
OEChem.OEWriteMolecule(outfs, fitmol);
Console.WriteLine("Fit Title: {0} ColorTanimoto: {1} Color score: {2}",
fitmol.GetTitle(), res.GetColorTanimoto(), res.GetColorScore());
}
}
}
Download code
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class UserColor
{
public static void Main(string [] args)
{
if (args.Length != 2)
OEChem.OEThrow.Usage("UserColor <reffile> <overlayfile>");
oemolistream reffs = new oemolistream(args[0]);
oemolistream fitfs = new oemolistream(args[1]);
OEGraphMol refmol = new OEGraphMol();
OEChem.OEReadMolecule(reffs, refmol);
// Modify ImplicitMillsDean color force field by
// adding user defined color interactions
OEColorForceField cff = new OEColorForceField();
cff.Init(OEColorFFType.ImplicitMillsDean);
cff.ClearInteractions();
uint donorType = cff.GetType("donor");
uint 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();
foreach (OEGraphMol fitmol in fitfs.GetOEGraphMols())
{
prep.Prep(fitmol);
colorFunc.Overlap(fitmol, res);
Console.WriteLine("Fit Title: {0} ColorTanimoto: {1}",
fitmol.GetTitle(),
res.GetColorTanimoto());
}
}
}
Download code
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class OverlapColor
{
public static void Main(string [] args)
{
if (args.Length != 2)
OEChem.OEThrow.Usage("OverlapColor <reffile> <fitfile>");
oemolistream reffs = new oemolistream(args[0]);
oemolistream fitfs = new oemolistream(args[1]);
OEGraphMol refmol = new OEGraphMol();
OEChem.OEReadMolecule(reffs, refmol);
// 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();
foreach (OEGraphMol fitmol in fitfs.GetOEGraphMols())
{
prep.Prep(fitmol);
func.Overlap(fitmol, res);
Console.WriteLine("{0} tanimoto combo = {1} shape tanimoto = {2} color tanimoto = {3}",
fitmol.GetTitle(), res.GetTanimotoCombo(), res.GetTanimoto(), res.GetColorTanimoto());
}
}
}
Download code
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class BestHit
{
public static void Main(string [] args)
{
if (args.Length != 3)
OEChem.OEThrow.Usage("BestHit <reffile> <fitfile> <outfile>");
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);
OEMol fitmol = new OEMol();
OEChem.OEReadMolecule(fitfs, fitmol);
OEROCSResult res = new OEROCSResult();
OEShape.OEROCSOverlay(res, refmol, fitmol);
OEMolBase outmol = res.GetOverlayConf();
OEChem.OEWriteMolecule(outfs, outmol);
Console.WriteLine("Tanimoto combo = "+res.GetTanimotoCombo());
}
}
Download code
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class TopHits
{
public static void Main(string [] args)
{
if (args.Length != 4)
OEChem.OEThrow.Usage("TopHits <reffile> <fitfile> <outfile> <nhits>");
oemolistream reffs = new oemolistream(args[0]);
oemolistream fitfs = new oemolistream(args[1]);
oemolostream outfs = new oemolostream(args[2]);
uint nhits = Convert.ToUInt32(args[3]);
OEMol refmol = new OEMol();
OEChem.OEReadMolecule(reffs, refmol);
// Setup OEROCS with specified number of best hits
OEROCSOptions options = new OEROCSOptions();
options.SetNumBestHits(nhits);
OEROCS rocs = new OEROCS(options);
rocs.SetDatabase(fitfs);
foreach (OEROCSResult res in rocs.Overlay(refmol))
{
OEMolBase outmol = res.GetOverlayConf();
OEChem.OEWriteMolecule(outfs, outmol);
Console.WriteLine("title: {0} tanimoto combo = {1}",
outmol.GetTitle(), res.GetTanimotoCombo());
}
}
}
Download code
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class TopHitsConf
{
public static void Main(string [] args)
{
if (args.Length != 4)
OEChem.OEThrow.Usage("TopHitsConf <reffile> <fitfile> <outfile> <confsperhit>");
oemolistream reffs = new oemolistream(args[0]);
oemolistream fitfs = new oemolistream(args[1]);
oemolostream outfs = new oemolostream(args[2]);
uint nconfs = Convert.ToUInt32(args[3]);
OEMol refmol = new OEMol();
OEChem.OEReadMolecule(reffs, refmol);
// 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);
foreach (OEROCSResult res in rocs.Overlay(refmol))
{
OEMCMolBase outmol = res.GetOverlayConfs();
OEChem.OEWriteMolecule(outfs, outmol);
Console.WriteLine("title: {0} tanimoto combo = {1}",
outmol.GetTitle(), res.GetTanimotoCombo());
}
}
}
Download code
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.
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class OverlayBestRes
{
public static void Main(string[] args)
{
if (args.Length != 2)
OEChem.OEThrow.Usage("OverlayBestRes <reffile> <fitfile>");
oemolistream reffs = new oemolistream(args[0]);
oemolistream fitfs = new oemolistream(args[1]);
OEMol refmol = new OEMol();
OEChem.OEReadMolecule(reffs, refmol);
Console.WriteLine("Ref. title: {0} Num Confs: {0}\n",
refmol.GetTitle(), 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);
foreach (OEMol fitmol in fitfs.GetOEMols())
{
prep.Prep(fitmol);
OEBestOverlayScore score = new OEBestOverlayScore();
overlay.BestOverlay(score, fitmol, new OEHighestTanimoto());
Console.WriteLine("Fit. title: {0} FitConfIdx: {0} RefConfIdx: {1} Tanimoto Combo: {2}",
fitmol.GetTitle(), score.GetFitConfIdx(), score.GetRefConfIdx(), score.GetTanimotoCombo());
}
}
}
Download code
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.
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class OverlayAllRes
{
public static void Main(string [] args)
{
if (args.Length != 2)
OEChem.OEThrow.Usage("OverlayAllRes <reffile> <fitfile>");
oemolistream reffs = new oemolistream(args[0]);
oemolistream fitfs = new oemolistream(args[1]);
OEMol refmol = new OEMol();
OEChem.OEReadMolecule(reffs, refmol);
Console.WriteLine("Ref. title: {0} Num Confs: {0}\n",
refmol.GetTitle(), 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);
foreach (OEMol fitmol in fitfs.GetOEMols())
{
Console.WriteLine("Fit. title: {0} Num Confs: {1}",
fitmol.GetTitle(), fitmol.NumConfs());
int resCount = 0;
// double loop over results and scores to obtain all scores
foreach (OEBestOverlayResults res in overlay.Overlay(fitmol))
{
foreach (OEBestOverlayScore score in res.GetScores())
{
Console.WriteLine("FitConfIdx: {0} RefConfIdx: {1} Tanimoto Combo: {2}",
score.GetFitConfIdx(), score.GetRefConfIdx(), score.GetTanimotoCombo());
++resCount;
}
}
Console.WriteLine(resCount+" results returned.");
}
}
}
Download code
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.
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class OverlayStruct
{
public static void Main(string[] args)
{
if (args.Length != 4)
OEChem.OEThrow.Usage("OverlayStruct <reffile> <fitfile> <outsdf> <keepsize>");
oemolistream reffs = new oemolistream(args[0]);
oemolistream fitfs = new oemolistream(args[1]);
oemolostream outfs = new oemolostream(args[2]);
uint keepSize = Convert.ToUInt32(args[3]);
OEMol refmol = new OEMol();
OEChem.OEReadMolecule(reffs, refmol);
Console.WriteLine("Ref. title: {0} Num Confs: {0}\n",
refmol.GetTitle(), 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);
foreach (OEMol fitmol in fitfs.GetOEMols())
{
Console.WriteLine("Fit. title: {0} Num Confs: {1}",
fitmol.GetTitle(), fitmol.NumConfs());
prep.Prep(fitmol);
uint resCount = 0;
OEBestOverlayResultsIter resiter = overlay.Overlay(fitmol);
// Sort all scores according to highest tanimoto
OEBestOverlayScoreIter scoreiter = new OEBestOverlayScoreIter();
OEShape.OESortOverlayScores(scoreiter, resiter, new OEHighestTanimoto());
foreach (OEBestOverlayScore score in scoreiter)
{
OEGraphMol outmol =
new OEGraphMol(fitmol.GetConf(new OEHasConfIdx(score.GetFitConfIdx())));
score.Transform(outmol);
OEChem.OESetSDData(outmol, "RefConfIdx", Convert.ToString(score.GetRefConfIdx()));
OEChem.OESetSDData(outmol, "Tanimoto Combo", Convert.ToString(score.GetTanimotoCombo()));
OEShape.OERemoveColorAtoms(outmol);
OEChem.OEWriteConstMolecule(outfs, outmol);
++resCount;
// Break at the user specified size
if (resCount == keepSize)
break;
}
Console.WriteLine(resCount + " results returned.");
}
}
}
Download code
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEShape;
public class CreateQuery
{
public static void Main(string[] argv)
{
OESimpleAppOptions opts = new OESimpleAppOptions("CreateQuery", OEFileStringType.Mol3D, "sq");
if (OEChem.OEConfigureOpts(opts, argv, false) == OEOptsConfigureStatus.Help)
Environment.Exit(1);
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
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class OverlapQuery
{
public static void Main(string [] args)
{
if (args.Length != 2)
OEChem.OEThrow.Usage("OverlapQuery <queryfile> <fitfile>");
String ext = OEChem.OEGetFileExtension(args[0]);
if (ext != "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();
foreach (OEGraphMol fitmol in fitfs.GetOEGraphMols())
{
prep.Prep(fitmol);
func.Overlap(fitmol, res);
Console.WriteLine("{0} tanimoto combo = {1} shape tanimoto = {2} color tanimoto = {3}",
fitmol.GetTitle(), res.GetTanimotoCombo(), res.GetTanimoto(), res.GetColorTanimoto());
}
}
}
Download code
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class TopHitsQuery
{
public static void Main(string [] args)
{
if (args.Length != 4)
OEChem.OEThrow.Usage("TopHitsQuery <queryfile> <fitfile> <outfile> <nhits>");
String ext = OEChem.OEGetFileExtension(args[0]);
if (ext != "sq")
OEChem.OEThrow.Fatal("Requires a shape query .sq input file format");
oemolistream fitfs = new oemolistream(args[1]);
oemolostream outfs = new oemolostream(args[2]);
uint nhits = Convert.ToUInt32(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);
foreach (OEROCSResult res in rocs.Overlay(query))
{
OEMolBase outmol = res.GetOverlayConf();
OEChem.OEWriteMolecule(outfs, outmol);
Console.WriteLine("title: {0} tanimoto combo = {1}",
outmol.GetTitle(), res.GetTanimotoCombo());
}
}
}
Download code
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEShape;
using OpenEye.OEGrid;
public class HermiteExpansion
{
public static void Main(string[] args)
{
OEInterface itf = new OEInterface(InterfaceData, "HermiteExpansion", args);
uint NPolyMax = (uint) (int) 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();
Console.WriteLine("Best lambdas found X="
+ hopts.GetLambdaX().ToString("R") + " Y="
+ hopts.GetLambdaY().ToString("R") + " Z="
+ hopts.GetLambdaZ().ToString("R"));
Console.WriteLine("Hermite self-overlap =" + hermite.GetSelfOverlap().ToString("R"));
OEDoubleVector coeffs = new OEDoubleVector();
hermite.GetCoefficients(coeffs);
string NPolyMaxstring = NPolyMax.ToString();
Console.WriteLine("Hermite coefficients f_{l,m,n} in the following order l = 0..."
+ NPolyMaxstring + ", m = 0..." + NPolyMaxstring+"-l, n = " + NPolyMaxstring + "-l-m :");
Console.WriteLine(string.Join(",", coeffs));
OEScalarGrid grid = new OEScalarGrid();
hermite.CreateGrid(grid, gridspacing, transfm);
if (!OEGrid.OEWriteGrid(ofname, grid))
OEChem.OEThrow.Fatal("Unable to write grid file");
}
private static String InterfaceData = @"
!CATEGORY HermiteExpansion
!BRIEF %(prog)s [-inputfile] <InputFileName> [-outputgrid] <OutputGridFileName> [-NPolyMax] <NPolyMax>
!PARAMETER -inputfile 1
!ALIAS -in
!TYPE string
!REQUIRED true
!BRIEF Filename of the input molecule
!KEYLESS 1
!END
!PARAMETER -outputgrid 2
!ALIAS -out
!TYPE string
!REQUIRED true
!BRIEF Filename of the output Hermite grid (needs to have .grd file extension)
!KEYLESS 2
!END
!END
!CATEGORY 'Hermite options :' 2
!PARAMETER -NPolyMax 3
!ALIAS -NP
!TYPE int
!REQUIRED false
!DEFAULT 5
!LEGAL_RANGE 0 30
!BRIEF Resolution parameter of Hermite Prep
!KEYLESS 3
!END
!PARAMETER -gridspacing 4
!ALIAS -gs
!TYPE float
!REQUIRED false
!DEFAULT 1.0
!LEGAL_RANGE 0.01 10.0
!BRIEF Grid spacing of the output Hermite grid
!KEYLESS 4
!END
!END";
}
Download code
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEShape;
using OpenEye.OEGrid;
public class HermiteTanimoto
{
public static void Main(string[] args)
{
OEInterface itf = new OEInterface(InterfaceData, "HermiteTanimoto", args);
uint NPolyMax_MAX = (uint) 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");
OETrans transfm = new OETrans();
int idx = 0;
while (OEChem.OEReadMolecule(ifsfit, fitmol)){
OEMol fitmol_copy = new OEMol(fitmol);
Console.WriteLine("Working on the fit molecule with idx = " + 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;
foreach (OEBestOverlayScore score in scoreiter)
{
hermitetanimoto = score.GetTanimoto();
score.Transform(fitmol);
}
Console.WriteLine("Hermite Tanimoto = " + hermitetanimoto);
// Transform from the inertial frame to the original reference mol frame
reftransfm.Transform(fitmol);
OEChem.OESetSDData(fitmol, "HermiteTanimoto_"+NPolyMax_MAX, hermitetanimoto.ToString());
OEShape.OERemoveColorAtoms(fitmol);
OEChem.OEWriteMolecule(ofs, fitmol);
idx += 1;
}
ofs.flush();
ofs.close();
}
private static String InterfaceData = @"
!CATEGORY HermiteTanimoto
!BRIEF %(prog)s [-inputreffile] <InputReferenceFileName> [-inputfitfile] <InputFitFileName> [-outputfile] <OutputFileName> [-NPolyMax_MAX] <NPolyMax_MAX>
!PARAMETER -inputreffile 1
!ALIAS -inref
!TYPE string
!REQUIRED true
!BRIEF Input file name with reference molecule (will only read the first molecule).
!KEYLESS 1
!END
!PARAMETER -inputfitfile 2
!ALIAS -infit
!TYPE string
!REQUIRED true
!BRIEF Input file name with fit molecules
!KEYLESS 2
!END
!PARAMETER -outputfile 3
!ALIAS -out
!TYPE string
!REQUIRED true
!BRIEF Output file name
!KEYLESS 3
!END
!END
!CATEGORY 'Hermite options' : 2
!PARAMETER -NPolyMax_MAX 4
!ALIAS -NP_MAX
!TYPE int
!REQUIRED false
!DEFAULT 5
!LEGAL_RANGE 0 30
!BRIEF Maximum value of the parameter of the NPolyMax parameter of the Hermite prep
!KEYLESS 4
!END
!END";
}
Download code
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.
*/
using System;
using System.IO;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class NxNShape
{
private static StreamWriter csv;
private void OneConf(OEConfBase conf, OEOverlapPrep prep, String filename)
{
csv.Write("{0}_{1}", 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);
foreach (OEMol fitmol in bfs.GetOEMols())
{
prep.Prep(fitmol);
OEBestOverlayResultsIter resiter = overlay.Overlay(fitmol);
OEBestOverlayScoreIter scoreiter = new OEBestOverlayScoreIter();
OEShape.OESortOverlayScores(scoreiter, resiter, new OEHighestTanimoto(), 1, true);
foreach (OEBestOverlayScore score in scoreiter)
csv.Write(",{0:0.00}", score.GetTanimoto());
}
bfs.close();
csv.WriteLine();
}
private void GenHeader(String filename)
{
csv.Write("name");
oemolistream ifs = new oemolistream(filename);
foreach (OEMol mol in ifs.GetOEMols())
{
Console.WriteLine(mol.GetTitle());
foreach (OEConfBase conf in mol.GetConfs())
{
csv.Write(",{0}_{1}", conf.GetTitle(), conf.GetIdx());
}
}
ifs.close();
csv.WriteLine();
}
private void OpenCSV(String csvfilename) {
try
{
csv = File.CreateText(csvfilename);
}
catch (Exception)
{
Console.WriteLine("Unable to open output file {0}", csvfilename);
}
}
public void NxN(String filename, String csvfilename)
{
OpenCSV(csvfilename);
GenHeader(filename);
oemolistream afs = new oemolistream(filename);
OEOverlapPrep prep = new OEOverlapPrep();
prep.SetAssignColor(false);
foreach (OEMol molA in afs.GetOEMols())
{
prep.Prep(molA);
foreach (OEConfBase conf in molA.GetConfs())
{
OneConf(conf, prep, filename);
}
}
csv.Close();
}
public static void Main(string [] args)
{
if (args.Length != 2)
{
OEChem.OEThrow.Usage("NxNShape <infile> <csvfile>");
}
NxNShape app = new NxNShape();
app.NxN(args[0], args[1]);
}
}
Download code
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.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEGrid;
using OpenEye.OEShape;
public class ShapeProps
{
public static void Main(string [] args)
{
if (args.Length != 1)
{
OEChem.OEThrow.Usage("ShapeProps <infile>");
}
oemolistream ifs = new oemolistream(args[0]);
foreach (OEGraphMol mol in ifs.GetOEGraphMols())
{
Console.WriteLine(" Title: "+mol.GetTitle());
Console.WriteLine(" Volume: "+OEShape.OECalcVolume(mol));
Console.WriteLine("Volume: (without H): "+
OEShape.OECalcVolume(mol, false));
float [] smult = new float[14];
OEShape.OECalcShapeMultipoles(mol, smult);
Console.WriteLine(" Steric multipoles:");
Console.WriteLine(" monopole: "+smult[0]);
Console.WriteLine(" quadrupoles: "+
smult[1]+" "+smult[2]+" "+smult[3]);
Console.WriteLine(" octopoles:");
Console.WriteLine(" xxx: "+smult[4]+
" yyy: "+smult[5]+" zzz: "+smult[6]);
Console.WriteLine(" xxy: "+smult[7]+
" xxz: "+smult[8]+" yyx: "+smult[9]);
Console.WriteLine(" yyz: "+smult[10]+
" zzx: "+smult[11]+" zzy: "+smult[12]);
Console.WriteLine(" xyz: "+smult[13]);
Console.WriteLine("");
}
}
}
Download code
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> 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