https://github.com/mdanalysis/cellgrid
https://github.com/mdanalysis/cellgrid
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/mdanalysis/cellgrid
- Owner: MDAnalysis
- License: mit
- Created: 2015-06-24T19:53:29.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2018-06-09T16:31:13.000Z (about 8 years ago)
- Last Synced: 2024-10-29T17:36:41.017Z (over 1 year ago)
- Language: Python
- Size: 610 KB
- Stars: 7
- Watchers: 4
- Forks: 6
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
CellGrid
========
[](https://travis-ci.org/MDAnalysis/cellgrid)
[](https://coveralls.io/r/MDAnalysis/cellgrid?branch=master)
Cellgrid offers scalable functions for calculating pairwise distances between arrays of 3d coordinates.
For many cases the distances only up to a given value are of interest, meaning that the volume can be decomposed into smaller subvolumes to reduce the number of pairs that need to be calculated.
CellGrid was designed with molecular dynamics results in mind, and offers support for periodic boundary conditions.
Install me like this:
---------------------
``` bash
git clone git@github.com:MDAnalysis/cellgrid.git
cd cellgrid
python setup.py install --user
```
How to use me
-------------
``` python
>>> import numpy as np
>>> from cellgrid import capped_distance_array
# Random coordinates to search for pairs between
>>> a = np.random.random(3000).reshape(1000, 3).astype(np.float32)
>>> b = np.random.random(30000).reshape(10000, 3).astype(np.float32)
# All reside within a 1 x 1 x 1 box
>>> box = np.ones(3).astype(np.float32)
# Find all pairs witin 0.25 of each other
# Returns indices of pairs and the distance between them
>>> capped_distance_array(a, b, 0.25, box)
(array([[ 226, 8896],
[ 226, 3557],
[ 226, 8982],
...,
[ 259, 11],
[ 259, 2215],
[ 259, 5117]]),
array([ 0.21252801, 0.21431111, 0.12156317, ..., 0.02756999,
0.24850761, 0.15750615], dtype=float32))
```
Internally this is done using the eponymous CellGrid object, which takes coordinates and sorts them spatially into Cells.
``` python
>>> from cellgrid import CellGrid
>>> cg = CellGrid(box, 0.25, a)
>>> cg
>>> cg[0]
```