[−]Trait lumol::GlobalPotential
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:
- Potentials that does not fit the pair/bond/angle/dihedral framework for potentials: the coulombic potential solver is the more important example;
- External potentials like an external electric field or a hard wall;
- Potentials coming from external software: DFT computations, metadynamic drivers, or other.
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
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
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
.