Skip to content

Commit

Permalink
Merge pull request #26 from tjjarvinen/atoms_base
Browse files Browse the repository at this point in the history
Add option to create PairList from AtomsBase structure
  • Loading branch information
cortner committed Nov 24, 2023
2 parents 37539ea + 58fbf81 commit 4acc475
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ uuid = "2fcf5ba9-9ed4-57cf-b73f-ff513e316b9c"
version = "0.5.5"

[deps]
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
julia = "1"
StaticArrays = "1"
AtomsBase = "0.3"
Unitful = "1"

[extras]
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
Expand Down
3 changes: 3 additions & 0 deletions src/NeighbourLists.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ include("iterators.jl")
# alternative assembly protocol more akin to mapreduce
include("mapreduce.jl")

# AtomsBase interface
include("atoms_base.jl")


end # module
18 changes: 18 additions & 0 deletions src/atoms_base.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using AtomsBase
using StaticArrays: SVector
using Unitful


function PairList(ab::AtomsBase.AbstractSystem, cutoff::Unitful.Length; length_unit=unit(cutoff))
cell = ustrip.(length_unit, hcat( bounding_box(ab)... )' )
pbc = map( boundary_conditions(ab) ) do x
x == Periodic()
end
r = map( 1:length(ab)) do i
# Need to have SVector here for PairList to work
# if position does not give SVector
SVector( ustrip.(length_unit, position(ab,i))...)
end
nlist = PairList(r, ustrip(length_unit, cutoff), cell, pbc; int_type=Int)
return nlist
end
10 changes: 10 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[deps]
ASEconvert = "3da9722f-58c2-4165-81be-b4d7253e8fd2"
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ println("# threads = $(Base.Threads.nthreads())")
@testset "NeighbourLists" begin
@testset "Aux" begin include("test_aux.jl") end
@testset "CellList" begin include("test_celllist.jl") end
include("test_atoms_base.jl")

# pointless until we switch to comparing against ASE / matscipy
# if hasjulip
Expand Down
19 changes: 19 additions & 0 deletions test/test_atoms_base.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using ASEconvert
using NeighbourLists
using Test
using Unitful

@testset "AtomsBase PairList" begin
cu = ase.build.bulk("Cu") * pytuple((4, 2, 3))
sys = pyconvert(AbstractSystem, cu)

nlist = PairList(sys, 3.5u"Å")

id, r = neigs(nlist,1)

@test length(id) == 12
end




0 comments on commit 4acc475

Please sign in to comment.