IMP logo
IMP Reference Guide  2.20.2
The Integrative Modeling Platform
Order.h
Go to the documentation of this file.
1 /**
2  * \file IMP/domino/Order.h
3  * \brief A Bayesian inference-based sampler.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPDOMINO_ORDER_H
10 #define IMPDOMINO_ORDER_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"
18 #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 persistent ordering for a subset based on the list.
27 /** \return a list of indexes into s, representing a permutation of the
28  particles in s, so that they are ordered according to all_particles.
29  This order can be used to write s to disk, as the order in s can
30  change between domino runs.
31 */
32 class IMPDOMINOEXPORT Order : public ConstVector<unsigned int> {
34 
35  friend class cereal::access;
36 
37  template<class Archive> void serialize(Archive &ar) {
38  ar(cereal::base_class<P>(this));
39  }
40 
41  public:
42  Order() {}
43  Order(Subset outer, const ParticlesTemp &order);
44  template <class It>
45  Ints get_list_ordered(It b, It e) const {
46  IMP_USAGE_CHECK(static_cast<unsigned int>(std::distance(b, e)) == size(),
47  "Sizes don't match in permutation");
48  Ints ret(std::distance(b, e));
49  for (unsigned int i = 0; i < ret.size(); ++i) {
50  ret[operator[](i)] = b[i];
51  }
52  IMP_USAGE_CHECK(get_subset_ordered(ret) == Assignment(b, e),
53  "In and out don't match: " << Assignment(b, e) << " vs "
54  << get_subset_ordered(ret));
55  return ret;
56  }
57  template <class It>
58  Assignment get_subset_ordered(It b, It e) const {
59  IMP_CHECK_VARIABLE(e);
60  IMP_USAGE_CHECK(static_cast<unsigned int>(std::distance(b, e)) == size(),
61  "Sizes don't match in permutation");
62  Assignment ret(size());
63  for (unsigned int i = 0; i < size(); ++i) {
64  ret.set_item(i, b[operator[](i)]);
65  }
66  return ret;
67  }
68  Ints get_list_ordered(const Assignment &a) const {
69  return get_list_ordered(a.begin(), a.end());
70  }
71  Assignment get_subset_ordered(const Ints &a) const {
72  return get_subset_ordered(a.begin(), a.end());
73  }
74 };
75 
77 IMP_SWAP(Order);
78 
79 IMPDOMINO_END_NAMESPACE
80 
81 #endif /* IMPDOMINO_ORDER_H */
Store a list of ParticleIndexes.
Store an array of values of the same type.
A Bayesian inference-based sampler.
Store a persistent ordering for a subset based on the list.
Definition: Order.h:32
Represent a subset of the particles being optimized.
Definition: Subset.h:33
Various general useful macros for IMP.
#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