[]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:


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.
struct ShiftAll {
    delta: f64,

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

    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

// 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 {

    fn update(&self) {

// A simple test
let mut system = System::with_cell(UnitCell::cubic(10.0));

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

fn cutoff(&self) -> Option<f64>

Return the cut off radius.

fn energy(&self, configuration: &Configuration) -> f64

Compute the energetic contribution of this potential

fn forces(&self, configuration: &Configuration, forces: &mut [Vector3D])

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

fn atomic_virial(&self, configuration: &Configuration) -> Matrix3

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

Loading content...

Provided methods

fn molecular_virial(&self, configuration: &Configuration) -> Matrix3

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

Loading content...


impl GlobalPotential for SharedEwald

impl GlobalPotential for Wolf

Loading content...