use std::collections::BTreeMap;
use crate::query::{AtomQueryPredicate, QueryNode};
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ChiralTag {
Unspecified,
TetrahedralCw,
TetrahedralCcw,
TrigonalBipyramidal,
}
macro_rules! impl_chiral_tag_metadata {
($($variant:path => ($code:literal, $name:literal, $from_rdkit:literal)),+ $(,)?) => {
impl ChiralTag {
#[must_use]
pub const fn python_code(self) -> i64 {
match self {
$($variant => $code,)+
}
}
#[must_use]
pub const fn rdkit_name(self) -> &'static str {
match self {
$($variant => $name,)+
}
}
#[must_use]
pub fn from_rdkit_name(name: &str) -> Option<Self> {
match name {
$($from_rdkit => Some($variant),)+
_ => None,
}
}
}
};
}
impl_chiral_tag_metadata! {
ChiralTag::Unspecified => (0, "CHI_UNSPECIFIED", "CHI_UNSPECIFIED"),
ChiralTag::TetrahedralCw => (1, "CHI_TETRAHEDRAL_CW", "CHI_TETRAHEDRAL_CW"),
ChiralTag::TetrahedralCcw => (2, "CHI_TETRAHEDRAL_CCW", "CHI_TETRAHEDRAL_CCW"),
ChiralTag::TrigonalBipyramidal => (
3,
"CHI_TRIGONALBIPYRAMIDAL",
"CHI_TRIGONALBIPYRAMIDAL"
),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Atom {
pub index: usize,
pub atomic_num: u8,
pub is_aromatic: bool,
pub formal_charge: i8,
pub explicit_hydrogens: u8,
pub no_implicit: bool,
pub num_radical_electrons: u8,
pub chiral_tag: ChiralTag,
pub isotope: Option<u16>,
pub atom_map_num: Option<u32>,
pub props: BTreeMap<String, String>,
pub query: Option<QueryNode<AtomQueryPredicate>>,
#[doc(hidden)]
pub rdkit_cip_rank: Option<i64>,
}
impl Atom {
#[must_use]
pub fn prop(&self, key: &str) -> Option<&str> {
self.props.get(key).map(String::as_str)
}
#[must_use]
pub fn prop_f64(&self, key: &str) -> Option<f64> {
self.prop(key)?.parse().ok()
}
}