IMP  2.0.0
The Integrative Modeling Platform
Domain.h
Go to the documentation of this file.
1 /**
2  * \file IMP/atom/Domain.h
3  * \brief A decorator for associating an atom::Hierarchy piece with a domain
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPATOM_DOMAIN_H
9 #define IMPATOM_DOMAIN_H
10 
11 #include <IMP/atom/atom_config.h>
12 #include "Hierarchy.h"
13 #include <IMP/Decorator.h>
14 
15 IMPATOM_BEGIN_NAMESPACE
16 
17 //! A decorator to associate a particle with a part of a protein
18 /** The decorator stores the indexes of the first and last residues
19  in this domain.
20  */
21 class IMPATOMEXPORT Domain: public Hierarchy
22 {
23  struct Data {
24  Data(): begin("domain_begin"),
25  end("domain_end"){}
26  IntKey begin, end;
27  };
28  static const Data &get_data();
29 public:
30 #ifndef IMP_DOXYGEN
31  //! Create a domain covering the range [b, e)
32  static Domain setup_particle(Particle *p, Int b, Int e) {
33  p->add_attribute(get_data().begin, b);
34  p->add_attribute(get_data().end, e);
35  if (!Hierarchy::particle_is_instance(p)) {
36  Hierarchy::setup_particle(p);
37  }
38  return Domain(p);
39  }
40 #endif
41 //! Create a domain covering the range [b, e)
42  static Domain setup_particle(Particle *p, IntRange r) {
43  p->add_attribute(get_data().begin, r.first);
44  p->add_attribute(get_data().end, r.second);
45  if (!Hierarchy::particle_is_instance(p)) {
46  Hierarchy::setup_particle(p);
47  }
48  return Domain(p);
49  }
50  //! Create a domain by copying from o
52  p->add_attribute(get_data().begin, o.get_begin_index());
53  p->add_attribute(get_data().end, o.get_end_index());
54  if (!Hierarchy::particle_is_instance(p)) {
55  Hierarchy::setup_particle(p);
56  }
57  return Domain(p);
58  }
59 
60  virtual ~Domain();
61 
62  static bool particle_is_instance(Particle *p) {
63  return p->has_attribute(get_data().begin)
64  && p->has_attribute(get_data().end)
66  }
67 
68  void set_index_range(IntRange ir) {
69  IMP_USAGE_CHECK(ir.first < ir.second,
70  "Bad range passed: " << ir.first
71  << "..." << ir.second);
72  get_particle()->set_value(get_data().begin, ir.first);
73  get_particle()->set_value(get_data().end, ir.second);
74  }
75 
76  IntRange get_index_range() const {
77  return IntRange(get_begin_index(), get_end_index());
78  }
79 
80  //! Get the index of the first residue in the domain
81  Int get_begin_index() const {
82  return get_particle()->get_value(get_data().begin);
83  }
84 
85  //! Get the index of the first residue not in the domain
86  Int get_end_index() const {
87  return get_particle()->get_value(get_data().end);
88  }
89 
91 };
92 
93 IMP_DECORATORS(Domain,Domains, Hierarchies);
94 
95 IMPATOM_END_NAMESPACE
96 
97 #endif /* IMPATOM_DOMAIN_H */