IMP  2.1.1
The Integrative Modeling Platform
domino/interactive_with_containers.py

Run domino storing the intermediate and final results in an hdf5 database. This has the advantage that if you interrupt the run at any point, you have a list of everything computed so far and so can get some more idea of what is going on.

1 ## \example domino/interactive_with_containers.py
2 # Run domino storing the intermediate and final results in an hdf5
3 # database. This has the advantage that if you interrupt the run at any
4 # point, you have a list of everything computed so far and so can get some
5 # more idea of what is going on.
6 
7 import IMP.domino
8 import IMP.algebra
9 import IMP.container
10 import IMP
11 import RMF
12 
13 m = IMP.kernel.Model()
14 
15 # create some particles
16 ps = [IMP.core.XYZ.setup_particle(IMP.kernel.Particle(m)) for x in range(0, 3)]
17 
20  [(ps[i[0]], ps[i[1]]) for i in [(0, 1), (1, 2)]])
21 print [(p[0].get_name(), p[1].get_name()) for p in lpc.get_particle_pairs()]
23 r.set_model(m)
24 r.set_maximum_score(.1)
25 
26 space = IMP.domino.XYZStates(
27  [IMP.algebra.Vector3D(i, 0, 0) for i in range(0, 6)])
28 
30 for p in ps:
31  pst.set_particle_states(p, space)
32 
33 m.set_log_level(IMP.base.SILENT)
34 
35 # make sure to break up the
36 mt = IMP.domino.get_merge_tree([r], pst)
37 try:
38  IMP.show_graphviz(mt)
39 except:
40  print "Unable to display graph using 'dot'"
42 rc.add_restraints([r])
45 leaf_table = IMP.domino.BranchAndBoundAssignmentsTable(pst, filters)
46 
47 # create a database to store the results
48 name = IMP.create_temporary_file_name("assignments", ".hdf5")
49 root = RMF.HDF5.create_file(name)
50 
51 # recurse down the tree getting the assignments and printing them
52 
53 
54 def get_assignments(vertex):
55  on = mt.get_out_neighbors(vertex)
56  ss = mt.get_vertex_name(vertex)
57  print "computing assignments for", ss
58  ssn = str(ss)
59  dataset = root.add_child_index_data_set_2d(ssn)
60  dataset.set_size([0, len(ss)])
62  dataset, ss, pst.get_particles(), ssn)
63  if len(on) == 0:
64  # we have a leaf
65  IMP.domino.load_leaf_assignments(ss, leaf_table, mine)
66  else:
67  # recurse on the two children
68  (ss0, a0) = get_assignments(on[0])
69  (ss1, a1) = get_assignments(on[1])
70  IMP.domino.load_merged_assignments(ss0, a0, ss1, a1, filters, mine)
71  print ss, mine.get_number_of_assignments()
72  # make sure that the cache is flushed
73  del mine
74  return (ss, IMP.domino.ReadHDF5AssignmentContainer(dataset, ss, pst.get_particles(), ssn))
75 
76 # the root is the last vetex
77 all = get_assignments(mt.get_vertices()[-1])
78 all[1].set_was_used(True)
79 
80 print 'try: h5dump', name