Skip to content

Commit

Permalink
simplity eachresidue iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed Sep 30, 2024
1 parent e32332d commit c97e687
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Residue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ julia> for res in eachresidue(atoms)
eachresidue(atoms::AbstractVector{Atom}) = EachResidue(atoms)

# Collect residues default constructor
Base.collect(r::EachResidue) = collect(Residue, r)
Base.collect(residues::EachResidue) = collect(Residue, residues)
Base.length(residues::EachResidue) = sum(1 for residue in residues)
Base.firstindex(residues::EachResidue) = 1
Base.lastindex(residues::EachResidue) = length(residues)
Expand All @@ -143,14 +143,10 @@ Base.length(residue::Residue) = length(residue.range)
Base.eltype(::Residue) = Atom

#
# Iterate over residues of a structure
# Iterate, lazily, over residues of a structure
#
function Base.iterate(residues::EachResidue, current_atom=nothing)
if isnothing(current_atom)
current_atom = 1
elseif current_atom > length(residues.atoms)
return nothing
end
function Base.iterate(residues::EachResidue, current_atom=firstindex(residues.atoms))
current_atom > length(residues.atoms) && return nothing
next_atom = current_atom + 1
while next_atom <= length(residues.atoms) &&
same_residue(residues.atoms[current_atom], residues.atoms[next_atom])
Expand Down

0 comments on commit c97e687

Please sign in to comment.