nvalchemi.models.base.NeighborConfig#
- pydantic model nvalchemi.models.base.NeighborConfig[source]#
Configuration for on-the-fly neighbor list construction.
An instance of this class attached to a
ModelConfig(via itsneighbor_configfield) signals that the model requires a neighbor list and describes the format and parameters it expects. At runtime aNeighborListHookreads this config to compute and cache the appropriate neighbor data on eachBatchbefore the model’s forward pass, rebuilding only when atoms have moved beyond the Verletskin.The single required argument is
cutoff(in the same length units aspositions).formatselects the storage layout:COOproduces a sparse[E, 2]edge index (the default, used by most GNN-based MLIPs), whileMATRIXproduces a dense[N, max_neighbors]neighbor matrix (used by Warp interaction kernels) — seeNeighborListFormat.half_listandskintune pair deduplication and rebuild frequency, respectively.Examples
A minimal sparse (COO) neighbor list with a 5 A cutoff:
>>> from nvalchemi.models.base import NeighborConfig >>> nc = NeighborConfig(cutoff=5.0) >>> nc.format <NeighborListFormat.COO: 'coo'>
A dense half neighbor list with a Verlet skin, e.g. for a Warp kernel:
>>> from nvalchemi.models.base import NeighborListFormat >>> nc = NeighborConfig( ... cutoff=5.0, ... format=NeighborListFormat.MATRIX, ... half_list=True, ... skin=1.0, ... )
Attach it to a
ModelConfigto declare a neighbor-list requirement:>>> from nvalchemi.models.base import ModelConfig >>> cfg = ModelConfig(neighbor_config=NeighborConfig(cutoff=5.0)) >>> cfg.needs_neighborlist True
Notes
skin=0.0(the default) rebuilds the neighbor list every step; a positive skin defers rebuilds until any atom moves more thanskin / 2, trading memory staleness for fewer rebuilds.half_list=Truestores each(i, j)pair once; the interaction kernel applies Newton’s third law to recover forces on both atoms, so it is only appropriate for kernels that expect a half list.
- field cutoff: float [Required]#
Interaction cutoff radius in the same length units as positions.
- field format: NeighborListFormat = NeighborListFormat.COO#
Whether to build a dense neighbor matrix (
MATRIX) or a sparse edge-index list (COO). Defaults toCOO.
- field half_list: bool = False#
If
True, each pair(i, j)withi < jappears only once. Newton’s third law is applied inside the interaction kernel to recover forces on both atoms. Defaults toFalse.
- field skin: float = 0.0#
Verlet skin distance. The neighbor list is only rebuilt when any atom has moved more than
skin / 2since the last build. Set to0.0(default) to rebuild every step.