I'm trying to implement the following form of the cell/neighbor list method in my MD code. I have divided my simulation box into a fixed number of cells, and according to its positions, I have correctly assigned each atom to the appropriate cell. I build the neighbor list for each individual cell $i$. When performing calculations, I only consider the atoms within the neighboring cells; furthermore, on this subset, I perform the Verlet search where I only consider the atoms within radius $r_{cutoff}$ of atom $k$. This even smaller subset of atoms will be interacting. The algorithm I want to implement is found in this paper, algorithm C 1. Algorithm 1 is the pseudocode for it.
My questions are regarding the building of the neighbors list. Pictured above is the simulation box represented in 3 layers (picture them on top of each other to form a 3D box).
- I know that we should not consider all the neighboring cells because that would lead to double counting the interactions. Is it correct to only consider the L shaped cells I have drawn? In the figure, we are considering the atoms in cell 14 and are interested in its neighbors.
- Currently, I can make a neighbors list if I use A LOT of
if/else
statements to get all the boundary conditions correctly. I have been thinking about a more efficient/concise algorithm by detecting patterns but I couldn't come up with anything. Is there an algorithm that is more efficient than doing a bunch ofif
statements? Perhaps one that automatically accounts for the periodic boundary conditions too?
Essentially, I'm asking how I can build the neighbors list. For this part, I'm looking to have something like int neighbors[N_c][26]
, where N_c
is the number of cells, and 26
is how many neighbors each cell $i$ has. Data type is int
because cells are identified by an int
. neighbors[1]
returns the array of neighbors of cell 1.