pub struct SimBox { /* private fields */ }Expand description
Simulation box: triclinic cell with origin and per-axis PBC mask
Implementations§
Source§impl SimBox
impl SimBox
Sourcepub fn new(h: F3x3, origin: F3, pbc: Pbc3) -> Result<Self, BoxError>
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
Sourcepub fn new_cell(
h: F3x3,
origin: F3,
pbc: Pbc3,
cell_defined: bool,
) -> Result<Self, BoxError>
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.
Sourcepub fn is_cell_defined(&self) -> bool
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).
pub fn try_new(h: F3x3, origin: F3, pbc: Pbc3) -> Result<Self, BoxError>
Sourcepub fn cube(a: F, origin: F3, pbc: Pbc3) -> Result<Self, BoxError>
pub fn cube(a: F, origin: F3, pbc: Pbc3) -> Result<Self, BoxError>
Factory: cubic box with edge length a and origin O
Sourcepub fn ortho(lengths: F3, origin: F3, pbc: Pbc3) -> Result<Self, BoxError>
pub fn ortho(lengths: F3, origin: F3, pbc: Pbc3) -> Result<Self, BoxError>
Factory: ortho box with lengths (ax, ay, az) and origin O
Sourcepub fn matrix_from_lengths_angles(
lengths: [F; 3],
angles: [F; 3],
) -> Result<F3x3, BoxError>
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.
Sourcepub fn matrix_from_lengths_tilts(lengths: [F; 3], tilts: [F; 3]) -> F3x3
pub fn matrix_from_lengths_tilts(lengths: [F; 3], tilts: [F; 3]) -> F3x3
Restricted-triclinic matrix from diagonal sizes and (xy, xz, yz) tilts.
Sourcepub fn restricted_matrix(matrix: FNx3View<'_>) -> Result<F3x3, BoxError>
pub fn restricted_matrix(matrix: FNx3View<'_>) -> Result<F3x3, BoxError>
Convert a general cell matrix to LAMMPS restricted-triclinic form.
Sourcepub fn free(points: FNx3View<'_>, padding: F) -> Result<Self, BoxError>
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.
Sourcepub fn from_bounds(
points: FNx3View<'_>,
padding: [F; 3],
pbc: Pbc3,
) -> Result<Self, BoxError>
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.
Sourcepub fn free_columns(
xs: &[F],
ys: &[F],
zs: &[F],
padding: F,
) -> Result<Self, BoxError>
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.
Sourcepub fn origin_view(&self) -> F3View<'_>
pub fn origin_view(&self) -> F3View<'_>
View of the origin
Sourcepub fn pbc_view(&self) -> ArrayView1<'_, bool>
pub fn pbc_view(&self) -> ArrayView1<'_, bool>
View of the PBC flags
Sourcepub fn style(&self) -> &'static str
pub fn style(&self) -> &'static str
Geometry style label: "free" (no periodic axis), "orthogonal"
(diagonal H), or "triclinic".
Sourcepub fn nearest_plane_distance(&self) -> F3
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
pub fn kind(&self) -> &BoxKind
Sourcepub fn make_fractional(&self, r: F3View<'_>) -> F3
pub fn make_fractional(&self, r: F3View<'_>) -> F3
Convert Cartesian coordinates to fractional coordinates [0, 1)
Sourcepub fn make_fractional_fast(&self, r: F3View<'_>) -> F3
pub fn make_fractional_fast(&self, r: F3View<'_>) -> F3
Fractional coordinates with ortho fast-path
Sourcepub fn make_fractional_raw_arr3(&self, r: [F; 3]) -> [F; 3]
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.
Sourcepub fn make_cartesian(&self, frac: F3View<'_>) -> F3
pub fn make_cartesian(&self, frac: F3View<'_>) -> F3
Convert fractional coordinates to Cartesian coordinates
Sourcepub fn mic(&self) -> Mic
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.
Sourcepub fn shortest_vector(&self, r1: F3View<'_>, r2: F3View<'_>) -> F3
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).
Sourcepub fn shortest_vector_impl(&self, a: [F; 3], b: [F; 3]) -> [F; 3]
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.
Sourcepub fn calc_distance2(&self, a: F3View<'_>, b: F3View<'_>) -> F
pub fn calc_distance2(&self, a: F3View<'_>, b: F3View<'_>) -> F
Calculate squared distance using MIC.
Sourcepub fn to_frac(&self, xyz: FNx3View<'_>) -> FNx3
pub fn to_frac(&self, xyz: FNx3View<'_>) -> FNx3
Convert Cartesian points to fractional coordinates (N×3)
Sourcepub fn to_cart(&self, frac: FNx3View<'_>) -> FNx3
pub fn to_cart(&self, frac: FNx3View<'_>) -> FNx3
Convert fractional coordinates to Cartesian points (N×3)
Sourcepub fn isin(&self, xyz: FNx3View<'_>) -> Array1<bool>
pub fn isin(&self, xyz: FNx3View<'_>) -> Array1<bool>
Check if points lie within [0,1) in fractional space.
Sourcepub fn delta_out(
&self,
xyzu1: FNx3View<'_>,
xyzu2: FNx3View<'_>,
out: &mut FNx3,
minimum_image: bool,
)
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.
Sourcepub fn delta(
&self,
xyzu1: FNx3View<'_>,
xyzu2: FNx3View<'_>,
minimum_image: bool,
) -> FNx3
pub fn delta( &self, xyzu1: FNx3View<'_>, xyzu2: FNx3View<'_>, minimum_image: bool, ) -> FNx3
Batched displacement vectors row-wise (N×3)
Sourcepub fn distances(
&self,
points1: FNx3View<'_>,
points2: FNx3View<'_>,
) -> Array1<F>
pub fn distances( &self, points1: FNx3View<'_>, points2: FNx3View<'_>, ) -> Array1<F>
Row-wise minimum-image distances between equally sized point arrays.
Sourcepub fn pairwise_delta(
&self,
points1: FNx3View<'_>,
points2: FNx3View<'_>,
) -> Array3<F>
pub fn pairwise_delta( &self, points1: FNx3View<'_>, points2: FNx3View<'_>, ) -> Array3<F>
All pairwise minimum-image displacement vectors (points2 - points1).
Sourcepub fn pairwise_distances(
&self,
points1: FNx3View<'_>,
points2: FNx3View<'_>,
) -> Array2<F>
pub fn pairwise_distances( &self, points1: FNx3View<'_>, points2: FNx3View<'_>, ) -> Array2<F>
All pairwise minimum-image distances.
Sourcepub fn transformed(&self, transformation: &F3x3) -> Result<Self, BoxError>
pub fn transformed(&self, transformation: &F3x3) -> Result<Self, BoxError>
Return a box with its cell matrix right-multiplied by a transform.
Sourcepub fn wrap(&self, xyz: FNx3View<'_>) -> FNx3
pub fn wrap(&self, xyz: FNx3View<'_>) -> FNx3
Wrap Cartesian points into the unit cell according to PBC
Sourcepub fn images(&self, xyz: FNx3View<'_>) -> Array2<i64>
pub fn images(&self, xyz: FNx3View<'_>) -> Array2<i64>
Integer periodic images for Cartesian points.
Sourcepub fn unwrap(&self, xyz: FNx3View<'_>, images: ArrayView2<'_, i64>) -> FNx3
pub fn unwrap(&self, xyz: FNx3View<'_>, images: ArrayView2<'_, i64>) -> FNx3
Reconstruct unwrapped coordinates from wrapped points and image flags.
pub fn get_corners(&self) -> FNx3
Sourcepub fn bounds(&self) -> FNx3
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§
Auto Trait Implementations§
impl Freeze for SimBox
impl RefUnwindSafe for SimBox
impl Send for SimBox
impl Sync for SimBox
impl Unpin for SimBox
impl UnsafeUnpin for SimBox
impl UnwindSafe for SimBox
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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