• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files

grid.h

Go to the documentation of this file.
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.sourceforge.net/>
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 
00027 #include <iosfwd>
00028 #include <algorithm>
00029 #include <vector>
00030 #include <string>
00031 
00032 namespace OpenBabel
00033 {
00034 
00035   // Forward declaration
00036   class OBMol;
00037 
00040  class OBAPI OBGrid: public OBBase
00041   {
00042   protected:
00043     double _xmin,_xmax,_ymin,_ymax,_zmin,_zmax; 
00044 
00045   public:
00046     OBGrid() {}
00047 
00051     virtual void Init(OBMol &box);
00052 
00054     double GetXmin() const    { return(_xmin);    }
00056     double GetYmin() const    { return(_ymin);    }
00058     double GetZmin() const    { return(_zmin);    }
00060     double GetXmax() const    { return(_xmax);    }
00062     double GetYmax() const    { return(_ymax);    }
00064     double GetZmax() const    { return(_zmax);    }
00065 
00067     bool PointIsInBox(double x,double y,double z)
00068     {
00069       return (x>=_xmin) && (x<=_xmax) &&
00070         (y>=_ymin) && (y<=_ymax) &&
00071         (z>=_zmin) && (z<=_zmax);
00072     }
00074     bool PointIsInBox(double *c)
00075     {
00076       return (c[0]>=_xmin) && (c[0]<=_xmax) &&
00077         (c[1]>=_ymin) && (c[1]<=_ymax) &&
00078         (c[2]>=_zmin) && (c[2]<=_zmax);
00079     }
00080 
00082     bool PointIsInBox(vector3 v)
00083     {
00084       return (v.x() >= _xmin) && (v.x() <=_xmax) &&
00085       (v.y()>=_ymin) && (v.y()<=_ymax) &&
00086       (v.z()>=_zmin) && (v.z()<=_zmax);
00087     }
00088   };
00089 
00097  class OBAPI OBFloatGrid: public OBGrid
00098   {
00099   protected:
00100     std::vector<double> _values;   
00101     int   *_ival;             
00102     double _midz,_midx,_midy; 
00103     int _ydim,_xdim,_zdim;    
00104     double _spacing,_inv_spa; 
00105     double _halfSpace;        
00106 
00107     vector3 _xAxis, _yAxis, _zAxis;
00108 
00109   public:
00110 
00111     OBFloatGrid() : _ival(NULL), _halfSpace(0.0) {}
00112     ~OBFloatGrid()
00113     {
00114       if (_ival) delete [] _ival;
00115     }
00116 
00119     void Init(OBMol &box,double spacing, double pad=0.0);
00120 
00122     vector3 GetMin() { return vector3(_xmin, _ymin, _zmin); }
00123 
00127     void GetMin(double *a)
00128     {
00129       a[0]=_xmin;
00130       a[1]=_ymin;
00131       a[2]=_zmin;
00132     }
00133 
00135     vector3 GetMax() { return vector3(_xmax, _ymax, _zmax); }
00136 
00140     void GetMax(double *a)
00141     {
00142       a[0]=_xmax;
00143       a[1]=_ymax;
00144       a[2]=_zmax;
00145     }
00146 
00148     double GetSpacing() const { return(_spacing); }
00152     void GetSpacing(double &s)
00153     {
00154       s=_spacing;
00155     }
00157     double GetScale() const   { return(_inv_spa); }
00159     double GetHalfSpace() const {return(_halfSpace);}
00161     int GetXdim() const       { return(_xdim);    }
00163     int GetYdim() const       { return(_ydim);    }
00165     int GetZdim() const       { return(_zdim);    }
00169     void GetDim(int *a)
00170     {
00171       a[0]=_xdim;
00172       a[1]=_ydim;
00173       a[2]=_zdim;
00174     }
00175 
00177     vector3 GetMidpointVector()
00178     {
00179       vector3 v;
00180       v.Set(_midx,_midy,_midz);
00181       return(v);
00182     }
00183 
00185     vector3 GetXAxis() const
00186     {
00187       return _xAxis;
00188     }
00189 
00191     vector3 GetYAxis() const
00192     {
00193       return _yAxis;
00194     }
00195 
00197     vector3 GetZAxis() const
00198     {
00199       return _zAxis;
00200     }
00201 
00203     void SetNumberOfPoints(int nx, int ny, int nz);
00204 
00206     void SetXAxis(vector3);
00208     void SetYAxis(vector3);
00210     void SetZAxis(vector3);
00211 
00216     void SetLimits(const vector3& origin, const vector3& x, const vector3& y,
00217                    const vector3& z);
00220     void SetLimits(const double origin[3], const double x[3], const double y[3],
00221                    const double z[3]);
00222 
00224     std::vector<double> GetDataVector();
00228     void SetVals(const std::vector<double> & vals);
00229 
00234     double *GetVals()    {        return(&_values[0]);    }
00235 
00237     double GetValue(int i, int j, int k)
00238     {
00239       if (i*_ydim*_zdim + j*_zdim + k > _xdim*_ydim*_zdim)
00240         return 0.0;
00241       else
00242         return _values[i*_ydim*_zdim + j*_zdim + k];
00243     }
00244 
00247     void SetVals(double *ptr)
00248     {
00249      for (int i = 0; i < _xdim*_ydim*_zdim; ++i)
00250        _values[i] = ptr[i];
00251     }
00252 
00254     bool SetValue(int i, int j, int k, double val)
00255     {
00256       if (i*_ydim*_zdim + j*_zdim + k > _xdim*_ydim*_zdim)
00257         return false;
00258 
00259       _values[i*_ydim*_zdim + j*_zdim + k] = val;
00260       return true;
00261     }
00262 
00264     vector3 Center()
00265     {
00266       return vector3(_midx,_midy,_midz);
00267     }
00268 
00269     friend std::ostream& operator<< ( std::ostream&, const OBFloatGrid& ) ;
00270     friend std::istream& operator>> ( std::istream&,OBFloatGrid& ) ;
00271 
00273     double Inject(double x,double y,double z);
00274     void IndexToCoords(int idx, double &x, double &y, double &z);
00275     void CoordsToIndex(int*,double*);
00276     int CoordsToIndex(double x, double y, double z);
00278     double Interpolate(double,double,double);
00280     double InterpolateDerivatives(double,double,double,double *derivatives);
00281   };
00282 
00283 #ifndef OBPolarGrid
00284 #define OBPolarGrid 0x01 /* polar interactions? */
00285 #endif //OBPolarGrid
00286 
00287 #ifndef OBLipoGrid
00288 #define OBLipoGrid 0x02 /* lipophilicity? */
00289 #endif //OBLipoGrid
00290 
00294  class OBAPI OBProxGrid: public OBGrid
00295   {
00296   protected:
00297     int _gridtype;
00298     int _nxinc,_nyinc,_nzinc,_maxinc;
00299     double _inc;
00300     std::vector<std::vector<int> > cell;
00301 
00302   public:
00303 
00304     OBProxGrid(int gridtype=0)
00305       {
00306         _gridtype=gridtype;
00307       }
00308     ~OBProxGrid()
00309       {}
00310     void Setup(OBMol &mol,OBMol &box, double cutoff,double resolution = 0.5);
00311     void Setup(OBMol &mol,OBMol &box, double cutoff,
00312                std::vector<bool> &use,double resolution = 0.5);
00313     std::vector<int> *GetProxVector(double,double,double);
00314     std::vector<int> *GetProxVector(double*);
00315 
00316     bool LipoGrid()
00317     {
00318       return((_gridtype&OBLipoGrid) ? true : false);
00319     }
00320     bool PolarGrid()
00321     {
00322       return(_gridtype&OBPolarGrid);
00323     }
00324     void SetGridType(int gridtype)
00325     {
00326       _gridtype = gridtype;
00327     }
00328   };
00329 
00330   // scoring function used: PLP = Piecewise Linear Potential or ChemScore algorithm
00331   typedef enum { Undefined = -1, PLP, ChemScore } score_t;
00332 
00336   class OBAPI OBScoreGrid
00337   {
00338   protected:
00339     score_t gridtype;
00340     bool verbose;
00341 
00342   public:
00343 
00344     double score;
00345 
00346     OBScoreGrid(void)                 {  verbose = false;      }
00347     virtual ~OBScoreGrid(void) {}
00348 
00349     void    SetVerbose(bool v)        {      verbose = v;      }
00350     void    SetType(score_t type)     {      gridtype = type;  }
00351     score_t GetType(void)             {    return gridtype;    }
00352 
00353     virtual void   Clear(void)        { }
00354     virtual double  Eval(double *)    {       return -1;       }
00355     virtual double  Eval(OBMol &mol){return Eval(mol.GetCoordinates());}
00356     virtual void   Init(OBMol &, OBMol &, std::string &, double){}
00357     virtual void   Setup(OBMol &) {}
00358     virtual void   Setup(OBMol &, std::vector<int> &){}
00359     virtual void   Setup(std::vector<int> &) {}
00360     virtual void   Config(std::string) {}
00361     virtual bool   Read(std::string)   {      return false;    }
00362     virtual bool   Write(std::string)  {      return false;    }
00363     virtual vector3 Center()           {      return VZero;    }
00364     virtual vector3 CenterMol(OBMol &) {      return VZero;    }
00365   };
00366 
00367 } // end namespace OpenBabel
00368 
00369 #endif // OB_GRID_H
00370 

This file is part of the documentation for Open Babel, version 2.2.0.

Documentation copyright © 1998-2007, the Open Babel Developers.
Open Babel is hosted by: SourceForge Logo
Generated on Thu Jul 3 14:30:33 2008 by doxygen 1.5.6.