IMP  2.2.1
The Integrative Modeling Platform
Subset.h
Go to the documentation of this file.
1 /**
2  * \file IMP/domino/Subset.h
3  * \brief A beyesian infererence-based sampler.
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPDOMINO_SUBSET_H
10 #define IMPDOMINO_SUBSET_H
11 
12 #include <IMP/domino/domino_config.h>
13 #include "IMP/macros.h"
15 #include <IMP/base/Pointer.h>
16 #include <IMP/base/Value.h>
17 #include <IMP/base/ConstVector.h>
18 #include <algorithm>
19 #include <IMP/base/hash.h>
20 
21 IMPDOMINO_BEGIN_NAMESPACE
22 
23 //! Represent a subset of the particles being optimized.
24 /** Domino acts by dividing the particles being changed
25  into subsets and optimizing the subsets independently.
26  Each subset is represented using a Subset class. These
27  classes, like the Assignment classes simply store
28  a constant list (in this case of particles). The list
29  is stored in sorted order. Their interface is more or
30  less that of a constant vector in C++ or
31  a constant list in python.
32  */
33 class IMPDOMINOEXPORT Subset
34  : public base::ConstVector<base::WeakPointer<kernel::Particle>,
35  kernel::Particle *> {
38  static const kernel::ParticlesTemp &get_sorted(kernel::ParticlesTemp &ps) {
39  std::sort(ps.begin(), ps.end());
40  return ps;
41  }
42 
43  public:
44 #ifndef IMP_DOXYGEN
45  // only use this if particles are sorted already
46  Subset(const kernel::ParticlesTemp &ps, bool) : P(ps.begin(), ps.end()) {
48  for (unsigned int i = 0; i < size(); ++i) {
49  IMP_CHECK_OBJECT(ps[i]);
50  }
51  for (unsigned int i = 1; i < ps.size(); ++i) {
52  IMP_INTERNAL_CHECK(ps[i - 1] < ps[i], "Particles not ordered");
53  }
54  }
55  }
56 #endif
57  Subset() {}
58  /** Construct a subset from a non-empty list of particles.
59  */
60  explicit Subset(kernel::ParticlesTemp ps) : P(get_sorted(ps)) {
61  IMP_USAGE_CHECK(!ps.empty(), "Do not create empty subsets");
63  std::sort(ps.begin(), ps.end());
64  IMP_USAGE_CHECK(std::unique(ps.begin(), ps.end()) == ps.end(),
65  "Duplicate particles in set");
66  for (unsigned int i = 0; i < ps.size(); ++i) {
67  IMP_CHECK_OBJECT(ps[i]);
68  }
69  }
70  }
71  kernel::Model *get_model() const { return operator[](0)->get_model(); }
72  std::string get_name() const;
73  bool get_contains(const Subset &o) const {
74  return std::includes(begin(), end(), o.begin(), o.end());
75  }
76 };
77 
79 IMP_SWAP(Subset);
80 
81 inline Subset get_union(const Subset &a, const Subset &b) {
83  set_union(a.begin(), a.end(), b.begin(), b.end(), std::back_inserter(pt));
84  return Subset(pt, true);
85 }
86 
87 inline Subset get_intersection(const Subset &a, const Subset &b) {
89  set_intersection(a.begin(), a.end(), b.begin(), b.end(),
90  std::back_inserter(pt));
91  if (pt.empty()) {
92  return Subset();
93  } else {
94  return Subset(pt, true);
95  }
96 }
97 
98 inline Subset get_difference(const Subset &a, const Subset &b) {
99  kernel::ParticlesTemp rs;
100  std::set_difference(a.begin(), a.end(), b.begin(), b.end(),
101  std::back_inserter(rs));
102  Subset ret(rs, true);
103  return ret;
104 }
105 
106 IMPDOMINO_END_NAMESPACE
107 
108 #endif /* IMPDOMINO_SUBSET_H */
Store a list of kernel::ParticlesTemp.
A nullptr-initialized pointer to an IMP Object.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
A beyesian infererence-based sampler.
Represent a subset of the particles being optimized.
Definition: Subset.h:33
Import IMP/kernel/macros.h in the namespace.
Subset(kernel::ParticlesTemp ps)
Definition: Subset.h:60
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Store an array of values of the same type.
Basic types used by IMP.
#define IMP_CHECK_OBJECT(obj)
Perform some basic validity checks on the object for memory debugging.
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
#define IMP_IF_CHECK(level)
Execute the code block if a certain level checks are on.
Class to handle individual model particles.
IO support.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:72