Skip to main content

castep_cell_io/param/geometry_optimization/
geom_spin_fix.rs

1use castep_cell_fmt::{Cell, CellValue, ToCell, ToCellValue};
2use castep_cell_fmt::parse::{FromCellValue, FromKeyValue};
3use castep_cell_fmt::{CResult, Error};
4use castep_cell_fmt::query::value_as_i32;
5use serde::{Deserialize, Serialize};
6
7/// Determines the number of geometry optimization steps for which the total spin is fixed.
8///
9/// Keyword type: Integer
10///
11/// Default: 0 (spin is allowed to vary)
12///
13/// Example:
14/// GEOM_SPIN_FIX : 5
15#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
16#[serde(rename = "GEOM_SPIN_FIX")]
17pub struct GeomSpinFix(pub i32); // Using i32 to allow negative values
18
19impl FromCellValue for GeomSpinFix {
20    fn from_cell_value(value: &CellValue<'_>) -> CResult<Self> {
21        Ok(Self(value_as_i32(value)?))
22    }
23}
24
25impl FromKeyValue for GeomSpinFix {
26    const KEY_NAME: &'static str = "GEOM_SPIN_FIX";
27
28    fn from_cell_value_kv(value: &CellValue<'_>) -> CResult<Self> {
29        Self::from_cell_value(value)
30    }
31}
32
33impl ToCell for GeomSpinFix {
34    fn to_cell(&self) -> Cell<'_> {
35        Cell::KeyValue("GEOM_SPIN_FIX", CellValue::Int(self.0))
36    }
37}
38
39impl ToCellValue for GeomSpinFix {
40    fn to_cell_value(&self) -> CellValue<'_> {
41        CellValue::Int(self.0)
42    }
43}
44
45