IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
interactive.py
1## \example domino/interactive.py
2# IMP::domino::DominoSampler supports an interactive mode whereby each step
3# of the sampling process is called explicitly and all intermediate results
4# are exposed. This usage mode can be used to help understand how domino
5# behaves as well as to distribute a domino computation to multiple cores
6# or multiple machines. For the latter, it is useful to use the
7# IMP::domino::get_assignments() and IMP::domino::set_assignments()
8# functions to save the states to a file.
9
10import IMP.domino
11import IMP.algebra
12import IMP.container
13import IMP
14import sys
15
16IMP.setup_from_argv(sys.argv, "interactive")
17
18m = IMP.Model()
19
20# create some particles
22 for x in range(0, 3)])
23
26 m, [(ps[i[0]], ps[i[1]]) for i in [(0, 1), (1, 2)]])
27print([(m.get_particle_name(p[0]), m.get_particle_name(p[1]))
28 for p in lpc.get_contents()])
30r.set_maximum_score(.1)
31
33 [IMP.algebra.Vector3D(i, 0, 0) for i in range(0, 6)])
34
36for p in ps:
37 pst.set_particle_states(m.get_particle(p), space)
38
39m.set_log_level(IMP.SILENT)
40
41# make sure to break up the
42mt = IMP.domino.get_merge_tree([r], pst)
43try:
45except:
46 print("Unable to display graph using 'dot'")
47
48ds = IMP.domino.DominoSampler(m, pst)
49# use the default setup for filters
50ds.set_restraints([r])
51ds.set_scoring_function([r])
52ds.set_merge_tree(mt)
53ds.set_log_level(IMP.SILENT)
54
55# recurse down the tree getting the assignments and printing them
56
57
58def get_assignments(vertex):
59 on = mt.get_out_neighbors(vertex)
60 if len(on) == 0:
61 # we have a leaf
62 ret = ds.get_vertex_assignments(vertex)
63 else:
64 # recurse on the two children
65 if on[0] > on[1]:
66 # the get_vertex_assignment methods expects the children in sorted
67 # order
68 on = [on[1], on[0]]
69 a0 = get_assignments(on[0])
70 a1 = get_assignments(on[1])
71 ret = ds.get_vertex_assignments(vertex, a0, a1)
72 print(mt.get_vertex_name(vertex), [str(r) for r in ret])
73 return ret
74
75
76# the root is the last vertex
77get_assignments(mt.get_vertices()[-1])
78
79schedule = []
80# we could instead decompose the tree into independent sets of jobs
81
82
83def schedule_job(vertex):
84 # first figure out the maximum phase for my children, then add me to the
85 # next higher phase
86 on = mt.get_out_neighbors(vertex)
87 max_child_time = -1
88 for n in on:
89 max_child_time = max(schedule_job(n), max_child_time)
90 my_time = max_child_time + 1
91 while len(schedule) < my_time + 1:
92 schedule.append([])
93 # add myself to the next free phase
94 schedule[my_time].append(vertex)
95 return my_time
96
97
98schedule_job(mt.get_vertices()[-1])
99print("The merging can be scheduled as", schedule)
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Class to handle individual particles of a Model object.
Definition Particle.h:45
Store a list of ParticleIndexPairs.
Applies a PairScore to each Pair in a list.
Score distance between two particle centers using a harmonic function.
static XYZ setup_particle(Model *m, ParticleIndex pi)
Definition XYZ.h:51
Sample best solutions using Domino.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
VectorD< 3 > Vector3D
Definition VectorD.h:407
Various classes to hold sets of particles.
Divide-and-conquer inferential optimization in discrete space.
MergeTree get_merge_tree(ScoringFunctionAdaptor input, const ParticleStatesTable *pst)
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.
ParticleIndexes get_indexes(const ParticlesTemp &ps)
Get the indexes from a list of particles.
std::string show_graphviz(Graph g)