Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ACEsuit committed Jul 22, 2024
1 parent 997c761 commit 85d1471
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
26 changes: 18 additions & 8 deletions src/atomsbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ for (sym, name) in _list_of_properties
@eval symbol(::typeof($name)) = $(Meta.quot(sym))
end

atomic_number(atom::PState) = atomic_number(atomic_symbol(atom))

_post(p, a) = a
_post(::typeof(atomic_symbol), sym::Symbol) = ChemicalElement(sym)
_post(::typeof(atomic_symbol), z::Integer) = ChemicalElement(z)
Expand Down Expand Up @@ -72,7 +70,8 @@ Base.length(at::AosSystem) = length(at.particles)
Base.getindex(at::AosSystem, i::Int) = at.particles[i]
Base.getindex(at::AosSystem, inds::AbstractVector) = at.particles[inds]

for (sym, name) in [ _list_of_properties; [(:ignore, :atomic_number) ] ]
# for (sym, name) in [ _list_of_properties; [(:ignore, :atomic_number) ] ]
for (sym, name) in _list_of_properties
@eval $name(sys::AosSystem) = [ $name(x) for x in sys.particles ]
@eval $name(sys::AosSystem, i::Integer) = $name(sys.particles[i])
@eval $name(sys::AosSystem, inds::AbstractVector) = [$name(sys.particles[i]) for i in inds]
Expand Down Expand Up @@ -134,21 +133,32 @@ end
Base.getindex(sys::SoaSystem, inds::AbstractVector{<: Integer}) =
[ sys[i] for i in inds ]


for (sym, name) in [ _list_of_properties; [(:ignore, :atomic_number) ] ]
# for (sym, name) in [ _list_of_properties; [(:ignore, :atomic_number) ] ]
for (sym, name) in _list_of_properties
@eval $name(sys::SoaSystem) = copy(sys.arrays.$sym)
@eval $name(sys::SoaSystem, i::Integer) = sys.arrays.$sym[i]
@eval $name(sys::SoaSystem, inds::AbstractVector) = sys.arrays.$sym[inds]
end


get_cell(at::SoaSystem) = at.cell

for f in (:n_dimensions, :bounding_box, :boundary_conditions, :periodicity)
@eval $f(at::SoaSystem) = $f(at.cell)
end


# ---------------------------------------------------
# atomic_number overload

atomic_number(atom::PState) =
atomic_number(atomic_symbol(atom))

atomic_number(sys::Union{SoaSystem, AosSystem}, i::Integer) =
atomic_number(atomic_symbol(sys, i))

atomic_number(sys::Union{SoaSystem, AosSystem}, args...) =
atomic_number.(atomic_symbol(sys, args...))



# ---------------------------------------------------------------
Expand Down Expand Up @@ -181,13 +191,13 @@ for (sym, name) in _list_of_properties
for i = 1:length(sys)
$set_name_ip(sys, i, Rs[i])
end
return sys
end
return nothing
end
@eval begin
function $set_names_ip(sys::SoaSystem, R::AbstractVector)
copy!(sys.arrays.$sym, R)
return nothing
return sys
end
end
end
Expand Down
10 changes: 8 additions & 2 deletions test/test_atomsbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ using LinearAlgebra: I
##
#generate an atom and check that the accessors work

Z0 = 6
x = PState(𝐫 = SA[1.0, 2.0, 3.0], 𝐯 = SA[0.1, 0.2, 0.3],
π‘š = 1.0, 𝑍 = ChemicalElement(6) )
π‘š = 1.0, 𝑍 = ChemicalElement(Z0) )
display(x)
@test position(x) == x.𝐫
@test velocity(x) == x.𝐯
@test atomic_mass(x) == x.π‘š
@test atomic_symbol(x) == x.𝑍
@test atomic_number(x) == 6
@test atomic_number(x) == Z0


##
Expand Down Expand Up @@ -54,6 +55,11 @@ for f in (get_cell, periodicity, boundary_conditions, bounding_box, n_dimensions
@test f(aos) == f(soa)
end

for _sys in (aos, soa)
@test atomic_number(_sys) == fill(14, length(_sys))
@test atomic_number(_sys, 5) == 14
@test atomic_number(_sys, [2,4,7]) == fill(14, 3)
end

##
# some performance related tests
Expand Down

0 comments on commit 85d1471

Please sign in to comment.