Subsections

 
2.3 Storage

OEGrid supports the following storage formats:

(.phi)
GRASP
(.grd)
Binary format
(.agd)
ASCII format
(.map OR .ccp OR .ccp4)
CCP4
(.xplor OR .xplmap)
XPLOR

The ASCII format was developed by OpenEye to allow for easy integration with other software. The following is an example of the ASCII output:

Title: Example Grid
Mid:     0.000000     0.000000     0.000000
Dim:      2      2      2
Spacing:     0.500000
Values:
0.000000e+00
0.000000e+00
0.000000e+00
0.000000e+00
0.000000e+00
0.000000e+00
0.000000e+00
0.000000e+00

Listing 2.8 is the code used to write the ASCII format out. It is provided here to leave no doubt as to how to inter-operate with the format.

ofs << "Title: " << grid.GetTitle() << oeendl;

char buffer[80];
sprintf(buffer, "Mid: %12.6f %12.6f %12.6f", grid.GetXMid(), grid.GetYMid(),
        grid.GetZMid());
ofs << buffer << oeendl;

unsigned int xdim = grid.GetXDim();
unsigned int ydim = grid.GetYDim();
unsigned int zdim = grid.GetZDim();

sprintf(buffer, "Dim: %6d %6d %6d", xdim, ydim, zdim);
ofs << buffer << oeendl;

sprintf(buffer, "Spacing: %12.6f", grid.GetSpacing());
ofs << buffer << oeendl;

ofs << "Values:" << oeendl;
char numbuff[13];
for (unsigned int iz=0;iz<zdim;++iz)
  for (unsigned int iy=0;iy<ydim;++iy)
    for (unsigned int ix=0;ix<xdim;++ix)
    {
      sprintf(numbuff, "%-12.6e", grid.operator()(ix,iy,iz));
      ofs << numbuff << oeendl;
    }

Listing:2.8 ASCII grid writer

2.3.1 Attaching to Molecules

 The OpenEye format allows surfaces to be attached to molecules and then written out to OEBinary (.oeb) files. A visualizer can then read in the molecule and grid without any other means of making the association.

To do this the binary writers inside OESystem need to be initialized to handle grids. Listing 2.9 demonstrates how to properly attach surfaces to molecules.

oemolostream ofs;
if (!ofs.open(fname))
  OEThrow.Fatal("Unable to open file: %s", fname);
OEInitGridHandlers(ofs);

OEGraphMol mol;
// Read a molecule into mol

OEScalarGrid grid;
OEMakeMolecularGaussianGrid(grid, mol, 1.0);
// Create a grid for a molecule
mol.SetData<OEScalarGrid>("grid", grid);

OEWriteMolecule(ofs, mol);

Listing:2.9 Attaching surfaces to molecules