From d6eafbbc264aadc0cca12dd0301de6c0d6539a5c Mon Sep 17 00:00:00 2001 From: anton083 Date: Thu, 16 May 2024 16:12:09 +0200 Subject: [PATCH] Define indexing of subchains --- src/protein/chain.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/protein/chain.jl b/src/protein/chain.jl index 254b007..4ff1123 100644 --- a/src/protein/chain.jl +++ b/src/protein/chain.jl @@ -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))