Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename bounding_box to cell_vectors consistently #127

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/AtomsBaseTesting/src/AtomsBaseTesting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function test_approx_eq(s::AbstractSystem, t::AbstractSystem;

# Test some things on cell objects
if cell(s) isa PeriodicCell
@test maximum(map(rnorm, bounding_box(cell(s)), bounding_box(cell(t)))) < rtol
@test maximum(map(rnorm, cell_vectors(cell(s)), cell_vectors(cell(t)))) < rtol
end
@test periodicity(cell(s)) == periodicity(cell(t))
@test n_dimensions(cell(s)) == n_dimensions(cell(t))
Expand All @@ -96,7 +96,7 @@ function test_approx_eq(s::AbstractSystem, t::AbstractSystem;

if s[prop] isa Quantity
@test rnorm(s[prop], t[prop]) < rtol
elseif prop in (:bounding_box, ) && (cell(s) isa PeriodicCell)
elseif prop in (:cell_vectors, ) && (cell(s) isa PeriodicCell)
@test maximum(map(rnorm, s[prop], t[prop])) < rtol
else
@test s[prop] == t[prop]
Expand Down Expand Up @@ -146,7 +146,7 @@ function make_test_system(D=3; drop_atprop=Symbol[], drop_sysprop=Symbol[],
:magnetic_moment => [0.0, 0.0, 1.0, -1.0, 0.0],
)
sysprop = Dict{Symbol,Any}(
:bounding_box => box,
:cell_vectors => box,
:periodicity => (true, true, false),
#
:extra_data => 42,
Expand All @@ -171,15 +171,15 @@ function make_test_system(D=3; drop_atprop=Symbol[], drop_sysprop=Symbol[],
Atom(atprop[:species][i], atprop[:position][i]; atargs...)
end
end
cell = PeriodicCell(; cell_vectors=sysprop[:bounding_box],
cell = PeriodicCell(; cell_vectors=sysprop[:cell_vectors],
periodicity=sysprop[:periodicity])

sysargs = Dict(k => v for (k, v) in pairs(sysprop)
if !(k in (:bounding_box, :periodicity)))
if !(k in (:cell_vectors, :periodicity)))
system = FlexibleSystem(atoms, cell; sysargs...)

(; system, atoms, cell,
bounding_box=sysprop[:bounding_box], periodicity=sysprop[:periodicity],
cell_vectors=sysprop[:cell_vectors], periodicity=sysprop[:periodicity],
atprop=NamedTuple(atprop), sysprop=NamedTuple(sysprop))
end

Expand Down
14 changes: 7 additions & 7 deletions lib/AtomsBaseTesting/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ include("testmacros.jl")
@test sort(collect(keys(case.atprop))) == sort(collect(atomkeys(case.system)))
@test sort(collect(keys(case.atprop))) == sort(collect(keys(case.atoms[1])))
@test sort(collect(keys(case.sysprop))) == sort(collect(keys(case.system)))
@test case.bounding_box == bounding_box(case.system)
@test case.cell_vectors == cell_vectors(case.system)
@test case.periodicity == periodicity(case.system)
end

let case = make_test_system(; cellmatrix=:full)
box = reduce(hcat, bounding_box(case.system))
box = reduce(hcat, cell_vectors(case.system))
@test UpperTriangular(box) != box
@test LowerTriangular(box) != box
@test Diagonal(box) != box
end
let case = make_test_system(; cellmatrix=:upper_triangular)
box = reduce(hcat, bounding_box(case.system))
box = reduce(hcat, cell_vectors(case.system))
@test UpperTriangular(box) == box
@test LowerTriangular(box) != box
@test Diagonal(box) != box
end
let case = make_test_system(; cellmatrix=:lower_triangular)
box = reduce(hcat, bounding_box(case.system))
box = reduce(hcat, cell_vectors(case.system))
@test UpperTriangular(box) != box
@test LowerTriangular(box) == box
@test Diagonal(box) != box
end
let case = make_test_system(; cellmatrix=:diagonal)
box = reduce(hcat, bounding_box(case.system))
box = reduce(hcat, cell_vectors(case.system))
@test Diagonal(box) == box
@test UpperTriangular(box) == box
@test LowerTriangular(box) == box
Expand All @@ -63,7 +63,7 @@ include("testmacros.jl")
case = make_test_system()
system = case.system
atoms = case.atoms
box = case.bounding_box
box = case.cell_vectors
bcs = case.periodicity
sysprop = case.sysprop
# end simplify
Expand All @@ -82,7 +82,7 @@ include("testmacros.jl")
case = make_test_system()
system = case.system
atoms = case.atoms
box = case.bounding_box
box = case.cell_vectors
bcs = case.periodicity
sysprop = case.sysprop
# end simplify
Expand Down
18 changes: 9 additions & 9 deletions src/implementation/fast_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ struct FastSystem{D, TCELL, L <: Unitful.Length, M <: Unitful.Mass, S} <: Abstra
end

# Constructor to fetch the types
function FastSystem(box::AUTOBOX,
pbc::AUTOPBC,
function FastSystem(cell_vectors::AUTOCELL,
periodicity::AUTOPBC,
positions, species, masses)
cϵll = PeriodicCell(; cell_vectors = box, periodicity = pbc)
cϵll = PeriodicCell(; cell_vectors, periodicity)
FastSystem(cϵll, positions, species, masses)
end

Expand All @@ -40,8 +40,8 @@ function FastSystem(system::AbstractSystem)
end

# Convenience constructor where we don't have to preconstruct all the static stuff...
function FastSystem(particles, box::AUTOBOX, pbc::AUTOPBC)
box1 = _auto_cell_vectors(box)
function FastSystem(particles, cell_vectors::AUTOCELL, pbc::AUTOPBC)
box1 = _auto_cell_vectors(cell_vectors)
pbc1 = _auto_pbc(pbc, box1)
D = length(box1)
if !all(length.(box1) .== D)
Expand All @@ -66,16 +66,16 @@ Base.getindex(sys::FastSystem, i::Integer) = AtomView(sys, i)

# System property access
function Base.getindex(system::FastSystem, x::Symbol)
if x === :bounding_box
bounding_box(system)
if x === :cell_vectors
cell_vectors(system)
elseif x === :periodicity
periodicity(system)
else
throw(KeyError(x))
end
end
Base.haskey(::FastSystem, x::Symbol) = x in (:bounding_box, :periodicity)
Base.keys(::FastSystem) = (:bounding_box, :periodicity)
Base.haskey(::FastSystem, x::Symbol) = x in (:cell_vectors, :periodicity)
Base.keys(::FastSystem) = (:cell_vectors, :periodicity)

# Atom and atom property access
atomkeys(::FastSystem) = (:position, :species, :mass)
Expand Down
26 changes: 13 additions & 13 deletions src/implementation/flexible_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ cell(sys::FlexibleSystem) = sys.cell

# System property access
function Base.getindex(system::FlexibleSystem, x::Symbol)
if x === :bounding_box
bounding_box(system)
if x === :cell_vectors
cell_vectors(system)
elseif x === :periodicity
periodicity(system)
else
Expand All @@ -26,10 +26,10 @@ function Base.getindex(system::FlexibleSystem, x::Symbol)
end

function Base.haskey(system::FlexibleSystem, x::Symbol)
x in (:bounding_box, :periodicity) || haskey(system.data, x)
x in (:cell_vectors, :periodicity) || haskey(system.data, x)
end

Base.keys(system::FlexibleSystem) = (:bounding_box, :periodicity, keys(system.data)...)
Base.keys(system::FlexibleSystem) = (:cell_vectors, :periodicity, keys(system.data)...)

# Atom and atom property access
Base.getindex(system::FlexibleSystem, i::Integer) = system.particles[i]
Expand All @@ -41,25 +41,25 @@ Base.getindex(system::FlexibleSystem, ::Colon, x::Symbol) = [at[x] for at in sys


"""
FlexibleSystem(particles, bounding_box, periodicity; kwargs...)
FlexibleSystem(particles; bounding_box, periodicity, kwargs...)
FlexibleSystem(particles, cell_vectors, periodicity; kwargs...)
FlexibleSystem(particles; cell_vectors, periodicity, kwargs...)
FlexibleSystem(particles, cell; kwargs...)

Construct a flexible system, a versatile data structure for atomistic systems,
which puts an emphasis on flexibility rather than speed.
"""
function FlexibleSystem(
particles::AbstractVector{S},
box::AUTOBOX{D},
pbc::AUTOPBC{D};
cell_vectors::AUTOCELL{D},
periodicity::AUTOPBC{D};
kwargs...
) where {S, D}
cϵll = PeriodicCell(; cell_vectors = box, periodicity = pbc)
cϵll = PeriodicCell(; cell_vectors, periodicity)
FlexibleSystem{D, S, typeof(cϵll)}(particles, cϵll, Dict(kwargs...))
end

function FlexibleSystem(particles; bounding_box, periodicity, kwargs...)
FlexibleSystem(particles, bounding_box, periodicity; kwargs...)
function FlexibleSystem(particles; cell_vectors, periodicity, kwargs...)
FlexibleSystem(particles, cell_vectors, periodicity; kwargs...)
end

function FlexibleSystem(particles::AbstractVector, cell; kwargs...)
Expand Down Expand Up @@ -88,13 +88,13 @@ Update constructor. Construct a new system where one or more properties are chan
which are given as `kwargs`. A subtype of `AbstractSystem` is returned, by default
a `FlexibleSystem`, but depending on the type of the passed system this might differ.

Supported `kwargs` include `particles`, `atoms`, `bounding_box` and `periodicity`
Supported `kwargs` include `particles`, `atoms`, `cell_vectors` and `periodicity`
as well as user-specific custom properties.

# Examples
Change the bounding box and the atoms of the passed system
```julia-repl
julia> AbstractSystem(system; bounding_box= ..., atoms = ... )
julia> AbstractSystem(system; cell_vectors= ..., atoms = ... )
```
"""
AbstractSystem(system::AbstractSystem; kwargs...) = FlexibleSystem(system; kwargs...)
Expand Down
14 changes: 7 additions & 7 deletions src/implementation/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
export atomic_system, isolated_system, periodic_system

"""
atomic_system(atoms::AbstractVector, bounding_box, periodicity; kwargs...)
atomic_system(atoms::AbstractVector, cell_vectors, periodicity; kwargs...)

Construct a [`FlexibleSystem`](@ref) using the passed `atoms` and boundary box and conditions.
Extra `kwargs` are stored as custom system properties.

# Examples
Construct a hydrogen molecule in a box, which is periodic only in the first two dimensions
```julia-repl
julia> bounding_box = [[10.0, 0.0, 0.0], [0.0, 10.0, 0.0], [0.0, 0.0, 10.0]]u"Å"
julia> cell_vectors = [[10.0, 0.0, 0.0], [0.0, 10.0, 0.0], [0.0, 0.0, 10.0]]u"Å"
julia> pbcs = (true, true, false)
julia> hydrogen = atomic_system([:H => [0, 0, 1.]u"bohr",
:H => [0, 0, 3.]u"bohr"],
bounding_box, pbcs)
cell_vectors, pbcs)
```
"""
atomic_system(atoms::AbstractVector{<:Atom}, box, pbcs; kwargs...) =
Expand Down Expand Up @@ -63,10 +63,10 @@ Extra `kwargs` are stored as custom system properties.
# Examples
Setup a hydrogen molecule inside periodic BCs:
```julia-repl
julia> bounding_box = ([10.0, 0.0, 0.0]u"Å", [0.0, 10.0, 0.0]u"Å", [0.0, 0.0, 10.0]u"Å")
julia> cell_vectors = ([10.0, 0.0, 0.0]u"Å", [0.0, 10.0, 0.0]u"Å", [0.0, 0.0, 10.0]u"Å")
julia> hydrogen = periodic_system([:H => [0, 0, 1.]u"bohr",
:H => [0, 0, 3.]u"bohr"],
bounding_box)
cell_vectors)
```

Setup a silicon unit cell using fractional positions
Expand All @@ -78,9 +78,9 @@ julia> silicon = periodic_system([:Si => ones(3)/8,
```
"""
function periodic_system(atoms::AbstractVector,
box::AUTOBOX;
cell::AUTOCELL;
fractional=false, kwargs...)
lattice = _auto_cell_vectors(box)
lattice = _auto_cell_vectors(cell)
pbcs = fill(true, length(lattice))
!fractional && return atomic_system(atoms, lattice, pbcs; kwargs...)

Expand Down
18 changes: 9 additions & 9 deletions src/interface.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Base.position
import PeriodicTable

export bounding_box,
export cell_vectors,
periodicity,
cell,
n_dimensions,
Expand Down Expand Up @@ -34,24 +34,24 @@ abstract type AbstractSystem{D} end


"""
bounding_box(sys::AbstractSystem{D})
cell_vectors(sys::AbstractSystem{D})

Return a tuple of length `D` of vectors of length `D` that describe the
"box" in which the system `sys` is defined.
Return a tuple of length `D` of vectors of length `D` that describe the
cell in which the system `sys` is defined.
"""
function bounding_box end
function cell_vectors end

"""
set_bounding_box!(sys::AbstractSystem{D}, bb::NTuple{D, SVector{D, L}})
set_cell_vectors!(sys::AbstractSystem{D}, bb::NTuple{D, SVector{D, L}})
"""
function set_bounding_box! end
function set_cell_vectors! end


"""
periodicity(sys::AbstractSystem{D})

Return a `NTuple{D, Bool}` indicating whether the system is periodic along a
cell vector as specified by `bounding_box`.
cell vector as specified by `cell_vectors`.
"""
function periodicity end

Expand Down Expand Up @@ -169,7 +169,7 @@ n_dimensions(::AbstractSystem{D}) where {D} = D

# interface functions to connect Systems and cells

bounding_box(system::AbstractSystem) = bounding_box(cell(system))
cell_vectors(system::AbstractSystem) = cell_vectors(cell(system))

periodicity(system::AbstractSystem) = periodicity(cell(system))

Expand Down
4 changes: 2 additions & 2 deletions src/utils/atomview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ See [FastSystem](@ref Struct-of-Arrays-/-FastSystem) for an example of system
using `AtomView` as its species type.

## Example
```jldoctest; setup=:(using AtomsBase, Unitful; atoms = Atom[:C => [0.25, 0.25, 0.25]u"Å", :C => [0.75, 0.75, 0.75]u"Å"]; box = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]u"Å"; boundary_conditions = [Periodic(), Periodic(), DirichletZero()])
julia> system = FastSystem(atoms, box, boundary_conditions);
```jldoctest; setup=:(using AtomsBase, Unitful; atoms = Atom[:C => [0.25, 0.25, 0.25]u"Å", :C => [0.75, 0.75, 0.75]u"Å"]; cell_vectorn = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]u"Å"; boundary_conditions = [Periodic(), Periodic(), DirichletZero()])
julia> system = FastSystem(atoms, cell_vectorn, boundary_conditions);

julia> atom = system[2]
AtomView(C, atomic_number = 6, mass = 12.011 u):
Expand Down
Loading
Loading