[]Trait lumol::energy::GlobalCache

pub trait GlobalCache {
    fn move_molecule_cost(
        &self,
        configuration: &Configuration,
        molecule_id: usize,
        new_positions: &[Vector3D]
    ) -> f64;
fn update(&self); }

Energetic cache for global potentials.

This trait provide all the functions needed by EnergyCache to compute partial energy updates in Monte Carlo simulations. You can use a panic!ing implementation for all methods if you never need to use a given GlobalPotential in Monte Carlo simulations.

All methods take a non-mutable &self receiver, which means you may want to wrap the implemntation in RwLock or Mutex to allow for inner mutability while still implementing Send + Sync.

Examples

use lumol_core::energy::{GlobalPotential, GlobalCache};
use lumol_core::types::{Vector3D, Matrix3};
use lumol_core::sys::Configuration;

/// Shift the energy of all the particles by a given delta.
#[derive(Clone)]
struct ShiftAll {
    delta: f64,
}

impl GlobalPotential for ShiftAll {
    fn cutoff(&self) -> Option<f64> {
        None
    }

    fn energy(&self, configuration: &Configuration) -> f64 {
        // shift all particles by delta
        self.delta * configuration.size() as f64
    }

    fn forces(&self, _: &Configuration, _: &mut [Vector3D]) {
        // this potential does not changes the forces
    }

    fn atomic_virial(&self, _: &Configuration) -> Matrix3 {
        // the virial is null as all the forces are null
        Matrix3::zero()
    }
}

impl GlobalCache for ShiftAll {
    fn move_molecule_cost(&self, _: &Configuration, _: usize, _: &[Vector3D]) -> f64 {
        // The cost of moving particles is null, because all the particles
        // get the same energy shift whatever there position are.
        return 0.0
    }

    fn update(&self) {
        // We are not storing anything in the ShiftAll struct, so this
        // function is a no-op.
    }
}

Required Methods

Get the cost of moving a rigid molecule in the system.

This function is passed the current configuration, the index of the molecule in the configuration; and the new_positions of the particles. The previous positions of the particles are still in the system.

Update the cache as needed after a call to move_molecule_cost.

If the Monte Carlo move is accepted, this function will be called and should update any cached quantity so that further call to GlobalPotential::energy gives the right value.

Implementors

impl GlobalCache for SharedEwald

impl GlobalCache for Wolf