Open Babel  3.0
bond.h
Go to the documentation of this file.
1 /**********************************************************************
2 bond.h - Handle OBBond class.
3 
4 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
5 Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison
6 Some portions Copyright (C) 2003 by Michael Banck
7 Some portions Copyright (C) 2008 by Tim Vandermeersch
8 
9 This file is part of the Open Babel project.
10 For more information, see <http://openbabel.org/>
11 
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation version 2 of the License.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20 ***********************************************************************/
21 
22 #ifndef OB_BOND_H
23 #define OB_BOND_H
24 
25 #include <openbabel/babelconfig.h>
26 
27 #ifndef EXTERN
28 # define EXTERN extern
29 #endif
30 
31 #include <openbabel/base.h>
32 #include <openbabel/atom.h>
33 
34 namespace OpenBabel
35 {
36  class OBAtom;
37  class OBRing;
38 
39  //BOND Property Macros (flags)
41 #define OB_AROMATIC_BOND (1<<1)
42 #define OB_WEDGE_BOND (1<<2)
44 #define OB_HASH_BOND (1<<3)
46 #define OB_RING_BOND (1<<4)
48 #define OB_CLOSURE_BOND (1<<10)
50  // 11-16 currently unused
51 #define OB_WEDGE_OR_HASH_BOND (1<<11)
52 
53 #define SET_OR_UNSET_FLAG(X) \
54  if (value) SetFlag(X); \
55  else UnsetFlag(X);
56 
57 
58  class OBAPI OBBond: public OBBase
59  {
60  protected:
61  unsigned int _idx;
65  char _order;
66  unsigned short int _flags;
67  unsigned long _id;
68  //OBBondPrivate * const d;
69 
73  bool HasFlag(int flag) const { return ((_flags & flag) != 0); }
77  void SetFlag(int flag) { _flags |= flag; }
81  void UnsetFlag(int flag) { _flags &= (~(flag)); }
82 
83  public:
84  enum Flag {
85  Aromatic = (1<<1),
86  Ring = (1<<4),
87  Closure = (1<<10)
88  };
89  enum StereoFlag {
90  Wedge = (1<<2),
91  Hash = (1<<3),
92  WedgeOrHash = (1<<11),
93  CisOrTrans = (1<<12)
94  };
96 
97  bool Visit;
98 
100  OBBond();
102  virtual ~OBBond();
103 
105 
106 
109  void SetIdx(int idx) { _idx = idx; }
110  void SetId(unsigned long id) { _id = id; }
112  void SetBondOrder(int order);
114  void SetBegin(OBAtom *begin){ _bgn = begin; }
116  void SetEnd(OBAtom *end) { _end = end; }
118  void SetParent(OBMol *ptr) { _parent= ptr; }
120  void SetLength(OBAtom *fixed,double length);
123  void SetLength(double length);
125  void Set(int index, OBAtom* begin,OBAtom* end,int order,int flags);
127  void SetAromatic(bool value=true) { SET_OR_UNSET_FLAG(OB_AROMATIC_BOND); }
132  void SetWedge(bool value=true) { SET_OR_UNSET_FLAG(Wedge); }
137  void SetHash(bool value=true) { SET_OR_UNSET_FLAG(Hash); }
141  void SetWedgeOrHash(bool value=true) { SET_OR_UNSET_FLAG(WedgeOrHash); }
143  void SetInRing(bool value=true) { SET_OR_UNSET_FLAG(OB_RING_BOND); }
145 
148  void SetClosure(bool value=true) { SET_OR_UNSET_FLAG(OB_CLOSURE_BOND); }
150 
152 
153  unsigned int GetIdx() const { return(_idx); }
155  unsigned long GetId() const { return _id; }
157  unsigned int GetBondOrder() const { return(_order); }
159  unsigned int GetFlags() const { return(_flags); }
161  unsigned int GetBeginAtomIdx() const
162  { return (_bgn ? _bgn->GetIdx() : 0); }
164  unsigned int GetEndAtomIdx() const
165  { return (_end ? _end->GetIdx() : 0); }
167  OBAtom *GetBeginAtom() { return(_bgn); }
168  const OBAtom *GetBeginAtom() const
169  { return(_bgn); }
171  OBAtom *GetEndAtom() { return(_end); }
172  const OBAtom *GetEndAtom() const
173  { return(_end); }
175 
178  {
179  return((ptr != _bgn)? _bgn : _end);
180  }
182  OBMol *GetParent() {return(_parent);}
184 
185  double GetEquibLength() const;
187  double GetLength() const;
189 
191  unsigned int GetNbrAtomIdx(OBAtom *ptr)
192  {
193  if (ptr!=_bgn)
194  return (_bgn ? _bgn->GetIdx() : 0);
195  else
196  return (_end ? _end->GetIdx() : 0);
197  }
199  OBRing* FindSmallestRing() const;
201 
203 
204  bool IsAromatic() const;
209  bool IsInRing() const;
211 
217  bool IsRotor(bool includeRingBonds=false);
220  bool IsAmide();
223  bool IsPrimaryAmide();
226  bool IsSecondaryAmide();
229  bool IsTertiaryAmide();
231  bool IsEster();
233  bool IsCarbonyl();
235  bool IsClosure();
238  bool IsWedge() { return(HasFlag(OB_WEDGE_BOND)); }
241  bool IsHash() { return(HasFlag(OB_HASH_BOND)); }
247  bool IsWedgeOrHash() const { return(HasFlag(WedgeOrHash)); }
252  bool IsCisOrTrans() const { return(HasFlag(CisOrTrans)); }
253 
255  bool IsDoubleBondGeometry();
257 
258  }; // class OBBond
259 
261  typedef std::vector<OBBond*>::iterator OBBondIterator;
262 
263 }// namespace OpenBabel
264 
265 #endif // OB_BOND_H
266 
void SetFlag(int flag)
Definition: bond.h:77
bool IsCisOrTrans() const
Definition: bond.h:252
#define OB_WEDGE_BOND
A solid black wedge in 2D representations – i.e., "up" from the 2D plane.
Definition: bond.h:43
unsigned int GetBeginAtomIdx() const
Definition: bond.h:161
Flag
Definition: bond.h:84
unsigned short int _flags
Any flags for this bond.
Definition: bond.h:66
void SetHash(bool value=true)
Definition: bond.h:137
unsigned int GetNbrAtomIdx(OBAtom *ptr)
Definition: bond.h:191
Stores information on rings in a molecule from SSSR perception.
Definition: ring.h:40
void SetEnd(OBAtom *end)
Set the ending atom of this bond to end. Does not update end.
Definition: bond.h:116
Base classes to build a graph.
const OBAtom * GetBeginAtom() const
Definition: bond.h:168
OBAtom * GetNbrAtom(OBAtom *ptr)
Definition: bond.h:177
#define OB_AROMATIC_BOND
An aromatic bond (regardless of bond order)
Definition: bond.h:41
void SetWedgeOrHash(bool value=true)
Definition: bond.h:141
#define OB_CLOSURE_BOND
A bond which "closes" a ring when walking the molecular graph.
Definition: bond.h:49
void SetWedge(bool value=true)
Definition: bond.h:132
unsigned int _idx
Unique edge index used by GetIdx() and SetIdx()
Definition: bond.h:61
Bond class.
Definition: bond.h:58
const OBAtom * GetEndAtom() const
Definition: bond.h:172
Molecule Class.
Definition: mol.h:118
void SetBegin(OBAtom *begin)
Set the beginning atom of this bond to begin. Does not update begin.
Definition: bond.h:114
bool IsWedge()
Definition: bond.h:238
bool Visit
Whether this bond has been visited by a graph algorithm.
Definition: bond.h:97
bool IsWedgeOrHash() const
Definition: bond.h:247
unsigned int GetFlags() const
Definition: bond.h:159
void SetAromatic(bool value=true)
Mark that this bond is aromatic. Does not update atoms or validate.
Definition: bond.h:127
StereoFlag
Definition: bond.h:89
OBAtom * _bgn
I connect one node.
Definition: bond.h:63
OBAtom * GetBeginAtom()
Definition: bond.h:167
unsigned long GetId() const
Definition: bond.h:155
std::vector< OBBond * >::iterator OBBondIterator
A standard iterator over a vector of bonds.
Definition: atom.h:46
void SetInRing(bool value=true)
Mark that this bond is in a ring. Primarily for internal use.
Definition: bond.h:143
#define OB_HASH_BOND
A dashed "hash" bond in 2D representations – i.e., "down" from the 2D plane.
Definition: bond.h:45
void SetParent(OBMol *ptr)
Set the parent molecule to ptr. Does not update parent.
Definition: bond.h:118
void SetClosure(bool value=true)
Mark that this bond indicates a ring closure when walking the molecule.
Definition: bond.h:148
#define SET_OR_UNSET_FLAG(X)
Definition: bond.h:53
unsigned int GetIdx() const
Definition: atom.h:189
#define OB_RING_BOND
A bond in a ring.
Definition: bond.h:47
bool HasFlag(int flag) const
Definition: bond.h:73
unsigned int GetBondOrder() const
Definition: bond.h:157
OBMol * GetParent()
Definition: bond.h:182
void SetIdx(int idx)
Set the internal bond index.
Definition: bond.h:109
OBMol * _parent
The molecule which contains me (if any)
Definition: bond.h:62
void SetId(unsigned long id)
Definition: bond.h:110
OBAtom * GetEndAtom()
Definition: bond.h:171
void UnsetFlag(int flag)
Definition: bond.h:81
Handle atoms.
bool IsHash()
Definition: bond.h:241
unsigned int GetEndAtomIdx() const
Definition: bond.h:164
char _order
Bond order (1, 2, 3, 5=aromatic)
Definition: bond.h:65
Base Class.
Definition: base.h:239
OBAtom * _end
to another node
Definition: bond.h:64
unsigned long _id
unique id
Definition: bond.h:67
Global namespace for all Open Babel code.
Definition: alias.h:22
Atom class.
Definition: atom.h:71