IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
domino_approach.py
1## \example domino/domino_approach.py
2# Optimize six particles
3
4# NOT FULLY IMPLEMENTED YET!
5import IMP
6import IMP.domino
7import IMP.core
8import sys
9
10IMP.setup_from_argv(sys.argv, "domino approach")
11
12
13def optimize_subsets(subsets):
15 for subset in subsets:
16 None
17 # TODO - do the actual sampling
18 # combine back to ParticleStatesTable
19 # there is now a write_particles_binary (multiple states into one file)
20 return pst
21
22
23def get_subsets(ps):
24 mdl = ps[0].get_model()
26 mdl.get_root_restraint_set(), ps)
27 jt = IMP.domino.get_junction_tree(inter_graph)
28 return IMP.domino.get_subsets(jt)
29
30
31def setup_scoring_function(ps):
32 m = ps[0].get_model()
33 pairs = [[0, 1], [0, 2], [1, 2], [2, 3], [3, 4], [4, 5], [3, 5]]
34 sf = IMP.core.Harmonic(1.0, 1)
35 rs = IMP.RestraintSet(m)
36 for pair in pairs:
37 r = IMP.core.DistanceRestraint(m, sf, ps[pair[0]], ps[pair[1]])
38 rs.add_restraint(r)
39 return rs
40
41# Initiate a set of states for each particle in ps
42
43
44def initiate_configuration(domino_smp, ps):
45 # Generate a discrete set of states
46 vector_states = []
47 for i in range(0, 4):
48 vector_states.append(IMP.algebra.Vector3D(i, 0, 0))
49 vector_states.append(IMP.algebra.Vector3D(i, 1, 0))
50 # Generate a discrete set of states for each of the particles
51 states = IMP.domino.XYZStates(vector_states)
52 # Map states of particles
53 for p in ps:
54 domino_smp.set_particle_states(p, states)
55
56
57sys.exit()
58# REPRESENTATION
59# 1. setting up the representation (6 particles)
60mdl = IMP.Model()
61mdl.set_log_level(IMP.SILENT)
62ps = []
63for i in range(0, 6):
64 p = IMP.Particle(mdl)
66 ps.append(p)
67
68# SCORING
69# 1. setting up the scoring function
70rs = setup_scoring_function(ps)
71
72# 1. get the subsets
73subsets = get_subsets(ps)
74
75# optimize each one (returning ParticleStatesTable)
76pst = optimize_subsets(subsets)
77sys.exit()
78
79# subsets=[]
80
81# jt.show()
82
83# 2. sample each subset
84# 3. gathering
85
86
87# OPTIMIZATION
88# 1. load domino sampler and set required properties
89domino_smp = IMP.domino.DominoSampler(m)
90domino_smp.set_restraints([rs])
91domino_smp.set_maximum_score(.2)
92
93# 2. initiate configuration
94initiate_configuration(domino_smp, ps)
95
96
97# 3. construct subset of variables AND
98# optimize subsets of variables subject to the discrete sampling space AND
99# gather subset of variables into global solutions
100cs = domino_smp.create_sample()
101
102# ANALYSE
103# 4. report solutions
104print("Found ", cs.get_number_of_configurations(), "solutions")
105for i in range(cs.get_number_of_configurations()):
106 cs.load_configuration(i)
107 # print the configuration:
108 print("solution number:", i, " scored:", rs.evaluate(False))
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
Object used to hold a set of restraints.
Distance restraint between two particles.
Harmonic function (symmetric about the mean)
static XYZ setup_particle(Model *m, ParticleIndex pi)
Definition XYZ.h:51
Sample best solutions using Domino.
VectorD< 3 > Vector3D
Definition VectorD.h:407
Basic functionality that is expected to be used by a wide variety of IMP users.
Divide-and-conquer inferential optimization in discrete space.
Subsets get_subsets(const SubsetGraph &g)
Gets all of the Subsets of a SubsetGraph.
InteractionGraph get_interaction_graph(ScoringFunctionAdaptor rs, const ParticleStatesTable *pst)
SubsetGraph get_junction_tree(const InteractionGraph &ig)
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.