3.1 Grid Babel

The following is an example of using OEGrid to convert between various grid formats:

 1 /*******************************************************************
 2  Copyright 2003, 2004, 2006 OpenEye Scientific Software, Inc.
 3  *******************************************************************/
 4 #include "openeye.h"
 5
 6 #include "oegrid.h"
 7 #include "oechem.h"
 8 #include "oesystem.h"
 9 #include "oeplatform.h"
10
11 using namespace OEChem;
12 using namespace OESystem;
13 using namespace OEPlatform;
14
15 #include "gridbabel.itf"
16
17 bool SetupInterface(OEInterface &itf, int argc, char **argv)
18 {
19   if (!OEConfigure(itf, InterfaceData))
20     return false;
21
22   if (OECheckHelp(itf,argc,argv))
23     return false;
24
25   return OEParseCommandLine(itf, argc, argv);
26 }
27
28 int main(int argc, char *argv[])
29 {
30   OEInterface itf;
31   if (!SetupInterface(itf, argc, argv))
32     return 1;
33
34   float res=itf.Get<float>("-res");
35
36   bool regularize=itf.Get<bool>("-regularize");
37
38   std::string outfile = itf.Get<std::string>("-o");
39   if (!OEIsWriteableGrid(OEGetGridFileType(OEGetFileExtension(outfile.c_str()))))
40     OEThrow.Fatal("Not a writeable grid file: %s", outfile.c_str());
41
42   std::string infile = itf.Get<std::string>("-i");
43
44   if (OEIsReadableGrid(OEGetGridFileType(OEGetFileExtension(infile.c_str()))))
45   {
46     if (regularize)
47     {
48       OEScalarGrid grid;
49       if (OEReadGrid(infile, grid))
50         OEWriteGrid(outfile, grid);
51       else
52         OEThrow.Fatal("Problem reading grid file: %s", infile.c_str());
53     }
54     else
55     {
56       OESkewGrid grid;
57       if (OEReadGrid(infile, grid))
58         OEWriteGrid(outfile, grid);
59       else
60         OEThrow.Fatal("Problem reading grid file: %s", infile.c_str());
61     }
62   }
63   else if (OEIsReadable(OEGetFileType(OEGetFileExtension(infile.c_str()))))
64   {
65     oemolistream ifs(infile);
66     OEMol mol;
67     if (OEReadMolecule(ifs, mol))
68     {
69       OEAssignBondiVdWRadii(mol);
70       OEScalarGrid grid;
71       OEMakeMolecularGaussianGrid(grid, mol, res);
72       OEWriteGrid(outfile, grid);
73     }
74     else
75       OEThrow.Fatal("Problem reading molecule file: %s", infile.c_str());
76   }
77   else
78     OEThrow.Fatal("Not a readable grid file: %s", infile.c_str());
79
80   OEThrow.Info("Converted %s into %s", infile.c_str(), outfile.c_str());
81   return 0;
82 }

Listing:3.1 gridbabel.cpp

Note that it can also read in molecules to make molecular gaussian grids. This is just one example of how grids can be mixed with OEChem. Listing 3.2 is code fragment to map molecular gaussian functions onto a grid (assuming mol is already a valid OEMolBase object).

OEAssignBondiVdWRadii(mol);
OEScalarGrid grid;
OEMakeMolecularGaussianGrid(grid, mol, 0.5);

Listing:3.2 Making a molecular Gaussian grid