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