Example of optimizing an EM2D restraint using Monte Carlo.
21 IMP.OptimizerState.__init__(self)
29 o=self.get_optimizer()
31 m.show_restraint_score_statistics()
32 m.show_all_statistics()
36 def do_show(self, stream):
43 prot = atom.read_pdb(em2d.get_example_path(
"1z5s.pdb"),m,atom.ATOMPDBSelector())
47 chains = atom.get_by_type(prot,atom.CHAIN_TYPE)
48 print "there are",len(chains),
"chains in 1z5s.pdb"
51 native_chain_centers = []
54 atoms=core.get_leaves(c)
55 rbd=core.RigidBody.setup_particle(c,atoms)
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())
61 bb=alg.BoundingBox3D(alg.Vector3D(-25, -40,-60),
62 alg.Vector3D( 25, 40, 60))
64 for rbd
in rigid_bodies:
66 rotation= alg.get_random_rotation_3d()
67 transformation1=alg.get_rotation_about_point(rbd.get_coordinates(),rotation)
69 transformation2=alg.Transformation3D(alg.get_random_vector_in(bb))
71 final_transformation = alg.compose(transformation1,transformation2)
72 core.transform(rbd,final_transformation)
73 print "Writing transformed assembly"
74 atom.write_pdb (prot,
"1z5s-transformed.pdb")
78 d01 = alg.get_distance(native_chain_centers[0],native_chain_centers[1])
79 r01 = core.DistanceRestraint(core.Harmonic(d01,1),chains[0],chains[1])
80 r01.set_name(
"distance 0-1")
81 d12 = alg.get_distance(native_chain_centers[1],native_chain_centers[2])
82 r12 = core.DistanceRestraint(core.Harmonic(d12,1),chains[1],chains[2])
83 r12.set_name(
"distance 1-2")
84 d23 = alg.get_distance(native_chain_centers[2],native_chain_centers[3])
85 r23 = core.DistanceRestraint(core.Harmonic(d23,1),chains[2],chains[3])
86 r23.set_name(
"distance 2-3")
87 d30 = alg.get_distance(native_chain_centers[3],native_chain_centers[0])
88 r30 = core.DistanceRestraint(core.Harmonic(d30,1),chains[3],chains[0])
89 r30.set_name(
"distance 3-0")
90 print "Distances in the solution: d01 =", \
91 d01,
"d12 =",d12,
"d23 =",d23,
"d30 =",d30
94 print "adding distance restraints "
95 for r
in [r01,r12,r23,r30]:
97 print "model has ",m.get_number_of_restraints(),
"restraints"
100 srw = em2d.SpiderImageReaderWriter()
101 selection_file=em2d.get_example_path(
"all-1z5s-projections.sel")
103 em2d.read_selection_file(selection_file)]
104 em_images =em2d.read_images(images_to_read_names,srw)
105 print len(em_images),
"images read"
107 em2d_restraint = em2d.Em2DRestraint()
115 params = em2d.Em2DRestraintParameters(apix,resolution,n_projections)
119 params.coarse_registration_method = IMP.em2d.ALIGN2D_PREPROCESSING
122 params.save_match_images =
False
126 em2d_restraint.setup(score_function, params)
127 em2d_restraint.set_images(em_images)
128 em2d_restraint.set_name(
"em2d restraint")
130 em2d_restraint.set_particles(container)
139 print "adding em2d restraint "
140 m.add_restraint(em2d_restraints_set)
142 print "model has ",m.get_number_of_restraints(),
"restraints"
149 for rbd
in rigid_bodies:
150 movers.append(core.RigidBodyMover(rbd,5,2))
152 print "MonteCarlo sampler has",s.get_number_of_movers(),
"movers"
154 o_state=atom.WritePDBOptimizerState(chains,
"intermediate-step-%1%.pdb")
155 o_state.set_skip_steps(10)
156 s.add_optimizer_state(o_state)
158 ostate2 = WriteStatisticsOptimizerScore()
159 s.add_optimizer_state(ostate2)
163 temperatures=[200,100,60,40,20,5]
166 optimization_steps = 10
167 for T
in temperatures:
169 s.optimize(optimization_steps)
170 atom.write_pdb(prot,
"solution.pdb")
174 print "*** End optimization ***"
176 for rbd
in rigid_bodies:
177 print "chain has",rbd.get_number_of_members(), \
178 "atoms",
"coordinates: ",rbd.get_coordinates()
179 new_centers.append(rbd.get_coordinates())
181 d01 = alg.get_distance(new_centers[0],new_centers[1])
182 d12 = alg.get_distance(new_centers[1],new_centers[2])
183 d23 = alg.get_distance(new_centers[2],new_centers[3])
184 d30 = alg.get_distance(new_centers[3],new_centers[0])
185 print "Distances at the end of the optimization: d01 =", \
186 d01,
"d12 =",d12,
"d23 =",d23,
"d30 =",d30