mod types¶
- module types¶
C-compatible core data types for force/energy calculations.
These two
#[repr(C)]structs are the fundamental data exchange types at the FFI boundary. Each field that previously held a raw pointer to a flat array now holds a*mut DLManagedTensorVersioned, making the types device-agnostic (CPU, CUDA, ROCm, etc.) via the DLPack tensor exchange protocol.Memory Model
Input tensors are borrowed — the caller retains ownership.
Output forces are callee-allocated — the callback sets
output.forcesto a DLPack tensor it creates. After the call, the caller takes ownership and must free it viargpot_tensor_free.Energy and variance are plain
f64scalars, always on the host.
DLPack Tensor Shapes
Field
dtype
ndim
shape
positionsf64
2
[n_atoms, 3]atomic_numbersi32
1
[n_atoms]box_matrixf64
2
[3, 3]forcesf64
2
[n_atoms, 3]Structs and Unions
- struct rgpot_force_input_t¶
Input configuration for a potential energy evaluation.
All tensor fields are borrowed — the caller retains ownership and must keep them alive for the lifetime of this struct.
Example (from C)
double positions[] = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0}; int types[] = {1, 1}; double cell[] = {10.0,0,0, 0,10.0,0, 0,0,10.0}; rgpot_force_input_t input = rgpot_force_input_create(2, positions, types, cell); // ... use input ... rgpot_force_input_free(&input);
- positions: *mut DLManagedTensorVersioned¶
Positions tensor:
[n_atoms, 3], dtype f64, any device.
- atomic_numbers: *mut DLManagedTensorVersioned¶
Atomic numbers tensor:
[n_atoms], dtype i32, any device.
- box_matrix: *mut DLManagedTensorVersioned¶
Box matrix tensor:
[3, 3], dtype f64, any device.
Implementations
- impl rgpot_force_input_t¶
Functions
- unsafe fn n_atoms(&self) -> Option<usize>¶
Extract
n_atomsfrom the positions tensor’sshape[0].Returns
Noneifpositionsis null or has no shape.Safety
The
positionstensor must be a valid DLPack tensor with ndim >= 1.
- struct rgpot_force_out_t¶
Results from a potential energy evaluation.
The
forcesfield starts asNULLand is set by the potential callback to a callee-allocated DLPack tensor. After the call, the caller owns the tensor and must free it viargpot_tensor_free.Fields
forces: output force tensor, same shape/dtype aspositions.energy: the calculated potential energy.variance: uncertainty estimate; zero when not applicable.
- forces: *mut DLManagedTensorVersioned¶
Forces tensor
[n_atoms, 3], f64 — set by the callback.
- energy: f64¶
Calculated potential energy.
- variance: f64¶
Variance / uncertainty of the calculation (0.0 when unused).