IMP logo
Atom.h
Go to the documentation of this file.
1 /**
2  * \file atom/Atom.h \brief Simple atom decorator.
3  *
4  * Copyright 2007-2012 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPATOM_ATOM_H
9 #define IMPATOM_ATOM_H
10 
11 #include "atom_config.h"
12 #include "atom_macros.h"
13 #include "Residue.h"
14 #include "Hierarchy.h"
15 #include "element.h"
16 #include <IMP/core/utility.h>
17 #include <IMP/core/XYZ.h>
18 
19 #include <IMP/base_types.h>
20 #include <IMP/Particle.h>
21 #include <IMP/Model.h>
22 
23 #include <vector>
24 #include <deque>
25 
26 IMPATOM_BEGIN_NAMESPACE
27 
28 IMP_DECLARE_CONTROLLED_KEY_TYPE(AtomType, IMP_ATOM_TYPE_INDEX);
29 /** \class AtomType
30  \brief The type of an atom.
31 
32  The standard Atom names in %IMP are derived from the PDB names as follows:
33  - the AtomType of a protein, DNA or RNA atom is the AtomType
34  created from the PDB atom name string with spaces removed. For
35  example, a protein C-alpha has the name AtomType("CA").
36  - the AtomType for a hetero (HETATM) atom is the AtomType created by
37  prefixing "HET:" to the PBD atom name string (this time without
38  spaces removed). For example, a calcium atom is AtomType("HET:CA ").
39 
40  We provide an AtomType instance for each of the standard PDB %atom types.
41  These have names such as IMP::atom::AT_N. The full list is elided for
42  readability.
43 
44  An AtomType implies an element (and hence a mass). While we have the
45  associations set up for protein, DNA and RNA atoms, it may be necessary
46  to add them for hetero atoms. You can use the add_atom_type() function
47  to do this.
48 
49  All atoms have the mass stored internally using a Mass decorator.
50 
51  \see IMP::atom::Atom
52 */
53 
54 /* each static must be on a separate line because of MSVC bug C2487:
55  see http://support.microsoft.com/kb/127900/
56 */
57 /** \relatesalso AtomType */
58 IMPATOMEXPORT extern const AtomType AT_UNKNOWN;
59 /** \relatesalso AtomType */
60 IMPATOMEXPORT extern const AtomType AT_N;
61 /** \relatesalso AtomType */
62 IMPATOMEXPORT extern const AtomType AT_CA;
63 #ifndef IMP_DOXYGEN
64 /** \relatesalso AtomType */
65 IMPATOMEXPORT extern const AtomType AT_C;
66 /** \relatesalso AtomType */
67 IMPATOMEXPORT extern const AtomType AT_O;
68 /** \relatesalso AtomType */
69 IMPATOMEXPORT extern const AtomType AT_H;
70 /** \relatesalso AtomType */
71 IMPATOMEXPORT extern const AtomType AT_H1;
72 /** \relatesalso AtomType */
73 IMPATOMEXPORT extern const AtomType AT_H2;
74 /** \relatesalso AtomType */
75 IMPATOMEXPORT extern const AtomType AT_H3;
76 /** \relatesalso AtomType */
77 IMPATOMEXPORT extern const AtomType AT_HA;
78 /** \relatesalso AtomType */
79 IMPATOMEXPORT extern const AtomType AT_HA1;
80 /** \relatesalso AtomType */
81 IMPATOMEXPORT extern const AtomType AT_HA2;
82 /** \relatesalso AtomType */
83 IMPATOMEXPORT extern const AtomType AT_HA3;
84 /** \relatesalso AtomType */
85 IMPATOMEXPORT extern const AtomType AT_CB;
86 /** \relatesalso AtomType */
87 IMPATOMEXPORT extern const AtomType AT_HB;
88 /** \relatesalso AtomType */
89 IMPATOMEXPORT extern const AtomType AT_HB1;
90 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HB2;
91 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HB3;
92 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_OXT;
93 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CH3;
94 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CH;
95 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CG;
96 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CG1;
97 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CG2;
98 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HG;
99 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HG1;
100 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HG2;
101 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HG3;
102 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HG11;
103 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HG21;
104 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HG31;
105 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HG12;
106 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HG13;
107 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HG22;
108 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HG23;
109 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HG32;
110 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_OG;
111 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_OG1;
112 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_SG;
113 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CD;
114 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CD1;
115 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CD2;
116 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HD;
117 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HD1;
118 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HD2;
119 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HD3;
120 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HD11;
121 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HD21;
122 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HD31;
123 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HD12;
124 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HD13;
125 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HD22;
126 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HD32;
127 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_SD;
128 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_OD1;
129 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_OD2;
130 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_ND1;
131 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_ND2;
132 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CE;
133 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CE1;
134 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CE2;
135 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CE3;
136 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HE;
137 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HE1;
138 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HE2;
139 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HE3;
140 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HE21;
141 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HE22;
142 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_OE1;
143 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_OE2;
144 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_NE;
145 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_NE1;
146 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_NE2;
147 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CZ;
148 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CZ2;
149 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CZ3;
150 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_NZ;
151 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HZ;
152 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HZ1;
153 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HZ2;
154 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HZ3;
155 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_CH2;
156 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_NH1;
157 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_NH2;
158 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_OH;
159 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HH;
160 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HH11;
161 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HH21;
162 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HH2;
163 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HH12;
164 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HH22;
165 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HH13;
166 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HH23;
167 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HH33;
168 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_P;
169 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_OP1;
170 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_OP2;
171 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_OP3;
172 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_O5p;
173 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_C5p;
174 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H5p;
175 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H5pp;
176 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_C4p;
177 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H4p;
178 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_O4p;
179 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_C1p;
180 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H1p;
181 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_C3p;
182 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H3p;
183 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_O3p;
184 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_C2p;
185 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H2p;
186 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H2pp;
187 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_O2p;
188 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_HO2p;
189 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_N9;
190 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_C8;
191 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H8;
192 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_N7;
193 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_C5;
194 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_C4;
195 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_N3;
196 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_C2;
197 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_N1;
198 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_C6;
199 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_N6;
200 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H61;
201 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H62;
202 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_O6;
203 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_N2;
204 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_NT;
205 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H21;
206 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H22;
207 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H6;
208 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H5;
209 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_O2;
210 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_N4;
211 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H41;
212 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H42;
213 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_O4;
214 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_C7;
215 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H71;
216 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H72;
217 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_H73;
218 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_O1A;
219 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_O2A;
220 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_O3A;
221 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_O1B;
222 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_O2B;
223 /** \relatesalso AtomType */ IMPATOMEXPORT extern const AtomType AT_O3B;
224 #endif
225 
226 
227 //! A decorator for a particle representing an atom.
228 /** Atoms always are Mass particles.
229  \ingroup hierarchy
230  \see Hierarchy
231  */
232 class IMPATOMEXPORT Atom:
233  public Hierarchy
234 {
235 public:
236 
238 
239  Particle* get_particle() const {
240  return Hierarchy::get_particle();
241  }
242 
243  /** Create a decorator with the passed type and coordinates.*/
244  static Atom setup_particle(Particle *p, AtomType t);
245 
246  /** Create a decorator by copying from o.*/
247  static Atom setup_particle(Particle *p, Atom o);
248 
249  //! return true if the particle has the needed attributes
250  static bool particle_is_instance(Particle *p) {
251  return p->has_attribute(get_atom_type_key())
252  && Hierarchy::particle_is_instance(p);
253  }
254 
255  AtomType get_atom_type() const {
256  return AtomType(get_particle()->get_value(get_atom_type_key()));
257  }
258 
259  //! Set the name and corresponding element and mass
260  void set_atom_type(AtomType t);
261 
262  //! get element
263  Element get_element() const {
264  return Element(get_particle()->get_value(get_element_key()));
265  }
266 #ifndef IMP_DOXYGEN
267  void set_element(Element e);
268 #endif
269 
270  double get_occupancy() const {
271  if (!get_particle()->has_attribute(get_occupancy_key())) {
272  return 1;
273  } else {
274  return get_particle()->get_value(get_occupancy_key());
275  }
276  }
277 
278  void set_occupancy(double occupancy) {
279  if (!get_particle()->has_attribute(get_occupancy_key())) {
280  get_particle()->add_attribute(get_occupancy_key(),occupancy);
281  } else {
282  get_particle()->set_value(get_occupancy_key(),occupancy);
283  }
284  }
285 
286  double get_temperature_factor() const {
287  if (!get_particle()->has_attribute(get_temperature_factor_key())) {
288  return 0;
289  } else {
290  return get_particle()->get_value(get_temperature_factor_key());
291  }
292  }
293 
294  void set_temperature_factor(double tempFactor) {
295  if (!get_particle()->has_attribute(get_temperature_factor_key())) {
296  get_particle()->add_attribute(get_temperature_factor_key(),tempFactor);
297  } else {
298  get_particle()->set_value(get_temperature_factor_key(),tempFactor);
299  }
300  }
301 
302  /** @name The atom index in the input file
303  This index is not necessarily unique over any particular
304  set of atoms and so should never be used as an atom identifier
305  except during I/O.
306  @{
307  */
308  IMP_DECORATOR_GET_SET_OPT(input_index, get_input_index_key(),
309  Int, Int, -1);
310  /* @}*/
311 
312  /** @name Keys
313  These methods provide access to the various keys used to store
314  things in the Atom. These can be used if you want to
315  use an attribute to search a set of particles.
316  @{
317  */
318  static IntKey get_atom_type_key();
319 
320  static IntKey get_element_key();
321 
322  static IntKey get_input_index_key();
323 
324  static FloatKey get_occupancy_key();
325 
326  static FloatKey get_temperature_factor_key();
327  //! @}
328 };
329 
330 IMP_DECORATORS(Atom,Atoms, Hierarchies);
331 
332 
333 #ifdef SWIG
334 class Residue;
335 #endif
336 
337 //! Return the Residue containing this atom
338 /** The atom must be part of a molecular hierarchy.
339 
340  \throw ValueException if no residue is found, unless
341  nothrow is true.
342 
343  \relatesalso Atom
344  \relatesalso Residue
345  \relatesalso Hierarchy
346  */
347 IMPATOMEXPORT Residue get_residue(Atom d, bool nothrow=false);
348 
349 //! Return a particle atom from the residue
350 /** The residue must be part of a molecular hierarchy.
351  \relatesalso Atom
352  \relatesalso Residue
353  \relatesalso Hierarchy
354  */
355 IMPATOMEXPORT Atom get_atom(Residue rd, AtomType at);
356 
357 
358 //! Create a new AtomType
359 /** This creates a new AtomType (returned) and sets up the mapping
360  between the AtomType and the proper element.
361  \note This method has not been tested. If you use it, please
362  write a test and remove this comment.
363  \relatesalso AtomType
364  \see atom_type_exists()
365 */
366 IMPATOMEXPORT AtomType add_atom_type(std::string name, Element e);
367 
368 IMPATOMEXPORT Element get_element_for_atom_type(AtomType at);
369 
370 //! Return true if that atom type already exists.
371 IMPATOMEXPORT bool get_atom_type_exists(std::string name);
372 
373 IMPATOM_END_NAMESPACE
374 
375 #endif /* IMPATOM_ATOM_H */

Generated on Tue May 22 2012 23:33:12 for IMP by doxygen 1.8.1