castep_param_io/param/electro_min/
max_cg_steps.rs

1use castep_param_derive::KeywordDisplay;
2use serde::{Deserialize, Serialize};
3
4use super::ElectronicMinimizer;
5
6/// This keyword determines the maximum number of conjugate gradient steps in an SCF cycle.
7/// # Default
8/// The default depends on the value of `ELECTRONIC_MINIMIZER`:
9/// `SD` then `MAX_CG_STEPS` : 0
10/// `CG` then `MAX_CG_STEPS` : 4
11/// `RMM`/`DIIS` then `MAX_CG_STEPS` : 2
12/// If `ELECTRONIC_MINIMIZER` is not defined, the default is 4.
13/// # Example
14/// `MAX_CG_STEPS : 5`
15#[derive(
16    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, KeywordDisplay,
17)]
18#[keyword_display(field="MAX_CG_STEPS", from=u32,value=u32, default_value=4)]
19pub struct MaxCgSteps(u32);
20
21impl MaxCgSteps {
22    pub fn default_value(electronic_minimizer: ElectronicMinimizer) -> Self {
23        match electronic_minimizer {
24            ElectronicMinimizer::SD => Self(0),
25            ElectronicMinimizer::CG => Self(4),
26        }
27    }
28}