data.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 data.h - Global data and resource file parsers.
00003  
00004 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
00005 Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison
00006  
00007 This file is part of the Open Babel project.
00008 For more information, see <http://openbabel.sourceforge.net/>
00009  
00010 This program is free software; you can redistribute it and/or modify
00011 it under the terms of the GNU General Public License as published by
00012 the Free Software Foundation version 2 of the License.
00013  
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 ***********************************************************************/
00019 
00020 #ifndef OB_DATA_H
00021 #define OB_DATA_H
00022 
00023 #include <openbabel/babelconfig.h>
00024 
00025 #include <stdio.h>
00026 
00027 #include <fstream>
00028 #include <vector>
00029 #include <string>
00030 
00031 namespace OpenBabel
00032 {
00033 
00034   class OBAtom;
00035   class OBMol;
00036   class OBBitVec;
00037 
00048   class OBAPI OBGlobalDataBase
00049     {
00050     protected:
00051       bool         _init;               
00052       const char  *_dataptr;
00053       std::string  _filename;
00054       std::string  _dir;                
00055       std::string  _subdir;     
00056       std::string  _envvar;     
00057 
00058     public:
00060       OBGlobalDataBase(): _init(false), _dataptr(NULL) { }
00062       virtual ~OBGlobalDataBase()                  {}
00064       void  Init();
00066       virtual unsigned int GetSize()                 { return 0;}
00068       void  SetReadDirectory(char *dir)            { _dir = dir;    }
00070       void  SetEnvironmentVariable(char *var)      { _envvar = var; }
00072       virtual void ParseLine(const char*)          {}
00073     };
00074 
00081   class OBAPI OBElement
00082     {
00083       int _num;
00084       char _symbol[3];
00085       std::string _name;
00086       double _Rcov,_Rvdw,_mass,_elNeg,_ionize,_elAffinity;
00087       double _red, _green, _blue;
00088       int _maxbonds;
00089     public:
00091       OBElement()    {}
00107       OBElement(int num, const char *sym, double rcov, double rvdw,
00108                 int maxbo, double mass, double elNeg, double ionize,
00109                 double elAffin, double red, double green, double blue,
00110                 std::string name) :
00111         _num(num), _name(name), _Rcov(rcov), _Rvdw(rvdw), _mass(mass), 
00112         _elNeg(elNeg), _ionize(ionize), _elAffinity(elAffin), 
00113         _red(red), _green(green), _blue(blue),
00114         _maxbonds(maxbo)
00115         {
00116           strncpy(_symbol, sym, 3);
00117         }
00118 
00120       int GetAtomicNum()         {       return(_num);    }
00122       const char *GetSymbol()    {       return(_symbol); }
00124       double GetCovalentRad()    {       return(_Rcov);   }
00126       double GetVdwRad()         {       return(_Rvdw);   }
00128       double GetMass()           {       return(_mass);   }
00130       int GetMaxBonds()          {       return(_maxbonds);}
00132       double GetElectroNeg()     {       return(_elNeg);  }
00134       double GetIonization()     {       return(_ionize);  }
00136       double GetElectronAffinity(){      return(_elAffinity);  }
00138       std::string GetName()      {       return(_name);    }
00140       double GetRed()            {       return(_red);     }
00142       double GetGreen()          {       return(_green);   }
00144       double GetBlue()           {       return(_blue);    }
00145     };
00146 
00147   // class introduction in data.cpp
00148   class OBAPI OBElementTable : public OBGlobalDataBase
00149     {
00150       std::vector<OBElement*> _element;
00151 
00152     public:
00153 
00154       OBElementTable(void);
00155       ~OBElementTable();
00156 
00157       void  ParseLine(const char*);
00158 
00160       unsigned int              GetNumberOfElements();
00162       unsigned int    GetSize() { return GetNumberOfElements(); }
00163 
00165       int   GetAtomicNum(const char *);
00169       int   GetAtomicNum(const char *, int &iso);
00171       const char *GetSymbol(int);
00173       double GetVdwRad(int);
00175       double GetCovalentRad(int);
00178       double GetMass(int);
00181       double CorrectedBondRad(int,int = 3); // atomic #, hybridization
00184       double CorrectedVdwRad(int,int = 3); // atomic #, hybridization
00186       int       GetMaxBonds(int);
00188       double GetElectroNeg(int);
00190       double GetIonization(int);
00192       double GetElectronAffinity(int);
00194       std::vector<double> GetRGB(int);
00196       std::string GetName(int);
00197     };
00198 
00199   // class introduction in data.cpp
00200   class OBAPI OBIsotopeTable : public OBGlobalDataBase
00201     {
00202       std::vector<std::vector<std::pair <unsigned int, double> > > _isotopes;
00203 
00204     public:
00205 
00206       OBIsotopeTable(void);
00207       ~OBIsotopeTable()    {}
00208 
00210       unsigned int GetSize() { return _isotopes.size(); }
00211 
00212       void      ParseLine(const char*);
00215       double    GetExactMass(const unsigned int atomicNum,
00216                            const unsigned int isotope = 0);
00217     };
00218 
00219   // class introduction in data.cpp
00220   class OBAPI OBTypeTable : public OBGlobalDataBase
00221     {
00222       int             _linecount;
00223       unsigned int    _ncols,_nrows;
00224       int             _from,_to;
00225       std::vector<std::string> _colnames;
00226       std::vector<std::vector<std::string> > _table;
00227 
00228     public:
00229 
00230       OBTypeTable(void);
00231       ~OBTypeTable() {}
00232 
00233       void ParseLine(const char*);
00234 
00236       unsigned int GetSize() { return _table.size(); }
00237 
00239       bool SetFromType(const char*);
00241       bool SetToType(const char*);
00243       bool Translate(char *to, const char *from); // to, from
00246       bool Translate(std::string &to, const std::string &from); // to, from
00249       std::string Translate(const std::string &from);
00250 
00252       std::string GetFromType();
00254       std::string GetToType();
00255     };
00256 
00262   class OBAPI OBResidueData : public OBGlobalDataBase
00263     {
00264       int                                               _resnum;
00265       std::vector<std::string>                          _resname;
00266       std::vector<std::vector<std::string> >            _resatoms;
00267       std::vector<std::vector<std::pair<std::string,int> > > _resbonds;
00268 
00269       //variables used only temporarily for parsing resdata.txt
00270       std::vector<std::string>                          _vatmtmp;
00271       std::vector<std::pair<std::string,int> >          _vtmp;
00272     public:
00273 
00274       OBResidueData();
00275       void ParseLine(const char*);
00276 
00278       unsigned int GetSize() { return _resname.size(); }
00279 
00283       bool SetResName(const std::string &);
00286       int  LookupBO(const std::string &);
00289       int  LookupBO(const std::string &, const std::string&);
00293       bool LookupType(const std::string &,std::string&,int&);
00297       bool AssignBonds(OBMol &,OBBitVec &);
00298     };
00299 
00301   // full documentation in data.cpp
00302   OBAPI std::string OpenDatafile(std::ifstream& fs, 
00303                                  const std::string& filename,
00304                                  const std::string& envvar = "BABEL_DATADIR");
00305 
00306   // Used by other code for reading files
00307 #ifdef WIN32
00308 #define FILE_SEP_CHAR "\\"
00309 #else
00310 #define FILE_SEP_CHAR "/"
00311 #endif
00312 
00313 } // end namespace OpenBabel
00314 
00315 #endif //DATA_H
00316