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:
cellrows are lattice vectors and positions are row vectors, sofrac = positions @ inv(cell)andpositions = frac @ cell.Properties: * Grad-safe:
floorhas zero gradient, sod(wrapped)/d(positions)is the identity almost everywhere — forces (galilean/HMC) are unchanged.
Degenerate-cell-safe: non-periodic systems pass
cell == 0(or a dummysafe_cell); for any singular cell this is a no-op, and theinvof 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
positionsunchanged whencellis degenerate (|det| ~ 0).- Return type:
Array