Algorithm Search⌘K

Data structurecore

Verlet neighbor list

Also called Verlet list.

Stores for each atom the atoms within the cutoff plus a skin, and is rebuilt only when some atom has moved more than half the skin.

Time
O(N^2) build_directO(N) build_with_cells_fixed_densityO(N + P) step
Space
O(N + P) total
Where
N = the number of atoms; P = the number of pairs in the list
Origin
Loup Verlet, 1967

A Verlet neighbor list stores, once, all pairs of atoms closer than a list radius rℓ=rc+sr_\ell = r_c + s, where rcr_c is the cutoff of the forces and the skin s>0s > 0 is a margin, and then reuses this list for many time steps. At each step the force loop tests only the stored pairs, and the list is built again only when the atoms have moved far enough that a pair outside the list could have come within rcr_c. It differs from the linked-cell list, which stores the atoms by position and is rebuilt at every step; a cell list is the usual way to build a Verlet list. Both are parts of the force loop of molecular dynamics under periodic boundary conditions.

In plain words

Suppose you must check, many times a minute, which people in a crowd stand within two meters of each other. People walk slowly, so the answer changes little from one check to the next.

So once in a while, write down every pair of people within two and a half meters, a little more than you need. At each check, look only at the pairs on your paper. A pair that was more than two and a half meters apart cannot come within two meters until the two people have walked half a meter between them.

Keep track of how far people walked since you made the paper. When the two who walked farthest have together walked more than half a meter, make a new paper.

The abstract type

The list answers, at each time step nn, the query "all unordered pairs {i,j}\{i, j\} with ∣rij∣<rc|r_{ij}| < r_c" for the current positions r1,…,rNr_1, \ldots, r_N in a periodic cubic box of side LL, with the distance taken under the minimum image rule. The positions change a little between queries. The list is a cache of candidate pairs with a test that says when the cache can no longer be trusted. The answer is the same as that of the direct loop or a linked-cell list at every step; only the cost differs.

Representation

  • The list radius is rℓ=rc+sr_\ell = r_c + s, with rℓ≤L/2r_\ell \le L/2, so that the minimum image of each pair in the list is unique.
  • The list is the set of pairs (i,j)(i, j) with i<ji < j and ∣rij0∣<rℓ|r_{ij}^0| < r_\ell at the last build. Codes store it in compressed form: an array point of N+1N + 1 start positions and an array list of neighbors, so that the neighbors of atom ii with j>ij > i are list[point[i]] to list[point[i+1] - 1]. The implementation keeps a plain list of pairs.
  • The reference positions ri0r_i^0, the positions at the last build.
  • The displacement of atom ii since the build, di=∣ri−ri0∣d_i = |r_i - r_i^0|, taken under the minimum image rule so that an atom that crosses the boundary and is wrapped back into the box does not seem to have jumped by LL.

Invariant (V). Let d(1)≥d(2)d_{(1)} \ge d_{(2)} be the two largest displacements since the last build. If d(1)+d(2)≤sd_{(1)} + d_{(2)} \le s, then every pair with ∣rij∣<rc|r_{ij}| < r_c now is in the list.

The reason is the triangle inequality on the torus. If the pair was not in the list, then ∣rij0∣≥rℓ|r_{ij}^0| \ge r_\ell at the build, and now ∣rij∣≥∣rij0∣−di−dj≥rc+s−(d(1)+d(2))≥rc|r_{ij}| \ge |r_{ij}^0| - d_i - d_j \ge r_c + s - (d_{(1)} + d_{(2)}) \ge r_c. So the pair is not within the cutoff.

Operations

  1. BUILD(r_1..r_N)
  2. 1r_ℓ ← r_c + s
  3. 2for each pair i < j:
  4. 3if |r_ij| < r_ℓ under the minimum image rule then add (i, j) to the list
  5. 4r_i^0 ← r_i for each atom i
  6. PAIRS(r_1..r_N) ▷ called once per time step
  7. 5d_i ← |r_i - r_i^0| under the minimum image rule, for each atom i
  8. 6if d_(1) + d_(2) > s, where d_(1) ≥ d_(2) are the two largest d_i then
  9. 7BUILD(r_1..r_N)
  10. 8for each pair (i, j) in the list:
  11. 9if |r_ij| < r_c then report (i, j)

