Skip to main content

Unit

Struct Unit 

Source
pub struct Unit<'a> { /* private fields */ }
Expand description

Zero-copy view into a subset of a Model.

Unit holds a reference to a Model and an OrderedSet of selected atom indices. All operations are lazy — iterators do not allocate, and set operations produce new Units without copying coordinate data.

Implementations§

Source§

impl<'a> Unit<'a>

Source

pub fn from_mask(model: &'a Model, mask: &[bool]) -> Self

Create a Unit from a boolean mask.

The mask must have the same length as model.n_atoms(). Only atoms where mask[i] == true are included.

§Panics

Panics if mask.len() != model.n_atoms().

Source

pub fn all(model: &'a Model) -> Self

Create a Unit containing all atoms in the model.

Source

pub fn from_indices(model: &'a Model, indices: OrderedSet) -> Self

Create a Unit from pre-computed indices.

Source

pub fn len(&self) -> usize

Number of selected atoms.

Source

pub fn is_empty(&self) -> bool

Returns true if no atoms are selected.

Source

pub fn model(&self) -> &Model

Reference to the underlying model.

Source

pub fn atom_indices(&self) -> impl Iterator<Item = u32> + '_

Lazy iterator over selected atom indices.

Source

pub fn coords(&self) -> impl Iterator<Item = [f32; 3]> + '_

Lazy iterator over coordinates of selected atoms.

Source

pub fn union(&self, other: &Unit<'a>) -> Self

Union of two units (must reference the same model).

§Panics

Panics if the units reference different models.

Source

pub fn intersection(&self, other: &Unit<'a>) -> Self

Intersection of two units (must reference the same model).

§Panics

Panics if the units reference different models.

Source

pub fn difference(&self, other: &Unit<'a>) -> Self

Difference of two units: atoms in self but not in other.

§Panics

Panics if the units reference different models.

Source

pub fn chain(model: &'a Model, chain_id: &str) -> Option<Self>

Select atoms belonging to a specific chain.

Returns None if the chain doesn’t exist.

Source

pub fn backbone(model: &'a Model) -> Self

Select backbone atoms (N, CA, C, O).

Trait Implementations§

Source§

impl<'a> Clone for Unit<'a>

Source§

fn clone(&self) -> Unit<'a>

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

Auto Trait Implementations§

§

impl<'a> Freeze for Unit<'a>

§

impl<'a> RefUnwindSafe for Unit<'a>

§

impl<'a> Send for Unit<'a>

§

impl<'a> Sync for Unit<'a>

§

impl<'a> Unpin for Unit<'a>

§

impl<'a> UnsafeUnpin for Unit<'a>

§

impl<'a> UnwindSafe for Unit<'a>

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