IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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
21IMPATOM_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*/
26typedef 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
44IMPATOMEXPORT extern const ResidueType UNK;
45/** \see ResidueType
46 glycine G*/
47IMPATOMEXPORT 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
52IMPATOMEXPORT extern const ResidueType ALA;
53//! valine V
54IMPATOMEXPORT extern const ResidueType VAL;
55//! leucine L
56IMPATOMEXPORT extern const ResidueType LEU;
57//! isoleucine I
58IMPATOMEXPORT extern const ResidueType ILE;
59//! serine S
60IMPATOMEXPORT extern const ResidueType SER;
61//! threonine T
62IMPATOMEXPORT extern const ResidueType THR;
63//! cysteine C
64IMPATOMEXPORT extern const ResidueType CYS;
65//! methionine M
66IMPATOMEXPORT extern const ResidueType MET;
67//! proline P
68IMPATOMEXPORT extern const ResidueType PRO;
69//! aspartic acid D
70IMPATOMEXPORT extern const ResidueType ASP;
71//! asparagine N
72IMPATOMEXPORT extern const ResidueType ASN;
73//! glutamine Q
74IMPATOMEXPORT extern const ResidueType GLU;
75//! glutamic acid E
76IMPATOMEXPORT extern const ResidueType GLN;
77//! lysine K
78IMPATOMEXPORT extern const ResidueType LYS;
79//! arginine N
80IMPATOMEXPORT extern const ResidueType ARG;
81//! histidine H
82IMPATOMEXPORT extern const ResidueType HIS;
83//! phenylalanine F
84IMPATOMEXPORT extern const ResidueType PHE;
85//! tyrosine Y
86IMPATOMEXPORT extern const ResidueType TYR;
87//! tryptophan W
88IMPATOMEXPORT extern const ResidueType TRP;
89//! ACE
90IMPATOMEXPORT extern const ResidueType ACE;
91//! end group
92IMPATOMEXPORT extern const ResidueType NH2;
93//! Selenomethionine
94IMPATOMEXPORT 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)
98IMPATOMEXPORT extern const ResidueType ADE;
99//! uracil (RNA)
100IMPATOMEXPORT extern const ResidueType URA;
101//! cytosine (RNA)
102IMPATOMEXPORT extern const ResidueType CYT;
103//! guanine (RNA)
104IMPATOMEXPORT extern const ResidueType GUA;
105//! thymine (RNA)
106IMPATOMEXPORT extern const ResidueType THY;
107//! adenine (DNA)
108IMPATOMEXPORT extern const ResidueType DADE;
109//! uracil (DNA)
110IMPATOMEXPORT extern const ResidueType DURA;
111//! cytosine (DNA)
112IMPATOMEXPORT extern const ResidueType DCYT;
113//! guanine (DNA)
114IMPATOMEXPORT extern const ResidueType DGUA;
115//! thymine (DNA)
116IMPATOMEXPORT extern const ResidueType DTHY;
117// All further residues (including user-added residues) are ligands
118
119//! water molecule
120IMPATOMEXPORT extern const ResidueType HOH;
121//! heme
122IMPATOMEXPORT extern const ResidueType HEME;
123//! Phosphitidyl Choline
124IMPATOMEXPORT 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 */
137class 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:
158 IMP_DECORATOR_METHODS(Residue, Hierarchy);
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. */
162 IMP_DECORATOR_SETUP_2(Residue, ResidueType, t, int, index);
163 IMP_DECORATOR_SETUP_1(Residue, ResidueType, t);
164 IMP_DECORATOR_SETUP_1(Residue, Residue, other);
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(),
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
216};
217
218IMP_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 */
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 */
236
237//! Get the residue type from the 1-letter amino acid code.
238/** \throw ValueException if an invalid character is passed.
239 */
240IMPATOMEXPORT ResidueType get_residue_type(char c);
241
242//! Get the 1-letter amino acid code from the residue type.
243IMPATOMEXPORT char get_one_letter_code(ResidueType c);
244
245
246//! Get the mass from the residue type.
247IMPATOMEXPORT double get_mass(ResidueType c);
248
249
250IMPATOM_END_NAMESPACE
251
252#endif /* IMPATOM_RESIDUE_H */
Store the chain ID.
The base class for decorators.
Storage of a model, its restraints, constraints and particles.
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
Decorator for helping deal with a hierarchy of molecules.
Macros for maintaining molecular hierarchies.
Basic types used by IMP.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition Decorator.h:211
Model * get_model() const
Returns the Model containing the particle.
Definition Decorator.h:214
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
The standard decorator for manipulating molecular structures.
static bool get_is_setup(Model *m, ParticleIndex p)
Check if the particle has the needed attributes for a cast to succeed.
static Hierarchy setup_particle(Model *m, ParticleIndex pi, ParticleIndexesAdaptor children=ParticleIndexesAdaptor())
Create a Hierarchy of level t by adding the needed attributes.
The type for a residue.
A decorator for a residue.
Definition Residue.h:137
static TriggerKey get_type_changed_key()
The key used to signal to the Model that residue/atom type has changed.
void set_residue_type(ResidueType t)
Update the stored ResidueType and the atom::Hierarchy::Name.
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_DECORATOR_GET_SET(name, AttributeKey, Type, ReturnType)
Define methods for getting and setting a particular simple field.
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
#define IMP_DECORATOR_SETUP_2(Name, FirstArgumentType, first_argument_name, SecondArgumentType, second_argument_name)
#define IMP_DECORATOR_METHODS(Name, Parent)
#define IMP_DECORATOR_SETUP_3(Name, FirstArgumentType, first_argument_name, SecondArgumentType, second_argument_name, ThirdArgumentType, third_argument_name)
Hierarchy get_next_residue(Residue rd)
Return the residue from the same chain with one higher index.
IMP::Vector< ResidueType > ResidueTypes
Definition Residue.h:27
char get_one_letter_code(ResidueType c)
Get the 1-letter amino acid code from the residue type.
double get_mass(ResidueType c)
Get the mass from the residue type.
const ResidueType UNK
Unknown residue.
Hierarchy get_previous_residue(Residue rd)
Return the residue from the same chain with one lower index.
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
int Int
Basic integer value.
Definition types.h:34
Key< 1 > IntKey
The type used to identify int attributes in the Particles.
Definition base_types.h:36
Key< 11 > TriggerKey
The type used to identify changed model properties.
Definition base_types.h:82
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.