1 """@namespace IMP.EMageFit.monte_carlo
2 Classes for Monte Carlo sampling using rigid body relative moves.
13 log = logging.getLogger(
"MonteCarloParticleSates")
26 initializing the random number generator manually is useful for the
28 @param index Seed for the random number generator
31 log.debug(
"Seed for the random number generator: %s", index)
32 IMP.random_number_generator.seed(index)
34 IMP.random_number_generator.seed(int(time.time()))
40 Class to do Monte Carlo sampling by using as the set of movements
41 relative positions between rigid bodies
44 def __init__(self, model, rigid_bodies, anchored):
45 log.info(
"Setting MonteCarloRelativeMoves")
47 self.rbs = rigid_bodies
50 self.anchored = anchored
54 self.dock_transforms =
None
55 self.non_relative_move_prob = 0.1
57 log.debug(
"Anchored components %s", self.anchored)
58 T = alg.Transformation3D(alg.get_identity_rotation_3d(),
59 alg.Vector3D(0., 0., 0.))
60 origin = alg.ReferenceFrame3D(T)
62 rb.set_reference_frame(origin)
66 Set the temperature pattern to use during the Monte Carlo
68 @param temperatures List of temperature values
69 @param iterations List with the iterations to do for each of the
71 @param cycles Number of repetitions of the
72 pattern of temperatures and iterations
74 self.temperatures = temperatures
75 self.iterations = iterations
77 log.debug(
"Temperatures %s", self.temperatures)
78 log.debug(
"Iterations %s", self.iterations)
79 log.debug(
"Cycles %s", self.cycles)
81 def set_movers(self, max_translation, max_rotation):
82 log.info(
"Setting movers for subunits")
84 for is_anchored, rb
in zip(self.anchored, self.rbs):
91 Generate the relative models form the transforms. The transforms
92 is a list with triplets [id1, id2, transform_file]
93 @param max_translation Maximum translation distance allowed for
95 @param max_rotation Maximum rotation angle allowed for the moves
97 log.info(
"Setting relative movers")
101 for d
in self.dock_transforms:
102 rb_id = representation.get_rb_name(d[1])
103 if rb_id
not in relative_names:
104 log.debug(
"Checking for %s", rb_id)
105 rb_lig = representation.get_rigid_body(self.rbs, rb_id)
106 rb_lig.set_coordinates_are_optimized(
True)
109 relative_movers.append(mv)
110 relative_names.append(rb_id)
111 log.debug(
"added a RelativePositionMover for %s", rb_id)
112 i = relative_names.index(rb_id)
113 relative_movers[i].set_random_move_probability(
114 self.non_relative_move_prob)
115 rb_rec = representation.get_rigid_body(
116 self.rbs, representation.get_rb_name(d[0]))
117 rb_rec.set_coordinates_are_optimized(
True)
118 log.debug(
"Reference added for %s: %s. ref. frame %s ",
119 rb_id, rb_rec.get_name(), rb_rec)
120 Tis = io.read_transforms(d[2])
121 relative_movers[i].add_internal_transformations(rb_rec, Tis)
125 for is_anchored, rb
in zip(self.anchored, self.rbs):
128 if name
not in relative_names:
129 rb.set_coordinates_are_optimized(
True)
130 log.debug(
"adding a RigidBodyMover for %s", name)
132 regular_movers.append(mv)
133 self.movers = regular_movers
134 self.movers += relative_movers
136 def set_moving_parameters(self, max_translations, max_rotations):
137 self.max_translations = max_translations
138 self.max_rotations = max_rotations
139 log.debug(
"Maximum translations %s", self.max_translations)
140 log.debug(
"Maximum rotations %s", self.max_rotations)
143 """Set the scoring function to be used by MonteCarlo."""
144 self._scoring_function = scoring_function
148 Run MonteCarlo sampling to generate possible states for DOMINO
151 log.info(
"Running MonteCarlo")
153 mc.set_scoring_function(self._scoring_function)
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,
161 log.debug(
"%s %s", rb.get_name(), rb.get_reference_frame())
162 self.set_movers(tr, rot)
163 mc.add_movers(self.movers)
167 log.debug(
"%s %s", rb.get_name(), rb.get_reference_frame())
170 log.info(
"MonteCarlo run finished. Time %s", time.time() - t0)
174 Run MonteCarlo sampling to generate possible states for DOMINO
177 log.info(
"Running MonteCarlo")
179 mc.set_scoring_function(self._scoring_function)
180 mc.set_return_best(
True)
182 for i
in range(self.cycles):
183 log.info(
"Cycle: %s", i)
184 for iters, T, tr, rot
in zip(self.iterations, self.temperatures,
185 self.max_translations,
187 log.debug(
"BEFORE RELATIVE MOVERS")
189 for m
in self.movers:
192 mc.add_movers(self.movers)
194 log.debug(
"Optimizing for %s iterations ...", iters)
196 log.debug(
"Finished optimizing.")
198 log.info(
"MonteCarlo run finished. Time %s", time.time() - t0)
Restraints using electron microscopy 2D images (class averages).
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.
def set_scoring_function
Set the scoring function to be used by MonteCarlo.
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...
def set_random_seed
initializing the random number generator manually is useful for the jobs in the cluster.