IMP logo
IMP Reference Guide  develop.7400db2aee,2024/11/23
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 
17 IMPATOM_BEGIN_NAMESPACE
18 
19 typedef 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
37 IMPATOMEXPORT extern const ChainType UnknownChainType;
38 //! Polypeptide(D)
39 IMPATOMEXPORT extern const ChainType DPolypeptide;
40 //! Polypeptide(L)
41 IMPATOMEXPORT extern const ChainType LPolypeptide;
42 //! DNA
43 IMPATOMEXPORT extern const ChainType Polydeoxyribonucleotide;
44 //! RNA
45 IMPATOMEXPORT extern const ChainType Polyribonucleotide;
46 //! Polysaccharide(D)
47 IMPATOMEXPORT extern const ChainType DPolysaccharide;
48 //! Polysaccharide(L)
49 IMPATOMEXPORT extern const ChainType LPolysaccharide;
50 //! Shorthand for IMP::atom::LPolypeptide
51 IMPATOMEXPORT extern const ChainType Protein;
52 //! Shorthand for IMP::atom::Polydeoxyribonucleotide
53 IMPATOMEXPORT extern const ChainType DNA;
54 //! Shorthand for IMP::atom::Polyribonucleotide
55 IMPATOMEXPORT extern const ChainType RNA;
56 
57 
58 //! Store info for a chain of a protein
59 /** \see Hierarchy
60  */
61 class 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:
84  IMP_DECORATOR_SETUP_1(Chain, std::string, id);
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
140  int get_sequence_offset() const {
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) {
153  get_model()->set_attribute(get_sequence_offset_key(), get_particle_index(),
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
171  return ChainType(get_model()->get_attribute(get_chain_type_key(),
172  get_particle_index()));
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  */
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
192  static SparseStringKey get_id_key();
193 
194  //! The key used to store the mmCIF asym ID
195  static SparseStringKey get_label_asym_id_key();
196 
197  //! The key used to store the primary sequence
198  static SparseStringKey get_sequence_key();
199 
200  //! The key used to store the sequence offset
201  static SparseIntKey get_sequence_offset_key();
202 
203  //! The key used to store the UniProt accession
204  static SparseStringKey get_uniprot_accession_key();
205 
206  //! The key used to store the polymer type
207  static SparseIntKey get_chain_type_key();
208 };
209 
210 IMP_DECORATORS(Chain, Chains, Hierarchies);
211 
212 //! Get the containing chain or Chain() if there is none
213 IMPATOMEXPORT Chain get_chain(Hierarchy h);
214 
215 //! Walk up the hierarchy to determine the chain id.
216 IMPATOMEXPORT std::string get_chain_id(Hierarchy h);
217 
218 IMPATOM_END_NAMESPACE
219 
220 #endif /* IMPATOM_CHAIN_H */
The base class for decorators.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:211
Chain get_chain(Hierarchy h)
Get the containing chain or Chain() if there is none.
Basic types used by IMP.
const ChainType LPolysaccharide
Polysaccharide(L)
const ChainType Protein
Shorthand for IMP::atom::LPolypeptide.
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
Model * get_model() const
Returns the Model containing the particle.
Definition: Decorator.h:214
std::string get_sequence() const
Return the primary sequence (or any empty string)
Definition: Chain.h:121
ChainType get_chain_type() const
Return the chain type.
Definition: Chain.h:170
void set_chain_type(ChainType t)
Set the chain type, using IMP::atom::ChainType.
Definition: Chain.h:185
std::string get_id() const
Return the (author-provided) chain id.
Definition: Chain.h:99
void set_sequence(std::string sequence)
Set the primary sequence, as a string.
Definition: Chain.h:134
Various general useful macros for IMP.
A more IMP-like version of the std::vector.
Definition: Vector.h:50
const ChainType UnknownChainType
Unknown chain type.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
Decorator for helping deal with a hierarchy of molecules.
const ChainType DPolypeptide
Polypeptide(D)
#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.
std::string get_label_asym_id() const
Return the mmCIF asym ID.
Definition: Chain.h:109
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
add particle attribute with the specified key and initial value
The standard decorator for manipulating molecular structures.
void set_id(std::string c)
Set the (author-provided) chain id.
Definition: Chain.h:104
void set_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
set the value of particle attribute with the specified key
void set_sequence_offset(int offset)
Set the offset from the sequence numbering to residue indexes.
Definition: Chain.h:152
void set_uniprot_accession(std::string accession)
Set the UniProt accession for the chain's sequence.
Definition: Chain.h:164
A base class for Keys.
Definition: Key.h:45
The type for a chain.
const ChainType DNA
Shorthand for IMP::atom::Polydeoxyribonucleotide.
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)
const ChainType RNA
Shorthand for IMP::atom::Polyribonucleotide.
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
const ChainType DPolysaccharide
Polysaccharide(D)
std::string get_uniprot_accession() const
Return the UniProt accession for the chain's sequence.
Definition: Chain.h:158
Store info for a chain of a protein.
Definition: Chain.h:61
bool get_has_attribute(TypeKey attribute_key, ParticleIndex particle) const
return true if particle has attribute with the specified key
const ChainType LPolypeptide
Polypeptide(L)
const ChainType Polydeoxyribonucleotide
DNA.
void set_label_asym_id(std::string c)
Set the mmCIF asym ID.
Definition: Chain.h:115
std::string get_chain_id(Hierarchy h)
Walk up the hierarchy to determine the chain id.
Type get_attribute(TypeKey attribute_key, ParticleIndex particle)
get the value of the particle attribute with the specified key
const ChainType Polyribonucleotide
RNA.
int get_sequence_offset() const
Return the offset from the sequence numbering to residue indexes.
Definition: Chain.h:140