IMP
2.0.0
The Integrative Modeling Platform
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
grid_space.py
1
## \example algebra/grid_space.py
2
## 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.
3
4
import
IMP.algebra
5
6
# create a unit grid with its origin at 0,0,0
7
g=
IMP.algebra.SparseUnboundedIntGrid3D
(1,
IMP.algebra.Vector3D
(0,0,0))
8
9
s=
IMP.algebra.Sphere3D
(
IMP.algebra.Vector3D
(1,1,1), 6)
10
count=0
11
for
i
in
range(0,100):
12
p=
IMP.algebra.get_random_vector_on
(s)
13
ei= g.get_extended_index(p)
14
if
g.get_has_index(ei):
15
print
"hit"
16
else
:
17
g.add_voxel(ei, count)
18
count=count+1
19
print
"There are"
, len(g.get_all_indexes()),
"distinct values"
, count