diff --git a/src/cells.jl b/src/cells.jl index d488c83..79f337d 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,9 +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}) where {T} + @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]) + apply_cell_boundaries!(cell, R[:, i]) end end apply_cell_boundaries!(::InfiniteCell, ::AbstractArray) = nothing @@ -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}) where {T} + @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 @@ -78,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 @@ -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