Struct chemfiles::Residue

source ·
pub struct Residue { /* private fields */ }
Expand description

A Residue is a group of atoms belonging to the same logical unit. They can be small molecules, amino-acids in a protein, monomers in polymers, etc.

Implementations§

source§

impl Residue

source

pub fn new<'a>(name: impl Into<&'a str>) -> Residue

Create a new residue with the given name

Example
let residue = Residue::new("ALA");
assert_eq!(residue.name(), "ALA");
assert_eq!(residue.id(), None);
source

pub fn with_id<'a>(name: impl Into<&'a str>, id: i64) -> Residue

Create a new residue with the given name and id as identifier.

Example
let residue = Residue::with_id("ALA", 67);
assert_eq!(residue.name(), "ALA");
assert_eq!(residue.id(), Some(67));
source

pub fn size(&self) -> usize

Get the number of atoms in this residue.

Example
let mut residue = Residue::new("water");
assert_eq!(residue.size(), 0);

residue.add_atom(0);
residue.add_atom(1);
residue.add_atom(2);
assert_eq!(residue.size(), 3);
source

pub fn id(&self) -> Option<i64>

Get the identifier of this residue in the initial topology file.

Example
let residue = Residue::with_id("", 42);
assert_eq!(residue.id(), Some(42));
source

pub fn name(&self) -> String

Get the name of this residue.

Example
let residue = Residue::new("water");
assert_eq!(residue.name(), "water");
source

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

Add the atom at index atom in this residue.

This will fail if the atom is already in the residue.

Example
let mut residue = Residue::new("water");
assert_eq!(residue.size(), 0);
assert_eq!(residue.contains(56), false);

residue.add_atom(56);
assert_eq!(residue.size(), 1);
assert_eq!(residue.contains(56), true);

// Adding the same atom twice is fine
residue.add_atom(56);
assert_eq!(residue.size(), 1);
source

pub fn contains(&self, atom: usize) -> bool

Check if the atom at index i is in this residue

Example
let mut residue = Residue::new("water");
assert_eq!(residue.contains(56), false);

residue.add_atom(56);
assert_eq!(residue.contains(56), true);
source

pub fn atoms(&self) -> Vec<usize>

Get the list of atoms of this residue.

Example
let mut residue = Residue::new("water");
assert_eq!(residue.atoms(), vec![]);

residue.add_atom(56);
assert_eq!(residue.atoms(), vec![56]);
source

pub fn set(&mut self, name: &str, property: impl Into<Property>)

Add a new property with the given name to this residue.

If a property with the same name already exists, this function override the existing property with the new one.

Examples
let mut residue = Residue::new("ALA");
residue.set("a string", "hello");
residue.set("a double", 3.2);

assert_eq!(residue.get("a string"), Some(Property::String("hello".into())));
assert_eq!(residue.get("a double"), Some(Property::Double(3.2)));
source

pub fn get(&self, name: &str) -> Option<Property>

Get a property with the given name in this frame, if it exist.

Examples
let mut residue = Residue::new("ALA");
residue.set("foo", Property::Double(22.2));

assert_eq!(residue.get("foo"), Some(Property::Double(22.2)));
assert_eq!(residue.get("Bar"), None);
source

pub fn properties(&self) -> PropertiesIter<'_>

Get an iterator over all (name, property) pairs for this frame

Examples
let mut residue = Residue::new("ALA");
residue.set("foo", Property::Double(22.2));
residue.set("bar", Property::Bool(false));

for (name, property) in residue.properties() {
    if name == "foo" {
        assert_eq!(property, Property::Double(22.2));
    } else if name == "bar" {
        assert_eq!(property, Property::Bool(false));
    }
}

Trait Implementations§

source§

impl Clone for Residue

source§

fn clone(&self) -> Residue

Returns a copy 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 Drop for Residue

source§

fn drop(&mut self)

Executes the destructor for this type. 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> 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,

§

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

§

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

§

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.