pub trait Potential2<T: Vector> {
// Required methods
fn energy(&self, r_sq: T) -> T;
fn force_factor(&self, r_sq: T) -> T;
// Provided method
fn energy_force(&self, r_sq: T) -> (T, T) { ... }
}Expand description
Two-body potential energy function.
Used for both non-bonded pair interactions (LJ, Coulomb) and bonded stretch interactions (harmonic, Morse).
§Input Convention
All methods accept r_sq (squared distance) rather than r to avoid
unnecessary square root operations in the common case.
§Force Factor Convention
The force_factor method returns:
S = -(dV/dr) / r = -dV/d(r^2) * 2To obtain the force vector from particle j to particle i:
F_ij = S * r_ij_vecwhere r_ij_vec = r_i - r_j (vector from j to i).
Required Methods§
Sourcefn force_factor(&self, r_sq: T) -> T
fn force_factor(&self, r_sq: T) -> T
Provided Methods§
Sourcefn energy_force(&self, r_sq: T) -> (T, T)
fn energy_force(&self, r_sq: T) -> (T, T)
Computes both energy and force factor simultaneously.
Default implementation calls both methods separately. Override for potentials with shared subexpressions.
§Returns
Tuple of (energy, force_factor)