smiles-rs 0.2.0

A SMILES parser producing molecular graphs, with no_std support
Documentation

smiles-rs

crates.io docs.rs downloads Rust CI codecov License: MIT MSRV

Parses SMILES strings into molecular graphs, following the OpenSMILES specification. no_std with alloc, no unsafe code.

Beyond parsing it canonicalizes molecules through canonicalize and canonical_labeling, perceives aromaticity under the RDKit default, MDL and simple models, and kekulizes back to alternating bonds. It computes symmetrized SSSR rings and ring membership, fragments and connected components, radius-bounded atom environments for MAP4-style fingerprints, and the maximum common edge subgraph of two molecules through geometric-traits. Tetrahedral and double bond stereochemistry survive canonicalization, formulas convert into molecular-formulas types, and WildcardSmiles accepts * atoms with a fallible conversion back into Smiles.

Example

use core::str::FromStr;

use molecular_formulas::prelude::ChemicalFormula;
use smiles_rs::prelude::Smiles;

let ethanol = Smiles::from_str("CCO")?;

assert_eq!(ethanol.nodes().len(), 3);
assert_eq!(ethanol.number_of_bonds(), 2);
assert_eq!(ethanol.render(), "CCO");

let formula: ChemicalFormula<u32, i32> = ChemicalFormula::from(&ethanol);
assert_eq!(formula.to_string(), "C₂H₆O");
# Ok::<(), smiles_rs::SmilesErrorWithSpan>(())

Features

Feature Effect
datasets Streams PubChem, ZINC20, COCONUT, LOTUS and MassSpecGym from a local cache, requires std. See datasets.
fuzzing Exposes the parser internals the fuzz targets drive.