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 "babelconfig.h"
00024
00025 #include <string>
00026 #include <vector>
00027 #include <map>
00028
00029 namespace OpenBabel
00030 {
00031
00032 class OBAtom;
00033 class OBBond;
00034 class OBRing;
00035
00036 OBAPI void Trim(std::string& txt);
00037
00049 namespace OBGenericDataType
00050 {
00052 static const unsigned int UndefinedData = 0;
00053
00055 static const unsigned int PairData = 1;
00056
00058 static const unsigned int EnergyData = 2;
00059
00061 static const unsigned int CommentData = 3;
00062
00064 static const unsigned int ConformerData = 4;
00065
00067 static const unsigned int ExternalBondData = 5;
00068
00070 static const unsigned int RotamerList = 6;
00071
00073 static const unsigned int VirtualBondData = 7;
00074
00076 static const unsigned int RingData = 8;
00077
00079 static const unsigned int TorsionData = 9;
00080
00082 static const unsigned int AngleData = 10;
00083
00085 static const unsigned int SerialNums = 11;
00086
00088 static const unsigned int UnitCell = 12;
00089
00091 static const unsigned int SpinData = 13;
00092
00094 static const unsigned int ChargeData = 14;
00095
00097 static const unsigned int SymmetryData = 15;
00098
00100 static const unsigned int ChiralData = 16;
00101
00103 static const unsigned int OccupationData = 17;
00104
00106 static const unsigned int DensityData = 18;
00107
00109 static const unsigned int ElectronicData = 19;
00110
00112 static const unsigned int VibrationData = 20;
00113
00115 static const unsigned int RotationData = 21;
00116
00118 static const unsigned int NuclearData = 22;
00119
00120
00121
00123 static const unsigned int CustomData0 = 16384;
00124 static const unsigned int CustomData1 = 16385;
00125 static const unsigned int CustomData2 = 16386;
00126 static const unsigned int CustomData3 = 16387;
00127 static const unsigned int CustomData4 = 16388;
00128 static const unsigned int CustomData5 = 16389;
00129 static const unsigned int CustomData6 = 16390;
00130 static const unsigned int CustomData7 = 16391;
00131 static const unsigned int CustomData8 = 16392;
00132 static const unsigned int CustomData9 = 16393;
00133 static const unsigned int CustomData10 = 16394;
00134 static const unsigned int CustomData11 = 16395;
00135 static const unsigned int CustomData12 = 16396;
00136 static const unsigned int CustomData13 = 16397;
00137 static const unsigned int CustomData14 = 16398;
00138 static const unsigned int CustomData15 = 16399;
00139 }
00140
00142
00143 class OBAPI OBGenericData
00144 {
00145 protected:
00146 std::string _attr;
00147 unsigned int _type;
00148 public:
00149 OBGenericData();
00150 OBGenericData(const OBGenericData&);
00151 virtual ~OBGenericData() {}
00152 OBGenericData& operator=(const OBGenericData &src);
00153
00154 void SetAttribute(const std::string &v)
00155 { _attr = v; }
00156 virtual const std::string &GetAttribute() const
00157 { return(_attr); }
00158 unsigned int GetDataType() const
00159 { return(_type); }
00160 };
00161
00163 class OBAPI OBCommentData : public OBGenericData
00164 {
00165 protected:
00166 std::string _data;
00167 public:
00168 OBCommentData();
00169 OBCommentData(const OBCommentData&);
00170 OBCommentData& operator=(const OBCommentData &src);
00171
00172 void SetData(const std::string &data)
00173 { _data = data; Trim(_data); }
00174 void SetData(const char *d)
00175 {_data = d; Trim(_data); }
00176 const std::string &GetData() const
00177 { return(_data); }
00178 };
00179
00182 class OBAPI OBExternalBond
00183 {
00184 int _idx;
00185 OBAtom *_atom;
00186 OBBond *_bond;
00187 public:
00188 OBExternalBond() {}
00189 OBExternalBond(OBAtom *,OBBond *,int);
00190 OBExternalBond(const OBExternalBond &);
00191 ~OBExternalBond() {}
00192
00193 int GetIdx() const { return(_idx); }
00194 OBAtom *GetAtom() const { return(_atom); }
00195 OBBond *GetBond() const { return(_bond); }
00196 void SetIdx(int idx) { _idx = idx; }
00197 void SetAtom(OBAtom *atom) { _atom = atom; }
00198 void SetBond(OBBond *bond) { _bond = bond; }
00199 };
00200
00202 class OBAPI OBExternalBondData : public OBGenericData
00203 {
00204 protected:
00205 std::vector<OBExternalBond> _vexbnd;
00206 public:
00207 OBExternalBondData();
00208 void SetData(OBAtom*,OBBond*,int);
00209 std::vector<OBExternalBond> *GetData()
00210 {
00211 return(&_vexbnd);
00212 }
00213 };
00214
00219 class OBAPI OBPairData : public OBGenericData
00220 {
00221 protected:
00222 std::string _value;
00223 public:
00224 OBPairData();
00225 void SetValue(const char *v)
00226 {
00227 _value = v;
00228 }
00229 void SetValue(const std::string &v)
00230 {
00231 _value = v;
00232 }
00233 std::string &GetValue()
00234 {
00235 return(_value);
00236 }
00237 };
00238
00241 class OBAPI OBVirtualBond : public OBGenericData
00242 {
00243 protected:
00244 int _bgn;
00245 int _end;
00246 int _ord;
00247 int _stereo;
00248 public:
00249 OBVirtualBond();
00250 OBVirtualBond(int,int,int,int stereo=0);
00251 int GetBgn()
00252 {
00253 return(_bgn);
00254 }
00255 int GetEnd()
00256 {
00257 return(_end);
00258 }
00259 int GetOrder()
00260 {
00261 return(_ord);
00262 }
00263 int GetStereo()
00264 {
00265 return(_stereo);
00266 }
00267 };
00268
00270 class OBAPI OBRingData : public OBGenericData
00271 {
00272 protected:
00273 std::vector<OBRing*> _vr;
00274 public:
00275 OBRingData();
00276 OBRingData(const OBRingData &);
00277 ~OBRingData();
00278
00279 OBRingData &operator=(const OBRingData &);
00280
00281 void SetData(std::vector<OBRing*> &vr)
00282 {
00283 _vr = vr;
00284 }
00285 void PushBack(OBRing *r)
00286 {
00287 _vr.push_back(r);
00288 }
00289 std::vector<OBRing*> &GetData()
00290 {
00291 return(_vr);
00292 }
00293 };
00294
00298 class OBAPI OBUnitCell: public OBGenericData
00299 {
00300 protected:
00301 double _a, _b, _c, _alpha, _beta, _gamma;
00302 vector3 _offset;
00303 vector3 _v1, _v2, _v3;
00304 std::string _spaceGroup;
00305 public:
00306 OBUnitCell();
00307 OBUnitCell(const OBUnitCell &);
00308 ~OBUnitCell() {}
00309
00310 OBUnitCell &operator=(const OBUnitCell &);
00311
00312 void SetData(const double a, const double b, const double c,
00313 const double alpha, const double beta, const double gamma)
00314 { _a = a; _b = b; _c = c;
00315 _alpha = alpha; _beta = beta; _gamma = gamma; }
00316 void SetData(const vector3 v1, const vector3 v2, const vector3 v3);
00317 void SetOffset(const vector3 v1) { _offset = v1; }
00321 void SetSpaceGroup(const std::string sg) { _spaceGroup = sg; }
00322
00323 double GetA() { return(_a); }
00324 double GetB() { return(_b); }
00325 double GetC() { return(_c); }
00326 double GetAlpha(){ return(_alpha);}
00327 double GetBeta() { return(_beta); }
00328 double GetGamma(){ return(_gamma);}
00329 vector3 GetOffset() { return(_offset); }
00330 const std::string GetSpaceGroup() { return(_spaceGroup); }
00331
00333 std::vector<vector3> GetCellVectors();
00335 matrix3x3 GetCellMatrix();
00337 matrix3x3 GetOrthoMatrix();
00339 matrix3x3 GetFractionalMatrix();
00340 };
00341
00343 class OBAPI OBConformerData: public OBGenericData
00344 {
00345 protected:
00347 std::vector<unsigned short> _vDimension;
00349 std::vector<double> _vEnergies;
00351 std::vector< std::vector< vector3 > > _vForces;
00353 std::vector< std::vector< vector3 > > _vVelocity;
00355 std::vector< std::vector< vector3 > > _vDisplace;
00357 std::vector<std::string> _vData;
00358
00359 public:
00360 OBConformerData();
00361 OBConformerData(const OBConformerData &);
00362 ~OBConformerData() {}
00363
00364 OBConformerData &operator=(const OBConformerData &);
00365
00366 void SetDimension(std::vector<unsigned short> vd) { _vDimension = vd; }
00367 void SetEnergies(std::vector<double> ve) { _vEnergies = ve; }
00368 void SetForces(std::vector< std::vector< vector3 > > vf) {_vForces = vf;}
00369 void SetVelocities(std::vector< std::vector< vector3 > > vv)
00370 { _vVelocity = vv; }
00371 void SetDisplacements(std::vector< std::vector< vector3 > > vd)
00372 { _vDisplace = vd; }
00373 void SetData(std::vector<std::string> vdat) { _vData = vdat; }
00374
00375 std::vector<unsigned short> GetDimension() { return _vDimension; }
00376 std::vector<double> GetEnergies() { return _vEnergies; }
00377 std::vector< std::vector< vector3 > > GetForces() {return _vForces; }
00378 std::vector< std::vector< vector3 > > GetVelocities()
00379 {return _vVelocity;}
00380 std::vector< std::vector< vector3 > > GetDisplacements()
00381 {return _vDisplace;}
00382 std::vector<std::string> GetData() { return _vData; }
00383
00384 };
00385
00389 class OBAPI OBSymmetryData: public OBGenericData
00390 {
00391 protected:
00392 std::string _spaceGroup;
00393 std::string _pointGroup;
00394 public:
00395 OBSymmetryData();
00396 OBSymmetryData(const OBSymmetryData &);
00397 ~OBSymmetryData() {}
00398
00399 OBSymmetryData &operator=(const OBSymmetryData &);
00400
00401 void SetData(std::string pg, std::string sg = "")
00402 { _pointGroup = pg; _spaceGroup = sg; }
00403 void SetPointGroup(std::string pg) { _pointGroup = pg; }
00404 void SetSpaceGroup(std::string sg) { _spaceGroup = sg; }
00405
00406 std::string GetPointGroup() { return _pointGroup; }
00407 std::string GetSpaceGroup() { return _spaceGroup; }
00408 };
00409
00412 class OBAPI OBTorsion
00413 {
00414 friend class OBMol;
00415 friend class OBTorsionData;
00416
00417 protected:
00418 std::pair<OBAtom*,OBAtom*> _bc;
00420 std::vector<triple<OBAtom*,OBAtom*,double> > _ads;
00421
00422 OBTorsion()
00423 {
00424 _bc.first=0;
00425 _bc.second=0;
00426 }
00427 ;
00428 OBTorsion(OBAtom *, OBAtom *, OBAtom *, OBAtom *);
00429
00430 std::vector<quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> > GetTorsions();
00431
00432 public:
00433 OBTorsion(const OBTorsion &);
00434 ~OBTorsion()
00435 {}
00436
00437 OBTorsion& operator=(const OBTorsion &);
00438
00439 void Clear();
00440 bool Empty()
00441 {
00442 return(_bc.first == 0 && _bc.second == 0);
00443 }
00444
00445 bool AddTorsion(OBAtom *a,OBAtom *b, OBAtom *c,OBAtom *d);
00446 bool AddTorsion(quad<OBAtom*,OBAtom*,OBAtom*,OBAtom*> &atoms);
00447
00448 bool SetAngle(double radians, unsigned int index = 0);
00449 bool SetData(OBBond *bond);
00450
00451 bool GetAngle(double &radians, unsigned int index =0);
00452 unsigned int GetBondIdx();
00453 unsigned int GetSize() const
00454 {
00455 return (unsigned int)_ads.size();
00456 }
00457
00458 std::pair<OBAtom*,OBAtom*> GetBC()
00459 {
00460 return(_bc);
00461 }
00462 std::vector<triple<OBAtom*,OBAtom*,double> > GetADs()
00463 {
00464 return(_ads) ;
00465 }
00466
00467 bool IsProtonRotor();
00468 };
00469
00472 class OBAPI OBTorsionData : public OBGenericData
00473 {
00474 friend class OBMol;
00475
00476 protected:
00477 std::vector<OBTorsion> _torsions;
00478
00479 OBTorsionData();
00480 OBTorsionData(const OBTorsionData &);
00481
00482 public:
00483 OBTorsionData &operator=(const OBTorsionData &);
00484
00485 void Clear();
00486
00487 std::vector<OBTorsion> GetData() const
00488 {
00489 return _torsions;
00490 }
00491 unsigned int GetSize() const
00492 {
00493 return (unsigned int)_torsions.size();
00494 }
00495
00496 void SetData(OBTorsion &torsion);
00497
00498 bool FillTorsionArray(std::vector<std::vector<unsigned int> > &torsions);
00499 };
00500
00502 class OBAPI OBAngle
00503 {
00504 friend class OBMol;
00505 friend class OBAngleData;
00506
00507 protected:
00508
00509
00510
00511 OBAtom *_vertex;
00512 std::pair<OBAtom*,OBAtom*> _termini;
00513 double _radians;
00514
00515
00516
00517 OBAngle();
00518 OBAngle(OBAtom *vertex,OBAtom *a,OBAtom *b);
00519
00520 triple<OBAtom*,OBAtom*,OBAtom*> GetAtoms();
00521 void SortByIndex();
00522
00523 public:
00524
00525 OBAngle(const OBAngle &);
00526 ~OBAngle()
00527 {
00528 _vertex = NULL;
00529 }
00530
00531 OBAngle &operator = (const OBAngle &);
00532 bool operator ==(const OBAngle &);
00533
00534 void Clear();
00535
00536 double GetAngle() const
00537 {
00538 return(_radians);
00539 }
00540
00541 void SetAngle(double radians)
00542 {
00543 _radians = radians;
00544 }
00545 void SetAtoms(OBAtom *vertex,OBAtom *a,OBAtom *b);
00546 void SetAtoms(triple<OBAtom*,OBAtom*,OBAtom*> &atoms);
00547
00548 };
00549
00550
00552 class OBAPI OBAngleData : public OBGenericData
00553 {
00554 friend class OBMol;
00555
00556 protected:
00557 std::vector<OBAngle> _angles;
00558
00559 OBAngleData();
00560 OBAngleData(const OBAngleData &);
00561 std::vector<OBAngle> GetData() const
00562 {
00563 return(_angles);
00564 }
00565
00566 public:
00567 OBAngleData &operator =(const OBAngleData &);
00568
00569 void Clear();
00570 unsigned int FillAngleArray(int **angles, unsigned int &size);
00571 void SetData(OBAngle &);
00572 unsigned int GetSize() const
00573 {
00574 return (unsigned int)_angles.size();
00575 }
00576 };
00577
00578 enum atomreftype{output,input,calcvolume};
00579
00581 class OBAPI OBChiralData : public OBGenericData
00582 {
00583 friend class OBMol;
00584 friend class OBAtom;
00585
00586 protected:
00587 std::vector<unsigned int> _atom4refs;
00588 int parity;
00589 std::vector<unsigned int> _atom4refo;
00590 std::vector<unsigned int> _atom4refc;
00591
00592 public:
00593 std::vector<unsigned int> GetAtom4Refs(atomreftype t) const;
00594 unsigned int GetAtomRef(int a,atomreftype t);
00595
00596 OBChiralData();
00597 OBChiralData(const OBChiralData &src);
00598 OBChiralData &operator =(const OBChiralData &);
00599 ~OBChiralData(){}
00600
00601 void Clear();
00602 bool SetAtom4Refs(std::vector<unsigned int> atom4refs, atomreftype t);
00603 int AddAtomRef(unsigned int atomref, atomreftype t);
00604 unsigned int GetSize(atomreftype t) const;
00605 };
00606
00608 class OBSerialNums : public OBGenericData
00609 {
00610 protected:
00611 std::map<int, OBAtom*> _serialMap;
00612
00613 public:
00614
00615 OBSerialNums()
00616 {
00617 _attr = "obSerialNums";
00618 _type = OBGenericDataType::SerialNums;
00619 }
00620 OBSerialNums(const OBSerialNums &cp) : OBGenericData(cp)
00621 {
00622 _serialMap = cp._serialMap;
00623 }
00624
00625 std::map<int,OBAtom*> &GetData() { return _serialMap; }
00626 void SetData(std::map<int,OBAtom*> &sm) { _serialMap = sm; }
00627
00628 };
00629
00630
00685 }
00686
00687 #endif // OB_GENERIC_H
00688