use crate::parser::Rows;
use std::borrow::Cow;
#[doc(hidden)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum Field {
GroupPdb,
Id,
TypeSymbol,
LabelAtomId,
AuthAtomId,
LabelAltId,
LabelCompId,
AuthCompId,
LabelAsymId,
AuthAsymId,
LabelEntityId,
LabelSeqId,
AuthSeqId,
InsCode,
CartnX,
CartnY,
CartnZ,
Occupancy,
BFactor,
FormalCharge,
ModelNum,
}
impl Field {
pub const COUNT: usize = 21;
#[must_use]
pub const fn item(self) -> &'static str {
match self {
Self::GroupPdb => "group_PDB",
Self::Id => "id",
Self::TypeSymbol => "type_symbol",
Self::LabelAtomId => "label_atom_id",
Self::AuthAtomId => "auth_atom_id",
Self::LabelAltId => "label_alt_id",
Self::LabelCompId => "label_comp_id",
Self::AuthCompId => "auth_comp_id",
Self::LabelAsymId => "label_asym_id",
Self::AuthAsymId => "auth_asym_id",
Self::LabelEntityId => "label_entity_id",
Self::LabelSeqId => "label_seq_id",
Self::AuthSeqId => "auth_seq_id",
Self::InsCode => "pdbx_PDB_ins_code",
Self::CartnX => "Cartn_x",
Self::CartnY => "Cartn_y",
Self::CartnZ => "Cartn_z",
Self::Occupancy => "occupancy",
Self::BFactor => "B_iso_or_equiv",
Self::FormalCharge => "pdbx_formal_charge",
Self::ModelNum => "pdbx_PDB_model_num",
}
}
#[must_use]
pub fn from_item(item: &str) -> Option<Self> {
match item.as_bytes() {
b"group_PDB" => Some(Self::GroupPdb),
b"id" => Some(Self::Id),
b"type_symbol" => Some(Self::TypeSymbol),
b"label_atom_id" => Some(Self::LabelAtomId),
b"auth_atom_id" => Some(Self::AuthAtomId),
b"label_alt_id" => Some(Self::LabelAltId),
b"label_comp_id" => Some(Self::LabelCompId),
b"auth_comp_id" => Some(Self::AuthCompId),
b"label_asym_id" => Some(Self::LabelAsymId),
b"auth_asym_id" => Some(Self::AuthAsymId),
b"label_entity_id" => Some(Self::LabelEntityId),
b"label_seq_id" => Some(Self::LabelSeqId),
b"auth_seq_id" => Some(Self::AuthSeqId),
b"pdbx_PDB_ins_code" => Some(Self::InsCode),
b"Cartn_x" => Some(Self::CartnX),
b"Cartn_y" => Some(Self::CartnY),
b"Cartn_z" => Some(Self::CartnZ),
b"occupancy" => Some(Self::Occupancy),
b"B_iso_or_equiv" => Some(Self::BFactor),
b"pdbx_formal_charge" => Some(Self::FormalCharge),
b"pdbx_PDB_model_num" => Some(Self::ModelNum),
_ => None,
}
}
#[must_use]
pub const fn position(self) -> usize {
self as usize
}
}
#[doc(hidden)]
pub trait AtomSiteRow {
fn row(&self) -> usize;
fn text(&self, field: Field) -> Option<&str>;
fn identifier(&self, field: Field) -> Option<Cow<'_, str>>;
fn integer(&self, field: Field) -> Option<i64>;
fn float(&self, field: Field) -> Option<f64>;
fn is_recorded(&self, field: Field) -> bool;
}
#[doc(hidden)]
pub trait AtomSiteRowSink {
fn feed(&mut self, row: &dyn AtomSiteRow);
}
impl AtomSiteRow for Rows<'_> {
fn row(&self) -> usize {
Rows::row(self)
}
fn text(&self, field: Field) -> Option<&str> {
Rows::text(self, field.item())
}
fn identifier(&self, field: Field) -> Option<Cow<'_, str>> {
Rows::identifier(self, field.item())
}
fn integer(&self, field: Field) -> Option<i64> {
Rows::integer(self, field.item())
}
fn float(&self, field: Field) -> Option<f64> {
Rows::float(self, field.item())
}
fn is_recorded(&self, field: Field) -> bool {
Rows::is_recorded(self, field.item())
}
}