Example of optimizing an EM2D restraint using Monte Carlo.
20 def __init__(self, m, restraints):
21 IMP.OptimizerState.__init__(self, m,
"WriteStats")
23 self.restraints = restraints
26 if (self.count != 10):
31 for r
in self.restraints:
32 print(r.get_name(), r.get_last_score())
46 chains = IMP.atom.get_by_type(prot, IMP.atom.CHAIN_TYPE)
47 print(
"there are", len(chains),
"chains in 1z5s.pdb")
50 native_chain_centers = []
55 rbd.set_coordinates_are_optimized(
True)
56 rigid_bodies.append(rbd)
57 print(
"chain has", rbd.get_number_of_members(),
58 "atoms",
"coordinates: ", rbd.get_coordinates())
59 native_chain_centers.append(rbd.get_coordinates())
64 for rbd
in rigid_bodies:
68 rbd.get_coordinates(), rotation)
74 transformation1, transformation2)
76 print(
"Writing transformed assembly")
82 native_chain_centers[0], native_chain_centers[1])
85 r01.set_name(
"distance 0-1")
87 native_chain_centers[1], native_chain_centers[2])
90 r12.set_name(
"distance 1-2")
92 native_chain_centers[2], native_chain_centers[3])
95 r23.set_name(
"distance 2-3")
97 native_chain_centers[3], native_chain_centers[0])
100 r30.set_name(
"distance 3-0")
101 print(
"Distances in the solution: d01 =",
102 d01,
"d12 =", d12,
"d23 =", d23,
"d30 =", d30)
108 IMP.em2d.read_selection_file(selection_file)]
110 print(len(em_images),
"images read")
124 params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
127 params.save_match_images =
False
131 em2d_restraint.setup(score_function, params)
132 em2d_restraint.set_images(em_images)
133 em2d_restraint.set_name(
"em2d restraint")
135 em2d_restraint.set_particles(container)
145 all_restraints = [r01, r12, r23, r30, em2d_restraints_set]
150 s.set_scoring_function(sf)
153 for rbd
in rigid_bodies:
156 print(
"MonteCarlo sampler has", s.get_number_of_movers(),
"movers")
159 o_state.set_period(10)
160 s.add_optimizer_state(o_state)
162 ostate2 = WriteStatisticsOptimizerScore(m, all_restraints)
163 s.add_optimizer_state(ostate2)
166 temperatures = [200, 100, 60, 40, 20, 5]
169 optimization_steps = 10
170 for T
in temperatures:
172 s.optimize(optimization_steps)
177 print(
"*** End optimization ***")
179 for rbd
in rigid_bodies:
180 print(
"chain has", rbd.get_number_of_members(),
181 "atoms",
"coordinates: ", rbd.get_coordinates())
182 new_centers.append(rbd.get_coordinates())
188 print(
"Distances at the end of the optimization: d01 =",
189 d01,
"d12 =", d12,
"d23 =", d23,
"d30 =", d30)