IMP  2.2.1
The Integrative Modeling Platform
Order.h
Go to the documentation of this file.
1 /**
2  * \file IMP/domino/Order.h
3  * \brief A beyesian infererence-based sampler.
4  *
5  * Copyright 2007-2014 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/base/Value.h>
19 #include <IMP/base/ConstVector.h>
20 
21 IMPDOMINO_BEGIN_NAMESPACE
22 
23 //! Store a persistent ordering for a subset based on the list.
24 /** Return a list of indexes into s, representing a permutation of the
25  particles in s, so that they are ordered according to all_particles.
26  This order can be used to write s to disk, as the order in s can
27  change between domino runs.
28 */
29 class IMPDOMINOEXPORT Order : public base::ConstVector<unsigned int> {
31 
32  public:
33  Order() {}
34  Order(Subset outer, const kernel::ParticlesTemp &order);
35  template <class It>
36  Ints get_list_ordered(It b, It e) const {
37  IMP_USAGE_CHECK(static_cast<unsigned int>(std::distance(b, e)) == size(),
38  "Sizes don't match in permutation");
39  Ints ret(std::distance(b, e));
40  for (unsigned int i = 0; i < ret.size(); ++i) {
41  ret[operator[](i)] = b[i];
42  }
43  IMP_USAGE_CHECK(get_subset_ordered(ret) == Assignment(b, e),
44  "In and out don't match: " << Assignment(b, e) << " vs "
45  << get_subset_ordered(ret));
46  return ret;
47  }
48  template <class It>
49  Assignment get_subset_ordered(It b, It e) const {
50  IMP_CHECK_VARIABLE(e);
51  IMP_USAGE_CHECK(static_cast<unsigned int>(std::distance(b, e)) == size(),
52  "Sizes don't match in permutation");
53  Assignment ret(size());
54  for (unsigned int i = 0; i < size(); ++i) {
55  ret.set_item(i, b[operator[](i)]);
56  }
57  return ret;
58  }
59  Ints get_list_ordered(const Assignment &a) const {
60  return get_list_ordered(a.begin(), a.end());
61  }
62  Assignment get_subset_ordered(const Ints &a) const {
63  return get_subset_ordered(a.begin(), a.end());
64  }
65 };
66 
68 IMP_SWAP(Order);
69 
70 IMPDOMINO_END_NAMESPACE
71 
72 #endif /* IMPDOMINO_ORDER_H */
Store a list of kernel::ParticlesTemp.
A beyesian infererence-based sampler.
Store a persistent ordering for a subset based on the list.
Definition: Order.h:29
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
A beyesian infererence-based sampler.
Represent a subset of the particles being optimized.
Definition: Subset.h:33
Import IMP/kernel/macros.h in the namespace.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Store an array of values of the same type.
Basic types used by IMP.
Various important macros for implementing decorators.
A beyesian infererence-based sampler.
Store a configuration of a subset.
Definition: Assignment.h:32