Skip to content

Commit

Permalink
Fix printing of spin configurations (#108)
Browse files Browse the repository at this point in the history
* Fix printing of vectors of spin configurations

* Bump version
  • Loading branch information
jagot authored Sep 12, 2022
1 parent 0bb57c1 commit b38386f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion 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.7"
version = "0.1.8"

[deps]
BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0"
Expand Down
20 changes: 10 additions & 10 deletions src/configurations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1182,36 +1182,36 @@ macro rsc_str(conf_str, suffix="")
parse(SpinConfiguration{SpinOrbital{RelativisticOrbital}}, conf_str, sorted=suffix=="s")
end

function Base.show(io::IO, c::SpinConfiguration)
function Base.show(io::IO, c::SpinConfiguration{O}) where {O<:SpinOrbital}
ascii = get(io, :ascii, false)
nc = length(c)
if nc == 0
write(io, ascii ? "empty" : "")
return
end

orbitals = Dict{Orbital, Vector{<:SpinOrbital}}()
core_orbitals = sort(unique(map(o -> o.orb, core(c).orbitals)))
core_cfg = Configuration(core_orbitals, ones(Int, length(core_orbitals))) |> fill |> close
core_orbitals = sort(unique(map(o -> o.orb, orbitals(core(c)))))

if !isempty(core_cfg)
if !isempty(core_orbitals)
core_cfg = Configuration(core_orbitals, ones(Int, length(core_orbitals))) |> fill |> close
show(io, core_cfg)
write(io, " ")
end
# if !c.sorted
# In the unsorted case, we do not yet contract subshells for
# printing; to be implemented.
so = string.(peel(c).orbitals)
so = string.(orbitals(peel(c)))
write(io, join(so, " "))
return
# end
# for orb in peel(c).orbitals
# orbitals[orb.orb] = push!(get(orbitals, orb.orb, SpinOrbital[]), orb)
# os = Dict{Orbital, Vector{O}}()
# for orb in orbitals(peel(c))
# os[orb.orb] = push!(get(os, orb.orb, SpinOrbital[]), orb)
# end
# map(sort(collect(keys(orbitals)))) do orb
# map(sort(collect(keys(os)))) do orb
# ℓ = orb.ℓ
# g = degeneracy(orb)
# sub_shell = orbitals[orb]
# sub_shell = os[orb]
# if length(sub_shell) == g
# format("{1:s}{2:s}", orb, to_superscript(g))
# else
Expand Down
14 changes: 14 additions & 0 deletions test/configurations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@
c"" => ""]) do (c,s)
@test "$(c)" == s
end

# Test pretty-printing of vectors of spin-configurations; if
# there is a mix of integer and symbolic principal quantum
# numbers, the underlying orbital type of the SpinOrbital
# becomes a UnionAll, which complicates printing of the core
# configuration (if any).
@test string.([sc"1s₀α"]) == ["1s₀α"]
@test string.([sc"1s₀α 1s₀β"]) == ["1s₀α 1s₀β"]
@test string.([sc"1s₀α ks₀β"]) == ["1s₀α ks₀β"]
@test string.([sc"[He]c 2s₀α 2s₀β", sc"[He]c ks₀α ks₀β"]) == ["[He]ᶜ 2s₀α 2s₀β", "[He]ᶜ ks₀α ks₀β"]
@test string.([rsc"[He]c 2s(1/2) 2s(-1/2)", sc"[He]c ks₀α ks₀β"]) == ["[He]ᶜ 2s(1/2) 2s(-1/2)", "[He]ᶜ ks₀α ks₀β"]
@test string.([rsc"[He]c 2s(1/2) 2s(-1/2)", rsc"[He]c ks(1/2) ks(-1/2)"]) == ["[He]ᶜ 2s(1/2) 2s(-1/2)", "[He]ᶜ ks(1/2) ks(-1/2)"]
@test string.([sc"2s₀α 2s₀β", sc"ks₀α ks₀β"]) == ["2s₀α 2s₀β", "ks₀α ks₀β"]
@test string.([rsc"2s(1/2) 2s(-1/2)", rsc"ks(1/2) ks(-1/2)"]) == ["2s(1/2) 2s(-1/2)", "ks(1/2) ks(-1/2)"]
end

@testset "Orbital substitutions" begin
Expand Down

2 comments on commit b38386f

@jagot
Copy link
Member Author

@jagot jagot commented on b38386f Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/68159

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.8 -m "<description of version>" b38386fec7bd3fd5d475eb9e744f77ece28e8be7
git push origin v0.1.8

Please sign in to comment.