00001 /********************************************************************** 00002 generic.h - Handle generic data classes. Custom data for atoms, bonds, etc. 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_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/spacegroup.h> 00030 #include <openbabel/obutil.h> 00031 #include <openbabel/base.h> 00032 00033 namespace OpenBabel 00034 { 00035 00036 // Forward declarations 00037 class OBBase; 00038 class OBAtom; 00039 class OBBond; 00040 class OBMol; 00041 class OBRing; 00042 00045 class OBAPI OBCommentData : public OBGenericData 00046 { 00047 protected: 00048 std::string _data; 00049 public: 00050 OBCommentData(); 00051 OBCommentData(const OBCommentData&); 00052 virtual OBGenericData* Clone(OBBase* /*parent*/) const{return new OBCommentData(*this);} 00053 00054 OBCommentData& operator=(const OBCommentData &src); 00055 00056 void SetData(const std::string &data) 00057 { _data = data; Trim(_data); } 00058 void SetData(const char *d) 00059 {_data = d; Trim(_data); } 00060 const std::string &GetData() const 00061 { return(_data); } 00062 virtual const std::string &GetValue() const 00063 { return(_data); } 00064 }; 00065 00069 class OBAPI OBExternalBond 00070 { 00071 int _idx; 00072 OBAtom *_atom; 00073 OBBond *_bond; 00074 public: 00075 OBExternalBond(): _idx(0), _atom(NULL), _bond(NULL) {} 00076 OBExternalBond(OBAtom *,OBBond *,int); 00077 OBExternalBond(const OBExternalBond &); 00078 ~OBExternalBond() {} 00079 00080 int GetIdx() const { return(_idx); } 00081 OBAtom *GetAtom() const { return(_atom); } 00082 OBBond *GetBond() const { return(_bond); } 00083 void SetIdx(int idx) { _idx = idx; } 00084 void SetAtom(OBAtom *atom) { _atom = atom; } 00085 void SetBond(OBBond *bond) { _bond = bond; } 00086 }; 00087 00090 class OBAPI OBExternalBondData : public OBGenericData 00091 { 00092 protected: 00093 std::vector<OBExternalBond> _vexbnd; 00094 public: 00095 OBExternalBondData(); 00096 00097 //Copying is not used and too much work to set up 00098 virtual OBGenericData* Clone(OBBase* /*parent*/) const{return NULL;} 00099 00100 void SetData(OBAtom*,OBBond*,int); 00101 std::vector<OBExternalBond> *GetData() 00102 { 00103 return(&_vexbnd); 00104 } 00105 }; 00106 00112 class OBAPI OBPairData : public OBGenericData 00113 { 00114 protected: 00115 std::string _value; 00116 public: 00117 OBPairData(); 00118 virtual OBGenericData* Clone(OBBase* /*parent*/) const 00119 {return new OBPairData(*this);} 00120 void SetValue(const char *v) { _value = v; } 00121 void SetValue(const std::string &v) { _value = v; } 00122 virtual const std::string &GetValue() const 00123 { return(_value); } 00124 }; 00125 00128 // More detailed description in generic.cpp 00129 template <class ValueT> 00130 class OBAPI OBPairTemplate : public OBGenericData 00131 { 00132 protected: 00133 ValueT _value; 00134 public: 00135 OBPairTemplate(): 00136 OBGenericData("PairData", OBGenericDataType::PairData) {}; 00137 void SetValue(const ValueT t) { _value = t; } 00138 virtual const ValueT &GetGenericValue() const { return(_value); } 00139 }; 00140 00142 typedef OBPairTemplate<int> OBPairInteger; 00144 typedef OBPairTemplate<double> OBPairFloatingPoint; 00145 00149 class OBAPI OBSetData : public OBGenericData 00150 { 00151 protected: 00152 std::vector<OBGenericData *> _vdata; 00153 public: 00154 OBSetData() : OBGenericData("SetData", OBGenericDataType::SetData) {} 00155 virtual OBGenericData* Clone(OBBase* /*parent*/) const{return new OBSetData(*this);} 00156 00158 void AddData(OBGenericData *d) 00159 { 00160 if(d) 00161 { 00162 _vdata.push_back(d); 00163 } 00164 } 00165 00167 void SetData(std::vector<OBGenericData *> &vdata) 00168 { 00169 _vdata = vdata; 00170 } 00171 00173 OBGenericData *GetData(const char *s) 00174 { 00175 std::vector<OBGenericData*>::iterator i; 00176 00177 for (i = _vdata.begin();i != _vdata.end();++i) 00178 if ((*i)->GetAttribute() == s) 00179 return(*i); 00180 00181 return(NULL); 00182 } 00183 00185 OBGenericData *GetData(const std::string &s) 00186 { 00187 std::vector<OBGenericData*>::iterator i; 00188 00189 for (i = _vdata.begin();i != _vdata.end();++i) 00190 if ((*i)->GetAttribute() == s) 00191 return(*i); 00192 00193 return(NULL); 00194 } 00195 00197 virtual const std::vector<OBGenericData *> &GetData() const //now virtual and const 00198 { 00199 return(_vdata); 00200 } 00201 00203 std::vector<OBGenericData*>::iterator GetBegin() 00204 { 00205 return _vdata.begin(); 00206 } 00207 00209 std::vector<OBGenericData*>::iterator GetEnd() 00210 { 00211 return _vdata.end(); 00212 } 00213 00215 void DeleteData(OBGenericData *gd) 00216 { 00217 std::vector<OBGenericData*>::iterator i; 00218 for (i = _vdata.begin();i != _vdata.end();++i) 00219 if (*i == gd) 00220 { 00221 delete *i; 00222 _vdata.erase(i); 00223 } 00224 } 00225 00226 }; // OBSetData 00227 00231 class OBAPI OBVirtualBond : public OBGenericData 00232 { 00233 protected: 00234 int _bgn; 00235 int _end; 00236 int _ord; 00237 int _stereo; 00238 public: 00239 OBVirtualBond(); 00240 virtual OBGenericData* Clone(OBBase* /*parent*/) const{return new OBVirtualBond(*this);} 00241 OBVirtualBond(int,int,int,int stereo=0); 00242 int GetBgn() { return(_bgn); } 00243 int GetEnd() { return(_end); } 00244 int GetOrder() { return(_ord); } 00245 int GetStereo() { return(_stereo); } 00246 }; 00247 00250 class OBAPI OBRingData : public OBGenericData 00251 { 00252 protected: 00253 std::vector<OBRing*> _vr; 00254 public: 00255 OBRingData(); 00256 OBRingData(const OBRingData &); 00257 virtual OBGenericData* Clone(OBBase* /*parent*/) const{return new OBRingData(*this);} 00258 ~OBRingData(); 00259 00260 OBRingData &operator=(const OBRingData &); 00261 00262 void SetData(std::vector<OBRing*> &vr) 00263 { 00264 _vr = vr; 00265 } 00266 void PushBack(OBRing *r) 00267 { 00268 _vr.push_back(r); 00269 } 00270 std::vector<OBRing*> &GetData() 00271 { 00272 return(_vr); 00273 } 00274 00275 std::vector<OBRing*>::iterator BeginRings() 00276 { return(_vr.begin()); } 00277 std::vector<OBRing*>::iterator EndRings() 00278 { return(_vr.end()); } 00279 OBRing *BeginRing(std::vector<OBRing*>::iterator &i); 00280 OBRing *NextRing(std::vector<OBRing*>::iterator &i); 00281 }; 00282 00287 class OBAPI OBUnitCell: public OBGenericData 00288 { 00289 public: 00290 enum LatticeType { Undefined, 00291 Triclinic, 00292 Monoclinic, 00293 Orthorhombic, 00294 Tetragonal, 00295 Rhombohedral , 00296 Hexagonal, 00297 Cubic}; 00298 00299 00300 protected: 00301 double _a, _b, _c, _alpha, _beta, _gamma; 00302 vector3 _offset; 00303 vector3 _v1, _v2, _v3; 00304 std::string _spaceGroupName; 00305 const SpaceGroup* _spaceGroup; 00306 LatticeType _lattice; 00307 public: 00309 OBUnitCell(); 00310 OBUnitCell(const OBUnitCell &); 00311 virtual OBGenericData* Clone(OBBase* /*parent*/) const 00312 {return new OBUnitCell(*this);} 00313 ~OBUnitCell() {} 00314 00315 OBUnitCell &operator=(const OBUnitCell &); 00316 00326 void SetData(const double a, const double b, const double c, 00327 const double alpha, const double beta, const double gamma) 00328 { _a = a; _b = b; _c = c; 00329 _alpha = alpha; _beta = beta; _gamma = gamma; } 00330 void SetData(const vector3 v1, const vector3 v2, const vector3 v3); 00331 00333 void SetOffset(const vector3 v1) { _offset = v1; } 00334 00337 void SetSpaceGroup(const SpaceGroup* sg) { _spaceGroup = sg; } 00338 00342 void SetSpaceGroup(const std::string sg) { _spaceGroup = SpaceGroup::GetSpaceGroup (sg); 00343 _spaceGroupName = sg; } 00344 00350 void SetSpaceGroup(const int sg) { _spaceGroup = SpaceGroup::GetSpaceGroup (sg); } 00351 00353 void SetLatticeType(const LatticeType lt) { _lattice = lt; } 00354 00357 void FillUnitCell(OBMol *); 00358 00360 double GetA() { return(_a); } 00362 double GetB() { return(_b); } 00364 double GetC() { return(_c); } 00366 double GetAlpha(){ return(_alpha);} 00368 double GetBeta() { return(_beta); } 00370 double GetGamma(){ return(_gamma);} 00372 vector3 GetOffset() { return(_offset); } 00373 00375 const SpaceGroup* GetSpaceGroup() { return(_spaceGroup); } 00376 00378 const std::string GetSpaceGroupName() { return(_spaceGroupName); } 00379 00381 LatticeType GetLatticeType( int spacegroup ); 00382 00384 LatticeType GetLatticeType(); 00385 00387 std::vector<vector3> GetCellVectors(); 00389 matrix3x3 GetCellMatrix(); 00391 matrix3x3 GetOrthoMatrix(); 00393 matrix3x3 GetFractionalMatrix(); 00394 00396 int GetSpaceGroupNumber( std::string name = "" ); 00398 double GetCellVolume(); 00399 }; 00400 00406 class OBAPI OBConformerData: public OBGenericData 00407 { 00408 protected: 00410 std::vector<unsigned short> _vDimension; 00412 std::vector<double> _vEnergies; 00414 std::vector< std::vector< vector3 > > _vForces; 00416 std::vector< std::vector< vector3 > > _vVelocity; 00418 std::vector< std::vector< vector3 > > _vDisplace; 00420 std::vector<std::string> _vData; 00421 00422 public: 00423 OBConformerData(); 00424 OBConformerData(const OBConformerData &); 00425 virtual OBGenericData* Clone(OBBase* /*parent*/) const{return new OBConformerData(*this);} 00426 ~OBConformerData() {} 00427 00428 OBConformerData &operator=(const OBConformerData &); 00429 00430 void SetDimension(std::vector<unsigned short> vd) { _vDimension = vd; } 00431 void SetEnergies(std::vector<double> ve) { _vEnergies = ve; } 00432 void SetForces(std::vector< std::vector< vector3 > > vf) {_vForces = vf;} 00433 void SetVelocities(std::vector< std::vector< vector3 > > vv) 00434 { _vVelocity = vv; } 00435 void SetDisplacements(std::vector< std::vector< vector3 > > vd) 00436 { _vDisplace = vd; } 00437 void SetData(std::vector<std::string> vdat) { _vData = vdat; } 00438 00439 std::vector<unsigned short> GetDimension() { return _vDimension; } 00440 std::vector<double> GetEnergies() { return _vEnergies; } 00441 std::vector< std::vector< vector3 > > GetForces() {return _vForces; } 00442 std::vector< std::vector< vector3 > > GetVelocities() 00443 {return _vVelocity;} 00444 std::vector< std::vector< vector3 > > GetDisplacements() 00445 {return _vDisplace;} 00446 std::vector<std::string> GetData() { return _vData; } 00447 00448 }; 00449 00454 class OBAPI OBSymmetryData: public OBGenericData 00455 { 00456 protected: 00457 std::string _spaceGroup; 00458 std::string _pointGroup; 00459 public: 00460 OBSymmetryData(); 00461 OBSymmetryData(const OBSymmetryData &); 00462 virtual OBGenericData* Clone(OBBase* /*parent*/) const{return new OBSymmetryData(*this);} 00463 ~OBSymmetryData() {} 00464 00465 OBSymmetryData &operator=(const OBSymmetryData &); 00466 00467 void SetData(std::string pg, std::string sg = "") 00468 { _pointGroup = pg; _spaceGroup = sg; } 00469 void SetPointGroup(std::string pg) { _pointGroup = pg; } 00470 void SetSpaceGroup(std::string sg) { _spaceGroup = sg; } 00471 00472 std::string GetPointGroup() { return _pointGroup; } 00473 std::string GetSpaceGroup() { return _spaceGroup; } 00474 }; 00475 00479 class OBAPI OBTorsion 00480 { 00481 friend class OBMol; 00482 friend class OBTorsionData; 00483 00484 protected: 00485 std::pair<OBAtom*,OBAtom*> _bc; 00487 std::vector<triple<OBAtom*,OBAtom*,double> > _ads; 00488 00489 OBTorsion(): _bc(NULL, NULL) { } 00490 //protected for use only by friend classes 00491 OBTorsion(OBAtom *, OBAtom *, OBAtom *, OBAtom *); 00492 00493 std::vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> > GetTorsions(); 00494 00495 public: 00496 OBTorsion(const OBTorsion &); 00497 ~OBTorsion() {} 00498 00499 OBTorsion& operator=(const OBTorsion &); 00500 00501 void Clear(); 00502 bool Empty() { return(_bc.first == 0 && _bc.second == 0); } 00503 00504 bool AddTorsion(OBAtom *a,OBAtom *b, OBAtom *c,OBAtom *d); 00505 bool AddTorsion(quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> &atoms); 00506 00507 bool SetAngle(double radians, unsigned int index = 0); 00508 bool SetData(OBBond * /*bond*/) { return false; } 00509 00510 bool GetAngle(double &radians, unsigned int index =0); 00513 unsigned int GetBondIdx(); 00514 unsigned int GetSize() const { return _ads.size(); } 00515 00518 std::pair<OBAtom*,OBAtom*> GetBC() 00519 { 00520 return(_bc); 00521 } 00524 std::vector<triple<OBAtom*,OBAtom*,double> > GetADs() 00525 { 00526 return(_ads) ; 00527 } 00528 00529 bool IsProtonRotor(); 00530 }; 00531 00536 class OBAPI OBTorsionData : public OBGenericData 00537 { 00538 friend class OBMol; 00539 00540 protected: 00541 std::vector<OBTorsion> _torsions; 00542 00543 OBTorsionData(); 00544 OBTorsionData(const OBTorsionData &); 00545 00546 public: 00547 OBTorsionData &operator=(const OBTorsionData &); 00548 00550 virtual OBGenericData* Clone(OBBase* /*parent*/) const 00551 {return new OBTorsionData(*this);} 00552 00553 void Clear(); 00554 00557 std::vector<OBTorsion> GetData() const 00558 { 00559 return _torsions; 00560 } 00561 00564 unsigned int GetSize() const 00565 { 00566 return _torsions.size(); 00567 } 00568 00569 void SetData(OBTorsion &torsion); 00570 00571 bool FillTorsionArray(std::vector<std::vector<unsigned int> > &torsions); 00572 }; 00573 00576 class OBAPI OBAngle 00577 { 00578 friend class OBMol; 00579 friend class OBAngleData; 00580 00581 protected: 00582 00583 //member data 00584 00585 OBAtom *_vertex; 00586 std::pair<OBAtom*,OBAtom*> _termini; 00587 double _radians; 00588 00589 //protected member functions 00590 00591 OBAngle(); //protect constructor for use only by friend classes 00592 OBAngle(OBAtom *vertex,OBAtom *a,OBAtom *b); 00593 00594 triple<OBAtom*,OBAtom*,OBAtom*> GetAtoms(); 00595 void SortByIndex(); 00596 00597 public: 00598 00599 OBAngle(const OBAngle &); 00600 ~OBAngle() 00601 { 00602 _vertex = NULL; 00603 } 00604 00605 OBAngle &operator = (const OBAngle &); 00606 bool operator ==(const OBAngle &); 00607 00608 void Clear(); 00609 00612 double GetAngle() const 00613 { 00614 return(_radians); 00615 } 00618 void SetAngle(double angle) 00619 { 00620 _radians = angle; 00621 } 00622 void SetAtoms(OBAtom *vertex,OBAtom *a,OBAtom *b); 00623 void SetAtoms(triple<OBAtom*,OBAtom*,OBAtom*> &atoms); 00624 00625 }; 00626 00629 class OBAPI OBAngleData : public OBGenericData 00630 { 00631 friend class OBMol; 00632 00633 protected: 00634 std::vector<OBAngle> _angles; 00635 00636 OBAngleData(); 00637 OBAngleData(const OBAngleData &); 00639 00640 std::vector<OBAngle> GetData() const 00641 { 00642 return(_angles); 00643 } 00644 00645 public: 00646 OBAngleData &operator =(const OBAngleData &); 00647 virtual OBGenericData* Clone(OBBase* /*parent*/) const 00648 {return new OBAngleData(*this);} 00649 00650 void Clear(); 00651 unsigned int FillAngleArray(int **angles, unsigned int &size); 00652 bool FillAngleArray(std::vector<std::vector<unsigned int> > &angles); 00653 00654 void SetData(OBAngle &); 00657 unsigned int GetSize() const 00658 { 00659 return _angles.size(); 00660 } 00661 }; 00662 00663 enum atomreftype{ 00664 output, 00665 input, 00666 calcvolume 00667 }; // sets which atom4ref is accessed by OBChiralData 00668 00671 class OBAPI OBChiralData : public OBGenericData 00672 { 00673 friend class OBMol; 00674 friend class OBAtom; 00675 00676 protected: 00677 std::vector<unsigned int> _atom4refs; 00678 std::vector<unsigned int> _atom4refo; 00679 std::vector<unsigned int> _atom4refc; 00680 00683 int parity; 00684 00685 public: 00686 00687 OBChiralData(); 00688 OBChiralData(const OBChiralData &src); 00689 virtual OBGenericData* Clone(OBBase* /*parent*/) const 00690 { return new OBChiralData(*this); } 00691 OBChiralData &operator =(const OBChiralData &); 00692 ~OBChiralData(){} 00693 00694 void Clear(); 00695 00697 std::vector<unsigned int> GetAtom4Refs(atomreftype t) const; 00699 unsigned int GetAtomRef(int a,atomreftype t); 00700 00701 bool SetAtom4Refs(std::vector<unsigned int> atom4refs, atomreftype t); 00702 int AddAtomRef(unsigned int atomref, atomreftype t); 00703 00705 unsigned int GetSize(atomreftype t) const; 00706 }; 00707 00710 class OBSerialNums : public OBGenericData 00711 { 00712 protected: 00713 std::map<int, OBAtom*> _serialMap; 00714 00715 public: 00716 00717 OBSerialNums() : 00718 OBGenericData("obSerialNums", OBGenericDataType::SerialNums) 00719 {} 00720 00721 OBSerialNums(const OBSerialNums &cp) : OBGenericData(cp) 00722 { 00723 _serialMap = cp._serialMap; 00724 } 00727 virtual OBGenericData* Clone(OBBase* /*parent*/) const 00728 {return new OBSerialNums(*this);} 00729 00730 std::map<int,OBAtom*> &GetData() { return _serialMap; } 00731 void SetData(std::map<int,OBAtom*> &sm) { _serialMap = sm; } 00732 00733 }; 00734 00737 class OBAPI OBVibrationData: public OBGenericData 00738 { 00739 protected: 00741 std::vector< std::vector< vector3 > > _vLx; 00742 00744 std::vector<double> _vFrequencies; 00745 00747 std::vector<double> _vIntensities; 00748 00749 00750 public: 00751 OBVibrationData(): OBGenericData("VibrationData", OBGenericDataType::VibrationData){}; 00752 virtual ~OBVibrationData() {} 00753 virtual OBGenericData* Clone(OBBase*) const 00754 {return new OBVibrationData(*this);} 00755 00756 OBVibrationData & operator=(const OBVibrationData &); 00757 00758 void SetData(const std::vector< std::vector< vector3 > > &, 00759 const std::vector<double> &, 00760 const std::vector<double> &); 00761 00762 std::vector< std::vector< vector3 > > GetLx() const 00763 { return this->_vLx; } 00764 std::vector<double> GetFrequencies() const 00765 { return this->_vFrequencies; } 00766 std::vector<double> GetIntensities() const 00767 { return this->_vIntensities; } 00768 00769 unsigned int GetNumberOfFrequencies() const; 00770 }; 00771 00774 class OBAPI OBRotationData: public OBGenericData 00775 { 00776 public: 00777 enum RType{UNKNOWN, ASYMMETRIC, SYMMETRIC, LINEAR}; 00778 OBRotationData(): OBGenericData("RotationData", OBGenericDataType::RotationData){} 00779 virtual ~OBRotationData(){}; 00780 virtual OBGenericData* Clone(OBBase*) const 00781 {return new OBRotationData(*this);} 00782 void SetData(RType RotorType, std::vector<double> RotationalConstants, int SymmetryNumber) 00783 { 00784 RotConsts = RotationalConstants; 00785 type = RotorType; 00786 SymNum = SymmetryNumber; 00787 } 00788 00790 std::vector<double> GetRotConsts()const{ return RotConsts; } 00791 00792 int GetSymmetryNumber()const{ return SymNum; } 00793 RType GetRotorType()const { return type; } 00794 00795 protected: 00796 std::vector<double> RotConsts; 00797 int SymNum; 00798 RType type; 00799 }; 00800 00804 class OBAPI OBVectorData: public OBGenericData 00805 { 00806 public: 00807 OBVectorData(): OBGenericData("VectorData", OBGenericDataType::VectorData){} 00808 virtual ~OBVectorData(){}; 00809 virtual OBGenericData* Clone(OBBase*) const 00810 {return new OBVectorData(*this);} 00811 void SetData(double x, double y, double z) 00812 { _vec = vector3(x, y, z); } 00813 void SetData(vector3 data) 00814 { _vec = data; } 00815 vector3 GetData() const 00816 { return _vec; } 00817 00818 protected: 00819 vector3 _vec; 00820 }; 00821 00825 class OBAPI OBMatrixData: public OBGenericData 00826 { 00827 public: 00828 OBMatrixData(): OBGenericData("MatrixData", OBGenericDataType::MatrixData){} 00829 virtual ~OBMatrixData(){}; 00830 virtual OBGenericData* Clone(OBBase*) const 00831 {return new OBMatrixData(*this);} 00832 void SetData(matrix3x3 data) 00833 { _matrix = data; } 00834 matrix3x3 GetData() const 00835 { return _matrix; } 00836 00837 protected: 00838 matrix3x3 _matrix; 00839 }; 00840 00842 typedef std::vector<OBGenericData*>::iterator OBDataIterator; 00843 00844 } //end namespace OpenBabel 00845 00846 #endif // OB_GENERIC_H 00847
This file is part of the documentation for Open Babel, version 2.2.0.