IMP logo
IMP Reference Guide  2.7.0
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  )[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)
Represent an RGB color.
Definition: Color.h:24
setup
Definition: setup.py:1
VectorD< 2 > Vector2D
Definition: VectorD.h:391
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:72
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:27
Basic functionality that is expected to be used by a wide variety of IMP users.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
Class to handle individual particles of a Model object.
Definition: Particle.h:41
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:29
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:24