3.2 Get a Grid

ZAP uses regular cubic lattices, or grids, to solve the PB equation. The examples here illustrate how to retrieve such from the calculation and to manipulate and store the information held by each. Typically, grids are not used per se but information is extracted, such as the potential at particular points in space, as is illustrated in the next section. However, some programs, such as VIDA, can read grids and display their properties. Also, having direct access to grids allows for manipulations of the potential map that may not have been anticipated.

This first example shows the simplest method of generating a grid of potentials using ZAP. We save the grid in OpenEye GRD (*.grd) format which is a compact, binary format that can be visualized in VIDA. Alternatively, the grid can be written into GRASP format (*.phi), which means that the grid stored will be 65 cubed irregardless of the size of the grid used in the calculation. A 65**3 grid is obtained by interpolation to a grid with that many points that fits over the largest dimension of the grid calculated.

 1 /*******************************************************************
 2   Copyright (C) 2006,2007, 2008 OpenEye Scientific Software, Inc.
 3 *******************************************************************/
 4 #include "openeye.h"
 5
 6 #include "oezap.h"
 7 #include "oegrid.h"
 8 #include "oechem.h"
 9 #include "oesystem.h"
10 #include "oeplatform.h"
11
12 using namespace OEPB;
13 using namespace OEChem;
14 using namespace OESystem;
15 using namespace OEPlatform;
16
17 int main(int argc, char *argv[])
18 {
19   if (argc!=2)
20     OEThrow.Usage("%s <molfile>", argv[0]);
21
22   oemolistream ifs;
23   if (!ifs.open(argv[1]))
24     OEThrow.Fatal("Could not open %s for reading", argv[1]);
25
26   float epsin = 1.0f;
27   OEGraphMol mol;
28
29   OEReadMolecule(ifs, mol);
30   OEAssignBondiVdWRadii(mol);
31   OEMMFFAtomTypes(mol);
32   OEMMFF94PartialCharges(mol);
33
34   OEZap zap;
35   zap.SetInnerDielectric(epsin);
36   zap.SetMolecule(mol);
37
38   OEScalarGrid grid;
39   if (zap.CalcPotentialGrid(grid))
40     OEWriteGrid("zap.grd", grid);
41
42   return 0;
43 }

Listing:3.2 Calculating potential grid with zap

The next example is an elaboration of the previous simple version where we add in control of the parameters of the calculation. Options are provided to set the internal and external (solute and solvent) dielectric constants, the distance between the molecule and the edges of the grid (boundary spacing or buffer) and the grid spacing. A smaller grid spacing implies a more dense and accurate grid, but it does come with a larger memory footprint.

 1 /*******************************************************************
 2   Copyright (C) 2006,2007, 2008 OpenEye Scientific Software, Inc.
 3 *******************************************************************/
 4 #include "openeye.h"
 5
 6 #include "oezap.h"
 7 #include "oegrid.h"
 8 #include "oechem.h"
 9 #include "oesystem.h"
10 #include "oeplatform.h"
11
12 #include "zap_grid2.itf"
13
14 using namespace OEPB;
15 using namespace OEChem;
16 using namespace OESystem;
17 using namespace OEPlatform;
18 using namespace std;
19
20 bool SetupInterface(int argc, char *argv[], OEInterface &itf)
21 {
22   OEConfigure(itf, InterfaceData);
23   if(OECheckHelp(itf, argc, argv))
24     return false;
25   if (!OEParseCommandLine(itf, argc, argv))
26     return false;
27
28   string infile=itf.Get<string>("-in");
29   if(!OEIsReadable(infile))
30   {
31     OEThrow.Warning("%s is not a readable input file", infile.c_str());
32     return false;
33   }
34
35   string outfile=itf.Get<string>("-out");
36   if(!OEIsWriteableGrid(outfile))
37   {
38     OEThrow.Warning("%s is not a writable grid file", outfile.c_str());
39     return false;
40   }
41   return true;
42 }
43
44 int main(int argc, char *argv[])
45 {
46   OEInterface itf;
47   if (!SetupInterface(argc, argv, itf))
48     return 1;
49
50   OEZap zap;
51   zap.SetInnerDielectric(itf.Get<float>("-epsin"));
52   zap.SetOuterDielectric(itf.Get<float>("-epsout"));
53   zap.SetGridSpacing(itf.Get<float>("-grid_spacing"));
54   zap.SetBoundarySpacing(itf.Get<float>("-buffer"));
55
56   oemolistream ifs;
57   if (!ifs.open(itf.Get<std::string>("-in")))
58     OEThrow.Fatal("Could not open %s for reading", argv[1]);
59
60   OEGraphMol mol;
61
62   OEReadMolecule(ifs,mol);
63   OEAssignBondiVdWRadii(mol);
64   OEMMFFAtomTypes(mol);
65   OEMMFF94PartialCharges(mol);
66   zap.SetMolecule(mol);
67
68   OEScalarGrid grid;
69   if (zap.CalcPotentialGrid(grid))
70     OEWriteGrid(itf.Get<string>("-out"), grid);
71
72   return 0;
73 }

Listing:3.3 Calculating potential grid with optional parameters

Here we show how to calculate a difference-map, that is to say the potential difference between a standard, two dielectric, calculation and and a single dielectric calculation (approximating pure Coulombic potentials). These difference potentials represent the electrostatic response of the solvent to the charges within the solute molecule. If we mask away everything outside the molecule, we can see the contributions from the charges inside the molecule.

 1 /*******************************************************************
 2   Copyright (C) 2006,2007, 2008 OpenEye Scientific Software, Inc.
 3 *******************************************************************/
 4 #include "openeye.h"
 5
 6 #include "oezap.h"
 7 #include "oegrid.h"
 8 #include "oechem.h"
 9 #include "oesystem.h"
10 #include "oeplatform.h"
11
12 using namespace OEPB;
13 using namespace OEChem;
14 using namespace OESystem;
15 using namespace OEPlatform;
16
17 int main(int argc, char *argv[])
18 {
19   if (argc!=2)
20     OEThrow.Usage("%s <molfile>", argv[0]);
21
22   oemolistream ifs;
23   if (!ifs.open(argv[1]))
24     OEThrow.Fatal("Could not open %s for reading", argv[1]);
25
26   OEGraphMol mol;
27
28   OEReadMolecule(ifs, mol);
29   OEAssignBondiVdWRadii(mol);
30   OEMMFFAtomTypes(mol);
31   OEMMFF94PartialCharges(mol);
32
33   OEScalarGrid grid1, grid2;
34   OEZap zap;
35   zap.SetInnerDielectric(1.0f);
36   zap.SetMolecule(mol);
37
38   // calculate standard 2-dielectric grid
39   zap.CalcPotentialGrid(grid1);
40
41   // calculate grid with single dielectric
42   zap.SetOuterDielectric(zap.GetInnerDielectric());
43   zap.CalcPotentialGrid(grid2);
44
45   // take the difference
46   OESubtractGrid(grid1, grid2);
47
48   // mask out everything outside the molecule
49   OEMaskGridByMolecule(grid1, mol, OEGridMaskType::GaussianMinus);
50
51   OEWriteGrid("zap_diff.grd", grid1);
52
53   return 0;
54 }

Listing:3.4 Calculating potential grid with optional parameters