Skip to content

Commit

Permalink
Also parse symbolic principal quantum numbers from strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jagot committed May 30, 2024
1 parent 16eb445 commit 23fa891
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/orbitals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function parse_orbital_ℓ(m::RegexMatch,i=2)
end

function Base.parse(::Type{<:Orbital}, orb_str)
m = match(r"^([0-9]+|.)([a-z]|\[[0-9]+\])$", orb_str)
m = match(r"^([0-9]+|.|\[.+\])([a-z]|\[[0-9]+\])$", orb_str)
isnothing(m) && throw(ArgumentError("Invalid orbital string: $(orb_str)"))
n = parse_orbital_n(m)
= parse_orbital_ℓ(m)
Expand Down
2 changes: 1 addition & 1 deletion src/relativistic_orbitals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ end
# * Orbital construction from strings

function Base.parse(::Type{<:RelativisticOrbital}, orb_str)
m = match(r"^([0-9]+|.)([a-z]|\[[0-9]+\])([-]{0,1})$", orb_str)
m = match(r"^([0-9]+|.|\[.+\])([a-z]|\[[0-9]+\])([-]{0,1})$", orb_str)
isnothing(m) && throw(ArgumentError("Invalid orbital string: $(orb_str)"))
n = parse_orbital_n(m)
= parse_orbital_ℓ(m)
Expand Down
2 changes: 2 additions & 0 deletions test/orbitals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ using Random
@test parse(Orbital, "1s") == Orbital(1, 0)
@test parse(Orbital{Int}, "1s") == Orbital(1, 0)
@test parse(Orbital{Symbol}, "ks") == Orbital(:k, 0)
@test parse(Orbital, "[abc]s") == Orbital(Symbol("[abc]"), 0)
@test parse(RelativisticOrbital, "[abc]p") == RelativisticOrbital(Symbol("[abc]"), 1, 3/2)

@test ro"1s" == RelativisticOrbital(1, -1) # κ=-1 => s orbital
@test ro"2p-" == RelativisticOrbital(2, 1, half(1))
Expand Down

0 comments on commit 23fa891

Please sign in to comment.