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.sourceforge.net/> 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) 00054 #define OB_3RING_ATOM (1<<2) 00056 #define OB_AROMATIC_ATOM (1<<3) 00058 #define OB_RING_ATOM (1<<4) 00060 #define OB_CSTEREO_ATOM (1<<5) 00062 #define OB_ACSTEREO_ATOM (1<<6) 00064 #define OB_DONOR_ATOM (1<<7) 00066 #define OB_ACCEPTOR_ATOM (1<<8) 00068 #define OB_CHIRAL_ATOM (1<<9) 00070 #define OB_POS_CHIRAL_ATOM (1<<10) 00072 #define OB_NEG_CHIRAL_ATOM (1<<11) 00074 #define OB_ATOM_HAS_NO_H (1<<12) 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 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 00103 int GetFlag() const { return(_flags); } 00105 void SetFlag(int flag) { _flags |= flag; } 00107 bool HasFlag(int flag) { return((_flags & flag) ? true : false); } 00108 00109 public: 00111 bool Visit; 00112 00114 OBAtom(); 00116 virtual ~OBAtom(); 00118 OBAtom &operator = (OBAtom &); 00121 void Duplicate(OBAtom *); 00124 bool Clear(); 00125 00127 00128 00129 void SetIdx(int idx) { _idx = idx; _cidx = (idx-1)*3; } 00131 void SetHyb(int hyb) { _hyb = hyb; } 00133 void SetAtomicNum(int atomicnum) { _ele = (char)atomicnum; } 00135 void SetIsotope(unsigned int iso); 00137 void SetImplicitValence(int val) { _impval = (char)val; } 00139 void IncrementImplicitValence() { _impval++; } 00141 void DecrementImplicitValence() { _impval--; } 00143 void SetFormalCharge(int fcharge) { _fcharge = fcharge; } 00145 void SetSpinMultiplicity(short spin){ _spinmultiplicity = spin; } 00147 void SetType(const char *type); 00149 void SetType(const std::string &type); 00151 void SetPartialCharge(double pcharge){ _pcharge = pcharge; } 00153 void SetVector(const vector3 &v); 00155 void SetVector(const double x,const double y,const double z); 00157 void SetCoordPtr(double **c) { _c = c; _cidx = (GetIdx()-1)*3; } 00159 void SetVector(); 00161 void SetResidue(OBResidue *res) { _residue=res; } 00163 void SetParent(OBMol *ptr) { _parent=ptr; } 00165 void SetAromatic() { SetFlag(OB_AROMATIC_ATOM); } 00167 void UnsetAromatic() { _flags &= (~(OB_AROMATIC_ATOM)); } 00169 void SetClockwiseStereo() { SetFlag(OB_CSTEREO_ATOM|OB_CHIRAL_ATOM); } 00171 void SetAntiClockwiseStereo() { SetFlag(OB_ACSTEREO_ATOM|OB_CHIRAL_ATOM); } 00173 void SetPositiveStereo() { SetFlag(OB_POS_CHIRAL_ATOM|OB_CHIRAL_ATOM); } 00175 void SetNegativeStereo() { SetFlag(OB_NEG_CHIRAL_ATOM|OB_CHIRAL_ATOM); } 00177 void UnsetStereo() 00178 { 00179 _flags &= ~(OB_ACSTEREO_ATOM); 00180 _flags &= ~(OB_CSTEREO_ATOM); 00181 _flags &= ~(OB_POS_CHIRAL_ATOM); 00182 _flags &= ~(OB_NEG_CHIRAL_ATOM); 00183 _flags &= ~(OB_CHIRAL_ATOM); 00184 } 00186 void SetInRing() { SetFlag(OB_RING_ATOM); } 00188 void SetChiral() { SetFlag(OB_CHIRAL_ATOM); } 00190 void ClearCoordPtr() { _c = NULL; _cidx=0; } 00192 00194 00195 00196 int GetFormalCharge() const { return(_fcharge); } 00198 unsigned int GetAtomicNum() const { return((unsigned int)_ele); } 00200 unsigned short int GetIsotope() const { return(_isotope); } 00203 int GetSpinMultiplicity() const { return(_spinmultiplicity); } 00206 double GetAtomicMass() const; 00209 double GetExactMass() const; 00211 unsigned int GetIdx() const { return((int)_idx); } 00214 unsigned int GetCoordinateIdx() const { return((int)_cidx); } 00216 unsigned int GetCIdx() const { return((int)_cidx); } 00218 unsigned int GetValence() const 00219 { 00220 return((_vbond.empty()) ? 0 : _vbond.size()); 00221 } 00223 unsigned int GetHyb() const; 00225 unsigned int GetImplicitValence() const; 00227 unsigned int GetHvyValence() const; 00229 unsigned int GetHeteroValence() const; 00231 char *GetType(); 00232 00234 double GetX() const { return(x()); } 00236 double GetY() const { return(y()); } 00238 double GetZ() const { return(z()); } 00239 00240 // These methods check to see if there is a coordinate pointer 00241 // or an internal vector (e.g., SetCoordPtr()) 00243 double x() const { 00244 if (_c) return((*_c)[_cidx]); 00245 else return _v.x(); 00246 } 00248 double y() const { 00249 if (_c) return((*_c)[_cidx+1]); 00250 else return _v.y(); 00251 } 00253 double z() const { 00254 if (_c) return((*_c)[_cidx+2]); 00255 else return _v.z(); 00256 } 00261 double *GetCoordinate(){ 00262 if (_c) return(&(*_c)[_cidx]); 00263 else return NULL; 00264 } 00266 vector3 &GetVector(); 00268 const vector3 &GetVector() const; 00270 double GetPartialCharge(); 00272 OBResidue *GetResidue(); 00275 OBResidue *GetResidue(bool perception); 00277 OBMol *GetParent() {return((OBMol*)_parent);} 00280 bool GetNewBondVector(vector3 &v,double length); 00283 OBBond *GetBond(OBAtom *); 00288 OBAtom *GetNextAtom(); 00290 00292 00293 00294 OBBondIterator BeginBonds() 00295 { return(_vbond.begin()); } 00297 OBBondIterator EndBonds() 00298 { return(_vbond.end()); } 00301 OBBond *BeginBond(OBBondIterator &i); 00304 OBBond *NextBond(OBBondIterator &i); 00307 OBAtom *BeginNbrAtom(OBBondIterator &i); 00310 OBAtom *NextNbrAtom(OBBondIterator &i); 00312 00314 double GetDistance(int index); 00316 double GetDistance(OBAtom*); 00318 double GetAngle(int b, int c); 00320 double GetAngle(OBAtom *b, OBAtom *c); 00321 00323 00324 00326 void NewResidue() 00327 { 00328 if (!_residue) 00329 _residue = new OBResidue; 00330 } 00332 void AddResidue(OBResidue *res) { SetResidue(res); } 00334 void DeleteResidue(){ 00335 if (_residue) { 00336 delete _residue; 00337 _residue = NULL; // Make sure to clear that a residue existed 00338 } 00339 } 00341 void AddBond(OBBond *bond) { _vbond.push_back(bond); } 00344 void InsertBond(OBBondIterator &i, OBBond *bond) 00345 { 00346 _vbond.insert(i, bond); 00347 } 00349 bool DeleteBond(OBBond* bond); 00351 void ClearBond() {_vbond.clear();} 00353 00355 00356 00359 bool HtoMethyl(); 00362 bool SetHybAndGeom(int); 00364 void ForceNoH() {SetFlag(OB_ATOM_HAS_NO_H);} 00366 bool HasNoHForced() {return HasFlag(OB_ATOM_HAS_NO_H);} 00367 00370 void ForceImplH() {SetFlag(OB_ATOM_NOT_H_DEFICIENT);} 00373 bool HasImplHForced() {return HasFlag(OB_ATOM_NOT_H_DEFICIENT);} 00375 00377 00378 00379 unsigned int CountFreeOxygens() const; 00381 unsigned int ImplicitHydrogenCount() const; 00383 unsigned int ExplicitHydrogenCount(bool ExcludeIsotopes=false) const; 00385 unsigned int MemberOfRingCount() const; 00387 unsigned int MemberOfRingSize() const; 00389 unsigned int CountRingBonds() const; 00391 double SmallestBondAngle(); 00393 double AverageBondAngle(); 00395 unsigned int BOSum() const; 00398 unsigned int KBOSum() const; 00400 bool HasResidue() { return(_residue != NULL); } 00402 bool IsHydrogen() { return(GetAtomicNum() == 1); } 00404 bool IsCarbon() { return(GetAtomicNum() == 6); } 00406 bool IsNitrogen() { return(GetAtomicNum() == 7); } 00408 bool IsOxygen() { return(GetAtomicNum() == 8); } 00410 bool IsSulfur() { return(GetAtomicNum() == 16);} 00412 bool IsPhosphorus() { return(GetAtomicNum() == 15);} 00414 bool IsAromatic() const; 00416 bool IsInRing() const; 00418 bool IsInRingSize(int) const; 00421 bool IsHeteroatom(); 00423 bool IsNotCorH(); 00425 bool IsConnected(OBAtom*); 00428 bool IsOneThree(OBAtom*); 00431 bool IsOneFour(OBAtom*); 00433 bool IsCarboxylOxygen(); 00435 bool IsPhosphateOxygen(); 00437 bool IsSulfateOxygen(); 00439 bool IsNitroOxygen(); 00441 bool IsAmideNitrogen(); 00444 bool IsPolarHydrogen(); 00447 bool IsNonPolarHydrogen(); 00450 bool IsAromaticNOxide(); 00452 bool IsChiral(); 00454 bool IsAxial(); 00456 bool IsClockwise() { return(HasFlag(OB_CSTEREO_ATOM)); } 00458 bool IsAntiClockwise() { return(HasFlag(OB_ACSTEREO_ATOM)); } 00460 bool IsPositiveStereo() { return(HasFlag(OB_POS_CHIRAL_ATOM)); } 00462 bool IsNegativeStereo() { return(HasFlag(OB_NEG_CHIRAL_ATOM)); } 00464 bool HasChiralitySpecified() 00465 { return(HasFlag(OB_CSTEREO_ATOM|OB_ACSTEREO_ATOM)); } 00467 bool HasChiralVolume() 00468 { return(HasFlag(OB_POS_CHIRAL_ATOM|OB_NEG_CHIRAL_ATOM)); } 00470 bool IsHbondAcceptor(); 00472 bool IsHbondDonor(); 00474 bool IsHbondDonorH(); 00479 bool HasAlphaBetaUnsat(bool includePandS=true); 00481 bool HasBondOfOrder(unsigned int bo); 00483 int CountBondsOfOrder(unsigned int bo); 00485 bool HasNonSingleBond(); 00487 bool HasSingleBond() { return(HasBondOfOrder(1)); } 00489 bool HasDoubleBond() { return(HasBondOfOrder(2)); } 00491 bool HasAromaticBond() { return(HasBondOfOrder(5)); } 00493 bool MatchesSMARTS(const char *); 00495 00496 }; // class OBAtom 00497 00498 }// namespace OpenBabel 00499 00500 #endif // OB_ATOM_H 00501
This file is part of the documentation for Open Babel, version 2.2.0.