Skip to main content

minimage

minimage

Minimum-image convention for a periodic parallelepiped.

linkcell walks k-nearest neighbours. vesin builds cutoff pair lists. Both need the same wrap: fold through H, pick one image, never the self image. This crate is that wrap. Cell holds the 3x3 lattice and a dump-cell origin. Constructors accept LAMMPS bounds plus xy, xz, yz tilts, a CON lattice or length-angle box, an ASE-style 3x3 cell, and a vesin box. PartialCell handles slabs, wires, and open systems where only some axes are periodic.

It is a LODE library. The Rust crate is the implementation. The C ABI (minimage_*) is the hourglass waist, the same shape as linkcell and readcon-core. C++ is a header-only wrapper over that ABI.

Docs (orgmode first, HTML export): lode-org.github.io/minimage. Org catalog: lode-org.github.io. Rust API docs: docs.rs/minimage.

Install

Rust:

cargo add minimage

C and C++ consumers take the staticlib (--features capi, on by default) plus include/minimage.h or include/minimage.hpp. Meson, CMake, and pkg-config all install that archive, the shared library, and those headers. The function prefix spells out the crate name (minimage_*) so it cannot collide with mimalloc's mi_* ABI. The non-default capi-compat-names feature adds deprecated thin aliases for the old mi_* function names while consumers migrate; those aliases can still collide with mimalloc.

pip install minimage

Python 3.10 or newer. Each release has one abi3 wheel per platform, for Linux x86_64 and aarch64 (manylinux_2_28), macOS arm64 and Windows x86_64, which covers every CPython from 3.10 on. Elsewhere pip builds the sdist, which needs a Rust toolchain.

import minimage

cell = minimage.Cell.ortho(10.0, 10.0, 10.0)
assert abs(cell.dist2([0.2, 0.0, 0.0], [9.4, 0.0, 0.0]) - 0.64) < 1e-12

Meson

meson setup build
meson compile -C build
meson install -C build

As a wrap, Meson exposes minimage_dep:

[wrap-git]
url = https://github.com/lode-org/minimage.git
revision = v0.3.0
depth = 1

[provide]
minimage = minimage_dep
minimage_dep = dependency('minimage', fallback: ['minimage', 'minimage_dep'])

CMake

cmake -B build -DCMAKE_INSTALL_PREFIX=$PREFIX
cmake --build build
cmake --install build
find_package(minimage 0.3 REQUIRED)
target_link_libraries(app PRIVATE minimage::minimage)

pkg-config

pkg-config --cflags --libs minimage

Rust

use minimage::{dist2_many, reduce_pairs, Cell, Error, PartialCell};

fn main() -> Result<(), Error> {
    let sim = Cell::ortho(10.0, 10.0, 10.0)?;
    let sheared = Cell::from_lammps_bounds(
        15.0, 8.660254037844386, 10.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    )?;
    let left = [0.2, 0.0, 0.0];
    let right = [9.4, 0.0, 0.0];
    assert!((sim.dist2(left, right) - 0.64).abs() < 1e-12);

    // Hex-prism body diagonal: Euclidean MIC finds a shorter image than the engine wrap.
    let q_diag = sheared.cartesian([0.49, 0.49, 0.49]);
    let euc = sheared.displacement_euclidean([0.0; 3], q_diag);
    assert!(euc.iter().map(|x| x * x).sum::<f64>() < sheared.dist2([0.0; 3], q_diag));

    let qs = [[9.4, 0.0, 0.0], [1.0, 0.0, 0.0]];
    let mut out = [0.0; 2];
    dist2_many(&sim, left, &qs, &mut out)?;

    let slab = PartialCell::from_ase(
        [[10.0, 0.0, 0.0], [0.0, 10.0, 0.0], [0.0, 0.0, 0.0]],
        [true, true, false],
    )?;
    assert!((slab.displacement_euclidean([0.5, 0.5, 0.0], [9.5, 0.5, 20.0])[2] - 20.0).abs() < 1e-12);

    let pairs = [[0, 1], [0, 0], [0, 1]];
    let mut kept = Vec::new();
    reduce_pairs(&pairs, &mut kept)?;
    assert_eq!(kept, vec![[0, 1]]);
    Ok(())
}

C ABI (minimage_*)

All exported C ABI functions use the minimage_ prefix, including minimage_cell_from_lammps_bounds, minimage_displacement, minimage_displacement_euclidean, minimage_dist2, minimage_dist2_many, minimage_dist2_pairs, minimage_wrap_many, minimage_pbc_cell_from_ase, minimage_displacement_euclidean_pbc, minimage_filter_shifted, minimage_ring_centroid, and minimage_reduce_pairs.

#include "minimage.h"
#include <stdio.h>

mi_cell cell;
if (minimage_cell_from_lammps_bounds(
        15.0, 8.660254037844386, 10.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, &cell) != 0) {
    fprintf(stderr, "%s\n", minimage_last_error());
}
const double p[3] = {0.0, 0.0, 0.0};
const double q[3] = {
    0.49 * (cell.ax + cell.bx + cell.cx),
    0.49 * (cell.ay + cell.by + cell.cy),
    0.49 * (cell.az + cell.bz + cell.cz),
};
double dr[3] = {0.0};
if (minimage_displacement_euclidean(&cell, p, q, dr) != 0) {
    fprintf(stderr, "%s\n", minimage_last_error());
}

