pub trait SiteEnergy<S> {
// Required method
fn site_energy(&self, site_properties: &S) -> f64;
// Provided methods
fn site_energy_initial(&self, site_properties: &S) -> f64 { ... }
fn is_only_infinite_or_zero() -> bool { ... }
}Expand description
Compute the energy contribution of a single site.
The SiteEnergy trait describes a type that can compute the energy contribution
of a site to the system’s total energy as a function only of that site’s
properties.
The external module provides a number of commonly used implementations.
Combine them with External newtype for use with MC and MD simulations or to
compute system-wide properties.
The generic type names are:
S: TheSite::propertiestype.
§Examples
Implement a custom site energy function:
use hoomd_interaction::{External, SiteEnergy, TotalEnergy};
use hoomd_microstate::{
Body, Microstate,
property::{Point, Position},
};
use hoomd_vector::Cartesian;
struct Custom {
a: f64,
b: f64,
}
impl<S> SiteEnergy<S> for Custom
where
S: Position<Position = Cartesian<2>>,
{
fn site_energy(&self, site_properties: &S) -> f64 {
self.a * (site_properties.position()[0] / self.b).cos()
}
}
let mut microstate = Microstate::new();
microstate.extend_bodies([
Body::point(Cartesian::from([1.0, 0.0])),
Body::point(Cartesian::from([-1.0, 2.0])),
])?;
let custom = Custom { a: 1.0, b: 10.0 };
let site_energy = custom.site_energy(µstate.sites()[0].properties);
let custom = External(custom);
let total_energy = custom.total_energy(µstate);Custom method that checks for overlaps of a disk with a circular boundary.
use hoomd_interaction::{External, SiteEnergy, TotalEnergy};
use hoomd_microstate::{
Body, Microstate,
property::{Point, Position},
};
use hoomd_vector::{Cartesian, Metric};
struct Custom {
r: f64,
}
impl<S> SiteEnergy<S> for Custom
where
S: Position<Position = Cartesian<2>>,
{
fn site_energy(&self, site_properties: &S) -> f64 {
if site_properties.position().distance(&Cartesian::default())
> self.r - 0.5
{
f64::INFINITY
} else {
0.0
}
}
fn is_only_infinite_or_zero() -> bool {
true
}
}
let mut microstate = Microstate::new();
microstate.extend_bodies([Body::point(Cartesian::from([9.6, 0.0]))])?;
let custom = Custom { r: 10.0 };
let site_energy = custom.site_energy(µstate.sites()[0].properties);
assert_eq!(site_energy, f64::INFINITY);
let custom = External(custom);
let total_energy = custom.total_energy(µstate);
assert_eq!(total_energy, f64::INFINITY);Required Methods§
Sourcefn site_energy(&self, site_properties: &S) -> f64
fn site_energy(&self, site_properties: &S) -> f64
Evaluate the energy contribution of a single site.
Provided Methods§
Sourcefn site_energy_initial(&self, site_properties: &S) -> f64
fn site_energy_initial(&self, site_properties: &S) -> f64
Evaluate the energy contribution of a single site in the initial state.
Override this method in potentials that have both infinite or zero
terms and finite terms, such as the sum of a hard site-wall interaction
plus an attractive well. site_energy should compute both terms and
site_energy_initial should compute only the finite terms.
External calls site_energy_initial when evaluating the energy of
the initial state in a trial move. The infinite interaction term can be
assumed 0 in the initial state because no site will ever be placed in an
infinite energy configuration.
Sourcefn is_only_infinite_or_zero() -> bool
fn is_only_infinite_or_zero() -> bool
Does this potential only ever return infinity or zero?
Override this method and return true for e.g. hard site-wall
interactions that always return infinity or zero and never any other
value. When this method returns true, External skips the initial
energy computation and assumes it is zero.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.