5.4 Using color along with shape

In order to maximize chemical similarity along with shape, an OEColorForceField can be added to OEBestOverlay. Once added, color scores will be calculated along with shape overlap scores. By default, the color force field only appears as a post-optimization scoring function. That is, after the shape overlap is maximized, color scores are calculated.

Color force can, however, also be used as part of the optimization. Color optimization is turned on by the SetColorOptimize(bool) member function.

 1 /*****************************************************************************
 2  * Copyright 2005,2006,2007,2008 OpenEye Scientific Software, Inc.
 3  ****************************************************************************/
 4 package openeye.examples.oeshape;
 5
 6 import openeye.oechem.*;
 7 import openeye.oeshape.*;
 8
 9 public class BestOverlayColor {
10   public static void main(String[] args) {
11     if (args.length!=4) {
12       System.out.println("BestOverlayColor <reffile> <fitfile> <out.sdf> <keepsize>");
13       System.exit(0);
14     }
15
16     oemolistream reffs = new oemolistream(args[0]);
17     oemolistream fitfs = new oemolistream(args[1]);
18     oemolostream outfs = new oemolostream(args[2]);
19     int keepsize = Integer.parseInt(args[3]);
20
21     OEMol refmol = new OEMol();
22     oechem.OEReadMolecule(reffs, refmol);
23
24     OEBestOverlay best = new OEBestOverlay();
25     best.SetRefMol(refmol);
26     best.SetColorForceField(OEColorFFType.ImplicitMillsDean);
27     best.SetColorOptimize(true);
28
29     System.out.print("Ref. title: "+refmol.GetTitle()+" ");
30     System.out.print("Num Confs: "+refmol.NumConfs()+" ");
31     System.out.println("Self color: "+best.GetRefSelfColor());
32
33     int resCount=0;
34     OEBestOverlayScore score;
35
36     OEMol fitmol = new OEMol();
37     while (oechem.OEReadMolecule(fitfs, fitmol)) {
38       System.out.print("Fit. title: "+fitmol.GetTitle()+" ");
39       System.out.println("Num Confs: "+fitmol.NumConfs());
40       OEBestOverlayResultsIter resiter = best.Overlay(fitmol);
41       OEBestOverlayScoreIter scoreiter = new OEBestOverlayScoreIter();
42       oeshape.OESortOverlayScores(scoreiter, resiter, new OEHighestTanimotoCombo());
43       for (;scoreiter.IsValid();scoreiter.Increment()) {
44         score = scoreiter.Target();
45         OEGraphMol outmol =
46           new OEGraphMol(fitmol.GetConf(new OEHasConfIdx(score.getFitconfidx())));
47         score.Transform(outmol);
48
49         oechem.OESetSDData(outmol, "RefConfIdx",
50                 String.valueOf(score.getRefconfidx()));
51         oechem.OESetSDData(outmol, "TanimotoCombo",
52                 String.valueOf(score.GetTanimotoCombo()));
53         oechem.OESetSDData(outmol, "Tanimoto",
54                 String.valueOf(score.getTanimoto()));
55         oechem.OESetSDData(outmol, "ColorTanimoto",
56                 String.valueOf(score.GetColorTanimoto()));
57
58         oechem.OEWriteMolecule(outfs,
59                           refmol.GetConf(new OEHasConfIdx(score.getRefconfidx())));
60         oechem.OEWriteMolecule(outfs, outmol);
61
62         ++resCount;
63         if (resCount==keepsize)
64           break;
65       }
66     }
67     System.out.println(resCount+" results returned.");
68   }
69 }
70

Listing:5.5 Using color with OEBestOverlay.