[][src]Struct chemfiles::Residue

pub struct Residue { /* fields omitted */ }

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.

Methods

impl Residue[src]

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

Create a new residue with the given name

Example

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

pub fn with_id<'a>(
    name: impl Into<&'a str>,
    id: u64
) -> Residue
[src]

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));

pub fn size(&self) -> u64[src]

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);

pub fn id(&self) -> Option<u64>[src]

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

Example

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

pub fn name(&self) -> String[src]

Get the name of this residue.

Example

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

pub fn add_atom(&mut self, atom: u64)[src]

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);

pub fn contains(&self, atom: u64) -> bool[src]

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);

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

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)));

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

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);

Important traits for PropertiesIter<'a>
pub fn properties(&self) -> PropertiesIter[src]

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

impl Clone for Residue[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Drop for Residue[src]

Auto Trait Implementations

impl !Send for Residue

impl !Sync for Residue

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]