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 00231 { 00232 return((_vbond.empty()) ? 0 : static_cast<unsigned int> (_vbond.size())); 00233 } 00235 unsigned int GetHyb() const; 00237 unsigned int GetImplicitValence() const; 00239 unsigned int GetHvyValence() const; 00241 unsigned int GetHeteroValence() const; 00243 char *GetType(); 00244 00246 double GetX() const { return(x()); } 00248 double GetY() const { return(y()); } 00250 double GetZ() const { return(z()); } 00251 00252 // These methods check to see if there is a coordinate pointer 00253 // or an internal vector (e.g., SetCoordPtr()) 00255 double x() const { 00256 if (_c) return((*_c)[_cidx]); 00257 else return _v.x(); 00258 } 00260 double y() const { 00261 if (_c) return((*_c)[_cidx+1]); 00262 else return _v.y(); 00263 } 00265 double z() const { 00266 if (_c) return((*_c)[_cidx+2]); 00267 else return _v.z(); 00268 } 00273 double *GetCoordinate(){ 00274 if (_c) return(&(*_c)[_cidx]); 00275 else return NULL; 00276 } 00278 vector3 &GetVector(); 00280 const vector3 &GetVector() const; 00282 double GetPartialCharge(); 00284 OBResidue *GetResidue(); 00287 OBResidue *GetResidue(bool perception); 00289 OBMol *GetParent() {return((OBMol*)_parent);} 00292 bool GetNewBondVector(vector3 &v,double length); 00295 OBBond *GetBond(OBAtom *); 00300 OBAtom *GetNextAtom(); 00302 00304 00305 00306 OBBondIterator BeginBonds() 00307 { return(_vbond.begin()); } 00309 OBBondIterator EndBonds() 00310 { return(_vbond.end()); } 00313 OBBond *BeginBond(OBBondIterator &i); 00316 OBBond *NextBond(OBBondIterator &i); 00319 OBAtom *BeginNbrAtom(OBBondIterator &i); 00322 OBAtom *NextNbrAtom(OBBondIterator &i); 00324 00326 double GetDistance(int index); 00328 double GetDistance(OBAtom*); 00330 double GetAngle(int b, int c); 00332 double GetAngle(OBAtom *b, OBAtom *c); 00333 00335 00336 00338 void NewResidue() 00339 { 00340 if (!_residue) 00341 _residue = new OBResidue; 00342 } 00344 void AddResidue(OBResidue *res) { SetResidue(res); } 00346 void DeleteResidue(){ 00347 if (_residue) { 00348 delete _residue; 00349 _residue = NULL; // Make sure to clear that a residue existed 00350 } 00351 } 00353 void AddBond(OBBond *bond) { _vbond.push_back(bond); } 00356 void InsertBond(OBBondIterator &i, OBBond *bond) 00357 { 00358 _vbond.insert(i, bond); 00359 } 00361 bool DeleteBond(OBBond* bond); 00363 void ClearBond() {_vbond.clear();} 00365 00367 00368 00371 bool HtoMethyl(); 00374 bool SetHybAndGeom(int); 00376 void ForceNoH() {SetFlag(OB_ATOM_HAS_NO_H);} 00378 bool HasNoHForced() {return HasFlag(OB_ATOM_HAS_NO_H);} 00379 00382 void ForceImplH() {SetFlag(OB_ATOM_NOT_H_DEFICIENT);} 00385 bool HasImplHForced() {return HasFlag(OB_ATOM_NOT_H_DEFICIENT);} 00387 00389 00390 00391 unsigned int CountFreeOxygens() const; 00393 unsigned int ImplicitHydrogenCount() const; 00395 unsigned int ExplicitHydrogenCount(bool ExcludeIsotopes=false) const; 00397 unsigned int MemberOfRingCount() const; 00399 unsigned int MemberOfRingSize() const; 00401 unsigned int CountRingBonds() const; 00403 double SmallestBondAngle(); 00405 double AverageBondAngle(); 00407 unsigned int BOSum() const; 00410 unsigned int KBOSum() const; 00412 bool HasResidue() { return(_residue != NULL); } 00414 bool IsHydrogen() { return(GetAtomicNum() == 1); } 00415 bool IsHydrogen() const { return(GetAtomicNum() == 1); } 00417 bool IsCarbon() { return(GetAtomicNum() == 6); } 00419 bool IsNitrogen() { return(GetAtomicNum() == 7); } 00421 bool IsOxygen() { return(GetAtomicNum() == 8); } 00423 bool IsSulfur() { return(GetAtomicNum() == 16);} 00425 bool IsPhosphorus() { return(GetAtomicNum() == 15);} 00427 bool IsAromatic() const; 00429 bool IsInRing() const; 00431 bool IsInRingSize(int) const; 00434 bool IsHeteroatom(); 00436 bool IsNotCorH(); 00438 bool IsConnected(OBAtom*); 00441 bool IsOneThree(OBAtom*); 00444 bool IsOneFour(OBAtom*); 00446 bool IsCarboxylOxygen(); 00448 bool IsPhosphateOxygen(); 00450 bool IsSulfateOxygen(); 00452 bool IsNitroOxygen(); 00454 bool IsAmideNitrogen(); 00457 bool IsPolarHydrogen(); 00460 bool IsNonPolarHydrogen(); 00463 bool IsAromaticNOxide(); 00465 bool IsChiral(); 00467 bool IsAxial(); 00469 bool IsClockwise() { return(HasFlag(OB_CSTEREO_ATOM)); } 00471 bool IsAntiClockwise() { return(HasFlag(OB_ACSTEREO_ATOM)); } 00473 bool IsPositiveStereo() { return(HasFlag(OB_POS_CHIRAL_ATOM)); } 00475 bool IsNegativeStereo() { return(HasFlag(OB_NEG_CHIRAL_ATOM)); } 00477 bool HasChiralitySpecified() { return(HasFlag(OB_CSTEREO_ATOM|OB_ACSTEREO_ATOM)); } 00479 bool HasChiralVolume() { return(HasFlag(OB_POS_CHIRAL_ATOM|OB_NEG_CHIRAL_ATOM)); } 00481 bool IsHbondAcceptor(); 00483 bool IsHbondDonor(); 00485 bool IsHbondDonorH(); 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
This file is part of the documentation for Open Babel, version 2.3.