castep_param_io/param/units/
length_unit.rs

1use std::fmt::Display;
2
3use serde::{Deserialize, Serialize};
4
5use crate::param::KeywordDisplay;
6
7#[derive(
8    Debug, Clone, Copy, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Default,
9)]
10/// This keyword specifies the units in which lengths will be reported.
11/// # Example
12/// `LENGTH_UNIT : bohr`
13pub enum LengthUnit {
14    Bohr,
15    BohrA0,
16    Meter,
17    Centimeter,
18    Nanometer,
19    #[default]
20    Ang,
21}
22
23impl Display for LengthUnit {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        match self {
26            LengthUnit::Bohr => f.write_str("bohr"),
27            LengthUnit::BohrA0 => f.write_str("a0"),
28            LengthUnit::Meter => f.write_str("m"),
29            LengthUnit::Centimeter => f.write_str("cm"),
30            LengthUnit::Nanometer => f.write_str("nm"),
31            LengthUnit::Ang => f.write_str("ang"),
32        }
33    }
34}
35
36impl KeywordDisplay for LengthUnit {
37    fn field(&self) -> String {
38        "LENGTH_UNIT".to_string()
39    }
40}