00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef OB_GENERIC_H
00021 #define OB_GENERIC_H
00022
00023 #include <openbabel/babelconfig.h>
00024
00025 #include <string>
00026 #include <vector>
00027 #include <map>
00028
00029 #include <openbabel/math/vector3.h>
00030 #include <openbabel/obutil.h>
00031
00032 namespace OpenBabel
00033 {
00034
00035 class OBBase;
00036 class OBAtom;
00037 class OBBond;
00038 class OBRing;
00039
00040 OBAPI std::string& Trim(std::string& txt);
00041
00053 namespace OBGenericDataType
00054 {
00055 enum
00056 {
00058 UndefinedData = 0,
00059
00061 PairData = 1,
00062
00064 EnergyData = 2,
00065
00067 CommentData = 3,
00068
00070 ConformerData = 4,
00071
00073 ExternalBondData = 5,
00074
00076 RotamerList = 6,
00077
00079 VirtualBondData = 7,
00080
00082 RingData = 8,
00083
00085 TorsionData = 9,
00086
00088 AngleData = 10,
00089
00091 SerialNums = 11,
00092
00094 UnitCell = 12,
00095
00097 SpinData = 13,
00098
00100 ChargeData = 14,
00101
00103 SymmetryData = 15,
00104
00106 ChiralData = 16,
00107
00109 OccupationData = 17,
00110
00112 DensityData = 18,
00113
00115 ElectronicData = 19,
00116
00118 VibrationData = 20,
00119
00121 RotationData = 21,
00122
00124 NuclearData = 22,
00125
00127 SetData = 23,
00128
00129
00130
00132 CustomData0 = 16384,
00133 CustomData1 = 16385,
00134 CustomData2 = 16386,
00135 CustomData3 = 16387,
00136 CustomData4 = 16388,
00137 CustomData5 = 16389,
00138 CustomData6 = 16390,
00139 CustomData7 = 16391,
00140 CustomData8 = 16392,
00141 CustomData9 = 16393,
00142 CustomData10 = 16394,
00143 CustomData11 = 16395,
00144 CustomData12 = 16396,
00145 CustomData13 = 16397,
00146 CustomData14 = 16398,
00147 CustomData15 = 16399,
00148 };
00149 }
00150
00151 enum DataOrigin {
00152 any,
00153 fileformatInput,
00154 userInput,
00155 perceived,
00156 external
00157 };
00158
00159
00160
00162
00163 class OBAPI OBGenericData
00164 {
00165 protected:
00166 std::string _attr;
00167 unsigned int _type;
00168 DataOrigin _source;
00169 public:
00170 OBGenericData(const std::string attr = "undefined",
00171 const unsigned int type = OBGenericDataType::UndefinedData,
00172 const DataOrigin source = any);
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 virtual OBGenericData* Clone(OBBase* ) const
00185 { return NULL; }
00186 virtual ~OBGenericData() {}
00187
00188
00189
00191 void SetAttribute(const std::string &v)
00192 { _attr = v; }
00194 void SetOrigin(const DataOrigin s) { _source = s; }
00196 virtual const std::string &GetAttribute() const
00197 { return(_attr); }
00199 unsigned int GetDataType() const
00200 { return(_type); }
00203 virtual const std::string &GetValue() const
00204 { return _attr; }
00205 virtual DataOrigin GetOrigin() const
00206 { return _source; }
00207 };
00208
00211 class OBAPI OBCommentData : public OBGenericData
00212 {
00213 protected:
00214 std::string _data;
00215 public:
00216 OBCommentData();
00217 OBCommentData(const OBCommentData&);
00218 virtual OBGenericData* Clone(OBBase* ) const{return new OBCommentData(*this);}
00219
00220 OBCommentData& operator=(const OBCommentData &src);
00221
00222 void SetData(const std::string &data)
00223 { _data = data; Trim(_data); }
00224 void SetData(const char *d)
00225 {_data = d; Trim(_data); }
00226 const std::string &GetData() const
00227 { return(_data); }
00228 virtual const std::string &GetValue() const
00229 { return(_data); }
00230 };
00231
00235 class OBAPI OBExternalBond
00236 {
00237 int _idx;
00238 OBAtom *_atom;
00239 OBBond *_bond;
00240 public:
00241 OBExternalBond(): _idx(0), _atom(NULL), _bond(NULL) {}
00242 OBExternalBond(OBAtom *,OBBond *,int);
00243 OBExternalBond(const OBExternalBond &);
00244 ~OBExternalBond() {}
00245
00246 int GetIdx() const { return(_idx); }
00247 OBAtom *GetAtom() const { return(_atom); }
00248 OBBond *GetBond() const { return(_bond); }
00249 void SetIdx(int idx) { _idx = idx; }
00250 void SetAtom(OBAtom *atom) { _atom = atom; }
00251 void SetBond(OBBond *bond) { _bond = bond; }
00252 };
00253
00256 class OBAPI OBExternalBondData : public OBGenericData
00257 {
00258 protected:
00259 std::vector<OBExternalBond> _vexbnd;
00260 public:
00261 OBExternalBondData();
00262
00263
00264 virtual OBGenericData* Clone(OBBase* ) const{return NULL;}
00265
00266 void SetData(OBAtom*,OBBond*,int);
00267 std::vector<OBExternalBond> *GetData()
00268 {
00269 return(&_vexbnd);
00270 }
00271 };
00272
00278 class OBAPI OBPairData : public OBGenericData
00279 {
00280 protected:
00281 std::string _value;
00282 public:
00283 OBPairData();
00284 virtual OBGenericData* Clone(OBBase* ) const
00285 {return new OBPairData(*this);}
00286 void SetValue(const char *v) { _value = v; }
00287 void SetValue(const std::string &v) { _value = v; }
00288 virtual const std::string &GetValue() const
00289 { return(_value); }
00290 };
00291
00294
00295 template <class ValueT>
00296 class OBAPI OBPairTemplate : public OBGenericData
00297 {
00298 protected:
00299 ValueT _value;
00300 public:
00301 OBPairTemplate():
00302 OBGenericData("PairData", OBGenericDataType::PairData), ValueT() {};
00303 void SetValue(const ValueT t) { _value = t; }
00304 virtual const ValueT &GetValue() const { return(_value); }
00305 };
00306
00308 typedef OBPairTemplate<int> OBPairInteger;
00310 typedef OBPairTemplate<double> OBPairFloatingPoint;
00311
00315 class OBAPI OBSetData : public OBGenericData
00316 {
00317 protected:
00318 std::vector<OBGenericData *> _vdata;
00319 public:
00320 OBSetData() : OBGenericData("SetData", OBGenericDataType::SetData) {}
00321 virtual OBGenericData* Clone(OBBase* ) const{return new OBSetData(*this);}
00322
00324 void AddData(OBGenericData *d)
00325 {
00326 if(d)
00327 {
00328 _vdata.push_back(d);
00329 }
00330 }
00331
00333 void SetData(std::vector<OBGenericData *> &vdata)
00334 {
00335 _vdata = vdata;
00336 }
00337
00339 OBGenericData *GetData(const char *s)
00340 {
00341 std::vector<OBGenericData*>::iterator i;
00342
00343 for (i = _vdata.begin();i != _vdata.end();++i)
00344 if ((*i)->GetAttribute() == s)
00345 return(*i);
00346
00347 return(NULL);
00348 }
00349
00351 OBGenericData *GetData(const std::string &s)
00352 {
00353 std::vector<OBGenericData*>::iterator i;
00354
00355 for (i = _vdata.begin();i != _vdata.end();++i)
00356 if ((*i)->GetAttribute() == s)
00357 return(*i);
00358
00359 return(NULL);
00360 }
00361
00363 virtual const std::vector<OBGenericData *> &GetData() const
00364 {
00365 return(_vdata);
00366 }
00367
00369 std::vector<OBGenericData*>::iterator GetBegin()
00370 {
00371 return _vdata.begin();
00372 }
00373
00375 std::vector<OBGenericData*>::iterator GetEnd()
00376 {
00377 return _vdata.end();
00378 }
00379
00381 void DeleteData(OBGenericData *gd)
00382 {
00383 std::vector<OBGenericData*>::iterator i;
00384 for (i = _vdata.begin();i != _vdata.end();++i)
00385 if (*i == gd)
00386 {
00387 delete *i;
00388 _vdata.erase(i);
00389 }
00390 }
00391
00392 };
00393
00397 class OBAPI OBVirtualBond : public OBGenericData
00398 {
00399 protected:
00400 int _bgn;
00401 int _end;
00402 int _ord;
00403 int _stereo;
00404 public:
00405 OBVirtualBond();
00406 virtual OBGenericData* Clone(OBBase* ) const{return new OBVirtualBond(*this);}
00407 OBVirtualBond(int,int,int,int stereo=0);
00408 int GetBgn() { return(_bgn); }
00409 int GetEnd() { return(_end); }
00410 int GetOrder() { return(_ord); }
00411 int GetStereo() { return(_stereo); }
00412 };
00413
00416 class OBAPI OBRingData : public OBGenericData
00417 {
00418 protected:
00419 std::vector<OBRing*> _vr;
00420 public:
00421 OBRingData();
00422 OBRingData(const OBRingData &);
00423 virtual OBGenericData* Clone(OBBase* ) const{return new OBRingData(*this);}
00424 ~OBRingData();
00425
00426 OBRingData &operator=(const OBRingData &);
00427
00428 void SetData(std::vector<OBRing*> &vr)
00429 {
00430 _vr = vr;
00431 }
00432 void PushBack(OBRing *r)
00433 {
00434 _vr.push_back(r);
00435 }
00436 std::vector<OBRing*> &GetData()
00437 {
00438 return(_vr);
00439 }
00440
00441 std::vector<OBRing*>::iterator BeginRings()
00442 { return(_vr.begin()); }
00443 std::vector<OBRing*>::iterator EndRings()
00444 { return(_vr.end()); }
00445 OBRing *BeginRing(std::vector<OBRing*>::iterator &i);
00446 OBRing *NextRing(std::vector<OBRing*>::iterator &i);
00447 };
00448
00453 class OBAPI OBUnitCell: public OBGenericData
00454 {
00455 public:
00456 enum LatticeType { Undefined,
00457 Triclinic,
00458 Monoclinic,
00459 Orthorhombic,
00460 Tetragonal,
00461 Rhombohedral ,
00462 Hexagonal,
00463 Cubic};
00464
00465
00466 protected:
00467 double _a, _b, _c, _alpha, _beta, _gamma;
00468 vector3 _offset;
00469 vector3 _v1, _v2, _v3;
00470 std::string _spaceGroup;
00471 int _numericSpaceGroup;
00472 LatticeType _lattice;
00473 public:
00475 OBUnitCell();
00476 OBUnitCell(const OBUnitCell &);
00477 virtual OBGenericData* Clone(OBBase* ) const
00478 {return new OBUnitCell(*this);}
00479 ~OBUnitCell() {}
00480
00481 OBUnitCell &operator=(const OBUnitCell &);
00482
00492 void SetData(const double a, const double b, const double c,
00493 const double alpha, const double beta, const double gamma)
00494 { _a = a; _b = b; _c = c;
00495 _alpha = alpha; _beta = beta; _gamma = gamma; }
00496 void SetData(const vector3 v1, const vector3 v2, const vector3 v3);
00497
00499 void SetOffset(const vector3 v1) { _offset = v1; }
00500
00504 void SetSpaceGroup(const std::string sg) { _spaceGroup = sg; }
00505
00511 void SetSpaceGroup(const int sg) { _numericSpaceGroup = sg; }
00512
00514 void SetLatticeType(const LatticeType lt) { _lattice = lt; }
00515
00517 double GetA() { return(_a); }
00519 double GetB() { return(_b); }
00521 double GetC() { return(_c); }
00523 double GetAlpha(){ return(_alpha);}
00525 double GetBeta() { return(_beta); }
00527 double GetGamma(){ return(_gamma);}
00529 vector3 GetOffset() { return(_offset); }
00530
00532 const std::string GetSpaceGroup() { return(_spaceGroup); }
00533
00535 LatticeType GetLatticeType( int spacegroup );
00536
00538 LatticeType GetLatticeType();
00539
00541 std::vector<vector3> GetCellVectors();
00543 matrix3x3 GetCellMatrix();
00545 matrix3x3 GetOrthoMatrix();
00547 matrix3x3 GetFractionalMatrix();
00548
00550 int GetSpaceGroupNumber( std::string name );
00552 double GetCellVolume();
00553 };
00554
00560 class OBAPI OBConformerData: public OBGenericData
00561 {
00562 protected:
00564 std::vector<unsigned short> _vDimension;
00566 std::vector<double> _vEnergies;
00568 std::vector< std::vector< vector3 > > _vForces;
00570 std::vector< std::vector< vector3 > > _vVelocity;
00572 std::vector< std::vector< vector3 > > _vDisplace;
00574 std::vector<std::string> _vData;
00575
00576 public:
00577 OBConformerData();
00578 OBConformerData(const OBConformerData &);
00579 virtual OBGenericData* Clone(OBBase* ) const{return new OBConformerData(*this);}
00580 ~OBConformerData() {}
00581
00582 OBConformerData &operator=(const OBConformerData &);
00583
00584 void SetDimension(std::vector<unsigned short> vd) { _vDimension = vd; }
00585 void SetEnergies(std::vector<double> ve) { _vEnergies = ve; }
00586 void SetForces(std::vector< std::vector< vector3 > > vf) {_vForces = vf;}
00587 void SetVelocities(std::vector< std::vector< vector3 > > vv)
00588 { _vVelocity = vv; }
00589 void SetDisplacements(std::vector< std::vector< vector3 > > vd)
00590 { _vDisplace = vd; }
00591 void SetData(std::vector<std::string> vdat) { _vData = vdat; }
00592
00593 std::vector<unsigned short> GetDimension() { return _vDimension; }
00594 std::vector<double> GetEnergies() { return _vEnergies; }
00595 std::vector< std::vector< vector3 > > GetForces() {return _vForces; }
00596 std::vector< std::vector< vector3 > > GetVelocities()
00597 {return _vVelocity;}
00598 std::vector< std::vector< vector3 > > GetDisplacements()
00599 {return _vDisplace;}
00600 std::vector<std::string> GetData() { return _vData; }
00601
00602 };
00603
00608 class OBAPI OBSymmetryData: public OBGenericData
00609 {
00610 protected:
00611 std::string _spaceGroup;
00612 std::string _pointGroup;
00613 public:
00614 OBSymmetryData();
00615 OBSymmetryData(const OBSymmetryData &);
00616 virtual OBGenericData* Clone(OBBase* ) const{return new OBSymmetryData(*this);}
00617 ~OBSymmetryData() {}
00618
00619 OBSymmetryData &operator=(const OBSymmetryData &);
00620
00621 void SetData(std::string pg, std::string sg = "")
00622 { _pointGroup = pg; _spaceGroup = sg; }
00623 void SetPointGroup(std::string pg) { _pointGroup = pg; }
00624 void SetSpaceGroup(std::string sg) { _spaceGroup = sg; }
00625
00626 std::string GetPointGroup() { return _pointGroup; }
00627 std::string GetSpaceGroup() { return _spaceGroup; }
00628 };
00629
00633 class OBAPI OBTorsion
00634 {
00635 friend class OBMol;
00636 friend class OBTorsionData;
00637
00638 protected:
00639 std::pair<OBAtom*,OBAtom*> _bc;
00641 std::vector<triple<OBAtom*,OBAtom*,double> > _ads;
00642
00643 OBTorsion(): _bc(NULL, NULL) { }
00644
00645 OBTorsion(OBAtom *, OBAtom *, OBAtom *, OBAtom *);
00646
00647 std::vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> > GetTorsions();
00648
00649 public:
00650 OBTorsion(const OBTorsion &);
00651 ~OBTorsion() {}
00652
00653 OBTorsion& operator=(const OBTorsion &);
00654
00655 void Clear();
00656 bool Empty() { return(_bc.first == 0 && _bc.second == 0); }
00657
00658 bool AddTorsion(OBAtom *a,OBAtom *b, OBAtom *c,OBAtom *d);
00659 bool AddTorsion(quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> &atoms);
00660
00661 bool SetAngle(double radians, unsigned int index = 0);
00662 bool SetData(OBBond * ) { return false; }
00663
00664 bool GetAngle(double &radians, unsigned int index =0);
00667 unsigned int GetBondIdx();
00668 unsigned int GetSize() const { return _ads.size(); }
00669
00672 std::pair<OBAtom*,OBAtom*> GetBC()
00673 {
00674 return(_bc);
00675 }
00678 std::vector<triple<OBAtom*,OBAtom*,double> > GetADs()
00679 {
00680 return(_ads) ;
00681 }
00682
00683 bool IsProtonRotor();
00684 };
00685
00690 class OBAPI OBTorsionData : public OBGenericData
00691 {
00692 friend class OBMol;
00693
00694 protected:
00695 std::vector<OBTorsion> _torsions;
00696
00697 OBTorsionData();
00698 OBTorsionData(const OBTorsionData &);
00699
00700 public:
00701 OBTorsionData &operator=(const OBTorsionData &);
00702
00704 virtual OBGenericData* Clone(OBBase* ) const
00705 {return new OBTorsionData(*this);}
00706
00707 void Clear();
00708
00711 std::vector<OBTorsion> GetData() const
00712 {
00713 return _torsions;
00714 }
00715
00718 unsigned int GetSize() const
00719 {
00720 return _torsions.size();
00721 }
00722
00723 void SetData(OBTorsion &torsion);
00724
00725 bool FillTorsionArray(std::vector<std::vector<unsigned int> > &torsions);
00726 };
00727
00730 class OBAPI OBAngle
00731 {
00732 friend class OBMol;
00733 friend class OBAngleData;
00734
00735 protected:
00736
00737
00738
00739 OBAtom *_vertex;
00740 std::pair<OBAtom*,OBAtom*> _termini;
00741 double _radians;
00742
00743
00744
00745 OBAngle();
00746 OBAngle(OBAtom *vertex,OBAtom *a,OBAtom *b);
00747
00748 triple<OBAtom*,OBAtom*,OBAtom*> GetAtoms();
00749 void SortByIndex();
00750
00751 public:
00752
00753 OBAngle(const OBAngle &);
00754 ~OBAngle()
00755 {
00756 _vertex = NULL;
00757 }
00758
00759 OBAngle &operator = (const OBAngle &);
00760 bool operator ==(const OBAngle &);
00761
00762 void Clear();
00763
00766 double GetAngle() const
00767 {
00768 return(_radians);
00769 }
00772 void SetAngle(double angle)
00773 {
00774 _radians = angle;
00775 }
00776 void SetAtoms(OBAtom *vertex,OBAtom *a,OBAtom *b);
00777 void SetAtoms(triple<OBAtom*,OBAtom*,OBAtom*> &atoms);
00778
00779 };
00780
00783 class OBAPI OBAngleData : public OBGenericData
00784 {
00785 friend class OBMol;
00786
00787 protected:
00788 std::vector<OBAngle> _angles;
00789
00790 OBAngleData();
00791 OBAngleData(const OBAngleData &);
00793
00794 std::vector<OBAngle> GetData() const
00795 {
00796 return(_angles);
00797 }
00798
00799 public:
00800 OBAngleData &operator =(const OBAngleData &);
00801 virtual OBGenericData* Clone(OBBase* ) const
00802 {return new OBAngleData(*this);}
00803
00804 void Clear();
00805 unsigned int FillAngleArray(int **angles, unsigned int &size);
00806 bool FillAngleArray(std::vector<std::vector<unsigned int> > &angles);
00807
00808 void SetData(OBAngle &);
00811 unsigned int GetSize() const
00812 {
00813 return _angles.size();
00814 }
00815 };
00816
00817 enum atomreftype{
00818 output,
00819 input,
00820 calcvolume
00821 };
00822
00825 class OBAPI OBChiralData : public OBGenericData
00826 {
00827 friend class OBMol;
00828 friend class OBAtom;
00829
00830 protected:
00831 std::vector<unsigned int> _atom4refs;
00832 std::vector<unsigned int> _atom4refo;
00833 std::vector<unsigned int> _atom4refc;
00834
00837 int parity;
00838
00839 public:
00840
00841 OBChiralData();
00842 OBChiralData(const OBChiralData &src);
00843 virtual OBGenericData* Clone(OBBase* ) const
00844 { return new OBChiralData(*this); }
00845 OBChiralData &operator =(const OBChiralData &);
00846 ~OBChiralData(){}
00847
00848 void Clear();
00849
00851 std::vector<unsigned int> GetAtom4Refs(atomreftype t) const;
00853 unsigned int GetAtomRef(int a,atomreftype t);
00854
00855 bool SetAtom4Refs(std::vector<unsigned int> atom4refs, atomreftype t);
00856 int AddAtomRef(unsigned int atomref, atomreftype t);
00857
00859 unsigned int GetSize(atomreftype t) const;
00860 };
00861
00864 class OBSerialNums : public OBGenericData
00865 {
00866 protected:
00867 std::map<int, OBAtom*> _serialMap;
00868
00869 public:
00870
00871 OBSerialNums() :
00872 OBGenericData("obSerialNums", OBGenericDataType::SerialNums)
00873 {}
00874
00875 OBSerialNums(const OBSerialNums &cp) : OBGenericData(cp)
00876 {
00877 _serialMap = cp._serialMap;
00878 }
00881 virtual OBGenericData* Clone(OBBase* ) const
00882 {return new OBSerialNums(*this);}
00883
00884 std::map<int,OBAtom*> &GetData() { return _serialMap; }
00885 void SetData(std::map<int,OBAtom*> &sm) { _serialMap = sm; }
00886
00887 };
00888
00891 class OBAPI OBVibrationData: public OBGenericData
00892 {
00893 protected:
00895 std::vector< std::vector< vector3 > > _vLx;
00896
00898 std::vector<double> _vFrequencies;
00899
00901 std::vector<double> _vIntensities;
00902
00903 public:
00904 OBVibrationData();
00905 OBVibrationData(const OBVibrationData &);
00906 ~OBVibrationData() {}
00907
00908 OBVibrationData & operator=(const OBVibrationData &);
00909
00910 void SetData(const std::vector< std::vector< vector3 > > &,
00911 const std::vector<double> &,
00912 const std::vector<double> &);
00913
00914 std::vector< std::vector< vector3 > > GetLx() const
00915 { return this->_vLx; }
00916 std::vector<double> GetFrequencies() const
00917 { return this->_vFrequencies; }
00918 std::vector<double> GetIntensities() const
00919 { return this->_vIntensities; }
00920
00921 unsigned int GetNumberOfFrequencies() const;
00922 };
00923
00925 typedef std::vector<OBGenericData*>::iterator OBDataIterator;
00926
00927 }
00928
00929 #endif // OB_GENERIC_H
00930