IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
Chain.h
Go to the documentation of this file.
1/**
2 * \file IMP/atom/Chain.h
3 * \brief Store the chain ID
4 *
5 * Copyright 2007-2022 IMP Inventors. All rights reserved.
6 */
7
8#ifndef IMPATOM_CHAIN_H
9#define IMPATOM_CHAIN_H
10
11#include <IMP/atom/atom_config.h>
12#include "Hierarchy.h"
13#include <IMP/macros.h>
14#include <IMP/Decorator.h>
15#include <IMP/base_types.h>
16
17IMPATOM_BEGIN_NAMESPACE
18
19typedef Key<IMP_CHAIN_TYPE_INDEX> ChainType;
21
22/** \class IMP::atom::ChainType
23 \brief The type for a chain.
24
25 A given chain can be a Protein, DNA, or RNA polymer (or a few other much
26 more rare types).
27
28 The standard chain types are provided with names like IMP::atom::Protein.
29
30 \see Chain
31*/
32
33// To add a new chain type, add both here and in src/Chain.cpp.
34// RMF may also need to be updated to understand the new type.
35
36//! Unknown chain type
37IMPATOMEXPORT extern const ChainType UnknownChainType;
38//! Polypeptide(D)
39IMPATOMEXPORT extern const ChainType DPolypeptide;
40//! Polypeptide(L)
41IMPATOMEXPORT extern const ChainType LPolypeptide;
42//! DNA
43IMPATOMEXPORT extern const ChainType Polydeoxyribonucleotide;
44//! RNA
45IMPATOMEXPORT extern const ChainType Polyribonucleotide;
46//! Polysaccharide(D)
47IMPATOMEXPORT extern const ChainType DPolysaccharide;
48//! Polysaccharide(L)
49IMPATOMEXPORT extern const ChainType LPolysaccharide;
50//! Shorthand for IMP::atom::LPolypeptide
51IMPATOMEXPORT extern const ChainType Protein;
52//! Shorthand for IMP::atom::Polydeoxyribonucleotide
53IMPATOMEXPORT extern const ChainType DNA;
54//! Shorthand for IMP::atom::Polyribonucleotide
55IMPATOMEXPORT extern const ChainType RNA;
56
57
58//! Store info for a chain of a protein
59/** \see Hierarchy
60 */
61class IMPATOMEXPORT Chain : public Hierarchy {
62
63 static void do_setup_particle(Model *m, ParticleIndex pi,
64 std::string id) {
65 m->add_attribute(get_id_key(), pi, id);
66 m->add_attribute(get_sequence_key(), pi, "");
67 m->add_attribute(get_sequence_offset_key(), pi, 0);
68 m->add_attribute(get_uniprot_accession_key(), pi, "");
69 m->add_attribute(get_label_asym_id_key(), pi, "");
70 m->add_attribute(get_chain_type_key(), pi, UnknownChainType.get_index());
71 if (!Hierarchy::get_is_setup(m, pi)) {
73 }
74 }
75 static void do_setup_particle(Model *m, ParticleIndex pi, char c) {
76 do_setup_particle(m, pi, std::string(1, c));
77 }
78 static void do_setup_particle(Model *m, ParticleIndex pi, Chain o) {
79 do_setup_particle(m, pi, o.get_id());
80 }
81
82 public:
83 IMP_DECORATOR_METHODS(Chain, Hierarchy);
84 IMP_DECORATOR_SETUP_1(Chain, std::string, id);
85 IMP_DECORATOR_SETUP_1(Chain, char, id);
86 IMP_DECORATOR_SETUP_1(Chain, Chain, other);
87
88 static bool get_is_setup(Model *m, ParticleIndex pi) {
89 return m->get_has_attribute(get_id_key(), pi) &&
90 m->get_has_attribute(get_sequence_key(), pi) &&
91 m->get_has_attribute(get_sequence_offset_key(), pi) &&
92 m->get_has_attribute(get_uniprot_accession_key(), pi) &&
93 m->get_has_attribute(get_chain_type_key(), pi) &&
94 m->get_has_attribute(get_label_asym_id_key(), pi) &&
96 }
97
98 //! Return the (author-provided) chain id
99 std::string get_id() const {
100 return get_model()->get_attribute(get_id_key(), get_particle_index());
101 }
102
103 //! Set the (author-provided) chain id
104 void set_id(std::string c) {
105 get_model()->set_attribute(get_id_key(), get_particle_index(), c);
106 }
107
108 //! Return the mmCIF asym ID
109 std::string get_label_asym_id() const {
110 return get_model()->get_attribute(get_label_asym_id_key(),
112 }
113
114 //! Set the mmCIF asym ID
115 void set_label_asym_id(std::string c) {
116 get_model()->set_attribute(get_label_asym_id_key(),
117 get_particle_index(), c);
118 }
119
120 //! Return the primary sequence (or any empty string)
121 std::string get_sequence() const {
122 return get_model()->get_attribute(get_sequence_key(), get_particle_index());
123 }
124
125 //! Set the primary sequence, as a string
126 /** Usually the primary sequence of a chain can be uniquely deduced by
127 iterating over all child Residue decorators and querying their type.
128 However, this may not be possible in all cases (e.g. if there are gaps
129 in the sequence or parts that are not explicitly represented).
130
131 \note The sequence set here should be consistent with that of any
132 children of this Chain. This is not currently enforced.
133 */
134 void set_sequence(std::string sequence) {
135 get_model()->set_attribute(get_sequence_key(), get_particle_index(),
136 sequence);
137 }
138
139 //! Return the offset from the sequence numbering to residue indexes
141 return get_model()->get_attribute(get_sequence_offset_key(),
143 }
144
145 //! Set the offset from the sequence numbering to residue indexes
146 /** This offset is added to 1-based indexes into the chain primary sequence
147 (see set_sequence()) to get corresponding residue indexes. By default,
148 the offset is zero, corresponding to residues being numbered from 1.
149 For example, if residues were instead numbered starting from 0, the
150 offset would be -1.
151 */
152 void set_sequence_offset(int offset) {
154 offset);
155 }
156
157 //! Return the UniProt accession for the chain's sequence
158 std::string get_uniprot_accession() const {
159 return get_model()->get_attribute(get_uniprot_accession_key(),
161 }
162
163 //! Set the UniProt accession for the chain's sequence
164 void set_uniprot_accession(std::string accession) {
165 get_model()->set_attribute(get_uniprot_accession_key(),
166 get_particle_index(), accession);
167 }
168
169 //! Return the chain type
170 ChainType get_chain_type() const {
171 return ChainType(get_model()->get_attribute(get_chain_type_key(),
173 }
174
175
176 //! Set the chain type, using IMP::atom::ChainType
177 /** Usually the chain type can be uniquely deduced by
178 iterating over all child Residue decorators and querying their type.
179 However, this may not be possible in all cases.
180
181 \note The type set here should be consistent with that of any
182 children of this Chain. This is not currently enforced.
183 One can use IMP::atom::Residue::get_is_protein() on the leaves.
184 */
185 void set_chain_type(ChainType t) {
186 get_model()->set_attribute(get_chain_type_key(), get_particle_index(),
187 t.get_index());
188 }
189
190
191 //! The key used to store the author-provided chain ID
193
194 //! The key used to store the mmCIF asym ID
196
197 //! The key used to store the primary sequence
199
200 //! The key used to store the sequence offset
202
203 //! The key used to store the UniProt accession
205
206 //! The key used to store the polymer type
208};
209
210IMP_DECORATORS(Chain, Chains, Hierarchies);
211
212//! Get the containing chain or Chain() if there is none
213IMPATOMEXPORT Chain get_chain(Hierarchy h);
214
215//! Walk up the hierarchy to determine the chain id.
216IMPATOMEXPORT std::string get_chain_id(Hierarchy h);
217
218IMPATOM_END_NAMESPACE
219
220#endif /* IMPATOM_CHAIN_H */
The base class for decorators.
Decorator for helping deal with a hierarchy of molecules.
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 type for a chain.
Store info for a chain of a protein.
Definition Chain.h:61
static SparseStringKey get_uniprot_accession_key()
The key used to store the UniProt accession.
void set_sequence_offset(int offset)
Set the offset from the sequence numbering to residue indexes.
Definition Chain.h:152
static SparseStringKey get_label_asym_id_key()
The key used to store the mmCIF asym ID.
static SparseIntKey get_chain_type_key()
The key used to store the polymer type.
ChainType get_chain_type() const
Return the chain type.
Definition Chain.h:170
void set_sequence(std::string sequence)
Set the primary sequence, as a string.
Definition Chain.h:134
std::string get_label_asym_id() const
Return the mmCIF asym ID.
Definition Chain.h:109
void set_id(std::string c)
Set the (author-provided) chain id.
Definition Chain.h:104
std::string get_id() const
Return the (author-provided) chain id.
Definition Chain.h:99
static SparseIntKey get_sequence_offset_key()
The key used to store the sequence offset.
void set_chain_type(ChainType t)
Set the chain type, using IMP::atom::ChainType.
Definition Chain.h:185
static SparseStringKey get_id_key()
The key used to store the author-provided chain ID.
std::string get_sequence() const
Return the primary sequence (or any empty string).
Definition Chain.h:121
void set_label_asym_id(std::string c)
Set the mmCIF asym ID.
Definition Chain.h:115
std::string get_uniprot_accession() const
Return the UniProt accession for the chain's sequence.
Definition Chain.h:158
int get_sequence_offset() const
Return the offset from the sequence numbering to residue indexes.
Definition Chain.h:140
void set_uniprot_accession(std::string accession)
Set the UniProt accession for the chain's sequence.
Definition Chain.h:164
static SparseStringKey get_sequence_key()
The key used to store the primary sequence.
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.
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
#define IMP_DECORATOR_METHODS(Name, Parent)
Various general useful macros for IMP.
Chain get_chain(Hierarchy h)
Get the containing chain or Chain() if there is none.
const ChainType UnknownChainType
Unknown chain type.
IMP::Vector< ChainType > ChainTypes
Definition Chain.h:20
std::string get_chain_id(Hierarchy h)
Walk up the hierarchy to determine the chain id.
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
Key< 12 > SparseStringKey
The type used to identify sparse string attributes in the Particles.
Definition base_types.h:86
Key< 13 > SparseIntKey
The type used to identify sparse int attributes in the Particles.
Definition base_types.h:90
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.