IMP  2.2.0
The Integrative Modeling Platform
ReplicaExchange.h
Go to the documentation of this file.
1 /**
2  * \file IMP/mpi/ReplicaExchange.h
3  * \brief A class to do replica exchange in a generic hamiltonian parameter
4  *
5  * Copyright 2007-2014 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  //! MPI rank
25  int myrank_;
26  //! Number of replicas
27  int nproc_;
28  //! List of replica indexes
29  Ints index_;
30  //! List of number of exchanges accepted
31  Ints exarray_;
32  //! MPI status
33  MPI_Status status_;
34  //! Exchange parameters
35  std::map<std::string, Floats> parameters_;
36 
37  private:
38  //! Create list of replica indices
39  Ints create_indexes();
40  //! Create list of number of exchange accepted
41  /** This is useful to track exchange acceptance across replicas */
42  Ints create_exarray();
43  //! Calculate acceptance probability
44  bool get_acceptance(double myscore, double fscore);
45  //! Get the rank for a given replica index
46  int get_rank(int index);
47 
48  virtual void do_destroy() IMP_OVERRIDE { MPI_Finalize(); }
49 
50  public:
52  //! Set exchange parameter
53  void set_my_parameter(std::string key, Floats values);
54  //! Get the value of my exchange parameter
55  Floats get_my_parameter(std::string key);
56  //! Get the index of friend with which trying an exchange
57  int get_friend_index(int istep);
58  //! Get the array with exchange acceptance
59  Ints get_exchange_array();
60  //! Get the value of my friend's parameter
61  Floats get_friend_parameter(std::string key, int findex);
62  //! Try an exchange
63  bool do_exchange(double myscore0, double myscore1, int findex);
64  //! Initialize array of temperatures
65  /** Temperatures are distributed according to a geometric progression */
66  Floats create_temperatures(double tmin, double tmax, int nrep);
67  //! Get replica index
68  int get_my_index() const { return index_[myrank_]; }
69  //! Get number of replicas
70  int get_number_of_replicas() const { return nproc_; }
71 
73 };
74 
75 IMPMPI_END_NAMESPACE
76 
77 #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.
Definition: base/Object.h:106
A container which has pairs which ensure a set is connected.
virtual void do_destroy()
Definition: base/Object.h:230
A shared base class to help in debugging and things.