IMP  2.0.0
The Integrative Modeling Platform
Residue.h
Go to the documentation of this file.
1 /**
2  * \file IMP/atom/Residue.h \brief A decorator for Residues.
3  *
4  * Copyright 2007-2013 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPATOM_RESIDUE_H
9 #define IMPATOM_RESIDUE_H
10 
11 #include <IMP/atom/atom_config.h>
12 #include "atom_macros.h"
13 #include "Hierarchy.h"
14 #include "Chain.h"
15 
16 #include <IMP/base_types.h>
17 #include <IMP/Particle.h>
18 #include <IMP/Model.h>
19 #include <IMP/Decorator.h>
20 
21 IMPATOM_BEGIN_NAMESPACE
22 
23 /* each static must be on a separate line because of MSVC bug C2487:
24  see http://support.microsoft.com/kb/127900/
25 */
26 
27 IMP_DECLARE_KEY_TYPE(ResidueType, IMP_RESIDUE_TYPE_INDEX);
28 /** \class IMP::atom::ResidueType
29  \brief The type for a residue.
30 
31  A given residue is either a Residue::LIGAND, Residue::AMINOACID,
32  or Residue::NUCLEICACID.
33 
34  The standard residue types are provided with names like
35  IMP::atom::GLY. New types can be added simply by creating an
36  instance of ResidueType("my_residue_name"). All user-added
37  residues are assumed to be ligands.
38 
39  \see Residue
40 */
41 
42 /** Unknown residue */
43 IMPATOMEXPORT extern const ResidueType UNK;
44 /** \relatesalso ResidueType
45  glycein G*/
46 IMPATOMEXPORT extern const ResidueType GLY;
47 #ifndef IMP_DOXYGEN
48 /* Code currently assumes that all indices between GLY.get_index()
49  and TRP.get_index() being amino acids */
50 /** alanine A*/
51 IMPATOMEXPORT extern const ResidueType ALA;
52 /** valine V*/
53 IMPATOMEXPORT extern const ResidueType VAL;
54 /** leucine L*/
55 IMPATOMEXPORT extern const ResidueType LEU;
56 /** isoleucine I*/
57 IMPATOMEXPORT extern const ResidueType ILE;
58 /** serine S*/
59 IMPATOMEXPORT extern const ResidueType SER;
60 /** threonine T*/
61 IMPATOMEXPORT extern const ResidueType THR;
62 /** cystein C*/
63 IMPATOMEXPORT extern const ResidueType CYS;
64 /** metthionine M*/
65 IMPATOMEXPORT extern const ResidueType MET;
66 /** proline P*/
67 IMPATOMEXPORT extern const ResidueType PRO;
68 /** aspartic acid D*/
69 IMPATOMEXPORT extern const ResidueType ASP;
70 /** asparagine N*/
71 IMPATOMEXPORT extern const ResidueType ASN;
72 /** glutamine Q*/
73 IMPATOMEXPORT extern const ResidueType GLU;
74 /** glutamic acid E*/
75 IMPATOMEXPORT extern const ResidueType GLN;
76 /** lysine K*/
77 IMPATOMEXPORT extern const ResidueType LYS;
78 /** arginine N*/
79 IMPATOMEXPORT extern const ResidueType ARG;
80 /** histidine H*/
81 IMPATOMEXPORT extern const ResidueType HIS;
82 /** phynylaline F*/
83 IMPATOMEXPORT extern const ResidueType PHE;
84 /** tyrosine Y */
85 IMPATOMEXPORT extern const ResidueType TYR;
86 /** tryptophan W */
87 IMPATOMEXPORT extern const ResidueType TRP;
88 /** ACE */
89 IMPATOMEXPORT extern const ResidueType ACE;
90 /** end group */
91 IMPATOMEXPORT extern const ResidueType NH2;
92 /* Code currently assumes that all indices between ADE.get_index()
93  and DTHY.get_index() being nucleic acid */
94 /** adenine (RNA) */
95 IMPATOMEXPORT extern const ResidueType ADE;
96 /** uracil (RNA) */
97 IMPATOMEXPORT extern const ResidueType URA;
98 /** cytosine (RNA) */
99 IMPATOMEXPORT extern const ResidueType CYT;
100 /** guanine (RNA) */
101 IMPATOMEXPORT extern const ResidueType GUA;
102 /** thymine (RNA) */
103 IMPATOMEXPORT extern const ResidueType THY;
104 /** adenine (DNA) */
105 IMPATOMEXPORT extern const ResidueType DADE;
106 /** uracil (DNA) */
107 IMPATOMEXPORT extern const ResidueType DURA;
108 /** cytosine (DNA) */
109 IMPATOMEXPORT extern const ResidueType DCYT;
110 /** guanine (DNA) */
111 IMPATOMEXPORT extern const ResidueType DGUA;
112 /** thymine (DNA) */
113 IMPATOMEXPORT extern const ResidueType DTHY;
114 
115 // All further residues (including user-added residues) are ligands
116 
117 /** water molecule */
118 IMPATOMEXPORT extern const ResidueType HOH;
119 /** heme */
120 IMPATOMEXPORT extern const ResidueType HEME;
121 #endif
122 /*@}*/
123 
124 
125 //! A decorator for a residue.
126 /**
127  As with the Atom, the names of residues may be expanded
128  dynamically. This can be easily done in an analogous manner when we
129  need it.
130  \ingroup hierarchy
131  \ingroup decorators
132  */
133 class IMPATOMEXPORT Residue: public Hierarchy
134 {
135 public:
137  //! Add the required attributes to the particle and create a Residue
138  static Residue setup_particle(Model *m, ParticleIndex pi,
139  ResidueType t= UNK,
140  int index=-1, int insertion_code = 32) {
141  m->add_attribute(get_residue_type_key(), pi, t.get_index());
142  m->add_attribute(get_index_key(), pi, index);
143  m->add_attribute(get_insertion_code_key(), pi, insertion_code);
144  // insertion code 32 is for space
145  if (!Hierarchy::particle_is_instance(m, pi)) {
146  Hierarchy::setup_particle(m, pi);
147  }
148  Residue ret(m, pi);
149  ret.set_residue_type(t);
150  return ret;
151  }
152 
153  static Residue setup_particle(Particle *p, ResidueType t= UNK,
154  int index=-1, int insertion_code = 32) {
155  return setup_particle(p->get_model(),
156  p->get_index(), t, index, insertion_code);
157  }
158 
159  //! Copy data from the other Residue to the particle p
161  return setup_particle(p, o.get_residue_type(),
162  o.get_index(),
163  o.get_insertion_code());
164  }
165 
166  static bool particle_is_instance(Particle *p) {
167  return p->has_attribute(get_residue_type_key())
168  && p->has_attribute(get_index_key())
169  && p->has_attribute(get_insertion_code_key())
171  }
172 
173  ResidueType get_residue_type() const {
174  return ResidueType(get_particle()->get_value(get_residue_type_key()));
175  }
176 
177  //! Update the stored ResidueType and the atom::Hierarchy::Name.
178  void set_residue_type(ResidueType t);
179 
180  bool get_is_protein() const {
181  return get_residue_type().get_index() < ADE.get_index();
182  }
183 
184  bool get_is_dna() const {
185  return get_residue_type().get_index() >= DADE.get_index()
186  && get_residue_type().get_index() <= DTHY.get_index();
187  }
188 
189  bool get_is_rna() const {
190  return get_residue_type().get_index() >= ADE.get_index()
191  && get_residue_type().get_index() < DADE.get_index();
192  }
193 
194  //! The residues index in the chain
195  IMP_DECORATOR_GET_SET(index, get_index_key(),
196  Int, Int);
197 
198  char get_insertion_code() const {
199  return char(get_particle()->get_value(get_insertion_code_key()));
200  }
201 
202  void set_insertion_code(char insertion_code) {
203  return get_particle()->set_value(get_insertion_code_key(), insertion_code);
204  }
205 
206  static IntKey get_index_key();
207 
208  static IntKey get_residue_type_key();
209 
210  static IntKey get_insertion_code_key();
211 };
212 
213 IMP_DECORATORS(Residue,Residues, Hierarchies);
214 
215 /** \relatesalso Residue
216 
217  Return the residue from the same chain with one
218  higher index, or Hierarchy().
219 
220  \note Currently, this function only works if
221  the parent of rd is the chain. This should be fixed
222  later. Ask if you need it.
223 
224  The return type is Hierarchy since the particle
225  representing the next residue might not
226  be a Residue particle.
227  */
228 IMPATOMEXPORT Hierarchy get_next_residue(Residue rd);
229 
230 /** \relatesalso Residue
231 
232  Return the residue from the same chain with one
233  lower index, or Hierarchy().
234  \see get_next_residue
235  */
236 IMPATOMEXPORT Hierarchy get_previous_residue(Residue rd);
237 
238 /** Get the residue type from the 1-letter amino acid
239  code.
240  \throw ValueException if an invalid character is passed.
241 */
242 IMPATOMEXPORT ResidueType get_residue_type(char c);
243 
244 
245 /** Get the 1-letter amino acid code from the residue type.
246 */
247 IMPATOMEXPORT char get_one_letter_code(ResidueType c);
248 
249 IMPATOM_END_NAMESPACE
250 
251 #endif /* IMPATOM_RESIDUE_H */