Example of optimizing an EM2D restraint using Monte Carlo.
5 from __future__
import print_function
22 def __init__(self, m, restraints):
23 IMP.OptimizerState.__init__(self, m,
"WriteStats")
25 self.restraints = restraints
28 if (self.count != 10):
33 o = self.get_optimizer()
35 for r
in self.restraints:
36 print(r.get_name(), r.get_last_score())
50 chains = IMP.atom.get_by_type(prot, IMP.atom.CHAIN_TYPE)
51 print(
"there are", len(chains),
"chains in 1z5s.pdb")
54 native_chain_centers = []
59 rbd.set_coordinates_are_optimized(
True)
60 rigid_bodies.append(rbd)
61 print(
"chain has", rbd.get_number_of_members(), \
62 "atoms",
"coordinates: ", rbd.get_coordinates())
63 native_chain_centers.append(rbd.get_coordinates())
68 for rbd
in rigid_bodies:
72 rbd.get_coordinates(), rotation)
78 transformation1, transformation2)
80 print(
"Writing transformed assembly")
86 native_chain_centers[0], native_chain_centers[1])
89 r01.set_name(
"distance 0-1")
91 native_chain_centers[1], native_chain_centers[2])
94 r12.set_name(
"distance 1-2")
96 native_chain_centers[2], native_chain_centers[3])
99 r23.set_name(
"distance 2-3")
101 native_chain_centers[3], native_chain_centers[0])
104 r30.set_name(
"distance 3-0")
105 print(
"Distances in the solution: d01 =", \
106 d01,
"d12 =", d12,
"d23 =", d23,
"d30 =", d30)
112 IMP.em2d.read_selection_file(selection_file)]
114 print(len(em_images),
"images read")
128 params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
131 params.save_match_images =
False
135 em2d_restraint.setup(score_function, params)
136 em2d_restraint.set_images(em_images)
137 em2d_restraint.set_name(
"em2d restraint")
139 em2d_restraint.set_particles(container)
149 all_restraints = [r01, r12, r23, r30, em2d_restraints_set]
154 s.set_scoring_function(sf)
157 for rbd
in rigid_bodies:
160 print(
"MonteCarlo sampler has", s.get_number_of_movers(),
"movers")
163 o_state.set_period(10)
164 s.add_optimizer_state(o_state)
166 ostate2 = WriteStatisticsOptimizerScore(m, all_restraints)
167 s.add_optimizer_state(ostate2)
170 temperatures = [200, 100, 60, 40, 20, 5]
173 optimization_steps = 10
174 for T
in temperatures:
176 s.optimize(optimization_steps)
181 print(
"*** End optimization ***")
183 for rbd
in rigid_bodies:
184 print(
"chain has", rbd.get_number_of_members(), \
185 "atoms",
"coordinates: ", rbd.get_coordinates())
186 new_centers.append(rbd.get_coordinates())
192 print(
"Distances at the end of the optimization: d01 =", \
193 d01,
"d12 =", d12,
"d23 =", d23,
"d30 =", d30)