diff --git a/.gitignore b/.gitignore index 2c3bc5d..8583cfa 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /docs/build/ .DS_Store +.vscode/ \ No newline at end of file diff --git a/src/struct.jl b/src/struct.jl index 041cbbf..fcf7ce0 100644 --- a/src/struct.jl +++ b/src/struct.jl @@ -1,33 +1,13 @@ struct Lattice{T} - vectors::AbstractMatrix{T} - pbc::AbstractVector{Bool} + vectors::Matrix{T} + pbc::Vector{Bool} end struct Ion{T} - species::String + species::Symbol charge::Int - frac_pos::AbstractVector{T} + frac_pos::Vector{T} end -function periodic_vectors(lattice::Lattice{T}) where T - periodic_vectors = Matrix{T}(undef, size(lattice.vectors)[1], sum(lattice.pbc)) - for column in range(1, size(lattice.vectors)[2]) - if lattice.pbc[column] - periodic_vectors[:, column] = lattice.vectors[:, column] - end - end - return periodic_vectors -end - -function build_grid(nsize::AbstractVector{Int}) - function decompose(n::Int) - remain = n - result = Vector{Int}(undef, length(nsize)) - for i in range(1, length(nsize)) - result[i] = remain รท prod(nsize[i+1:end]) - remain = remain % prod(nsize[i+1:end]) - end - return result - end - return [decompose(n) for n in range(0, prod(nsize) - 1)] -end \ No newline at end of file +periodic_vectors(lattice::Lattice) = lattice.vectors[:, lattice.pbc] +build_grid(nsize::AbstractVector{Int}) = map(x->collect(x.I[end:-1:1] .- 1), vec(CartesianIndices(Tuple(nsize[end:-1:1])))) \ No newline at end of file diff --git a/test/interaction.jl b/test/interaction.jl index 2435bbb..5a99cfa 100644 --- a/test/interaction.jl +++ b/test/interaction.jl @@ -7,8 +7,8 @@ using CrystalStructurePrediction end @testset "real_space_sum" begin - ion_a = Ion("", rand(3), 1) - ion_b = Ion("", rand(3), 2) + ion_a = Ion(:none, 1, rand(3)) + ion_b = Ion(:none, 2, rand(3)) lattice = Lattice(rand(3,3), [true, true, true]) alpha = 2.0 for depth in range(0,4) @@ -18,8 +18,8 @@ end end @testset "reciprocal_space_sum" begin - ion_a = Ion("", rand(3), 1) - ion_b = Ion("", rand(3), 2) + ion_a = Ion(:none, 1, rand(3)) + ion_b = Ion(:none, 2, rand(3)) lattice = Lattice(rand(3,3), [true, true, true]) alpha = 2.0 for depth in range(0,4) @@ -29,8 +29,8 @@ end end @testset "buckingham_sum" begin - ion_a = Ion("Sr", rand(3), 1) - ion_b = Ion("O", rand(3), 2) + ion_a = Ion(:Sr, 1, rand(3)) + ion_b = Ion(:O, 2, rand(3)) lattice = Lattice(rand(3,3), [true, true, true]) for depth in range(0,4) depth_list = [depth for _ in range(1,3)]