IMP  2.3.1
The Integrative Modeling Platform
interactive.py
1 ## \example domino/interactive.py
2 # IMP::domino::DominoSampler supports an interactive mode where by each step of the sampling process is called explicitly and all intermediate results are exposed. This usage mode can be used to help understand how domino behaves as well as to distribute a domino computation to multiple cores or multiple machines. For the latter, it is useful to use the IMP::domino::get_assignments() and IMP::domino::set_assignments() functions to save the states to a file.
3 #
4 
5 import IMP.domino
6 import IMP.algebra
7 import IMP.container
8 import IMP
9 
10 m = IMP.kernel.Model()
11 
12 # create some particles
13 ps = [IMP.core.XYZ.setup_particle(IMP.kernel.Particle(m)) for x in range(0, 3)]
14 
17  [(ps[i[0]], ps[i[1]]) for i in [(0, 1), (1, 2)]])
18 print [(p[0].get_name(), p[1].get_name()) for p in lpc.get_particle_pairs()]
20 r.set_maximum_score(.1)
21 
22 space = IMP.domino.XYZStates(
23  [IMP.algebra.Vector3D(i, 0, 0) for i in range(0, 6)])
24 
26 for p in ps:
27  pst.set_particle_states(p, space)
28 
29 m.set_log_level(IMP.base.SILENT)
30 
31 # make sure to break up the
32 mt = IMP.domino.get_merge_tree([r], pst)
33 try:
34  IMP.show_graphviz(mt)
35 except:
36  print "Unable to display graph using 'dot'"
37 
38 ds = IMP.domino.DominoSampler(m, pst)
39 # use the default setup for filters
40 ds.set_scoring_function([r])
41 ds.set_merge_tree(mt)
42 ds.set_log_level(IMP.base.SILENT)
43 
44 # recurse down the tree getting the assignments and printing them
45 
46 
47 def get_assignments(vertex):
48  on = mt.get_out_neighbors(vertex)
49  if len(on) == 0:
50  # we have a leaf
51  ret = ds.get_vertex_assignments(vertex)
52  else:
53  # recurse on the two children
54  if on[0] > on[1]:
55  # the get_vertex_assignment methods expects the children in sorted
56  # order
57  on = [on[1], on[0]]
58  a0 = get_assignments(on[0])
59  a1 = get_assignments(on[1])
60  ret = ds.get_vertex_assignments(vertex, a0, a1)
61  print mt.get_vertex_name(vertex), [str(r) for r in ret]
62  return ret
63 
64 # the root is the last vetex
65 get_assignments(mt.get_vertices()[-1])
66 
67 
68 schedule = []
69 # we could instead decompose the tree into independent sets of jobs
70 
71 
72 def schedule_job(vertex):
73  # first figure out the maximum phase for my children, then add me to the
74  # next higher phase
75  on = mt.get_out_neighbors(vertex)
76  max_child_time = -1
77  for n in on:
78  max_child_time = max(schedule_job(n), max_child_time)
79  my_time = max_child_time + 1
80  while len(schedule) < my_time + 1:
81  schedule.append([])
82  # add myself to the next free phase
83  schedule[my_time].append(vertex)
84  return my_time
85 
86 schedule_job(mt.get_vertices()[-1])
87 print "The merging can be scheduled as", schedule
Various classes to hold sets of particles.
Sample best solutions using Domino.
Definition: DominoSampler.h:32
static XYZ setup_particle(kernel::Model *m, ParticleIndex pi)
Definition: XYZ.h:51
Store a kernel::ParticleIndexPairs.
Class to handle individual model particles.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
MergeTree get_merge_tree(const SubsetGraph &junction_tree)
VectorD< 3 > Vector3D
Definition: VectorD.h:395
Applies a PairScore to each Pair in a list.
Divide-and-conquer inferential optimization in discrete space.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73