[]Struct lumol::sys::Composition

pub struct Composition { /* fields omitted */ }

The system composition contains the number of particles of each kind in the system, as well as the number of molecules of each molecule type.

Methods

impl Composition

pub fn new() -> Composition

Create a new empty composition

Examples

let composition = Composition::new();

// no particles
assert_eq!(composition.all_particles().count(), 0);

// no molecules
assert_eq!(composition.all_molecules().count(), 0);

pub fn add_particle(&mut self, kind: ParticleKind)

Add a particle with the given kind to the internal counter

Examples

let mut composition = Composition::new();

composition.add_particle(ParticleKind(3));
composition.add_particle(ParticleKind(3));

assert_eq!(composition.particles(ParticleKind(3)), 2);

pub fn remove_particle(&mut self, kind: ParticleKind)

Remove a particle with the given kind to the internal counter

Examples

let mut composition = Composition::new();

composition.add_particle(ParticleKind(3));
composition.add_particle(ParticleKind(3));

assert_eq!(composition.particles(ParticleKind(3)), 2);

composition.remove_particle(ParticleKind(3));

assert_eq!(composition.particles(ParticleKind(3)), 1);

pub fn particles(&self, kind: ParticleKind) -> usize

Get the number of particles with a given kind

Examples

let mut composition = Composition::new();

assert_eq!(composition.particles(ParticleKind(3)), 0);

composition.add_particle(ParticleKind(3));
composition.add_particle(ParticleKind(3));

assert_eq!(composition.particles(ParticleKind(3)), 2);

pub fn all_particles(
    &'a self
) -> impl Iterator<Item = (ParticleKind, usize)> + 'a

Get an iterator over the particles kind and count

Examples

let mut composition = Composition::new();

composition.add_particle(ParticleKind(10));
composition.add_particle(ParticleKind(4));
composition.add_particle(ParticleKind(4));

let mut iter = composition.all_particles();
assert_eq!(iter.next(), Some((ParticleKind(4), 2)));
assert_eq!(iter.next(), Some((ParticleKind(10), 1)));
assert_eq!(iter.next(), None);

pub fn add_molecule(&mut self, hash: MoleculeHash)

Add a molecule with the given moltype to the internal counter

Examples

// Getting a molecule hash
let he = Molecule::new(Particle::new("He")).hash();

let mut composition = Composition::new();
assert_eq!(composition.molecules(he), 0);

composition.add_molecule(he);
composition.add_molecule(he);

assert_eq!(composition.molecules(he), 2);

pub fn remove_molecule(&mut self, hash: MoleculeHash)

Add a molecule with the given moltype to the internal counter

Examples

// Getting a molecule hash
let he = Molecule::new(Particle::new("He")).hash();

let mut composition = Composition::new();
assert_eq!(composition.molecules(he), 0);

composition.add_molecule(he);
composition.add_molecule(he);

assert_eq!(composition.molecules(he), 2);

composition.remove_molecule(he);

assert_eq!(composition.molecules(he), 1);

pub fn molecules(&self, hash: MoleculeHash) -> usize

Get the number of particles with the given hash

Examples

// Getting some molecules hashes
let he = Molecule::new(Particle::new("He")).hash();

let ar = Molecule::new(Particle::new("Ar")).hash();

let mut n2 = Molecule::new(Particle::new("N"));
n2.add_particle_bonded_to(0, Particle::new("N"));
let n2 = n2.hash();

let mut composition = Composition::new();

composition.add_molecule(he);
composition.add_molecule(he);
composition.add_molecule(n2);

assert_eq!(composition.molecules(he), 2);
assert_eq!(composition.molecules(n2), 1);
assert_eq!(composition.molecules(ar), 0);

pub fn all_molecules(
    &'a self
) -> impl Iterator<Item = (MoleculeHash, usize)> + 'a

Get an iterator over the molecules hashes and count

Examples

let mut composition = Composition::new();
let he = Molecule::new(Particle::new("He")).hash();
let ar = Molecule::new(Particle::new("Ar")).hash();

composition.add_molecule(he);
composition.add_molecule(he);
composition.add_molecule(ar);

let mut iter = composition.all_molecules();
assert_eq!(iter.next(), Some((he, 2)));
assert_eq!(iter.next(), Some((ar, 1)));
assert_eq!(iter.next(), None);

Trait Implementations

impl Eq for Composition

impl PartialEq<Composition> for Composition

impl Clone for Composition

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

Performs copy-assignment from source. Read more

impl Debug for Composition

Auto Trait Implementations

impl Send for Composition

impl Sync for Composition

Blanket Implementations

impl<T> From for T[src]

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