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