File: grid.h

package info (click to toggle)
ghemical 1.01-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 10,984 kB
  • ctags: 19,443
  • sloc: ansic: 69,073; cpp: 60,583; fortran: 35,324; sh: 5,419; makefile: 506; perl: 91
file content (180 lines) | stat: -rw-r--r-- 5,937 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**********************************************************************
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
Some portions Copyright (c) 2001-2002 by Geoffrey R. Hutchison

This file is part of the Open Babel project.
For more information, see <http://openbabel.sourceforge.net/>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
***********************************************************************/

#ifndef OB_GRID_H
#define OB_GRID_H

#ifdef __sgi
#include <iostream.h>
#else
#include <iostream>
#endif

#include <algorithm>
#include <vector>
#include <string>

#ifndef OBPolarGrid
#define OBPolarGrid 0x01
#endif //OBPolarGrid

#ifndef OBLipoGrid
#define OBLipoGrid 0x02
#endif //OBLipoGrid

namespace OpenBabel {

class OBProxGrid
{
  int _gridtype;
  int _nxinc,_nyinc,_nzinc,_maxinc;
  float _xmin,_xmax,_ymin,_ymax,_zmin,_zmax,_inc;
  std::vector<std::vector<int> > cell;

public:

  OBProxGrid(int gridtype=0){_gridtype=0;}
  ~OBProxGrid(){}
  void Setup(OBMol &,OBMol &,float,float res=0.5);
  void Setup(OBMol &,OBMol &,float,std::vector<bool>&,float res=0.5);
  std::vector<int> *GetProxVector(float,float,float);
  std::vector<int> *GetProxVector(float*);
  // For HasFlag force return type to bool so VC6.0 doesn't complain
  bool LipoGrid() {return((_gridtype&OBLipoGrid) ? true : false);}
  bool PolarGrid() {return(_gridtype&OBPolarGrid);}
  void SetGridType(int gridtype) {_gridtype = gridtype;}
  bool PointIsInBox(float x,float y,float z)
    {
      if (x>_xmin && x<_xmax && y>_ymin && y<_ymax &&
	  z>_zmin && z<_zmax)
	return(true);
      return(false);
    }
};

class OBFloatGrid
{
  float *_val;             /* floating point values */
  int   *_ival;            /* for integer values */
  float _midz,_midx,_midy;   /* center of grid in world coordinates */
  int _ydim,_xdim,_zdim;     /* grid dimensions */
  float _spacing,_inv_spa;  /* spacing between grid points and its inverse*/
  float _xmin,_xmax,_ymin,_ymax,_zmin,_zmax;
  float _halfSpace;         /* half of the grid spacing */        

public:

    OBFloatGrid() : _halfSpace(0.0f) {_val=NULL;_ival=NULL;}
    ~OBFloatGrid() {if (_ival) {delete [] _ival; _ival = NULL;}
                    if (_val) {delete [] _val; _val = NULL;}}
  void Init(OBMol &,float, float pad= 0.0f); //initialized using boxfile
  bool PointIsInBox(float x,float y,float z)
    {
      if (x < _xmin || x > _xmax) return(false);
      if (y < _ymin || y > _ymax) return(false);
      if (z < _zmin || z > _zmax) return(false);
      return(true);
    }
  bool PointIsInBox(float *c)
    {
      if (c[0] < _xmin || c[0] > _xmax) return(false);
      if (c[1] < _ymin || c[1] > _ymax) return(false);
      if (c[2] < _zmin || c[2] > _zmax) return(false);
      return(true);
    }
  float GetXmin() const {return(_xmin);}
  float GetYmin() const {return(_ymin);}
  float GetZmin() const {return(_zmin);}
  float GetXmax() const {return(_xmax);}
  float GetYmax() const {return(_ymax);}
  float GetZmax() const {return(_zmax);}
  float GetSpacing() const {return(_spacing);}
  float GetScale() const {return(_inv_spa);}
  float GetHalfSpace() const {return(_halfSpace);}
  int GetXdim() const {return(_xdim);}
  int GetYdim() const {return(_ydim);}
  int GetZdim() const {return(_zdim);}
  void GetMin(float *a) {a[0]=_xmin;a[1]=_ymin;a[2]=_zmin;}
  void GetMax(float *a) {a[0]=_xmax;a[1]=_ymax;a[2]=_zmax;}
  void GetDim(int *a)   {a[0]=_xdim;a[1]=_ydim;a[2]=_zdim;}
  void GetSpacing(float &s) {s=_spacing;}
  Vector GetMidpointVector() 
    {Vector v; v.Set(_midx,_midy,_midz); return(v);}
  float *GetVals() {return(_val);}
  void SetVals(float *ptr) {_val = ptr;}
  Vector Center() { return Vector(_midx,_midy,_midz); } //added by jjc
  friend std::ostream& operator<< ( std::ostream&, const OBFloatGrid& ) ;
  friend std::istream& operator>> ( std::istream&,OBFloatGrid& ) ;

  float Inject(float x,float y,float z)
    {
      if((x<=_xmin)||(x>=_xmax)) return(0.0);
      if((y<=_ymin)||(y>=_ymax)) return(0.0);
      if((z<=_zmin)||(z>=_zmax)) return(0.0);

      int gx=(int)((x-_xmin)*_inv_spa);
      int gy=(int)((y-_ymin)*_inv_spa);
      int gz=(int)((z-_zmin)*_inv_spa);

      return(_val[(gz*_ydim*_xdim)+(gy*_xdim)+gx]);
    }


  void IndexToCoords(int idx, float &x, float &y, float &z);
  void CoordsToIndex(int*,float*);
  int CoordsToIndex(float &x, float &y, float &z);
  float Interpolate(float,float,float);
	float InterpolateDerivatives(float,float,float,float *derivatives);
};

typedef enum { Undefined = -1, PLP, ChemScore } score_t;

class OBScoreGrid
{
protected:

  score_t gridtype;
  bool verbose;

public:

  float score;

  OBScoreGrid(void) { verbose = false; }
  virtual ~OBScoreGrid(void) {}

  void    SetVerbose(bool v)    { verbose = v; }
  void    SetType(score_t type) { gridtype = type; }
  score_t GetType(void)         { return gridtype; }

  virtual void   Clear(void) { }
  virtual float  Eval(float *)    { return -1; }
  virtual float  Eval(OBMol &mol) { return Eval(mol.GetCoordinates()); }
  virtual void   Init(OBMol &, OBMol &, std::string &, float) {}
  virtual void   Setup(OBMol &) {}
  virtual void   Setup(OBMol &, std::vector<int> &) {}
  virtual void   Setup(std::vector<int> &) {}
  virtual void   Config(std::string) {}
  virtual bool   Read(std::string)       { return false; }
  virtual bool   Write(std::string)      { return false; }
  virtual Vector Center()           { return VZero; }
  virtual Vector CenterMol(OBMol &) { return VZero; }
};

} // end namespace OpenBabel

#endif // OB_GRID_H