Skip to content

Commit

Permalink
Several Minor Bugfixes (#114)
Browse files Browse the repository at this point in the history
* bugfixes for #113, 112, 109

* some io checks for ChemicalSpecies

* fixing default neutron number

* add atomic_number(::Symbol)

* bump v0.4.1

---------

Co-authored-by: Christoph Ortner <[email protected]>
  • Loading branch information
cortner and Christoph Ortner committed Sep 9, 2024
1 parent 202ff91 commit 16c52c1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AtomsBase"
uuid = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
authors = ["JuliaMolSim community"]
version = "0.4"
version = "0.4.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
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
11 changes: 9 additions & 2 deletions 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 @@ -79,7 +82,7 @@ for z in 1:length(_chem_el_info)
end

function _nneut_default(z::Integer)
nplusp = floor(Int, ustrip(u"u", _chem_el_info[z].atomic_mass))
nplusp = round(Int, ustrip(u"u", _chem_el_info[z].atomic_mass))
return nplusp - z
end

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

atomic_number(z::Integer) = z

atomic_number(s::Symbol) = _sym2z[s]

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
33 changes: 33 additions & 0 deletions test/species.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

using AtomsBase
using Unitful
using UnitfulAtomic
using Test

##

@testset "ChemicalSpecies" begin

symbols = [:H, :He, :Li, :Be, :B, :C, :N, :O, :F, :Ne,
:Na, :Mg, :Al, :Si, :P, :S, :Cl, :Ar, :K, :Ca]

# https://thechemicalelements.com/protons-neutrons-electrons-of-elements/
n_neut = [0, 2, 4, 5, 6, 6, 7, 8, 10, 10,
12, 12, 14, 14, 16, 16, 18, 22, 20, 20]

for z = 1:10
@test ChemicalSpecies(symbols[z]) == ChemicalSpecies(z) == ChemicalSpecies(z, n_neut[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

@test "$(ChemicalSpecies(:O))" == "$(ChemicalSpecies(8))" == "O"
@test "$(ChemicalSpecies(8, 8, 0))" == "O"
@test "$(ChemicalSpecies(:C; n_neutrons=6))" == "C"
@test "$(ChemicalSpecies(:C; n_neutrons=7))" == "C13"

end

0 comments on commit 16c52c1

Please sign in to comment.