ferritin_core/views/
model_chain.rs1use super::model_residue::ModelResidueView;
2use crate::model::Model;
3
4pub struct ModelChainView<'a> {
6 pub(crate) model: &'a Model,
7 pub(crate) chain_idx: usize,
8}
9
10impl<'a> ModelChainView<'a> {
11 pub(crate) fn new(model: &'a Model, chain_idx: usize) -> Self {
12 ModelChainView { model, chain_idx }
13 }
14
15 pub fn chain_id(&self) -> &'a str {
16 &self.model.hierarchy.chains.auth_asym_id[self.chain_idx]
17 }
18
19 pub fn iter_residues(&self) -> impl Iterator<Item = ModelResidueView<'a>> + '_ {
20 let range = self.model.hierarchy.residues_in_chain(self.chain_idx);
21 let model = self.model;
22 range.map(move |res_idx| ModelResidueView::new(model, res_idx))
23 }
24
25 pub fn residue_count(&self) -> usize {
26 let range = self.model.hierarchy.residues_in_chain(self.chain_idx);
27 range.end - range.start
28 }
29}