Skip to main content

DeltaEnergyOne

Trait DeltaEnergyOne 

Source
pub trait DeltaEnergyOne<B, S, X, C> {
    // Required method
    fn delta_energy_one(
        &self,
        initial_microstate: &Microstate<B, S, X, C>,
        body_index: usize,
        final_body: &Body<B, S>,
    ) -> f64;
}
Expand description

Compute the change in energy as a function of a single modified body.

Some trial moves apply to a single body at a time and use a Hamiltonian that implements DeltaEnergyOne to efficiently compute the change in energy.

The generic type names are:

See the Implementors section below for examples.

§Derive macro

Use the DeltaEnergyOne derive macro to automatically implement the DeltaEnergyOne trait on a type. The derived implementation sums the result of delta_energy_one over all fields in the struct (in the order in which fields are named in the struct definition). The sum short circuits and returns f64::INFINITY when any one field returns infinity.

use hoomd_interaction::{
    DeltaEnergyOne, External, PairwiseCutoff, external::Linear,
    pairwise::Isotropic, univariate::Boxcar,
};
use hoomd_microstate::{Body, Microstate, property::Point};
use hoomd_vector::Cartesian;

#[derive(DeltaEnergyOne)]
struct Hamiltonian {
    linear: External<Linear<Cartesian<2>>>,
    pairwise_cutoff: PairwiseCutoff<Isotropic<Boxcar>>,
}

let mut microstate = Microstate::new();
microstate.extend_bodies([
    Body::point(Cartesian::from([0.0, 0.0])),
    Body::point(Cartesian::from([1.0, 0.0])),
])?;

let epsilon = 2.0;
let (left, right) = (0.0, 1.5);
let boxcar = Boxcar {
    epsilon,
    left,
    right,
};
let pairwise_cutoff = PairwiseCutoff(Isotropic {
    interaction: boxcar,
    r_cut: right,
});

let linear = External(Linear {
    alpha: 10.0,
    plane_origin: Cartesian::default(),
    plane_normal: [0.0, 1.0].try_into()?,
});

let hamiltonian = Hamiltonian {
    pairwise_cutoff,
    linear,
};

let delta_energy = hamiltonian.delta_energy_one(
    &microstate,
    0,
    &Body::point([-1.0, 0.0].into()),
);
assert_eq!(delta_energy, -2.0);

Required Methods§

Source

fn delta_energy_one( &self, initial_microstate: &Microstate<B, S, X, C>, body_index: usize, final_body: &Body<B, S>, ) -> f64

Compute the change in energy.

initial_microstate describes the initial configuration and final_body describes the new body configuration. In the final configuration, the body may have changed properties and/or sites. The index body_index identifies which body in initial_microstate is changing.

Returns:

\Delta E = E_\mathrm{final} - E_\mathrm{initial}

Implementors§

Source§

impl<B, S, X, C> DeltaEnergyOne<B, S, X, C> for Zero

Source§

impl<P, B, S, X, C, E> DeltaEnergyOne<B, S, X, C> for External<E>
where E: SiteEnergy<S>, B: Transform<S>, S: Position<Position = P>, C: Wrap<B> + Wrap<S>,

Source§

impl<P, B, S, X, C, E> DeltaEnergyOne<B, S, X, C> for PairwiseCutoff<E>
where E: SitePairEnergy<S> + MaximumInteractionRange, B: Transform<S>, S: Position<Position = P>, X: PointsNearBall<P, SiteKey>, C: Wrap<B> + Wrap<S>,