xnn.common.data.atomic_data.AtomicGraph#
- class xnn.common.data.atomic_data.AtomicGraph(pos, atomic_numbers, edge_index, cell_shifts, batch, n_atoms, cell=None, pbc=None, energy=None, forces=None, stress=None, total_charge=None, weight=None)[source]#
Bases:
objectGraph representation of one or a batch of atomic systems.
AtomicGraphis the single data abstraction that flows through the whole library: every model inxnn.common.modelsconsumes this object and nothing else. It represents molecular or periodic systems as a graph where nodes are atoms and edges connect neighboring atoms within a cutoff. A batch is several graphs concatenated along the node/edge axes, with abatchvector mapping each node to its structure index (the PyTorch Geometric convention).Positions, cell and the integer
cell_shiftsare stored separately from edge displacement vectors; the displacementr_ijis recomputed inside the model (seeedge_vectors()) so that autograd can flow back topos(forces) andcell(stress).- Parameters:
pos (Tensor) – Cartesian positions of shape
(N, 3).atomic_numbers (Tensor) – Integer atomic number
Zper atom, of shape(N,).edge_index (Tensor) – Edge list of shape
(2, E)holding[src, dst]node indices; the energy ofdstdepends onsrc.cell_shifts (Tensor) – Integer periodic image shift for each edge, of shape
(E, 3).batch (Tensor) – Structure index per atom, of shape
(N,)(all zero for a single structure).n_atoms (Tensor) – Number of atoms per structure, of shape
(B,).cell (Tensor, optional) – Lattice vectors as rows, of shape
(B, 3, 3).Nonefor molecular systems.pbc (Tensor, optional) – Boolean periodicity flags, of shape
(B, 3).Nonefor molecular systems.energy (Tensor, optional) – Target energy per structure, of shape
(B,). Present during training.forces (Tensor, optional) – Target forces, of shape
(N, 3). Present during training.stress (Tensor, optional) – Target stress, of shape
(B, 3, 3). Present during training.total_charge (Tensor, optional) – Net charge per structure, of shape
(B,).Nonemeans neutral. Read by the charge-aware models (D4 dispersion, PhysNet, ReaxFF).weight (Tensor, optional) – Per-structure loss weight, of shape
(B,).Nonemeans every structure counts equally, which is the default and reproduces the unweighted loss exactly. Read only byweighted_loss(); no model sees it.
- Variables:
pos (Tensor) – Cartesian positions
(N, 3).atomic_numbers (Tensor) – Integer atomic number
Zper atom(N,).edge_index (Tensor) – Edge list
(2, E)as[src, dst].cell_shifts (Tensor) – Integer periodic image shift per edge
(E, 3).batch (Tensor) – Structure index per atom
(N,).n_atoms (Tensor) – Atoms per structure
(B,).cell (Tensor or None) – Lattice vectors as rows
(B, 3, 3).pbc (Tensor or None) – Boolean periodicity flags
(B, 3).energy (Tensor or None) – Target energy
(B,).forces (Tensor or None) – Target forces
(N, 3).stress (Tensor or None) – Target stress
(B, 3, 3).total_charge (Tensor or None) – Net charge per structure
(B,).weight (Tensor or None) – Per-structure loss weight
(B,).
- to(device)[source]#
Return a copy of the graph with all tensors moved to
device.- Parameters:
device (torch.device or str) – Target device to move every tensor field to.
- Returns:
A new
AtomicGraphwhose tensor fields live ondevice. Non-tensor fields (e.g.None) are copied unchanged.- Return type:
- edge_vectors()[source]#
Compute the displacement vector
r_ijfor every edge.The displacement is
pos[dst] - pos[src]plus, for periodic systems, the contributioncell_shift @ cellof the periodic image. The result is differentiable with respect topos(forces) andcell(stress). Works for molecular (cellisNone) and periodic systems alike.- Returns:
Edge displacement vectors
r_ijof shape(E, 3).- Return type:
Tensor