IMP  2.1.0
The Integrative Modeling Platform
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 
8 
9 # Use faster built-in 'set' type on newer Pythons; fall back to the older
10 # 'sets' module on older Pythons
11 try:
12  x = set
13  del x
14 except NameError:
15  import sets
16  set = sets.Set
17 
18 m = IMP.kernel.Model()
19 m.set_log_level(IMP.base.SILENT)
21  for i in range(0, 3)]
22 for i, d in enumerate(ds):
23  d.set_radius(1)
25 
26 k = 1
27 h = IMP.core.Harmonic(0, k)
30  ds[0], "0 at origin")
31 r0.set_model(m)
32 
35  )[0]),
36  ds[1], "1 on axis")
37 r1.set_model(m)
38 
39 rs = [r0, r1]
40 for pr in [(0, 1), (1, 2), (0, 2)]:
42  (ds[pr[0]], ds[pr[1]]),
43  "R for " + str(pr))
44  r.set_model(m)
45  rs.append(r)
46 
47 
50 
51 covers = []
52 for i in range(0, 6):
54  print cur
55  covers.append([IMP.algebra.Vector3D(x[0], x[1], 0) for x in cur])
56 
57 
58 def setup(cover, scale):
60  st = IMP.domino.XYZStates(cover)
61  for p in ds:
62  pst.set_particle_states(p, st)
63  for r in rs:
64  r.set_maximum_score(.5 * scale ** 2)
67  rc.add_restraints(rs)
69  lf]
70  sampler = IMP.domino.DominoSampler(m, pst)
71  sampler.set_subset_filter_tables(fs)
72  sampler.set_log_level(IMP.base.SILENT)
73  return (sampler, lf, pst)
74 
75 (sampler, lf, pst) = setup(covers[0], 4.0)
76 
77 subset = IMP.domino.Subset(ds)
78 ac = sampler.get_sample_assignments(subset)
79 
80 print ac
81 
82 
83 def get_mapping(cover0, cover1):
84  nn = IMP.algebra.NearestNeighbor3D(cover0)
85  ret = [[] for c in cover0]
86  for i, p in enumerate(cover1):
87  nns = nn.get_nearest_neighbor(p)
88  ret[nns].append(i)
89  return ret
90 
91 mw = IMP.display.PymolWriter("mapping.pym")
92 
93 
94 def display_mapping(index, cover0, cover1, mapping):
95  mw.set_frame(index)
96  for i, c in enumerate(mapping):
97  for p in c:
98  g = IMP.display.PointGeometry(cover1[p])
99  g.set_color(IMP.display.get_display_color(i))
100  g.set_name("fine")
101  mw.add_geometry(g)
102  for i, c in enumerate(cover0):
104  g.set_color(IMP.display.get_display_color(i))
105  g.set_name("coarse")
106  mw.add_geometry(g)
107 
108 
109 for curi in range(1, len(covers)):
110  scale = 4.0 / 2 ** curi
111  print scale
112  mapping = get_mapping(covers[curi - 1], covers[curi])
113  print mapping
114  display_mapping(curi - 1, covers[curi - 1], covers[curi], mapping)
115  (sampler, lf, pst) = setup(covers[curi], scale)
116  lac = ac
117  cac = []
118  for a in lac:
119  for i, p in enumerate(subset):
120  s = a[i]
121  allowed = mapping[s]
122  lf.set_allowed_states(p, allowed)
123  ccac = sampler.get_sample_assignments(subset)
124  print a, ccac
125  cac = cac + ccac
126  ac = list(set(cac))
127  print "for scale", scale, "got", ac
128  sw = IMP.display.PymolWriter("solutions." + str(curi) + ".pym")
129  for i, a in enumerate(ac):
130  IMP.domino.load_particle_states(subset, a, pst)
131  sw.set_frame(i)
132  for p in ds:
133  g = IMP.core.XYZRGeometry(p)
134  sw.add_geometry(g)
135  for c in covers[curi]:
137  g.set_color(IMP.display.Color(1, 1, 1))
138  g.set_name("grid")
139  sw.add_geometry(g)
Represent an RGB color.
Definition: Color.h:24
setup
Definition: setup.py:1
Maintain an explicit list of what states each particle is allowed to have.
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 kernel::Model thresholds.
Represent a subset of the particles being optimized.
Definition: Subset.h:33
static XYZR setup_particle(kernel::Model *m, ParticleIndex pi)
Definition: XYZR.h:48
static Colored setup_particle(kernel::Model *m, ParticleIndex pi, Color color)
Definition: Colored.h:62
Color get_display_color(unsigned int i)
Apply a function to the distance to a fixed point.
Class to handle individual model particles.
An axis-aligned bounding box.
Definition: BoundingBoxD.h:26
base::Vector< VectorD< D > > get_grid_interior_cover_by_spacing(const BoundingBoxD< D > &bb, double s)
See IMP.core for more information.
Write a CGO file with the geometry.
Definition: PymolWriter.h:34
Applies a PairScore to a Pair.
Definition: PairRestraint.h:30
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)
Applies a SingletonScore to a Singleton.
Apply a function to an attribute.
See IMP.domino for more information.
Definition: analysis.h:15
Class for storing model, its restraints, constraints, and particles.
Display an IMP::core::XYZR particle as a ball.
Definition: XYZR.h:160
Harmonic function (symmetric about the mean)
Definition: core/Harmonic.h:25