IMP  2.1.1
The Integrative Modeling Platform
ReplicaExchange.h
Go to the documentation of this file.
1 /**
2  * \file ReplicaExchange.h
3  * \brief A class to do replica exchange in a generic hamiltonian parameter
4  *
5  * Copyright 2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPMPI_REPLICA_EXCHANGE_H
9 #define IMPMPI_REPLICA_EXCHANGE_H
10 
11 #include "mpi_config.h"
12 #include <IMP/base/Object.h>
13 #include <IMP/base/types.h>
14 #include "mpi.h"
15 #include <string>
16 
17 IMPMPI_BEGIN_NAMESPACE
18 
19 //! A class to implement Hamiltonian Replica Exchange
20 /** Any model parameter can be used as exchange parameter:
21  temperature, restraint intensity, ...
22 */
23 class IMPMPIEXPORT ReplicaExchange: public base::Object
24 {
25  //! MPI rank
26  int myrank_;
27  //! Number of replicas
28  int nproc_;
29  //! List of replica indexes
30  Ints index_;
31  //! List of number of exchanges accepted
32  Ints exarray_;
33  //! MPI status
34  MPI_Status status_;
35  //! Exchange parameters
36  std::map<std::string,Floats> parameters_;
37 
38 private:
39  //! Create list of replica indices
40  Ints create_indexes();
41  //! Create list of number of exchange accepted
42  /** This is useful to track exchange acceptance across replicas */
43  Ints create_exarray();
44  //! Calculate acceptance probability
45  bool get_acceptance(double myscore,double fscore);
46  //! Get the rank for a given replica index
47  int get_rank(int index);
48 
49  virtual void do_destroy() IMP_OVERRIDE {
50  MPI_Finalize();
51  }
52 public:
54  //! Set exchange parameter
55  void set_my_parameter(std::string key,Floats values);
56  //! Get the value of my exchange parameter
57  Floats get_my_parameter(std::string key);
58  //! Get the index of friend with which trying an exchange
59  int get_friend_index(int istep);
60  //! Get the array with exchange acceptance
61  Ints get_exchange_array();
62  //! Get the value of my friend's parameter
63  Floats get_friend_parameter(std::string key,int findex);
64  //! Try an exchange
65  bool do_exchange(double myscore0,double myscore1,int findex);
66  //! Initialize array of temperatures
67  /** Temperatures are distributed according to a geometric progression */
68  Floats create_temperatures(double tmin,double tmax,int nrep);
69  //! Get replica index
70  int get_my_index() const {return index_[myrank_];}
71  //! Get number of replicas
72  int get_number_of_replicas() const {return nproc_;}
73 
75 };
76 
77 IMPMPI_END_NAMESPACE
78 
79 #endif /* IMPMPI_REPLICA_EXCHANGE_H */
Basic types used by IMP.
A class to implement Hamiltonian Replica Exchange.
int get_my_index() const
Get replica index.
int get_number_of_replicas() const
Get number of replicas.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Common base class for heavy weight IMP objects.
virtual void do_destroy()
A shared base class to help in debugging and things.