IMP logo
IMP Reference Guide  2.6.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 from __future__ import print_function
6 import IMP.domino
7 import IMP.core
8 import sys
9 
10 IMP.setup_from_argv(sys.argv, "multiscale")
11 
12 m = IMP.Model()
13 m.set_log_level(IMP.SILENT)
15  for i in range(0, 3)]
16 for i, d in enumerate(ds):
17  d.set_radius(1)
19 
20 k = 1
21 h = IMP.core.Harmonic(0, k)
24  ds[0].get_particle_index(), "0 at origin")
25 
28  )[0]),
29  ds[1].get_particle_index(), "1 on axis")
30 
31 rs = [r0, r1]
32 for pr in [(0, 1), (1, 2), (0, 2)]:
35  (ds[pr[0]].get_particle_index(),
36  ds[pr[1]].get_particle_index()),
37  "R for " + str(pr))
38  rs.append(r)
39 
40 
43 
44 covers = []
45 for i in range(0, 6):
47  print(cur)
48  covers.append([IMP.algebra.Vector3D(x[0], x[1], 0) for x in cur])
49 
50 
51 def setup(cover, scale):
53  st = IMP.domino.XYZStates(cover)
54  for p in ds:
55  pst.set_particle_states(p, st)
56  for r in rs:
57  r.set_maximum_score(.5 * scale ** 2)
60  rc.add_restraints(rs)
62  lf]
63  sampler = IMP.domino.DominoSampler(m, pst)
64  sampler.set_restraints(rs)
65  sampler.set_subset_filter_tables(fs)
66  sampler.set_log_level(IMP.SILENT)
67  return (sampler, lf, pst)
68 
69 (sampler, lf, pst) = setup(covers[0], 4.0)
70 
71 subset = IMP.domino.Subset(ds)
72 ac = sampler.get_sample_assignments(subset)
73 
74 print(ac)
75 
76 
77 def get_mapping(cover0, cover1):
78  nn = IMP.algebra.NearestNeighbor3D(cover0)
79  ret = [[] for c in cover0]
80  for i, p in enumerate(cover1):
81  nns = nn.get_nearest_neighbor(p)
82  ret[nns].append(i)
83  return ret
84 
85 mw = IMP.display.PymolWriter("mapping.pym")
86 
87 
88 def display_mapping(index, cover0, cover1, mapping):
89  mw.set_frame(index)
90  for i, c in enumerate(mapping):
91  for p in c:
92  g = IMP.display.PointGeometry(cover1[p])
93  g.set_color(IMP.display.get_display_color(i))
94  g.set_name("fine")
95  mw.add_geometry(g)
96  for i, c in enumerate(cover0):
98  g.set_color(IMP.display.get_display_color(i))
99  g.set_name("coarse")
100  mw.add_geometry(g)
101 
102 
103 for curi in range(1, len(covers)):
104  scale = 4.0 / 2 ** curi
105  print(scale)
106  mapping = get_mapping(covers[curi - 1], covers[curi])
107  print(mapping)
108  display_mapping(curi - 1, covers[curi - 1], covers[curi], mapping)
109  (sampler, lf, pst) = setup(covers[curi], scale)
110  lac = ac
111  cac = []
112  for a in lac:
113  for i, p in enumerate(subset):
114  s = a[i]
115  allowed = mapping[s]
116  lf.set_allowed_states(p, allowed)
117  ccac = sampler.get_sample_assignments(subset)
118  print(a, ccac)
119  cac = cac + ccac
120  ac = list(set(cac))
121  print("for scale", scale, "got", ac)
122  sw = IMP.display.PymolWriter("solutions." + str(curi) + ".pym")
123  for i, a in enumerate(ac):
124  IMP.domino.load_particle_states(subset, a, pst)
125  sw.set_frame(i)
126  for p in ds:
127  g = IMP.core.XYZRGeometry(p)
128  sw.add_geometry(g)
129  for c in covers[curi]:
131  g.set_color(IMP.display.Color(1, 1, 1))
132  g.set_name("grid")
133  sw.add_geometry(g)