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

Implement isolated system for AB (#32) #33

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 20 additions & 3 deletions src/atoms_base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,30 @@ using Unitful


function PairList(ab::AtomsBase.AbstractSystem, cutoff::Unitful.Length; length_unit=unit(cutoff))
cell = ustrip.(length_unit, hcat( cell_vectors(ab)... )' )
pbc = periodicity(ab)
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)
if cell(ab) isa AtomsBase.IsolatedCell{3, <:Any}
# this only works in 3D
max_x = maximum(q->q[1], r)
max_y = maximum(q->q[2], r)
max_z = maximum(q->q[3], r)
min_x = minimum(q->q[1], r)
min_y = minimum(q->q[2], r)
min_z = minimum(q->q[3], r)
cell_matrix = SMatrix{3,3, typeof(max_x), 9}(
# add +1 for cell size
max_x - min_x + 1, 0., 0.,
0., max_y - min_y + 1, 0.,
0., 0., max_z - min_z + 1,
)
else
cell_matrix = ustrip.(length_unit, hcat( cell_vectors(ab)... )' )
end
pbc = periodicity(ab)

nlist = PairList(r, ustrip(length_unit, cutoff), cell_matrix, pbc; int_type=Int)
return nlist
end
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
AtomsBuilder = "f5cc8831-eeb7-4288-8d9f-d6c1ddb77004"
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Expand Down
20 changes: 20 additions & 0 deletions test/test_atoms_base.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#using ASEconvert
using AtomsBase
using AtomsBuilder
using NeighbourLists
using Test
Expand All @@ -12,6 +13,25 @@ using Unitful
id, r = neigs(nlist,1)

@test length(id) == 12

@testset "AtomsBase Isolated System" begin
isys = isolated_system([
:H => [0., 0., 0.]u"Å",
:H => [0., 0., 2.]u"Å",
:H => [0., 10., 0.]u"Å"
])
nlist = PairList(isys, 5.0u"Å")
id, r = neigs(nlist,1)
@test length(id) == 1
@test id[1] == 2
@test all( r[1] .≈ [0., 0., 2.] )
id, r = neigs(nlist,2)
@test length(id) == 1
@test id[1] == 1
@test all( r[1] .≈ [0., 0., -2.] )
id, r = neigs(nlist,3)
@test length(id) == 0
end
end


Expand Down
Loading