pdbtbx/
reference_tables.rs

1#[cfg(feature = "rayon")]
2use rayon::prelude::*;
3
4/// Gets the index (into Int. Crys. Handbook Vol A 2016) for the given symbol. First it is
5/// interpreted as a Herman Mauguin symbol, if that is unsuccessful it is interpreted as a
6/// Hall symbol.
7pub fn get_index_for_symbol(symbol: impl AsRef<str>) -> Option<usize> {
8    let symbol = symbol.as_ref();
9    if let Some(index) = HERMANN_MAUGUIN_SYMBOL.iter().position(|i| *i == symbol) {
10        Some(index + 1)
11    } else {
12        HALL_SYMBOL.iter().position(|i| *i == symbol).map(|n| n + 1)
13    }
14}
15
16/// Gets the index (into Int. Crys. Handbook Vol A 2016) for the given symbol in parallel. First it is
17/// interpreted as a Herman Mauguin symbol, if that is unsuccessful it is interpreted as a
18/// Hall symbol.
19#[cfg(feature = "rayon")]
20#[allow(dead_code)]
21pub fn par_get_index_for_symbol(symbol: impl AsRef<str>) -> Option<usize> {
22    let symbol = symbol.as_ref();
23    if let Some(index) = HERMANN_MAUGUIN_SYMBOL
24        .par_iter()
25        .position_any(|i| *i == symbol)
26    {
27        Some(index + 1)
28    } else {
29        HALL_SYMBOL
30            .par_iter()
31            .position_any(|i| *i == symbol)
32            .map(|n| n + 1)
33    }
34}
35
36/// Gets the Herman Mauguin symbol for the given index (into Int. Crys. Handbook Vol A 2016)
37pub fn get_herman_mauguin_symbol_for_index(index: usize) -> Option<&'static str> {
38    HERMANN_MAUGUIN_SYMBOL.get(index - 1).copied()
39}
40
41/// Gets the Hall symbol for the given index (into Int. Crys. Handbook Vol A 2016)
42pub fn get_hall_symbol_for_index(index: usize) -> Option<&'static str> {
43    HALL_SYMBOL.get(index - 1).copied()
44}
45
46/// Gets the transformations given an index (into Int. Crys. Handbook Vol A 2016) for the given space group
47pub fn get_transformation(index: usize) -> Option<&'static [[[f64; 4]; 3]]> {
48    SYMBOL_TRANSFORMATION.get(index - 1).copied()
49}
50
51/// Returns if the given atom name is a common amino acid
52pub fn is_amino_acid(aa: impl AsRef<str>) -> bool {
53    AMINO_ACIDS.contains(&aa.as_ref())
54}
55
56/// Returns if the given atom name is a name for an atom in the backbone of a protein
57pub fn is_backbone(name: impl AsRef<str>) -> bool {
58    BACKBONE_NAMES.contains(&name.as_ref())
59}
60
61/// Returns if the given number is a valid remark-type-number (according to wwPDB v 3.30)
62pub fn valid_remark_type_number(number: usize) -> bool {
63    REMARK_TYPES.contains(&number)
64}
65
66/// The valid remark type numbers as of PDB v3.30
67const REMARK_TYPES: [usize; 42] = [
68    0, 1, 2, 3, 4, 5, 100, 200, 205, 210, 215, 217, 230, 240, 245, 247, 250, 265, 280, 285, 290,
69    300, 350, 375, 400, 450, 465, 470, 475, 480, 500, 525, 600, 610, 615, 620, 630, 650, 700, 800,
70    900, 999,
71];
72
73/// All amino acids. Includes Amber-specific naming conventions for (de-)protonated versions, CYS involved in
74/// disulfide bonding and the like.
75const AMINO_ACIDS: &[&str] = &[
76    "ALA", "ARG", "ASH", "ASN", "ASP", "ASX", "CYS", "CYX", "GLH", "GLN", "GLU", "GLY", "HID",
77    "HIE", "HIM", "HIP", "HIS", "ILE", "LEU", "LYN", "LYS", "MET", "PHE", "PRO", "SER", "THR",
78    "TRP", "TYR", "VAL", "SEC", "PYL",
79];
80
81/// The names of atom in the backbone of proteins
82const BACKBONE_NAMES: &[&str] = &[
83    "N", "CA", "C", "O", "H", "H1", "H2", "H3", "HA", "HA2", "HA3",
84];
85
86/// The list of Hermann Mauguin symbols in the same order as in the handbook
87const HERMANN_MAUGUIN_SYMBOL: &[&str] = include!("reference/hermann_mauguin_symbols.txt");
88
89/// The list of Hall crystal symmetry symbols in the same order as in the handbook (and the Hermann Mauguin table above)
90const HALL_SYMBOL: &[&str] = include!("reference/hall_symbols.txt");
91
92/// Reworked from CCTBX output (Jan 2021)
93const SYMBOL_TRANSFORMATION: &[&[[[f64; 4]; 3]]] =
94    include!("reference/crystal_transformations.txt");