IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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
7import IMP.algebra
8import sys
9
10IMP.setup_from_argv(sys.argv, "grid space")
11
12# create a unit grid with its origin at 0,0,0
14
16count = 0
17for 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
26in_count = 0
27for 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
36print("There are", len(g.get_all_indexes()), "distinct values",
37 count, in_count)
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
VectorD< 3 > Vector3D
Definition VectorD.h:407
VectorD< D > get_random_vector_on(const BoundingBoxD< D > &bb)
Generate a random vector on a box with uniform density.
BoundingBoxD< D > get_bounding_box(const GridD< D, Storage, Value, Embedding > &g)
Definition GridD.h:406
Grid3D< int, SparseGridStorage3D< int, UnboundedGridStorage3D > > SparseUnboundedIntGrid3D
double get_distance(const Line3D &s, const Vector3D &p)
Get closest distance between a line and a point.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.