IMP logo
IMP Reference Guide  2.15.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-2021 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 /* Code currently assumes that all indices between ADE.get_index()
94  and DTHY.get_index() being nucleic acid */
95 //! adenine (RNA)
96 IMPATOMEXPORT extern const ResidueType ADE;
97 //! uracil (RNA)
98 IMPATOMEXPORT extern const ResidueType URA;
99 //! cytosine (RNA)
100 IMPATOMEXPORT extern const ResidueType CYT;
101 //! guanine (RNA)
102 IMPATOMEXPORT extern const ResidueType GUA;
103 //! thymine (RNA)
104 IMPATOMEXPORT extern const ResidueType THY;
105 //! adenine (DNA)
106 IMPATOMEXPORT extern const ResidueType DADE;
107 //! uracil (DNA)
108 IMPATOMEXPORT extern const ResidueType DURA;
109 //! cytosine (DNA)
110 IMPATOMEXPORT extern const ResidueType DCYT;
111 //! guanine (DNA)
112 IMPATOMEXPORT extern const ResidueType DGUA;
113 //! thymine (DNA)
114 IMPATOMEXPORT extern const ResidueType DTHY;
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 //! Phosphitidyl Choline
122 IMPATOMEXPORT extern const ResidueType POP;
123 #endif
124 /*@}*/
125 
126 
127 //! A decorator for a residue.
128 /**
129  As with the Atom, the names of residues may be expanded
130  dynamically. This can be easily done in an analogous manner when we
131  need it.
132  \ingroup hierarchy
133  \ingroup decorators
134  */
135 class IMPATOMEXPORT Residue : public Hierarchy {
136  static void do_setup_particle(Model *m, ParticleIndex pi,
137  ResidueType t = UNK, int index = -1,
138  int insertion_code = 32) {
139  m->add_attribute(get_residue_type_key(), pi, t.get_index());
140  m->add_attribute(get_index_key(), pi, index);
141  m->add_attribute(get_insertion_code_key(), pi, insertion_code);
142  // insertion code 32 is for space
143  if (!Hierarchy::get_is_setup(m, pi)) {
145  }
146  Residue ret(m, pi);
147  ret.set_residue_type(t);
148  }
149  static void do_setup_particle(Model *m, ParticleIndex pi,
150  const Residue &o) {
151  do_setup_particle(m, pi, o.get_residue_type(), o.get_index(),
152  o.get_insertion_code());
153  }
154 
155  public:
157  IMP_DECORATOR_SETUP_3(Residue, ResidueType, t, int, index, int,
158  insertion_code);
159  /** Setup the particle as a Residue with the passed type and index. */
163 
164  static bool get_is_setup(Model *m, ParticleIndex pi) {
165  return m->get_has_attribute(get_residue_type_key(), pi) &&
166  m->get_has_attribute(get_index_key(), pi) &&
167  m->get_has_attribute(get_insertion_code_key(), pi) &&
169  }
170 
171  ResidueType get_residue_type() const {
172  return ResidueType(get_model()->get_attribute(get_residue_type_key(),
173  get_particle_index()));
174  }
175 
176  //! Update the stored ResidueType and the atom::Hierarchy::Name.
177  void set_residue_type(ResidueType t);
178 
179  bool get_is_protein() const {
180  return get_residue_type().get_index() < ADE.get_index();
181  }
182 
183  bool get_is_dna() const {
184  return get_residue_type().get_index() >= DADE.get_index() &&
185  get_residue_type().get_index() <= DTHY.get_index();
186  }
187 
188  bool get_is_rna() const {
189  return get_residue_type().get_index() >= ADE.get_index() &&
190  get_residue_type().get_index() < DADE.get_index();
191  }
192 
193  //! The residues index in the chain
194  IMP_DECORATOR_GET_SET(index, get_index_key(), Int, Int);
195 
196  char get_insertion_code() const {
197  return char(get_model()->get_attribute(get_insertion_code_key(),
198  get_particle_index()));
199  }
200 
201  void set_insertion_code(char insertion_code) {
202  return get_model()->set_attribute(get_insertion_code_key(),
203  get_particle_index(), 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 //! Return the residue from the same chain with one higher index.
216 /** If no such residue exists, return Hierarchy().
217 
218  \see Residue
219  \note Currently, this function only works if
220  the parent of rd is the chain. This should be fixed
221  later. Ask if you need it.
222 
223  The return type is Hierarchy since the particle
224  representing the next residue might not
225  be a Residue particle.
226  */
227 IMPATOMEXPORT Hierarchy get_next_residue(Residue rd);
228 
229 //! Return the residue from the same chain with one lower index.
230 /** If no such residue exists, return Hierarchy().
231  \see get_next_residue
232  */
233 IMPATOMEXPORT Hierarchy get_previous_residue(Residue rd);
234 
235 //! Get the residue type from the 1-letter amino acid code.
236 /** \throw ValueException if an invalid character is passed.
237  */
238 IMPATOMEXPORT ResidueType get_residue_type(char c);
239 
240 //! Get the 1-letter amino acid code from the residue type.
241 IMPATOMEXPORT char get_one_letter_code(ResidueType c);
242 
243 
244 //! Get the mass from the residue type.
245 IMPATOMEXPORT double get_mass(ResidueType c);
246 
247 
248 IMPATOM_END_NAMESPACE
249 
250 #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:188
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:191
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:40
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
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:194
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...
Various important macros for implementing decorators.
A decorator for a residue.
Definition: Residue.h:135
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:35
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.