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