Skip to main content
← OpenMECP Documentation

parse_cosine_mode

Function parse_cosine_mode 

Source
pub fn parse_cosine_mode(s: &str) -> CosineCheckMode
Expand description

Performs a hybrid GEDIIS optimization step (50% GDIIS + 50% GEDIIS).

DEPRECATED: Use sequential_hybrid_gediis_step instead for production use. This function is kept for backward compatibility and testing.

This function implements a simple fixed 50/50 blend of GDIIS and GEDIIS. The smart hybrid version is significantly more robust.

§Arguments

  • opt_state - Optimization state with history
  • config - Configuration with step size limits

§Returns

Returns the new geometry coordinates after hybrid GEDIIS step. pub fn hybrid_gediis_step(opt_state: &OptimizationState, config: &Config) -> DVector { // Compute both GDIIS and GEDIIS results let gdiis_result = gdiis_step(opt_state, config); let gediis_result = gediis_step(opt_state, config);

// Apply 50/50 averaging  behavior)
let n = gdiis_result.len();
let mut hybrid_result = DVector::zeros(n);
for i in 0..n {
    hybrid_result[i] = 0.5 * gdiis_result[i] + 0.5 * gediis_result[i];
}

// step reduction for hybrid final step
let last_grad_norm = opt_state.grad_history.back().unwrap().norm();
if last_grad_norm < config.thresholds.rms_grad * 10.0 {
    let last_geom = opt_state.geom_history.back().unwrap().clone();
    let mut hybrid_step = &hybrid_result - &last_geom;
    hybrid_step *= config.reduced_factor;
    hybrid_result = last_geom + hybrid_step;
}

let last_geom = opt_state.geom_history.back().unwrap().clone();
let hybrid_final_step = &hybrid_result - &last_geom;
let hybrid_final_norm = hybrid_final_step.norm();

if hybrid_final_norm > config.max_step_size {
    let scale = config.max_step_size / hybrid_final_norm;
    println!(
        "Hybrid final stepsize: {:.10} is reduced to max_size {:.3}",
        hybrid_final_norm, config.max_step_size
    );
    hybrid_result = last_geom + &hybrid_final_step * scale;
} else {
    println!(
        "Hybrid final stepsize: {:.10} is within max_size {:.3} (no reduction)",
        hybrid_final_norm, config.max_step_size
    );
}
hybrid_result

} Converts config string to CosineCheckMode.

Maps user-friendly string values to the corresponding enum variant.

§Arguments

  • s - Configuration string (case-insensitive)

§Returns

The corresponding CosineCheckMode variant.