IMP Reference Guide  develop.879b8d2544,2020/09/29 The Integrative Modeling Platform
em/analyze_convergence.py

Analyze the convergence of the IMP.em.FitRestraint. The script builds a simple model and then displays the derivatives, em score and how well conjugate gradients converges under various displacements of the model.

1 ## \example em/analyze_convergence.py
2 # Analyze the convergence of the IMP.em.FitRestraint. The script builds a
3 # simple model and then displays the derivatives, em score and how well
4 # conjugate gradients converges under various displacements of the model.
5
6 from __future__ import print_function
7 import IMP.display
8 import IMP.em
9 import sys
10
11 IMP.setup_from_argv(sys.argv, "analyze convergence")
12
13 use_rigid_bodies = True
14 bd = 10
16
17 m = IMP.Model()
18 p = IMP.Particle(m)
22
23 # Set up the particle as either a rigid body or a simple ball
24 if use_rigid_bodies:
25  prb = IMP.Particle(m)
26  prb.set_name("rigid body")
27  d.set_coordinates(IMP.algebra.Vector3D(0, 0, 0))
31  print("initial frame", drb.get_reference_frame())
32  fp = prb
33  drb.set_coordinates_are_optimized(True)
34  to_move = drb
35  fp = d
36 else:
37  fp = d
38  to_move = d
39  d.set_coordinates_are_optimized(True)
40
41
45
49 dmap.set_particles([p])
50
51 dmap.resample()
52 # computes statistic stuff about the map and insert it in the header
53 dmap.calcRMS()
55 rs = IMP.RestraintSet(m)
56 # rs.set_weight(.003)
57
58 # if rigid bodies are used, we need to define a refiner as
59 # FitRestraint doesn't support just passing all the geometry
60 r = IMP.em.FitRestraint([fp], dmap)
63 g.set_name("deriv")
64 w = IMP.display.PymolWriter("derivatives.pym")
65 # kind of abusive
66 steps = 4
67 m.set_log_level(IMP.SILENT)
68
70 opt.set_scoring_function(sf)
71
72 def try_point(i, j, k):
73  print("trying", i, j, k)
74  vc = IMP.algebra.Vector3D(i, j, k)
75  to_move.set_coordinates(vc)
76  # display the score at this position
78  cg.set_name("score")
79  v = sf.evaluate(True)
80  cg.set_color(IMP.display.get_hot_color(v))
82  print("score and derivatives", v, to_move.get_derivatives())
84
85  opt.optimize(10)
86  print("after", d.get_coordinates())
87  mag = to_move.get_coordinates().get_magnitude()
88
89  converge_color = IMP.display.get_gray_color(1.0 / (1.0 + mag))
90  # display the distance after optimization at this position
92  sg.set_color(converge_color)
93  sg.set_name("converge")