IMP logo
IMP Reference Guide  2.20.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 #include <cereal/access.hpp>
21 #include <cereal/types/vector.hpp>
22 #include <cereal/types/base_class.hpp>
23 
24 IMPDOMINO_BEGIN_NAMESPACE
25 
26 //! Store a subset of a subset or assignment.
27 /** This class stores a particular slice through a subset. The entire
28  inner Subset must be contained in the outer one.
29 */
30 class IMPDOMINOEXPORT Slice : public ConstVector<unsigned int> {
32 
33  friend class cereal::access;
34 
35  template<class Archive> void serialize(Archive &ar) {
36  ar(cereal::base_class<P>(this));
37  }
38 
39  static Ints get_slice(Subset outer, Subset inner) {
40  Ints ret(inner.size());
41  for (unsigned int i = 0; i < inner.size(); ++i) {
42  for (unsigned int j = 0; j < outer.size(); ++j) {
43  if (inner[i] == outer[j]) {
44  ret[i] = j;
45  }
46  }
47  }
48  return ret;
49  }
50 
51  public:
52  Slice() {}
53  Slice(Subset outer, Subset inner) : P(get_slice(outer, inner)) {}
54  Assignment get_sliced(const Assignment& a) const {
55  Ints ret(size(), -1);
56  for (unsigned int i = 0; i < size(); ++i) {
57  ret[i] = a[operator[](i)];
58  }
59  return Assignment(ret);
60  }
61  Subset get_sliced(const Subset& a) const {
62  ParticlesTemp ret(size());
63  for (unsigned int i = 0; i < size(); ++i) {
64  ret[i] = a[operator[](i)];
65  }
66  return Subset(ret, true);
67  }
68 };
69 
71 IMP_SWAP(Slice);
72 
73 /** Return a slice for the inner subset if it is not contained
74  in any of the excluded subsets, otherwise return the empty slice.
75 */
76 inline Slice get_slice(Subset outer, Subset inner, const Subsets& excluded) {
77  IMP_USAGE_CHECK(inner.size() <= outer.size(), "Inner and outer are switched");
78  for (unsigned int i = 0; i < excluded.size(); ++i) {
79  if (get_intersection(inner, excluded[i]).size() == inner.size()) {
80  return Slice();
81  }
82  }
83  return Slice(outer, inner);
84 }
85 
86 IMPDOMINO_END_NAMESPACE
87 
88 #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:30
BoundingBoxD< D > get_intersection(const BoundingBoxD< D > &a, const BoundingBoxD< D > &b)
Return the intersecting bounding box.
Definition: BoundingBoxD.h:230
#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:35
Base class for a simple primitive-like type.
Store an array of values of the same type.
Definition: ConstVector.h:27
#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:76