Count

Struct Count 

Source
pub struct Count {
    pub accepted: u64,
    pub rejected: u64,
}
Expand description

Accepted and rejected trial moves.

A Trial reports the number moves it accepts and rejects via Count (or some variation on Count). Count implements Add, AddAssign, and convenience methods that compute often used properties, like the acceptance rate.

§Example

Count the total number of trial moves performed over a number of sweeps:

use hoomd_interaction::Zero;
use hoomd_mc::{Count, Sweep, Translate, Trial};
use hoomd_microstate::{Body, Microstate, property::Position};
use hoomd_simulation::macrostate::Isothermal;
use hoomd_vector::Cartesian;

let macrostate = Isothermal { temperature: 1.0 };
let mut microstate = Microstate::new();
microstate.add_body(Body::point(Cartesian::from([0.0, 0.0])));
let d = 0.1;
let translate = Translate::with_maximum_distance(d.try_into()?);
let mut translate_sweep = Sweep(translate);

let mut count = Count::default();

for _ in 0..1_000 {
    count += translate_sweep.apply(&mut microstate, &Zero, &macrostate);
    microstate.increment_step();
}

assert_eq!(count.total(), 1_000);

Fields§

§accepted: u64

The number of accepted moves.

§rejected: u64

The number of rejected moves.

Implementations§

Source§

impl Count

Source

pub fn total(&self) -> u64

The total number of trial moves.

§Example
use hoomd_mc::Count;

let count = Count {
    accepted: 2_000,
    rejected: 8_000,
};
let total = count.total();

assert_eq!(total, 10_000);
Source

pub fn acceptance_ratio(&self) -> Option<f64>

The fraction of moves that were accepted.

The acceptance ratio is the ratio of accepted moves to total moves. acceptance_ratio returns Some(ratio) when the number of total moves is nonzero and None when there are 0 moves.

§Example
use hoomd_mc::Count;

let count = Count {
    accepted: 2_000,
    rejected: 8_000,
};
let acceptance_ratio = count.acceptance_ratio();

assert_eq!(acceptance_ratio, Some(0.2));
use hoomd_mc::Count;

let count = Count::default();
let acceptance_ratio = count.acceptance_ratio();

assert_eq!(acceptance_ratio, None);

Trait Implementations§

Source§

impl Add for Count

Source§

type Output = Count

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl AddAssign for Count

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Count

Source§

fn clone(&self) -> Count

Returns a duplicate 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 Count

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Count

Source§

fn default() -> Count

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Count

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Count

Source§

fn eq(&self, other: &Count) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Count

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Count

Source§

impl StructuralPartialEq for Count

Auto Trait Implementations§

§

impl Freeze for Count

§

impl RefUnwindSafe for Count

§

impl Send for Count

§

impl Sync for Count

§

impl Unpin for Count

§

impl UnwindSafe for Count

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

Source§

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

Source§

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,