IMP logo
IMP Reference Guide  develop.5dd67dc178,2024/04/28
The Integrative Modeling Platform
MultiStateModel.h
Go to the documentation of this file.
1 /**
2  * \file IMP/multi_state/MultiStateModel.h
3  * \brief Keep track of multiple states
4  *
5  * \authors Dina Schneidman
6  * Copyright 2007-2022 IMP Inventors. All rights reserved.
7  *
8  */
9 
10 #ifndef IMPMULTI_STATE_MULTI_STATE_MODEL_H
11 #define IMPMULTI_STATE_MULTI_STATE_MODEL_H
12 
13 #include <IMP/multi_state/multi_state_config.h>
14 
15 #include <IMP/Vector.h>
16 
17 #include <iostream>
18 #include <iomanip>
19 
20 IMPMULTISTATE_BEGIN_NAMESPACE
21 
22 //! Keep track of multiple states
24 public:
25  MultiStateModel(unsigned int size) : score_(0.0), zscore_(0.0) {
26  states_.reserve(size);
27  }
28 
29  /* Modifiers */
30 
31  void add_state(unsigned int new_state) {
32  states_.push_back(new_state);
33  // invalidate score
34  score_ = 0.0;
35  }
36 
37  void set_score(double score) { score_ = score; }
38 
39  void set_zscore(double score) { zscore_ = score; }
40 
41  void replace_last_state(unsigned int new_state) {
42  states_[states_.size()-1] = new_state;
43  }
44 
45  /* Access */
46 
47  const Vector<unsigned int>& get_states() const { return states_; }
48 
49  double get_score() const { return score_; }
50 
51  double get_zscore() const { return zscore_; }
52 
53  unsigned int size() const { return states_.size(); }
54 
55  unsigned int get_last_state() const { return states_.back(); }
56 
57  friend std::ostream& operator<<(std::ostream& s, const MultiStateModel& e) {
58  for(unsigned int i=0; i<e.states_.size(); i++)
59  s << std::setw(4) << e.states_[i] << " ";
60  s << std::setw(6) << std::setprecision(4) << e.score_;
61  return s;
62  }
63 
64 private:
65  Vector<unsigned int> states_;
66  double score_;
67  double zscore_;
68 };
69 
70 //! Utility class to help sort MultiStateModel objects
72 public:
73  bool operator()(const MultiStateModel& e1, const MultiStateModel& e2) const {
74  return (e1.get_score() < e2.get_score());
75  }
76 };
77 
78 IMPMULTISTATE_END_NAMESPACE
79 
80 #endif /* IMPMULTI_STATE_MULTI_STATE_MODEL_H */
A class for storing lists of IMP items.
Utility class to help sort MultiStateModel objects.
Keep track of multiple states.