Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order spin orbitals; parse symbolic principal quantum numbers from string #116

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AtomicLevels"
uuid = "10933b4c-d60f-11e8-1fc6-bd9035a249a1"
authors = ["Stefanos Carlström <[email protected]>"]
version = "0.1.11"
version = "0.1.12"

[deps]
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
Expand All @@ -15,7 +15,7 @@ UnicodeFun = "1cfade01-22cf-5700-b092-accc4b62d6e1"
WignerSymbols = "9f57e263-0b3d-5e2e-b1be-24f2bb48858b"

[compat]
BlockArrays = "1"
BlockArrays = "0.16,1"
BlockBandedMatrices = "0.8, 0.9, 0.10, 0.11, 0.12, 0.13"
Combinatorics = "1"
FillArrays = "1"
Expand Down
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
15 changes: 12 additions & 3 deletions src/spin_orbitals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ end

degeneracy(::SpinOrbital) = 1

# We cannot order spin-orbitals of differing orbital types
Base.isless(a::SpinOrbital{O,M}, b::SpinOrbital{O,N}) where {O<:AbstractOrbital,M,N} = false

function Base.isless(a::SpinOrbital{<:O,M}, b::SpinOrbital{<:O,M}) where {O,M}
a.orb < b.orb && return true
a.orb > b.orb && return false
Expand All @@ -86,6 +83,18 @@ function Base.isless(a::SpinOrbital{<:O,M}, b::SpinOrbital{<:O,M}) where {O,M}
return false
end

function Base.isless(a::SpinOrbital{O,M}, b::SpinOrbital{O,M}) where {O,M}
a.orb < b.orb && return true
a.orb > b.orb && return false

for (ma,mb) in zip(a.m,b.m)
ma < mb && return true
ma > mb && return false
end
# All projections were equal
return false
end

function Base.isless(a::SpinOrbital{<:Orbital}, b::SpinOrbital{<:Orbital})
a.orb < b.orb && return true
a.orb > b.orb && return false
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
Loading