IMP logo
IMP Reference Guide  2.20.2
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 IMP.setup_from_argv(sys.argv, "domino approach")
11 
12 
13 def 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 
23 def 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 
31 def 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 
44 def 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 
57 sys.exit()
58 # REPRESENTATION
59 # 1. setting up the representation (6 particles)
60 mdl = IMP.Model()
61 mdl.set_log_level(IMP.SILENT)
62 ps = []
63 for i in range(0, 6):
64  p = IMP.Particle(mdl)
66  ps.append(p)
67 
68 # SCORING
69 # 1. setting up the scoring function
70 rs = setup_scoring_function(ps)
71 
72 # 1. get the subsets
73 subsets = get_subsets(ps)
74 
75 # optimize each one (returning ParticleStatesTable)
76 pst = optimize_subsets(subsets)
77 sys.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
89 domino_smp = IMP.domino.DominoSampler(m)
90 domino_smp.set_restraints([rs])
91 domino_smp.set_maximum_score(.2)
92 
93 # 2. initiate configuration
94 initiate_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
100 cs = domino_smp.create_sample()
101 
102 # ANALYSE
103 # 4. report solutions
104 print("Found ", cs.get_number_of_configurations(), "solutions")
105 for 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))