00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef OB_MOL_H
00023 #define OB_MOL_H
00024
00025 #include <openbabel/babelconfig.h>
00026
00027 #ifndef EXTERN
00028 # define EXTERN extern
00029 #endif
00030
00031 #include <math.h>
00032 #include <float.h>
00033
00034 #include <vector>
00035 #include <string>
00036 #include <map>
00037
00038
00039
00040
00041
00042 #include <openbabel/atom.h>
00043 #include <openbabel/bond.h>
00044 #include <openbabel/base.h>
00045 #include <openbabel/data.h>
00046 #include <openbabel/chains.h>
00047 #include <openbabel/math/vector3.h>
00048 #include <openbabel/bitvec.h>
00049 #include <openbabel/residue.h>
00050 #include <openbabel/ring.h>
00051 #include <openbabel/generic.h>
00052 #include <openbabel/typer.h>
00053 #include <openbabel/oberror.h>
00054 #include <openbabel/obiter.h>
00055 #include <openbabel/internalcoord.h>
00056
00057 namespace OpenBabel
00058 {
00059
00060 class OBAtom;
00061 class OBBond;
00062 class OBInternalCoord;
00063
00064
00065
00067 #define OB_SSSR_MOL (1<<1)
00069 #define OB_RINGFLAGS_MOL (1<<2)
00071 #define OB_AROMATIC_MOL (1<<3)
00073 #define OB_ATOMTYPES_MOL (1<<4)
00075 #define OB_CHIRALITY_MOL (1<<5)
00077 #define OB_PCHARGE_MOL (1<<6)
00079 #define OB_HYBRID_MOL (1<<8)
00081 #define OB_IMPVAL_MOL (1<<9)
00083 #define OB_KEKULE_MOL (1<<10)
00085 #define OB_CLOSURE_MOL (1<<11)
00087 #define OB_H_ADDED_MOL (1<<12)
00089 #define OB_PH_CORRECTED_MOL (1<<13)
00091 #define OB_AROM_CORRECTED_MOL (1<<14)
00093 #define OB_CHAINS_MOL (1<<15)
00095 #define OB_TCHARGE_MOL (1<<16)
00097 #define OB_TSPIN_MOL (1<<17)
00099 #define OB_RINGTYPES_MOL (1<<18)
00100
00101 #define OB_CURRENT_CONFORMER -1
00102
00103
00104 class OBAPI OBMol: public OBBase
00105 {
00106 protected:
00107 int _flags;
00108 bool _autoPartialCharge;
00109 bool _autoFormalCharge;
00110 std::string _title;
00111 std::vector<OBAtom*> _vatom;
00112 std::vector<OBBond*> _vbond;
00113 unsigned short int _dimension;
00114 int _totalCharge;
00115 unsigned int _totalSpin;
00116 double *_c;
00117 std::vector<double*> _vconf;
00118 double _energy;
00119 unsigned int _natoms;
00120 unsigned int _nbonds;
00121 std::vector<OBResidue*> _residue;
00122 std::vector<OBInternalCoord*> _internals;
00123 unsigned short int _mod;
00124
00125 bool HasFlag(int flag) { return((_flags & flag) ? true : false); }
00126 void SetFlag(int flag) { _flags |= flag; }
00127
00129
00130 void start_kekulize(std::vector <OBAtom*> &cycle, std::vector<int> &electron);
00131 int expand_kekulize(OBAtom *atom1, OBAtom *atom2, std::vector<int> ¤tState, std::vector<int> &initState, std::vector<int> &bcurrentState, std::vector<int> &binitState, std::vector<bool> &mark);
00132 int getorden(OBAtom *atom);
00133 bool expandcycle(OBAtom *atom, OBBitVec &avisit, OBAtom *first = NULL, int depth = 0);
00135
00136 public:
00137
00139
00140
00141 OBMol();
00143 OBMol(const OBMol &);
00145 virtual ~OBMol();
00147 OBMol &operator=(const OBMol &mol);
00149 OBMol &operator+=(const OBMol &mol);
00150
00153 void ReserveAtoms(int natoms)
00154 {
00155 if (natoms > 0 && _mod)
00156 _vatom.reserve(natoms);
00157 }
00158
00161 virtual OBAtom *CreateAtom(void);
00164 virtual OBBond *CreateBond(void);
00167 virtual OBResidue *CreateResidue(void);
00170 virtual void DestroyAtom(OBAtom*);
00173 virtual void DestroyBond(OBBond*);
00176 virtual void DestroyResidue(OBResidue*);
00177
00180 bool AddAtom(OBAtom&);
00183 bool InsertAtom(OBAtom &);
00191 bool AddBond(int beginIdx, int endIdx, int order,
00192 int flags=0,int insertpos=-1);
00195 bool AddBond(OBBond&);
00198 bool AddResidue(OBResidue&);
00199
00202 OBAtom *NewAtom();
00205 OBBond *NewBond();
00207 OBResidue *NewResidue();
00212 bool DeleteAtom(OBAtom*, bool destroyAtom = true);
00215 bool DeleteBond(OBBond*, bool destroyBond = true);
00218 bool DeleteResidue(OBResidue*, bool destroyResidue = true);
00220
00222
00223
00224
00225
00226 virtual void BeginModify(void);
00230 virtual void EndModify(bool nukePerceivedData=true);
00232 int GetMod() { return(_mod); }
00235 void IncrementMod() { _mod++; }
00238 void DecrementMod() { _mod--; }
00240
00242
00243
00244 int GetFlags() { return(_flags); }
00247 const char *GetTitle(bool replaceNewlines = true) const;
00249 unsigned int NumAtoms() const { return(_natoms); }
00251 unsigned int NumBonds() const { return(_nbonds); }
00253 unsigned int NumHvyAtoms();
00255 unsigned int NumResidues() const { return(_residue.size()); }
00257 unsigned int NumRotors();
00258
00261 OBAtom *GetAtom(int idx) const;
00264 OBAtom *GetFirstAtom() const;
00267 OBBond *GetBond(int idx) const;
00270 OBBond *GetBond(int a, int b) const;
00271
00273 OBBond *GetBond(OBAtom* bgn, OBAtom* end) const;
00276 OBResidue *GetResidue(int idx) const;
00277 std::vector<OBInternalCoord*> GetInternalCoord();
00282 double GetTorsion(int,int,int,int);
00287 double GetTorsion(OBAtom* a,OBAtom* b,OBAtom* c,OBAtom* d);
00290 double GetAngle(OBAtom* a, OBAtom* b, OBAtom* c);
00292 std::string GetFormula();
00294 std::string GetSpacedFormula(int ones=0, const char* sp=" ", bool implicitH = true);
00296 double GetEnergy() const { return _energy; }
00298 double GetMolWt(bool implicitH = true);
00300 double GetExactMass(bool implicitH = true);
00302 int GetTotalCharge();
00304 unsigned int GetTotalSpinMultiplicity();
00306 unsigned short int GetDimension() const { return _dimension; }
00308 double *GetCoordinates() { return(_c); }
00310 std::vector<OBRing*> &GetSSSR();
00312 bool AutomaticFormalCharge() { return(_autoFormalCharge); }
00314 bool AutomaticPartialCharge() { return(_autoPartialCharge); }
00316
00317
00319
00320
00321 void SetTitle(const char *title);
00323 void SetTitle(std::string &title);
00325 void SetFormula(std::string molFormula);
00327 void SetEnergy(double energy) { _energy = energy; }
00329 void SetDimension(unsigned short int d) { _dimension = d; }
00331 void SetTotalCharge(int charge);
00334 void SetTotalSpinMultiplicity(unsigned int spinMultiplicity);
00337 void SetInternalCoord(std::vector<OBInternalCoord*> int_coord)
00338 { _internals = int_coord; }
00340 void SetAutomaticFormalCharge(bool val)
00341 { _autoFormalCharge=val; }
00343 void SetAutomaticPartialCharge(bool val)
00344 { _autoPartialCharge=val; }
00345
00347 void SetAromaticPerceived() { SetFlag(OB_AROMATIC_MOL); }
00349 void SetSSSRPerceived() { SetFlag(OB_SSSR_MOL); }
00351 void SetRingAtomsAndBondsPerceived(){SetFlag(OB_RINGFLAGS_MOL);}
00353 void SetAtomTypesPerceived() { SetFlag(OB_ATOMTYPES_MOL); }
00355 void SetRingTypesPerceived() { SetFlag(OB_RINGTYPES_MOL); }
00357 void SetChainsPerceived() { SetFlag(OB_CHAINS_MOL); }
00359 void SetChiralityPerceived() { SetFlag(OB_CHIRALITY_MOL); }
00361 void SetPartialChargesPerceived(){ SetFlag(OB_PCHARGE_MOL); }
00363 void SetHybridizationPerceived() { SetFlag(OB_HYBRID_MOL); }
00365 void SetImplicitValencePerceived(){ SetFlag(OB_IMPVAL_MOL); }
00367 void SetKekulePerceived() { SetFlag(OB_KEKULE_MOL); }
00369 void SetClosureBondsPerceived(){ SetFlag(OB_CLOSURE_MOL); }
00371 void SetHydrogensAdded() { SetFlag(OB_H_ADDED_MOL); }
00372 void SetCorrectedForPH() { SetFlag(OB_PH_CORRECTED_MOL);}
00373 void SetAromaticCorrected() { SetFlag(OB_AROM_CORRECTED_MOL);}
00374 void SetSpinMultiplicityAssigned(){ SetFlag(OB_TSPIN_MOL); }
00375 void SetFlags(int flags) { _flags = flags; }
00376
00377 void UnsetAromaticPerceived() { _flags &= (~(OB_AROMATIC_MOL)); }
00378 void UnsetSSSRPerceived() { _flags &= (~(OB_SSSR_MOL)); }
00379 void UnsetRingTypesPerceived() { _flags &= (~(OB_RINGTYPES_MOL)); }
00380 void UnsetPartialChargesPerceived(){ _flags &= (~(OB_PCHARGE_MOL));}
00381 void UnsetImplicitValencePerceived(){_flags &= (~(OB_IMPVAL_MOL)); }
00382 void UnsetHydrogensAdded() { UnsetFlag(OB_H_ADDED_MOL); }
00383 void UnsetFlag(int flag) { _flags &= (~(flag)); }
00385
00387
00388
00389 virtual OBBase* DoTransformations(const std::map<std::string,std::string>* pOptions);
00390
00391 static const char* ClassDescription();
00393 bool Clear();
00395 void RenumberAtoms(std::vector<OBAtom*>&);
00398 void SetCoordinates(double *c);
00400 void ToInertialFrame(int conf, double *rmat);
00402 void ToInertialFrame();
00404 void Translate(const vector3 &v);
00406 void Translate(const vector3 &v, int conf);
00408 void Rotate(const double u[3][3]);
00410 void Rotate(const double m[9]);
00412 void Rotate(const double m[9],int nconf);
00414 void Center();
00416
00417 bool Kekulize();
00418 bool PerceiveKekuleBonds();
00419
00420 void NewPerceiveKekuleBonds();
00421
00424 bool DeleteHydrogens();
00427 bool DeleteHydrogens(OBAtom*);
00430 bool DeleteNonPolarHydrogens();
00433 bool DeleteHydrogen(OBAtom*);
00440 bool AddHydrogens(bool polaronly=false,bool correctForPH=false, double pH=7.4);
00442 bool AddHydrogens(OBAtom*);
00444 bool AddPolarHydrogens();
00445
00447 bool StripSalts(int threshold);
00449 std::vector<OBMol> Separate(int StartIndex=1);
00451 bool GetNextFragment( OpenBabel::OBMolAtomDFSIter& iter, OBMol& newMol );
00453 bool ConvertDativeBonds();
00454
00456 bool CorrectForPH(double pH=7.4);
00457
00458 bool AssignSpinMultiplicity(bool NoImplicitH=false);
00461 vector3 Center(int nconf);
00467 void SetTorsion(OBAtom*,OBAtom*,OBAtom*,OBAtom*,double ang);
00469
00471
00472
00473 void FindSSSR();
00475 void FindRingAtomsAndBonds();
00477 void FindChiralCenters();
00478
00479 void FindChildren(std::vector<int> & children,int bgnIdx,int endIdx);
00480
00481 void FindChildren(std::vector<OBAtom*>& children,OBAtom* bgn,OBAtom* end);
00486 void FindLargestFragment(OBBitVec &frag);
00489 void ContigFragList(std::vector<std::vector<int> >&);
00491 void Align(OBAtom*,OBAtom*,vector3&,vector3&);
00493 void ConnectTheDots();
00495 void PerceiveBondOrders();
00497 void FindAngles();
00499 void FindTorsions();
00500
00501 bool GetGTDVector(std::vector<int> &);
00502
00503 void GetGIVector(std::vector<unsigned int> &);
00504
00505 void GetGIDVector(std::vector<unsigned int> &);
00507
00509
00510
00511 bool Has2D();
00513 bool Has3D();
00515 bool HasNonZeroCoords();
00517 bool HasAromaticPerceived() { return(HasFlag(OB_AROMATIC_MOL)); }
00519 bool HasSSSRPerceived() { return(HasFlag(OB_SSSR_MOL)); }
00521 bool HasRingAtomsAndBondsPerceived(){return(HasFlag(OB_RINGFLAGS_MOL));}
00523 bool HasAtomTypesPerceived() { return(HasFlag(OB_ATOMTYPES_MOL));}
00525 bool HasRingTypesPerceived() { return(HasFlag(OB_RINGTYPES_MOL));}
00527 bool HasChiralityPerceived() { return(HasFlag(OB_CHIRALITY_MOL));}
00529 bool HasPartialChargesPerceived() { return(HasFlag(OB_PCHARGE_MOL));}
00531 bool HasHybridizationPerceived() { return(HasFlag(OB_HYBRID_MOL)); }
00533 bool HasImplicitValencePerceived() { return(HasFlag(OB_IMPVAL_MOL));}
00535 bool HasKekulePerceived() { return(HasFlag(OB_KEKULE_MOL)); }
00537 bool HasClosureBondsPerceived() { return(HasFlag(OB_CLOSURE_MOL)); }
00539 bool HasChainsPerceived() { return(HasFlag(OB_CHAINS_MOL)); }
00541 bool HasHydrogensAdded() { return(HasFlag(OB_H_ADDED_MOL)); }
00543 bool HasAromaticCorrected() { return(HasFlag(OB_AROM_CORRECTED_MOL));}
00545 bool IsCorrectedForPH() { return(HasFlag(OB_PH_CORRECTED_MOL)); }
00547 bool HasSpinMultiplicityAssigned() { return(HasFlag(OB_TSPIN_MOL)); }
00549 bool IsChiral();
00551 bool Empty() { return(_natoms == 0); }
00553
00555
00556
00557 int NumConformers() { return((_vconf.empty())?0:_vconf.size()); }
00559 void SetConformers(std::vector<double*> &v);
00561 void AddConformer(double *f) { _vconf.push_back(f); }
00564 void SetConformer(int i);
00567 void CopyConformer(double* c,int nconf);
00569 void DeleteConformer(int nconf);
00571 double *GetConformer(int i) { return(_vconf[i]); }
00573 void SetEnergies(std::vector<double> &energies);
00575 std::vector<double> GetEnergies();
00578 double GetEnergy(int ci);
00581 double *BeginConformer(std::vector<double*>::iterator&i)
00582 { i = _vconf.begin();
00583 return((i == _vconf.end()) ? NULL:*i); }
00586 double *NextConformer(std::vector<double*>::iterator&i)
00587 { ++i;
00588 return((i == _vconf.end()) ? NULL:*i); }
00590 std::vector<double*> &GetConformers() { return(_vconf); }
00592
00594
00595
00596 OBAtomIterator BeginAtoms() { return _vatom.begin(); }
00598 OBAtomIterator EndAtoms() { return _vatom.begin() + NumAtoms() ; }
00600 OBBondIterator BeginBonds() { return _vbond.begin(); }
00602 OBBondIterator EndBonds() { return _vbond.begin() + NumBonds() ; }
00604 OBResidueIterator BeginResidues() { return _residue.begin(); }
00606 OBResidueIterator EndResidues() { return _residue.end(); }
00607
00610 OBAtom *BeginAtom(OBAtomIterator &i);
00613 OBAtom *NextAtom(OBAtomIterator &i);
00616 OBBond *BeginBond(OBBondIterator &i);
00619 OBBond *NextBond(OBBondIterator &i);
00622 OBResidue *BeginResidue(OBResidueIterator &i)
00623 {
00624 i = _residue.begin();
00625 return((i == _residue.end()) ? NULL:*i);
00626 }
00629 OBResidue *NextResidue(OBResidueIterator &i)
00630 {
00631 ++i;
00632 return((i == _residue.end()) ? NULL:*i);
00633 }
00637 OBInternalCoord *BeginInternalCoord(std::vector<OBInternalCoord*>::iterator &i)
00638 {
00639 i = _internals.begin();
00640 return((i == _internals.end()) ? NULL:*i);
00641 }
00645 OBInternalCoord *NextInternalCoord(std::vector<OBInternalCoord*>::iterator &i)
00646 {
00647 ++i;
00648 return((i == _internals.end()) ? NULL:*i);
00649 }
00651
00652 };
00653
00654
00655
00656
00657 OBAPI void ThrowError(char *str);
00658
00659 OBAPI void ThrowError(std::string &str);
00661 OBAPI void CartesianToInternal(std::vector<OBInternalCoord*>&,OBMol&);
00663 OBAPI void InternalToCartesian(std::vector<OBInternalCoord*>&,OBMol&);
00664
00665 OBAPI std::string NewExtension(std::string&,char*);
00666
00667
00669 EXTERN OBElementTable etab;
00672 EXTERN OBTypeTable ttab;
00674 EXTERN OBIsotopeTable isotab;
00676 EXTERN OBAromaticTyper aromtyper;
00679 EXTERN OBAtomTyper atomtyper;
00681 EXTERN OBChainsParser chainsparser;
00683 OBERROR extern OBMessageHandler obErrorLog;
00685 EXTERN OBResidueData resdat;
00686
00687
00688
00689 #ifndef BUFF_SIZE
00690 #define BUFF_SIZE 32768
00691 #endif
00692
00693 #ifndef EQ
00694 #define EQ(a,b) (!strcmp((a), (b)))
00695 #endif
00696
00697 #ifndef EQn
00698 #define EQn(a,b,n) (!strncmp((a), (b), (n)))
00699 #endif
00700
00701 #ifndef SQUARE
00702 #define SQUARE(x) ((x)*(x))
00703 #endif
00704
00705 #ifndef IsUnsatType
00706 #define IsUnsatType(x) (EQ(x,"Car") || EQ(x,"C2") || EQ(x,"Sox") || EQ(x,"Sac") || EQ(x,"Pac") || EQ(x,"So2"))
00707 #endif
00708
00709 #ifndef __KCC
00710 extern "C"
00711 {
00712 OBAPI void get_rmat(double*,double*,double*,int);
00713 OBAPI void ob_make_rmat(double mat[3][3],double rmat[9]);
00714 OBAPI void qtrfit (double *r,double *f,int size,double u[3][3]);
00715 OBAPI double superimpose(double*,double*,int);
00716 }
00717 #else
00718 OBAPI void get_rmat(double*,double*,double*,int);
00719 OBAPI void ob_make_rmat(double mat[3][3],double rmat[9]);
00720 OBAPI void qtrfit (double *r,double *f,int size,double u[3][3]);
00721 OBAPI double superimpose(double*,double*,int);
00722 #endif // __KCC
00723
00724
00725
00726 }
00727
00728 #endif // OB_MOL_H
00729