pub fn add_constraint_lagrange(
geometry: &Geometry,
forces: DVector<f64>,
constraints: &[Constraint],
lambdas: &mut Vec<f64>,
) -> Result<(DVector<f64>, DVector<f64>), ConstraintError>Expand description
Applies constraint forces using the Lagrange multiplier method.
This function implements compatible constraint handling by:
- First step: Diagonal λ initialization: λ = - (c·g)/(c·c)
- Subsequent steps: Reuse previous λ values
- Apply constraint forces: F_new = F_old + C^T * λ
- Return violations for extended gradient optimization
§Arguments
geometry- Current molecular geometryforces- Original forces from QM calculation (negative gradient)constraints- List of geometric constraints to enforcelambdas- Mutable reference to Lagrange multipliers (updated in-place)
§Returns
Returns a tuple of (modified_forces, violations) where:
- modified_forces: Forces with constraint contributions (F + Cᵀλ)
- violations: Current constraint violation values for extended gradient
The constraint equation solved is: C * C^T * λ = -g(x) where C is the Jacobian, λ are the multipliers, and g(x) are violations.
The modified forces are: F_new = F_old + C^T * λ
§Arguments
geometry- Current molecular geometryforces- Original forces from QM calculation (negative gradient)constraints- List of geometric constraints to enforcelambdas- Mutable reference to Lagrange multipliers (updated in-place)