use chematic_core::Molecule;
pub fn expand_abbreviation(symbol: &str) -> Option<Molecule> {
let smiles = ABBREVIATIONS
.iter()
.find(|(s, _)| *s == symbol)
.map(|(_, sm)| *sm)?;
chematic_smiles::parse(smiles).ok()
}
pub fn abbreviations() -> &'static [(&'static str, &'static str)] {
ABBREVIATIONS
}
static ABBREVIATIONS: &[(&str, &str)] = &[
("Me", "C"),
("Et", "CC"),
("Pr", "CCC"),
("iPr", "CC(C)"),
("Bu", "CCCC"),
("iBu", "CC(C)C"),
("tBu", "CC(C)(C)C"),
("nBu", "CCCC"),
("sBu", "CCC(C)"),
("Pent", "CCCCC"),
("Hex", "CCCCCC"),
("Ac", "CC(=O)"),
("Boc", "CC(C)(C)OC(=O)"),
("Cbz", "O=C(OC[*])c1ccccc1"),
("Fmoc", "O=C(O[*])OCC1c2ccccc2-c2ccccc21"),
("Ph", "c1ccccc1"),
("Bn", "Cc1ccccc1"),
("Np", "c1ccc2ccccc2c1"), ("Py", "c1ccncc1"), ("OMe", "OC"),
("OEt", "OCC"),
("NHMe", "NC"),
("NMe2", "N(C)C"),
("CF3", "C(F)(F)F"),
("CCl3", "C(Cl)(Cl)Cl"),
("CN", "C#N"),
("NO2", "[N+](=O)[O-]"),
("TMS", "[Si](C)(C)C"),
("TBS", "[Si](C)(C)CC(C)(C)C"),
("Ts", "Cc1ccc(cc1)S(=O)(=O)"),
("Ms", "CS(=O)(=O)"),
("Tf", "C(F)(F)(F)S(=O)(=O)"),
];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_expand_me() {
let mol = expand_abbreviation("Me").unwrap();
assert_eq!(mol.atom_count(), 1);
}
#[test]
fn test_expand_ph() {
let mol = expand_abbreviation("Ph").unwrap();
assert_eq!(mol.atom_count(), 6);
}
#[test]
fn test_expand_cf3() {
let mol = expand_abbreviation("CF3").unwrap();
assert_eq!(mol.atom_count(), 4);
}
#[test]
fn test_unknown_returns_none() {
assert!(expand_abbreviation("Xyz123").is_none());
}
#[test]
fn test_abbreviations_slice_non_empty() {
assert!(!abbreviations().is_empty());
}
}