5.3 Saving aligned structures

OEBestOverlay 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. It is up to the user to apply these transformations. The OpenEye standard is rotation then translation, but as a convenience, OEBestOverlayScore has a Transform() (section ) method that will apply the transforms in the proper order. This next example, expands from the previous. Now, not only can we choose the number of overlays to keep, we are also going to align each fit conformer to the ref conformer it was overlaid on, and then output 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.

 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 BestOverlay4 {
10   public static void main(String[] args) {
11     if (args.length!=4) {
12       System.out.println("BestOverlay4 <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
27     System.out.print("Ref. title: "+refmol.GetTitle()+" ");
28     System.out.println("Num Confs: "+refmol.NumConfs());
29
30     int resCount=0;
31     OEBestOverlayScore score;
32
33     OEMol fitmol = new OEMol();
34     while (oechem.OEReadMolecule(fitfs, fitmol)) {
35       System.out.print("Fit. title: "+fitmol.GetTitle()+" ");
36       System.out.println("Num Confs: "+fitmol.NumConfs());
37       OEBestOverlayResultsIter resiter = best.Overlay(fitmol);
38       OEBestOverlayScoreIter scoreiter = new OEBestOverlayScoreIter();
39       oeshape.OESortOverlayScores(scoreiter, resiter, new OEHighestTanimoto());
40       for (;scoreiter.IsValid();scoreiter.Increment()) {
41         score = scoreiter.Target();
42         OEGraphMol outmol =
43           new OEGraphMol(fitmol.GetConf(new OEHasConfIdx(score.getFitconfidx())));
44         score.Transform(outmol);
45
46         oechem.OESetSDData(outmol, "RefConfIdx", String.valueOf(score.getRefconfidx()));
47         oechem.OESetSDData(outmol, "Tanimoto", String.valueOf(score.getTanimoto()));
48
49         oechem.OEWriteMolecule(outfs,
50                         refmol.GetConf(new OEHasConfIdx(score.getRefconfidx())));
51         oechem.OEWriteMolecule(outfs, outmol);
52
53         ++resCount;
54         if (resCount==keepsize)
55           break;
56       }
57     }
58     System.out.println(resCount+" results returned.");
59   }
60 }
61

Listing:5.4 Writing aligned structures from OEBestOverlay.