Local identity
Identity can be computed from the structure you drew — offline,
through reference software. The InChI algorithm is never
reimplemented: an engine wraps an InChI implementation behind one
contract, and the pipe is always
Model::Molecule → molfile → engine → InChI/InChIKey. Without an
engine, every derivation raises an explicit error with install
guidance — there is no silent fallback.
This page is the Ruby (and binding) seam. The authoritative Rust crate needs none of it: chemomer rides in-process as a version-pinned dependency — no FFI, no engine registration (see Rust).
The engine contract
Section titled “The engine contract”AsciiChem::Inchi.engine = ... # register once, or pass engine: per callAsciiChem::Inchi.identity_for(molecule)# => #<AsciiChem::Inchi::Identity inchi: "InChI=1S/...", inchikey: "BSYNRYMUTXBXSQ-UHFFFAOYSA-N">Two engines ship with the gem; both are opt-in external artifacts — the core gem stays dependency-free.
Engine 1: the IUPAC inchi-1 binary
Section titled “Engine 1: the IUPAC inchi-1 binary”AsciiChem::Inchi::BinaryEngine shells out to the standalone IUPAC
binary (inchi-trust.org downloads):
AsciiChem::Inchi.engine = AsciiChem::Inchi::BinaryEngine.newAsciiChem::Inchi.engine = AsciiChem::Inchi::BinaryEngine.new(bin: "/usr/local/bin/inchi-1")From the CLI, --engine-bin points at a binary for one invocation:
asciichem identity -i "CC(=O)OC1=CC=CC=C1C(=O)O" --from smilesasciichem identity -i "..." --engine-bin /usr/local/bin/inchi-1The engine stages the molfile to a temp file and reads the output
file back — the distributed binary’s file interface is the contract
(-STDIO is not part of it). Without any engine, asciichem identity exits 5 with install guidance.
Engine 2: the native Rust engine (chemomer)
Section titled “Engine 2: the native Rust engine (chemomer)”chemomer is a native Rust
InChI engine — canonical numbering, every standard layer (mobile-H
groups, tetrahedral and double-bond stereo), and the InChIKey with a
dependency-free SHA-256 — gated byte-exactly against the recorded
IUPAC 1.07.5 oracle corpus
(chemomer/inchi-tests,
pinned at v0.3.41). It ships as a Rust library, a C ABI (cdylib),
and Python/WASM/Node bindings — no third-party binary at runtime.
The C ABI also exports the AuxInfo line (chemomer_aux_from_molfile).
The Ruby gem reaches it through NativeEngine over the C ABI (FFI
loads lazily):
AsciiChem::Inchi.engine = AsciiChem::Inchi::NativeEngine.newAsciiChem::Inchi.engine = AsciiChem::Inchi::NativeEngine.new(lib: "/path/libchemomer.dylib")Build the cdylib once from an engine checkout and point CHEMOMER_LIB
at it (or install the dylib on the loader’s search path):
cargo build --release # in the chemomer checkoutexport CHEMOMER_LIB=$PWD/target/release/libchemomer.dylibThe same engine ships ready-made for other stacks — each binding is its own thin package over the same C ABI:
| Stack | Package | Call |
|---|---|---|
| Rust | crates.io chemomer | Engine::from_molfile(mol) → inchi_string() / inchikey() |
| Node / WASM | npm chemomer | from_molfile(text) / aux_from_molfile(text) / inchikey(text) |
| Python | PyPI chemomer | inchi, inchikey = chemomer.from_molfile(text) |
| Ruby | RubyGems chemomer | inchi, inchikey = Chemomer.from_molfile(text) |
What crosses into the engine
Section titled “What crosses into the engine”- Connectivity, charges, isotopes cross through the V2000 molfile block.
- Tetrahedral chirality is written as MDL atom parity; stated hydrogens become the H-count field — so enantiomers derive different InChIs.
- Directional bonds (
/,\) need stereo-aware 2D geometry, which the molfile emitted here does not carry. The loss is documented and asserted, never silent.
Identity derivation needs exactly one molecule; formulas with several (or reactions) are rejected with a count in the message.
Reactions: RInChI
Section titled “Reactions: RInChI”Reactions get the same treatment through RInChI — the reaction is
written as an MDL RXN file and passed to the opt-in IUPAC
rinchi_cmdline binary
(built against InChI v1.07.5):
AsciiChem::Rinchi.engine = AsciiChem::Rinchi::BinaryEngine.newAsciiChem::Rinchi.identity_for(reaction).long_rinchikeyLike the InChI engines, it is opt-in: without it, derivation raises
EngineMissingError with build instructions.
The linter tie-in
Section titled “The linter tie-in”With an engine configured, the linter’s IdentityCrossCheck derives
every @inchi/@inchikey-annotated molecule’s identifier and asserts
agreement with what you actually drew — catching transcription errors
that format validation cannot. Without an engine it emits one guidance
warning. See the Linter reference.