[]Trait lumol::energy::GlobalPotential

pub trait GlobalPotential: GlobalCache + BoxCloneGlobal + Send + Sync {
    fn cutoff(&self) -> Option<f64>;
fn energy(&self, configuration: &Configuration) -> f64;
fn forces(&self, configuration: &Configuration, forces: &mut [Vector3D]);
fn atomic_virial(&self, configuration: &Configuration) -> Matrix3; fn molecular_virial(&self, configuration: &Configuration) -> Matrix3 { ... } }

A potential acting on the whole System at once.

This kind of potential is passed all the data in a system and returns the energy/forces/virial contribution for this potential. It has three main usages:

Examples

use lumol_core::energy::{GlobalPotential, GlobalCache};
use lumol_core::types::{Vector3D, Matrix3};
use lumol_core::sys::{System, Configuration, Particle, Molecule, UnitCell};

/// 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: &Configuration, forces: &mut [Vector3D]) {
        // this potential does not changes the forces
    }

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

// Not implementing `GlobalCache` means that we will not be able to use
// `ShiftAll` in Monte Carlo simulations.
impl GlobalCache for ShiftAll {
    fn move_molecule_cost(&self, _: &Configuration, _: usize, _: &[Vector3D]) -> f64 {
        unimplemented!()
    }

    fn update(&self) {
        unimplemented!()
    }
}

// A simple test
let mut system = System::with_cell(UnitCell::cubic(10.0));
system.add_molecule(Molecule::new(Particle::new("Ar")));
system.add_molecule(Molecule::new(Particle::new("Ar")));

system.add_global_potential(Box::new(ShiftAll{delta: 1.0}));

assert_eq!(system.potential_energy(), 2.0);
assert_eq!(system.forces(), vec![Vector3D::zero(); 2]);
assert_eq!(system.virial(), Matrix3::zero());

Required Methods

Return the cut off radius.

Compute the energetic contribution of this potential

Compute the force contribution of this potential. This function should return a vector containing the force acting on each particle in the configuration.

Compute the total virial contribution of this potential, using the atomic virial definition

Provided Methods

Compute the total virial contribution of this potential, using the molecular virial definition. This default to atomic_virial.

Implementors

impl GlobalPotential for SharedEwald

impl GlobalPotential for Wolf