Jax API reference

class vesin_jax.NeighborList(*, cutoff: float, full_list: bool, sorted: bool = False, padded_to: int | None = None, fixed_n_pairs: int | None = None, algorithm: str = 'auto', skin: float = 0.0, n_threads: int = 0)

A neighbor list calculator that can be used with JAX.

The calculation is compatible with jax.jit() and jax.vmap() when either padded_to or fixed_n_pairs is set, since the number of pairs is then a known, static shape:

  • with padded_to, there are n_points * padded_to pairs, with missing pairs for each point padded with pseudo-pairs (i, -1) carrying a zero shift;

  • with fixed_n_pairs, there are fixed_n_pairs pairs, the actual pairs coming first, followed by pseudo-pairs (-1, -1) carrying a zero shift.

If both are None, the number of pairs is dynamic, and the calculation only works outside of jax.jit() and jax.vmap().

Parameters:
  • cutoff – spherical cutoff for this neighbor list

  • full_list – should we return each pair twice (as i-j and j-i) or only once

  • sorted – Should the neighbor list be sorted? If True, the returned pairs will be sorted by the first point index (i). The order of the second point index (j) and shifts in the list of pairs is unspecified.

  • padded_to – pad full lists so every point has exactly this many outgoing pairs, using (i, -1) pseudo-pairs with zero shift, distance and vector. Computing the list fails if a point has more neighbors than this, unless "n" is part of the requested quantities in compute().

  • fixed_n_pairs – pad the neighbor list to exactly this many pairs in total, adding (-1, -1) pseudo-pairs with zero shift, distance and vector after the actual pairs. Computing the list fails if there are more pairs than this, unless "n" is part of the requested quantities in compute(). This can not be used together with padded_to.

  • algorithm – algorithm to use when computing the neighbor list. One of "auto", "brute_force", or "cell_list".

  • skin – skin size for Verlet caching. A positive value enables caching the neighbor list until any atom moves farther than skin/2 from its reference coordinates. A negative value sets the skin to an unspecified fraction of the cutoff that is optimal for the current implementation. Zero disables caching (the default).

  • n_threads – number of CPU threads to use. Must be 0 or a positive integer. If set to 0, Vesin uses OMP_NUM_THREADS when set to a positive integer, and otherwise the number of available CPU cores.

property cutoff: float

The cutoff distance for this neighbor list.

property full_list: bool

Whether this neighbor list returns both i-j and j-i pairs.

property sorted: bool

Whether this neighbor list is sorted by the first index i.

property padded_to: int | None

Number of outgoing pairs each point is padded to, or None.

property fixed_n_pairs: int | None

Total number of pairs the neighbor list is padded to, or None.

property algorithm: str

Algorithm used to compute this neighbor list.

property skin: float

Skin size used for Verlet caching.

property n_threads: int

Number of CPU threads requested for the calculation.

compute(points: Array, box: Array, periodic: bool | Sequence[bool], quantities: str = 'ij') → Tuple[Array, ...]

Compute the neighbor list for the system defined by points, box, and periodic; returning the requested quantities.

quantities can contain any combination of the following values:

  • "i" to get the index of the first point in the pair

  • "j" to get the index of the second point in the pair

  • "P" to get the indexes of the two points in the pair simultaneously

  • "S" to get the periodic shift of the pair

  • "d" to get the distance between points in the pair

  • "D" to get the distance vector between points in the pair

  • "n" to get the number of pairs in the neighbor list. If either fixed_n_pairs or padded_to are set and result in a capacity that is too small, the returned value of "n" is the required total capacity to hold all pairs, and all other outputs are filled with pseudo-pairs (-1, -1) and zero shifts, distances and vectors. This can be used inside jax.jit() to detect when the neighbor list needs to be re-created with a larger size.

The distances and distance vectors are always recomputed from the pairs and shifts with JAX operations, making the calculation differentiable with respect to points and box, and are returned with the same dtype as points.

The pairs indexes are returned as int64 arrays if 64-bit support is enabled in JAX (jax.config.update("jax_enable_x64", True)), and int32 arrays otherwise. The shifts are always returned as int32 arrays. The neighbor list itself is always computed with float64 precision.

Parameters:
  • points – positions of all points in the system

  • box – bounding box of the system, as a 3x3 matrix. Ignored if the system is not periodic, but must still be provided.

  • periodic – should we use periodic boundary conditions? This can be a single boolean to enable/disable periodic boundary conditions in all directions, or a sequence of three booleans (one for each direction).

  • quantities – quantities to return, defaults to “ij”

Returns:

tuple of jax.Array as indicated by quantities.