castep_param_io/param/electro_min/
efermi_tol.rs

1use std::fmt::Display;
2
3use castep_param_derive::KeywordDisplay;
4use derive_builder::Builder;
5use serde::{Deserialize, Serialize};
6
7use crate::param::EnergyUnit;
8
9use super::elec_eigenvalue_tol::ElecEigenvalueTol;
10
11#[derive(
12    Debug,
13    Clone,
14    Copy,
15    Deserialize,
16    Serialize,
17    PartialEq,
18    PartialOrd,
19    Default,
20    Builder,
21    KeywordDisplay,
22)]
23#[builder(setter(into), default)]
24#[keyword_display(field = "EFERMI_TOL", direct_display = false)]
25/// This keyword controls the tolerance for accepting convergence of the
26/// Fermi-energy if the system is being treated as a metal.
27/// #Note
28/// This parameter is used only if FIX_OCCUPANCY : FALSE.
29/// # Default
30/// `0.1 × ELEC_EIGENVALUE_TOL`
31/// # Example
32/// `EFERMI_TOL : 0.0000007 eV`
33pub struct EFermiTol {
34    pub tol: f64,
35    pub unit: Option<EnergyUnit>,
36}
37
38impl EFermiTol {
39    pub fn default_value(elec_eigenvalue_tol: ElecEigenvalueTol) -> Self {
40        Self {
41            tol: 0.1 * elec_eigenvalue_tol.tol,
42            unit: elec_eigenvalue_tol.unit,
43        }
44    }
45}
46
47impl Display for EFermiTol {
48    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49        write!(
50            f,
51            "{:20.15} {}",
52            self.tol,
53            self.unit.map(|v| v.to_string()).unwrap_or_default()
54        )
55    }
56}