ferritin_core/views/
atom.rs

1//! Provides a read-only view into an atom from an AtomCollection.
2//!
3//! This module defines the `AtomView` struct, which is a lightweight handle that
4//! references an atom in an existing `AtomCollection` without taking ownership.
5//! It provides accessor methods to retrieve atom properties such as coordinates,
6//! element, name, residue information, and more.
7
8use crate::AtomCollection;
9use crate::info::elements::Element;
10
11pub struct AtomView<'a> {
12    pub(crate) data: &'a AtomCollection,
13    pub(crate) idx: usize,
14}
15
16impl<'a> AtomView<'a> {
17    pub fn new(data: &'a AtomCollection, idx: usize) -> Self {
18        AtomView { data, idx }
19    }
20    pub fn coords(&self) -> &'a [f32; 3] {
21        self.data.get_coord(self.idx)
22    }
23    pub fn element(&self) -> &'a Element {
24        self.data.get_element(self.idx)
25    }
26    pub fn atom_name(&self) -> &'a String {
27        self.data.get_atom_name(self.idx)
28    }
29    pub fn residue_id(&self) -> i32 {
30        *self.data.get_res_id(self.idx)
31    }
32    pub fn residue_name(&self) -> &'a String {
33        self.data.get_res_name(self.idx)
34    }
35    pub fn chain_id(&self) -> &'a String {
36        self.data.get_chain_id(self.idx)
37    }
38    pub fn is_hetero(&self) -> bool {
39        self.data.get_is_hetero(self.idx)
40    }
41    // Add index accessor if needed for direct access
42    pub fn index(&self) -> usize {
43        self.idx
44    }
45}