atom.h
Go to the documentation of this file.
00001 /********************************************************************** 00002 atom.h - Handle OBAtom class. 00003 00004 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. 00005 Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison 00006 Some portions Copyright (C) 2003 by Michael Banck 00007 00008 This file is part of the Open Babel project. 00009 For more information, see <http://openbabel.org/> 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation version 2 of the License. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 ***********************************************************************/ 00020 00021 #ifndef OB_ATOM_H 00022 #define OB_ATOM_H 00023 00024 #include <openbabel/babelconfig.h> 00025 00026 #ifndef EXTERN 00027 # define EXTERN extern 00028 #endif 00029 00030 #include <vector> 00031 #include <string> 00032 00033 #include <openbabel/base.h> 00034 #include <openbabel/residue.h> 00035 #include <openbabel/math/vector3.h> 00036 00037 namespace OpenBabel 00038 { 00039 00040 class OBBond; 00041 class OBMol; 00042 00044 typedef OBAtom OBNodeBase; 00046 typedef std::vector<OBBond*>::iterator OBBondIterator; 00048 typedef std::vector<OBAtom*>::iterator OBAtomIterator; 00049 00050 //ATOM Property Macros (flags) 00052 #define OB_4RING_ATOM (1<<1) 00053 00054 #define OB_3RING_ATOM (1<<2) 00055 00056 #define OB_AROMATIC_ATOM (1<<3) 00057 00058 #define OB_RING_ATOM (1<<4) 00059 00060 #define OB_CSTEREO_ATOM (1<<5) 00061 00062 #define OB_ACSTEREO_ATOM (1<<6) 00063 00064 #define OB_DONOR_ATOM (1<<7) 00065 00066 #define OB_ACCEPTOR_ATOM (1<<8) 00067 00068 #define OB_CHIRAL_ATOM (1<<9) 00069 00070 #define OB_POS_CHIRAL_ATOM (1<<10) 00071 00072 #define OB_NEG_CHIRAL_ATOM (1<<11) 00073 00074 #define OB_ATOM_HAS_NO_H (1<<12) 00075 00076 #define OB_ATOM_NOT_H_DEFICIENT (1<<13) 00077 00078 // Class OBAtom 00079 // class introduction in atom.cpp 00080 class OBAPI OBAtom: public OBBase 00081 { 00082 protected: 00083 unsigned char _ele; 00084 char _impval; 00085 char _type[6]; 00086 short _fcharge; 00087 unsigned short _isotope; 00088 short _spinmultiplicity; 00089 00090 unsigned int _idx; 00091 OBMol *_parent; 00092 std::vector<OBBond*> _vbond; 00093 00094 unsigned int _cidx; 00095 unsigned short _hyb; 00096 unsigned short _flags; 00097 double _pcharge; 00098 double **_c; 00099 mutable vector3 _v; 00100 OBResidue *_residue; 00101 00102 unsigned long _id; 00103 00105 int GetFlag() const { return(_flags); } 00107 void SetFlag(int flag) { _flags |= flag; } 00109 bool HasFlag(int flag) { return((_flags & flag) ? true : false); } 00110 00111 public: 00112 enum StereoFlag { 00113 00114 }; 00115 00116 00118 bool Visit; 00119 00121 OBAtom(); 00123 virtual ~OBAtom(); 00125 OBAtom &operator = (OBAtom &); 00127 bool operator==(const OBAtom * other) const { return (GetIdx() == other->GetIdx()); } 00130 void Duplicate(OBAtom *); 00133 bool Clear(); 00134 00136 00137 00138 void SetIdx(int idx) { _idx = idx; _cidx = (idx-1)*3; } 00139 void SetId(unsigned long id) { _id = id; } 00141 void SetHyb(int hyb) { _hyb = hyb; } 00143 void SetAtomicNum(int atomicnum) { _ele = (char)atomicnum; } 00145 void SetIsotope(unsigned int iso); 00147 void SetImplicitValence(int val) { _impval = (char)val; } 00149 void IncrementImplicitValence() { _impval++; } 00151 void DecrementImplicitValence() { _impval--; } 00153 void SetFormalCharge(int fcharge) { _fcharge = fcharge; } 00155 void SetSpinMultiplicity(short spin){ _spinmultiplicity = spin; } 00157 void SetType(const char *type); 00159 void SetType(const std::string &type); 00161 void SetPartialCharge(double pcharge){ _pcharge = pcharge; } 00163 void SetVector(const vector3 &v); 00165 void SetVector(const double x,const double y,const double z); 00167 void SetCoordPtr(double **c) { _c = c; _cidx = (GetIdx()-1)*3; } 00169 void SetVector(); 00171 void SetResidue(OBResidue *res) { _residue=res; } 00173 void SetParent(OBMol *ptr) { _parent=ptr; } 00175 void SetAromatic() { SetFlag(OB_AROMATIC_ATOM); } 00177 void UnsetAromatic() { _flags &= (~(OB_AROMATIC_ATOM)); } 00179 void SetClockwiseStereo() { SetFlag(OB_CSTEREO_ATOM|OB_CHIRAL_ATOM); } 00181 void SetAntiClockwiseStereo() { SetFlag(OB_ACSTEREO_ATOM|OB_CHIRAL_ATOM); } 00183 void SetPositiveStereo() { SetFlag(OB_POS_CHIRAL_ATOM|OB_CHIRAL_ATOM); } 00185 void SetNegativeStereo() { SetFlag(OB_NEG_CHIRAL_ATOM|OB_CHIRAL_ATOM); } 00187 void UnsetStereo() 00188 { 00189 _flags &= ~(OB_ACSTEREO_ATOM); 00190 _flags &= ~(OB_CSTEREO_ATOM); 00191 _flags &= ~(OB_POS_CHIRAL_ATOM); 00192 _flags &= ~(OB_NEG_CHIRAL_ATOM); 00193 _flags &= ~(OB_CHIRAL_ATOM); 00194 } 00196 void SetInRing() { SetFlag(OB_RING_ATOM); } 00198 void SetChiral() { SetFlag(OB_CHIRAL_ATOM); } 00200 void ClearCoordPtr() { _c = NULL; _cidx=0; } 00202 00204 00205 00206 int GetFormalCharge() const { return(_fcharge); } 00208 unsigned int GetAtomicNum() const { return((unsigned int)_ele); } 00210 unsigned short int GetIsotope() const { return(_isotope); } 00213 int GetSpinMultiplicity() const { return(_spinmultiplicity); } 00216 double GetAtomicMass() const; 00219 double GetExactMass() const; 00221 unsigned int GetIdx() const { return((int)_idx); } 00222 unsigned int GetIndex() const { return _idx - 1; } 00223 unsigned long GetId() const { return _id; } 00226 unsigned int GetCoordinateIdx() const { return((int)_cidx); } 00228 unsigned int GetCIdx() const { return((int)_cidx); } 00230 unsigned int GetValence() const { return (unsigned int)_vbond.size(); } 00232 unsigned int GetHyb() const; 00234 unsigned int GetImplicitValence() const; 00236 unsigned int GetHvyValence() const; 00238 unsigned int GetHeteroValence() const; 00240 char *GetType(); 00241 00243 double GetX() const { return(x()); } 00245 double GetY() const { return(y()); } 00247 double GetZ() const { return(z()); } 00248 00249 // These methods check to see if there is a coordinate pointer 00250 // or an internal vector (e.g., SetCoordPtr()) 00252 double x() const { 00253 if (_c) return((*_c)[_cidx]); 00254 else return _v.x(); 00255 } 00257 double y() const { 00258 if (_c) return((*_c)[_cidx+1]); 00259 else return _v.y(); 00260 } 00262 double z() const { 00263 if (_c) return((*_c)[_cidx+2]); 00264 else return _v.z(); 00265 } 00270 double *GetCoordinate(){ 00271 if (_c) return(&(*_c)[_cidx]); 00272 else return NULL; 00273 } 00275 vector3 &GetVector(); 00277 const vector3 &GetVector() const; 00279 double GetPartialCharge(); 00281 OBResidue *GetResidue(); 00284 OBResidue *GetResidue(bool perception); 00286 OBMol *GetParent() {return((OBMol*)_parent);} 00289 bool GetNewBondVector(vector3 &v,double length); 00292 OBBond *GetBond(OBAtom *); 00297 OBAtom *GetNextAtom(); 00299 00301 00302 00303 OBBondIterator BeginBonds() 00304 { return(_vbond.begin()); } 00306 OBBondIterator EndBonds() 00307 { return(_vbond.end()); } 00310 OBBond *BeginBond(OBBondIterator &i); 00313 OBBond *NextBond(OBBondIterator &i); 00316 OBAtom *BeginNbrAtom(OBBondIterator &i); 00319 OBAtom *NextNbrAtom(OBBondIterator &i); 00321 00323 double GetDistance(int index); 00325 double GetDistance(OBAtom*); 00327 double GetDistance(vector3* v); 00329 double GetAngle(int b, int c); 00331 double GetAngle(OBAtom *b, OBAtom *c); 00332 00334 00335 00337 void NewResidue() 00338 { 00339 if (!_residue) 00340 _residue = new OBResidue; 00341 } 00343 void AddResidue(OBResidue *res) { SetResidue(res); } 00345 void DeleteResidue(){ 00346 if (_residue) { 00347 delete _residue; 00348 _residue = NULL; // Make sure to clear that a residue existed 00349 } 00350 } 00352 void AddBond(OBBond *bond) { _vbond.push_back(bond); } 00355 void InsertBond(OBBondIterator &i, OBBond *bond) 00356 { 00357 _vbond.insert(i, bond); 00358 } 00360 bool DeleteBond(OBBond* bond); 00362 void ClearBond() {_vbond.clear();} 00364 00366 00367 00370 bool HtoMethyl(); 00373 bool SetHybAndGeom(int); 00375 void ForceNoH() {SetFlag(OB_ATOM_HAS_NO_H);} 00377 bool HasNoHForced() {return HasFlag(OB_ATOM_HAS_NO_H);} 00378 00381 void ForceImplH() {SetFlag(OB_ATOM_NOT_H_DEFICIENT);} 00384 bool HasImplHForced() {return HasFlag(OB_ATOM_NOT_H_DEFICIENT);} 00386 00388 00389 00390 unsigned int CountFreeOxygens() const; 00392 unsigned int ImplicitHydrogenCount() const; 00394 unsigned int ExplicitHydrogenCount(bool ExcludeIsotopes=false) const; 00396 unsigned int MemberOfRingCount() const; 00398 unsigned int MemberOfRingSize() const; 00400 unsigned int CountRingBonds() const; 00402 double SmallestBondAngle(); 00404 double AverageBondAngle(); 00406 unsigned int BOSum() const; 00409 unsigned int KBOSum() const; 00411 bool HasResidue() { return(_residue != NULL); } 00413 bool IsHydrogen() { return(GetAtomicNum() == 1); } 00414 bool IsHydrogen() const { return(GetAtomicNum() == 1); } 00416 bool IsCarbon() { return(GetAtomicNum() == 6); } 00418 bool IsNitrogen() { return(GetAtomicNum() == 7); } 00420 bool IsOxygen() { return(GetAtomicNum() == 8); } 00422 bool IsSulfur() { return(GetAtomicNum() == 16);} 00424 bool IsPhosphorus() { return(GetAtomicNum() == 15);} 00426 bool IsAromatic() const; 00428 bool IsInRing() const; 00430 bool IsInRingSize(int) const; 00433 bool IsHeteroatom(); 00435 bool IsNotCorH(); 00437 bool IsConnected(OBAtom*); 00440 bool IsOneThree(OBAtom*); 00443 bool IsOneFour(OBAtom*); 00445 bool IsCarboxylOxygen(); 00447 bool IsPhosphateOxygen(); 00449 bool IsSulfateOxygen(); 00451 bool IsNitroOxygen(); 00453 bool IsAmideNitrogen(); 00456 bool IsPolarHydrogen(); 00459 bool IsNonPolarHydrogen(); 00462 bool IsAromaticNOxide(); 00464 bool IsChiral(); 00466 bool IsAxial(); 00468 bool IsClockwise() { return(HasFlag(OB_CSTEREO_ATOM)); } 00470 bool IsAntiClockwise() { return(HasFlag(OB_ACSTEREO_ATOM)); } 00472 bool IsPositiveStereo() { return(HasFlag(OB_POS_CHIRAL_ATOM)); } 00474 bool IsNegativeStereo() { return(HasFlag(OB_NEG_CHIRAL_ATOM)); } 00476 bool HasChiralitySpecified() { return(HasFlag(OB_CSTEREO_ATOM|OB_ACSTEREO_ATOM)); } 00478 bool HasChiralVolume() { return(HasFlag(OB_POS_CHIRAL_ATOM|OB_NEG_CHIRAL_ATOM)); } 00480 bool IsHbondAcceptor(); 00482 bool IsHbondDonor(); 00483 bool IsHbondDonorH(); 00485 bool IsMetal(); 00490 bool HasAlphaBetaUnsat(bool includePandS=true); 00492 bool HasBondOfOrder(unsigned int bo); 00494 int CountBondsOfOrder(unsigned int bo); 00496 bool HasNonSingleBond(); 00498 bool HasSingleBond() { return(HasBondOfOrder(1)); } 00500 bool HasDoubleBond() { return(HasBondOfOrder(2)); } 00502 bool HasAromaticBond() { return(HasBondOfOrder(5)); } 00504 bool MatchesSMARTS(const char *); 00506 00507 }; // class OBAtom 00508 00509 }// namespace OpenBabel 00510 00511 #endif // OB_ATOM_H 00512