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, 2008 OpenEye Scientific Software, Inc.
 3  ******************************************************************************/
 4 package openeye.examples.oezap;
 5
 6 import openeye.oechem.*;
 7 import openeye.oegrid.*;
 8 import openeye.oezap.*;
 9
10 public class ZapGrid1 {
11   public static void main(String argv[]) {
12     if (argv.length != 1) {
13       System.err.println("usage: ZapGrid1 <molfile>");
14       System.exit(1);
15     }
16
17     OEGraphMol mol = new OEGraphMol();
18     oemolistream ifs = new oemolistream();
19     if (!ifs.open(argv[0])) {
20       System.err.println("Unable to open for reading: " + argv[0]);
21       System.exit(1);
22     }
23     oechem.OEReadMolecule(ifs, mol);
24     oechem.OEAssignBondiVdWRadii(mol);
25     oechem.OEMMFFAtomTypes(mol);
26     oechem.OEMMFF94PartialCharges(mol);
27     ifs.close();
28
29     OEZap zap = new OEZap();
30     zap.SetInnerDielectric(1.0f);
31     zap.SetGridSpacing(0.5f);
32     zap.SetMolecule(mol);
33
34     OEScalarGrid grid = new OEScalarGrid();
35     if (zap.CalcPotentialGrid(grid))
36       oegrid.OEWriteGrid("zap.grd", grid);
37   }
38 }

Listing:3.1 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, 2008 OpenEye Scientific Software, Inc.
 3  ******************************************************************************/
 4 package openeye.examples.oezap;
 5
 6 import openeye.oechem.*;
 7 import openeye.oegrid.*;
 8 import openeye.oezap.*;
 9
10 public class ZapGrid2 {
11   private static String InterfaceString =
12     "!PARAMETER -in \n"+
13     "  !TYPE string\n"+
14     "  !BRIEF Input molecule file\n"+
15     "  !REQUIRED true\n"+
16     "!END\n"+
17     "!PARAMETER -out\n"+
18     "  !TYPE string\n"+
19     "  !BRIEF Output grid file\n"+
20     "  !REQUIRED true\n"+
21     "!END\n"+
22     "!PARAMETER -epsin\n"+
23     "  !TYPE float\n"+
24     "  !BRIEF Inner dielectric\n"+
25     "  !DEFAULT 1.0\n"+
26     "  !LEGAL_RANGE 0.0 100.0\n"+
27     "!END\n"+
28     "!PARAMETER -epsout\n"+
29     "  !TYPE float\n"+
30     "  !BRIEF Outer dielectric\n"+
31     "  !DEFAULT 80.0\n"+
32     "  !LEGAL_RANGE 0.0 100.0\n"+
33     "!END\n"+
34     "!PARAMETER -grid_spacing\n"+
35     "  !TYPE float\n"+
36     "  !DEFAULT 0.5\n"+
37     "  !BRIEF Spacing between grid points (Angstroms)\n"+
38     "  !LEGAL_RANGE 0.1 2.0\n"+
39     "!END\n"+
40     "!PARAMETER -buffer\n"+
41     "  !TYPE float\n"+
42     "  !DEFAULT 2.0\n"+
43     "  !BRIEF Extra buffer outside extents of molecule.\n"+
44     "  !LEGAL_RANGE 0.1 10.0\n"+
45     "!END\n"+
46     "!PARAMETER -mask\n"+
47     "  !TYPE bool\n"+
48     "  !DEFAULT false\n"+
49     "  !BRIEF Mask potential grid by the molecule\n"+
50     "!END\n";
51
52   public static void main(String argv[]) {
53     OEInterface itf = new OEInterface();
54     if (!oechem.OEConfigure(itf,InterfaceString))
55       System.exit(1);
56
57     //String appName = getClass().toString().replaceFirst("class ","");
58     if (oechem.OECheckHelp(itf, argv))
59       System.exit(0);
60
61     oechem.OEParseCommandLine(itf, argv);
62
63     OEGraphMol mol = new OEGraphMol();
64     oemolistream ifs = new oemolistream();
65     if (!ifs.open(itf.GetString("-in"))) {
66       System.err.println("Unable to open for reading: " + itf.GetString("-in"));
67       System.exit(1);
68     }
69     oechem.OEReadMolecule(ifs, mol);
70     oechem.OEAssignBondiVdWRadii(mol);
71     oechem.OEMMFFAtomTypes(mol);
72     oechem.OEMMFF94PartialCharges(mol);
73     ifs.close();
74
75     OEZap zap = new OEZap();
76     zap.SetInnerDielectric(itf.GetFloat("-epsin"));
77     zap.SetOuterDielectric(itf.GetFloat("-epsout"));
78     zap.SetGridSpacing(itf.GetFloat("-grid_spacing"));
79     zap.SetBoundarySpacing(itf.GetFloat("-buffer"));
80     zap.SetMolecule(mol);
81
82     OEScalarGrid grid = new OEScalarGrid();
83     if (zap.CalcPotentialGrid(grid))
84       if (itf.GetBool("-mask"))
85         oegrid.OEMaskGridByMolecule(grid,mol);
86       oegrid.OEWriteGrid(itf.GetString("-out"), grid);
87   }
88 }

Listing:3.2 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, 2008 OpenEye Scientific Software, Inc.
 3  ******************************************************************************/
 4 package openeye.examples.oezap;
 5
 6 import openeye.oechem.*;
 7 import openeye.oegrid.*;
 8 import openeye.oezap.*;
 9
10 public class ZapGrid3 {
11   public static void main(String argv[]) {
12     if (argv.length != 1) {
13       System.err.println("usage: ZapGrid3 <molfile>");
14       System.exit(1);
15     }
16
17     OEGraphMol mol = new OEGraphMol();
18     oemolistream ifs = new oemolistream();
19     if (!ifs.open(argv[0])) {
20       System.err.println("Unable to open for reading: " + argv[0]);
21       System.exit(1);
22     }
23     oechem.OEReadMolecule(ifs, mol);
24     oechem.OEAssignBondiVdWRadii(mol);
25     oechem.OEMMFFAtomTypes(mol);
26     oechem.OEMMFF94PartialCharges(mol);
27     ifs.close();
28
29     OEZap zap = new OEZap();
30     zap.SetInnerDielectric(1.0f);
31     zap.SetGridSpacing(0.5f);
32     zap.SetMolecule(mol);
33
34     OEScalarGrid grid1 = new OEScalarGrid();
35     zap.CalcPotentialGrid(grid1);
36     OEScalarGrid grid2 = new OEScalarGrid();
37     zap.CalcPotentialGrid(grid2);
38     oegrid.OESubtractScalarGrid(grid1, grid2);
39     oegrid.OEMaskGridByMolecule(grid1, mol, OEGridMaskType.GaussianMinus);
40     oegrid.OEWriteGrid("zap_diff.grd", grid1);
41   }
42 }

Listing:3.3 Calculating potential grid with optional parameters