Lines L2 and L3 are the direct loop here; with a linked-cell list of cell side at least rℓr_\ell, the build looks only at neighboring cells. Line L6 is the automatic update test that Allen and Tildesley give, after Fincham (1981) and Thompson (1983). The simpler and more common test is the half-skin rule: rebuild when d(1)>s/2d_{(1)} > s/2. It is also safe, because d(1)≤s/2d_{(1)} \le s/2 gives d(1)+d(2)≤sd_{(1)} + d_{(2)} \le s, but it rebuilds at least as often. Many codes skip the test and rebuild every 10 to 20 steps; that interval is a choice, and it is safe only if no two atoms can close the skin between rebuilds.

Example

Take a box of side L=10L = 10 (in units of σ\sigma) with rc=2.5r_c = 2.5 and s=0.5s = 0.5, so rℓ=3.0r_\ell = 3.0. Three atoms lie at r0=(1,0,0)r_0 = (1, 0, 0), r1=(3.95,0,0)r_1 = (3.95, 0, 0) and r2=(1,3.05,0)r_2 = (1, 3.05, 0).

pair distance at the build in the list (<3.0< 3.0) within rcr_c (<2.5< 2.5)
(0, 1) 2.950 yes no
(0, 2) 3.050 no no
(1, 2) 4.243 no no

The list is {(0,1)}\{(0, 1)\}, and the step reports no pair.

Two atoms move toward each other. Atom 0 moves to (1,0.3,0)(1, 0.3, 0) and atom 2 to (1,2.75,0)(1, 2.75, 0), so d=(0.3,0,0.3)d = (0.3, 0, 0.3). Now ∣r02∣=2.45<rc|r_{02}| = 2.45 < r_c, but the pair is not in the list. Each atom alone moved less than the skin, so a test of the form "rebuild when one atom has moved more than ss" does not rebuild, and the force loop misses the pair. The test of line L6 gives 0.3+0.3=0.6>0.50.3 + 0.3 = 0.6 > 0.5 and rebuilds. The new list is {(0,1),(0,2)}\{(0, 1), (0, 2)\}, with ∣r01∣=2.965|r_{01}| = 2.965 and ∣r02∣=2.45|r_{02}| = 2.45, and the step reports (0,2)(0, 2). The half-skin rule also rebuilds, since 0.3>0.250.3 > 0.25.

One atom moves more than the other. Start again from the build. Atom 1 moves to (3.65,0,0)(3.65, 0, 0) and atom 2 to (1,2.95,0)(1, 2.95, 0), so d=(0,0.3,0.1)d = (0, 0.3, 0.1). The test of line L6 gives 0.3+0.1=0.4≤0.50.3 + 0.1 = 0.4 \le 0.5, so the list is kept. The half-skin rule rebuilds, since 0.3>0.250.3 > 0.25. Both report no pair, which is right: ∣r01∣=2.65|r_{01}| = 2.65 and ∣r02∣=2.95|r_{02}| = 2.95 are both above rcr_c. The test of line L6 saved one build.

Correctness

PAIRS reports exactly the pairs within rcr_c. Each reported pair passes the test of line L9, so it is within the cutoff. Conversely, after lines L5 to L7, either the list was just built, so that d(1)=d(2)=0d_{(1)} = d_{(2)} = 0, or the test of line L6 found d(1)+d(2)≤sd_{(1)} + d_{(2)} \le s; in both cases invariant (V) holds, and every pair within rcr_c is in the list, so line L9 reports it. Each pair is stored once with i<ji < j, so it is reported once. The proof uses only the triangle inequality for the minimum image distance, which is the distance on the torus, so it holds even when atoms cross the boundary between builds. The full proof is in the proofs folder.

