use ndarray::{Array1, Array2};
use refeff_core::FEFF_ORBITAL_SLOT_COUNT;
use crate::error::Result;
use super::parse::parse_config_inp;
pub const CONFIG_RECORD_WIDTH: usize = 150;
#[derive(Debug, Clone, PartialEq)]
pub struct ConfigInput {
pub records: Vec<ConfigRecord>,
}
impl ConfigInput {
pub fn parse_str(text: &str) -> Result<Self> {
parse_config_inp(text)
}
#[must_use]
pub fn potential_indices(&self) -> Array1<i32> {
self.records
.iter()
.map(|record| record.potential_index)
.collect()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ConfigRecord {
pub potential_index: i32,
pub element: String,
pub noble_gas: Option<String>,
pub states: Vec<ConfigState>,
}
impl ConfigRecord {
#[must_use]
pub fn occupations(&self) -> Array1<f64> {
self.states
.iter()
.flat_map(|state| {
state
.occupations
.iter()
.map(|occupation| occupation.occupation)
})
.collect()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ConfigSlotRows {
pub occupations: Array1<f64>,
pub valence_occupations: Array1<f64>,
pub spin_occupations: Array1<f64>,
pub electron_count: f64,
}
impl ConfigSlotRows {
#[must_use]
pub fn zeros() -> Self {
Self {
occupations: Array1::zeros(FEFF_ORBITAL_SLOT_COUNT),
valence_occupations: Array1::zeros(FEFF_ORBITAL_SLOT_COUNT),
spin_occupations: Array1::zeros(FEFF_ORBITAL_SLOT_COUNT),
electron_count: 0.0,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ConfigSlotTable {
pub occupations: Array2<f64>,
pub valence_occupations: Array2<f64>,
pub spin_occupations: Array2<f64>,
pub electron_counts: Array1<f64>,
}
impl ConfigSlotTable {
#[must_use]
pub fn zeros(potential_count: usize) -> Self {
Self {
occupations: Array2::zeros((potential_count, FEFF_ORBITAL_SLOT_COUNT)),
valence_occupations: Array2::zeros((potential_count, FEFF_ORBITAL_SLOT_COUNT)),
spin_occupations: Array2::zeros((potential_count, FEFF_ORBITAL_SLOT_COUNT)),
electron_counts: Array1::zeros(potential_count),
}
}
#[must_use]
pub fn potential_count(&self) -> usize {
self.electron_counts.len()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ConfigState {
pub orbital: String,
pub occupations: Vec<ConfigOccupation>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ConfigOccupation {
pub occupation: f64,
pub spin: Option<f64>,
}