Crate zelll

Crate zelll 

Source
Expand description

zelll1 provides a Rust implementation of the cell lists algorithm.

Particle simulations usually require to compute interactions between those particles. Considering all pairwise interactions of n particles would be of time complexity O(n²).
Cell lists facilitate linear-time enumeration of particle pairs closer than a certain cutoff distance by dividing the enclosing bounding box into (cuboid) grid cells.

§Caveats

zelll is motivated by coarse-grained (bio-)molecular simulations but is not restricted to that.
This is reflected by a few things:

  • internally, the simulation box is represented by a (sparse) hash map only storing non-empty grid cells, which gives an upper bound for memory usage given by n
  • bounding boxes are assumed to change and are computed from particle data
    (future APIs may be added to set a fixed bounding box)
  • instead of cell lists, slices into a contiguous storage buffer are used
  • periodic boundary conditions are currently not supported
  • parts of this implementation are more cache-aware than others, which becomes noticeable with larger data sets
    (at 10⁶10⁷ particles, mostly depending on last-level cache size) but is less pronounced with structured data2

§Usage

The general pattern in which this crate is intended to be used is roughly:

  1. construct CellGrid from particle positions
  2. enumerate pairs in order to compute particle interactions
  3. simulate particle motion
  4. rebuild CellGrid from updated particle positions

This crate only provides iteration over particle pairs. It is left to the user to filter (eg. by distance) and compute interaction potentials. The rayon feature enables parallel iteration. Performance gains depend on data size and computational cost per pair though. Benchmarks are encouraged.

While the main struct CellGrid is generic over dimension N, it is intended to be used with N = 2 or N = 3. Particle data represented as fixed-size arrays is supported without additional work.
Additionally, implementing Particle allows usage of custom types as particle data. This can be used to encode different kinds of particles or enable interior mutability if required.

§Examples

use zelll::CellGrid;

let data = vec![[0.0, 0.0, 0.0], [1.0,2.0,0.0], [0.0, 0.1, 0.2]];
let mut cg = CellGrid::new(data.iter().copied(), 1.0);

for ((i, p), (j, q)) in cg.particle_pairs() {
    /* do some work */
}

cg.rebuild_mut(data.iter().copied(), Some(0.5));

  1. abbrv. from German Zelllisten /ˈʦɛlɪstən/, for cell lists. 

  2. Usually, (bio-)molecular data files are not completely unordered even though they could be. In practice, it may be a reasonable assumption that sequentially proximate particles often have spatially clustered coordinates as well. 

Modules§

cellgrid
Primary module of this crate.

Structs§

CellGrid
The central type representing a grid of cells that provides an implementation of the cell lists algorithm.

Traits§

Particle
Particle data trait.