[]Trait lumol::energy::Computation

pub trait Computation: Send + Sync {
    fn compute_energy(&self, r: f64) -> f64;
fn compute_force(&self, r: f64) -> f64; }

Alternative energy and forces computation.

The Computation trait represent an alternative way to compute a given potential. For example using interpolation on a table or on a grid, from a Fourier decomposition, etc.


use lumol_core::energy::Computation;
use lumol_core::energy::Harmonic;

/// This is just a thin wrapper logging every time the `energy/force`
/// methods are called.
struct LoggingComputation<T: Potential>(T);

impl<T: Potential> Computation for LoggingComputation<T> {
    fn compute_energy(&self, r: f64) -> f64 {
        println!("Called energy");

    fn compute_force(&self, r: f64) -> f64 {
        println!("Called force");

let potential = Harmonic{x0: 0.5, k: 4.2};
let computation = LoggingComputation(potential.clone());

assert_eq!(computation.energy(1.0), potential.energy(1.0));
assert_eq!(computation.force(2.0), potential.force(2.0));

Required methods

fn compute_energy(&self, r: f64) -> f64

Compute the energy value at r

fn compute_force(&self, r: f64) -> f64

Compute the force value at r

Loading content...


impl Computation for TableComputation

Loading content...