IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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
24IMPDOMINO_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*/
30class IMPDOMINOEXPORT Slice : public ConstVector<unsigned int> {
31 typedef ConstVector<unsigned int> P;
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
71IMP_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*/
76inline 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
86IMPDOMINO_END_NAMESPACE
87
88#endif /* IMPDOMINO_SLICE_H */
A Bayesian inference-based sampler.
Store an array of values of the same type.
Store a list of ParticleIndexes.
A Bayesian inference-based sampler.
Base class for a simple primitive-like type.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Store a configuration of a subset.
Definition Assignment.h:35
Store a subset of a subset or assignment.
Definition Slice.h:30
Represent a subset of the particles being optimized.
Definition Subset.h:34
Various important macros for implementing decorators.
Various general useful macros for IMP.
Slice get_slice(Subset outer, Subset inner, const Subsets &excluded)
Definition Slice.h:76
IMP::Vector< Slice > Slices
Definition Slice.h:70
IMP::Vector< Subset > Subsets
Definition Subset.h:76
IMP::Vector< Int > Ints
Standard way to pass a bunch of Int values.
Definition types.h:48
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.