Skip to content

Detailed NMR Implementation Roadmap (High-Performance Module) ​

This document outlines the four-phase implementation strategy for the NMR spectroscopy module in sci-form, focusing on topological HOSE codes, static database integration, 3D J-coupling, and Lorentzian signal generation.


Phase 1: Topological Engine and HOSE Codes ​

The foundation of the NMR module is an ultra-fast topological analyzer inspired by the RDKit descriptor generation logic.

1.1 Concentric Environment Scanning ​

  • Algorithm: Traverse the molecular graph in concentric spheres (radius R=0 to 5) around each atom.
  • Node Invariants: Assign unique identifiers to each atom based on element, hybridization, formal charge, and connectivity.
  • Path Length: Target up to 4 or 5 bonds of distance to capture long-range induction and resonance effects.

1.2 HOSE Code Hashing ​

  • Logic: Generate a unique, deterministic alphanumeric hash for each atomic environment at each sphere level.
  • Optimization: Leverage the existing graph structure (petgraph) and bitwise operations to ensure hashing completes in nanoseconds.

Phase 2: Static Database Compilation (WASM-Friendly) ​

Status 2026-11-08: the runtime loader is implemented (nmr::HoseDatabase, JSON/CSV/TSV, longest-prefix lookup and the predict_chemical_shifts_with_hose_database override). The NMRShiftDB2/SDBS data is not bundled because its CC-BY-SA review is external; users can supply their own export. The pre-compiled phf table below remains the optional next step for a self-contained WASM bundle.

Since a heavy relational database cannot be bundled in the WASM/CLI binary, we use a pre-compiled static lookup system.

2.1 Pre-processing Pipeline (External Script) ​

  • Source: Parse open dataset from NMRShiftDB.
  • Transformation: For every reported atom, calculate its HOSE codes (R=1…5) and extract the experimental chemical shift (ppm).
  • Averaging: Average the ppm values for identical HOSE hashes to build a robust statistical dictionary.

2.2 Native Integration (Perfect Hashing) ​

  • Crate Choice: Use the phf crate (Perfect Hash Functions) or a custom compressed binary format to store the dictionary.
  • Binary Size: Optimize the storage to ensure the WASM bundle remains lightweight while retaining high prediction coverage.

Phase 3: Additivity Rules and 3D J-Couplings ​

A hybrid approach combines topological lookups with empirical rules and 3D geometric data.

3.1 Empirical Additivity (Backstop) ​

  • Logic: If a perfect HOSE match (R=5) isn't found, fall back to R=4,3,… and apply Empirical Additivity Rules.
  • Adjustment: Add/subtract ppm offsets based on neighboring functional groups (e.g., electronegative atoms, carbonyls, aromatic rings).

3.2 3D J-Couplings (Karplus Equation) ​

  • Input: Extract 3-bond dihedral angles (ϕ) from the 3D conformer generated by the sci-form core engine.
  • Formula: Implement the Karplus Equation (3JHH=Acos2⁡ϕ+Bcos⁡ϕ+C) to estimate spin-spin coupling constants in Hz.
  • Multiplets: Use topological connectivity to determine split patterns (singlets, doublets, triplets, etc.).

Phase 4: Signal Generation and Public API ​

The final stage converts calculated shifts and couplings into a visually accurate spectrum.

4.1 Lorentzian Smearing ​

  • Function: Implement Lorentzian broadening: L(x)=1πγ(x−x0)2+γ2.
  • Physics: Lorentzian shapes better represent the natural line width of NMR signals compared to Gaussian broadening.
  • Integration: Sum individual signals to produce the final continuous spectral curve.

4.2 Multi-Interface API ​

  • CLI: Command-line tool to output ppm/intensity tables or SVG plots.
  • Python (PyO3): Seamless integration for data science workflows (NumPy/Pandas friendly).
  • WASM: High-performance TypeScript bindings for interactive browser-based NMR viewers.

Verification & Benchmarks ​

Tags: [NMR, RDKit-inspired, Rust, Molecular Topology, WASM, High-Performance] ​

Performance Target: ​

  • Prediction Speed: Microsecond-range for 1H/13C shift predictions.
  • Memory Footprint: < 5MB overhead for the static HOSE database.
  • Accuracy: Mean Absolute Error (MAE) < 0.5 ppm for 1H and < 3.0 ppm for 13C.

Released under the MIT License.