IMP logo
IMP Reference Guide  2.17.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  ds[1].get_particle_index(), "1 on axis")
29 
30 rs = [r0, r1]
31 for pr in [(0, 1), (1, 2), (0, 2)]:
34  (ds[pr[0]].get_particle_index(), ds[pr[1]].get_particle_index()),
35  "R for " + str(pr))
36  rs.append(r)
37 
38 
41 
42 covers = []
43 for i in range(0, 6):
45  print(cur)
46  covers.append([IMP.algebra.Vector3D(x[0], x[1], 0) for x in cur])
47 
48 
49 def setup(cover, scale):
51  st = IMP.domino.XYZStates(cover)
52  for p in ds:
53  pst.set_particle_states(p, st)
54  for r in rs:
55  r.set_maximum_score(.5 * scale ** 2)
58  rc.add_restraints(rs)
60  lf]
61  sampler = IMP.domino.DominoSampler(m, pst)
62  sampler.set_restraints(rs)
63  sampler.set_subset_filter_tables(fs)
64  sampler.set_log_level(IMP.SILENT)
65  return (sampler, lf, pst)
66 
67 
68 (sampler, lf, pst) = setup(covers[0], 4.0)
69 
70 subset = IMP.domino.Subset(ds)
71 ac = sampler.get_sample_assignments(subset)
72 
73 print(ac)
74 
75 
76 def get_mapping(cover0, cover1):
77  nn = IMP.algebra.NearestNeighbor3D(cover0)
78  ret = [[] for c in cover0]
79  for i, p in enumerate(cover1):
80  nns = nn.get_nearest_neighbor(p)
81  ret[nns].append(i)
82  return ret
83 
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)