bond.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 bond.h - Handle OBBond 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_BOND_H
00022 #define OB_BOND_H
00023 
00024 #include <openbabel/babelconfig.h>
00025 
00026 #ifndef EXTERN
00027 #  define EXTERN extern
00028 #endif
00029 
00030 #include <openbabel/base.h>
00031 #include <openbabel/atom.h>
00032 
00033 namespace OpenBabel
00034 {
00035 
00036   class OBAtom;
00037 
00039   typedef OBBond OBEdgeBase;
00040 
00041   //BOND Property Macros (flags)
00043 #define OB_AROMATIC_BOND  (1<<1)
00045 #define OB_WEDGE_BOND     (1<<2)
00047 #define OB_HASH_BOND      (1<<3)
00049 #define OB_RING_BOND      (1<<4)
00051 #define OB_TORUP_BOND     (1<<5)
00053 #define OB_TORDOWN_BOND   (1<<6)
00055 #define OB_KSINGLE_BOND   (1<<7)
00057 #define OB_KDOUBLE_BOND   (1<<8)
00059 #define OB_KTRIPLE_BOND   (1<<9)
00061 #define OB_CLOSURE_BOND   (1<<10)
00062   // 11-16 currently unused
00063 
00064   // class introduction in bond.cpp
00065  class OBAPI OBBond: public OBBase
00066     {
00067     protected:
00068       unsigned int                _idx;   
00069       OBMol                      *_parent;
00070       OBAtom                     *_bgn;   
00071       OBAtom                     *_end;   
00072 
00073       char                        _order; 
00074       unsigned short int          _flags; 
00075 
00076       bool HasFlag(int flag)    { return((_flags & flag) != 0); }
00077       void SetFlag(int flag)    { _flags |= flag;               }
00078       void UnsetFlag(int flag)  { _flags &= (~(flag));          }
00079 
00080     public:
00082 
00083       bool Visit;
00084 
00086       OBBond();
00088       virtual ~OBBond();
00089 
00091 
00092 
00093 
00095       void SetIdx(int idx)        {          _idx = idx;        }
00097 
00098       void SetBO(int order);
00100       void SetBondOrder(int order);
00102       void SetBegin(OBAtom *begin){          _bgn = begin;      }
00104       void SetEnd(OBAtom *end)    {          _end = end;        }
00106       void SetParent(OBMol *ptr)  {        _parent= ptr;        }
00108       void SetLength(OBAtom *fixed,double length);
00110       void Set(int index, OBAtom* begin,OBAtom* end,int order,int flags);
00112       void SetKSingle();
00114       void SetKDouble();
00116       void SetKTriple();
00118       void SetAromatic()    { SetFlag(OB_AROMATIC_BOND); }
00120       void SetHash()        { SetFlag(OB_HASH_BOND);     }
00122       void SetWedge()       { SetFlag(OB_WEDGE_BOND);    }
00124       void SetUp()          { SetFlag(OB_TORUP_BOND); UnsetFlag(OB_TORDOWN_BOND); }
00126       void SetDown()        { SetFlag(OB_TORDOWN_BOND); UnsetFlag(OB_TORUP_BOND);   }
00128       void SetInRing()      { SetFlag(OB_RING_BOND);     }
00130 
00133       void SetClosure()     { SetFlag(OB_CLOSURE_BOND);  }
00135       void UnsetHash()      { UnsetFlag(OB_HASH_BOND);    }
00137       void UnsetWedge()     { UnsetFlag(OB_WEDGE_BOND);   }
00139       void UnsetUp()        { UnsetFlag(OB_TORUP_BOND);   }
00141       void UnsetDown()      { UnsetFlag(OB_TORDOWN_BOND); }
00143       void UnsetAromatic()  { UnsetFlag(OB_AROMATIC_BOND);}
00145       void UnsetKekule()
00146         {
00147           _flags &= (~(OB_KSINGLE_BOND|OB_KDOUBLE_BOND|OB_KTRIPLE_BOND));
00148         }
00150 
00152 
00153 
00154       unsigned int     GetIdx()           const { return(_idx);  }
00156 
00157       unsigned int     GetBO()            const { return(_order); }
00159       unsigned int     GetBondOrder()     const { return(_order); }
00161       unsigned int     GetFlags()         const { return(_flags);      }
00163       unsigned int     GetBeginAtomIdx()  const { return(_bgn->GetIdx()); }
00165       unsigned int     GetEndAtomIdx()    const { return(_end->GetIdx()); }
00167       OBAtom *GetBeginAtom()    { return(_bgn);    }
00168       const OBAtom *GetBeginAtom() const 
00169         { return(_bgn);    }
00171       OBAtom *GetEndAtom()      { return(_end);    }
00172       const OBAtom *GetEndAtom() const
00173         { return(_end);    }
00175 
00177       OBAtom *GetNbrAtom(OBAtom *ptr)
00178         {
00179           return((ptr != _bgn)? _bgn : _end);
00180         }
00182       OBMol  *GetParent()                 {return(_parent);}
00184 
00185       double  GetEquibLength();
00187       double  GetLength();
00189 
00191       unsigned int     GetNbrAtomIdx(OBAtom *ptr)
00192         {
00193           return((ptr!=_bgn)?_bgn->GetIdx():_end->GetIdx());
00194         }
00196 
00198 
00199 
00200 
00201 
00202       bool IsAromatic() const;
00204       bool IsInRing() const;
00206 
00211       bool IsRotor();
00213       bool IsAmide();
00215       bool IsPrimaryAmide();
00217       bool IsSecondaryAmide();
00219       bool IsEster();
00221       bool IsCarbonyl();
00223       bool IsSingle();
00225       bool IsDouble();
00227       bool IsTriple();
00229       bool IsKSingle();
00231       bool IsKDouble();
00233       bool IsKTriple();
00235       bool IsClosure();
00238       bool IsUp()    {    return(HasFlag(OB_TORUP_BOND));    }
00241       bool IsDown()  {    return(HasFlag(OB_TORDOWN_BOND));  }
00244       bool IsWedge() {    return(HasFlag(OB_WEDGE_BOND));    }
00247       bool IsHash()  {    return(HasFlag(OB_HASH_BOND));     }
00249       bool IsDoubleBondGeometry();
00251 
00252     }; // class OBBond
00253 
00255   typedef std::vector<OBBond*>::iterator OBBondIterator;
00256 
00257 }// namespace OpenBabel
00258 
00259 #endif   // OB_BOND_H
00260