IMP logo
IMP Reference Guide  2.17.0
The Integrative Modeling Platform
Slice.h
Go to the documentation of this file.
1 /**
2  * \file IMP/domino/Slice.h
3  * \brief A Bayesian inference-based sampler.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPDOMINO_SLICE_H
10 #define IMPDOMINO_SLICE_H
11 
12 #include <IMP/domino/domino_config.h>
13 #include "IMP/macros.h"
14 #include "domino_macros.h"
15 #include "Subset.h"
16 #include "Assignment.h"
17 #include <IMP/Value.h>
19 #include <IMP/ConstVector.h>
20 
21 IMPDOMINO_BEGIN_NAMESPACE
22 
23 //! Store a subset of a subset or assignment.
24 /** This class stores a particular slice through a subset. The entire
25  inner Subset must be contained in the outer one.
26 */
27 class IMPDOMINOEXPORT Slice : public ConstVector<unsigned int> {
29  static Ints get_slice(Subset outer, Subset inner) {
30  Ints ret(inner.size());
31  for (unsigned int i = 0; i < inner.size(); ++i) {
32  for (unsigned int j = 0; j < outer.size(); ++j) {
33  if (inner[i] == outer[j]) {
34  ret[i] = j;
35  }
36  }
37  }
38  return ret;
39  }
40 
41  public:
42  Slice() {}
43  Slice(Subset outer, Subset inner) : P(get_slice(outer, inner)) {}
44  Assignment get_sliced(const Assignment& a) const {
45  Ints ret(size(), -1);
46  for (unsigned int i = 0; i < size(); ++i) {
47  ret[i] = a[operator[](i)];
48  }
49  return Assignment(ret);
50  }
51  Subset get_sliced(const Subset& a) const {
52  ParticlesTemp ret(size());
53  for (unsigned int i = 0; i < size(); ++i) {
54  ret[i] = a[operator[](i)];
55  }
56  return Subset(ret, true);
57  }
58 };
59 
61 IMP_SWAP(Slice);
62 
63 /** Return a slice for the inner subset if it is not contained
64  in any of the excluded subsets, otherwise return the empty slice.
65 */
66 inline Slice get_slice(Subset outer, Subset inner, const Subsets& excluded) {
67  IMP_USAGE_CHECK(inner.size() <= outer.size(), "Inner and outer are switched");
68  for (unsigned int i = 0; i < excluded.size(); ++i) {
69  if (get_intersection(inner, excluded[i]).size() == inner.size()) {
70  return Slice();
71  }
72  }
73  return Slice(outer, inner);
74 }
75 
76 IMPDOMINO_END_NAMESPACE
77 
78 #endif /* IMPDOMINO_SLICE_H */
Store a list of ParticleIndexes.
Store an array of values of the same type.
A Bayesian inference-based sampler.
Represent a subset of the particles being optimized.
Definition: Subset.h:33
Various general useful macros for IMP.
Store a subset of a subset or assignment.
Definition: Slice.h:27
BoundingBoxD< D > get_intersection(const BoundingBoxD< D > &a, const BoundingBoxD< D > &b)
Return the intersecting bounding box.
Definition: BoundingBoxD.h:223
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
Various important macros for implementing decorators.
A Bayesian inference-based sampler.
Store a configuration of a subset.
Definition: Assignment.h:32
Base class for a simple primitive-like type.
Store an array of values of the same type.
Definition: ConstVector.h:26
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
Slice get_slice(Subset outer, Subset inner, const Subsets &excluded)
Definition: Slice.h:66