IMP logo
IMP Reference Guide  2.6.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 a better 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 a
5 # better idea of what is going on.
6 
7 from __future__ import print_function
8 import IMP.domino
9 import IMP.algebra
10 import IMP.container
11 import IMP
12 import RMF
13 import sys
14 
15 IMP.setup_from_argv(sys.argv, "interactive with containers")
16 
17 m = IMP.Model()
18 
19 # create some particles
21  for x in range(0, 3)])
22 
25  [(ps[i[0]], ps[i[1]]) for i in [(0, 1), (1, 2)]])
26 print([(p[0].get_name(), p[1].get_name()) for p in lpc.get_particle_pairs()])
28 r.set_maximum_score(.1)
29 
30 space = IMP.domino.XYZStates(
31  [IMP.algebra.Vector3D(i, 0, 0) for i in range(0, 6)])
32 
34 for p in ps:
35  pst.set_particle_states(m.get_particle(p), space)
36 
37 m.set_log_level(IMP.SILENT)
38 
39 # make sure to break up the
40 mt = IMP.domino.get_merge_tree([r], pst)
41 try:
43 except:
44  print("Unable to display graph using 'dot'")
46 rc.add_restraints([r])
49 leaf_table = IMP.domino.BranchAndBoundAssignmentsTable(pst, filters)
50 
51 # create a database to store the results
52 name = IMP.create_temporary_file_name("assignments", ".hdf5")
53 root = RMF.HDF5.create_file(name)
54 
55 # recurse down the tree getting the assignments and printing them
56 
57 
58 def get_assignments(vertex):
59  on = mt.get_out_neighbors(vertex)
60  ss = mt.get_vertex_name(vertex)
61  print("computing assignments for", ss)
62  ssn = str(ss)
63  dataset = root.add_child_index_data_set_2d(ssn)
64  dataset.set_size([0, len(ss)])
66  dataset, ss, pst.get_particles(), ssn)
67  if len(on) == 0:
68  # we have a leaf
69  IMP.domino.load_leaf_assignments(ss, leaf_table, mine)
70  else:
71  # recurse on the two children
72  (ss0, a0) = get_assignments(on[0])
73  (ss1, a1) = get_assignments(on[1])
74  IMP.domino.load_merged_assignments(ss0, a0, ss1, a1, filters, mine)
75  print(ss, mine.get_number_of_assignments())
76  # make sure that the cache is flushed
77  del mine
78  return (
80  dataset, ss, pst.get_particles(), ssn))
81  )
82 
83 # the root is the last vetex
84 all = get_assignments(mt.get_vertices()[-1])
85 all[1].set_was_used(True)
86 
87 print('try: h5dump', name)