Residue

Struct Residue 

Source
pub struct Residue {
    pub id: i32,
    pub insertion_code: Option<char>,
    pub name: String,
    pub standard_name: Option<StandardResidue>,
    pub category: ResidueCategory,
    pub position: ResiduePosition,
    /* private fields */
}
Expand description

A residue within a biomolecular structure.

Residues capture crystallographic identifiers (sequence number and insertion code), the original and normalized names, classification metadata, and the atoms that belong to the residue. They are the primary unit passed between IO routines, topology builders, and structure editing operations.

Fields§

§id: i32

Author-provided sequence identifier (can be negative for certain files).

§insertion_code: Option<char>

Optional insertion code differentiating records that share the same id.

§name: String

Original residue name as encountered during parsing.

§standard_name: Option<StandardResidue>

Canonical residue assignment if the name maps to a standard alphabet entry.

§category: ResidueCategory

Category describing whether the residue is standard, heterogen, or ion.

§position: ResiduePosition

Chain position annotation (terminus, internal, or nucleic end).

Implementations§

Source§

impl Residue

Source

pub fn new( id: i32, insertion_code: Option<char>, name: &str, standard_name: Option<StandardResidue>, category: ResidueCategory, ) -> Self

Creates a residue with the provided identifiers and classification.

The residue starts without atoms and defaults to ResiduePosition::None until the caller updates it based on chain topology.

§Arguments
  • id - Sequence number pulled from the original structure file.
  • insertion_code - Optional insertion code for distinguishing alternate residues.
  • name - Author-provided residue label (e.g., "ALA", "DN1").
  • standard_name - Canonical assignment when the residue matches a standard entry.
  • category - Classification describing standard, hetero, or ion behavior.
§Returns

A Residue ready for atoms to be added.

Source

pub fn is_standard(&self) -> bool

Reports whether the residue maps to a standard residue definition.

§Returns

true when standard_name is set.

Source

pub fn add_atom(&mut self, atom: Atom)

Appends an atom to the residue.

Duplicate atom names are guarded with a debug assertion to prevent inconsistent topologies while still allowing release builds to proceed.

§Arguments
  • atom - The atom to insert; ownership moves into the residue.
§Panics

Panics in debug builds if an atom with the same name already exists.

Source

pub fn remove_atom(&mut self, name: &str) -> Option<Atom>

Removes an atom by name and returns ownership to the caller.

§Arguments
  • name - Atom name to remove (case-sensitive).
§Returns

Some(atom) if the atom existed, otherwise None.

Source

pub fn atom(&self, name: &str) -> Option<&Atom>

Retrieves an immutable reference to an atom by name.

§Arguments
  • name - Atom name to search for.
§Returns

Some(&Atom) when the atom exists, otherwise None.

Source

pub fn atom_mut(&mut self, name: &str) -> Option<&mut Atom>

Retrieves a mutable reference to an atom by name.

§Arguments
  • name - Atom name to search for.
§Returns

Some(&mut Atom) when the atom exists, otherwise None.

Source

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

Checks whether an atom with the provided name exists.

§Arguments
  • name - Atom name to test.
§Returns

true if the atom is present.

Source

pub fn atoms(&self) -> &[Atom]

Returns an immutable slice of all atoms contained in the residue.

Enables zero-copy iteration when only read-only access is required.

§Returns

A slice view over the internal atom vector.

Source

pub fn atom_count(&self) -> usize

Counts the number of atoms owned by the residue.

§Returns

Number of atoms currently stored.

Source

pub fn is_empty(&self) -> bool

Indicates whether the residue has no atoms.

§Returns

true if atom_count() equals zero.

Source

pub fn iter_atoms(&self) -> Iter<'_, Atom>

Provides an iterator over immutable atom references.

This mirrors atoms() but allows idiomatic for loops without exposing the backing vector.

§Returns

An iterator yielding &Atom values.

Source

pub fn iter_atoms_mut(&mut self) -> IterMut<'_, Atom>

Provides an iterator over mutable atom references.

§Returns

An iterator yielding &mut Atom values so callers can edit coordinates or metadata.

Source

pub fn strip_hydrogens(&mut self)

Removes all hydrogen atoms from the residue.

Used by cleaning operations when preparing structures for solvation or heavy-atom analysis.

Trait Implementations§

Source§

impl Clone for Residue

Source§

fn clone(&self) -> Residue

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 Residue

Source§

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

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

impl Display for Residue

Source§

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

Formats the residue with identifier, canonical name, category, and atom count.

Source§

impl PartialEq for Residue

Source§

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

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

Source§

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