LOOS  v2.3.2
Atom.hpp
1 /*
2  This file is part of LOOS.
3 
4  LOOS (Lightweight Object-Oriented Structure library)
5  Copyright (c) 2008, Tod D. Romo, Alan Grossfield
6  Department of Biochemistry and Biophysics
7  School of Medicine & Dentistry, University of Rochester
8 
9  This package (LOOS) is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation under version 3 of the License.
12 
13  This package is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 
23 #if !defined(LOOS_ATOM_HPP)
24 #define LOOS_ATOM_HPP
25 
26 #include <iostream>
27 #include <string>
28 #include <stdexcept>
29 #include <vector>
30 #include <functional>
31 
32 #include <loos_defs.hpp>
33 #include <exceptions.hpp>
34 #include <Coord.hpp>
35 
36 namespace loos {
37 
39 
50  class Atom {
51  public:
52 
54  class UnsetProperty : public LOOSError {
55  public:
56  UnsetProperty() : LOOSError("Attempting to access an unset atom property") {}
57  UnsetProperty(const std::string& p) : LOOSError(p) {}
58  UnsetProperty(const Atom& a, const std::string& p) : LOOSError(a, p) {}
59  };
60 
61 
62 
63  // Be careful that we don't overflow an unsigned long!
65  enum bits {
66  nullbit = 0,
67  coordsbit = 1,
68  bondsbit = coordsbit << 1,
69  massbit = bondsbit << 1,
70  chargebit = massbit << 1,
71  anumbit = chargebit << 1,
72  flagbit = anumbit << 1,
73  usr1bit = flagbit << 1,
74  usr2bit = usr1bit << 1,
75  usr3bit = usr2bit << 1,
76  indexbit = usr3bit << 1
77  };
78 
79  Atom() { init(); }
80 
82 
89  Atom(const int i, const std::string s, const GCoord& c) {
90  init();
91  _index = 0;
92  _id = i;
93  _name = s;
94  _coords = c;
95  }
96 
97 
98  ~Atom() { }
99 
100  // Accessors...
101  int id(void) const;
102  void id(const int);
103 
104  uint index(void) const;
105  void index(const uint i);
106 
107  int resid(void) const;
108  void resid(const int);
109 
110  int atomic_number(void) const;
111  void atomic_number(const int);
112 
113  std::string name(void) const;
114  void name(const std::string);
115 
116  std::string altLoc(void) const;
117  void altLoc(const std::string);
118 
119  std::string chainId(void) const;
120  void chainId(const std::string);
121 
122  std::string resname(void) const;
123  void resname(const std::string);
124 
125  std::string segid(void) const;
126  void segid(const std::string);
127 
128  std::string iCode(void) const;
129  void iCode(const std::string);
130 
131  std::string PDBelement(void) const;
132  void PDBelement(const std::string);
133 
137  const GCoord& coords(void) const;
138 
139 #if !defined(SWIG)
140 
146  GCoord& coords(void);
147 #endif // !defined(SWIG)
148 
150  void coords(const GCoord&);
151 
152  double bfactor(void) const;
153  void bfactor(const double);
154 
155  double occupancy(void) const;
156  void occupancy(const double);
157 
158  // Note: swig requires explicit namespace on exception objects
159  double charge(void) const;
160 
162 
163  void charge(const double);
164 
165  double mass(void) const;
166  void mass(const double);
167 
168  int atomType() const;
169  void atomType(const int);
170 
174  std::string recordName(void) const;
175  void recordName(const std::string);
176 
178  void clearBonds(void);
180  void addBond(const pAtom&);
182  void addBond(const int);
183 
185  void deleteBond(const int);
186 
188  void deleteBond(const pAtom&);
189 
191  std::vector<int> getBonds(void) const;
192 
194  void setBonds(const std::vector<int>& list);
195 
196  bool hasBonds(void) const;
197 
199  bool isBoundTo(const int);
200 
201  bool isBoundTo(const pAtom&);
202 
204 
216  bool checkProperty(const bits bitmask);
217 
218 
220 
228  void setProperty(const bits bitmask);
229 
230 
232  void clearProperty(const bits bitmask);
233 
234 #if !defined(SWIG)
235  friend std::ostream& operator<<(std::ostream&, const Atom&);
237 #endif
238 
239  private:
240  void init(void);
242  void setPropertyBit(const bits);
244  void clearPropertyBit(const bits);
245 
246  void checkUserBits(const bits bitmask);
247 
248  private:
249  int _id;
250  uint _index;
251  std::string _record, _name, _altloc, _resname, _chainid;
252  int _resid;
253  int _atomic_number;
254  std::string _icode;
255  double _b, _q, _charge, _mass;
256  std::string _segid, _pdbelement;
257  int _atom_type;
258  GCoord _coords;
259  unsigned long mask;
260 
261  std::vector<int> bonds;
262  };
263 
264 
265 #if !defined(SWIG)
266  struct AtomEquals : public std::binary_function<pAtom, pAtom, bool> {
268  bool operator()(const pAtom& a, const pAtom& b) const;
269  };
270 
271 
273 
276  struct AtomCoordsEquals : public std::binary_function<pAtom, pAtom, bool> {
277  AtomCoordsEquals(const double d) : threshold(d*d) { }
278  AtomCoordsEquals() : threshold(1e-6) { }
279 
280  bool operator()(const pAtom& a, const pAtom& b) const;
281  double threshold;
282  };
283 
284 #endif // !defined(SWIG)
285 }
286 
287 #endif
std::string recordName(void) const
Definition: Atom.cpp:102
void clearBonds(void)
Clear all stored bonds.
Definition: Atom.cpp:106
void setProperty(const bits bitmask)
Sets user-defined bits.
Definition: Atom.cpp:169
std::vector< int > getBonds(void) const
Returns a copy of the bond list.
Definition: Atom.cpp:126
void addBond(const pAtom &)
Add a bond given a pAtom (extracting the atomid of the bond)
Definition: Atom.cpp:108
Basic Atom class for handling atom properties.
Definition: Atom.hpp:50
Compares two atoms based on name, id, resid, resname, segid, and coords.
Definition: Atom.hpp:276
bits
Bits in the bitmask that flag what properties have actually been set.
Definition: Atom.hpp:65
friend std::ostream & operator<<(std::ostream &, const Atom &)
Outputs an atom in pseudo-XML.
Definition: Atom.cpp:210
bool isBoundTo(const int)
Checks to see if this atom is bound to another atom.
Definition: Atom.cpp:140
void setBonds(const std::vector< int > &list)
Sets the bonds list.
Definition: Atom.cpp:132
DEPRECATED exception class...use loos::UnsetProperty instead.
Definition: Atom.hpp:54
Generic LOOS exception.
Definition: exceptions.hpp:40
Atom(const int i, const std::string s, const GCoord &c)
Constructs an atom with the atomid i, atomname s, and coordinates c.
Definition: Atom.hpp:89
void deleteBond(const int)
Deletes the specified bond.
Definition: Atom.cpp:113
Namespace for most things not already encapsulated within a class.
bool checkProperty(const bits bitmask)
Given a bit-mask, checks to see if those bits are set.
Definition: Atom.cpp:160
const GCoord & coords(void) const
Definition: Atom.cpp:74
void clearProperty(const bits bitmask)
Clears user-defined bits...
Definition: Atom.cpp:173