diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 1a7e221..27c1add 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -19,8 +19,8 @@ jobs: fail-fast: false matrix: version: - - '1.9' - - '1.10' + - '1.11' + - '1.12' - 'nightly' os: - ubuntu-latest diff --git a/Project.toml b/Project.toml index 080ba3c..9df7516 100644 --- a/Project.toml +++ b/Project.toml @@ -1,10 +1,9 @@ name = "DecoratedParticles" uuid = "023d0394-cb16-4d2d-a5c7-724bed42bbb6" -authors = ["Christoph Ortner and contributors"] -version = "0.0.7" +authors = ["Christoph Ortner and contributors"] +version = "0.0.8-dev" [deps] -AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a" ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" NamedTupleTools = "d9ec5142-1e00-5aa0-9d6a-321866360f50" @@ -12,19 +11,26 @@ PeriodicTable = "7b2266bf-644c-5ea3-82d8-af4bbd25a884" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" +[weakdeps] +AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a" + +[extensions] +AtomsBaseExt = "AtomsBase" + [compat] -AtomsBase = "0.4.0" +AtomsBase = "0.5" ChainRulesCore = "1" -LinearAlgebra = "1.9, 1.10" +LinearAlgebra = "1.11" NamedTupleTools = "0.14" PeriodicTable = "1" StaticArrays = "1" Unitful = "1.20" -julia = "1.9, 1.10" +julia = "1.11" [extras] +AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a" AtomsBuilder = "f5cc8831-eeb7-4288-8d9f-d6c1ddb77004" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "AtomsBuilder"] +test = ["Test", "AtomsBuilder", "AtomsBase"] diff --git a/ext/AtomsBaseExt.jl b/ext/AtomsBaseExt.jl new file mode 100644 index 0000000..4ace595 --- /dev/null +++ b/ext/AtomsBaseExt.jl @@ -0,0 +1,209 @@ +module AtomsBaseExt + +using DecoratedParticles +import DecoratedParticles: PState, VState, XState, _x, _syms, setproperty, + system, aos_system, soa_system + +import AtomsBase +import AtomsBase: AbstractSystem, + position, velocity, mass, atomic_number, species, + atomic_symbol, n_dimensions, cell_vectors, + periodicity, cell, + PeriodicCell, ChemicalSpecies, + set_cell_vectors! + +# --------------------------------------------------- +# an `Atom` is now just a `PState`, so we define +# accessors for the PState fields with canonical names. + +for (sym, name) in DecoratedParticles._list_of_properties + @eval $name(x::XState) = x.$sym + @eval DecoratedParticles.symbol(::typeof($name)) = $(Meta.quot(sym)) +end + +_post(p, a) = a +_post(::typeof(atomic_symbol), sym::Symbol) = ChemicalSpecies(sym) +_post(::typeof(atomic_symbol), z::Integer) = ChemicalSpecies(z) + +""" +Generate an atom with the given properties. +""" +DecoratedParticles.atom(at; properties = (position, mass, species)) = + PState((; [DecoratedParticles.symbol(p) => _post(p, p(at)) for p in properties]...)) + +# --------------------------------------------------- +# Array of Structs System +# +mutable struct AosSystem{D, TCELL, TPART} <: AbstractSystem{D} + cell::TCELL + particles::Vector{TPART} + # -------- + meta::Dict{String, Any} +end + + +function AosSystem(sys::AbstractSystem; + properties = (position, mass, species), ) + + X = [ DecoratedParticles.atom(sys[i]; properties = properties) for i = 1:length(sys) ] + c3ll = cell(sys) + D = AtomsBase.n_dimensions(c3ll) + return AosSystem{D, typeof(c3ll), eltype(X)}(c3ll, X, Dict{String, Any}()) +end + +aos_system(sys::AbstractSystem; kwargs...) = AosSystem(sys; kwargs...) + + +# implementing the AtomsBase interface + +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 DecoratedParticles._list_of_properties + @eval $name(sys::AosSystem, ::Colon) = [ $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] +end + +cell(at::AosSystem) = at.cell +n_dimensions(at::AosSystem{D}) where {D} = D + + +# --------------------------------------------------- +# Struct of Arrays System + +mutable struct SoaSystem{D, TCELL, NT} <: AbstractSystem{D} + cell::TCELL + arrays::NT + # -------- + meta::Dict{String, Any} +end + +function SoaSystem(sys::AbstractSystem; + properties = (position, mass, species), ) + + arrays = (; [DecoratedParticles.symbol(p) => _post.(p, p(sys, :)) for p in properties]... ) + c3ll = cell(sys) + D = AtomsBase.n_dimensions(c3ll) + return SoaSystem{D, typeof(c3ll), typeof(arrays)}( + c3ll, arrays, Dict{String, Any}()) +end + +soa_system(sys::AbstractSystem; kwargs...) = SoaSystem(sys; kwargs...) + + +# implementing the AtomsBase interface + +Base.length(at::SoaSystem) = length(at.arrays[1]) + +@generated function Base.getindex(sys::SoaSystem{D, TCELL, NT}, i::Integer) where {D, TCELL, NT} + SYMS = _syms(NT) + # very naive code-writing ... probably there is a nicer way ... + code = "PState(" + for sym in SYMS + code *= "$(sym) = sys.arrays.$sym[i], " + end + code *= ")" + return quote + $(Meta.parse(code)) + end +end + +Base.getindex(sys::SoaSystem, inds::AbstractVector{<: Integer}) = + [ sys[i] for i in inds ] + +for (sym, name) in DecoratedParticles._list_of_properties + @eval $name(sys::SoaSystem, ::Colon) = sys.arrays.$sym + @eval $name(sys::SoaSystem, i::Integer) = sys.arrays.$sym[i] + @eval $name(sys::SoaSystem, inds::AbstractVector) = sys.arrays.$sym[inds] +end + +cell(at::SoaSystem) = at.cell +n_dimensions(at::SoaSystem{D}) where {D} = D + + +# --------------------------------------------------- +# atomic_number overload + +atomic_number(atom::PState) = + atomic_number(species(atom)) + +atomic_number(sys::Union{SoaSystem, AosSystem}, i::Integer) = + atomic_number(species(sys, i)) + +atomic_number(sys::Union{SoaSystem, AosSystem}, args...) = + atomic_number.(species(sys, args...)) + + + +# --------------------------------------------------------------- +# Extension of the AtomsBase interface with setter functions + +for (sym, name) in DecoratedParticles._list_of_properties + set_name = Symbol("set_$name") + set_name_ip = Symbol("set_$(name)!") + set_names_ip = Symbol("set_$(name)s!") + # e.g. set_position(x::PState, 𝐫) = setproperty(x, :𝐫, 𝐫) + @eval DecoratedParticles.$set_name(x::PState, t) = setproperty(x, $(Meta.quot(sym)), t) + # e.g. set_position!(sys, i, 𝐫) + @eval begin + function DecoratedParticles.$set_name_ip(sys::AosSystem, i::Integer, t) + xi = sys.particles[i] + sys.particles[i] = DecoratedParticles.$set_name(xi, t) + return nothing + end + end + @eval begin + function DecoratedParticles.$set_name_ip(sys::SoaSystem, i::Integer, t) + sys.arrays.$sym[i] = t + return nothing + end + end + # e.g. set_positions!(sys, X) + @eval begin + function DecoratedParticles.$set_names_ip(sys::AosSystem, Rs) + for i = 1:length(sys) + DecoratedParticles.$set_name_ip(sys, i, Rs[i]) + end + return sys + end + end + @eval begin + function DecoratedParticles.$set_names_ip(sys::SoaSystem, R::AbstractVector) + copy!(sys.arrays.$sym, R) + return sys + end + end +end + + +# cell-level setter + +function set_cell_vectors!(sys::Union{SoaSystem, AosSystem}, bb) + cell = PeriodicCell(bb, periodicity(sys)) + sys.cell = cell + return sys +end + + +# --------------------------------------------------- +# Pretty printing + +function Base.show(io::IO, sys::Union{AosSystem, SoaSystem}) + println(io, typeof(sys).name.name, ": len = $(length(sys)), ") + print(io, " ", cell(sys)) + for i = 1:min(4, length(sys)) + println(io, " ", sys[i]) + end + if length(sys) > 4 + println(io, " ... $(length(sys)-4) particles not shown ...") + end +end + +Base.show(io::IO, ::MIME"text/plain", sys::Union{AosSystem, SoaSystem}) = + show(io, sys) + + +end # module diff --git a/src/DecoratedParticles.jl b/src/DecoratedParticles.jl index 291c6e8..744a364 100644 --- a/src/DecoratedParticles.jl +++ b/src/DecoratedParticles.jl @@ -3,9 +3,9 @@ module DecoratedParticles # core of the package : manipulating particle states include("states.jl") -# AtomsBase interface +include("show.jl") + include("atomsbase.jl") -include("show.jl") end diff --git a/src/atomsbase.jl b/src/atomsbase.jl index 23d3a40..a9f18fb 100644 --- a/src/atomsbase.jl +++ b/src/atomsbase.jl @@ -1,29 +1,10 @@ -import AtomsBase -import AtomsBase: AbstractSystem, - position, velocity, mass, atomic_number, species, - atomic_symbol, n_dimensions, bounding_box, - periodicity, cell, - PeriodicCell, ChemicalSpecies +# AtomsBase interface is now in an extension +# these are the stubs that will be extended. -export AosSystem, SoaSystem, - position, - velocity, - mass, - species, - bounding_box, - periodicity, - cell, - atomic_number, - atomic_symbol, - ChemicalSpecies -# --------------------------------------------------- -# an `Atom` is now just a `PState`, so we define -# accessors for the PState fields with canonical names. - -# list of properties that DP knows about: -_list_of_properties = [ +# Define the _list_of_properties here for the extension to use +const _list_of_properties = [ (:𝐫, :position), (:𝐯, :velocity), (:𝑚, :mass), @@ -33,185 +14,24 @@ _list_of_properties = [ (:μ, :dipole), (:𝐩, :momentum), (:𝐸, :energy), - ] - -for (sym, name) in _list_of_properties - @eval $name(x::XState) = x.$sym - @eval symbol(::typeof($name)) = $(Meta.quot(sym)) -end - -_post(p, a) = a -_post(::typeof(atomic_symbol), sym::Symbol) = ChemicalSpecies(sym) -_post(::typeof(atomic_symbol), z::Integer) = ChemicalSpecies(z) - -""" -Generate an atom with the given properties. -""" -atom(at; properties = (position, mass, species)) = - PState((; [symbol(p) => _post(p, p(at)) for p in properties]...)) - -# --------------------------------------------------- -# Array of Structs System -# -mutable struct AosSystem{D, TCELL, TPART} <: AbstractSystem{D} - cell::TCELL - particles::Vector{TPART} - # -------- - meta::Dict{String, Any} -end - - -function AosSystem(sys::AbstractSystem; - properties = (position, mass, species), ) - - X = [ atom(sys[i]; properties = properties) for i = 1:length(sys) ] - c3ll = cell(sys) - D = AtomsBase.n_dimensions(c3ll) - return AosSystem{D, typeof(c3ll), eltype(X)}(c3ll, X, Dict{String, Any}()) -end - - -# implementing the AtomsBase interface - -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 - @eval $name(sys::AosSystem, ::Colon) = [ $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] -end - -# AtomsBase. -cell(at::AosSystem) = at.cell -n_dimensions(at::AosSystem{D}) where {D} = D - - -# --------------------------------------------------- -# Struct of Arrays System - -mutable struct SoaSystem{D, TCELL, NT} <: AbstractSystem{D} - cell::TCELL - arrays::NT - # -------- - meta::Dict{String, Any} -end +] -function SoaSystem(sys::AbstractSystem; - properties = (position, mass, species), ) +# Define function stubs that will be extended in AtomsBaseExt +function atom end +function symbol end +function aos_system end +function soa_system end - arrays = (; [symbol(p) => _post.(p, p(sys, :)) for p in properties]... ) - c3ll = cell(sys) - D = AtomsBase.n_dimensions(c3ll) - return SoaSystem{D, typeof(c3ll), typeof(arrays)}( - c3ll, arrays, Dict{String, Any}()) -end - - -# implementing the AtomsBase interface - -Base.length(at::SoaSystem) = length(at.arrays[1]) - -# this implementation seems canonical but appears to be type unstable -# unclear to me exactly why, maybe it can be fixed. -# function Base.getindex(sys::SoaSystem{D, TCELL, NT}, i::Integer) where {D, TCELL, NT} -# SYMS = _syms(NT) -# return PState(; ntuple(a -> SYMS[a] => sys.arrays[SYMS[a]][i], length(SYMS))...) -# end - -@generated function Base.getindex(sys::SoaSystem{D, TCELL, NT}, i::Integer) where {D, TCELL, NT} - SYMS = _syms(NT) - # very naive code-writing ... probably there is a nicer way ... - code = "PState(" - for sym in SYMS - code *= "$(sym) = sys.arrays.$sym[i], " - end - code *= ")" - return quote - $(Meta.parse(code)) - end -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 - @eval $name(sys::SoaSystem, ::Colon) = sys.arrays.$sym - @eval $name(sys::SoaSystem, i::Integer) = sys.arrays.$sym[i] - @eval $name(sys::SoaSystem, inds::AbstractVector) = sys.arrays.$sym[inds] -end - -cell(at::SoaSystem) = at.cell -n_dimensions(at::SoaSystem{D}) where {D} = D - - -# --------------------------------------------------- -# atomic_number overload - -atomic_number(atom::PState) = - atomic_number(species(atom)) - -atomic_number(sys::Union{SoaSystem, AosSystem}, i::Integer) = - atomic_number(species(sys, i)) - -atomic_number(sys::Union{SoaSystem, AosSystem}, args...) = - atomic_number.(species(sys, args...)) - - - -# --------------------------------------------------------------- -# Extension of the AtomsBase interface with setter functions +# Define setter function stubs that will be extended in AtomsBaseExt for (sym, name) in _list_of_properties - set_name = Symbol("set_$name") - set_name_ip = Symbol("set_$(name)!") - set_names_ip = Symbol("set_$(name)s!") - @eval export $set_name, $set_name_ip, $set_names_ip - # e.g. set_position(x::PState, 𝐫) = setproperty(x, :𝐫, 𝐫) - @eval $set_name(x::PState, t) = setproperty(x, $(Meta.quot(sym)), t) - # e.g. set_position!(sys, i, 𝐫) - @eval begin - function $set_name_ip(sys::AosSystem, i::Integer, t) - xi = sys.particles[i] - sys.particles[i] = $set_name(xi, t) - return nothing - end - end - @eval begin - function $set_name_ip(sys::SoaSystem, i::Integer, t) - sys.arrays.$sym[i] = t - return nothing - end - end - # e.g. set_positions!(sys, X) - @eval begin - function $set_names_ip(sys::AosSystem, Rs) - for i = 1:length(sys) - $set_name_ip(sys, i, Rs[i]) - end - return sys - end - end - @eval begin - function $set_names_ip(sys::SoaSystem, R::AbstractVector) - copy!(sys.arrays.$sym, R) - return sys - end - end + fname = Symbol("set_$name") + fname_ip = Symbol("set_$(name)!") + fnames_ip = Symbol("set_$(name)s!") + @eval begin + function $fname end + function $fname_ip end + function $fnames_ip end + export $fname, $fname_ip, $fnames_ip + end end - -# TODO: set_atomic_number & co - -# cell-level setter - -export set_bounding_box! - -function set_bounding_box!(sys::Union{SoaSystem, AosSystem}, bb) - cell = PeriodicCell(bb, periodicity(sys)) - sys.cell = cell - return sys -end \ No newline at end of file diff --git a/src/show.jl b/src/show.jl index 08d1910..70c4608 100644 --- a/src/show.jl +++ b/src/show.jl @@ -49,16 +49,3 @@ function Base.show(io::IO, X::XState) end -function Base.show(io::IO, sys::Union{AosSystem, SoaSystem}) - println(io, typeof(sys).name.name, ": len = $(length(sys)), ") - print(io, " ", cell(sys)) - for i = 1:min(4, length(sys)) - println(io, " ", sys[i]) - end - if length(sys) > 4 - println(io, " ... $(length(sys)-4) particles not shown ...") - end -end - -Base.show(io::IO, ::MIME"text/plain", sys::Union{AosSystem, SoaSystem}) = - show(io, sys) diff --git a/src/states.jl b/src/states.jl index 16a3137..72ef0d9 100644 --- a/src/states.jl +++ b/src/states.jl @@ -78,6 +78,16 @@ _syms(nt::Type{NamedTuple{SYMS, TT}}) where {SYMS, TT} = SYMS _syms(X::XState) = _syms(typeof(X)) _syms(::Type{<: XState{NamedTuple{SYMS, TT}}}) where {SYMS, TT} = SYMS +@generated function _syms(x1::TX1, x2::TX2) where {TX1 <: XState, TX2 <: XState} + vsyms = unique( tuple(_syms(TX1)..., _syms(TX2)...) ) + syms = tuple(vsyms...) + quote + $syms + end +end + + + _tt(X::XState) = _tt(typeof(X)) _tt(::Type{<: XState{NamedTuple{SYMS, TT}}}) where {SYMS, TT} = TT @@ -102,9 +112,12 @@ indices as well as the symbols and types """ _findcts(X::TX) where {TX <: XState} = _findcts(TX) -function _findcts(TX::Type{<: XState}) +@generated function _findcts(::Type{TX}) where {TX <: XState} SYMS, TT = _symstt(TX) icts = findall(T -> T <: CTSTT, TT.types) + quote + $(SVector(icts...)) + end end _ctssyms(X::TX) where {TX <: XState} = _ctssyms(TX) @@ -118,8 +131,12 @@ VState(t::NT) where {NT <: NamedTuple} = VState{NT}(t) VState(; kwargs...) = VState(NamedTuple(kwargs)) -VState(X::TX) where {TX <: PState} = - (vstate_type(X))( select(_x(X), _ctssyms(X)) ) +@generated function VState(X::TX) where {TX <: PState} + CSYMS = _ctssyms(TX) + quote + VState(select(_x(X), $CSYMS)) + end +end """ @@ -298,34 +315,47 @@ _mod_zero(::Union{Symbol, Type{Symbol}}) = :O import Base: +, - +_prom_plus(TX1::Type{<: PState}, TX2::Type{<: PState}) = error("cannot add two PStates") +_prom_plus(TX1::Type{<: PState}, TX2::Type{<: VState}) = PState +_prom_plus(TX1::Type{<: VState}, TX2::Type{<: PState}) = PState +_prom_plus(TX1::Type{<: VState}, TX2::Type{<: VState}) = VState + +function +(X1::TX1, X2::TX2) where {TX1 <: XState, TX2 <: XState} + SYMS = _syms(X1, X2) + vals = ntuple( i -> begin + sym = SYMS[i] + if haskey(_x(X1), sym) && haskey(_x(X2), sym) + return getproperty(_x(X1), sym) + getproperty(_x(X2), sym) + elseif haskey(_x(X1), sym) + return getproperty(_x(X1), sym) + else + return getproperty(_x(X2), sym) + end + end, length(SYMS)) + return _prom_plus(TX1, TX2)( NamedTuple{SYMS}(vals) ) +end -# for f in (:+, :-, ) -# eval( quote -# function $f(X1::TX1, X2::TX2) where {TX1 <: XState, TX2 <: XState} -# SYMS = _syms(TX1) -# @assert SYMS == _syms(TX2) -# vals = ntuple( i -> $f( getproperty(_x(X1), SYMS[i]), -# getproperty(_x(X2), SYMS[i]) ), length(SYMS) ) -# return TX1( NamedTuple{SYMS}(vals) ) -# end -# end ) -# end - -for f in (:+, :-, ) - eval( quote - function $f(X1::TX1, X2::TX2) where {TX1 <: XState, TX2 <: XState} - SYMS1 = _syms(TX1) - @assert issubset(_syms(TX2), SYMS1) - vals = ntuple( i -> begin - sym = SYMS1[i] - v1 = getproperty(_x(X1), sym) - haskey(_x(X2), sym) ? $f(v1, getproperty(_x(X2), sym)) : v1 - end, length(SYMS1)) - return TX1( NamedTuple{SYMS1}(vals) ) - end - end ) +_prom_minus(TX1::Type{<: PState}, TX2::Type{<: PState}) = VState +_prom_minus(TX1::Type{<: PState}, TX2::Type{<: VState}) = PState +_prom_minus(TX1::Type{<: VState}, TX2::Type{<: PState}) = error("Cannot subtrate a PState from a VState") +_prom_minus(TX1::Type{<: VState}, TX2::Type{<: VState}) = VState + +function -(X1::TX1, X2::TX2) where {TX1 <: XState, TX2 <: XState} + SYMS = _syms(X1, X2) + vals = ntuple( i -> begin + sym = SYMS[i] + if haskey(_x(X1), sym) && haskey(_x(X2), sym) + return getproperty(_x(X1), sym) - getproperty(_x(X2), sym) + elseif haskey(_x(X1), sym) + return getproperty(_x(X1), sym) + else + return - getproperty(_x(X2), sym) + end + end, length(SYMS)) + return _prom_minus(TX1, TX2)( NamedTuple{SYMS}(vals) ) end + # multiplication with a scalar function *(X1::TX, a::Number) where {TX <: XState} SYMS = _syms(TX) diff --git a/test/test_atomsbase.jl b/test/test_atomsbase.jl index 32abd06..16ee69f 100644 --- a/test/test_atomsbase.jl +++ b/test/test_atomsbase.jl @@ -1,7 +1,14 @@ +# # For interactive debugging only +# using Pkg; Pkg.activate(joinpath(@__DIR__(), "..")) +# using TestEnv; TestEnv.activate(); +# Pkg.develop(url = joinpath(@__DIR__(), "..")) +## + +@info("AtomsBase tests") using DecoratedParticles, AtomsBase, StaticArrays, Unitful, Test, AtomsBuilder -using AtomsBase: Atom, ChemicalSpecies -DP = DecoratedParticles +using AtomsBase: Atom, ChemicalSpecies, cell_vectors, periodicity, set_cell_vectors! +import DecoratedParticles as DP using LinearAlgebra: I @@ -37,8 +44,8 @@ display(x) # convert an entire system sys = rattle!(bulk(:Si, cubic=true) * 2, 0.1); -aos = DP.AosSystem(sys) -soa = DP.SoaSystem(sys) +aos = DP.aos_system(sys) +soa = DP.soa_system(sys) aos[1] soa[1] @@ -51,7 +58,7 @@ for i = 1:10 end end -for f in (cell, periodicity, bounding_box, n_dimensions) +for f in (cell, periodicity, cell_vectors, n_dimensions) @test f(aos) == f(soa) end @@ -66,8 +73,8 @@ end # some performance related tests sys = rattle!(bulk(:Si, cubic=true) * 2, 0.1); -aos = DP.AosSystem(sys) -soa = DP.SoaSystem(sys) +aos = DP.aos_system(sys) +soa = DP.soa_system(sys) x1 = aos[1] x2 = soa[1] @@ -86,7 +93,7 @@ _check_allocs(sys) = ( (@allocated position(sys, 1)) + # setters sys = rattle!(bulk(:Si, cubic=true) * 2, 0.1); -aos = DP.AosSystem(sys) +aos = DP.aos_system(sys) x = aos[1] 𝐫 = x.𝐫 @@ -115,7 +122,7 @@ DP.set_position!(aos1, 1, 𝐫1) ## -soa = DP.SoaSystem(aos) +soa = DP.soa_system(aos) @test all(position(soa, :) .== position(aos, :)) DP.set_positions!(soa, X) @test all(position(soa, :) .== position(aos1, :)) @@ -126,10 +133,10 @@ DP.set_position!(soa, 1, 𝐫1) ## -bb = bounding_box(soa) +bb = cell_vectors(soa) bb1 = ntuple(i -> (I + 0.01*randn(SMatrix{3,3,Float64})) * bb[i], 3) -DP.set_bounding_box!(soa, bb1) -@test bounding_box(soa) == bb1 -DP.set_bounding_box!(aos, bb1) -@test bounding_box(aos) == bb1 +set_cell_vectors!(soa, bb1) +@test cell_vectors(soa) == bb1 +set_cell_vectors!(aos, bb1) +@test cell_vectors(aos) == bb1 diff --git a/test/test_states.jl b/test/test_states.jl index 54cebb7..6b537be 100644 --- a/test/test_states.jl +++ b/test/test_states.jl @@ -2,7 +2,7 @@ using DecoratedParticles, StaticArrays, Test, LinearAlgebra using DecoratedParticles: PState, VState -DP = DecoratedParticles +import DecoratedParticles as DP ##