Example of optimizing an EM2D restraint using Monte Carlo.
5 from __future__
import print_function
20 def __init__(self, m, restraints):
21 IMP.OptimizerState.__init__(self, m,
"WriteStats")
23 self.restraints = restraints
26 if (self.count != 10):
31 o = self.get_optimizer()
33 for r
in self.restraints:
34 print(r.get_name(), r.get_last_score())
49 print(
"there are", len(chains),
"chains in 1z5s.pdb")
52 native_chain_centers = []
57 rbd.set_coordinates_are_optimized(
True)
58 rigid_bodies.append(rbd)
59 print(
"chain has", rbd.get_number_of_members(), \
60 "atoms",
"coordinates: ", rbd.get_coordinates())
61 native_chain_centers.append(rbd.get_coordinates())
66 for rbd
in rigid_bodies:
70 rbd.get_coordinates(), rotation)
76 transformation1, transformation2)
78 print(
"Writing transformed assembly")
84 native_chain_centers[0], native_chain_centers[1])
87 r01.set_name(
"distance 0-1")
89 native_chain_centers[1], native_chain_centers[2])
92 r12.set_name(
"distance 1-2")
94 native_chain_centers[2], native_chain_centers[3])
97 r23.set_name(
"distance 2-3")
99 native_chain_centers[3], native_chain_centers[0])
102 r30.set_name(
"distance 3-0")
103 print(
"Distances in the solution: d01 =", \
104 d01,
"d12 =", d12,
"d23 =", d23,
"d30 =", d30)
107 print(
"adding distance restraints ")
108 for r
in [r01, r12, r23, r30]:
110 print(
"model has ", m.get_number_of_restraints(),
"restraints")
116 IMP.em2d.read_selection_file(selection_file)]
118 print(len(em_images),
"images read")
132 params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
135 params.save_match_images =
False
139 em2d_restraint.setup(score_function, params)
140 em2d_restraint.set_images(em_images)
141 em2d_restraint.set_name(
"em2d restraint")
143 em2d_restraint.set_particles(container)
152 print(
"adding em2d restraint ")
153 m.add_restraint(em2d_restraints_set)
155 print(
"model has ", m.get_number_of_restraints(),
"restraints")
162 for rbd
in rigid_bodies:
165 print(
"MonteCarlo sampler has", s.get_number_of_movers(),
"movers")
168 o_state.set_period(10)
169 s.add_optimizer_state(o_state)
171 ostate2 = WriteStatisticsOptimizerScore(m, m.get_restraints())
172 s.add_optimizer_state(ostate2)
175 temperatures = [200, 100, 60, 40, 20, 5]
178 optimization_steps = 10
179 for T
in temperatures:
181 s.optimize(optimization_steps)
186 print(
"*** End optimization ***")
188 for rbd
in rigid_bodies:
189 print(
"chain has", rbd.get_number_of_members(), \
190 "atoms",
"coordinates: ", rbd.get_coordinates())
191 new_centers.append(rbd.get_coordinates())
197 print(
"Distances at the end of the optimization: d01 =", \
198 d01,
"d12 =", d12,
"d23 =", d23,
"d30 =", d30)