IMP  2.4.0
The Integrative Modeling Platform
MultiStateModel.h
Go to the documentation of this file.
1 /**
2  * \file IMP/multi_state/MultiStateModel.h
3  * \brief base class for MultiStateModel
4  *
5  * \authors Dina Schneidman
6  * Copyright 2007-2015 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 <vector>
16 #include <iostream>
17 #include <iomanip>
18 
19 IMPMULTISTATE_BEGIN_NAMESPACE
20 
21 class MultiStateModel {
22 public:
23  MultiStateModel(unsigned int size) : score_(0.0), zscore_(0.0) {
24  states_.reserve(size);
25  }
26 
27  /* Modifiers */
28 
29  void add_state(unsigned int new_state) {
30  states_.push_back(new_state);
31  // invalidate score
32  score_ = 0.0;
33  }
34 
35  void set_score(double score) { score_ = score; }
36 
37  void set_zscore(double score) { zscore_ = score; }
38 
39  void replace_last_state(unsigned int new_state) {
40  states_[states_.size()-1] = new_state;
41  }
42 
43  /* Access */
44 
45  const std::vector<unsigned int>& get_states() const { return states_; }
46 
47  double get_score() const { return score_; }
48 
49  double get_zscore() const { return zscore_; }
50 
51  unsigned int size() const { return states_.size(); }
52 
53  unsigned int get_last_state() const { return states_.back(); }
54 
55  friend std::ostream& operator<<(std::ostream& s, const MultiStateModel& e) {
56  for(unsigned int i=0; i<e.states_.size(); i++)
57  s << std::setw(4) << e.states_[i] << " ";
58  s << std::setw(6) << std::setprecision(4) << e.score_;
59  return s;
60  }
61 
62 private:
63  std::vector<unsigned int> states_;
64  double score_;
65  double zscore_;
66 };
67 
68 class CompareMultiStateModels {
69 public:
70  bool operator()(const MultiStateModel& e1, const MultiStateModel& e2) const {
71  return (e1.get_score() < e2.get_score());
72  }
73 };
74 
75 IMPMULTISTATE_END_NAMESPACE
76 
77 #endif /* IMPMULTI_STATE_MULTI_STATE_MODEL_H */