IMP  2.3.0
The Integrative Modeling Platform
domino/domino_approach.py

Optimize six particles

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 
11 def optimize_subsets(subsets):
13  for subset in subsets:
14  None
15  # TODO - do the actual sampling
16  # combine back to ParticleStatesTable
17  # there is now a write_particles_binary (multiple states into one file)
18  return pst
19 
20 
21 def get_subsets(ps):
22  mdl = ps[0].get_model()
24  mdl.get_root_restraint_set(), ps)
25  jt = IMP.domino.get_junction_tree(inter_graph)
26  return IMP.domino.get_subsets(jt)
27 
28 
29 def setup_scoring_function(ps):
30  m = ps[0].get_model()
31  pairs = [[0, 1], [0, 2], [1, 2], [2, 3], [3, 4], [4, 5], [3, 5]]
32  sf = IMP.core.Harmonic(1.0, 1)
33  for pair in pairs:
34  r = IMP.core.DistanceRestraint(sf, ps[pair[0]], ps[pair[1]])
35  m.add_restraint(r)
36 
37 # Initiate a set of states for each particle in ps
38 
39 
40 def initiate_configuration(domino_smp, ps):
41  # Generate a discrete set of states
42  vector_states = []
43  for i in range(0, 4):
44  vector_states.append(IMP.algebra.Vector3D(i, 0, 0))
45  vector_states.append(IMP.algebra.Vector3D(i, 1, 0))
46  # Generate a discrete set of states for each of the particles
47  states = IMP.domino.XYZStates(vector_states)
48  # Map states of particles
49  for p in ps:
50  domino_smp.set_particle_states(p, states)
51 
52 sys.exit()
53 # REPRESENTATION
54 # 1. setting up the representation (6 particles)
55 mdl = IMP.kernel.Model()
56 mdl.set_log_level(IMP.base.SILENT)
57 ps = []
58 for i in range(0, 6):
59  p = IMP.kernel.Particle(mdl)
61  ps.append(p)
62 
63 # SCORING
64 # 1. setting up the scoring function
65 setup_scoring_function(ps)
66 
67 # 1. get the subsets
68 subsets = get_subsets(ps)
69 
70 # optimize each one (returning ParticleStatesTable)
71 pst = optimize_subsets(subsets)
72 sys.exit()
73 
74 # subsets=[]
75 
76 # jt.show()
77 
78 # 2. sample each subset
79 # 3. gathering
80 
81 
82 # OPTIMIZATION
83 # 1. load domino sampler and set required properties
84 domino_smp = IMP.domino.DominoSampler(m)
85 domino_smp.set_maximum_score(.2)
86 
87 # 2. initiate configuration
88 initiate_configuration(domino_smp, ps)
89 
90 
91 # 3. construct subset of variables AND
92 # optimize subsets of variables subject to the discrete sampling space AND
93 # gather subset of variables into global solutions
94 cs = domino_smp.create_sample()
95 
96 # ANALYSE
97 # 4. report solutions
98 print "Found ", cs.get_number_of_configurations(), "solutions"
99 for i in range(cs.get_number_of_configurations()):
100  cs.load_configuration(i)
101  # print the configuration:
102  print "solution number:", i, " scored:", m.evaluate(False)