IMP  2.0.0
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-2013 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 
22 IMPDOMINO_BEGIN_NAMESPACE
23 
24 //! Store a persistent ordering for a subset based on the list.
25 /** Return a list of indexes into s, representing a permutation of the
26  particles in s, so that they are ordered according to all_particles.
27  This order can be used to write s to disk, as the order in s can
28  change between domino runs.
29 */
30 class IMPDOMINOEXPORT Order: public base::ConstVector<unsigned int> {
32 public:
33  Order() {}
34  Order(Subset outer, const 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)
44  == Assignment(b,e), "In and out don't match: "
45  << Assignment(b,e) << " vs " << 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 */