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

Merged
merged 9 commits into from
Nov 21, 2024
Merged
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
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.2"
version = "0.5.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
4 changes: 2 additions & 2 deletions docs/src/apireference.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ ChemicalSpecies
## System properties

```@docs
bounding_box
set_bounding_box!
cell_vectors
set_cell_vectors!
periodicity
set_periodicity!
cell
Expand Down
10 changes: 5 additions & 5 deletions docs/src/interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ A system is specified by a computational cell and particles within that cell (or
- [`AtomsBase.cell(system)](@ref) : returns an object `cell` that specifies the computational cell. Two reference implementations, [`PeriodicCell`](@ref) and [`IsolatedCell`](@ref) that should serve most purposes are provided.

A cell object must implement methods for the following functions:
- [`AtomsBase.bounding_box(cell)`](@ref) : returns `NTuple{D, SVector{D, T}}` the cell vectors that specify the computational domain if it is finite. For isolated systems, the return values are unspecified.
- [`AtomsBase.periodicity(cell)`](@ref) : returns `NTuple{D, Bool}`, booleans that specify whether the system is periodic in the direction of the `D` cell vectors provided by `bounding_box`. For isolated systems `periodicity` must return `(false, ..., false)`.
- [`AtomsBase.cell_vectors(cell)`](@ref) : returns `NTuple{D, SVector{D, T}}` the cell vectors that specify the computational domain if it is finite. For isolated systems, the return values are unspecified.
- [`AtomsBase.periodicity(cell)`](@ref) : returns `NTuple{D, Bool}`, booleans that specify whether the system is periodic in the direction of the `D` cell vectors provided by `cell_vectors`. For isolated systems `periodicity` must return `(false, ..., false)`.
- [`AtomsBase.n_dimensions(cell)`](@ref) : returns the dimensionality of the computational cell, it must match the dimensionality of the system.


AtomsBase provides `bounding_box` and `periodicity` methods so that they can be called with a system as argument, i.e.,
AtomsBase provides `cell_vectors` and `periodicity` methods so that they can be called with a system as argument, i.e.,
```julia
bounding_box(system) = bounding_box(cell(system))
cell_vectors(system) = cell_vectors(cell(system))
periodicity(system) = periodicity(cell(system))
```

Expand Down Expand Up @@ -95,7 +95,7 @@ The optional setter / mutation interface consists of the following functions to
- [`set_position!(system, i, x)`](@ref)
- [`set_mass!(system, i, x)`](@ref)
- [`set_species!(system, i, x)`](@ref)
- [`set_bounding_box!(cell, bb)`](@ref)
- [`set_cell_vectors!(cell, bb)`](@ref)
- [`set_periodicity!(cell, pbc)`](@ref)
- `deleteat!(system, i)` : delete atoms `i` (or atoms `i` if a list of `":`)
- `append!(system1, system2)` : append system 2 to system 1, provided they are "compatible".
Expand Down
12 changes: 6 additions & 6 deletions docs/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ An update constructor for systems is supported as well (see [`AbstractSystem`](@
````@example system
using AtomsBase: AbstractSystem
AbstractSystem(hydrogen;
bounding_box=([5.0, 0.0, 0.0]u"Å",
cell_vectors=([5.0, 0.0, 0.0]u"Å",
[0.0, 5.0, 0.0]u"Å",
[0.0, 0.0, 5.0]u"Å"))
````
Expand All @@ -182,7 +182,7 @@ implementing the `AbstractSystem` interface.
Similar to the atoms, system objects similarly support a functional-style access to system properties
as well as a dict-style access:
````@example system
bounding_box(hydrogen)
cell_vectors(hydrogen)
````
````@example system
hydrogen[:periodicity]
Expand Down Expand Up @@ -214,19 +214,19 @@ for some standard atomic system setups.
For example to setup a hydrogen system with periodic BCs, we can issue
````@example
using Unitful, UnitfulAtomic, AtomsBase # hide
bounding_box = ([10.0, 0.0, 0.0]u"Å", [0.0, 10.0, 0.0]u"Å", [0.0, 0.0, 10.0]u"Å")
cell_vectors = ([10.0, 0.0, 0.0]u"Å", [0.0, 10.0, 0.0]u"Å", [0.0, 0.0, 10.0]u"Å")
hydrogen = periodic_system([:H => [0, 0, 1.]u"Å",
:H => [0, 0, 3.]u"Å"],
bounding_box)
cell_vectors)
````
To setup a silicon unit cell we can use fractional coordinates
(which is common for solid-state simulations):
````@example
using Unitful, UnitfulAtomic, AtomsBase # hide
bounding_box = 10.26 / 2 .* ([0, 0, 1]u"bohr", [1, 0, 1]u"bohr", [1, 1, 0]u"bohr")
cell_vectors = 10.26 / 2 .* ([0, 0, 1]u"bohr", [1, 0, 1]u"bohr", [1, 1, 0]u"bohr")
silicon = periodic_system([:Si => ones(3)/8,
:Si => -ones(3)/8],
bounding_box, fractional=true)
cell_vectors, fractional=true)
````
Alternatively we can also place an isolated H2 molecule in vacuum, which is the standard setup for molecular simulations:
````@example
Expand Down
4 changes: 2 additions & 2 deletions lib/AtomsBaseTesting/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AtomsBaseTesting"
uuid = "ed7c10db-df7e-4efa-a7be-4f4190f7f227"
authors = ["JuliaMolSim community"]
version = "0.3.1"
version = "0.4.0"

[deps]
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
Expand All @@ -11,7 +11,7 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a"

[compat]
AtomsBase = "0.4"
AtomsBase = "0.5"
Unitful = "1"
UnitfulAtomic = "1"
julia = "1.6"
16 changes: 9 additions & 7 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,16 +171,18 @@ 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],
atprop=NamedTuple(atprop), sysprop=NamedTuple(sysprop))
cell_vectors=sysprop[:cell_vectors],
periodicity=sysprop[:periodicity],
atprop=NamedTuple(atprop),
sysprop=NamedTuple(sysprop))
end

end
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
Loading
Loading