IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2026 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#include <cereal/access.hpp>
16#include <cereal/types/base_class.hpp>
17
18// We only want the C API, so try to suppress the C++ API
19#ifndef MPICH_SKIP_MPICXX
20#define MPICH_SKIP_MPICXX
21#endif
22#ifndef OMPI_SKIP_MPICXX
23#define OMPI_SKIP_MPICXX
24#endif
25#ifndef _MPICC_H
26#define _MPICC_H
27#endif
28#include <mpi.h>
29
30IMPMPI_BEGIN_NAMESPACE
31
32//! A class to implement Hamiltonian Replica Exchange
33/** Any model parameter can be used as exchange parameter:
34 temperature, restraint intensity, ...
35*/
36class IMPMPIEXPORT ReplicaExchange : public Object {
37 //! MPI rank
38 int myrank_;
39 //! Number of replicas
40 int nproc_;
41 //! List of replica indexes
42 Ints index_;
43 //! List of number of exchanges accepted
44 Ints exarray_;
45 //! Exchange parameters
46 std::map<std::string, Floats> parameters_;
47
48 friend class cereal::access;
49
50 template<class Archive> void serialize(Archive &ar) {
51 ar(cereal::base_class<Object>(this), myrank_, nproc_, index_, exarray_,
52 parameters_);
53 }
54
55 private:
56 //! Create list of replica indices
57 Ints create_indexes();
58 //! Create list of number of exchange accepted
59 /** This is useful to track exchange acceptance across replicas */
60 Ints create_exarray();
61 //! Calculate acceptance probability
62 bool get_acceptance(double myscore, double fscore);
63 //! Get the rank for a given replica index
64 int get_rank(int index);
65
66 public:
67 ReplicaExchange();
68 //! Set exchange parameter
69 void set_my_parameter(std::string key, Floats values);
70 //! Get the value of my exchange parameter
71 Floats get_my_parameter(std::string key);
72 //! Get the index of friend with which trying an exchange
73 int get_friend_index(int istep);
74 //! Get the array with exchange acceptance
76 //! Get the value of my friend's parameter
77 Floats get_friend_parameter(std::string key, int findex);
78 //! Try an exchange
79 bool do_exchange(double myscore0, double myscore1, int findex);
80 //! Initialize array of temperatures
81 /** Temperatures are distributed according to a geometric progression */
82 Floats create_temperatures(double tmin, double tmax, int nrep);
83 //! Get replica index
84 int get_my_index() const { return index_[myrank_]; }
85 //! Get number of replicas
86 int get_number_of_replicas() const { return nproc_; }
87
88 IMP_OBJECT_METHODS(ReplicaExchange);
89};
90
91IMPMPI_END_NAMESPACE
92
93#endif /* IMPMPI_REPLICA_EXCHANGE_H */
A shared base class to help in debugging and things.
Object(std::string name)
Construct an object with the given name.
Floats create_temperatures(double tmin, double tmax, int nrep)
Initialize array of temperatures.
int get_number_of_replicas() const
Get number of replicas.
int get_my_index() const
Get replica index.
bool do_exchange(double myscore0, double myscore1, int findex)
Try an exchange.
Floats get_friend_parameter(std::string key, int findex)
Get the value of my friend's parameter.
void set_my_parameter(std::string key, Floats values)
Set exchange parameter.
Floats get_my_parameter(std::string key)
Get the value of my exchange parameter.
int get_friend_index(int istep)
Get the index of friend with which trying an exchange.
Ints get_exchange_array()
Get the array with exchange acceptance.
Include all non-deprecated headers in IMP.mpi.
IMP::Vector< Int > Ints
Standard way to pass a bunch of Int values.
Definition types.h:48
IMP::Vector< Float > Floats
Standard way to pass a bunch of Float values.
Definition types.h:46
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Basic types used by IMP.