Orthorhombic box
Two points near opposite faces of a 10-wide box sit 9.2 apart in Cartesian space and 0.8 apart under the minimum image.
use minimage::{Cell, Error};
fn main() -> Result<(), Error> {
let cell = Cell::ortho(10.0, 10.0, 10.0)?;
assert!((cell.dist2([0.2, 0.0, 0.0], [9.4, 0.0, 0.0]) - 0.64).abs() < 1e-12);
Ok(())
}
Sheared LAMMPS dump
A sheared LAMMPS dump uses bound spans, not lx, ly, lz. The a-image
pair (0.2, 0.1, 1) and (9.7, 0.1, 1) on
box = 15 8.660254037844386 10 5 0 0
has squared distance 0.25.
use minimage::{Cell, Error};
fn main() -> Result<(), Error> {
let sheared = Cell::from_lammps_bounds(
15.0, 8.660254037844386, 10.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0,
)?;
assert!((sheared.dist2([0.2, 0.1, 1.0], [9.7, 0.1, 1.0]) - 0.25).abs() < 1e-12);
Ok(())
}
Triclinic Euclidean nearest image
On a tilted hexagonal prism, the fractional engine wrap along a body
diagonal is not always the shortest image in Cartesian space.
displacement_euclidean finds the exact Voronoi nearest image.
use minimage::{Cell, Error};
fn main() -> Result<(), Error> {
let hex = Cell::from_vectors(
[10.0, 0.0, 0.0],
[5.0, 8.660254037844386, 0.0],
[0.0, 0.0, 10.0],
[0.0, 0.0, 0.0],
)?;
let q = hex.cartesian([0.49, 0.49, 0.49]);
let euc = hex.displacement_euclidean([0.0, 0.0, 0.0], q);
let e2 = euc[0] * euc[0] + euc[1] * euc[1] + euc[2] * euc[2];
assert!(e2 < hex.dist2([0.0, 0.0, 0.0], q));
Ok(())
}
Partial periodicity and pair reduction
For a slab periodic in two axes, PartialCell::from_ase wraps along
periodic vectors only and keeps open axes unwrapped.
use minimage::{reduce_pairs, Error, PartialCell};
fn main() -> Result<(), Error> {
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],
)?;
let d = slab.displacement_euclidean([0.5, 0.5, 0.0], [9.5, 0.5, 30.0]);
assert!((d[0] + 1.0).abs() < 1e-12 && (d[2] - 30.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(())
}