Structure

Struct Structure 

Source
pub struct Structure {
    pub box_vectors: Option<[[f64; 3]; 3]>,
    /* private fields */
}
Expand description

High-level biomolecular assembly composed of zero or more chains.

A Structure wraps individual chains, tracks optional periodic box vectors, and offers convenience iterators for traversing chains, residues, and atoms alongside contextual metadata. Builders and operations mutate the structure to clean, solvate, or analyze biological systems.

Fields§

§box_vectors: Option<[[f64; 3]; 3]>

Optional periodic box represented as crystallographic basis vectors.

Implementations§

Source§

impl Structure

Source

pub fn new() -> Self

Creates an empty structure with no chains or box vectors.

§Returns

A new Structure identical to Structure::default().

Source

pub fn add_chain(&mut self, chain: Chain)

Appends a chain to the structure, asserting unique chain IDs in debug builds.

The chain is inserted at the end of the current collection and becomes visible to iterator methods immediately.

§Arguments
  • chain - Chain instance whose id must be unique within the structure.
Source

pub fn remove_chain(&mut self, id: &str) -> Option<Chain>

Removes and returns a chain by identifier if it exists.

§Arguments
  • id - Chain identifier to search for.
§Returns

Some(Chain) when a chain with the provided ID is present, otherwise None.

Source

pub fn clear(&mut self)

Drops every chain from the structure, leaving box vectors untouched.

Source

pub fn chain(&self, id: &str) -> Option<&Chain>

Retrieves an immutable chain by identifier.

§Arguments
  • id - Chain identifier to search for.
§Returns

Some(&Chain) if found, otherwise None.

Source

pub fn chain_mut(&mut self, id: &str) -> Option<&mut Chain>

Retrieves a mutable chain by identifier.

§Arguments
  • id - Chain identifier to search for.
§Returns

Some(&mut Chain) if found, otherwise None.

Source

pub fn find_residue( &self, chain_id: &str, residue_id: i32, insertion_code: Option<char>, ) -> Option<&Residue>

Finds a residue using chain ID, residue number, and optional insertion code.

§Arguments
  • chain_id - Identifier of the chain to search.
  • residue_id - Numeric residue index (typically PDB resSeq).
  • insertion_code - Optional insertion code differentiating duplicate IDs.
§Returns

Some(&Residue) when the residue is located, otherwise None.

Source

pub fn find_residue_mut( &mut self, chain_id: &str, residue_id: i32, insertion_code: Option<char>, ) -> Option<&mut Residue>

Finds a mutable residue reference using chain and residue identifiers.

§Arguments
  • chain_id - Identifier of the chain to search.
  • residue_id - Numeric residue index.
  • insertion_code - Optional insertion code to disambiguate residues.
§Returns

Some(&mut Residue) when located, otherwise None.

Source

pub fn sort_chains_by_id(&mut self)

Sorts chains lexicographically by their identifier.

Source

pub fn chain_count(&self) -> usize

Returns the number of chains currently stored.

§Returns

Chain count as usize.

Source

pub fn residue_count(&self) -> usize

Counts all residues across every chain.

§Returns

Total residue count as usize.

Source

pub fn atom_count(&self) -> usize

Counts all atoms across every chain.

§Returns

Total atom count as usize.

Source

pub fn is_empty(&self) -> bool

Indicates whether the structure contains zero chains.

§Returns

true if no chains are present.

Source

pub fn iter_chains(&self) -> Iter<'_, Chain>

Provides an iterator over immutable chains.

§Returns

std::slice::Iter<'_, Chain> spanning all chains in insertion order.

Source

pub fn iter_chains_mut(&mut self) -> IterMut<'_, Chain>

Provides an iterator over mutable chains.

§Returns

std::slice::IterMut<'_, Chain> for in-place modification of chains.

Source

pub fn iter_atoms(&self) -> impl Iterator<Item = &Atom>

Iterates over immutable atoms across all chains.

§Returns

An iterator yielding &Atom in chain/residue order.

Source

pub fn iter_atoms_mut(&mut self) -> impl Iterator<Item = &mut Atom>

Iterates over mutable atoms across all chains.

§Returns

An iterator yielding &mut Atom for direct coordinate editing.

Source

pub fn retain_residues<F>(&mut self, f: F)
where F: FnMut(&str, &Residue) -> bool,

Retains residues that satisfy a predicate, removing all others.

The predicate receives the chain ID and a residue reference, enabling context-sensitive filtering.

§Arguments
  • f - Closure returning true to keep the residue.
Source

pub fn prune_empty_chains(&mut self)

Removes any chain that became empty after residue pruning.

Source

pub fn iter_atoms_with_context( &self, ) -> impl Iterator<Item = (&Chain, &Residue, &Atom)>

Iterates over atoms while including chain and residue context.

§Returns

An iterator yielding triples (&Chain, &Residue, &Atom) for every atom.

Source

pub fn geometric_center(&self) -> Point

Computes the geometric center of all atom coordinates.

Falls back to the origin when the structure contains no atoms.

§Returns

A Point located at the unweighted centroid.

Source

pub fn center_of_mass(&self) -> Point

Computes the mass-weighted center of all atoms.

Uses element atomic masses and returns the origin when the total mass is below numerical tolerance.

§Returns

A Point representing the center of mass.

Trait Implementations§

Source§

impl Clone for Structure

Source§

fn clone(&self) -> Structure

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 Structure

Source§

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

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

impl Default for Structure

Source§

fn default() -> Structure

Returns the “default value” for a type. Read more
Source§

impl Display for Structure

Source§

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

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

impl FromIterator<Chain> for Structure

Source§

fn from_iter<T: IntoIterator<Item = Chain>>(iter: T) -> Self

Creates a value from an iterator. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V