Skip to main content

Grid

Struct Grid 

Source
pub struct Grid {
    pub dim: [usize; 3],
    pub origin: [f64; 3],
    pub cell: [[f64; 3]; 3],
    pub pbc: [bool; 3],
    /* private fields */
}
Expand description

A collection of named scalar arrays on a shared uniform spatial grid.

Cell vectors are stored as columns (same convention as SimBox). The Cartesian position of voxel (i, j, k) is:

origin + (i/nx)*cell_col0 + (j/ny)*cell_col1 + (k/nz)*cell_col2

Fields§

§dim: [usize; 3]

Grid dimensions [nx, ny, nz].

§origin: [f64; 3]

Cartesian origin in Ångström.

§cell: [[f64; 3]; 3]

Cell matrix: columns are the three lattice vectors (Å).

§pbc: [bool; 3]

Periodic boundary flags for each axis.

Implementations§

Source§

impl Grid

Source

pub fn new( dim: [usize; 3], origin: [f64; 3], cell: [[f64; 3]; 3], pbc: [bool; 3], ) -> Grid

Create an empty grid with the given spatial definition.

Source

pub fn total(&self) -> usize

Total number of voxels: nx * ny * nz.

Source

pub fn insert( &mut self, name: impl Into<String>, data: Vec<f64>, ) -> Result<(), MolRsError>

Insert (or replace) a named array.

data must have length nx * ny * nz in row-major (ix, iy, iz) order.

Source

pub fn get( &self, name: &str, ) -> Option<ArrayBase<OwnedRepr<f64>, Dim<IxDynImpl>>>

Return a named array reshaped to (nx, ny, nz), or None if absent.

Source

pub fn get_raw(&self, name: &str) -> Option<&[f64]>

Borrow the raw flat slice for a named array, or None if absent.

Source

pub fn contains(&self, name: &str) -> bool

Whether a named array is present.

Source

pub fn len(&self) -> usize

Number of named arrays stored in this grid.

Source

pub fn is_empty(&self) -> bool

Returns true if no arrays are stored.

Source

pub fn raw_arrays(&self) -> impl Iterator<Item = (&str, &[f64])>

Iterate over (name, flat_data) pairs.

Source

pub fn keys(&self) -> impl Iterator<Item = &str>

Iterate over array names.

Source

pub fn voxel_position(&self, ix: usize, iy: usize, iz: usize) -> [f64; 3]

Compute Cartesian position of voxel (ix, iy, iz).

Trait Implementations§

Source§

impl Clone for Grid

Source§

fn clone(&self) -> Grid

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Grid

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Grid

Source§

fn eq(&self, other: &Grid) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Grid

Auto Trait Implementations§

§

impl Freeze for Grid

§

impl RefUnwindSafe for Grid

§

impl Send for Grid

§

impl Sync for Grid

§

impl Unpin for Grid

§

impl UnsafeUnpin for Grid

§

impl UnwindSafe for Grid

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> 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.