[]Struct lumol::energy::PairInteraction

pub struct PairInteraction { /* fields omitted */ }

A non-bonded interaction between two particle.

This is a thin wrapper around a Box<PairPotential> associated with a pair restriction. It ensure that the potential is computed up to a cutoff distance. An additional shifting of the potential can be used in molecular dynamics, to ensure that the energy is continuous at the cutoff distance.

Methods

impl PairInteraction

pub fn new(
    potential: Box<dyn PairPotential + 'static>,
    cutoff: f64
) -> PairInteraction

Create a new PairInteraction for the given potential and using the given cutoff distance.

Examples

use lumol_core::energy::PairInteraction;
use lumol_core::energy::Harmonic;

let potential = Box::new(Harmonic{x0: 0.5, k: 4.2});
let interaction = PairInteraction::new(potential, 2.0);

assert_eq!(interaction.energy(1.0), 0.525);
// energy at and after the cutoff is zero
assert_eq!(interaction.energy(2.0), 0.0);

pub fn shifted(
    potential: Box<dyn PairPotential + 'static>,
    cutoff: f64
) -> PairInteraction

Create a new PairInteraction with the given cutoff, using shifted computation of the energy.

Examples

use lumol_core::energy::PairInteraction;
use lumol_core::energy::Harmonic;

let potential = Box::new(Harmonic{x0: 0.5, k: 4.2});
let interaction = PairInteraction::shifted(potential, 2.0);

assert_eq!(interaction.energy(1.0), -4.2);

// energy goes smoothly to zero at the cutoff
assert!(interaction.energy(1.999).abs() < 0.01);
// energy after the cutoff is zero
assert_eq!(interaction.energy(2.0), 0.0);

pub fn enable_tail_corrections(&mut self)

Enable the use of tail corrections for energy and virial contribution of this pair interaction.

Examples

use lumol_core::energy::PairInteraction;
use lumol_core::energy::LennardJones;

let potential = Box::new(LennardJones{sigma: 0.5, epsilon: 4.2});
let mut interaction = PairInteraction::new(potential, 2.0);

assert_eq!(interaction.tail_energy(), 0.0);

interaction.enable_tail_corrections();
assert!(interaction.tail_energy() < 0.0);

pub fn restriction(&self) -> PairRestriction

Get the associated pair restriction. The default is to have no pair restriction.

Examples

use lumol_core::energy::PairInteraction;
use lumol_core::energy::{NullPotential, PairRestriction};
let interaction = PairInteraction::new(Box::new(NullPotential), 2.0);

assert_eq!(interaction.restriction(), PairRestriction::None);

pub fn set_restriction(&mut self, restriction: PairRestriction)

Set the pair restriction associated with this interaction.

Examples

use lumol_core::energy::PairInteraction;
use lumol_core::energy::{NullPotential, PairRestriction};
let mut interaction = PairInteraction::new(Box::new(NullPotential), 2.0);

assert_eq!(interaction.restriction(), PairRestriction::None);
interaction.set_restriction(PairRestriction::Exclude12);
assert_eq!(interaction.restriction(), PairRestriction::Exclude12);

pub fn cutoff(&self) -> f64

Return the cutoff radius

Examples

use lumol_core::energy::PairInteraction;
use lumol_core::energy::LennardJones;

let ar = LennardJones{sigma: 3.405, epsilon: 1.0};
let interaction = PairInteraction::new(Box::new(ar), 9.1935);
let rc = interaction.cutoff();
assert_eq!(rc, 2.7f64 * 3.405);

impl PairInteraction

pub fn energy(&self, r: f64) -> f64

Get the energy for this pair interaction at the distance r.

Examples

use lumol_core::energy::PairInteraction;
use lumol_core::energy::Harmonic;

let potential = Box::new(Harmonic{x0: 0.5, k: 4.2});
let interaction = PairInteraction::new(potential, 2.0);

assert_eq!(interaction.energy(1.0), 0.525);
// energy at and after the cutoff is zero
assert_eq!(interaction.energy(2.0), 0.0);

pub fn force(&self, r: f64) -> f64

Get the norm of the force for this pair interaction at the distance r.

Examples

use lumol_core::energy::PairInteraction;
use lumol_core::energy::Harmonic;

let potential = Box::new(Harmonic{x0: 0.5, k: 4.2});
let interaction = PairInteraction::new(potential, 2.0);

assert_eq!(interaction.force(1.0), -2.1);
// force at and after the cutoff is zero
assert_eq!(interaction.force(2.0), 0.0);

pub fn virial(&self, r: &Vector3D) -> Matrix3

Get the virial contribution for this pair interaction at the distance r.

Examples

use lumol_core::energy::PairInteraction;
use lumol_core::energy::Harmonic;

let potential = Box::new(Harmonic{x0: 0.5, k: 4.2});
let interaction = PairInteraction::shifted(potential, 2.0);

let r = Vector3D::new(1.0, 0.0, 0.3);
let force = interaction.force(r.norm()) * r / r.norm();
assert_eq!(interaction.virial(&r), r.tensorial(&force));

pub fn tail_energy(&self) -> f64

Get the tail correction to the energy for this pair interaction

Examples

use lumol_core::energy::PairInteraction;
use lumol_core::energy::LennardJones;

let potential = Box::new(LennardJones{sigma: 0.5, epsilon: 4.2});
let mut interaction = PairInteraction::new(potential, 2.0);
interaction.enable_tail_corrections();

assert_eq!(interaction.tail_energy(), -0.010936609903971353);

pub fn tail_virial(&self) -> Matrix3

Get the tail correction to the virial for this pair interaction

Examples

use lumol_core::energy::PairInteraction;
use lumol_core::energy::LennardJones;

let potential = Box::new(LennardJones{sigma: 0.5, epsilon: 4.2});
let mut interaction = PairInteraction::new(potential, 2.0);
interaction.enable_tail_corrections();

let w = -0.02187143961588542;
let virial = Matrix3::new([
    [w, 0.0, 0.0],
    [0.0, w, 0.0],
    [0.0, 0.0, w],
]);

assert_eq!(interaction.tail_virial(), virial);

Trait Implementations

impl Clone for PairInteraction

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for PairInteraction

impl Sync for PairInteraction

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]