wrap_positions

jaxrens.utils.cell.wrap_positions(positions, cell)[source]

Wrap atom positions into the home unit cell (fractional coords in [0, 1)).

Graph backends (MACE/nequix) find neighbors via a finite supercell image set (e.g. n in {-1,0,1}^3). That set is only complete when every atom sits in (or within one cell of) the home cell, so atoms that have drifted out of the cell — which they do under unwrapped Cartesian moves over a long NS run — would silently lose edges and get a wrong, position-origin-dependent energy. Wrapping restores the lattice-translation invariance the periodic energy must have.

Convention matches the rest of this module: cell rows are lattice vectors and positions are row vectors, so frac = positions @ inv(cell) and positions = frac @ cell.

Properties: * Grad-safe: floor has zero gradient, so d(wrapped)/d(positions)

is the identity almost everywhere — forces (galilean/HMC) are unchanged.

  • Degenerate-cell-safe: non-periodic systems pass cell == 0 (or a dummy safe_cell); for any singular cell this is a no-op, and the inv of the singular branch is masked so no NaNs leak through.

Parameters:
  • positions (Array) – (N, 3) Cartesian positions.

  • cell (Array) – (3, 3) cell matrix, rows are lattice vectors.

Returns:

(N, 3) positions wrapped into the home cell, or positions unchanged when cell is degenerate (|det| ~ 0).

Return type:

Array