IMP logo
IMP Reference Guide  2.16.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 from __future__ import print_function
8 import IMP.algebra
9 import sys
10 
11 IMP.setup_from_argv(sys.argv, "grid space")
12 
13 # create a unit grid with its origin at 0,0,0
15 
17 count = 0
18 for i in range(0, 100):
20  ei = g.get_extended_index(p)
21  if g.get_has_index(ei):
22  print("hit")
23  else:
24  g.add_voxel(ei, count)
25  count += 1
26 
27 in_count = 0
28 for i in g.get_extended_indexes(IMP.algebra.get_bounding_box(s)):
29  if IMP.algebra.get_distance(s.get_center(), g.get_center(i)) > 6:
30  continue
31  if g.get_has_index(i):
32  print("hit")
33  else:
34  g.add_voxel(i, -1)
35  in_count += 1
36 
37 print("There are", len(g.get_all_indexes()), "distinct values",
38  count, in_count)
Grid3D< int, SparseGridStorage3D< int, UnboundedGridStorage3D > > SparseUnboundedIntGrid3D
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
BoundingBoxD< 3 > get_bounding_box(const Geometry &)
Compute the bounding box of any geometric object.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
VectorD< 3 > Vector3D
Definition: VectorD.h:421
VectorD< D > get_random_vector_on(const UnitSimplexD< D > &s)
Generate a random vector on a unit simplex with uniform density.
double get_distance(const VectorD< D > &v1, const VectorD< D > &v2)
Compute the distance between two vectors.
Definition: VectorD.h:209