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)
148 """Set the scoring function to be used by MonteCarlo."""
149 self._scoring_function = scoring_function
153 Run MonteCarlo sampling to generate possible states for DOMINO
156 log.info(
"Running MonteCarlo")
158 mc.set_scoring_function(self._scoring_function)
159 mc.set_return_best(
True)
160 for i
in range(self.cycles):
161 log.info(
"Cycle: %s", i)
162 for iters, T, tr, rot
in zip(self.iterations, self.temperatures,
163 self.max_translations, self.max_rotations):
165 log.debug(
"%s %s", rb.get_name(), rb.get_reference_frame())
166 self.set_movers(tr, rot)
167 mc.add_movers(self.movers)
171 log.debug(
"%s %s", rb.get_name(), rb.get_reference_frame())
174 log.info(
"MonteCarlo run finished. Time %s", time.time() - t0)
178 Run MonteCarlo sampling to generate possible states for DOMINO
181 log.info(
"Running MonteCarlo")
183 mc.set_scoring_function(self._scoring_function)
184 mc.set_return_best(
True)
186 for i
in range(self.cycles):
187 log.info(
"Cycle: %s", i)
188 for iters, T, tr, rot
in zip(self.iterations, self.temperatures,
189 self.max_translations, self.max_rotations):
190 log.debug(
"BEFORE RELATIVE MOVERS")
192 for m
in self.movers:
195 mc.add_movers(self.movers)
197 log.debug(
"Optimizing for %s iterations ...", iters)
199 log.debug(
"Finished optimizing.")
201 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 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...
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.