C ABI (minimage_*)
Function symbols use the minimage_ prefix. Every buffer is
caller-owned. Coordinates, lattice vectors, and origins share one
consistent length unit; minimage_cell_from_con_box takes angles in
degrees. Displacements compute wrap(q - p).
Every int-returning function in the first table returns 0 on success and 1 on failure
(null pointer, invalid cell, buffer/index mismatch, or overflow). Read
minimage_last_error() on the same thread immediately after a nonzero
return; do not free the returned pointer. The next successful
minimage_* call on that thread clears the slot so
minimage_last_error() returns NULL. minimage_version() returns a
process-static string and neither reads nor modifies the error slot.
| Symbol | Role |
|---|---|
mi_cell |
Lattice vectors a, b, c (columns of H) and origin |
mi_cell_ortho |
Header-only diagonal box with zero origin |
minimage_cell_from_vectors |
Columns a, b, c and origin |
minimage_cell_from_lammps |
Dump-bound xlo xhi ylo yhi zlo zhi plus tilts |
minimage_cell_from_lammps_bounds |
Dump bound spans, tilts, and bound lo |
minimage_cell_from_ase |
Row-major 3x3 plus optional origin (NULL -> zero) |
minimage_cell_from_con |
CON 3x3 (zero origin) |
minimage_cell_from_con_box |
Lengths and angles in degrees (zero origin) |
minimage_cell_from_con_box_exact |
As minimage_cell_from_con_box, with an angle equal to 90 degrees taken as an exact right angle |
minimage_cell_from_vesin |
vesin 3x3 (zero origin) |
minimage_displacement |
Engine wrapped q - p |
minimage_displacement_euclidean |
Smith test, else the Selling slicer (exact Voronoi MIC) |
minimage_wrap_many |
Engine wrap of n packed difference vectors |
minimage_dist2 |
Squared minimum-image distance |
minimage_dist2_many |
One source, n packed candidates |
minimage_dist2_pairs |
n packed pair rows |
minimage_dist2_euclidean_many |
Euclidean nearest image, one source, packed candidates |
minimage_dist2_euclidean_pairs |
Euclidean nearest image, packed pair lists |
minimage_dist2_euclidean_pairs_warm |
Euclidean pairs from previous frame's int32_t shifts |
minimage_dist2_ortho_diffs |
Highway-shaped ortho wrap, AVX/NEON when present |
minimage_dist2_shifted_many |
One lattice shift, many candidates |
minimage_fixed_many |
Positions to 64-bit fixed-point fractions |
minimage_dist2_fixed |
Squared distance between two 64-bit fixed-point positions |
minimage_dist2_many_fixed |
One 64-bit fixed-point source, packed candidates |
minimage_dist2_pairs_fixed |
Packed 64-bit fixed-point pair lists |
minimage_fixed32_many, minimage_dist2_fixed32 |
32-bit fixed-point fractions and distance |
minimage_dist2_many_fixed32, minimage_dist2_pairs_fixed32 |
32-bit fixed-point batches |
mi_pbc_cell |
An mi_cell with three periodicity flags (pbc_a, pbc_b, pbc_c) |
minimage_pbc_cell_from_ase |
Row-major 3x3, mask of three ints, optional origin (NULL -> zero) |
minimage_displacement_euclidean_pbc |
Nearest image over the periodic axes only |
minimage_dist2_euclidean_pbc |
Squared length of minimage_displacement_euclidean_pbc |
minimage_filter_shifted |
Filter (ii, jj, shift) pairs below cut2; out_vector may be NULL |
minimage_ring_centroid |
Bead-major ring-polymer centroids wrapped into primary cell |
minimage_face_spacing |
Perpendicular altitude of the face opposite a lattice axis |
minimage_unique_image_radius |
Radius inside which a pair displacement has one nearest image; zero when no axis is periodic |
minimage_cutoff_exceeds_half_width |
Nonzero when 2 * cutoff reaches or exceeds a periodic face altitude |
mi_image_pair |
One periodic image (i, j, shift, d, dist2) within a cutoff |
minimage_pairs_within_images |
Enumerate all periodic images within cutoff (half or full list) |
minimage_visit_pairs_within_images |
Single-pass callback visitor over periodic images within cutoff; a nonzero callback return stops the walk |
minimage_reduce_pairs |
Drop self images, sort and deduplicate (i, j) pairs |
minimage_nd_wrap_point |
Wrap one N-dimensional point; zero period marks an open axis |
minimage_nd_wrap_difference |
Wrap one N-dimensional difference into its central image |
minimage_nd_dist2, minimage_nd_distance |
Scalar N-dimensional product-metric distances |
minimage_nd_dist2_many |
One point against contiguous row-major points |
minimage_nd_axis_min_dist2 |
Periodic per-axis lower bound to an interval |
minimage_nd_aabb_min_dist2 |
Periodic lower-bound squared distance to an axis-aligned box |
minimage_last_error |
Thread-local error string (NULL after success) |
minimage_version |
Process-static version string |
Function symbols use minimage_, the full crate name, to avoid
mimalloc's mi_ namespace. The non-default capi-compat-names Cargo
feature exports deprecated thin mi_ aliases for migration and must
not be linked with mimalloc.
Loading at run time
A host that opens the shared library by path, rather than linking it,
resolves three symbols by name and takes every other operation from a
table. These calls are additive: the entry points above keep their
names, signatures, and 0 / 1 returns.
minimage_abi_stamp(&abi)writes the ABI the library was built for.minimage_abi_compatible(&host)returnsMINIMAGE_STATUS_OKwhen the library serves a host compiled againsthost: the sameMINIMAGE_ABI_MAJORand the sameMINIMAGE_ABI_LAYOUT_REVISION. The minor is informational and is not compared.minimage_ops_get(&ops)fills the operations table. A null member is an operation the library lacks.
Every int32_t this layer returns is a status: 0 is success, a
positive code is a failure the caller can recover from, and a negative
code is a misuse of the interface or a fault inside the library. Branch
on the code. minimage_last_error() is text for a person, valid until
the next minimage_* call on the same thread, and its wording is not
stable. A panic inside the library is caught at the boundary and
returned as MINIMAGE_STATUS_PANIC.
| Code | Value | Meaning |
|---|---|---|
MINIMAGE_STATUS_OK |
0 | Success |
MINIMAGE_STATUS_ERROR |
1 | Any failure of the entry points that predate this layer; never returned by the table |
MINIMAGE_STATUS_BAD_CELL |
2 | Zero, infinite, or NaN periodic edge, dependent periodic vectors, or non-finite origin |
MINIMAGE_STATUS_UNSUPPORTED |
3 | The matching capability is zero; nothing was written |
MINIMAGE_STATUS_INCOMPATIBLE |
4 | Another major version or layout revision |
MINIMAGE_STATUS_NULL_POINTER |
-1 | A required pointer is null |
MINIMAGE_STATUS_BAD_SIZE |
-2 | A struct's size is smaller than the size member |
MINIMAGE_STATUS_BAD_COUNT |
-3 | A row count whose buffer would not fit in the address space |
MINIMAGE_STATUS_BAD_OVERLAP |
-4 | The output overlaps an input without being that input |
MINIMAGE_STATUS_PANIC |
-5 | A fault inside the library, caught at the boundary |
| Kind | Type | Layout |
|---|---|---|
| frozen | minimage_abi |
Three uint32_t: major, minor, layout revision. Written through a pointer |
| growable | minimage_caps |
uint32_t size, then one uint32_t flag per capability |
| growable | minimage_ops |
uint32_t size, uint32_t reserved, then function pointers |
| growable | minimage_lattice_info |
uint32_t size, flags, then the stored vectors, origin, and widths |
| opaque | minimage_lattice |
Incomplete type; only pointers cross the boundary |
A growable struct starts with uint32_t size. The host sets it to
sizeof as it compiled the struct. The library zeroes that many bytes,
writes the whole members that fit, and sets size to the bytes it
wrote, so a member the host knows and the library does not reads as
zero, and a byte past the host's size is never touched. Members only
ever append. minimage_caps and minimage_ops are outside the frozen
layout revision; a new capability or operation is a new member at the
end and a new minor.
| Symbol | Role | Threads |
|---|---|---|
minimage_abi_stamp |
Write the library's minimage_abi |
Any |
minimage_abi_compatible |
Same major and layout revision as the host | Any |
minimage_capabilities |
Fill a size-prefixed minimage_caps |
Any |
minimage_ops_get |
Fill a size-prefixed minimage_ops |
Any |
minimage_lattice_diagonal |
Lattice from three edges, a uint32_t periodicity mask (NULL -> all periodic), an origin (NULL -> zero) |
Any; builds share nothing |
minimage_lattice_general |
Lattice from vectors a, b, c (nine doubles), mask, origin | Any; builds share nothing |
minimage_lattice_get_info |
Read back the stored vectors, origin, periodicity, and widths | Shared read of the handle |
minimage_lattice_wrap_diffs |
Engine wrap of n packed differences; open axes kept; out may be the input |
Shared read |
minimage_lattice_wrap_pairs |
Engine wrap of q[k] - p[k]; out may be p or q |
Shared read |
minimage_lattice_nearest_diffs |
Nearest image of n packed differences over the periodic axes |
Shared read |
minimage_lattice_nearest_pairs |
Nearest image of q[k] - p[k] |
Shared read |
minimage_lattice_wrap_points |
Fold n packed points into the cell; open coordinates kept |
Shared read |
minimage_lattice_free |
Release a handle; NULL is ignored |
Exclusive per handle |
A lattice is immutable once built, so any number of threads may read one
handle at once; minimage_lattice_free must not run while another
thread uses it. An orthorhombic lattice stores each periodic vector with
a positive diagonal entry, whatever sign it was built with: the edge
-L spans the lattice the edge +L spans. A sheared lattice keeps the
vectors it was given. The engine wrap of a sheared lattice with an open
axis is not provided (minimage_caps.wrap_open_sheared is 0): the
wrap calls return MINIMAGE_STATUS_UNSUPPORTED and the nearest-image
calls serve it. A call with n = 0= reads no buffer.
The C11 test tests/c/abi_host.c pins the frozen layouts with
_Static_assert on sizeof and offsetof, and loads the library with
dlopen.
C++ (include/minimage.hpp)
Requires C++17 or later. Wraps minimage.h in namespace minimage and
throws minimage::Error (with status() and what()) on failure.
| Symbol | Role |
|---|---|
minimage::Error |
Exception carrying C ABI status() and what() |
minimage::check |
Throws minimage::Error when a C ABI status is nonzero |
minimage::Cell::ortho |
noexcept diagonal box (validated on first query) |
minimage::Cell::from_vectors, from_lammps, from_lammps_bounds |
Column / LAMMPS dump-bound constructors |
minimage::Cell::from_ase, from_con, from_con_box, from_vesin |
Row-major / crystallographic constructors |
minimage::Cell::raw, operator mi_cell |
Convert back to C mi_cell |
minimage::Cell::displacement, dist2 |
Single-pair engine MIC displacement and squared distance |
minimage::Cell::displacement_euclidean |
Single-pair Euclidean nearest-image displacement |
minimage::Cell::dist2_many, dist2_shifted_many |
Packed candidate batches (engine MIC and shifted) |
minimage::Cell::dist2_euclidean_many, dist2_euclidean_pairs, dist2_euclidean_pairs_warm |
Batched and warm-started Euclidean nearest-image distances |
minimage::dist2_ortho_diffs |
SoA orthorhombic batch wrap |
minimage::wrap_ortho_half_strict |
noexcept scalar wrap into the closed interval [-L/2, L/2]; NaN on invalid input |
minimage::visit_pairs_within_images, pairs_within_images |
Single-pass visitor and vector collector for periodic images within cutoff; an exception thrown by the visitor stops the walk and is rethrown to the caller |
minimage::reduce_pairs |
Sorted unique pairs with self images dropped |
C++ over the loaded library (include/minimage_abi.hpp)
Header-only, C++17. Refers to no minimage_* symbol at link time:
every call goes through the minimage_ops table a Library holds, so
a host compiles against the minimage-headers dependency alone.
| Symbol | Role |
|---|---|
minimage::abi::Library::open |
dlopen a path, check the stamp, fill the table |
minimage::abi::Library (EntryPoints) |
Negotiate through three entry points the host resolved itself |
minimage::abi::Library::stamp, version, capabilities, ops |
What the loaded library is and can do |
minimage::abi::Library::diagonal, general |
Build a Lattice |
minimage::abi::Lattice::info |
Stored vectors, origin, periodicity, widths |
minimage::abi::Lattice::wrap_diffs, wrap_pairs, nearest_diffs, nearest_pairs, wrap_points |
Batch calls, as pointers (output may be an input) or as Rows |
minimage::abi::Error |
status() is the MINIMAGE_STATUS_* code; recoverable() is status() > 0 |
A missing entry point, an incompatible ABI, or a null table member
throws Error with MINIMAGE_STATUS_UNSUPPORTED or
MINIMAGE_STATUS_INCOMPATIBLE instead of calling through a null
pointer. A moved-from Lattice throws MINIMAGE_STATUS_NULL_POINTER.
The loaded library stays open while the Library or any Lattice built
from it lives.
Rust
Full API docs build with cargo doc and are hosted at docs.rs/minimage.
Fallible functions return Result<_, Error> with variants
Error::BadBox, Error::BufferSize, and Error::Empty.
| Item | Role |
|---|---|
Cell::ortho, ortho_origin, from_vectors, from_lammps, from_lammps_bounds, from_ase, from_con, from_con_box, from_vesin |
Periodic cell constructors |
Cell::a, b, c, origin, widths, h, hinv, is_ortho, is_restricted, tilts_reduced |
Cell geometry and basis queries |
Cell::fractional, cartesian, lattice_shift, displacement, dist2, dist2_shifted, dist2_shifted_many, dist2_shifted_indexed |
Engine wrap, coordinate conversion, and linked-cell shifts |
Cell::displacement_cartesian, fractional_matches_cartesian, displacement_euclidean, dist2_euclidean |
27-image check and exact Selling-superbasis Euclidean MIC |
Cell::reduce_tilts, Cell::to_restricted |
Unimodular tilt reduction and restricted-frame rotation |
minkowski_reduce, is_minkowski_reduced |
3D Minkowski basis reduction and predicate |
Cell::fixed, displacement_fixed, dist2_fixed, fixed32, displacement_fixed32, dist2_fixed32 |
64-bit and 32-bit fixed-point fractional wraps |
wrap_many, dist2_many, dist2_pairs, dist2_ortho_diffs |
Batched engine MIC wraps and squared distances |
wrap_ortho_half_strict |
Scalar wrap into the closed interval [-L/2, L/2]; NaN on invalid input |
dist2_euclidean_many, dist2_euclidean_pairs, dist2_euclidean_pairs_warm |
Batched and warm-started Euclidean nearest-image distances |
fixed_many, dist2_many_fixed, dist2_pairs_fixed, fixed32_many, dist2_many_fixed32, dist2_pairs_fixed32 |
Batched fixed-point conversions and distances |
PartialCell::from_ase, periodic_count, full, displacement_euclidean, dist2_euclidean |
Slabs (2D), wires (1D), open (0D), and full (3D) cells |
Metric, Euclidean |
Tree metric contract and its zero-sized ordinary Euclidean implementation |
PeriodicSpace |
Optional period per feature axis; scalar wrap, displacement, distance, row-major batches, and per-axis / AABB lower bounds |
filter_shifted, FilterOut, ring_centroid |
Verlet-skin candidate filter and ring-polymer bead centroids |
pairs_within_images, visit_pairs_within_images, cutoff_exceeds_half_width, image_extents, ImagePair |
Multi-image cutoff enumeration for small or skewed cells |
reduce_pairs, reduce_pairs_packed, dump_bounds_to_h |
vesin pair deduplication and LAMMPS dump bound conversion |
simd_path() |
Active SIMD path: scalar, avx, avx2, avx512, or neon |
Error |
BadBox, BufferSize, Empty |
A slab rounds its in-plane coordinates and tries the nine neighbouring
images on a Lagrange-reduced basis of its two vectors; a wire rounds
along its one. The component normal to the periodic vectors is kept. A
half-box tie keeps the engine wrap s - floor(s + 1/2), as
Cell::displacement_euclidean does. With all three axes periodic a
PartialCell is a Cell and returns its displacement bit for bit.
wrap_ortho_half_strict(delta, length) (Rust) and
minimage::wrap_ortho_half_strict(delta, length) (C++) give identical
results. The result is delta - n * length for an integer
n, folded from the exact remainder fmod(delta, length) into the
closed interval [-length/2, length/2], so it is finite and in range for
any finite delta and finite positive length, including large
multiples such as 1e308 against 0.5. When the remainder equals
length/2 exactly in binary the result keeps the sign of delta:
15 and -15 against 10 give 5 and -5. A decimal tie such as
0.45 against 0.3 is not a binary tie and returns its nearest image,
-0.14999999999999997. A non-finite delta, or a length that is not
finite or not strictly positive, returns NaN; Rust does not panic and
the C++ function stays noexcept.
MINIMAGE_SIMD overrides the SIMD path choice. An unknown name is
ignored. A name this CPU cannot run selects scalar. The selection is
cached. Details are on SIMD paths and dispatch.
Python
Exported module items: Cell, PeriodicSpace,
reduce_image_pairs, and __version__.
Array arguments accept any host CPU DLPack producer, read in place when
contiguous and aligned; array results return a NumPy array (or a list
when NumPy is absent). Invalid inputs raise ValueError, TypeError,
or BufferError.
Cell method |
Role |
|---|---|
Cell.ortho, from_vectors, from_lammps_bounds, from_ase, from_con, from_vesin |
Construct a periodic cell |
is_ortho, is_restricted, tilts_reduced, is_minkowski_reduced, fractional_matches_cartesian |
Basis predicates |
reduce_tilts(), to_restricted() |
Return a tilt-reduced or restricted-frame Cell |
dist2(p, q), displacement(p, q), wrap(diff) |
Single-pair engine wrap |
displacement_euclidean(p, q), dist2_euclidean(p, q), displacement_cartesian(p, q) |
Single-pair Euclidean and 27-image MIC |
dist2_many(p, qs), dist2_pairs(ps, qs), wrap_many(diffs) |
Batched engine MIC |
dist2_euclidean_many(p, qs), dist2_euclidean_pairs(ps, qs) |
Batched Euclidean nearest image |
dist2_euclidean_pairs_warm(ps, qs, images=None) |
Distances and updated int32 shifts across frames |
fixed(r), fixed_many(rs), dist2_fixed(a, b), dist2_many_fixed(p, qs), dist2_pairs_fixed(ps, qs) |
64-bit fixed-point (uint64) |
fixed32(r), fixed32_many(rs), dist2_fixed32(a, b), dist2_many_fixed32(p, qs), dist2_pairs_fixed32(ps, qs) |
32-bit fixed-point (uint32) |
PeriodicSpace method |
Role |
|---|---|
PeriodicSpace(periods) |
Positive period or None per feature axis |
wrap_point(point), wrap_points(points) |
Point wrap; for finite input each periodic component is in the half-open interval [0, period); a periodic NaN, inf, or -inf gives NaN, and an open axis is unchanged |
wrap_difference(difference), wrap_differences(differences) |
Difference wrap; for finite input each periodic component is in the half-open interval [-period/2, period/2); a periodic NaN, inf, or -inf gives NaN, and an open axis is unchanged |
displacement(p, q) |
Exact minimum image of q - p, rounded once; for finite input each periodic component is in the closed interval [-period/2, period/2]; a periodic NaN, inf, or -inf in p or q gives NaN, and an open axis is q - p |
dist2, distance, dist2_many, dist2_pairs |
Scalar, one-to-many, and paired-row N-dimensional distances |
axis_min_dist2 |
Periodic per-axis lower bound to an interval |
aabb_min_dist2 |
Periodic lower-bound squared distance to an axis-aligned box |
PeriodicSpace.dist2_pairs accepts row-major sequences or CPU DLPack
float32 and float64 arrays. It validates the second dimension even
for empty (0, d) arrays and returns a float64 NumPy array when NumPy
is available.
| Module function | Role |
|---|---|
reduce_image_pairs(pairs) |
Drop self images, sort and deduplicate (i, j) pairs |
Burn (minimage-burn)
| Item | Role |
|---|---|
Lattice::new(cell, device, dtype) |
H and Hinv on a Burn device |
Lattice::rows |
Packed rows to an (n, 3) tensor |
Lattice::fractions |
Fold on the CPU in double precision, upload |
Lattice::fractional |
Fold on the device |
Lattice::wrap, dist2_pairs, dist2_many |
Cartesian rows |
Lattice::displacement_fractional, dist2_pairs_fractional, dist2_many_fractional |
Fraction rows, exact wrap |
rows_tensor, to_vec |
Convert row slices and read back rank-one f64 tensors |