IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
temperature_rem.py
1## \example temperature_rem.py
2# Temperature replica exchange
3
4import IMP
5import IMP.mpi
6import IMP.core
7import sys
8
9IMP.setup_from_argv(sys.argv, "Temperature MPI example")
10
11# min and max temperature
12TEMPMIN_ = 1.0
13TEMPMAX_ = 5.0
14
15# initialize Replica Exchange class
17# get number of replicas
18nproc = rem.get_number_of_replicas()
19# create array of temperatures, in geometric progression
20temp = rem.create_temperatures(TEMPMIN_, TEMPMAX_, nproc)
21# get replica index
22myindex = rem.get_my_index()
23# set initial value of the parameter (temperature) to exchange
24rem.set_my_parameter("temp", [temp[myindex]])
25
26# create model
27m = IMP.Model()
28
29# add 2 particles
30ps = []
31for i in range(2):
32 p = IMP.Particle(m)
34 d.set_coordinates_are_optimized(True)
35 ps.append(p)
36
37# add harmonic restraint to distance
38h = IMP.core.Harmonic(5.0, 1.0)
39ds = IMP.core.DistanceRestraint(m, h, ps[0], ps[1])
41
42# movers
43movers = []
44for p in ps:
45 movers.append(IMP.core.BallMover(m, p, 0.5))
46# serial mover
47sm = IMP.core.SerialMover(movers)
48
49# sampler
51mc.set_scoring_function(sf)
52mc.set_kt(temp[myindex])
53mc.set_return_best(False)
54mc.add_mover(sm)
55
56# prepare output
57log = open("log" + str(myindex), "w")
58
59# start sampling loop
60for istep in range(0, 100):
61 # do optimization
62 score = mc.optimize(100)
63
64 # get my replica index and temperature
65 myindex = rem.get_my_index()
66 mytemp = rem.get_my_parameter("temp")[0]
67 # score divided by kbt
68 myscore = score / mytemp
69
70 # printout
71 log.write("%4d %2d %6.3f\n" % (istep, myindex, score))
72
73 # get my friend index and temperature
74 findex = rem.get_friend_index(istep)
75 ftemp = rem.get_friend_parameter("temp", findex)[0]
76 # score divided by kbt
77 fscore = score / ftemp
78
79 # try exchange
80 flag = rem.do_exchange(myscore, fscore, findex)
81 # if accepted, change temperature
82 if (flag):
83 mc.set_kt(ftemp)
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Class to handle individual particles of a Model object.
Definition Particle.h:45
Move continuous particle variables by perturbing them within a ball.
Distance restraint between two particles.
Harmonic function (symmetric about the mean)
A Monte Carlo optimizer.
Definition MonteCarlo.h:46
Create a scoring function on a list of restraints.
Applies a list of movers one at a time.
Definition SerialMover.h:26
static XYZ setup_particle(Model *m, ParticleIndex pi)
Definition XYZ.h:51
A class to implement Hamiltonian Replica Exchange.
VectorD< 3 > Vector3D
Definition VectorD.h:407
Basic functionality that is expected to be used by a wide variety of IMP users.
Code that uses the MPI parallel library.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.