IMP  2.0.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 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.
3 
4 import IMP.domino
5 import IMP.algebra
6 import IMP.container
7 import IMP
8 import RMF
9 
10 m = IMP.Model()
11 
12 # create some particles
13 ps=[IMP.core.XYZ.setup_particle(IMP.Particle(m)) for x in range(0,3)]
14 
16 lpc= IMP.container.ListPairContainer([(ps[i[0]], ps[i[1]]) for i in [(0,1), (1,2)]])
17 print [(p[0].get_name(), p[1].get_name()) for p in lpc.get_particle_pairs()]
19 r.set_model(m)
20 r.set_maximum_score(.1)
21 
22 space= IMP.domino.XYZStates([IMP.algebra.Vector3D(i, 0, 0) for i in range(0,6)])
23 
25 for p in ps:
26  pst.set_particle_states(p, space)
27 
28 m.set_log_level(IMP.base.SILENT)
29 
30 # make sure to break up the
31 mt= IMP.domino.get_merge_tree([r], pst)
32 try:
33  IMP.show_graphviz(mt)
34 except:
35  print "Unable to display graph using 'dot'"
37 rc.add_restraints([r])
40 leaf_table=IMP.domino.BranchAndBoundAssignmentsTable(pst, filters)
41 
42 # create a database to store the results
43 name=IMP.create_temporary_file_name("assignments", ".hdf5")
44 root= RMF.HDF5.create_file(name)
45 
46 # recurse down the tree getting the assignments and printing them
47 def get_assignments(vertex):
48  on= mt.get_out_neighbors(vertex)
49  ss= mt.get_vertex_name(vertex)
50  print "computing assignments for", ss
51  ssn= str(ss)
52  dataset= root.add_child_index_data_set_2d(ssn)
53  dataset.set_size([0, len(ss)])
54  mine= IMP.domino.WriteHDF5AssignmentContainer(dataset, ss, pst.get_particles(), ssn)
55  if len(on)==0:
56  # we have a leaf
57  IMP.domino.load_leaf_assignments(ss, leaf_table, mine)
58  else:
59  # recurse on the two children
60  (ss0, a0)= get_assignments(on[0])
61  (ss1, a1)= get_assignments(on[1])
62  IMP.domino.load_merged_assignments(ss0, a0, ss1, a1, filters, mine)
63  print ss, mine.get_number_of_assignments()
64  # make sure that the cache is flushed
65  del mine
66  return (ss, IMP.domino.ReadHDF5AssignmentContainer(dataset, ss, pst.get_particles(), ssn))
67 
68 # the root is the last vetex
69 all=get_assignments(mt.get_vertices()[-1])
70 all[1].set_was_used(True)
71 
72 print 'try: h5dump', name