npx skills add ...
npx skills add nvidia/nvalchemi-toolkit --skill nvalchemi-data-structures
How to use AtomicData and Batch, the core graph-based data structures for representing atomic systems and batching them for GPU computation. Use when building systems from positions, cells, and atomic numbers, converting from ASE Atoms, batching or unbatching structures, reading per-atom vs per-graph tensors, or debugging shape, dtype, or device errors in model inputs.
npx skills add nvidia/nvalchemi-toolkit --skill nvalchemi-data-structures
nvalchemi represents atomic systems as graphs using two core classes:
AtomicData — a single atomic system (molecule, crystal, etc.)Batch — an efficient container of multiple AtomicData objects
stored as concatenated tensorsBoth are Pydantic BaseModel subclasses with DataMixin for device/dtype operations.
Required fields: positions [n_nodes, 3] and atomic_numbers [n_nodes].
From ASE Atoms:
Fields are organized by level. All are optional except positions and atomic_numbers.
| Level | Field | Shape | Notes |
|---|---|---|---|
| Node | atomic_numbers | [V] | Required, int64 |
| Node | positions | [V, 3] | Required, float |
| Node | atomic_masses | [V] | Auto-populated from periodic table |
| Node | atom_categories | [V] | Defaults to zeros |
| Node | forces | [V, 3] | eV/Angstrom |
| Node | velocities | [V, 3] | Auto-initialized to zeros |
| Node | momenta | [V, 3] | |
| Node | charges | [V, 1] | |
| Node | node_embeddings | [V, H] | |
| Node | kinetic_energies | [V, 1] | |
| Edge | neighbor_list | [E, 2] | COO format, int64 |
| Edge | shifts | [E, 3] | Cartesian displacements (neighbor_list_shifts @ cell) |
| Edge | neighbor_list_shifts | [E, 3] | Integer lattice image indices |
| Edge | edge_embeddings | [E, H] | |
| Dense | neighbor_matrix | [V, K] | Dense neighbor matrix (int64) |
| Dense | neighbor_matrix_shifts | [V, K, 3] | Periodic shifts for dense neighbors |
| Dense | num_neighbors | [V] | Valid neighbor count per atom |
| System | cell | [1, 3, 3] | Lattice vectors |
| System | pbc | [1, 3] | Periodic boundary conditions (bool) |
| System | energy | [1] | eV |
| System | stress | [1, 3, 3] | eV/Angstrom^3 |
| System | virial | [1, 3, 3] | |
| System | dipole | [1, 3] | |
| System | charge | [1] | |
| System | graph_embeddings | [1, H] |
Custom data can be stored in the info: dict[str, torch.Tensor] field.
Two AtomicData objects are equal if they have the same chemical_hash:
For high-throughput workflows (e.g. streaming dynamics), use pre-allocated buffers:
Batch supports point-to-point distributed communication via
torch.distributed. Data is sent in three phases: a metadata header
(num_graphs, num_nodes, num_edges), per-group segment lengths,
and bulk tensor data.
Blocking send/recv:
Non-blocking send/recv:
Key details:
template is required on the receiver to know the attribute keys,
dtypes, and group structure (atoms/edges/system). Cache it across calls.tag is a base tag incremented internally per group. Use distinct
base tags for concurrent send/recv pairs.empty_like(batch) creates a 0-graph batch with the same schema, which
is useful for sentinel signals.