IMP logo
IMP Reference Guide  2.18.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-2022 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 typedef Key<IMP_RESIDUE_TYPE_INDEX> ResidueType;
28 
29 /** \class IMP::atom::ResidueType
30  \brief The type for a residue.
31 
32  A given residue is either a Residue::LIGAND, Residue::AMINOACID,
33  or Residue::NUCLEICACID.
34 
35  The standard residue types are provided with names like
36  IMP::atom::GLY. New types can be added simply by creating an
37  instance of ResidueType("my_residue_name"). All user-added
38  residues are assumed to be ligands.
39 
40  \see Residue
41 */
42 
43 //! Unknown residue
44 IMPATOMEXPORT extern const ResidueType UNK;
45 /** \see ResidueType
46  glycine G*/
47 IMPATOMEXPORT extern const ResidueType GLY;
48 #ifndef IMP_DOXYGEN
49 /* Code currently assumes that all indices between GLY.get_index()
50  and TRP.get_index() being amino acids */
51 //! alanine A
52 IMPATOMEXPORT extern const ResidueType ALA;
53 //! valine V
54 IMPATOMEXPORT extern const ResidueType VAL;
55 //! leucine L
56 IMPATOMEXPORT extern const ResidueType LEU;
57 //! isoleucine I
58 IMPATOMEXPORT extern const ResidueType ILE;
59 //! serine S
60 IMPATOMEXPORT extern const ResidueType SER;
61 //! threonine T
62 IMPATOMEXPORT extern const ResidueType THR;
63 //! cysteine C
64 IMPATOMEXPORT extern const ResidueType CYS;
65 //! methionine M
66 IMPATOMEXPORT extern const ResidueType MET;
67 //! proline P
68 IMPATOMEXPORT extern const ResidueType PRO;
69 //! aspartic acid D
70 IMPATOMEXPORT extern const ResidueType ASP;
71 //! asparagine N
72 IMPATOMEXPORT extern const ResidueType ASN;
73 //! glutamine Q
74 IMPATOMEXPORT extern const ResidueType GLU;
75 //! glutamic acid E
76 IMPATOMEXPORT extern const ResidueType GLN;
77 //! lysine K
78 IMPATOMEXPORT extern const ResidueType LYS;
79 //! arginine N
80 IMPATOMEXPORT extern const ResidueType ARG;
81 //! histidine H
82 IMPATOMEXPORT extern const ResidueType HIS;
83 //! phenylalanine F
84 IMPATOMEXPORT extern const ResidueType PHE;
85 //! tyrosine Y
86 IMPATOMEXPORT extern const ResidueType TYR;
87 //! tryptophan W
88 IMPATOMEXPORT extern const ResidueType TRP;
89 //! ACE
90 IMPATOMEXPORT extern const ResidueType ACE;
91 //! end group
92 IMPATOMEXPORT extern const ResidueType NH2;
93 //! Selenomethionine
94 IMPATOMEXPORT extern const ResidueType MSE;
95 /* Code currently assumes that all indices between ADE.get_index()
96  and DTHY.get_index() being nucleic acid */
97 //! adenine (RNA)
98 IMPATOMEXPORT extern const ResidueType ADE;
99 //! uracil (RNA)
100 IMPATOMEXPORT extern const ResidueType URA;
101 //! cytosine (RNA)
102 IMPATOMEXPORT extern const ResidueType CYT;
103 //! guanine (RNA)
104 IMPATOMEXPORT extern const ResidueType GUA;
105 //! thymine (RNA)
106 IMPATOMEXPORT extern const ResidueType THY;
107 //! adenine (DNA)
108 IMPATOMEXPORT extern const ResidueType DADE;
109 //! uracil (DNA)
110 IMPATOMEXPORT extern const ResidueType DURA;
111 //! cytosine (DNA)
112 IMPATOMEXPORT extern const ResidueType DCYT;
113 //! guanine (DNA)
114 IMPATOMEXPORT extern const ResidueType DGUA;
115 //! thymine (DNA)
116 IMPATOMEXPORT extern const ResidueType DTHY;
117 // All further residues (including user-added residues) are ligands
118 
119 //! water molecule
120 IMPATOMEXPORT extern const ResidueType HOH;
121 //! heme
122 IMPATOMEXPORT extern const ResidueType HEME;
123 //! Phosphitidyl Choline
124 IMPATOMEXPORT extern const ResidueType POP;
125 #endif
126 /*@}*/
127 
128 
129 //! A decorator for a residue.
130 /**
131  As with the Atom, the names of residues may be expanded
132  dynamically. This can be easily done in an analogous manner when we
133  need it.
134  \ingroup hierarchy
135  \ingroup decorators
136  */
137 class IMPATOMEXPORT Residue : public Hierarchy {
138  static void do_setup_particle(Model *m, ParticleIndex pi,
139  ResidueType t = UNK, int index = -1,
140  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::get_is_setup(m, pi)) {
147  }
148  Residue ret(m, pi);
149  ret.set_residue_type(t);
150  }
151  static void do_setup_particle(Model *m, ParticleIndex pi,
152  const Residue &o) {
153  do_setup_particle(m, pi, o.get_residue_type(), o.get_index(),
154  o.get_insertion_code());
155  }
156 
157  public:
159  IMP_DECORATOR_SETUP_3(Residue, ResidueType, t, int, index, int,
160  insertion_code);
161  /** Setup the particle as a Residue with the passed type and index. */
165 
166  static bool get_is_setup(Model *m, ParticleIndex pi) {
167  return m->get_has_attribute(get_residue_type_key(), pi) &&
168  m->get_has_attribute(get_index_key(), pi) &&
169  m->get_has_attribute(get_insertion_code_key(), pi) &&
171  }
172 
173  ResidueType get_residue_type() const {
174  return ResidueType(get_model()->get_attribute(get_residue_type_key(),
175  get_particle_index()));
176  }
177 
178  //! Update the stored ResidueType and the atom::Hierarchy::Name.
179  void set_residue_type(ResidueType t);
180 
181  bool get_is_protein() const {
182  return get_residue_type().get_index() < ADE.get_index();
183  }
184 
185  bool get_is_dna() const {
186  return get_residue_type().get_index() >= DADE.get_index() &&
187  get_residue_type().get_index() <= DTHY.get_index();
188  }
189 
190  bool get_is_rna() const {
191  return get_residue_type().get_index() >= ADE.get_index() &&
192  get_residue_type().get_index() < DADE.get_index();
193  }
194 
195  //! The residues index in the chain
196  IMP_DECORATOR_GET_SET(index, get_index_key(), Int, Int);
197 
198  char get_insertion_code() const {
199  return char(get_model()->get_attribute(get_insertion_code_key(),
200  get_particle_index()));
201  }
202 
203  void set_insertion_code(char insertion_code) {
204  return get_model()->set_attribute(get_insertion_code_key(),
205  get_particle_index(), insertion_code);
206  }
207 
208  static IntKey get_index_key();
209 
210  static IntKey get_residue_type_key();
211 
212  static IntKey get_insertion_code_key();
213 
214  //! The key used to signal to the Model that residue/atom type has changed
215  static TriggerKey get_type_changed_key();
216 };
217 
218 IMP_DECORATORS(Residue, Residues, Hierarchies);
219 
220 //! Return the residue from the same chain with one higher index.
221 /** If no such residue exists, return Hierarchy().
222 
223  \see Residue
224 
225  The return type is Hierarchy since the particle
226  representing the next residue might not
227  be a Residue particle.
228  */
229 IMPATOMEXPORT Hierarchy get_next_residue(Residue rd);
230 
231 //! Return the residue from the same chain with one lower index.
232 /** If no such residue exists, return Hierarchy().
233  \see get_next_residue
234  */
235 IMPATOMEXPORT Hierarchy get_previous_residue(Residue rd);
236 
237 //! Get the residue type from the 1-letter amino acid code.
238 /** \throw ValueException if an invalid character is passed.
239  */
240 IMPATOMEXPORT ResidueType get_residue_type(char c);
241 
242 //! Get the 1-letter amino acid code from the residue type.
243 IMPATOMEXPORT char get_one_letter_code(ResidueType c);
244 
245 
246 //! Get the mass from the residue type.
247 IMPATOMEXPORT double get_mass(ResidueType c);
248 
249 
250 IMPATOM_END_NAMESPACE
251 
252 #endif /* IMPATOM_RESIDUE_H */
The base class for decorators.
#define IMP_DECORATOR_GET_SET(name, AttributeKey, Type, ReturnType)
Define methods for getting and setting a particular simple field.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:190
Basic types used by IMP.
double get_mass(ResidueType c)
Get the mass from the residue type.
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
Model * get_model() const
Returns the Model containing the particle.
Definition: Decorator.h:193
Storage of a model, its restraints, constraints and particles.
char get_one_letter_code(ResidueType c)
Get the 1-letter amino acid code from the residue type.
A more IMP-like version of the std::vector.
Definition: Vector.h:42
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:73
Decorator for helping deal with a hierarchy of molecules.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
static Hierarchy setup_particle(Model *m, ParticleIndex pi, ParticleIndexesAdaptor children=ParticleIndexesAdaptor())
Create a Hierarchy of level t by adding the needed attributes.
Int get_index() const
The residues index in the chain.
Definition: Residue.h:196
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
add particle atribute with the specied key and initial value
The standard decorator for manipulating molecular structures.
const ResidueType UNK
Unknown residue.
The type for a residue.
Hierarchy get_previous_residue(Residue rd)
Return the residue from the same chain with one lower index.
#define IMP_DECORATOR_SETUP_2(Name, FirstArgumentType, first_argument_name,SecondArgumentType, second_argument_name)
void set_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
set the value of particle attribute with the specified key
const ResidueType GLY
Store the chain ID.
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
Macros for maintaining molecular hierarchies.
A decorator for a residue.
Definition: Residue.h:137
static bool get_is_setup(Model *m, ParticleIndex p)
Check if the particle has the needed attributes for a cast to succeed.
#define IMP_DECORATOR_METHODS(Name, Parent)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
int Int
Basic integer value.
Definition: types.h:34
bool get_has_attribute(TypeKey attribute_key, ParticleIndex particle) const
return true if particle has attribute with the specified key
#define IMP_DECORATOR_SETUP_3(Name, FirstArgumentType, first_argument_name,SecondArgumentType, second_argument_name,ThirdArgumentType, third_argument_name)
void set_residue_type(ResidueType t)
Update the stored ResidueType and the atom::Hierarchy::Name.
Hierarchy get_next_residue(Residue rd)
Return the residue from the same chain with one higher index.
ResidueType get_residue_type(char c)
Get the residue type from the 1-letter amino acid code.