IMP logo
IMP Reference Guide  develop.031dafb4d2,2024/05/16
The Integrative Modeling Platform
domino/multiscale.py
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)
Represent an RGB color.
Definition: Color.h:25
setup
Definition: setup.py:1
VectorD< 2 > Vector2D
Definition: VectorD.h:404
Maintain an explicit list of what states each particle is allowed to have.
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
static XYZR setup_particle(Model *m, ParticleIndex pi)
Definition: XYZR.h:48
Sample best solutions using Domino.
Definition: DominoSampler.h:32
A harmonic score on the distance between two spheres.
Filter a configuration of the subset using the Model thresholds.
Represent a subset of the particles being optimized.
Definition: Subset.h:33
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
Color get_display_color(unsigned int i)
Apply a function to the distance to a fixed point.
static Colored setup_particle(Model *m, ParticleIndex pi, Color color)
Definition: Colored.h:62
An axis-aligned bounding box.
Definition: BoundingBoxD.h:28
Basic functionality that is expected to be used by a wide variety of IMP users.
VectorD< 3 > Vector3D
Definition: VectorD.h:408
Class to handle individual particles of a Model object.
Definition: Particle.h:43
Write a CGO file with the geometry.
Definition: PymolWriter.h:34
Vector< VectorD< D > > get_grid_interior_cover_by_spacing(const BoundingBoxD< D > &bb, double s)
Applies a PairScore to a Pair.
Definition: PairRestraint.h:31
static const FloatKeys & get_xyz_keys()
Get a vector containing the keys for x,y,z.
void load_particle_states(const Subset &s, const Assignment &ss, const ParticleStatesTable *pst)
Load the appropriate state for each particle in a Subset.
Applies a SingletonScore to a Singleton.
Divide-and-conquer inferential optimization in discrete space.
Display an IMP::core::XYZR particle as a ball.
Definition: XYZR.h:151
Harmonic function (symmetric about the mean)
Definition: core/Harmonic.h:27