Skip to content

Commit

Permalink
bugfixes for #113, 112, 109
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Ortner committed Sep 3, 2024
1 parent 202ff91 commit 70e7dfa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/AtomsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using UnitfulAtomic
using StaticArrays
using Requires

export Atom, FlexibleSystem, FastSystem
export Atom, FlexibleSystem, FastSystem, AbstractSystem

# Main Interface specification and inline docs
include("interface.jl")
Expand Down
7 changes: 6 additions & 1 deletion src/utils/chemspecies.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ end

Base.Broadcast.broadcastable(s::ChemicalSpecies) = Ref(s)

ChemicalSpecies(z::Integer) = ChemicalSpecies(z, 0, 0)
# better to convert z -> symbol to catch special cases such as D; e.g.
# Should ChemicalSpecies(z) == ChemicalSpecies(z,z,0)? For H this is false.
ChemicalSpecies(z::Integer) = ChemicalSpecies(_chem_el_info[z].symbol)

ChemicalSpecies(sym::ChemicalSpecies) = sym

==(a::ChemicalSpecies, sym::Symbol) =
Expand Down Expand Up @@ -135,6 +138,8 @@ end
# UInt* is not readable
atomic_number(element::ChemicalSpecies) = element.atomic_number

atomic_number(z::Integer) = z

atomic_symbol(element::ChemicalSpecies) = element

Base.convert(::Type{Symbol}, element::ChemicalSpecies) = Symbol(element)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const GROUP_COVERAGE = !isempty(get(ENV, "GROUP_COVERAGE", ""))
if GROUP == "Core"
@testset "AtomsBase.jl" begin
include("interface.jl")
include("species.jl")
include("atom.jl")
include("fast_system.jl")
include("properties.jl")
Expand Down
23 changes: 23 additions & 0 deletions test/species.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

using AtomsBase
using Unitful
using UnitfulAtomic
using Test

##

@testset "ChemicalSpecies" begin

symbols = [:H, :He, :Li, :Be, :B, :C, :N, :O, :F, :Ne]
nneut = collect(1:10); nneut[1] = 0; nneut[4] = 5; nneut[8] = 7;
for z = 1:10
@test ChemicalSpecies(symbols[z]) == ChemicalSpecies(z) == ChemicalSpecies(z, nneut[z], 0)
end

@test ChemicalSpecies(:D) == ChemicalSpecies(1, 1, 0)
@test ChemicalSpecies(:C13) == ChemicalSpecies(6, 7, 0)

@test atomic_number( UInt(8) ) == 8
@test atomic_number( Int16(12) ) == 12

end

0 comments on commit 70e7dfa

Please sign in to comment.