IMP logo
IMP Reference Guide  2.22.0
The Integrative Modeling Platform
algebra/grid_space.py

This example shows how to use the grid support in IMP.algebra to discretize a set of continuous points. In this case the points are simply randomly drawn from the surface of a sphere, but they could be taken from something more interesting.

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)