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 initilazing 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())
39 Class to do Monte Carlo sampling by using as the set of movements
40 relative positions between rigid bodies
42 def __init__(self,model, rigid_bodies, anchored):
43 log.info(
"Setting MonteCarloRelativeMoves")
45 self.rbs = rigid_bodies
48 self.anchored = anchored
52 self.dock_transforms =
None
53 self.non_relative_move_prob = 0.1
55 log.debug(
"Anchored components %s",self.anchored)
56 T = alg.Transformation3D( alg.get_identity_rotation_3d(),
57 alg.Vector3D(0., 0., 0.) )
58 origin = alg.ReferenceFrame3D(T)
60 rb.set_reference_frame(origin)
64 Set the temperature pattern to use during the Monte Carlo
66 @param temperatures List of temperature values
67 @param iterations List with the iterations to do for each of the
69 @param cycles Number of repetitions of the
70 pattern of temperatures and iterations
72 self.temperatures = temperatures
73 self.iterations = iterations
75 log.debug(
"Temperatures %s",self.temperatures)
76 log.debug(
"Iterations %s",self.iterations)
77 log.debug(
"Cycles %s",self.cycles)
79 def set_movers(self, max_translation, max_rotation):
80 log.info(
"Setting movers for subunits")
82 for is_anchored, rb
in zip(self.anchored, self.rbs):
89 Generate the relative models form the transforms. The transforms
90 is a list with triplets [id1, id2, transform_file]
91 @param max_translation Maximum translation distance allowed for
93 @param max_rotation Maximum rotation angle allowed for the moves
95 log.info(
"Setting relative movers")
99 for d
in self.dock_transforms:
100 rb_id = representation.get_rb_name(d[1])
101 if rb_id
not in relative_names:
102 log.debug(
"Checking for %s", rb_id)
103 rb_lig = representation.get_rigid_body(self.rbs, rb_id)
104 mv = em2d.RelativePositionMover(rb_lig, max_translation,
106 relative_movers.append(mv)
107 relative_names.append(rb_id)
108 log.debug(
"added a RelativePositionMover for %s",rb_id)
109 i = relative_names.index(rb_id)
110 relative_movers[i].set_random_move_probability(
111 self.non_relative_move_prob)
112 rb_rec = representation.get_rigid_body(self.rbs,
113 representation.get_rb_name(d[0]))
114 log.debug(
"Reference added for %s: %s. ref. frame %s ",
115 rb_id, rb_rec.get_name(), rb_rec)
116 Tis = io.read_transforms(d[2])
117 relative_movers[i].add_internal_transformations(rb_rec, Tis)
121 for is_anchored, rb
in zip(self.anchored, self.rbs):
124 if(
not name
in relative_names):
125 log.debug(
"adding a RigidBodyMover for %s",name)
127 regular_movers.append(mv)
128 self.movers = regular_movers
129 self.movers += relative_movers
131 def set_moving_parameters(self, max_translations, max_rotations):
132 self.max_translations = max_translations
133 self.max_rotations = max_rotations
134 log.debug(
"Maximum translations %s",self.max_translations)
135 log.debug(
"Maximum rotations %s",self.max_rotations)
140 Run MonteCarlo sampling to generate possible states for DOMINO
143 log.info(
"Running MonteCarlo")
145 mc.set_return_best(
True)
146 for i
in xrange(self.cycles):
147 log.info(
"Cycle: %s",i)
148 for iters, T, tr, rot
in zip(self.iterations, self.temperatures,
149 self.max_translations, self.max_rotations):
151 log.debug(
"%s %s",rb.get_name(), rb.get_reference_frame())
152 self.set_movers(tr, rot)
153 mc.add_movers( self.movers)
157 log.debug(
"%s %s",rb.get_name(),rb.get_reference_frame())
160 log.info(
"MonteCarlo run finished. Time %s", time.time() - t0)
166 Run MonteCarlo sampling to generate possible states for DOMINO
169 log.info(
"Running MonteCarlo")
171 mc.set_return_best(
True)
173 for i
in xrange(self.cycles):
174 log.info(
"Cycle: %s",i)
175 for iters, T, tr, rot
in zip(self.iterations, self.temperatures,
176 self.max_translations, self.max_rotations):
177 log.debug(
"BEFORE RELATIVE MOVERS")
179 for m
in self.movers:
181 mc.add_movers( self.movers)
183 log.debug(
"Optimizing for %s iterations ...", iters)
185 log.debug(
"Finished optimizing.")
187 log.info(
"MonteCarlo run finished. Time %s", time.time() - t0)