IMP logo
IMP Reference Guide  develop.d97d4ead1f,2024/11/21
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 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)
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