Skip to main content
← OpenMECP Documentation

calculate_path_length

Function calculate_path_length 

Source
pub fn calculate_path_length(geometries: &[Geometry]) -> f64
Expand description

Calculates the total path length along an interpolated reaction coordinate.

This function computes the cumulative Euclidean distance between consecutive geometries in the interpolation path. The path length provides a measure of the total geometric change along the reaction coordinate and can be useful for analyzing reaction paths and comparing different interpolation methods.

§Arguments

  • geometries - A slice of geometries representing the interpolation path

§Returns

Returns the total path length as a f64 value in the same units as the input coordinates (typically Angstroms).

§Algorithm

The path length is calculated as:

L = Σᵢ √(Σⱼ (xᵢ₊₁,ⱼ - xᵢ,ⱼ)²)

where the outer sum is over geometry pairs and the inner sum is over all coordinate components.

§Examples

use omecp::lst::{interpolate_linear, calculate_path_length};
use omecp::geometry::Geometry;

let elements = vec!["H".to_string(), "H".to_string()];
let coords1 = vec![0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
let coords2 = vec![1.0, 0.0, 0.0, 1.0, 0.0, 0.0];

let geom1 = Geometry::new(elements.clone(), coords1);
let geom2 = Geometry::new(elements, coords2);

let path = interpolate_linear(&geom1, &geom2, 1);
let length = calculate_path_length(&path);
// Length should be approximately sqrt(2) ≈ 1.414

§Notes

  • Returns 0.0 for empty or single-geometry paths
  • The path length depends on the coordinate system and units used
  • Longer paths may indicate more significant structural changes
  • Can be used to compare the “smoothness” of different interpolation methods