IMP  2.3.0
The Integrative Modeling Platform
domino/multiscale.py

We are interested in applying domino to problems systematically in a multiscale manner. This script experiments with those approaches.

1 ## \example domino/multiscale.py
2 # We are interested in applying domino to problems systematically in a
3 # multiscale manner. This script experiments with those approaches.
4 
5 import IMP.domino
6 import IMP.core
7 
8 
9 # Use faster built-in 'set' type on newer Pythons; fall back to the older
10 # 'sets' module on older Pythons
11 try:
12  x = set
13  del x
14 except NameError:
15  import sets
16  set = sets.Set
17 
18 m = IMP.kernel.Model()
19 m.set_log_level(IMP.base.SILENT)
21  for i in range(0, 3)]
22 for i, d in enumerate(ds):
23  d.set_radius(1)
25 
26 k = 1
27 h = IMP.core.Harmonic(0, k)
30  ds[0], "0 at origin")
31 
34  )[0]),
35  ds[1], "1 on axis")
36 
37 rs = [r0, r1]
38 for pr in [(0, 1), (1, 2), (0, 2)]:
40  (ds[pr[0]], ds[pr[1]]),
41  "R for " + str(pr))
42  rs.append(r)
43 
44 
47 
48 covers = []
49 for i in range(0, 6):
51  print cur
52  covers.append([IMP.algebra.Vector3D(x[0], x[1], 0) for x in cur])
53 
54 
55 def setup(cover, scale):
57  st = IMP.domino.XYZStates(cover)
58  for p in ds:
59  pst.set_particle_states(p, st)
60  for r in rs:
61  r.set_maximum_score(.5 * scale ** 2)
64  rc.add_restraints(rs)
66  lf]
67  sampler = IMP.domino.DominoSampler(m, pst)
68  sampler.set_subset_filter_tables(fs)
69  sampler.set_log_level(IMP.base.SILENT)
70  return (sampler, lf, pst)
71 
72 (sampler, lf, pst) = setup(covers[0], 4.0)
73 
74 subset = IMP.domino.Subset(ds)
75 ac = sampler.get_sample_assignments(subset)
76 
77 print ac
78 
79 
80 def get_mapping(cover0, cover1):
81  nn = IMP.algebra.NearestNeighbor3D(cover0)
82  ret = [[] for c in cover0]
83  for i, p in enumerate(cover1):
84  nns = nn.get_nearest_neighbor(p)
85  ret[nns].append(i)
86  return ret
87 
88 mw = IMP.display.PymolWriter("mapping.pym")
89 
90 
91 def display_mapping(index, cover0, cover1, mapping):
92  mw.set_frame(index)
93  for i, c in enumerate(mapping):
94  for p in c:
95  g = IMP.display.PointGeometry(cover1[p])
96  g.set_color(IMP.display.get_display_color(i))
97  g.set_name("fine")
98  mw.add_geometry(g)
99  for i, c in enumerate(cover0):
101  g.set_color(IMP.display.get_display_color(i))
102  g.set_name("coarse")
103  mw.add_geometry(g)
104 
105 
106 for curi in range(1, len(covers)):
107  scale = 4.0 / 2 ** curi
108  print scale
109  mapping = get_mapping(covers[curi - 1], covers[curi])
110  print mapping
111  display_mapping(curi - 1, covers[curi - 1], covers[curi], mapping)
112  (sampler, lf, pst) = setup(covers[curi], scale)
113  lac = ac
114  cac = []
115  for a in lac:
116  for i, p in enumerate(subset):
117  s = a[i]
118  allowed = mapping[s]
119  lf.set_allowed_states(p, allowed)
120  ccac = sampler.get_sample_assignments(subset)
121  print a, ccac
122  cac = cac + ccac
123  ac = list(set(cac))
124  print "for scale", scale, "got", ac
125  sw = IMP.display.PymolWriter("solutions." + str(curi) + ".pym")
126  for i, a in enumerate(ac):
127  IMP.domino.load_particle_states(subset, a, pst)
128  sw.set_frame(i)
129  for p in ds:
130  g = IMP.core.XYZRGeometry(p)
131  sw.add_geometry(g)
132  for c in covers[curi]:
134  g.set_color(IMP.display.Color(1, 1, 1))
135  g.set_name("grid")
136  sw.add_geometry(g)