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

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);

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);

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);

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);

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);

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

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);

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);

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));

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);

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for PairInteraction

impl Sync for PairInteraction

Blanket Implementations

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

Creates owned data from borrowed data, usually by cloning. Read more

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

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T> From for T
[src]

Performs the conversion.

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

Performs the conversion.

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

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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

Important traits for &'a mut R

Immutably borrows from an owned value. Read more

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

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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

Important traits for &'a mut R

Mutably borrows from an owned value. Read more

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

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

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more