IMP logo
IMP Reference Guide  develop.d97d4ead1f,2024/11/21
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-2022 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPMPI_REPLICA_EXCHANGE_H
9 #define IMPMPI_REPLICA_EXCHANGE_H
10 
11 #include <IMP/mpi/mpi_config.h>
12 #include <IMP/Object.h>
13 #include <IMP/types.h>
14 #include <string>
15 
16 // We only want the C API, so try to suppress the C++ API
17 #ifndef MPICH_SKIP_MPICXX
18 #define MPICH_SKIP_MPICXX
19 #endif
20 #ifndef OMPI_SKIP_MPICXX
21 #define OMPI_SKIP_MPICXX
22 #endif
23 #ifndef _MPICC_H
24 #define _MPICC_H
25 #endif
26 #include <mpi.h>
27 
28 IMPMPI_BEGIN_NAMESPACE
29 
30 //! A class to implement Hamiltonian Replica Exchange
31 /** Any model parameter can be used as exchange parameter:
32  temperature, restraint intensity, ...
33 */
34 class IMPMPIEXPORT ReplicaExchange : public Object {
35  //! MPI rank
36  int myrank_;
37  //! Number of replicas
38  int nproc_;
39  //! List of replica indexes
40  Ints index_;
41  //! List of number of exchanges accepted
42  Ints exarray_;
43  //! MPI status
44  MPI_Status status_;
45  //! Exchange parameters
46  std::map<std::string, Floats> parameters_;
47 
48  private:
49  //! Create list of replica indices
50  Ints create_indexes();
51  //! Create list of number of exchange accepted
52  /** This is useful to track exchange acceptance across replicas */
53  Ints create_exarray();
54  //! Calculate acceptance probability
55  bool get_acceptance(double myscore, double fscore);
56  //! Get the rank for a given replica index
57  int get_rank(int index);
58 
59  public:
61  //! Set exchange parameter
62  void set_my_parameter(std::string key, Floats values);
63  //! Get the value of my exchange parameter
64  Floats get_my_parameter(std::string key);
65  //! Get the index of friend with which trying an exchange
66  int get_friend_index(int istep);
67  //! Get the array with exchange acceptance
68  Ints get_exchange_array();
69  //! Get the value of my friend's parameter
70  Floats get_friend_parameter(std::string key, int findex);
71  //! Try an exchange
72  bool do_exchange(double myscore0, double myscore1, int findex);
73  //! Initialize array of temperatures
74  /** Temperatures are distributed according to a geometric progression */
75  Floats create_temperatures(double tmin, double tmax, int nrep);
76  //! Get replica index
77  int get_my_index() const { return index_[myrank_]; }
78  //! Get number of replicas
79  int get_number_of_replicas() const { return nproc_; }
80 
82 };
83 
84 IMPMPI_END_NAMESPACE
85 
86 #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:111
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.