fn calculate_distance(geometry: &Geometry, atom1: usize, atom2: usize) -> f64Expand description
Calculates the Euclidean distance between two atoms in a molecular geometry.
This function computes the bond length between two specified atoms using the standard Euclidean distance formula in 3D Cartesian coordinates. It’s a fundamental operation in molecular geometry analysis.
§Mathematical Formula
The distance between atoms i and j is:
d_ij = √[(x_j - x_i)² + (y_j - y_i)² + (z_j - z_i)²]where (x_i, y_i, z_i) and (x_j, y_j, z_j) are the Cartesian coordinates of atoms i and j, respectively.
§Arguments
geometry- The molecular geometry containing atomic coordinatesatom1- Index of the first atom (0-based)atom2- Index of the second atom (0-based)
§Returns
Distance between the two atoms in the same units as the input coordinates (typically Angstroms).
§Applications
- Bond length analysis: Measure actual bond distances
- Constraint evaluation: Check if bond constraints are satisfied
- Geometry validation: Ensure reasonable molecular structure
- Force calculations: Compute bond-based constraint forces
§Typical Bond Lengths (for reference)
- C-H: ~1.1 Angstrom
- C-C: ~1.5 Angstrom (single), ~1.3 Angstrom (double), ~1.2 Angstrom (triple)
- C-O: ~1.4 Angstrom (single), ~1.2 Angstrom (double)
- O-H: ~1.0 Angstrom
- N-H: ~1.0 Angstrom
§Examples
// Calculate C-H bond length
let ch_distance = calculate_distance(&geometry, 0, 1);
println!("C-H bond length: {:.3} Angstrom", ch_distance);
// Check if bond is within reasonable range
if ch_distance > 2.0 {
println!("Warning: Unusually long C-H bond!");
}