Proof: The Verlet list with the two-displacement test reports exactly the pairs within the cutofffull

We use the names of the pseudocode. The box is [0,L)3[0, L)^3 with periodic boundaries. For two points aa and bb, let ∥a−b∥\|a - b\| be the minimum image distance, the distance from aa to the nearest periodic image of bb:

∥a−b∥=min⁡m∈Z3∣a−b−Lm∣.\|a - b\| = \min_{m \in \mathbb{Z}^3} |a - b - L m|.

In a cubic box this minimum splits into one term per axis, and the rounding Δq=(aq−bq)−L round((aq−bq)/L)\Delta_q = (a_q - b_q) - L \, \mathrm{round}((a_q - b_q) / L) attains it on each axis, so the code computes exactly ∥a−b∥\|a - b\|. The cutoff is rcr_c, the skin is s>0s > 0 and the list radius is rℓ=rc+sr_\ell = r_c + s. A build at the positions r0r^0 stores the set L={(i,j):i<j,∥ri0−rj0∥<rℓ}\mathcal{L} = \{(i, j) : i < j, \|r_i^0 - r_j^0\| < r_\ell\} and the reference positions r0r^0.

Lemma 1 (triangle inequality on the torus). For all points aa, bb and cc, ∥a−c∥≤∥a−b∥+∥b−c∥\|a - c\| \le \|a - b\| + \|b - c\|. Proof. Choose m1m_1 and m2m_2 with ∥a−b∥=∣a−b−Lm1∣\|a - b\| = |a - b - L m_1| and ∥b−c∥=∣b−c−Lm2∣\|b - c\| = |b - c - L m_2|. Then ∣a−c−L(m1+m2)∣≤∣a−b−Lm1∣+∣b−c−Lm2∣|a - c - L(m_1 + m_2)| \le |a - b - L m_1| + |b - c - L m_2| by the triangle inequality in R3\mathbb{R}^3, and the left side is at least ∥a−c∥\|a - c\|. □\square

Lemma 2 (invariant V). Let rr be the current positions, di=∥ri−ri0∥d_i = \|r_i - r_i^0\|, and let d(1)≥d(2)d_{(1)} \ge d_{(2)} be the two largest values. If d(1)+d(2)≤sd_{(1)} + d_{(2)} \le s, then every pair i<ji < j with ∥ri−rj∥<rc\|r_i - r_j\| < r_c is in L\mathcal{L}. Proof. Take a pair i<ji < j that is not in L\mathcal{L}, so ∥ri0−rj0∥≥rℓ\|r_i^0 - r_j^0\| \ge r_\ell. By Lemma 1 applied twice,

∥ri0−rj0∥≤∥ri0−ri∥+∥ri−rj∥+∥rj−rj0∥=di+∥ri−rj∥+dj.\|r_i^0 - r_j^0\| \le \|r_i^0 - r_i\| + \|r_i - r_j\| + \|r_j - r_j^0\| = d_i + \|r_i - r_j\| + d_j.

Since i≠ji \ne j, di+dj≤d(1)+d(2)≤sd_i + d_j \le d_{(1)} + d_{(2)} \le s. So ∥ri−rj∥≥rℓ−s=rc\|r_i - r_j\| \ge r_\ell - s = r_c, and the pair is not within the cutoff. □\square

Lemma 3 (the half-skin rule). If d(1)≤s/2d_{(1)} \le s / 2, then d(1)+d(2)≤sd_{(1)} + d_{(2)} \le s. So the half-skin rule rebuilds whenever the test of line L6 does, and Lemma 2 holds after it too. Proof. d(2)≤d(1)≤s/2d_{(2)} \le d_{(1)} \le s/2. □\square

