JuliaAtoms / AtomicLevels.jl

https://juliaatoms.org/AtomicLevels.jl
Other
12 stars 3 forks source link

Separate Spin type? #24

Closed jagot closed 3 years ago

jagot commented 5 years ago
struct Spin
    s::Bool
end

Base.show(io::IO, s::Spin) = write(io, s.s ? "α" : "β")

macro spin_str(sstr)
    if sstr in ["up","α"]
        Spin(true)
    elseif sstr == ["down","β"]
        Spin(false)
    else
        throw(ArgumentError("Unknown spin $sstr")
    end
end

Then you could write SpinOrbital(o"2p", 0, spin"up") which reads better than SpinOrbital(o"2p", 0, true).

mortenpi commented 5 years ago

Could one define some Unicode up and down arrows as constants for this?

jagot commented 5 years ago

Yes of course. However, exporting those arrows is maybe not optimal? I tried to see if you could combine an arrow with an s, but no go:

julia> Meta.@lower ↑
:↑

julia> Meta.@lower ↑s
ERROR: syntax: "↑" is not a unary operator

spin"↑" is of course another possibility, but not sure if that reads better than spin"up".

jagot commented 3 years ago

This is no longer relevant since the magnetic quantum numbers are stored as HalfIntegers starting with 1a7af4ec32619d24ec3f33f78d6642d5ca5b4443.