Skip to content

Commit

Permalink
fix: handle missing when missing isotopes
Browse files Browse the repository at this point in the history
using function instead of dot notation
  • Loading branch information
Beforerr committed Nov 24, 2024
1 parent 48900da commit 8e9e98f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/properties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const synonym_properties = Dict(
:ele => :element
)

symbol(e) = getfield(e, :symbol)

"""Retrieve the mass of an element isotope."""
function mass(isotopes::Isotopes, mass_number)
for iso in isotopes
Expand All @@ -21,7 +23,14 @@ function mass(isotopes::Isotopes, mass_number)
end

mass(element::ChemElem, mass_number) = mass(element.isotopes, mass_number)
mass(atomic_number::Integer, mass_number) = mass(isotopes_data[atomic_number], mass_number)
function mass(atomic_number::Integer, mass_number)
isotopes = isotopes_data[atomic_number]
if !ismissing(isotopes)
return mass(isotopes, mass_number)
else
return elements[atomic_number].atomic_mass
end
end


# Basic properties
Expand Down Expand Up @@ -74,9 +83,9 @@ mass_number(::Nothing) = nothing
element(::AbstractParticle) = nothing

function element(p::Particle)
@match p.symbol begin
@match symbol(p) begin
:p => return elements[:H]
_ => return elements[p.symbol]
_ => return elements[symbol(p)]
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Fe-54³⁺
function Particle(p::AbstractParticle; mass_numb=nothing, z=nothing)
mass_number = something(mass_numb, p.mass_number)
charge_number = something(z, p.charge_number)
Particle(p.symbol, charge_number, mass_number)
Particle(symbol(p), charge_number, mass_number)
end

"""
Expand Down Expand Up @@ -118,7 +118,7 @@ See also: [`Particle(::AbstractString)`](@ref)
function Particle(atomic_number::Int; mass_numb=nothing, z=0)
element = elements[atomic_number]
mass_number = something(mass_numb, element.mass_number)
Particle(element.symbol, z, mass_number)
Particle(symbol(element), z, mass_number)
end

"""Create a proton"""
Expand Down

0 comments on commit 8e9e98f

Please sign in to comment.