mod element;
mod pool;
mod select;
use std::path::PathBuf;
pub use element::Element;
pub use pool::{StringPool, Sym};
pub use select::{AltLocPolicy, AtomSet, ChainIdKind, ModelChoice, Selection, WATER_RESIDUES};
use crate::diag::Diagnostics;
use crate::io::Format;
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct AtomRecord {
pub serial: u32,
pub name: Sym,
pub alt_loc: Option<char>,
pub res_name: Sym,
pub chain: Sym,
pub label_chain: Sym,
pub res_seq: i32,
pub label_seq: Option<i32>,
pub ins_code: Option<char>,
pub position: [f64; 3],
pub occupancy: f32,
pub b_factor: f32,
pub element: Option<Element>,
pub formal_charge: i8,
pub het: bool,
pub radius: Option<f32>,
pub partial_charge: Option<f32>,
}
impl AtomRecord {
pub fn new(position: [f64; 3]) -> Self {
Self {
serial: 0,
name: Sym::EMPTY,
alt_loc: None,
res_name: Sym::EMPTY,
chain: Sym::EMPTY,
label_chain: Sym::EMPTY,
res_seq: 0,
label_seq: None,
ins_code: None,
position,
occupancy: 1.0,
b_factor: 0.0,
element: None,
formal_charge: 0,
het: false,
radius: None,
partial_charge: None,
}
}
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct Model {
pub number: i32,
pub atoms: Vec<AtomRecord>,
}
impl Model {
pub fn new(number: i32) -> Self {
Self {
number,
atoms: Vec::new(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct Source {
pub format: Format,
pub path: Option<PathBuf>,
pub data_block: Option<String>,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Structure {
pub models: Vec<Model>,
pub strings: StringPool,
pub source: Source,
pub diagnostics: Diagnostics,
}
impl Structure {
pub fn str(&self, sym: Sym) -> &str {
self.strings.get(sym)
}
pub fn atom_count(&self) -> usize {
self.models.iter().map(|m| m.atoms.len()).sum()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn atom_record_stays_compact() {
assert!(size_of::<AtomRecord>() <= 96, "{}", size_of::<AtomRecord>());
}
}