00001 /********************************************************************** 00002 grid.h - Handle grids of values. 00003 00004 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. 00005 Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison 00006 Some Portions Copyright (C) 2008 by Marcus D. Hanwell 00007 00008 This file is part of the Open Babel project. 00009 For more information, see <http://openbabel.org/> 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation version 2 of the License. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 ***********************************************************************/ 00020 00021 #ifndef OB_GRID_H 00022 #define OB_GRID_H 00023 00024 #include <openbabel/babelconfig.h> 00025 #include <openbabel/math/vector3.h> 00026 #include <openbabel/base.h> 00027 00028 // Necessary evil for 2.x series -- should use OBMol* below 00029 #include <openbabel/mol.h> 00030 00031 #include <iosfwd> 00032 #include <algorithm> 00033 #include <vector> 00034 #include <string> 00035 00036 namespace OpenBabel 00037 { 00038 00039 // Forward declaration 00040 class OBMol; 00041 00044 class OBAPI OBGrid: public OBBase 00045 { 00046 protected: 00047 double _xmin,_xmax,_ymin,_ymax,_zmin,_zmax; 00048 00049 public: 00050 OBGrid() {} 00051 00055 virtual void Init(OBMol &box); 00056 00058 double GetXmin() const { return(_xmin); } 00060 double GetYmin() const { return(_ymin); } 00062 double GetZmin() const { return(_zmin); } 00064 double GetXmax() const { return(_xmax); } 00066 double GetYmax() const { return(_ymax); } 00068 double GetZmax() const { return(_zmax); } 00069 00071 bool PointIsInBox(double x,double y,double z) 00072 { 00073 return (x>=_xmin) && (x<=_xmax) && 00074 (y>=_ymin) && (y<=_ymax) && 00075 (z>=_zmin) && (z<=_zmax); 00076 } 00078 bool PointIsInBox(double *c) 00079 { 00080 return (c[0]>=_xmin) && (c[0]<=_xmax) && 00081 (c[1]>=_ymin) && (c[1]<=_ymax) && 00082 (c[2]>=_zmin) && (c[2]<=_zmax); 00083 } 00084 00086 bool PointIsInBox(vector3 v) 00087 { 00088 return (v.x() >= _xmin) && (v.x() <=_xmax) && 00089 (v.y()>=_ymin) && (v.y()<=_ymax) && 00090 (v.z()>=_zmin) && (v.z()<=_zmax); 00091 } 00092 }; 00093 00101 class OBAPI OBFloatGrid: public OBGrid 00102 { 00103 protected: 00104 std::vector<double> _values; 00105 int *_ival; 00106 double _midz,_midx,_midy; 00107 int _ydim,_xdim,_zdim; 00108 double _spacing,_inv_spa; 00109 double _halfSpace; 00110 00111 vector3 _xAxis, _yAxis, _zAxis; 00112 00113 public: 00114 00115 OBFloatGrid() : _ival(NULL), _halfSpace(0.0) {} 00116 ~OBFloatGrid() 00117 { 00118 if (_ival) delete [] _ival; 00119 } 00120 00123 void Init(OBMol &box,double spacing, double pad=0.0); 00124 00126 vector3 GetMin() { return vector3(_xmin, _ymin, _zmin); } 00127 00131 void GetMin(double *a) 00132 { 00133 a[0]=_xmin; 00134 a[1]=_ymin; 00135 a[2]=_zmin; 00136 } 00137 00139 vector3 GetMax() { return vector3(_xmax, _ymax, _zmax); } 00140 00144 void GetMax(double *a) 00145 { 00146 a[0]=_xmax; 00147 a[1]=_ymax; 00148 a[2]=_zmax; 00149 } 00150 00152 double GetSpacing() const { return(_spacing); } 00156 void GetSpacing(double &s) 00157 { 00158 s=_spacing; 00159 } 00161 double GetScale() const { return(_inv_spa); } 00163 double GetHalfSpace() const {return(_halfSpace);} 00165 int GetXdim() const { return(_xdim); } 00167 int GetYdim() const { return(_ydim); } 00169 int GetZdim() const { return(_zdim); } 00173 void GetDim(int *a) 00174 { 00175 a[0]=_xdim; 00176 a[1]=_ydim; 00177 a[2]=_zdim; 00178 } 00179 00181 vector3 GetMidpointVector() 00182 { 00183 vector3 v; 00184 v.Set(_midx,_midy,_midz); 00185 return(v); 00186 } 00187 00189 vector3 GetXAxis() const 00190 { 00191 return _xAxis; 00192 } 00193 00195 vector3 GetYAxis() const 00196 { 00197 return _yAxis; 00198 } 00199 00201 vector3 GetZAxis() const 00202 { 00203 return _zAxis; 00204 } 00205 00207 void SetNumberOfPoints(int nx, int ny, int nz); 00208 00210 void SetXAxis(vector3); 00212 void SetYAxis(vector3); 00214 void SetZAxis(vector3); 00215 00220 void SetLimits(const vector3& origin, const vector3& x, const vector3& y, 00221 const vector3& z); 00224 void SetLimits(const double origin[3], const double x[3], const double y[3], 00225 const double z[3]); 00226 00228 std::vector<double> GetDataVector(); 00232 void SetVals(const std::vector<double> & vals); 00233 00238 double *GetVals() { return(&_values[0]); } 00239 00241 double GetValue(int i, int j, int k) 00242 { 00243 if (i*_ydim*_zdim + j*_zdim + k > _xdim*_ydim*_zdim) 00244 return 0.0; 00245 else 00246 return _values[i*_ydim*_zdim + j*_zdim + k]; 00247 } 00248 00251 void SetVals(double *ptr) 00252 { 00253 for (int i = 0; i < _xdim*_ydim*_zdim; ++i) 00254 _values[i] = ptr[i]; 00255 } 00256 00258 bool SetValue(int i, int j, int k, double val) 00259 { 00260 if (i*_ydim*_zdim + j*_zdim + k > _xdim*_ydim*_zdim) 00261 return false; 00262 00263 _values[i*_ydim*_zdim + j*_zdim + k] = val; 00264 return true; 00265 } 00266 00268 vector3 Center() 00269 { 00270 return vector3(_midx,_midy,_midz); 00271 } 00272 00273 friend std::ostream& operator<< ( std::ostream&, const OBFloatGrid& ) ; 00274 friend std::istream& operator>> ( std::istream&,OBFloatGrid& ) ; 00275 00277 double Inject(double x,double y,double z); 00278 void IndexToCoords(int idx, double &x, double &y, double &z); 00279 void CoordsToIndex(int*,double*); 00280 int CoordsToIndex(double x, double y, double z); 00282 double Interpolate(double,double,double); 00284 double InterpolateDerivatives(double,double,double,double *derivatives); 00285 }; 00286 00287 #ifndef OBPolarGrid 00288 #define OBPolarGrid 0x01 /* polar interactions? */ 00289 #endif //OBPolarGrid 00290 00291 #ifndef OBLipoGrid 00292 #define OBLipoGrid 0x02 /* lipophilicity? */ 00293 #endif //OBLipoGrid 00294 00298 class OBAPI OBProxGrid: public OBGrid 00299 { 00300 protected: 00301 int _gridtype; 00302 int _nxinc,_nyinc,_nzinc,_maxinc; 00303 double _inc; 00304 std::vector<std::vector<int> > cell; 00305 00306 public: 00307 00308 OBProxGrid(int gridtype=0) 00309 { 00310 _gridtype=gridtype; 00311 } 00312 ~OBProxGrid() 00313 {} 00314 void Setup(OBMol &mol,OBMol &box, double cutoff,double resolution = 0.5); 00315 void Setup(OBMol &mol,OBMol &box, double cutoff, 00316 std::vector<bool> &use,double resolution = 0.5); 00317 std::vector<int> *GetProxVector(double,double,double); 00318 std::vector<int> *GetProxVector(double*); 00319 00320 bool LipoGrid() 00321 { 00322 return((_gridtype&OBLipoGrid) ? true : false); 00323 } 00324 bool PolarGrid() 00325 { 00326 return(_gridtype&OBPolarGrid); 00327 } 00328 void SetGridType(int gridtype) 00329 { 00330 _gridtype = gridtype; 00331 } 00332 }; 00333 00334 // scoring function used: PLP = Piecewise Linear Potential or ChemScore algorithm 00335 typedef enum { Undefined = -1, PLP, ChemScore } score_t; 00336 00340 class OBAPI OBScoreGrid 00341 { 00342 protected: 00343 score_t gridtype; 00344 bool verbose; 00345 00346 public: 00347 00348 double score; 00349 00350 OBScoreGrid(void) { verbose = false; } 00351 virtual ~OBScoreGrid(void) {} 00352 00353 void SetVerbose(bool v) { verbose = v; } 00354 void SetType(score_t type) { gridtype = type; } 00355 score_t GetType(void) { return gridtype; } 00356 00357 virtual void Clear(void) { } 00358 virtual double Eval(double *) { return -1; } 00359 virtual double Eval(OBMol &mol){return Eval(mol.GetCoordinates());} 00360 virtual void Init(OBMol &, OBMol &, std::string &, double){} 00361 virtual void Setup(OBMol &) {} 00362 virtual void Setup(OBMol &, std::vector<int> &){} 00363 virtual void Setup(std::vector<int> &) {} 00364 virtual void Config(std::string) {} 00365 virtual bool Read(std::string) { return false; } 00366 virtual bool Write(std::string) { return false; } 00367 virtual vector3 Center() { return VZero; } 00368 virtual vector3 CenterMol(OBMol &) { return VZero; } 00369 }; 00370 00371 } // end namespace OpenBabel 00372 00373 #endif // OB_GRID_H 00374
This file is part of the documentation for Open Babel, version 2.3.