IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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
5import IMP.domino
6import IMP.core
7import sys
8
9IMP.setup_from_argv(sys.argv, "multiscale")
10
11m = IMP.Model()
12m.set_log_level(IMP.SILENT)
14 for i in range(0, 3)]
15for i, d in enumerate(ds):
16 d.set_radius(1)
18
19k = 1
20h = 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
29rs = [r0, r1]
30for 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
41covers = []
42for 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
48def 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
69subset = IMP.domino.Subset(ds)
70ac = sampler.get_sample_assignments(subset)
71
72print(ac)
73
74
75def 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
84mw = IMP.display.PymolWriter("mapping.pym")
85
86
87def 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
102for 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:
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)
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Class to handle individual particles of a Model object.
Definition Particle.h:45
A harmonic score on the distance between two spheres.
Harmonic function (symmetric about the mean)
Applies a PairScore to a Pair.
Applies a SingletonScore to a Singleton.
Display an IMP::core::XYZR particle as a ball.
Definition XYZR.h:151
static XYZR setup_particle(Model *m, ParticleIndex pi)
Definition XYZR.h:48
static const FloatKeys & get_xyz_keys()
Get a vector containing the keys for x,y,z.
Represent an RGB color.
Definition Color.h:25
static Colored setup_particle(Model *m, ParticleIndex pi, Color color)
Definition Colored.h:62
Write a CGO file with the geometry.
Definition PymolWriter.h:34
Sample best solutions using Domino.
Maintain an explicit list of what states each particle is allowed to have.
Filter a configuration of the subset using the Model thresholds.
Represent a subset of the particles being optimized.
Definition Subset.h:34
VectorD< 3 > Vector3D
Definition VectorD.h:407
VectorD< 2 > Vector2D
Definition VectorD.h:403
Vector< VectorD< D > > get_grid_interior_cover_by_spacing(const BoundingBoxD< D > &bb, double s)
Basic functionality that is expected to be used by a wide variety of IMP users.
Color get_display_color(unsigned int i)
Divide-and-conquer inferential optimization in discrete space.
void load_particle_states(const Subset &s, const Assignment &ss, const ParticleStatesTable *pst)
Load the appropriate state for each particle in a Subset.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.
setup
Definition setup.py:1