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.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 
00036 namespace OpenBabel
00037 {
00038 
00039   class OBBond;
00040   class OBMol;
00041 
00043   typedef OBAtom OBNodeBase;
00045   typedef std::vector<OBBond*>::iterator OBBondIterator;
00047   typedef std::vector<OBAtom*>::iterator OBAtomIterator;
00048 
00049   //ATOM Property Macros (flags)
00051 #define OB_4RING_ATOM     (1<<1)
00053 #define OB_3RING_ATOM     (1<<2)
00055 #define OB_AROMATIC_ATOM  (1<<3)
00057 #define OB_RING_ATOM      (1<<4)
00059 #define OB_CSTEREO_ATOM   (1<<5)
00061 #define OB_ACSTEREO_ATOM  (1<<6)
00063 #define OB_DONOR_ATOM     (1<<7)
00065 #define OB_ACCEPTOR_ATOM  (1<<8)
00067 #define OB_CHIRAL_ATOM    (1<<9)
00069 #define OB_POS_CHIRAL_ATOM (1<<10)
00071 #define OB_NEG_CHIRAL_ATOM (1<<11)
00073 #define OB_ATOM_HAS_NO_H   (1<<12)
00074   // 13-16 currently unused
00075 
00076   // Class OBAtom
00077   // class introduction in atom.cpp
00078  class OBAPI OBAtom: public OBBase
00079     {
00080     protected:
00081       char                          _ele;       
00082       char                          _impval;    
00083       char                          _type[6];   
00084       short                         _fcharge;   
00085       unsigned short                _isotope;   
00086       short                         _spinmultiplicity;
00087 
00088       unsigned int                  _idx;       
00089       OBMol                        *_parent;    
00090       std::vector<OBBond*>          _vbond;     
00091 
00092       unsigned int                  _cidx;      
00093       unsigned short                _hyb;       
00094       unsigned short                _flags;     
00095       double                        _pcharge;   
00096       double                      **_c;         
00097       mutable vector3               _v;         
00098       OBResidue                    *_residue;   
00099 
00101       int  GetFlag() const    {  return(_flags);  }
00103       void SetFlag(int flag)  { _flags |= flag;   }
00105       bool HasFlag(int flag)  {  return((_flags & flag) ? true : false); }
00106 
00107     public:
00109       bool Visit;
00110 
00112       OBAtom();
00114       virtual ~OBAtom();
00116       OBAtom &operator = (OBAtom &);
00119       bool Clear();
00120 
00122 
00123 
00124       void SetIdx(int idx)    { _idx = idx; _cidx = (idx-1)*3; }
00126       void SetHyb(int hyb)    { _hyb = hyb; }
00128       void SetAtomicNum(int atomicnum)    { _ele = (char)atomicnum; }
00130       void SetIsotope(unsigned int iso);
00132       void SetImplicitValence(int val)    { _impval = (char)val; }
00134       void IncrementImplicitValence()     { _impval++; }
00136       void DecrementImplicitValence()     { _impval--; }
00138       void SetFormalCharge(int fcharge)   { _fcharge = fcharge; }
00140       void SetSpinMultiplicity(short spin){ _spinmultiplicity = spin; }
00142       void SetType(const char *type);
00144       void SetType(std::string &type);
00146       void SetPartialCharge(double pcharge){ _pcharge = pcharge; }
00148       void SetVector(const vector3 &v);
00150       void SetVector(const double x,const double y,const double z);
00152       void SetCoordPtr(double **c)        { _c = c; _cidx = (GetIdx()-1)*3; }
00154       void SetVector();
00156       void SetResidue(OBResidue *res)     { _residue=res; }
00158       void SetParent(OBMol *ptr)          { _parent=ptr; }
00160       void SetAromatic()                  { SetFlag(OB_AROMATIC_ATOM); }
00162       void UnsetAromatic()                { _flags &= (~(OB_AROMATIC_ATOM)); }
00164       void SetClockwiseStereo()           { SetFlag(OB_CSTEREO_ATOM|OB_CHIRAL_ATOM); }
00166       void SetAntiClockwiseStereo()       { SetFlag(OB_ACSTEREO_ATOM|OB_CHIRAL_ATOM); }
00168       void SetPositiveStereo() { SetFlag(OB_POS_CHIRAL_ATOM|OB_CHIRAL_ATOM); }
00170       void SetNegativeStereo() { SetFlag(OB_NEG_CHIRAL_ATOM|OB_CHIRAL_ATOM); }
00172       void UnsetStereo()
00173         {
00174           _flags &= ~(OB_ACSTEREO_ATOM);
00175           _flags &= ~(OB_CSTEREO_ATOM);
00176           _flags &= ~(OB_POS_CHIRAL_ATOM);
00177           _flags &= ~(OB_NEG_CHIRAL_ATOM);
00178           _flags &= ~(OB_CHIRAL_ATOM);
00179         }
00181       void SetInRing()         { SetFlag(OB_RING_ATOM); }
00183       void SetChiral()         { SetFlag(OB_CHIRAL_ATOM); }
00185       void ClearCoordPtr()     { _c = NULL; _cidx=0; }
00187 
00189 
00190 
00191       int          GetFormalCharge()  const { return(_fcharge);    }
00193       unsigned int GetAtomicNum()     const { return((unsigned int)_ele); }
00195       unsigned short int GetIsotope() const { return(_isotope);    }
00198       int          GetSpinMultiplicity() const { return(_spinmultiplicity); }
00201       double     GetAtomicMass()    const;
00204       double     GetExactMass()     const;
00206       unsigned int GetIdx()           const { return((int)_idx);  }
00209       unsigned int GetCoordinateIdx() const { return((int)_cidx); }
00211       unsigned int GetCIdx()          const { return((int)_cidx); }
00213       unsigned int GetValence()       const
00214         {
00215           return((_vbond.empty()) ? 0 : _vbond.size());
00216         }
00218       unsigned int GetHyb()             const;
00220       unsigned int GetImplicitValence() const;
00222       unsigned int GetHvyValence()      const;
00224       unsigned int GetHeteroValence()   const;
00226       char        *GetType();
00227 
00229       double      GetX()    {        return(x());    }
00231       double      GetY()    {        return(y());    }
00233       double      GetZ()    {        return(z());    }
00234 
00235       // These methods check to see if there is a coordinate pointer
00236       // or an internal vector (e.g., SetCoordPtr())
00238       double      x() {
00239         if (_c)            return((*_c)[_cidx]);
00240         else               return _v.x();
00241       }
00243       double      y() {
00244         if (_c)            return((*_c)[_cidx+1]);
00245         else               return _v.y();
00246       }
00248       double      z() {
00249         if (_c)            return((*_c)[_cidx+2]);
00250         else               return _v.z();
00251       }
00256       double     *GetCoordinate(){
00257         if (_c)          return(&(*_c)[_cidx]);
00258         else             return NULL;
00259       }
00261       vector3   &GetVector();
00262       const vector3   &GetVector() const;
00264       double     GetPartialCharge();
00266       OBResidue *GetResidue();
00268       OBMol     *GetParent()        {return((OBMol*)_parent);}
00271       bool       GetNewBondVector(vector3 &v,double length);
00274       OBBond    *GetBond(OBAtom *);
00279       OBAtom    *GetNextAtom();
00281 
00283 
00284 
00285       OBBondIterator BeginBonds()
00286         { return(_vbond.begin()); }
00288       OBBondIterator EndBonds()
00289         { return(_vbond.end());   }
00292       OBBond *BeginBond(OBBondIterator &i);
00295       OBBond *NextBond(OBBondIterator &i);
00298       OBAtom *BeginNbrAtom(OBBondIterator &i);
00301       OBAtom *NextNbrAtom(OBBondIterator &i);
00303 
00305       double GetDistance(int index);
00307       double GetDistance(OBAtom*);
00309       double GetAngle(int b, int c);
00311       double GetAngle(OBAtom *b, OBAtom *c);
00312 
00314 
00315 
00317       void NewResidue()
00318         {
00319           if (!_residue)
00320             _residue = new OBResidue;
00321         }
00323       void AddResidue(OBResidue *res) { SetResidue(res); }
00325       void DeleteResidue(){
00326         if (_residue) {
00327           delete _residue;
00328           _residue = NULL; // Make sure to clear that a residue existed
00329         }
00330       }
00332       void AddBond(OBBond *bond) { _vbond.push_back(bond); }
00335       void InsertBond(OBBondIterator &i, OBBond *bond)
00336         {
00337           _vbond.insert(i, bond);
00338         }
00340       bool DeleteBond(OBBond* bond);
00342       void ClearBond() {_vbond.clear();}
00344 
00346 
00347 
00350       bool HtoMethyl();
00353       bool SetHybAndGeom(int);
00355       void ForceNoH() {SetFlag(OB_ATOM_HAS_NO_H);}
00357       bool HasNoHForced() {return HasFlag(OB_ATOM_HAS_NO_H);}
00359 
00361 
00362 
00363       unsigned int  CountFreeOxygens()      const;
00365       unsigned int  ImplicitHydrogenCount() const;
00367       unsigned int  ExplicitHydrogenCount(bool ExcludeIsotopes=false) const;
00369       unsigned int  MemberOfRingCount()     const;
00371       unsigned int  MemberOfRingSize()    const;
00373       unsigned int  CountRingBonds() const;
00375       double      SmallestBondAngle();
00377       double      AverageBondAngle();
00379       unsigned int  BOSum()                 const;
00382       unsigned int  KBOSum()                const;
00384       bool HasResidue()    { return(_residue != NULL);    }
00386       bool IsHydrogen()    { return(GetAtomicNum() == 1); }
00388       bool IsCarbon()      { return(GetAtomicNum() == 6); }
00390       bool IsNitrogen()    { return(GetAtomicNum() == 7); }
00392       bool IsOxygen()      { return(GetAtomicNum() == 8); }
00394       bool IsSulfur()      { return(GetAtomicNum() == 16);}
00396       bool IsPhosphorus()  { return(GetAtomicNum() == 15);}
00398       bool IsAromatic()      const;
00400       bool IsInRing()        const;
00402       bool IsInRingSize(int) const;
00405       bool IsHeteroatom();
00407       bool IsNotCorH();
00409       bool IsConnected(OBAtom*);
00412       bool IsOneThree(OBAtom*);
00415       bool IsOneFour(OBAtom*);
00417       bool IsCarboxylOxygen();
00419       bool IsPhosphateOxygen();
00421       bool IsSulfateOxygen();
00423       bool IsNitroOxygen();
00425       bool IsAmideNitrogen();
00428       bool IsPolarHydrogen();
00431       bool IsNonPolarHydrogen();
00434       bool IsAromaticNOxide();
00436       bool IsChiral();
00438       bool IsAxial();
00440       bool IsClockwise()         { return(HasFlag(OB_CSTEREO_ATOM));  }
00442       bool IsAntiClockwise()     { return(HasFlag(OB_ACSTEREO_ATOM)); }
00444       bool IsPositiveStereo() { return(HasFlag(OB_POS_CHIRAL_ATOM)); }
00446       bool IsNegativeStereo() { return(HasFlag(OB_NEG_CHIRAL_ATOM)); }
00448       bool HasChiralitySpecified()
00449         { return(HasFlag(OB_CSTEREO_ATOM|OB_ACSTEREO_ATOM)); }
00451       bool HasChiralVolume()
00452         { return(HasFlag(OB_POS_CHIRAL_ATOM|OB_NEG_CHIRAL_ATOM)); }
00454       bool IsHbondAcceptor();
00456       bool IsHbondDonor();
00458       bool IsHbondDonorH();
00463       bool HasAlphaBetaUnsat(bool includePandS=true);
00465       bool HasBondOfOrder(unsigned int bo);
00467       int  CountBondsOfOrder(unsigned int bo);
00469       bool HasNonSingleBond();
00471       bool HasSingleBond()    {        return(HasBondOfOrder(1));    }
00473       bool HasDoubleBond()    {        return(HasBondOfOrder(2));    }
00475       bool HasAromaticBond()  {        return(HasBondOfOrder(5));    }
00477       bool MatchesSMARTS(const char *);
00479 
00480     }; // class OBAtom
00481 
00482 }// namespace OpenBabel
00483 
00484 #endif   // OB_ATOM_H
00485