Theorem. Each call of PAIRS reports each unordered pair {i,j}\{i, j\} with ∥ri−rj∥<rc\|r_i - r_j\| < r_c exactly once, and no other pair. Proof. After lines L5 to L7 there are two cases. If line L6 found d(1)+d(2)>sd_{(1)} + d_{(2)} > s, line L7 rebuilt the list at the current positions, so now r0=rr^0 = r, all di=0d_i = 0, and the hypothesis of Lemma 2 holds. Otherwise line L6 found d(1)+d(2)≤sd_{(1)} + d_{(2)} \le s. In both cases, by Lemma 2, every pair within rcr_c is in L\mathcal{L}. Line L8 visits each element of L\mathcal{L} once, and L\mathcal{L} holds each unordered pair at most once, as (i,j)(i, j) with i<ji < j. Line L9 reports exactly the visited pairs with ∥ri−rj∥<rc\|r_i - r_j\| < r_c. So the reported set is the set of pairs within the cutoff, each once. □\square

The theorem does not need rℓ≤L/2r_\ell \le L/2. That condition, which the implementation checks, makes the nearest image of each pair within rℓr_\ell unique, so that one stored pair stands for one interaction, as the force loop assumes. The theorem also does not assume that the atoms move by small steps: the displacement did_i is the torus distance from the reference position, and Lemma 1 holds for any motion.

Termination. BUILD runs over the N(N−1)/2N(N-1)/2 pairs and the NN atoms. PAIRS computes NN displacements, finds the two largest in O(N)O(N), calls BUILD at most once, and runs over the finite list. So each call stops. ■\blacksquare

Remark (the wrong test). The test "rebuild when d(1)>sd_{(1)} > s" is not safe. Two atoms at distance rℓr_\ell that each move 0.6s0.6 s toward each other have d(1)=0.6s≤sd_{(1)} = 0.6 s \le s, and they end at distance rℓ−1.2s=rc−0.2s<rcr_\ell - 1.2 s = r_c - 0.2 s < r_c, a pair not in the list. Lemma 2 needs the sum of the two displacements, because the gap closes from both ends.

Complexity

The model is the word RAM, with one distance test counted as one operation. Let PP be the number of pairs in the list.

  • Build. N(N−1)/2N(N-1)/2 tests with the direct loop. With a linked-cell list whose cells have side at least rℓr_\ell, O(N)O(N) at fixed density.
  • Step without a rebuild. O(N)O(N) for the displacements of line L5 and the two largest values, and O(P)O(P) for the pair tests.
  • Size of the list. At number density ρ\rho, an atom has on average about 43πrℓ3ρ\frac{4}{3}\pi r_\ell^3 \rho atoms within rℓr_\ell, so P≈23πrℓ3ρNP \approx \frac{2}{3}\pi r_\ell^3 \rho N, which is O(N)O(N) at fixed density. For the Lennard-Jones liquid at ρ∗=0.8\rho^* = 0.8 with rc=2.5r_c = 2.5 and s=0.3s = 0.3, this is about 73.6 neighbors per atom within rℓ=2.8r_\ell = 2.8, of which about 52.4 lie within rcr_c: about 71 percent of the tested pairs are hits, against at most 15.5 percent for the 27 cells of a cell list. These are geometric averages for a uniform density, not measurements.
  • Space. O(N+P)O(N + P).
operation time case
build O(N2)O(N^2) direct loop
build O(N)O(N) with a cell list, at fixed density
step O(N+P)O(N + P) without a rebuild
space O(N+P)O(N + P) total

The number of steps between rebuilds depends on the skin, the temperature and the time step hh, so the gain is a measurement. A larger skin makes rebuilds rarer and the list longer; the best skin is found by trying a few values. Allen and Tildesley show the speedup for the Lennard-Jones fluid at rc∗=2.5r_c^* = 2.5, ρ∗=0.78\rho^* = 0.78, T∗=0.85T^* = 0.85 and h∗=0.005h^* = 0.005 as a function of the skin (Section 5.3.1).

