From 5c5a287034bf8e7d5d701fd5235990380c586800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefanos=20Carlstr=C3=B6m?= Date: Wed, 24 Mar 2021 08:55:00 +0100 Subject: [PATCH] Support Unicode occupations/states when parsing configurations (#36, #73) --- src/configurations.jl | 16 ++++++++++++---- test/configurations.jl | 10 ++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/configurations.jl b/src/configurations.jl index 4d7ed1a..8f45cb4 100644 --- a/src/configurations.jl +++ b/src/configurations.jl @@ -319,9 +319,9 @@ function get_noble_core_name(config::Configuration{O}) where O end function state_sym(state::AbstractString) - if state == "c" + if state == "c" || state == "ᶜ" :closed - elseif state == "i" + elseif state == "i" || state == "ⁱ" :inactive else :open @@ -339,13 +339,21 @@ end function parse_orbital_occupation(::Type{O}, orb_str) where {O<:AbstractOrbital} m = match(r"^(([0-9]+|.)([a-z]|\[[0-9]+\])[-]{0,1})([0-9]*)([*ci]{0,1})$", orb_str) - parse(O, m[1]) , (m[4] == "") ? 1 : parse(Int, m[4]), state_sym(m[5]) + m2 = match(r"^(([0-9]+|.)([a-z]|\[[0-9]+\])[-]{0,1})([¹²³⁴⁵⁶⁷⁸⁹⁰]*)([ᶜⁱ]{0,1})$", orb_str) + orb,occ,state = if !isnothing(m) + m[1], m[4], m[5] + elseif !isnothing(m2) + m2[1], from_superscript(m2[4]), m2[5] + else + throw(ArgumentError("Unknown subshell specification $(orb_str)")) + end + parse(O, orb) , (occ == "") ? 1 : parse(Int, occ), state_sym(state) end function Base.parse(::Type{Configuration{O}}, conf_str; sorted=false) where {O<:AbstractOrbital} isempty(conf_str) && return Configuration{O}(sorted=sorted) orbs = split(conf_str, r"[\. ]") - core_m = match(r"\[([a-zA-Z]+)\]([*ci]{0,1})", first(orbs)) + core_m = match(r"\[([a-zA-Z]+)\]([*ciᶜⁱ]{0,1})", first(orbs)) if !isnothing(core_m) core_config = core_configuration(O, core_m[1], core_m[2], sorted) if length(orbs) > 1 diff --git a/test/configurations.jl b/test/configurations.jl index 7cfb853..2e5bac1 100644 --- a/test/configurations.jl +++ b/test/configurations.jl @@ -42,6 +42,16 @@ @test_throws ArgumentError parse(Configuration{RelativisticOrbital}, "1s3") @test_throws ArgumentError parse(Configuration{Orbital}, "1s2 2p-2") + @testset "Unicode occupations/states" begin + for c in [c"1s2 2p6", c"[He]c 2p6", c"[He]i 2p6", c"1s 3d4", c"[Xe]*"] + @test parse(Configuration{Orbital}, string(c)) == c + end + + for c in [rc"1s2 2p6", rc"1s 2p- 2p3", rc"[He]c 2p6", rc"[He]i 2p6", rc"1s 3d4", rc"[Xe]*"] + @test parse(Configuration{RelativisticOrbital}, string(c)) == c + end + end + @testset "Spin-configurations" begin a = sc"" @test a isa SpinConfiguration{<:SpinOrbital{<:Orbital}}