IMP logo
IMP Reference Guide  2.12.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-2019 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/Object.h>
13 #include <IMP/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 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  public:
50  //! Set exchange parameter
51  void set_my_parameter(std::string key, Floats values);
52  //! Get the value of my exchange parameter
53  Floats get_my_parameter(std::string key);
54  //! Get the index of friend with which trying an exchange
55  int get_friend_index(int istep);
56  //! Get the array with exchange acceptance
57  Ints get_exchange_array();
58  //! Get the value of my friend's parameter
59  Floats get_friend_parameter(std::string key, int findex);
60  //! Try an exchange
61  bool do_exchange(double myscore0, double myscore1, int findex);
62  //! Initialize array of temperatures
63  /** Temperatures are distributed according to a geometric progression */
64  Floats create_temperatures(double tmin, double tmax, int nrep);
65  //! Get replica index
66  int get_my_index() const { return index_[myrank_]; }
67  //! Get number of replicas
68  int get_number_of_replicas() const { return nproc_; }
69 
71 };
72 
73 IMPMPI_END_NAMESPACE
74 
75 #endif /* IMPMPI_REPLICA_EXCHANGE_H */
A class to implement Hamiltonian Replica Exchange.
Basic types used by IMP.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Common base class for heavy weight IMP objects.
Definition: Object.h:106
int get_my_index() const
Get replica index.
int get_number_of_replicas() const
Get number of replicas.
Include all non-deprecated headers in IMP.mpi.
A shared base class to help in debugging and things.