IMP  2.2.0
The Integrative Modeling Platform
grid_space.py
1 ## \example algebra/grid_space.py
2 # This example shows how to use the grid support in IMP.algebra to
3 # discretize a set of continuous points. In this case the points are
4 # simply randomly drawn from the surface of a sphere, but they could be
5 # taken from something more interesting.
6 
7 import IMP.algebra
8 
9 # create a unit grid with its origin at 0,0,0
11 
13 count = 0
14 for i in range(0, 100):
16  ei = g.get_extended_index(p)
17  if g.get_has_index(ei):
18  print "hit"
19  else:
20  g.add_voxel(ei, count)
21  count += 1
22 
23 in_count = 0
24 for i in g.get_extended_indexes(IMP.algebra.get_bounding_box(s)):
25  if IMP.algebra.get_distance(s.get_center(), g.get_center(i)) > 6:
26  continue
27  if g.get_has_index(i):
28  print "hit"
29  else:
30  g.add_voxel(i, -1)
31  in_count += 1
32 
33 print "There are", len(g.get_all_indexes()), "distinct values", count, in_count
Grid3D< int, SparseGridStorage3D< int, UnboundedGridStorage3D > > SparseUnboundedIntGrid3D
BoundingBoxD< 3 > get_bounding_box(const SpherePatch3D &g)
Definition: SpherePatch3D.h:50
See IMP.algebra for more information.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
double get_distance(const VectorD< D > &v1, const VectorD< D > &v2)
compute the distance between two vectors
Definition: VectorD.h:209
VectorD< D > get_random_vector_on(const SphereD< D > &s)
Generate a random vector on a sphere with uniform density.