IMP  2.0.0
The Integrative Modeling Platform
Slice.h
Go to the documentation of this file.
1 /**
2  * \file IMP/domino/Slice.h
3  * \brief A beyesian infererence-based sampler.
4  *
5  * Copyright 2007-2013 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/base/Value.h>
19 #include <IMP/base/ConstVector.h>
20 
21 
22 IMPDOMINO_BEGIN_NAMESPACE
23 
24 //! Store a subset of a subset or assignment.
25 /** This class stores a particular slice through a subset. The entire
26  inner Subset must be contained in the outer one.
27 */
28 class IMPDOMINOEXPORT Slice: public base::ConstVector<unsigned int> {
30  static Ints get_slice(Subset outer, Subset inner) {
31  Ints ret(inner.size());
32  for (unsigned int i=0; i< inner.size(); ++i) {
33  for (unsigned int j=0; j< outer.size(); ++j) {
34  if (inner[i]==outer[j]) {
35  ret[i]=j;
36  }
37  }
38  }
39  return ret;
40  }
41 public:
42  Slice() {}
43  Slice(Subset outer, Subset inner): P(get_slice(outer, inner)) {
44  }
45  Assignment get_sliced(const Assignment& a) const{
46  Ints ret(size(), -1);
47  for (unsigned int i=0; i< size(); ++i) {
48  ret[i]=a[operator[](i)];
49  }
50  return Assignment(ret);
51  }
52  Subset get_sliced(const Subset& a) const{
53  ParticlesTemp ret(size());
54  for (unsigned int i=0; i< size(); ++i) {
55  ret[i]=a[operator[](i)];
56  }
57  return Subset(ret, true);
58  }
59 };
60 
62 IMP_SWAP(Slice);
63 
64 /** Return a slice for the inner subset if it is not contained
65  in any of the excluded subsets, otherwise return the empty slice.
66 */
67 inline Slice get_slice(Subset outer, Subset inner,
68  const Subsets &excluded) {
69  IMP_USAGE_CHECK(inner.size() <= outer.size(),
70  "Inner and outer are switched");
71  for (unsigned int i=0; i< excluded.size(); ++i) {
72  if (get_intersection(inner, excluded[i]).size() == inner.size()) {
73  return Slice();
74  }
75  }
76  return Slice(outer, inner);
77 }
78 
79 IMPDOMINO_END_NAMESPACE
80 
81 #endif /* IMPDOMINO_SLICE_H */