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

Ring polymer cellboundary #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
25 changes: 20 additions & 5 deletions src/cells.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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
Expand All @@ -71,14 +77,23 @@ 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

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
Expand All @@ -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
end
Loading