IMP logo
IMP Reference Guide  2.20.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 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  m, [(ps[i[0]], ps[i[1]]) for i in [(0, 1), (1, 2)]])
26 print([(m.get_particle_name(p[0]), m.get_particle_name(p[1]))
27  for p in lpc.get_contents()])
29 r.set_maximum_score(.1)
30 
31 space = IMP.domino.XYZStates(
32  [IMP.algebra.Vector3D(i, 0, 0) for i in range(0, 6)])
33 
35 for p in ps:
36  pst.set_particle_states(m.get_particle(p), space)
37 
38 m.set_log_level(IMP.SILENT)
39 
40 # make sure to break up the
41 mt = IMP.domino.get_merge_tree([r], pst)
42 try:
44 except:
45  print("Unable to display graph using 'dot'")
47 rc.add_restraints([r])
50 leaf_table = IMP.domino.BranchAndBoundAssignmentsTable(pst, filters)
51 
52 # create a database to store the results
53 name = IMP.create_temporary_file_name("assignments", ".hdf5")
54 root = RMF.HDF5.create_file(name)
55 
56 # recurse down the tree getting the assignments and printing them
57 
58 
59 def get_assignments(vertex):
60  on = mt.get_out_neighbors(vertex)
61  ss = mt.get_vertex_name(vertex)
62  print("computing assignments for", ss)
63  ssn = str(ss)
64  dataset = root.add_child_index_data_set_2d(ssn)
65  dataset.set_size([0, len(ss)])
67  dataset, ss, pst.get_particles(), ssn)
68  if len(on) == 0:
69  # we have a leaf
70  IMP.domino.load_leaf_assignments(ss, leaf_table, mine)
71  else:
72  # recurse on the two children
73  (ss0, a0) = get_assignments(on[0])
74  (ss1, a1) = get_assignments(on[1])
75  IMP.domino.load_merged_assignments(ss0, a0, ss1, a1, filters, mine)
76  print(ss, mine.get_number_of_assignments())
77  # make sure that the cache is flushed
78  del mine
79  return (
81  dataset, ss, pst.get_particles(), ssn))
82  )
83 
84 
85 # the root is the last vertex
86 all = get_assignments(mt.get_vertices()[-1])
87 all[1].set_was_used(True)
88 
89 print('try: h5dump', name)
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
Various classes to hold sets of particles.
Filter a configuration of the subset using the Model thresholds.
Store the assignments in an HDF5DataSet.
Score distance between two particle centers using a harmonic function.
static XYZ setup_particle(Model *m, ParticleIndex pi)
Definition: XYZ.h:51
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
Do not allow two particles to be in the same state.
Store a list of ParticleIndexPairs.
ParticleIndexPairs get_indexes(const ParticlePairsTemp &ps)
Get the indexes from a list of particle pairs.
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.
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:425
Class to handle individual particles of a Model object.
Definition: Particle.h:43
std::string show_graphviz(Graph g)
Store the assignments in an HDF5DataSet.
Applies a PairScore to each Pair in a list.
Divide-and-conquer inferential optimization in discrete space.
std::string create_temporary_file_name(std::string prefix="imp_temp", std::string suffix="")
Create a temporary file.