IMP logo
IMP Reference Guide  2.20.0
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_chain_type_key(), pi, UnknownChainType.get_index());
70  if (!Hierarchy::get_is_setup(m, pi)) {
72  }
73  }
74  static void do_setup_particle(Model *m, ParticleIndex pi, char c) {
75  do_setup_particle(m, pi, std::string(1, c));
76  }
77  static void do_setup_particle(Model *m, ParticleIndex pi, Chain o) {
78  do_setup_particle(m, pi, o.get_id());
79  }
80 
81  public:
83  IMP_DECORATOR_SETUP_1(Chain, std::string, id);
86 
87  static bool get_is_setup(Model *m, ParticleIndex pi) {
88  return m->get_has_attribute(get_id_key(), pi) &&
89  m->get_has_attribute(get_sequence_key(), pi) &&
90  m->get_has_attribute(get_sequence_offset_key(), pi) &&
91  m->get_has_attribute(get_uniprot_accession_key(), pi) &&
92  m->get_has_attribute(get_chain_type_key(), pi) &&
94  }
95 
96  //! Return the chain id
97  std::string get_id() const {
98  return get_model()->get_attribute(get_id_key(), get_particle_index());
99  }
100 
101  //! Set the chain id
102  void set_id(std::string c) {
103  get_model()->set_attribute(get_id_key(), get_particle_index(), c);
104  }
105 
106  //! Return the primary sequence (or any empty string)
107  std::string get_sequence() const {
108  return get_model()->get_attribute(get_sequence_key(), get_particle_index());
109  }
110 
111  //! Set the primary sequence, as a string
112  /** Usually the primary sequence of a chain can be uniquely deduced by
113  iterating over all child Residue decorators and querying their type.
114  However, this may not be possible in all cases (e.g. if there are gaps
115  in the sequence or parts that are not explicitly represented).
116 
117  \note The sequence set here should be consistent with that of any
118  children of this Chain. This is not currently enforced.
119  */
120  void set_sequence(std::string sequence) {
121  get_model()->set_attribute(get_sequence_key(), get_particle_index(),
122  sequence);
123  }
124 
125  //! Return the offset from the sequence numbering to residue indexes
126  int get_sequence_offset() const {
127  return get_model()->get_attribute(get_sequence_offset_key(),
129  }
130 
131  //! Set the offset from the sequence numbering to residue indexes
132  /** This offset is added to 1-based indexes into the chain primary sequence
133  (see set_sequence()) to get corresponding residue indexes. By default,
134  the offset is zero, corresponding to residues being numbered from 1.
135  For example, if residues were instead numbered starting from 0, the
136  offset would be -1.
137  */
138  void set_sequence_offset(int offset) {
139  get_model()->set_attribute(get_sequence_offset_key(), get_particle_index(),
140  offset);
141  }
142 
143  //! Return the UniProt accession for the chain's sequence
144  std::string get_uniprot_accession() const {
145  return get_model()->get_attribute(get_uniprot_accession_key(),
147  }
148 
149  //! Set the UniProt accession for the chain's sequence
150  void set_uniprot_accession(std::string accession) {
151  get_model()->set_attribute(get_uniprot_accession_key(),
152  get_particle_index(), accession);
153  }
154 
155  //! Return the chain type
157  return ChainType(get_model()->get_attribute(get_chain_type_key(),
158  get_particle_index()));
159  }
160 
161 
162  //! Set the chain type, using IMP::atom::ChainType
163  /** Usually the chain type can be uniquely deduced by
164  iterating over all child Residue decorators and querying their type.
165  However, this may not be possible in all cases.
166 
167  \note The type set here should be consistent with that of any
168  children of this Chain. This is not currently enforced.
169  One can use IMP::atom::Residue::get_is_protein() on the leaves.
170  */
172  get_model()->set_attribute(get_chain_type_key(), get_particle_index(),
173  t.get_index());
174  }
175 
176 
177  //! The key used to store the chain
178  static SparseStringKey get_id_key();
179 
180  //! The key used to store the primary sequence
181  static SparseStringKey get_sequence_key();
182 
183  //! The key used to store the sequence offset
184  static SparseIntKey get_sequence_offset_key();
185 
186  //! The key used to store the UniProt accession
187  static SparseStringKey get_uniprot_accession_key();
188 
189  //! The key used to store the polymer type
190  static SparseIntKey get_chain_type_key();
191 };
192 
193 IMP_DECORATORS(Chain, Chains, Hierarchies);
194 
195 //! Get the containing chain or Chain() if there is none
196 IMPATOMEXPORT Chain get_chain(Hierarchy h);
197 
198 //! Walk up the hierarchy to determine the chain id.
199 IMPATOMEXPORT std::string get_chain_id(Hierarchy h);
200 
201 IMPATOM_END_NAMESPACE
202 
203 #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:107
ChainType get_chain_type() const
Return the chain type.
Definition: Chain.h:156
void set_chain_type(ChainType t)
Set the chain type, using IMP::atom::ChainType.
Definition: Chain.h:171
std::string get_id() const
Return the chain id.
Definition: Chain.h:97
void set_sequence(std::string sequence)
Set the primary sequence, as a string.
Definition: Chain.h:120
Various general useful macros for IMP.
A more IMP-like version of the std::vector.
Definition: Vector.h:42
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.
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 chain id.
Definition: Chain.h:102
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:138
void set_uniprot_accession(std::string accession)
Set the UniProt accession for the chain's sequence.
Definition: Chain.h:150
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:144
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.
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:126