Variants

  • Half-skin rule. Rebuild when one atom has moved more than s/2s/2. It needs only the largest displacement, and it rebuilds at least as often as the test of line L6.
  • Fixed interval. Rebuild every kk steps, with kk often 10 to 20. It needs no displacement tracking, but it has no guarantee: a fast atom can cross the skin, and a missed pair gives a wrong force with no warning. It is a rule of thumb.
  • Verlet list built with cells. Build the list with a linked-cell list of cell side rℓr_\ell, so that both the build and the step are O(N)O(N) at fixed density (Frenkel and Smit, Appendix F.3).
  • Full list. Store each pair twice, once for each atom. It doubles the memory and the tests, but each atom then sums its own force with no writes to other atoms, which suits parallel and GPU code.
  • Lists for Monte Carlo. In Monte Carlo, one atom moves at a time, and the same displacement test decides when to rebuild.
  • Multiple time steps. In RESPA, the short-range force uses the Verlet list and the slow force is evaluated less often.

When to use it

Use a Verlet list when atoms move a small distance per step compared with the cutoff, as in liquids, solids and biomolecules, so that one build serves many steps. It is worth more when the force per pair is costly, because the list wastes fewer tests than the 27 cells of a cell list. For a small system, a few hundred atoms or fewer, build it with the direct loop. For a large system, build it with a linked-cell list. Do not use it when the atoms move fast relative to the skin, as in a hot gas or a shock, because the list is then rebuilt at almost every step and the extra memory buys nothing; a plain linked-cell list is then better.

Pitfalls

  • Testing one displacement against the full skin. Two atoms that each move 0.6s0.6 s toward each other close a gap of 1.2s1.2 s, so the test d(1)>sd_{(1)} > s misses pairs, as the example shows. Use the half-skin rule or the two largest displacements.
  • Displacements per step instead of since the build. The test needs the displacement from the reference positions ri0r_i^0 of the last build. Small steps add up.
  • Displacements across the boundary. If positions are wrapped into the box, an atom that crosses the boundary seems to jump by LL. Use the minimum image of ri−ri0r_i - r_i^0, or keep unwrapped positions for the displacements.
  • A list radius above half the box. With rℓ>L/2r_\ell > L/2, a pair can have two images within rℓr_\ell, and one stored pair cannot stand for both. Check rc+s≤L/2r_c + s \le L/2, as the implementation does.
  • A box that changes size. Under a barostat, the box and all distances scale. A list built in the old box can miss pairs in the new one unless the test accounts for the change.
  • Calling it a speedup in all cases. The gain depends on the skin, the density and the temperature. It is a measured result for a given system.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

verlet_neighbor_list.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/verlet-neighbor-list/. The authors are listed in prov/NKWXRA.jsonl.

import math

Point = list[float]


def minimum_image_dist2(a: Point, b: Point, box: float) -> float:
    """Squared distance from a to the nearest periodic image of b in a cubic box of side box."""
    s = 0.0
    for x, y in zip(a, b):
        d = x - y
        d -= box * round(d / box)
        s += d * d
    return s


