molframe_pdb/writer/
identity.rs1use molframe_core::structure::{AtomRef, ChainRef, ResidueRef};
4
5#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
7pub enum PdbIdentifierNamespace {
8 #[default]
10 Label,
11 Auth,
13}
14
15impl PdbIdentifierNamespace {
16 pub(crate) const fn as_str(self) -> &'static str {
17 match self {
18 Self::Label => "label",
19 Self::Auth => "auth",
20 }
21 }
22}
23
24pub(crate) fn chain_name(chain: ChainRef<'_>, namespace: PdbIdentifierNamespace) -> Option<&str> {
25 match namespace {
26 PdbIdentifierNamespace::Label => chain.label(),
27 PdbIdentifierNamespace::Auth => chain.auth_label(),
28 }
29}
30
31pub(crate) fn residue_sequence(
32 residue: ResidueRef<'_>,
33 namespace: PdbIdentifierNamespace,
34) -> Option<i32> {
35 match namespace {
36 PdbIdentifierNamespace::Label => residue.label_seq_id(),
37 PdbIdentifierNamespace::Auth => residue.auth_seq_id(),
38 }
39}
40
41pub(crate) fn atom_name(atom: AtomRef<'_>, namespace: PdbIdentifierNamespace) -> Option<&str> {
42 match namespace {
43 PdbIdentifierNamespace::Label => atom.name(),
44 PdbIdentifierNamespace::Auth => atom.auth_name(),
45 }
46}
47
48pub(crate) fn component_name<'a>(
49 atom: AtomRef<'a>,
50 residue: ResidueRef<'a>,
51 namespace: PdbIdentifierNamespace,
52) -> Option<&'a str> {
53 match namespace {
54 PdbIdentifierNamespace::Label => atom.component_name(),
55 PdbIdentifierNamespace::Auth => residue.auth_name(),
56 }
57}