inchi
Safe, idiomatic Rust bindings to the IUPAC InChI reference library, for generating and parsing InChI and InChIKey chemical identifiers. The C library is vendored and statically linked via inchi-sys — no system install, no network at build time. No unsafe is exposed; native allocations are freed automatically.
Install
[]
= "0.1"
Example
From a Molfile/SDF record (pass () for default options):
use ;
let out = from_molfile?;
let inchi = out.inchi; // "InChI=1S/H2O/h1H2"
let key = inchikey?; // "XLYOFNOQVPJJNP-UHFFFAOYSA-N"
Or build a structure programmatically:
use ;
let mut mol = new;
let c = mol.add_atom;
let o = mol.add_atom;
mol.add_bond?;
let inchi = mol.to_inchi?.into_inchi;
Customize generation by passing Options instead of ():
use ;
let out = from_molfile?;
API
| Direction | Entry points |
|---|---|
| Structure → InChI | from_molfile, Molecule::to_inchi |
| InChI → structure | struct_from_inchi, struct_from_inchi_ex (polymers), struct_from_aux_info |
| InChI → InChIKey | inchikey, inchikey_with_hashes |
| Convert / validate | inchi_to_inchi, check_inchi, check_inchikey |
Generation is configured with Options (stereo, fixed-H, metals, tautomers, timeout, polymers, …). Polymers (CTFile SRU Sgroups) are supported via Options::polymers and Molecule::add_polymer_unit.
Full reference, semantics, and runnable examples: https://docs.rs/inchi.
Features
| Feature | Default | Description |
|---|---|---|
key |
yes | InChIKey computation (GetINCHIKeyFromINCHI). |
regenerate-bindings |
no | Regenerate FFI bindings with bindgen (needs libclang). |
Notes
- The InChI C library keeps
staticstate and is not re-entrant; all calls are serialized behind a global lock. The public types areSend + Sync. - MSRV: Rust 1.77. Raising it is a semver-breaking change.
License
MIT. Bundles the IUPAC InChI software (MIT); see inchi-sys.