glp icon indicating copy to clipboard operation
glp copied to clipboard

Adding cell list to neighborlist.py

Open suadou opened this issue 10 months ago • 5 comments

This pull request introduces a new method for computing the cell list to identify neighboring atoms. Here's how it works:

  1. The simulation cell is divided into a grid of bins.
  2. Each atom is assigned to a bin.
  3. For each atom, only the atoms in the same bin and its neighboring bins are considered.

This approach is jittable, making it efficient for large systems. However, the initial allocation is not jittable. The implementation follows the cell list method used in jax-md.

The existing function quadratic_neighbor_list has been updated with a new parameter use_cell_list=False. To use the new cell list method, set cell_list=True. Please note that for this to work, the cut_off should be at least three times smaller than the cell size in one or more of the components (x,y,z).

While the cell-list implementation is more efficient for large systems, it is more complex and requires the simulation cell to be periodic. On the other hand, the N-square implementation is simpler and can be used for non-periodic systems.

Important Note: If the cell size changes and the bins become smaller than the cutoff, the cell list must be reallocated. The CellList class has a reallocated attribute. If it's set to true, the cell list must be recomputed.

Test: The new code was tested using unit tests. It passes neighborlist_test.py (updated to increase the cell size to fulfill cell size). However, it fails test_lj.py and test_mlff.py due to unrelated errors:

=========================== short test summary info ============================
FAILED test_lj.py::TestCalculatorWithLJ::test_mega - RuntimeError
FAILED test_mlff.py::TestMLFF::test_mega - ValueError: max() arg is an empty sequence

suadou avatar Apr 09 '24 12:04 suadou