[]Struct lumol::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.

Implementations

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 Clone for Composition

impl Debug for Composition

impl Eq for Composition

impl PartialEq<Composition> for Composition

impl StructuralEq for Composition

impl StructuralPartialEq for Composition

Auto Trait Implementations

impl RefUnwindSafe for Composition

impl Send for Composition

impl Sync for Composition

impl Unpin for Composition

impl UnwindSafe for Composition

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

impl<T> Pointable for T

type Init = T

The type for initializers.

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,