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>
impl<P> Translate<P>
Sourcepub fn with_maximum_distance(maximum_distance: PositiveReal) -> Self
pub fn with_maximum_distance(maximum_distance: PositiveReal) -> Self
Sourcepub fn maximum_distance(&self) -> &PositiveReal
pub fn maximum_distance(&self) -> &PositiveReal
Get the maximum distance.
Sourcepub fn maximum_distance_mut(&mut self) -> &mut PositiveReal
pub fn maximum_distance_mut(&mut self) -> &mut PositiveReal
Get the maximum distance.
Trait Implementations§
Source§impl<P> Adjust for Translate<P>
impl<P> Adjust for Translate<P>
Source§fn adjust(&mut self, factor: PositiveReal)
fn adjust(&mut self, factor: PositiveReal)
Change the maximum trial move size by the given scale factor.
Source§impl<'de, P> Deserialize<'de> for Translate<P>
impl<'de, P> Deserialize<'de> for Translate<P>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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<const N: usize, B> LocalTrial<B> for Translate<Cartesian<N>>
impl<const N: usize, B> LocalTrial<B> for Translate<Cartesian<N>>
Source§fn propose<R: Rng>(&self, rng: &mut R, body_properties: B) -> B
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>>
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>
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>>>
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>>
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>>>
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>>
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_eq!(new_body_radius, 1.0);
// Translation move does not translate the point more than a distance d away
assert!(
d > new_body_properties
.position()
.distance(&initial_point.position())
);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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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