class VerletList:
    """A Verlet neighbor list with cutoff rc and skin in a periodic cubic box.

    The list holds the pairs i < j closer than rc + skin at the last build.
    rule is "two" (rebuild when the two largest displacements since the build
    add up to more than the skin) or "half" (rebuild when one displacement is
    more than half the skin). Both are safe; "half" rebuilds at least as often.
    """

    def __init__(self, positions: list[Point], box: float, rc: float, skin: float, rule: str = "two") -> None:
        if rc + skin > box / 2:
            raise ValueError("rc + skin must be at most half the box")
        if rule not in ("two", "half"):
            raise ValueError("rule must be 'two' or 'half'")
        self.box, self.rc, self.skin, self.rule = box, rc, skin, rule
        self.builds = 0
        self.build(positions)

    def build(self, positions: list[Point]) -> None:
        """Store every pair i < j closer than rc + skin, and the positions at this build. O(N^2)."""
        rl2 = (self.rc + self.skin) ** 2  # @line L1
        n = len(positions)
        self.neighbors: list[tuple[int, int]] = []
        for i in range(n):  # @line L2
            for j in range(i + 1, n):  # @line L2
                if minimum_image_dist2(positions[i], positions[j], self.box) < rl2:  # @line L3
                    self.neighbors.append((i, j))  # @line L3
        self.reference = [list(r) for r in positions]  # @line L4
        self.builds += 1

    def displacements(self, positions: list[Point]) -> list[float]:
        """The minimum image distance of each atom from its position at the last build."""
        return [math.sqrt(minimum_image_dist2(r, r0, self.box)) for r, r0 in zip(positions, self.reference)]

    def needs_rebuild(self, positions: list[Point]) -> bool:
        d = self.displacements(positions)  # @line L5
        if self.rule == "half":
            return max(d, default=0.0) > self.skin / 2
        top = sorted(d, reverse=True)[:2] + [0.0, 0.0]  # @line L6
        return top[0] + top[1] > self.skin  # @line L6

    def pairs(self, positions: list[Point]) -> list[tuple[int, int]]:
        """The pairs i < j closer than rc at these positions, rebuilding the list first if needed."""
        if self.needs_rebuild(positions):  # @line L7
            self.build(positions)  # @line L7
        rc2 = self.rc * self.rc
        out = []
        for i, j in self.neighbors:  # @line L8
            if minimum_image_dist2(positions[i], positions[j], self.box) < rc2:  # @line L9
                out.append((i, j))  # @line L9
        return out
test_verlet_neighbor_list.py 111 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/verlet-neighbor-list/. The authors are listed in prov/NKWXRA.jsonl.

import itertools
import random

import pytest

from verlet_neighbor_list import VerletList, minimum_image_dist2


def brute_force_pairs(positions, box, rc):
    """Every pair i < j whose nearest periodic image is closer than rc.

    In a cubic box the 27 images split by coordinate, so the nearest image
    takes the smallest of the shifts -box, 0 and box on each axis.
    """
    out = []
    for i, j in itertools.combinations(range(len(positions)), 2):
        best = 0.0
        for a in range(3):
            d = positions[i][a] - positions[j][a]
            best += min(d * d, (d - box) ** 2, (d + box) ** 2)
        if best < rc * rc:
            out.append((i, j))
    return out


def page_atoms():
    return [[1.0, 0.0, 0.0], [3.95, 0.0, 0.0], [1.0, 3.05, 0.0]]


def test_page_example_build():
    v = VerletList(page_atoms(), 10.0, 2.5, 0.5)
    assert v.neighbors == [(0, 1)]
    assert v.pairs(page_atoms()) == []


def test_page_example_two_atoms_approach():
    v = VerletList(page_atoms(), 10.0, 2.5, 0.5)
    moved = [[1.0, 0.3, 0.0], [3.95, 0.0, 0.0], [1.0, 2.75, 0.0]]
    assert v.displacements(moved) == pytest.approx([0.3, 0.0, 0.3])
    # One atom alone moved less than the skin, but the pair (0, 2) is now at 2.45.
    assert max(v.displacements(moved)) < v.skin
    assert v.needs_rebuild(moved)
    assert v.pairs(moved) == [(0, 2)]
    assert v.builds == 2


def test_page_example_stale_list_would_miss_the_pair():
    v = VerletList(page_atoms(), 10.0, 2.5, 0.5)
    moved = [[1.0, 0.3, 0.0], [3.95, 0.0, 0.0], [1.0, 2.75, 0.0]]
    stale = [p for p in v.neighbors if minimum_image_dist2(moved[p[0]], moved[p[1]], 10.0) < 2.5 ** 2]
    assert stale == []
    assert brute_force_pairs(moved, 10.0, 2.5) == [(0, 2)]


