IMP  2.1.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-2013 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 : public base::ConstVector<
34  base::WeakPointer<kernel::Particle>, kernel::Particle *> {
37  static const kernel::ParticlesTemp &get_sorted(kernel::ParticlesTemp &ps) {
38  std::sort(ps.begin(), ps.end());
39  return ps;
40  }
41 
42  public:
43 #ifndef IMP_DOXYGEN
44  // only use this if particles are sorted already
45  Subset(const kernel::ParticlesTemp &ps, bool) : P(ps.begin(), ps.end()) {
47  for (unsigned int i = 0; i < size(); ++i) {
48  IMP_CHECK_OBJECT(ps[i]);
49  }
50  for (unsigned int i = 1; i < ps.size(); ++i) {
51  IMP_INTERNAL_CHECK(ps[i - 1] < ps[i], "Particles not ordered");
52  }
53  }
54  }
55 #endif
56  Subset() {}
57  /** Construct a subset from a non-empty list of particles.
58  */
59  explicit Subset(kernel::ParticlesTemp ps) : P(get_sorted(ps)) {
60  IMP_USAGE_CHECK(!ps.empty(), "Do not create empty subsets");
62  std::sort(ps.begin(), ps.end());
63  IMP_USAGE_CHECK(std::unique(ps.begin(), ps.end()) == ps.end(),
64  "Duplicate particles in set");
65  for (unsigned int i = 0; i < ps.size(); ++i) {
66  IMP_CHECK_OBJECT(ps[i]);
67  }
68  }
69  }
70  kernel::Model *get_model() const { return operator[](0)->get_model(); }
71  std::string get_name() const;
72  bool get_contains(const Subset &o) const {
73  return std::includes(begin(), end(), o.begin(), o.end());
74  }
75 };
76 
78 IMP_SWAP(Subset);
79 
80 inline Subset get_union(const Subset &a, const Subset &b) {
82  set_union(a.begin(), a.end(), b.begin(), b.end(), std::back_inserter(pt));
83  return Subset(pt, true);
84 }
85 
86 inline Subset get_intersection(const Subset &a, const Subset &b) {
88  set_intersection(a.begin(), a.end(), b.begin(), b.end(),
89  std::back_inserter(pt));
90  if (pt.empty()) {
91  return Subset();
92  } else {
93  return Subset(pt, true);
94  }
95 }
96 
97 inline Subset get_difference(const Subset &a, const Subset &b) {
98  kernel::ParticlesTemp rs;
99  std::set_difference(a.begin(), a.end(), b.begin(), b.end(),
100  std::back_inserter(rs));
101  Subset ret(rs, true);
102  return ret;
103 }
104 
105 IMPDOMINO_END_NAMESPACE
106 
107 #endif /* IMPDOMINO_SUBSET_H */
Store a list of ParticlesTemp.
A nullptr-initialized pointer to an IMP Object.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
BoundingBoxD< D > get_union(BoundingBoxD< D > a, const BoundingBoxD< D > &b)
Return the union bounding box.
Definition: BoundingBoxD.h:236
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:59
#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.
BoundingBoxD< D > get_intersection(const BoundingBoxD< D > &a, const BoundingBoxD< D > &b)
Return the intersecting bounding box.
Definition: BoundingBoxD.h:207
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.