IMP  2.3.0
The Integrative Modeling Platform
interactive_with_containers.py
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_maximum_score(.1)
24 
25 space = IMP.domino.XYZStates(
26  [IMP.algebra.Vector3D(i, 0, 0) for i in range(0, 6)])
27 
29 for p in ps:
30  pst.set_particle_states(p, space)
31 
32 m.set_log_level(IMP.base.SILENT)
33 
34 # make sure to break up the
35 mt = IMP.domino.get_merge_tree([r], pst)
36 try:
37  IMP.show_graphviz(mt)
38 except:
39  print "Unable to display graph using 'dot'"
41 rc.add_restraints([r])
44 leaf_table = IMP.domino.BranchAndBoundAssignmentsTable(pst, filters)
45 
46 # create a database to store the results
47 name = IMP.create_temporary_file_name("assignments", ".hdf5")
48 root = RMF.HDF5.create_file(name)
49 
50 # recurse down the tree getting the assignments and printing them
51 
52 
53 def get_assignments(vertex):
54  on = mt.get_out_neighbors(vertex)
55  ss = mt.get_vertex_name(vertex)
56  print "computing assignments for", ss
57  ssn = str(ss)
58  dataset = root.add_child_index_data_set_2d(ssn)
59  dataset.set_size([0, len(ss)])
61  dataset, ss, pst.get_particles(), ssn)
62  if len(on) == 0:
63  # we have a leaf
64  IMP.domino.load_leaf_assignments(ss, leaf_table, mine)
65  else:
66  # recurse on the two children
67  (ss0, a0) = get_assignments(on[0])
68  (ss1, a1) = get_assignments(on[1])
69  IMP.domino.load_merged_assignments(ss0, a0, ss1, a1, filters, mine)
70  print ss, mine.get_number_of_assignments()
71  # make sure that the cache is flushed
72  del mine
73  return (
75  dataset, ss, pst.get_particles(), ssn))
76  )
77 
78 # the root is the last vetex
79 all = get_assignments(mt.get_vertices()[-1])
80 all[1].set_was_used(True)
81 
82 print 'try: h5dump', name
Various classes to hold sets of particles.
static XYZ setup_particle(kernel::Model *m, ParticleIndex pi)
Definition: XYZ.h:51
Filter a configuration of the subset using the kernel::Model thresholds.
Do not allow two particles to be in the same state.
Store a kernel::ParticleIndexPairs.
void load_leaf_assignments(const Subset &subset, AssignmentsTable *at, AssignmentContainer *ac)
Fill in assignments for a leaf.
void load_merged_assignments(const Subset &first_subset, AssignmentContainer *first, const Subset &second_subset, AssignmentContainer *second, const SubsetFilterTablesTemp &filters, AssignmentContainer *ret)
Fill in assignments for an internal node.
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