Translate

Struct Translate 

Source
pub struct Translate<P> { /* private fields */ }
Expand description

Move the position of a body by a small distance.

Translate proposes local trial moves that translate the position of a body in space by up to a maximum distance, given by a PositiveReal.

The generic type names are:

  • P: The type of the point to translate.

§Example

use hoomd_mc::Translate;
use hoomd_vector::Cartesian;

let d = 0.1;
let translate =
    Translate::<Cartesian<2>>::with_maximum_distance(d.try_into()?);

Implementations§

Source§

impl<P> Translate<P>

Source

pub fn with_maximum_distance(maximum_distance: PositiveReal) -> Self

Construct a Translate move with the given maximum distance.

§Example
use hoomd_mc::Translate;
use hoomd_vector::Cartesian;

let d = 0.1;
let translate =
    Translate::<Cartesian<2>>::with_maximum_distance(d.try_into()?);
Source

pub fn maximum_distance(&self) -> &PositiveReal

Get the maximum distance.

Source

pub fn maximum_distance_mut(&mut self) -> &mut PositiveReal

Get the maximum distance.

Trait Implementations§

Source§

impl<P> Adjust for Translate<P>

Source§

fn adjust(&mut self, factor: PositiveReal)

Change the maximum trial move size by the given scale factor.

Source§

impl<P: Clone> Clone for Translate<P>

Source§

fn clone(&self) -> Translate<P>

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<P: Debug> Debug for Translate<P>

Source§

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

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

impl<'de, P> Deserialize<'de> for Translate<P>

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<P> Display for Translate<P>

Source§

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

Format a Translate as {maximum_distance}.

Source§

impl<const N: usize, B> LocalTrial<B> for Translate<Cartesian<N>>
where B: Position<Position = Cartesian<N>>, Ball: Distribution<Cartesian<N>>,

Source§

fn propose<R: Rng>(&self, rng: &mut R, body_properties: B) -> B

Perturb a body’s position by a random amount.

§Example
use hoomd_mc::{LocalTrial, Translate};
use hoomd_microstate::property::Point;
use hoomd_vector::{Cartesian, InnerProduct};
use rand::{Rng, SeedableRng, rngs::StdRng};

let mut rng = StdRng::seed_from_u64(1);
let body_properties = Point::new(Cartesian::from([0.0, 0.0]));
let d = 1.0;
let translate = Translate::with_maximum_distance(d.try_into()?);

let new_body_properties = translate.propose(&mut rng, body_properties);
assert!(new_body_properties.position.norm() < 1.0);
Source§

impl LocalTrial<OrientedHyperbolicPoint<3, Angle>> for Translate<OrientedHyperbolicPoint<3, Angle>>

Source§

fn propose<R: Rng>( &self, rng: &mut R, body_properties: OrientedHyperbolicPoint<3, Angle>, ) -> OrientedHyperbolicPoint<3, Angle>

Propose local trial moves for an oriented body on a hyperbolic surface.

Source§

impl LocalTrial<Point<Hyperbolic<3>>> for Translate<Point<Hyperbolic<3>>>

Source§

fn propose<R: Rng>( &self, rng: &mut R, body_properties: Point<Hyperbolic<3>>, ) -> Point<Hyperbolic<3>>

Propose local trial moves for a body on a hyperbolic surface.

§Example
use approxim::assert_relative_eq;
use hoomd_manifold::{Hyperbolic, Minkowski};
use hoomd_mc::{LocalTrial, Translate};
use hoomd_microstate::property::{Point, Position};
use hoomd_vector::Metric;
use rand::{SeedableRng, rngs::StdRng};

let mut rng = StdRng::seed_from_u64(13);
let body_properties = Point::new(Hyperbolic::from_minkowski_coordinates(
    [1.0, -1.0, (3.0_f64).sqrt()].into(),
));
let d = 0.1;
let translate = Translate::with_maximum_distance(d.try_into()?);

let new_body_properties = translate.propose(&mut rng, body_properties);

