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

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

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

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

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

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

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

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

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

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Debug for Composition

Formats the value using the given formatter. Read more

impl Clone for Composition

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for Composition

impl Sync for Composition

Blanket Implementations

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

Creates owned data from borrowed data, usually by cloning. Read more

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

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T> From for T
[src]

Performs the conversion.

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

Performs the conversion.

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

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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

Important traits for &'a mut R

Immutably borrows from an owned value. Read more

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

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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

Important traits for &'a mut R

Mutably borrows from an owned value. Read more

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

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

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more