smiles-rs 0.1.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.

What it does

  • Canonicalization: canonicalize and canonical_labeling give a canonical SMILES and a canonical atom ordering.
  • Aromaticity perception: perceive_aromaticity under the RDKit default, MDL and simple models, plus kekulize back to alternating bonds.
  • Maximum common edge subgraph: mces compares two molecules through geometric-traits.
  • Ring analysis: symmetrized SSSR, ring membership, and fragment and connected component decomposition.
  • Atom environments: atom_environment yields radius-bounded neighbourhoods, the basis for MAP4-style fingerprints.
  • Stereochemistry: tetrahedral and double bond configuration, preserved across canonicalization.
  • Molecular formulas: conversion into molecular-formulas types.
  • Wildcard SMILES: WildcardSmiles accepts * atoms, and conversion back into Smiles is fallible.
  • Public corpora: PubChem, ZINC20, COCONUT, LOTUS and MassSpecGym stream from a local cache behind the datasets feature.

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 Fetches and streams public SMILES corpora, requires std. See datasets.
fuzzing Exposes the parser internals the fuzz targets drive.