IMP  2.0.1
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-2013 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 
16 IMPATOM_BEGIN_NAMESPACE
17 
18 //! Store info for a chain of a protein
19 /** \see Hierarchy
20  */
21 class IMPATOMEXPORT Chain: public Hierarchy
22 {
24 public:
25  static Chain setup_particle(Model *m, ParticleIndex pi, char id) {
26  m->add_attribute(get_id_key(), pi, id);
27  if (!Hierarchy::particle_is_instance(m, pi)) {
28  Hierarchy::setup_particle(m, pi);
29  }
30  return Chain(m, pi);
31  }
32  static Chain setup_particle(Particle *p, char id) {
33  return setup_particle(p->get_model(),
34  p->get_index(), id);
35  }
36 
37  static Chain setup_particle(Particle *p, Chain o) {
38  p->add_attribute(get_id_key(), o.get_id());
39  if (!Hierarchy::particle_is_instance(p)) {
40  Hierarchy::setup_particle(p);
41  }
42  return Chain(p);
43  }
44 
45 
46  static bool particle_is_instance(Particle *p) {
47  return p->has_attribute(get_id_key())
49  }
50 
51  //! Return the chain id
52  char get_id() const {
53  return static_cast<char>(get_particle()->get_value(get_id_key()));
54  }
55 
56  //! Set the chain id
57  void set_id(char c) {
58  get_particle()->set_value(get_id_key(), c);
59  }
60 
61  //! The key used to store the chain
62  static IntKey get_id_key();
63 };
64 
65 IMP_DECORATORS(Chain,Chains, Hierarchies);
66 
67 /** Get the containing chain or Chain() if there is none*/
68 IMPATOMEXPORT
69 Chain get_chain(Hierarchy h);
70 
71 IMPATOM_END_NAMESPACE
72 
73 #endif /* IMPATOM_CHAIN_H */