pub struct Sweep<L>(pub L);Expand description
Apply a local trial move to bodies in the microstate.
The first field in the tuple struct determines what trial moves Sweep
attempts. Sweep::apply applies the trial move to each body in the
microstate once. Sweep::apply_with_filter applies the trial move
to select bodies.
§Example
use hoomd_mc::{Sweep, Translate};
use hoomd_vector::Cartesian;
let d = 0.1;
let translate =
Translate::<Cartesian<2>>::with_maximum_distance(d.try_into()?);
let translate_sweep = Sweep(translate);Tuple Fields§
§0: LImplementations§
Source§impl<L> Sweep<L>
impl<L> Sweep<L>
Sourcepub fn apply_with_filter<P, B, S, X, C, H, MA, F>(
&self,
microstate: &mut Microstate<B, S, X, C>,
hamiltonian: &H,
macrostate: &MA,
should_move_body: F,
) -> Countwhere
P: Copy,
B: Copy + Default + Transform<S> + Position<Position = P>,
S: Copy + Default + Position<Position = P>,
X: PointUpdate<P, SiteKey>,
L: LocalTrial<B>,
H: DeltaEnergyOne<B, S, X, C>,
C: Wrap<B> + Wrap<S> + GenerateGhosts<S>,
MA: Temperature,
F: Fn(&Tagged<Body<B, S>>) -> bool,
pub fn apply_with_filter<P, B, S, X, C, H, MA, F>(
&self,
microstate: &mut Microstate<B, S, X, C>,
hamiltonian: &H,
macrostate: &MA,
should_move_body: F,
) -> Countwhere
P: Copy,
B: Copy + Default + Transform<S> + Position<Position = P>,
S: Copy + Default + Position<Position = P>,
X: PointUpdate<P, SiteKey>,
L: LocalTrial<B>,
H: DeltaEnergyOne<B, S, X, C>,
C: Wrap<B> + Wrap<S> + GenerateGhosts<S>,
MA: Temperature,
F: Fn(&Tagged<Body<B, S>>) -> bool,
Apply a local trial move to select bodies in the microstate.
apply_with_filter applies trial moves to bodies where should_move_body
returns true.
Each trial move is accepted when:
r < \exp\left(\frac{-\Delta H}{kT}\right)where r is a random value uniformly distributed in [0,1), $\Delta H$ is
the change in energy computed by the given hamiltonian and $kT$ is the
temperature given in macrostate.
§Example
use hoomd_interaction::Zero;
use hoomd_mc::{Sweep, Translate, Trial};
use hoomd_microstate::{Body, Microstate, property::Position};
use hoomd_simulation::macrostate::Isothermal;
use hoomd_vector::Cartesian;
let mut microstate = Microstate::new();
microstate.add_body(Body::point(Cartesian::from([0.0, 0.0])));
microstate.add_body(Body::point(Cartesian::from([1.0, 0.0])));
microstate.add_body(Body::point(Cartesian::from([0.0, 1.0])));
let d = 0.1;
let translate = Translate::with_maximum_distance(d.try_into()?);
let mut translate_sweep = Sweep(translate);
let hamiltonian = Zero;
let macrostate = Isothermal { temperature: 1.0 };
for _ in 0..1_000 {
translate_sweep.apply_with_filter(
&mut microstate,
&hamiltonian,
¯ostate,
|b| b.tag != 0,
);
microstate.increment_step();
}
assert_eq!(
microstate.bodies()[0].item.properties.position,
[0.0, 0.0].into()
);Sourcepub fn tune_with_options_and_filter<P, B, S, X, C, H, MA, F>(
&mut self,
microstate: &Microstate<B, S, X, C>,
hamiltonian: &H,
macrostate: &MA,
options: &TuneOptions,
should_move_body: F,
)where
P: Copy,
B: Copy + Default + Transform<S> + Position<Position = P>,
S: Copy + Default + Position<Position = P>,
X: PointUpdate<P, SiteKey>,
L: LocalTrial<B> + Adjust + Display,
H: DeltaEnergyOne<B, S, X, C>,
C: Wrap<B> + Wrap<S> + GenerateGhosts<S>,
MA: Temperature,
F: Fn(&Tagged<Body<B, S>>) -> bool,
pub fn tune_with_options_and_filter<P, B, S, X, C, H, MA, F>(
&mut self,
microstate: &Microstate<B, S, X, C>,
hamiltonian: &H,
macrostate: &MA,
options: &TuneOptions,
should_move_body: F,
)where
P: Copy,
B: Copy + Default + Transform<S> + Position<Position = P>,
S: Copy + Default + Position<Position = P>,
X: PointUpdate<P, SiteKey>,
L: LocalTrial<B> + Adjust + Display,
H: DeltaEnergyOne<B, S, X, C>,
C: Wrap<B> + Wrap<S> + GenerateGhosts<S>,
MA: Temperature,
F: Fn(&Tagged<Body<B, S>>) -> bool,
Tune the trial move maximum size to achieve a given acceptance ratio.
tune_with_options_and_filter applies trial moves to bodies where
should_move_body returns true.
§Example
use hoomd_geometry::shape::Rectangle;
use hoomd_interaction::{
MaximumInteractionRange, PairwiseCutoff, pairwise::HardSphere,
};
use hoomd_mc::{Sweep, Translate, Trial, Tune, TuneOptions};
use hoomd_microstate::{
Body, Microstate, boundary::Periodic, property::Position,
};
use hoomd_simulation::macrostate::Isothermal;
use hoomd_vector::Cartesian;
let square = Rectangle::with_equal_edges(2.2.try_into()?);
let mut microstate = Microstate::builder()
.boundary(Periodic::new(1.0, square)?)
.try_build()?;
microstate.add_body(Body::point(Cartesian::from([-0.6, -0.6])))?;
microstate.add_body(Body::point(Cartesian::from([-0.6, 0.6])))?;
microstate.add_body(Body::point(Cartesian::from([0.6, -0.6])))?;
microstate.add_body(Body::point(Cartesian::from([0.6, 0.6])))?;
let d = 0.1;
let translate = Translate::with_maximum_distance(d.try_into()?);
let mut translate_sweep = Sweep(translate);
let hamiltonian = PairwiseCutoff(HardSphere { diameter: 1.0 });
let macrostate = Isothermal { temperature: 1.0 };
translate_sweep.tune_with_options_and_filter(
µstate,
&hamiltonian,
¯ostate,
&TuneOptions::default(),
|b| b.tag >= 2,
);
Trait Implementations§
Source§impl<'de, L> Deserialize<'de> for Sweep<L>where
L: Deserialize<'de>,
impl<'de, L> Deserialize<'de> for Sweep<L>where
L: Deserialize<'de>,
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>,
Source§impl<P, B, S, X, C, L, H, MA> Trial<Microstate<B, S, X, C>, H, MA> for Sweep<L>where
P: Copy,
B: Copy + Default + Transform<S> + Position<Position = P>,
S: Copy + Default + Position<Position = P>,
X: PointUpdate<P, SiteKey>,
L: LocalTrial<B>,
H: DeltaEnergyOne<B, S, X, C>,
C: Wrap<B> + Wrap<S> + GenerateGhosts<S>,
MA: Temperature,
impl<P, B, S, X, C, L, H, MA> Trial<Microstate<B, S, X, C>, H, MA> for Sweep<L>where
P: Copy,
B: Copy + Default + Transform<S> + Position<Position = P>,
S: Copy + Default + Position<Position = P>,
X: PointUpdate<P, SiteKey>,
L: LocalTrial<B>,
H: DeltaEnergyOne<B, S, X, C>,
C: Wrap<B> + Wrap<S> + GenerateGhosts<S>,
MA: Temperature,
Source§fn apply(
&mut self,
microstate: &mut Microstate<B, S, X, C>,
hamiltonian: &H,
macrostate: &MA,
) -> Self::Count
fn apply( &mut self, microstate: &mut Microstate<B, S, X, C>, hamiltonian: &H, macrostate: &MA, ) -> Self::Count
Apply a local trial move to each body in the microstate.
Each trial move is accepted when:
r < \exp\left(\frac{-\Delta H}{kT}\right)where r is a random value uniformly distributed in [0,1), $\Delta H$ is
the change in energy computed by the given hamiltonian and $kT$ is the
temperature given in macrostate.
§Example
use hoomd_interaction::Zero;
use hoomd_mc::{Sweep, Translate, Trial};
use hoomd_microstate::{Body, Microstate, property::Position};
use hoomd_simulation::macrostate::Isothermal;
use hoomd_vector::Cartesian;
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 hamiltonian = Zero;
let macrostate = Isothermal { temperature: 1.0 };
for _ in 0..1_000 {
translate_sweep.apply(&mut microstate, &hamiltonian, ¯ostate);
microstate.increment_step();
}Source§impl<P, B, S, X, C, L, H, MA> Tune<P, B, S, X, C, L, H, MA> for Sweep<L>where
P: Copy,
B: Copy + Default + Transform<S> + Position<Position = P>,
S: Copy + Default + Position<Position = P>,
X: PointUpdate<P, SiteKey>,
L: LocalTrial<B> + Adjust + Display,
H: DeltaEnergyOne<B, S, X, C>,
C: Wrap<B> + Wrap<S> + GenerateGhosts<S>,
MA: Temperature,
impl<P, B, S, X, C, L, H, MA> Tune<P, B, S, X, C, L, H, MA> for Sweep<L>where
P: Copy,
B: Copy + Default + Transform<S> + Position<Position = P>,
S: Copy + Default + Position<Position = P>,
X: PointUpdate<P, SiteKey>,
L: LocalTrial<B> + Adjust + Display,
H: DeltaEnergyOne<B, S, X, C>,
C: Wrap<B> + Wrap<S> + GenerateGhosts<S>,
MA: Temperature,
Source§fn tune(
&mut self,
microstate: &Microstate<B, S, X, C>,
hamiltonian: &H,
macrostate: &MA,
target_acceptance: OpenUnitIntervalNumber,
samples: usize,
steps: usize,
)
👎Deprecated since 1.1.0: use tune_with_options
fn tune( &mut self, microstate: &Microstate<B, S, X, C>, hamiltonian: &H, macrostate: &MA, target_acceptance: OpenUnitIntervalNumber, samples: usize, steps: usize, )
tune_with_optionsTune the trial move maximum size to achieve a given acceptance ratio.
§Example
use hoomd_geometry::shape::Rectangle;
use hoomd_interaction::{
MaximumInteractionRange, PairwiseCutoff, pairwise::HardSphere,
};
use hoomd_mc::{Sweep, Translate, Trial, Tune, TuneOptions};
use hoomd_microstate::{
Body, Microstate, boundary::Periodic, property::Position,
};
use hoomd_simulation::macrostate::Isothermal;
use hoomd_vector::Cartesian;
let square = Rectangle::with_equal_edges(2.2.try_into()?);
let mut microstate = Microstate::builder()
.boundary(Periodic::new(1.0, square)?)
.try_build()?;
microstate.add_body(Body::point(Cartesian::from([-0.6, -0.6])))?;
microstate.add_body(Body::point(Cartesian::from([-0.6, 0.6])))?;
microstate.add_body(Body::point(Cartesian::from([0.6, -0.6])))?;
microstate.add_body(Body::point(Cartesian::from([0.6, 0.6])))?;
let d = 0.1;
let translate = Translate::with_maximum_distance(d.try_into()?);
let mut translate_sweep = Sweep(translate);
let hamiltonian = PairwiseCutoff(HardSphere { diameter: 1.0 });
let macrostate = Isothermal { temperature: 1.0 };
translate_sweep.tune_with_options(
µstate,
&hamiltonian,
¯ostate,
&TuneOptions::default(),
);
Source§fn tune_with_options(
&mut self,
microstate: &Microstate<B, S, X, C>,
hamiltonian: &H,
macrostate: &MA,
options: &TuneOptions,
)
fn tune_with_options( &mut self, microstate: &Microstate<B, S, X, C>, hamiltonian: &H, macrostate: &MA, options: &TuneOptions, )
Source§fn tune_default(
&mut self,
microstate: &Microstate<B, S, X, C>,
hamiltonian: &H,
macrostate: &MA,
)
fn tune_default( &mut self, microstate: &Microstate<B, S, X, C>, hamiltonian: &H, macrostate: &MA, )
tune_with_options(..., &TuneOptions::default())impl<L> StructuralPartialEq for Sweep<L>
Auto Trait Implementations§
impl<L> Freeze for Sweep<L>where
L: Freeze,
impl<L> RefUnwindSafe for Sweep<L>where
L: RefUnwindSafe,
impl<L> Send for Sweep<L>where
L: Send,
impl<L> Sync for Sweep<L>where
L: Sync,
impl<L> Unpin for Sweep<L>where
L: Unpin,
impl<L> UnwindSafe for Sweep<L>where
L: 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
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>
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>
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