Chain

Struct Chain 

Source
pub struct Chain {
    pub id: String,
    /* private fields */
}
Expand description

Polymer chain containing an ordered list of residues.

The chain preserves the order residues were added, mirrors the chain identifier seen in structure files (e.g., "A"), and provides iteration helpers for both residues and atoms while keeping the internal storage private.

Fields§

§id: String

Chain identifier matching the source structure (usually a single character).

Implementations§

Source§

impl Chain

Source

pub fn new(id: &str) -> Self

Creates an empty chain with the provided identifier.

Use this constructor when building structures procedurally or when importing from file formats that enumerate chains.

§Arguments
  • id - Label matching the original structure’s chain identifier.
§Returns

A new Chain with no residues.

Source

pub fn add_residue(&mut self, residue: Residue)

Adds a residue to the chain while preventing duplicate identifiers.

Residues are appended in insertion order. Duplicate (id, insertion_code) pairs are rejected during debug builds to guard against malformed inputs.

§Arguments
  • residue - The residue to append.
Source

pub fn residue(&self, id: i32, insertion_code: Option<char>) -> Option<&Residue>

Looks up a residue by identifier and optional insertion code.

§Arguments
  • id - Residue sequence number.
  • insertion_code - Optional insertion code used in PDB/mmCIF records.
§Returns

Some(&Residue) if a matching residue exists; otherwise None.

Source

pub fn residue_mut( &mut self, id: i32, insertion_code: Option<char>, ) -> Option<&mut Residue>

Fetches a mutable reference to a residue by identifier.

§Arguments
  • id - Residue sequence number.
  • insertion_code - Optional insertion code qualifier.
§Returns

Some(&mut Residue) when present; otherwise None.

Source

pub fn residues(&self) -> &[Residue]

Returns an immutable slice containing all residues in order.

Useful for bulk analysis or when interfacing with APIs that operate on slices.

§Returns

Slice view of the underlying residue list.

Source

pub fn residue_count(&self) -> usize

Reports the number of residues stored in the chain.

§Returns

Count of residues currently tracked.

Source

pub fn is_empty(&self) -> bool

Indicates whether the chain contains no residues.

§Returns

true when the chain is empty.

Source

pub fn iter_residues(&self) -> Iter<'_, Residue>

Provides an iterator over immutable residue references.

This mirrors residues() but avoids exposing slice internals and composes nicely with iterator adaptors.

§Returns

A standard slice iterator over Residue references.

Source

pub fn iter_residues_mut(&mut self) -> IterMut<'_, Residue>

Provides an iterator over mutable residue references.

§Returns

A mutable slice iterator that allows in-place modifications.

Source

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

Iterates over all atoms contained in the chain.

Residues are traversed in order and their atom iterators flattened, yielding atoms in the same relative ordering seen in the original structure.

§Returns

Iterator that yields immutable Atom references.

Source

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

Iterates over all atoms with mutable access.

§Returns

Iterator producing mutable Atom references for bulk editing operations.

Source

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

Retains only residues that satisfy the provided predicate.

§Arguments
  • f - Predicate invoked for each residue; keep the residue when it returns true.
Source

pub fn remove_residue( &mut self, id: i32, insertion_code: Option<char>, ) -> Option<Residue>

Removes a residue by identifier and returns ownership if found.

§Arguments
  • id - Residue number to remove.
  • insertion_code - Optional insertion qualifier.
§Returns

Some(Residue) containing the removed residue; otherwise None.

Trait Implementations§

Source§

impl Clone for Chain

Source§

fn clone(&self) -> Chain

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 Chain

Source§

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

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

impl Display for Chain

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
Source§

impl PartialEq for Chain

Source§

fn eq(&self, other: &Chain) -> 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 Chain

Auto Trait Implementations§

§

impl Freeze for Chain

§

impl RefUnwindSafe for Chain

§

impl Send for Chain

§

impl Sync for Chain

§

impl Unpin for Chain

§

impl UnwindSafe for Chain

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

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,