IMP logo
IMP Reference Guide  2.14.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-2020 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_chain_type_key(), pi, UnknownChainType.get_index());
68  if (!Hierarchy::get_is_setup(m, pi)) {
70  }
71  }
72  static void do_setup_particle(Model *m, ParticleIndex pi, char c) {
73  do_setup_particle(m, pi, std::string(1, c));
74  }
75  static void do_setup_particle(Model *m, ParticleIndex pi, Chain o) {
76  do_setup_particle(m, pi, o.get_id());
77  }
78 
79  public:
81  IMP_DECORATOR_SETUP_1(Chain, std::string, id);
84 
85  static bool get_is_setup(Model *m, ParticleIndex pi) {
86  return m->get_has_attribute(get_id_key(), pi) &&
87  m->get_has_attribute(get_sequence_key(), pi) &&
88  m->get_has_attribute(get_chain_type_key(), pi) &&
90  }
91 
92  //! Return the chain id
93  std::string get_id() const {
94  return get_model()->get_attribute(get_id_key(), get_particle_index());
95  }
96 
97  //! Set the chain id
98  void set_id(std::string c) {
99  get_model()->set_attribute(get_id_key(), get_particle_index(), c);
100  }
101 
102  //! Return the primary sequence (or any empty string)
103  std::string get_sequence() const {
104  return get_model()->get_attribute(get_sequence_key(), get_particle_index());
105  }
106 
107  //! Set the primary sequence, as a string
108  /** Usually the primary sequence of a chain can be uniquely deduced by
109  iterating over all child Residue decorators and querying their type.
110  However, this may not be possible in all cases (e.g. if there are gaps
111  in the sequence or parts that are not explictly represented).
112 
113  \note The sequence set here should be consistent with that of any
114  children of this Chain. This is not currently enforced.
115  */
116  void set_sequence(std::string sequence) {
117  get_model()->set_attribute(get_sequence_key(), get_particle_index(),
118  sequence);
119  }
120 
121  //! Return the chain type
123  return ChainType(get_model()->get_attribute(get_chain_type_key(),
124  get_particle_index()));
125  }
126 
127 
128  //! Set the chain type, using IMP::atom::ChainType
129  /** Usually the chain type can be uniquely deduced by
130  iterating over all child Residue decorators and querying their type.
131  However, this may not be possible in all cases.
132 
133  \note The type set here should be consistent with that of any
134  children of this Chain. This is not currently enforced.
135  One can use IMP::atom::Residue::get_is_protein() on the leaves.
136  */
138  get_model()->set_attribute(get_chain_type_key(), get_particle_index(),
139  t.get_index());
140  }
141 
142 
143  //! The key used to store the chain
144  static StringKey get_id_key();
145 
146  //! The key used to store the primary sequence
147  static StringKey get_sequence_key();
148 
149  //! The key used to store the polymer type
150  static IntKey get_chain_type_key();
151 };
152 
153 IMP_DECORATORS(Chain, Chains, Hierarchies);
154 
155 //! Get the containing chain or Chain() if there is none
156 IMPATOMEXPORT Chain get_chain(Hierarchy h);
157 
158 //! Walk up the hierarchy to determine the chain id.
159 IMPATOMEXPORT std::string get_chain_id(Hierarchy h);
160 
161 IMPATOM_END_NAMESPACE
162 
163 #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:188
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:191
std::string get_sequence() const
Return the primary sequence (or any empty string)
Definition: Chain.h:103
ChainType get_chain_type() const
Return the chain type.
Definition: Chain.h:122
void set_chain_type(ChainType t)
Set the chain type, using IMP::atom::ChainType.
Definition: Chain.h:137
std::string get_id() const
Return the chain id.
Definition: Chain.h:93
void set_sequence(std::string sequence)
Set the primary sequence, as a string.
Definition: Chain.h:116
Various general useful macros for IMP.
A more IMP-like version of the std::vector.
Definition: Vector.h:39
const ChainType UnknownChainType
Unknown chain type.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
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 atribute with the specied key and initial value
The standard decorator for manipulating molecular structures.
void set_id(std::string c)
Set the chain id.
Definition: Chain.h:98
void set_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
set the value of particle attribute with the specified key
A base class for Keys.
Definition: Key.h:44
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)
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.