IMP  2.4.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 from __future__ import print_function
8 import IMP.algebra
9 
10 # create a unit grid with its origin at 0,0,0
12 
14 count = 0
15 for i in range(0, 100):
17  ei = g.get_extended_index(p)
18  if g.get_has_index(ei):
19  print("hit")
20  else:
21  g.add_voxel(ei, count)
22  count += 1
23 
24 in_count = 0
25 for i in g.get_extended_indexes(IMP.algebra.get_bounding_box(s)):
26  if IMP.algebra.get_distance(s.get_center(), g.get_center(i)) > 6:
27  continue
28  if g.get_has_index(i):
29  print("hit")
30  else:
31  g.add_voxel(i, -1)
32  in_count += 1
33 
34 print("There are", len(g.get_all_indexes()), "distinct values", count, in_count)