Skip to content

Commit

Permalink
implemented unitcelltype function
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed Nov 9, 2022
1 parent a2c4674 commit dd0ae7a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/Box.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,36 @@ Base.@kwdef struct Box{UnitCellType,N,T,TSQ,M}
unit_cell_max::SVector{N,T}
end

"""
unitcelltype(::Box{T}) where T = T
Returns the type of a unitcell from the `Box` structure.
## Example
```julia-repl
julia> box = Box([1,1,1], 0.1)
julia> unitcelltype(box)
OrthorhombicCell
julia> box = Box([1 0 0; 0 1 0; 0 0 1], 0.1)
julia> unitcelltype(box)
TriclinicCell
```
"""
unitcelltype(::Box{T}) where T = T

@testitem "unitcelltype" begin
using CellListMap
@test unitcelltype(Box([1,1,1], 0.1)) == OrthorhombicCell
@test unitcelltype(Box([1 0 0; 0 1 0; 0 0 1], 0.1)) == TriclinicCell
x = rand(3,100)
@test unitcelltype(Box(limits(x), 0.1)) == NonPeriodicCell
end

"""
```
Expand Down
1 change: 1 addition & 0 deletions src/CellListMap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export limits
export TriclinicCell
export OrthorhombicCell
export NonPeriodicCell
export unitcelltype
export nbatches
export PeriodicSystem

Expand Down
17 changes: 16 additions & 1 deletion src/PeriodicSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ using StaticArrays

import ..CellListMap
import ..CellListMap: INTERNAL
import ..CellListMap: Box, update_box
import ..CellListMap: Box, update_box, unitcelltype

export PeriodicSystem
export map_pairwise!, map_pairwise
export update_cutoff!
export update_unitcell!
export unitcelltype

export copy_output
export resize_output!
Expand Down Expand Up @@ -182,6 +183,7 @@ function PeriodicSystem(;
return sys
end


# Abstract type only for cleaner dispatch
abstract type AbstractPeriodicSystem{OutputName} end

Expand All @@ -206,6 +208,14 @@ setproperty!(sys::AbstractPeriodicSystem, ::Val{:_box}, x) = setfield!(sys, :_bo
setproperty!(sys::AbstractPeriodicSystem, ::Val{:_cell_list}, x) = setfield!(sys, :_cell_list, x)
setproperty!(sys::AbstractPeriodicSystem, ::Val{:output}, x) = setfield!(sys, :output, x)

"""
unitcelltype(sys::AbstractPeriodicSystem)
Returns the type of a unitcell from the `PeriodicSystem` structure.
"""
unitcelltype(sys::AbstractPeriodicSystem) = unitcelltype(sys._box)

@testitem "PeriodicSystems properties" begin

using CellListMap.PeriodicSystems
Expand Down Expand Up @@ -245,6 +255,11 @@ setproperty!(sys::AbstractPeriodicSystem, ::Val{:output}, x) = setfield!(sys, :o
@test PeriodicSystems.map_pairwise((x,y,i,j,d2,out) -> out += d2, sys) == 0.0
end

# unitcell type
x = rand(SVector{3,Float64},100)
@test unitcelltype(PeriodicSystem(positions=x, cutoff=0.1, unitcell=[1,1,1], output=0.0)) == OrthorhombicCell
@test unitcelltype(PeriodicSystem(positions=x, cutoff=0.1, unitcell=[1 0 0; 0 1 0; 0 0 1], output=0.0)) == TriclinicCell

end

"""
Expand Down

2 comments on commit dd0ae7a

@lmiq
Copy link
Member Author

@lmiq lmiq commented on dd0ae7a Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/71940

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.6 -m "<description of version>" dd0ae7a7607c52db1f399c366e9d59fcbe1ef02f
git push origin v0.8.6

Please sign in to comment.