1 """@namespace IMP.EMageFit.monte_carlo
2 Classes for Monte Carlo sampling using rigid body relative moves.
18 log = logging.getLogger(
"MonteCarloParticleSates")
31 initializing the random number generator manually is useful for the
33 @param index Seed for the random number generator
36 log.debug(
"Seed for the random number generator: %s", index)
37 IMP.random_number_generator.seed(index)
39 IMP.random_number_generator.seed(time.time())
45 Class to do Monte Carlo sampling by using as the set of movements
46 relative positions between rigid bodies
49 def __init__(self, model, rigid_bodies, anchored):
50 log.info(
"Setting MonteCarloRelativeMoves")
52 self.rbs = rigid_bodies
55 self.anchored = anchored
59 self.dock_transforms =
None
60 self.non_relative_move_prob = 0.1
62 log.debug(
"Anchored components %s", self.anchored)
63 T = alg.Transformation3D(alg.get_identity_rotation_3d(),
64 alg.Vector3D(0., 0., 0.))
65 origin = alg.ReferenceFrame3D(T)
67 rb.set_reference_frame(origin)
71 Set the temperature pattern to use during the Monte Carlo
73 @param temperatures List of temperature values
74 @param iterations List with the iterations to do for each of the
76 @param cycles Number of repetitions of the
77 pattern of temperatures and iterations
79 self.temperatures = temperatures
80 self.iterations = iterations
82 log.debug(
"Temperatures %s", self.temperatures)
83 log.debug(
"Iterations %s", self.iterations)
84 log.debug(
"Cycles %s", self.cycles)
86 def set_movers(self, max_translation, max_rotation):
87 log.info(
"Setting movers for subunits")
89 for is_anchored, rb
in zip(self.anchored, self.rbs):
96 Generate the relative models form the transforms. The transforms
97 is a list with triplets [id1, id2, transform_file]
98 @param max_translation Maximum translation distance allowed for
100 @param max_rotation Maximum rotation angle allowed for the moves
102 log.info(
"Setting relative movers")
106 for d
in self.dock_transforms:
107 rb_id = representation.get_rb_name(d[1])
108 if rb_id
not in relative_names:
109 log.debug(
"Checking for %s", rb_id)
110 rb_lig = representation.get_rigid_body(self.rbs, rb_id)
111 rb_lig.set_coordinates_are_optimized(
True)
114 relative_movers.append(mv)
115 relative_names.append(rb_id)
116 log.debug(
"added a RelativePositionMover for %s", rb_id)
117 i = relative_names.index(rb_id)
118 relative_movers[i].set_random_move_probability(
119 self.non_relative_move_prob)
120 rb_rec = representation.get_rigid_body(self.rbs,
121 representation.get_rb_name(d[0]))
122 rb_rec.set_coordinates_are_optimized(
True)
123 log.debug(
"Reference added for %s: %s. ref. frame %s ",
124 rb_id, rb_rec.get_name(), rb_rec)
125 Tis = io.read_transforms(d[2])
126 relative_movers[i].add_internal_transformations(rb_rec, Tis)
130 for is_anchored, rb
in zip(self.anchored, self.rbs):
133 if(
not name
in relative_names):
134 rb.set_coordinates_are_optimized(
True)
135 log.debug(
"adding a RigidBodyMover for %s", name)
137 regular_movers.append(mv)
138 self.movers = regular_movers
139 self.movers += relative_movers
141 def set_moving_parameters(self, max_translations, max_rotations):
142 self.max_translations = max_translations
143 self.max_rotations = max_rotations
144 log.debug(
"Maximum translations %s", self.max_translations)
145 log.debug(
"Maximum rotations %s", self.max_rotations)
149 Run MonteCarlo sampling to generate possible states for DOMINO
152 log.info(
"Running MonteCarlo")
154 mc.set_return_best(
True)
155 for i
in range(self.cycles):
156 log.info(
"Cycle: %s", i)
157 for iters, T, tr, rot
in zip(self.iterations, self.temperatures,
158 self.max_translations, self.max_rotations):
160 log.debug(
"%s %s", rb.get_name(), rb.get_reference_frame())
161 self.set_movers(tr, rot)
162 mc.add_movers(self.movers)
166 log.debug(
"%s %s", rb.get_name(), rb.get_reference_frame())
169 log.info(
"MonteCarlo run finished. Time %s", time.time() - t0)
173 Run MonteCarlo sampling to generate possible states for DOMINO
176 log.info(
"Running MonteCarlo")
178 mc.set_return_best(
True)
180 for i
in range(self.cycles):
181 log.info(
"Cycle: %s", i)
182 for iters, T, tr, rot
in zip(self.iterations, self.temperatures,
183 self.max_translations, self.max_rotations):
184 log.debug(
"BEFORE RELATIVE MOVERS")
186 for m
in self.movers:
189 mc.add_movers(self.movers)
191 log.debug(
"Optimizing for %s iterations ...", iters)
193 log.debug(
"Finished optimizing.")
195 log.info(
"MonteCarlo run finished. Time %s", time.time() - t0)
Restraints using electron microscopy 2D images (class averages).
Various classes to hold sets of particles.
Utility functions to handle representation.
def set_temperature_pattern
Set the temperature pattern to use during the Monte Carlo optimizations.
Modify the transformation of a rigid body.
Class to do Monte Carlo sampling by using as the set of movements relative positions between rigid bo...
Utility functions to handle IO.
def run_monte_carlo
Run MonteCarlo sampling to generate possible states for DOMINO.
def set_relative_movers
Generate the relative models form the transforms.
Basic utilities for handling cryo-electron microscopy 3D density maps.
def run_monte_carlo_with_relative_movers
Run MonteCarlo sampling to generate possible states for DOMINO.
Basic functionality that is expected to be used by a wide variety of IMP users.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
Functionality for loading, creating, manipulating and scoring atomic structures.
def set_random_seed
initializing the random number generator manually is useful for the jobs in the cluster.