Skip to content

Commit

Permalink
Define indexing of subchains
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOresten committed May 16, 2024
1 parent ffe7268 commit d6eafbb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/protein/chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ end
@inline Base.size(chain::Chain) = Tuple(length(chain))
@inline Base.getindex(chain::Chain, i::Integer) = Residue(chain.resnums[i], chain.residue_atoms_dict[chain.resnums[i]], chain.aavector[i], chain.ssvector[i])

function Base.getindex(chain::Protein.Chain, I::AbstractVector{<:Integer})
backbone = Backbone(reshape(chain.backbone.coords, 3, 3, :)[:, :, I])
Protein.Chain(backbone; id=chain.id, modelnum=chain.modelnum, resnums=chain.resnums[I], aavector=chain.aavector[I], ssvector=chain.ssvector[I])
end

Base.summary(chain::Chain) = "Chain $(chain.id) with $(length(chain)) residue$(length(chain) == 1 ? "" : "s")"
Base.show(io::IO, chain::Chain) = print(io, summary(chain))

Expand Down

0 comments on commit d6eafbb

Please sign in to comment.