Loading at run time

A host that opens the library by path compiles against the headers alone (Meson: dependency('minimage-headers'), no cargo needed), resolves minimage_abi_stamp, minimage_abi_compatible, and minimage_ops_get with dlsym, and takes every other call from the minimage_ops table: lattice handles (lattice_diagonal, lattice_general, per-axis periodicity), engine wrap and nearest image of many differences or pairs, and wrapping many points into the cell. Each returns an int32_t status: 0 success, a positive MINIMAGE_STATUS_* code for a recoverable failure, a negative one for misuse or a fault caught inside the library. Compatible means the same MINIMAGE_ABI_MAJOR and MINIMAGE_ABI_LAYOUT_REVISION; the minor is informational. include/minimage_abi.hpp wraps the table for C++ and throws minimage::abi::Error. The entry points above are unchanged. See the reference and the how-to for the layouts, the codes, and the thread rules.

Conventions and error behaviour

  • Units and storage: coordinates, lattice vectors, and origins share one caller-chosen length unit; squared distances and cutoffs use that unit squared; from_con_box / minimage_cell_from_con_box take angles in degrees. Cell::from_vectors and Cell::h store a, b, c as the columns of H (r = H s + origin), while from_ase, from_con, from_vesin, and PartialCell::from_ase take row-major [a, b, c].
  • Displacements and triclinic cells: displacement(p, q) returns wrap(q - p). Orthorhombic boxes wrap each axis into [-L/2, L/2), keeping -L/2 and mapping +L/2 to -L/2. Restricted triclinic boxes (a along x, b in the xy plane) use the upper-triangular lamda wrap matching LAMMPS, HOOMD, OpenMM, and GROMACS; reduce_tilts applies GROMACS correct_box, to_restricted rotates general cells into that frame, and displacement_euclidean (minimage_displacement_euclidean) checks Smith's half-altitude bound and falls back to the Selling superbasis slicer for exact Voronoi nearest images.
  • N-dimensional features: PeriodicSpace assigns a positive period or None to each independent feature axis. It wraps points into [0, L), differences into [-L/2, L/2), handles contiguous row-major batches, and computes periodic point-to-box lower bounds for tree pruning. It is separate from coupled triclinic lattice geometry. Rust and Python use None for an open axis; the C-only period array uses 0.0 as its open-axis sentinel and requires positive finite periods otherwise.
  • Errors: Rust returns Result<_, Error> (BadBox, BufferSize, Empty). C ABI functions return 0 on success and 1 on failure and record a thread-local message in minimage_last_error() (cleared on the next success on that thread; minimage_version() leaves it untouched). C++ throws minimage::Error, and Python raises ValueError, TypeError, or BufferError.

Batch kernels select AVX-512, AVX2, AVX, NEON, or scalar at run time. MINIMAGE_SIMD overrides that choice. simd_path() returns the name.

License

MIT. See LICENSE.

Metadata

Release files for minimage 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for minimage 0.3.0
File Size Uploaded Provenance Actions
minimage-0.3.0.tar.gz 306.9 kB With provenance Details for minimage-0.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for minimage 0.3.0
File Actions
minimage-0.3.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for minimage-0.3.0-cp310-abi3-win_amd64.whl
minimage-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details for minimage-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl
minimage-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details for minimage-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl
minimage-0.3.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for minimage-0.3.0-cp310-abi3-macosx_11_0_arm64.whl

Total release size: 2.1 MB

Release files / minimage-0.3.0.tar.gz

Download URL minimage-0.3.0.tar.gz
Size 306.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c2aba9699d6071ea1783a688e80c3f24f1b0d3907324247ba30cd3ac28a6713f
BLAKE2b-256 checksum
How to use checksums
361fb9ab4140971a190cb48ac290df7b54cad01afd4a8f578ab06851d484f916
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / minimage-0.3.0-cp310-abi3-win_amd64.whl

Download URL minimage-0.3.0-cp310-abi3-win_amd64.whl
Size 423.4 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
601a5da2503d28c7ac089d0fc69e9d09cc87df623bf0eb9b71ed6098080935ed
BLAKE2b-256 checksum
How to use checksums
bdee46e9f4c4fd745ab95431adecb02d2567bfac217cd332ad23297d65a8908d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / minimage-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL minimage-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl
Size 505.7 kB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
a68d597db7af5825729dbe7d04a3a0a74ab1a3095b8711adc44151367aa33bd5
BLAKE2b-256 checksum
How to use checksums
20bb7bcca53e60e8978ee6704c1332310feadb5ebf40e03c0ab43530c9350c51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / minimage-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL minimage-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl
Size 436.6 kB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
cc456c417a84c32c9a8a7f410ebf588b50797960fe3995183454cafd412709b6
BLAKE2b-256 checksum
How to use checksums
7d6c2f712cbb191a77ce0ef2d2a948825a9478f06c20699db63fea559f8f5270
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / minimage-0.3.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL minimage-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
Size 412.0 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
555fd9609f7bdc5a56f1c070bd0a5a3f60f0e434fcd33a00cff67477bd25c7e7
BLAKE2b-256 checksum
How to use checksums
c5ee640ab9976edc2e3f6232a9d0f40db23a216cb7308cacc49ec8d37e7cd141
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for minimage 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for minimage-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page