// Translation move keeps the point on the Hyperboloid
assert_relative_eq!(
    new_body_properties
        .position()
        .point()
        .distance_squared(&Minkowski::from([0.0, 0.0, 0.0])),
    -1.0_f64,
    epsilon = 1e-12
);

// Translation move does not move the point more than a distance d
assert!(
    d > new_body_properties.position().distance(
        &Hyperbolic::from_minkowski_coordinates(Minkowski::from([
            1.0,
            -1.0,
            (3.0_f64).sqrt()
        ]))
    )
);
Source§

impl LocalTrial<Point<Spherical<3>>> for Translate<Point<Spherical<3>>>

Source§

fn propose<R: Rng>( &self, rng: &mut R, body_properties: Point<Spherical<3>>, ) -> Point<Spherical<3>>

Propose local trial moves for a body on the surface of a sphere

§Example
use approxim::assert_relative_eq;
use hoomd_manifold::{Spherical, SphericalDisk};
use hoomd_mc::{LocalTrial, Translate};
use hoomd_microstate::property::{Point, Position};
use hoomd_vector::{Cartesian, InnerProduct, Metric, Vector};
use rand::{Rng, SeedableRng, rngs::StdRng};

let mut rng = StdRng::seed_from_u64(14);
let initial_point = Point::new(Spherical::from_cartesian_coordinates(
    [0.5_f64.sqrt(), 0.5_f64.sqrt(), 0.0].into(),
));
let d = 0.1;
let translate = Translate::with_maximum_distance(d.try_into()?);

let new_body_properties = translate.propose(&mut rng, initial_point);

// Translation move keeps point on the surface of the sphere
let new_body_radius = new_body_properties.position.point().norm();
assert_relative_eq!(new_body_radius, 1.0, epsilon = 1e-8);

// Translation move does not translate the point more than a distance d away
assert!(
    d > new_body_properties
        .position()
        .distance(&initial_point.position())
);
Source§

impl LocalTrial<Point<Spherical<4>>> for Translate<Point<Spherical<4>>>

Source§

fn propose<R: Rng>( &self, rng: &mut R, body_properties: Point<Spherical<4>>, ) -> Point<Spherical<4>>

Propose local trial moves for a body on the surface of a 3-sphere

§Example
use approxim::assert_relative_eq;
use hoomd_manifold::{Spherical, SphericalDisk};
use hoomd_mc::{LocalTrial, Translate};
use hoomd_microstate::property::{Point, Position};
use hoomd_vector::{Cartesian, InnerProduct, Metric, Vector};
use rand::{Rng, SeedableRng, rngs::StdRng};
use std::f64::consts::PI;

let mut rng = StdRng::seed_from_u64(14);
let initial_point = Point::new(Spherical::<4>::from_polar_coordinates(
    PI / 4.0,
    PI / 10.0,
    5.0 * PI / 4.0,
));
let d = 0.1;
let translate = Translate::with_maximum_distance(d.try_into()?);

let new_body_properties = translate.propose(&mut rng, initial_point);

// Translation move keeps point on the surface of the sphere
assert_relative_eq!(
    new_body_properties.position().point().norm(),
    1.0_f64,
    epsilon = 1e-8
);

// Translation move does not translate the point more than a distance d away
assert!(
    d > new_body_properties
        .position()
        .distance(&initial_point.position())
);
Source§

impl<P: PartialEq> PartialEq for Translate<P>

Source§

fn eq(&self, other: &Translate<P>) -> 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<P> Serialize for Translate<P>

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<P> StructuralPartialEq for Translate<P>

Auto Trait Implementations§

§

impl<P> Freeze for Translate<P>

§

impl<P> RefUnwindSafe for Translate<P>
where P: RefUnwindSafe,

§

impl<P> Send for Translate<P>
where P: Send,

§

impl<P> Sync for Translate<P>
where P: Sync,

§

impl<P> Unpin for Translate<P>
where P: Unpin,

§

impl<P> UnwindSafe for Translate<P>
where P: UnwindSafe,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,