Open Babel  3.0
atom.h
Go to the documentation of this file.
1 /**********************************************************************
2 atom.h - Handle OBAtom 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 
8 This file is part of the Open Babel project.
9 For more information, see <http://openbabel.org/>
10 
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation version 2 of the License.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 ***********************************************************************/
20 
21 #ifndef OB_ATOM_H
22 #define OB_ATOM_H
23 
24 #include <openbabel/babelconfig.h>
25 
26 #ifndef EXTERN
27 # define EXTERN extern
28 #endif
29 
30 #include <vector>
31 #include <string>
32 
33 #include <openbabel/base.h>
34 #include <openbabel/residue.h>
35 #include <openbabel/math/vector3.h>
36 
37 namespace OpenBabel
38 {
39 
40  class OBBond;
41  class OBMol;
42 
44  typedef OBAtom OBNodeBase;
46  typedef std::vector<OBBond*>::iterator OBBondIterator;
48  typedef std::vector<OBAtom*>::iterator OBAtomIterator;
49 
50  //ATOM Property Macros (flags)
52 #define OB_4RING_ATOM (1<<1)
53 #define OB_3RING_ATOM (1<<2)
55 #define OB_AROMATIC_ATOM (1<<3)
57 #define OB_RING_ATOM (1<<4)
59 #define OB_DONOR_ATOM (1<<7)
61 #define OB_ACCEPTOR_ATOM (1<<8)
63 
64 #define SET_OR_UNSET_FLAG(X) \
65  if (value) SetFlag(X); \
66  else UnsetFlag(X);
67 
68  // Class OBAtom
69  // class introduction in atom.cpp
70  #define OBATOM_TYPE_LEN 6
71  class OBAPI OBAtom: public OBBase
72  {
73  protected:
74  unsigned char _ele;
75  unsigned char _imph;
76  char _type[OBATOM_TYPE_LEN];
77  short _fcharge;
78  unsigned short _isotope;
80 
81  unsigned int _idx;
83  std::vector<OBBond*> _vbond;
84 
85  unsigned int _cidx;
86  unsigned short _hyb;
87  unsigned short _flags;
88  double _pcharge;
89  double **_c;
90  mutable vector3 _v;
92 
93  unsigned long _id;
94 
96  int GetFlag() const { return(_flags); }
98  void SetFlag(int flag) { _flags |= flag; }
100  void UnsetFlag(int flag) { _flags &= (~(flag)); }
102  bool HasFlag(int flag) { return((_flags & flag) ? true : false); }
103 
104  public:
105  enum StereoFlag {
106 
107  };
108 
109 
111  bool Visit;
112 
114  OBAtom();
116  virtual ~OBAtom();
118  OBAtom &operator = (OBAtom &);
120  bool operator==(const OBAtom * other) const { return (GetIdx() == other->GetIdx()); }
123  void Duplicate(OBAtom *);
126  bool Clear();
127 
129 
130  void SetIdx(int idx) { _idx = idx; _cidx = (idx-1)*3; }
132  void SetId(unsigned long id) { _id = id; }
134  void SetHyb(int hyb) { _hyb = hyb; }
136  void SetAtomicNum(int atomicnum) { _ele = (char)atomicnum; }
138  void SetIsotope(unsigned int iso);
140  void SetImplicitHCount(unsigned int val) { _imph = (unsigned char)val; }
142  void SetFormalCharge(int fcharge) { _fcharge = fcharge; }
144  void SetSpinMultiplicity(short spin){ _spinmultiplicity = spin; }
146  void SetType(const char *type);
148  void SetType(const std::string &type);
150  void SetPartialCharge(double pcharge){ _pcharge = pcharge; }
152  void SetVector(const vector3 &v);
154  void SetVector(const double x,const double y,const double z);
156  void SetCoordPtr(double **c) { _c = c; _cidx = (GetIdx()-1)*3; }
158  void SetVector();
160  void SetResidue(OBResidue *res) { _residue=res; }
162  void SetParent(OBMol *ptr) { _parent=ptr; }
164  void SetAromatic(bool value=true) { SET_OR_UNSET_FLAG(OB_AROMATIC_ATOM); }
166  void SetInRing(bool value=true) { SET_OR_UNSET_FLAG(OB_RING_ATOM); }
168  void ClearCoordPtr() { _c = NULL; _cidx=0; }
170 
172 
173  int GetFormalCharge() const { return(_fcharge); }
176  unsigned int GetAtomicNum() const { return((unsigned int)_ele); }
178  unsigned short int GetIsotope() const { return(_isotope); }
181  int GetSpinMultiplicity() const { return(_spinmultiplicity); }
184  double GetAtomicMass() const;
187  double GetExactMass() const;
189  unsigned int GetIdx() const { return((int)_idx); }
190  unsigned int GetIndex() const { return _idx - 1; }
191  unsigned long GetId() const { return _id; }
194  unsigned int GetCoordinateIdx() const { return((int)_cidx); }
196  unsigned int GetExplicitDegree() const { return (unsigned int)_vbond.size(); }
198  unsigned int GetTotalDegree() const { return (unsigned int)(_vbond.size() + _imph); }
200  unsigned int GetExplicitValence() const;
202  unsigned int GetTotalValence() const;
204  unsigned int GetHyb() const;
206  unsigned char GetImplicitHCount() const { return _imph; };
208  unsigned int GetHvyDegree() const;
210  unsigned int GetHeteroDegree() const;
212  char *GetType();
213 
215  double GetX() const { return(x()); }
217  double GetY() const { return(y()); }
219  double GetZ() const { return(z()); }
220 
221  // These methods check to see if there is a coordinate pointer
222  // or an internal vector (e.g., SetCoordPtr())
224  double x() const {
225  if (_c) return((*_c)[_cidx]);
226  else return _v.x();
227  }
229  double y() const {
230  if (_c) return((*_c)[_cidx+1]);
231  else return _v.y();
232  }
234  double z() const {
235  if (_c) return((*_c)[_cidx+2]);
236  else return _v.z();
237  }
242  double *GetCoordinate(){
243  if (_c) return(&(*_c)[_cidx]);
244  else return NULL;
245  }
247  vector3 &GetVector();
249  const vector3 &GetVector() const;
251  double GetPartialCharge();
253  OBResidue *GetResidue();
255  OBMol *GetParent() {return((OBMol*)_parent);}
258  bool GetNewBondVector(vector3 &v,double length);
261  OBBond *GetBond(OBAtom *);
263 
265 
266  OBBondIterator BeginBonds()
268  { return(_vbond.begin()); }
270  OBBondIterator EndBonds()
271  { return(_vbond.end()); }
274  OBBond *BeginBond(OBBondIterator &i);
277  OBBond *NextBond(OBBondIterator &i);
280  OBAtom *BeginNbrAtom(OBBondIterator &i);
283  OBAtom *NextNbrAtom(OBBondIterator &i);
285 
287  double GetDistance(int index);
289  double GetDistance(OBAtom*);
292  double GetDistance(vector3* v);
294  double GetAngle(int b, int c);
296  double GetAngle(OBAtom *b, OBAtom *c);
297 
299 
300 
302  void NewResidue()
303  {
304  if (!_residue)
305  _residue = new OBResidue;
306  }
308  void AddResidue(OBResidue *res) { SetResidue(res); }
311  if (_residue) {
312  delete _residue;
313  _residue = NULL; // Make sure to clear that a residue existed
314  }
315  }
317  void AddBond(OBBond *bond) { _vbond.push_back(bond); }
320  void InsertBond(OBBondIterator &i, OBBond *bond)
321  {
322  _vbond.insert(i, bond);
323  }
325  bool DeleteBond(OBBond* bond);
327  void ClearBond() {_vbond.clear();}
329 
331 
332 
335  bool HtoMethyl();
338  bool SetHybAndGeom(int);
340 
342 
343  unsigned int CountFreeOxygens() const;
347  unsigned int CountFreeSulfurs() const;
349  unsigned int ExplicitHydrogenCount(bool ExcludeIsotopes=false) const;
351  unsigned int MemberOfRingCount() const;
353  unsigned int MemberOfRingSize() const;
355  unsigned int CountRingBonds() const;
357  double SmallestBondAngle();
359  double AverageBondAngle();
364  std::pair<int, int> LewisAcidBaseCounts() const;
366  bool HasResidue() { return(_residue != NULL); }
369  bool IsHetAtom() {
370  if (_residue == NULL)
371  return false;
372  else
373  return _residue->IsHetAtom(this);
374  }
376  bool IsAromatic() const;
378  bool IsInRing() const;
380  bool IsInRingSize(int) const;
383  bool IsHeteroatom();
385  bool IsConnected(OBAtom*);
388  bool IsOneThree(OBAtom*);
391  bool IsOneFour(OBAtom*);
393  bool IsCarboxylOxygen();
395  bool IsPhosphateOxygen();
397  bool IsSulfateOxygen();
399  bool IsNitroOxygen();
401  bool IsAmideNitrogen();
404  bool IsPolarHydrogen();
407  bool IsNonPolarHydrogen();
410  bool IsAromaticNOxide();
412  bool IsChiral();
414  bool IsAxial();
416  bool IsHbondAcceptor();
418  bool IsHbondAcceptorSimple();
420  bool IsHbondDonor();
422  bool IsHbondDonorH();
425  bool IsMetal();
430  bool HasAlphaBetaUnsat(bool includePandS=true);
432  bool HasBondOfOrder(unsigned int bo);
434  int CountBondsOfOrder(unsigned int bo);
436  int HighestBondOrder();
438  bool HasNonSingleBond();
440  bool HasSingleBond() { return(HasBondOfOrder(1)); }
442  bool HasDoubleBond() { return(HasBondOfOrder(2)); }
444  bool HasAromaticBond() { return(HasBondOfOrder(5)); }
446  bool MatchesSMARTS(const char *);
448 
449  }; // class OBAtom
450 
451 }// namespace OpenBabel
452 
453 #endif // OB_ATOM_H
454 
bool HasDoubleBond()
Definition: atom.h:442
unsigned char _imph
number of implicit hydrogens
Definition: atom.h:75
unsigned int _cidx
index into coordinate array
Definition: atom.h:85
void SetPartialCharge(double pcharge)
Set the partial charge to pcharge.
Definition: atom.h:150
double _pcharge
partial charge
Definition: atom.h:88
bool Visit
Used internally by graph traversal algorithms.
Definition: atom.h:111
void SetImplicitHCount(unsigned int val)
Set the implicit hydrogen count to val.
Definition: atom.h:140
void SetAtomicNum(int atomicnum)
Set atomic number.
Definition: atom.h:136
Handle 3D coordinates.
bool HasResidue()
Definition: atom.h:366
void SetParent(OBMol *ptr)
Attach an OBMol ptr as the parent container for this atom.
Definition: atom.h:162
unsigned short _isotope
isotope (0 = most abundant)
Definition: atom.h:78
unsigned long GetId() const
Definition: atom.h:191
double ** _c
coordinate array in double*
Definition: atom.h:89
bool IsHetAtom()
Definition: atom.h:369
Base classes to build a graph.
void SetAromatic(bool value=true)
Mark atom as being aromatic.
Definition: atom.h:164
void DeleteResidue()
Delete any residue associated with this atom.
Definition: atom.h:310
void AddBond(OBBond *bond)
Add a bond to the internal list. Does not update the bond.
Definition: atom.h:317
void SetSpinMultiplicity(short spin)
Set the atomic spin to spin. See _spinmultiplicity.
Definition: atom.h:144
void SetId(unsigned long id)
Definition: atom.h:132
OBBondIterator EndBonds()
Definition: atom.h:270
unsigned short int GetIsotope() const
Definition: atom.h:178
double GetX() const
Definition: atom.h:215
void UnsetFlag(int flag)
Unsets the bitwise flag.
Definition: atom.h:100
void ClearCoordPtr()
Clear the internal coordinate pointer.
Definition: atom.h:168
void AddResidue(OBResidue *res)
Add (set) the residue for this atom.
Definition: atom.h:308
StereoFlag
Definition: atom.h:105
Bond class.
Definition: bond.h:58
double * GetCoordinate()
Definition: atom.h:242
void SetInRing(bool value=true)
Mark an atom as belonging to at least one ring.
Definition: atom.h:166
OBAtom OBNodeBase
OBNodeBase is declared for backwards-compatibility with 2.0 and earlier code.
Definition: atom.h:41
#define OB_RING_ATOM
Atom is in a ring.
Definition: atom.h:58
const double & x() const
Access function to get the x-coordinate of the vector.
Definition: vector3.h:237
unsigned char _ele
atomic number (type unsigned char to minimize space – allows for 0..255 elements) ...
Definition: atom.h:74
Molecule Class.
Definition: mol.h:118
void SetResidue(OBResidue *res)
Attach an OBResidue res as containing this atom.
Definition: atom.h:160
void InsertBond(OBBondIterator &i, OBBond *bond)
Insert bond into the internal list at the position from i Does not modify the bond.
Definition: atom.h:320
bool HasFlag(int flag)
Definition: atom.h:102
bool HasAromaticBond()
Definition: atom.h:444
bool operator==(const OBAtom *other) const
Equivalence.
Definition: atom.h:120
unsigned int GetTotalDegree() const
Definition: atom.h:198
std::vector< OBBond * > _vbond
bonds to this atom – assumed to be one of the endpoints
Definition: atom.h:83
std::vector< OBAtom * >::iterator OBAtomIterator
A standard iterator over a vector of atoms.
Definition: atom.h:48
OBMol * _parent
parent molecule (if any)
Definition: atom.h:82
#define OB_AROMATIC_ATOM
Atom is aromatic.
Definition: atom.h:56
const double & y() const
Access function to get the y-coordinate of the vector.
Definition: vector3.h:242
std::vector< OBBond * >::iterator OBBondIterator
A standard iterator over a vector of bonds.
Definition: atom.h:46
unsigned short _flags
bitwise flags (e.g. aromaticity)
Definition: atom.h:87
unsigned int _idx
unique node index (GetIdx(), SetIdx())
Definition: atom.h:81
void SetCoordPtr(double **c)
Set the position of this atom from a pointer-driven array of coordinates.
Definition: atom.h:156
int GetSpinMultiplicity() const
Definition: atom.h:181
#define SET_OR_UNSET_FLAG(X)
Definition: atom.h:64
Represents a vector in 3-dimensional real space.
Definition: vector3.h:44
double z() const
Definition: atom.h:234
unsigned int GetAtomicNum() const
Definition: atom.h:176
Defines for residue properties, names, etc.
double GetExactMass(unsigned int atomic_number, unsigned int isotope=0)
Definition: elements.cpp:831
vector3 _v
coordinate vector
Definition: atom.h:90
void ClearBond()
Clear all bonding information in this atom (does not delete them)
Definition: atom.h:327
double x() const
Definition: atom.h:224
void SetHyb(int hyb)
Set atom hybridization (i.e., 1 = sp, 2 = sp2, 3 = sp3 ...)
Definition: atom.h:134
unsigned int GetIdx() const
Definition: atom.h:189
int GetFlag() const
Definition: atom.h:96
short _fcharge
formal charge
Definition: atom.h:77
OBResidue * _residue
parent residue (if applicable)
Definition: atom.h:91
void NewResidue()
If no residue has been set for this atom, create a new one.
Definition: atom.h:302
unsigned int GetIndex() const
Definition: atom.h:190
unsigned short _hyb
hybridization
Definition: atom.h:86
unsigned int GetCoordinateIdx() const
Definition: atom.h:194
double GetY() const
Definition: atom.h:217
void SetFlag(int flag)
Sets the bitwise flag.
Definition: atom.h:98
bool IsHetAtom(OBAtom *atom) const
Definition: residue.cpp:1098
unsigned char GetImplicitHCount() const
Definition: atom.h:206
short _spinmultiplicity
atomic spin, e.g., 2 for radical 1 or 3 for carbene
Definition: atom.h:79
bool HasSingleBond()
Definition: atom.h:440
void SetFormalCharge(int fcharge)
Set the formal charge of the atom to fcharge.
Definition: atom.h:142
OBMol * GetParent()
Definition: atom.h:255
#define OBATOM_TYPE_LEN
Definition: atom.h:70
const double & z() const
Access function to get the z-coordinate of the vector.
Definition: vector3.h:247
double y() const
Definition: atom.h:229
double GetZ() const
Definition: atom.h:219
Base Class.
Definition: base.h:239
Residue information.
Definition: residue.h:50
unsigned int GetExplicitDegree() const
Definition: atom.h:196
unsigned long _id
unique id
Definition: atom.h:93
Global namespace for all Open Babel code.
Definition: alias.h:22
Atom class.
Definition: atom.h:71