Skip to main content

SimBox

Struct SimBox 

Source
pub struct SimBox { /* private fields */ }
Expand description

Simulation box: triclinic cell with origin and per-axis PBC mask

Implementations§

Source§

impl SimBox

Source

pub fn new(h: F3x3, origin: F3, pbc: Pbc3) -> Result<Self, BoxError>

Construct from triclinic cell matrix H, origin O, and per-axis PBC flags

Source

pub fn new_cell( h: F3x3, origin: F3, pbc: Pbc3, cell_defined: bool, ) -> Result<Self, BoxError>

Construct a box, explicitly marking whether the cell is geometrically defined. Pass cell_defined = false for a “no-cell” box (undefined / zero-volume): supply the identity matrix so geometry ops degrade to no-ops, and volume / is_cell_defined reflect the undefined cell.

Source

pub fn is_cell_defined(&self) -> bool

Whether the cell is geometrically defined (false ⇒ a no-cell box of undefined / zero volume). Distinct from periodicity (is_free).

Source

pub fn try_new(h: F3x3, origin: F3, pbc: Pbc3) -> Result<Self, BoxError>

Source

pub fn cube(a: F, origin: F3, pbc: Pbc3) -> Result<Self, BoxError>

Factory: cubic box with edge length a and origin O

Source

pub fn ortho(lengths: F3, origin: F3, pbc: Pbc3) -> Result<Self, BoxError>

Factory: ortho box with lengths (ax, ay, az) and origin O

Source

pub fn matrix_from_lengths_angles( lengths: [F; 3], angles: [F; 3], ) -> Result<F3x3, BoxError>

Restricted-triclinic matrix from edge lengths and angles in degrees.

Source

pub fn matrix_from_lengths_tilts(lengths: [F; 3], tilts: [F; 3]) -> F3x3

Restricted-triclinic matrix from diagonal sizes and (xy, xz, yz) tilts.

Source

