IMP logo
IMP Reference Guide  develop.63b38c487d,2024/12/22
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 import sys
9 
10 IMP.setup_from_argv(sys.argv, "grid space")
11 
12 # create a unit grid with its origin at 0,0,0
14 
16 count = 0
17 for i in range(0, 100):
19  ei = g.get_extended_index(p)
20  if g.get_has_index(ei):
21  print("hit")
22  else:
23  g.add_voxel(ei, count)
24  count += 1
25 
26 in_count = 0
27 for i in g.get_extended_indexes(IMP.algebra.get_bounding_box(s)):
28  if IMP.algebra.get_distance(s.get_center(), g.get_center(i)) > 6:
29  continue
30  if g.get_has_index(i):
31  print("hit")
32  else:
33  g.add_voxel(i, -1)
34  in_count += 1
35 
36 print("There are", len(g.get_all_indexes()), "distinct values",
37  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:408
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:196