From 5c249ce97cab05084e93726948a20f1c6643efb0 Mon Sep 17 00:00:00 2001 From: Alexander Spears <39826690+Alexsp32@users.noreply.github.com> Date: Thu, 2 May 2024 11:39:25 +0100 Subject: [PATCH 1/2] Add ring-polymer versions of cell boundary methods --- src/cells.jl | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/cells.jl b/src/cells.jl index d488c83..8e384fa 100644 --- a/src/cells.jl +++ b/src/cells.jl @@ -38,11 +38,11 @@ Base.eltype(::PeriodicCell{T}) where {T} = T function PeriodicCell(vectors::AbstractMatrix) vectors = austrip.(vectors) - PeriodicCell{eltype(vectors)}(vectors, [true, true, true]) + PeriodicCell{eltype(vectors)}(vectors, [true, true, true]) end function PeriodicCell(vectors::AbstractMatrix{<:Integer}) - PeriodicCell{Float64}(vectors, [true, true, true]) + PeriodicCell{Float64}(vectors, [true, true, true]) end function set_periodicity!(cell::PeriodicCell, periodicity::AbstractVector{Bool}) @@ -54,6 +54,12 @@ function set_vectors!(cell::PeriodicCell, vectors::AbstractMatrix) cell.inverse .= inv(cell.vectors) end +function apply_cell_boundaries!(cell::PeriodicCell, R::AbstractArray{T, 3}) + @views for i in axes(R, 3) # beads + apply_cell_boundaries!(cell, R[:,:,i]) + end +end + function apply_cell_boundaries!(cell::PeriodicCell, R::AbstractMatrix) @views for i in axes(R, 2) # atoms apply_cell_boundaries!(cell, R[:,i]) @@ -71,6 +77,15 @@ function apply_cell_boundaries!(cell::PeriodicCell, R::AbstractVector) mul!(R, cell.vectors, cell.tmp_vector1) end +function check_atoms_in_cell(cell::PeriodicCell, R::AbstractArray{T,3}) + @views for i in axes(R, 3) # beads + if !check_atoms_in_cell(cell, R[:,:,i]) + return false + end + end + return true +end + """ check_atoms_in_cell(cell::PeriodicCell, R::AbstractMatrix)::Bool @@ -89,4 +104,4 @@ function evaluate_periodic_distance(cell::PeriodicCell, r1::AbstractVector, r2:: mul!(cell.tmp_vector1, cell.inverse, r1) mul!(cell.tmp_vector2, cell.inverse, r2) evaluate(periodic_distance, cell.tmp_vector1, cell.tmp_vector2) -end \ No newline at end of file +end From 860d2e52cddf2126c8d4d11f760cebef89129a78 Mon Sep 17 00:00:00 2001 From: Alexander Spears <39826690+Alexsp32@users.noreply.github.com> Date: Fri, 3 May 2024 12:46:24 +0100 Subject: [PATCH 2/2] Update ring-polymer versions of cell boundary methods --- src/cells.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cells.jl b/src/cells.jl index 8e384fa..79f337d 100644 --- a/src/cells.jl +++ b/src/cells.jl @@ -54,15 +54,15 @@ function set_vectors!(cell::PeriodicCell, vectors::AbstractMatrix) cell.inverse .= inv(cell.vectors) end -function apply_cell_boundaries!(cell::PeriodicCell, R::AbstractArray{T, 3}) +function apply_cell_boundaries!(cell::PeriodicCell, R::AbstractArray{T,3}) where {T} @views for i in axes(R, 3) # beads - apply_cell_boundaries!(cell, R[:,:,i]) + apply_cell_boundaries!(cell, R[:, :, i]) end end function apply_cell_boundaries!(cell::PeriodicCell, R::AbstractMatrix) @views for i in axes(R, 2) # atoms - apply_cell_boundaries!(cell, R[:,i]) + apply_cell_boundaries!(cell, R[:, i]) end end apply_cell_boundaries!(::InfiniteCell, ::AbstractArray) = nothing @@ -77,9 +77,9 @@ function apply_cell_boundaries!(cell::PeriodicCell, R::AbstractVector) mul!(R, cell.vectors, cell.tmp_vector1) end -function check_atoms_in_cell(cell::PeriodicCell, R::AbstractArray{T,3}) +function check_atoms_in_cell(cell::PeriodicCell, R::AbstractArray{T,3}) where {T} @views for i in axes(R, 3) # beads - if !check_atoms_in_cell(cell, R[:,:,i]) + if !check_atoms_in_cell(cell, R[:, :, i]) return false end end @@ -93,7 +93,7 @@ True if all atoms are inside the cell, false otherwise. """ function check_atoms_in_cell(cell::PeriodicCell, R::AbstractMatrix)::Bool @views for i in axes(R, 2) # atoms - mul!(cell.tmp_vector1, cell.inverse, R[:,i]) + mul!(cell.tmp_vector1, cell.inverse, R[:, i]) @. cell.tmp_bools = (cell.tmp_vector1 > 1) | (cell.tmp_vector1 < 0) any(cell.tmp_bools) && return false end