def test_page_example_two_rule_saves_a_rebuild():
    moved = [[1.0, 0.0, 0.0], [3.65, 0.0, 0.0], [1.0, 2.95, 0.0]]
    two = VerletList(page_atoms(), 10.0, 2.5, 0.5, rule="two")
    half = VerletList(page_atoms(), 10.0, 2.5, 0.5, rule="half")
    assert not two.needs_rebuild(moved)
    assert half.needs_rebuild(moved)
    assert two.pairs(moved) == half.pairs(moved) == brute_force_pairs(moved, 10.0, 2.5)


@pytest.mark.parametrize("rule", ["two", "half"])
def test_random_walk_against_brute_force(rule):
    rng = random.Random(11)
    box, rc, skin, n = 7.0, 1.5, 0.4, 60
    pos = [[rng.uniform(0, box) for _ in range(3)] for _ in range(n)]
    v = VerletList(pos, box, rc, skin, rule=rule)
    for _ in range(60):
        for r in pos:
            for a in range(3):
                r[a] = (r[a] + rng.gauss(0.0, 0.02)) % box
        assert v.pairs(pos) == brute_force_pairs(pos, box, rc)
    assert 1 < v.builds < 60


def test_two_rule_rebuilds_no_more_than_half_rule():
    rng = random.Random(12)
    box, rc, skin, n = 7.0, 1.5, 0.4, 80
    start = [[rng.uniform(0, box) for _ in range(3)] for _ in range(n)]
    steps = [[[rng.gauss(0.0, 0.02) for _ in range(3)] for _ in range(n)] for _ in range(150)]
    counts = {}
    for rule in ("two", "half"):
        pos = [list(r) for r in start]
        v = VerletList(pos, box, rc, skin, rule=rule)
        for step in steps:
            for r, dr in zip(pos, step):
                for a in range(3):
                    r[a] = (r[a] + dr[a]) % box
            v.pairs(pos)
        counts[rule] = v.builds
    assert counts["two"] <= counts["half"]


def test_atom_crossing_the_boundary():
    pos = [[9.9, 5.0, 5.0], [2.3, 5.0, 5.0]]
    v = VerletList(pos, 10.0, 2.5, 0.5)
    assert v.neighbors == [(0, 1)]
    pos[0][0] = (9.9 + 0.2) % 10.0
    assert v.displacements(pos)[0] == pytest.approx(0.2)
    assert v.pairs(pos) == [(0, 1)]
    assert v.builds == 1


def test_list_radius_must_fit_the_box():
    with pytest.raises(ValueError):
        VerletList([[0.0, 0.0, 0.0]], 5.0, 2.3, 0.4)

History

Loup Verlet introduced the list in his 1967 paper on the Lennard-Jones fluid, the same paper that made the Verlet integrator popular. He kept for each atom a table of the atoms within a radius somewhat larger than the cutoff and refreshed it only from time to time, so most steps did not search the whole box. Automatic tests based on the displacements since the last build came later; Allen and Tildesley credit the test on the two largest displacements to Fincham (1981) and Thompson (1983). Combining the list with cells, so that the build too is linear in NN, became the standard method in molecular dynamics codes.

References

  1. Loup Verlet, Computer "experiments" on classical fluids. I. Thermodynamical properties of Lennard-Jones molecules, Physical Review 159(1), 1967, 98-103, the table of neighbors within a radius larger than the cutoff, refreshed at intervals
  2. Michael P. Allen and Dominic J. Tildesley, Computer Simulation of Liquids, second edition, Oxford University Press, 2017, Section 5.3.1, The Verlet neighbour list (the automatic update test on the two largest displacements, and the measured speedup for the Lennard-Jones fluid)
  3. Daan Frenkel and Berend Smit, Understanding Molecular Simulation, From Algorithms to Applications, second edition, Academic Press, 2002, Appendix F, Saving CPU time (F.1 Verlet list, F.3 Combining the Verlet and cell lists, F.4 Efficiency)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.build_direct
  • a full proof of time.build_with_cells_fixed_density
  • a full proof of time.step
  • a full proof of space.total
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/NKWXRA/text.yaml