pub struct Torsion;Expand description
Periodic torsion potential for dihedral angles.
§Physics
Models the rotational barrier around a bond axis using a periodic cosine function.
- Formula: $$ E = \frac{1}{2} V [1 - \cos(n(\phi - \phi_0))] $$
- Derivative Factor (
diff): $$ T = \frac{dE}{d\phi} = \frac{1}{2} V \cdot n \cdot \sin(n(\phi - \phi_0)) $$
§Parameters
v_half: Half barrier height $V_{half} = V/2$.n: Periodicity/multiplicity.cos_n_phi0: $\cos_{n\phi_0}$, pre-computed phase cosine.sin_n_phi0: $\sin_{n\phi_0}$, pre-computed phase sine.
§Pre-computation
Use Torsion::precompute to convert physical constants into optimized parameters:
$(V, n, \phi_0°) \to (V/2, n, \cos_{n\phi_0}, \sin_{n\phi_0})$.
§Inputs
cos_phi: Cosine of the dihedral angle $\cos\phi$.sin_phi: Sine of the dihedral angle $\sin\phi$.
§Implementation Notes
- Uses optimized closed-form formulas for common periodicities ($n = 1, 2, 3$).
- Falls back to Chebyshev recurrence for higher periodicities.
- All intermediate calculations are shared between energy and torque computations.
- Branchless and panic-free.
Implementations§
Source§impl Torsion
impl Torsion
Sourcepub fn precompute<T: Real>(v_barrier: T, n: u8, phi0_deg: T) -> (T, u8, T, T)
pub fn precompute<T: Real>(v_barrier: T, n: u8, phi0_deg: T) -> (T, u8, T, T)
Pre-computes optimized kernel parameters from physical constants.
§Input
v_barrier: Total barrier height $V$.n: Periodicity/multiplicity.phi0_deg: Equilibrium dihedral angle $\phi_0$ in degrees.
§Output
Returns (v_half, n, cos_n_phi0, sin_n_phi0):
v_half: Half barrier height $V/2$.n: Periodicity (passed through).cos_n_phi0: $\cos_{n\phi_0}$, pre-computed phase cosine.sin_n_phi0: $\sin_{n\phi_0}$, pre-computed phase sine.
§Computation
$$ V_{half} = V / 2, \quad n\phi_0 = n \cdot \phi_0 \cdot \pi / 180 $$ $$ \cos_{n\phi_0} = \cos(n\phi_0), \quad \sin_{n\phi_0} = \sin(n\phi_0) $$
Trait Implementations§
Source§impl<T: Real> TorsionKernel<T> for Torsion
impl<T: Real> TorsionKernel<T> for Torsion
Source§fn energy(
cos_phi: T,
sin_phi: T,
(v_half, n, cos_n_phi0, sin_n_phi0): Self::Params,
) -> T
fn energy( cos_phi: T, sin_phi: T, (v_half, n, cos_n_phi0, sin_n_phi0): Self::Params, ) -> T
Computes only the potential energy.
§Formula
$$ E = V_{half} [1 - (\cos(n\phi) \cos_{n\phi_0} + \sin(n\phi) \sin_{n\phi_0})] $$
Source§fn diff(
cos_phi: T,
sin_phi: T,
(v_half, n, cos_n_phi0, sin_n_phi0): Self::Params,
) -> T
fn diff( cos_phi: T, sin_phi: T, (v_half, n, cos_n_phi0, sin_n_phi0): Self::Params, ) -> T
Computes only the torque $T$.
§Formula
$$ T = V_{half} \cdot n \cdot (\sin(n\phi) \cos_{n\phi_0} - \cos(n\phi) \sin_{n\phi_0}) $$
This factor allows computing forces via the chain rule: $$ \vec{F} = -T \cdot \nabla \phi $$
Source§fn compute(
cos_phi: T,
sin_phi: T,
(v_half, n, cos_n_phi0, sin_n_phi0): Self::Params,
) -> EnergyDiff<T>
fn compute( cos_phi: T, sin_phi: T, (v_half, n, cos_n_phi0, sin_n_phi0): Self::Params, ) -> EnergyDiff<T>
Computes both energy and torque efficiently.
This method reuses intermediate calculations to minimize operations.