8 import IMP.em2d.imp_general.representation
as representation
9 import IMP.em2d.imp_general.io
as io
14 log = logging.getLogger(
"MonteCarloParticleSates")
25 def set_random_seed(index):
27 initializing the random number generator manually is useful for the
29 @param index Seed for the random number generator
32 log.debug(
"Seed for the random number generator: %s", index)
33 IMP.random_number_generator.seed(index)
35 IMP.random_number_generator.seed(time.time())
41 Class to do Monte Carlo sampling by using as the set of movements
42 relative positions between rigid bodies
45 def __init__(self, model, rigid_bodies, anchored):
46 log.info(
"Setting MonteCarloRelativeMoves")
48 self.rbs = rigid_bodies
51 self.anchored = anchored
55 self.dock_transforms =
None
56 self.non_relative_move_prob = 0.1
58 log.debug(
"Anchored components %s", self.anchored)
59 T = alg.Transformation3D(alg.get_identity_rotation_3d(),
60 alg.Vector3D(0., 0., 0.))
61 origin = alg.ReferenceFrame3D(T)
63 rb.set_reference_frame(origin)
67 Set the temperature pattern to use during the Monte Carlo
69 @param temperatures List of temperature values
70 @param iterations List with the iterations to do for each of the
72 @param cycles Number of repetitions of the
73 pattern of temperatures and iterations
75 self.temperatures = temperatures
76 self.iterations = iterations
78 log.debug(
"Temperatures %s", self.temperatures)
79 log.debug(
"Iterations %s", self.iterations)
80 log.debug(
"Cycles %s", self.cycles)
82 def set_movers(self, max_translation, max_rotation):
83 log.info(
"Setting movers for subunits")
85 for is_anchored, rb
in zip(self.anchored, self.rbs):
92 Generate the relative models form the transforms. The transforms
93 is a list with triplets [id1, id2, transform_file]
94 @param max_translation Maximum translation distance allowed for
96 @param max_rotation Maximum rotation angle allowed for the moves
98 log.info(
"Setting relative movers")
102 for d
in self.dock_transforms:
103 rb_id = representation.get_rb_name(d[1])
104 if rb_id
not in relative_names:
105 log.debug(
"Checking for %s", rb_id)
106 rb_lig = representation.get_rigid_body(self.rbs, rb_id)
107 rb_lig.set_coordinates_are_optimized(
True)
110 relative_movers.append(mv)
111 relative_names.append(rb_id)
112 log.debug(
"added a RelativePositionMover for %s", rb_id)
113 i = relative_names.index(rb_id)
114 relative_movers[i].set_random_move_probability(
115 self.non_relative_move_prob)
116 rb_rec = representation.get_rigid_body(self.rbs,
117 representation.get_rb_name(d[0]))
118 rb_rec.set_coordinates_are_optimized(
True)
119 log.debug(
"Reference added for %s: %s. ref. frame %s ",
120 rb_id, rb_rec.get_name(), rb_rec)
121 Tis = io.read_transforms(d[2])
122 relative_movers[i].add_internal_transformations(rb_rec, Tis)
126 for is_anchored, rb
in zip(self.anchored, self.rbs):
129 if(
not name
in relative_names):
130 rb.set_coordinates_are_optimized(
True)
131 log.debug(
"adding a RigidBodyMover for %s", name)
133 regular_movers.append(mv)
134 self.movers = regular_movers
135 self.movers += relative_movers
137 def set_moving_parameters(self, max_translations, max_rotations):
138 self.max_translations = max_translations
139 self.max_rotations = max_rotations
140 log.debug(
"Maximum translations %s", self.max_translations)
141 log.debug(
"Maximum rotations %s", self.max_rotations)
145 Run MonteCarlo sampling to generate possible states for DOMINO
148 log.info(
"Running MonteCarlo")
150 mc.set_return_best(
True)
151 for i
in xrange(self.cycles):
152 log.info(
"Cycle: %s", i)
153 for iters, T, tr, rot
in zip(self.iterations, self.temperatures,
154 self.max_translations, self.max_rotations):
156 log.debug(
"%s %s", rb.get_name(), rb.get_reference_frame())
157 self.set_movers(tr, rot)
158 mc.add_movers(self.movers)
162 log.debug(
"%s %s", rb.get_name(), rb.get_reference_frame())
165 log.info(
"MonteCarlo run finished. Time %s", time.time() - t0)
169 Run MonteCarlo sampling to generate possible states for DOMINO
172 log.info(
"Running MonteCarlo")
174 mc.set_return_best(
True)
176 for i
in xrange(self.cycles):
177 log.info(
"Cycle: %s", i)
178 for iters, T, tr, rot
in zip(self.iterations, self.temperatures,
179 self.max_translations, self.max_rotations):
180 log.debug(
"BEFORE RELATIVE MOVERS")
182 for m
in self.movers:
185 mc.add_movers(self.movers)
187 log.debug(
"Optimizing for %s iterations ...", iters)
189 log.debug(
"Finished optimizing.")
191 log.info(
"MonteCarlo run finished. Time %s", time.time() - t0)
Class to do Monte Carlo sampling by using as the set of movements relative positions between rigid bo...
See IMP.em2d for more information.
def set_relative_movers
Generate the relative models form the transforms.
See IMP.container for more information.
Modify the transformation of a rigid body.
def run_monte_carlo
Run MonteCarlo sampling to generate possible states for DOMINO.
def run_monte_carlo_with_relative_movers
Run MonteCarlo sampling to generate possible states for DOMINO.
See IMP.em for more information.
def set_temperature_pattern
Set the temperature pattern to use during the Monte Carlo optimizations.
See IMP.core for more information.
See IMP.algebra for more information.
See IMP.atom for more information.