RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
MOEGrid.h
1/***********************************************************************
2 * The rDock program was developed from 1998 - 2006 by the software team
3 * at RiboTargets (subsequently Vernalis (R&D) Ltd).
4 * In 2006, the software was licensed to the University of York for
5 * maintenance and distribution.
6 * In 2012, Vernalis and the University of York agreed to release the
7 * program as Open Source software.
8 * This version is licensed under GNU-LGPL version 3.0 with support from
9 * the University of Barcelona.
10 * http://rdock.sourceforge.net/
11 ***********************************************************************/
12
13// MOE grid description at ${MOE}/html/svl/manual/gridman.htm
14// here you can read:
15// [...]
16// Creating a grid consists of creating both a shape vector and a data vector.
17// The shape vector stores gridpoint positions along each dimension. The number
18// of dimensions must be between 2 and 24 with each dimension containing at
19// least 2 points. Each element of the shape vector is a flat vector of strictly
20// increasing grid positions along the corresponding dimension. The values of
21// the field at the gridpoints are stored in row-major order, i.e., with the
22// index of the last dimension changing most rapidly.
23// [...]
24// Generating a shape vector consists of creating coordinate vectors along each
25// of the n dimensions of an n-dimensional lattice. The intervals between the
26// coordinates need not be regular. To generate the shape vector, you need the
27// origin of the lattice and the length of each side of the lattice, along with
28// the coordinate spacings in each dimension.
29// [...]
30// The values of the field at the gridpoints are stored in a data vector. There
31// must be one data value for every gridpoint. The length of the data vector
32// must therefore equal the product of the number of gridpoints along each
33// dimension.
34
35#ifndef _RBTMOEGRID_H_
36#define _RBTMOEGRID_H_
37
38#include "rxdock/Coord.h"
39#include "rxdock/Rbt.h"
40#include <cstdlib>
41#include <fstream>
42#include <vector>
43
44#include "rxdock/BiMolWorkSpace.h"
45
46namespace rxdock {
47
48// single point in a multi-dimensional grid
49// the coords contains N values where N is the dimension of the grid
51 std::vector<double> coords;
52 double value;
53
54public:
55 // default ctor with a 1D gridpoint at 0.0 value 1.0
56 // see also default ctor for the shape and data vector below
57 RBTDLL_EXPORT MOEGridPoint();
58 // parametrized ctor when supplying data as a vector + value pair
59 MOEGridPoint(std::vector<double>, double);
60 // parametrized ctor getting coord values from Coord (default 3D
61 // grid for convenience)
62 MOEGridPoint(Coord &, double);
63 // data access methods
64 double GetValue() { return value; }
65 const std::vector<double> &GetCoords() { return coords; }
66 void SetCoords(double a_val) { coords.push_back(a_val); }
67 void SetValue(double a_val) { value = a_val; }
68};
69
70// MOE grid shape vector
72 // data that is provided usually in the SVL code
73 // a shape vector is defined by
74 // i) starting coordinates
75 // ii) X,Y,Z extension (in absolute coordinates)
76 // iii) grid stepsize
77 // data vector defined by
78 // i) a 1D vector containing the same number
79 // of elements than the total number of the
80 // shape vector
81
82 std::vector<double> origin; // the starting point
83 std::vector<double> extents; // the final points
84 std::vector<int> i_extents; // extents in integers: number of
85 // points at the edges (ie 20 X 30 X 40 grid)
86 double step_size; // grid step size
87 long data_size; // total number of points
88
89public:
90 // default ctor allocates a 1D grid starting at 0.0 to 1.0
91 // with 1.0 stepsize (2 elements at least needed for MOE)
93
94 // parametrized ctor receives grid as the origin vector, the extent
95 // vector and stepsize
96 RBTDLL_EXPORT MOEGridShape(std::vector<double>, std::vector<double>, double);
97
98 const std::vector<double> &GetOrigin() { return origin; }
99 const std::vector<double> &GetExtents() { return extents; }
100 const std::vector<int> &GetIExtents() { return i_extents; }
101 double GetStepSize() { return step_size; }
102 long GetDataSize() { return data_size; }
103};
104
105typedef std::vector<MOEGridPoint> MOEGridData;
106
107// MOE grid data class for IO
108//
109// the MOE grid file format (in the present stage at 06/03/2003)
110class MOEGrid {
111 MOEGridShape myShape;
112 MOEGridData myData;
113 std::string stream_name; // filename
114 Coord min, max; // common extent min and max coords
115 Coord c_min, c_max; // current extent min and max coords
116public:
117 // default ctor
118 RBTDLL_EXPORT MOEGrid();
119 // parameterised ctor for a single grid
120 // pass shape, data and outfilename
121 MOEGrid(MOEGridShape &, MOEGridData &, std::string);
122 // or pass parameters using these functions (when it is about
123 // to save multiple grids into a single file)
124 void SetShape(MOEGridShape &a_shape) { myShape = a_shape; }
125 void SetData(MOEGridData &a_data) { myData = a_data; }
126 void SetOutputFileName(std::string &a_filename) { stream_name = a_filename; }
127 // methods to calculate grid extents
128 RBTDLL_EXPORT void
129 CalculateCommonExtents(std::vector<std::string> strPrmFiles); // for all
130 void GetDockingSiteExtents(std::string &a_strPrmFile); // for a single
131 // get methods
132 Coord GetMinExtents() { return min; }
133 Coord GetMaxExtents() { return max; }
134
135 // iofstream methods
136 RBTDLL_EXPORT long WriteGrid(
137 std::ios_base::openmode mode); // returns the number of points written
138 long ReadGrid(); // ditto (fields read)
139};
140
141// the relevant SVL code in gridshow.svl
142//
143// basic double should be the IEEE 8 byte double MSB first in Linux
144// on big-endian try swab with dd and/or cpio
145// MOE grid format:
146//
147// Note: the internal grid format (subject to change without notice!)
148// Header for the grid-file only:
149// GRID_SIGNATURE 8 bytes
150// Each grid:
151// version number int4m
152// ndata (= length data) int4m
153// ndim (= length size) int4m
154// skip int4m
155// ... (reserved for future use) byte * skip
156// size (= app length shape) int4m * ndim
157// shape ieee8m * (add size)
158// data ieee8m * ndata
159//
160// On reading, we check that ndata, ndim, and size are 24-bit non-negatives,
161// but we don't check "ndata == (mul size)"
162//
163// snippets from '$MOE/lib/svl/run/gridshow.svl'
164// const GRID_SIGNATURE = "SVLgrid\n";
165// const VERSION = 100;
166// const SKIP = 0;
167//
168// Check file signature and return non-zero if the file of file name fn
169// is a "grid file", i.e. a special file that contains exactly one grid
170// and nothing else
171//
172// local function read_gridsign fn =
173// freadb [fn, 'char', length GRID_SIGNATURE] === GRID_SIGNATURE;
174
175// Write grid to a file of given filename or filehandle
176//
177// local function writeb_fnum_grid [fn, [data, shape]]
178// local ndata = length data;
179// local ndim = length shape;
180// local size = app length shape;
181//
182// fwriteb [fn, 'int4m', [VERSION, ndata, ndim, SKIP]];
183// fwriteb [fn, 'char', rep ["\0", SKIP]];
184// fwriteb [fn, 'int4m', size];
185// fwriteb [fn, 'IEEE8m', cat shape];
186// fwriteb [fn, 'IEEE8m', data];
187// endfunction
188//
189// function grid_fwriteb [fn, grid]
190// if type fn === 'num' then writeb_fnum_grid [fn, grid]; return; endif
191// fn = fopenw fn;
192// writeb_fnum_grid [fn, grid];
193// fclose fn;
194// endfunction
195//
196// Create/rewrite "grid-file" of given name that willcontain a given grid
197//
198// function grid_writefile [fn, grid]
199// fn = fopenw fn;
200// fwriteb [fn, 'char', GRID_SIGNATURE];
201// writeb_fnum_grid [fn, grid];
202// fclose fn;
203// endfunction
204
205// fwriteb [fn, 'char', GRID_SIGNATURE];
206// fwriteb [fn, 'int4m', [VERSION, ndata, ndim, SKIP]];
207// fwriteb [fn, 'char', rep ["\0", SKIP]];
208// fwriteb [fn, 'int4m', size];
209// fwriteb [fn, 'IEEE8m', cat shape];
210// fwriteb [fn, 'IEEE8m', data];
211
212} // namespace rxdock
213
214#endif //_RBTMOEGRID_H_
Definition Coord.h:45
Definition MOEGrid.h:50
Definition MOEGrid.h:71
Definition MOEGrid.h:110