pub fn restricted_matrix(matrix: FNx3View<'_>) -> Result<F3x3, BoxError>

Convert a general cell matrix to LAMMPS restricted-triclinic form.

Source

pub fn free(points: FNx3View<'_>, padding: F) -> Result<Self, BoxError>

Create a non-periodic (free-boundary) box enclosing all points.

Computes the axis-aligned bounding box of points and adds padding on each side. The resulting box has pbc = [false, false, false].

padding should be >= the neighbor cutoff distance so that all particles sit well inside the box for correct cell assignment.

§Errors

Returns BoxError if padding is non-positive or the resulting box is degenerate.

§Panics

Panics if padding <= 0.

Source

pub fn from_bounds( points: FNx3View<'_>, padding: [F; 3], pbc: Pbc3, ) -> Result<Self, BoxError>

Create a tight orthorhombic box around a point cloud.

Unlike free, padding is specified per axis and may be zero. Periodicity is supplied by the caller instead of being forced to free-boundary semantics.

Source

pub fn free_columns( xs: &[F], ys: &[F], zs: &[F], padding: F, ) -> Result<Self, BoxError>

Create a non-periodic (free-boundary) box enclosing all points, reading positions from three separate x/y/z slices (SoA layout).

Arithmetically identical to free: computes the same axis-aligned bounding box (min/max over all points) plus padding on each side, and returns a box byte-identical to free on the same points. Provided so callers holding column-major (SoA) coordinates need not interleave them into an owned Array2 first.

§Errors

Returns BoxError if the resulting box is degenerate.

§Panics

Panics if padding <= 0 or the three slices do not have equal length.

Source

pub fn h_view(&self) -> FNx3View<'_>

View of the cell matrix

Source

pub fn inv_view(&self) -> FNx3View<'_>

View of the inverse cell matrix

Source

pub fn origin_view(&self) -> F3View<'_>

View of the origin

Source

pub fn pbc_view(&self) -> ArrayView1<'_, bool>

View of the PBC flags

Source

pub fn pbc(&self) -> Pbc3

Per-axis PBC flags

Source

pub fn volume(&self) -> F

Cell volume (|det(H)|)

Source

pub fn is_free(&self) -> bool

true when the box is free (non-periodic on every axis).

Source

pub fn style(&self) -> &'static str

Geometry style label: "free" (no periodic axis), "orthogonal" (diagonal H), or "triclinic".

Source

pub fn tilts(&self) -> F3

Off-diagonal tilts [xy, xz, yz] of the cell matrix

Source

pub fn lengths(&self) -> F3

Lattice vector lengths

Source

pub fn angles(&self) -> F3

Lattice angles [alpha, beta, gamma] in degrees.

Source

pub fn nearest_plane_distance(&self) -> F3

Nearest plane distance (half the box size along each axis) For triclinic boxes, this is the perpendicular distance to each face

Source

pub fn kind(&self) -> &BoxKind

Source

pub fn lattice(&self, index: usize) -> F3

Lattice vector by index (0,1,2) — columns of H

Source

pub fn make_fractional(&self, r: F3View<'_>) -> F3

Convert Cartesian coordinates to fractional coordinates [0, 1)

Source

pub fn make_fractional_fast(&self, r: F3View<'_>) -> F3

Fractional coordinates with ortho fast-path

Source

pub fn make_fractional_raw_arr3(&self, r: [F; 3]) -> [F; 3]

Fractional coordinates without the wrap into [0, 1).

make_fractional_fast_arr3 folds every axis back into the primitive cell unconditionally, which is right for a fully periodic box but destroys the information a caller needs on a non-periodic axis: a point above the box must stay above it, so that a cell-list assignment can clamp it to the edge cell instead of wrapping it to the opposite face. Callers that dispatch on pbc per axis — see CellGrid — start from this raw value and apply wrap or clamp themselves.

make_fractional_fast_arr3(r) is exactly this followed by f - f.floor() per component, so the two agree bit-for-bit on any point inside the cell.

Source

pub fn make_cartesian(&self, frac: F3View<'_>) -> F3

Convert fractional coordinates to Cartesian coordinates

Source

pub fn mic(&self) -> Mic

A detached, Copy minimum-image kernel.

shortest_vector_impl needs a &SimBox, which is awkward for a caller whose hot loop already holds the owning structure mutably: it either clones the box — two Array2 allocations, per evaluation — or restructures its borrows. Mic lifts the convention out as a plain value with everything it needs on the stack, so it can be captured once and carried into the loop.

Bit-identical to shortest_vector_impl: both dispatch to the same arithmetic.

Source

pub fn shortest_vector(&self, r1: F3View<'_>, r2: F3View<'_>) -> F3

Minimum image displacement vector from r1 to r2 (returns r2 − r1).

Ergonomic ndarray-flavoured API: takes views and returns an owned Array1<F>. Inside hot loops prefer shortest_vector_impl — it avoids the heap allocation for the output (~70% faster per call).

Source

pub fn shortest_vector_impl(&self, a: [F; 3], b: [F; 3]) -> [F; 3]

Zero-allocation MIC displacement from a to b (returns b − a).

Stack-array in / out; the canonical hot-loop entry point. Used by LinkCell, BruteForce, and AabbQuery inner loops.

Source

pub fn calc_distance2(&self, a: F3View<'_>, b: F3View<'_>) -> F

Calculate squared distance using MIC.

Source

pub fn to_frac(&self, xyz: FNx3View<'_>) -> FNx3

Convert Cartesian points to fractional coordinates (N×3)

Source

pub fn to_cart(&self, frac: FNx3View<'_>) -> FNx3

Convert fractional coordinates to Cartesian points (N×3)

Source

pub fn isin(&self, xyz: FNx3View<'_>) -> Array1<bool>

Check if points lie within [0,1) in fractional space.

Source

pub fn delta_out( &self, xyzu1: FNx3View<'_>, xyzu2: FNx3View<'_>, out: &mut FNx3, minimum_image: bool, )

Batched displacement vectors row-wise (N×3). Writes result into out to avoid allocation.

Source

pub fn delta( &self, xyzu1: FNx3View<'_>, xyzu2: FNx3View<'_>, minimum_image: bool, ) -> FNx3

Batched displacement vectors row-wise (N×3)

Source

pub fn distances( &self, points1: FNx3View<'_>, points2: FNx3View<'_>, ) -> Array1<F>

Row-wise minimum-image distances between equally sized point arrays.

Source

pub fn pairwise_delta( &self, points1: FNx3View<'_>, points2: FNx3View<'_>, ) -> Array3<F>

All pairwise minimum-image displacement vectors (points2 - points1).

Source

pub fn pairwise_distances( &self, points1: FNx3View<'_>, points2: FNx3View<'_>, ) -> Array2<F>

All pairwise minimum-image distances.

Source

pub fn transformed(&self, transformation: &F3x3) -> Result<Self, BoxError>

Return a box with its cell matrix right-multiplied by a transform.

Source

pub fn wrap(&self, xyz: FNx3View<'_>) -> FNx3

Wrap Cartesian points into the unit cell according to PBC

Source

pub fn images(&self, xyz: FNx3View<'_>) -> Array2<i64>

Integer periodic images for Cartesian points.

Source

pub fn unwrap(&self, xyz: FNx3View<'_>, images: ArrayView2<'_, i64>) -> FNx3

Reconstruct unwrapped coordinates from wrapped points and image flags.

Source

pub fn get_corners(&self) -> FNx3

Source

pub fn bounds(&self) -> FNx3

Axis-aligned bounding box of the cell geometry.

Layout: rows = x/y/z, col 0 = min, col 1 = max — the AABB of the eight corners. For triclinic cells this is larger than the true cell volume; use isin for membership. Geometric region types that describe the same volume live in spatial::region (Cuboid / Parallelepiped) — not on this type.

Trait Implementations§

Source§

impl Clone for SimBox

Source§

fn clone(&self) -> SimBox

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SimBox

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.