Skip to content

Commit

Permalink
move atomic stuff to another file, fix some broken functions
Browse files Browse the repository at this point in the history
Signed-off-by: Rachel Kurchin <[email protected]>
  • Loading branch information
rkurchin committed Nov 12, 2021
1 parent 4aca49f commit be999c7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 36 deletions.
1 change: 1 addition & 0 deletions src/AtomsBase.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module AtomsBase

include("interface.jl")
include("atoms.jl")
include("implementation_soa.jl")
include("implementation_aos.jl")

Expand Down
38 changes: 38 additions & 0 deletions src/atoms.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Extra stuff only for Systems composed of atoms
#

export StaticAtom, AbstractAtomicSystem
export atomic_mass,
atomic_number,
atomic_symbol
export atomic_property, has_atomic_property, atomic_propertynames

struct StaticAtom{D,L<:Unitful.Length}
position::SVector{D,L}
element::Element
end
StaticAtom(position, element) = StaticAtom{length(position)}(position, element)
position(atom::StaticAtom) = atom.position
species(atom::StaticAtom) = atom.element

function StaticAtom(position, symbol::Union{Integer,AbstractString,Symbol,AbstractVector})
StaticAtom(position, elements[symbol])
end

function Base.show(io::IO, a::StaticAtom)
print(io, "StaticAtom: $(a.element.symbol)")
end

const AbstractAtomicSystem{D} = AbstractSystem{D,Element}

atomic_symbol(e::Element) = e.symbol
atomic_mass(e::Element) = e.atomic_mass
atomic_number(e::Element) = e.number
atomic_property(e::Element, property::Symbol) = getproperty(e, property)

atomic_symbol(sys::AbstractAtomicSystem) = atomic_symbol.(species(sys))
atomic_number(sys::AbstractAtomicSystem) = atomic_number.(species(sys))
atomic_mass(sys::AbstractAtomicSystem) = atomic_mass.(species(sys))
atomic_property(sys::AbstractAtomicSystem, property::Symbol)::Vector{Any} =
atomic_property.(species(sys), property)
39 changes: 3 additions & 36 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@ using PeriodicTable
using StaticArrays
import Base.position

export AbstractSystem, AbstractAtomicSystem
export StaticAtom
export AbstractSystem
export BoundaryCondition, DirichletZero, Periodic
export atomic_mass,
atomic_number,
atomic_symbol,
bounding_box,
export bounding_box,
species,
position,
velocity,
boundary_conditions,
periodic_dims
export atomic_property, has_atomic_property, atomic_propertynames
get_periodic
export n_dimensions

velocity(p)::Union{Unitful.Velocity,Missing} = missing
Expand Down Expand Up @@ -48,7 +43,6 @@ get_periodic(sys::AbstractSystem) =
# Note: Can't use ndims, because that is ndims(sys) == 1 (because of indexing interface)
n_dimensions(::AbstractSystem{D}) where {D} = D


# indexing and iteration interface
Base.getindex(::AbstractSystem, ::Int) = error("Implement me")
Base.length(::AbstractSystem) = error("Implement me")
Expand All @@ -68,33 +62,6 @@ position(sys::AbstractSystem) = position.(sys) # in Cartesian coordinates!
velocity(sys::AbstractSystem) = velocity.(sys) # in Cartesian coordinates!
species(sys::AbstractSystem) = species.(sys)

#
# Extra stuff only for Systems composed of atoms
#
const AbstractAtomicSystem{D} = AbstractSystem{D,Element}
atomic_symbol(sys::AbstractAtomicSystem) = atomic_symbol.(sys)
atomic_number(sys::AbstractAtomicSystem) = atomic_number.(sys)
atomic_mass(sys::AbstractAtomicSystem) = atomic_mass.(sys)
atomic_property(sys::AbstractAtomicSystem, property::Symbol)::Vector{Any} =
atomic_property.(sys, property)
atomic_propertiesnames(sys::AbstractAtomicSystem) = unique(sort(atomic_propertynames.(sys)))

struct StaticAtom{D,L<:Unitful.Length}
position::SVector{D,L}
element::Element
end
StaticAtom(position, element) = StaticAtom{length(position),eltype(position)}(position, element)
position(atom::StaticAtom) = atom.position
species(atom::StaticAtom) = atom.element

function StaticAtom(position, symbol::Union{Integer,AbstractString,Symbol,AbstractVector})
StaticAtom(position, elements[symbol])
end

function Base.show(io::IO, a::StaticAtom)
print(io, "StaticAtom: $(a.element.symbol)")
end

# Just to make testing a little easier for now
function Base.show(io::IO, mime::MIME"text/plain", sys::AbstractSystem)
println(io, "$(string(nameof(typeof(sys)))):")
Expand Down

0 comments on commit be999c7

Please sign in to comment.