IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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
7import IMP.domino
8import IMP.algebra
9import IMP.container
10import IMP
11import RMF
12import sys
13
14IMP.setup_from_argv(sys.argv, "interactive with containers")
15
16m = IMP.Model()
17
18# create some particles
20 for x in range(0, 3)])
21
24 m, [(ps[i[0]], ps[i[1]]) for i in [(0, 1), (1, 2)]])
25print([(m.get_particle_name(p[0]), m.get_particle_name(p[1]))
26 for p in lpc.get_contents()])
28r.set_maximum_score(.1)
29
31 [IMP.algebra.Vector3D(i, 0, 0) for i in range(0, 6)])
32
34for p in ps:
35 pst.set_particle_states(m.get_particle(p), space)
36
37m.set_log_level(IMP.SILENT)
38
39# make sure to break up the
40mt = IMP.domino.get_merge_tree([r], pst)
41try:
43except:
44 print("Unable to display graph using 'dot'")
46rc.add_restraints([r])
49leaf_table = IMP.domino.BranchAndBoundAssignmentsTable(pst, filters)
50
51# create a database to store the results
52name = IMP.create_temporary_file_name("assignments", ".hdf5")
53root = RMF.HDF5.create_file(name)
54
55# recurse down the tree getting the assignments and printing them
56
57
58def 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
84# the root is the last vertex
85all = get_assignments(mt.get_vertices()[-1])
86all[1].set_was_used(True)
87
88print('try: h5dump', name)
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Class to handle individual particles of a Model object.
Definition Particle.h:45
Store a list of ParticleIndexPairs.
Applies a PairScore to each Pair in a list.
Score distance between two particle centers using a harmonic function.
static XYZ setup_particle(Model *m, ParticleIndex pi)
Definition XYZ.h:51
Do not allow two particles to be in the same state.
Store the assignments in an HDF5DataSet.
Filter a configuration of the subset using the Model thresholds.
Store the assignments in an HDF5DataSet.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
VectorD< 3 > Vector3D
Definition VectorD.h:407
Various classes to hold sets of particles.
Divide-and-conquer inferential optimization in discrete space.
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.
void load_leaf_assignments(const Subset &subset, AssignmentsTable *at, AssignmentContainer *ac)
Fill in assignments for a leaf.
MergeTree get_merge_tree(ScoringFunctionAdaptor input, const ParticleStatesTable *pst)
std::string create_temporary_file_name(std::string prefix="imp_temp", std::string suffix="")
Create a temporary file.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.
ParticleIndexes get_indexes(const ParticlesTemp &ps)
Get the indexes from a list of particles.
std::string show_graphviz(Graph g)