Browser Usage¶
The package core is runtime-neutral. In the browser (or any WebAssembly environment) install onnxruntime-web and pass it as ort; everything else is unchanged.
npm install mlconfgen onnxruntime-web
Loading Weights Client-Side¶
The weights are not published on npm. A common pattern is to let the user pick the ONNX files from their own machine so that they are never uploaded or re-hosted:
import { createGenerator, seed } from "mlconfgen";
import * as ort from "onnxruntime-web";
const [egnnFile, adjFile] = fileInput.files; // <input type="file" multiple>
const gen = await createGenerator({
ort,
egnnOnnx: new Uint8Array(await egnnFile.arrayBuffer()),
adjMatSeerOnnx: new Uint8Array(await adjFile.arrayBuffer()),
diffusionSteps: 50,
});
seed(42);
const mols = await gen.generateConformers({
referenceContext: [89.87, 210.78, 217.78],
nAtoms: 20,
nSamples: 4,
});
egnnOnnx, adjMatSeerOnnx and finetuneCheckpointOnnx accept Uint8Array buffers in place of paths. Buffers fetched from your own server (fetch(url).then(r => r.arrayBuffer())) work the same way.
RDKit in the Browser¶
The bundled @rdkit/rdkit is resolved automatically for the runtime it finds. Three setups are supported, tried in order:
- A global
initRDKitModuledefined by a plain<script>tag. - A bundler (Vite, webpack, …) that interops the CommonJS build into a usable
defaultexport. - No bundler — the UMD build is injected as a classic script from the jsDelivr CDN.
To pin a specific RDKit build (e.g. a self-hosted WASM), pass rdkitLoader:
const gen = await createGenerator({
ort,
egnnOnnx,
adjMatSeerOnnx,
rdkitLoader: () =>
initRDKitModule({ locateFile: () => "/wasm/RDKit_minimal.wasm" }),
});
The loader is module-global: calling createGenerator without rdkitLoader resets it to the bundled default.
Failure modes¶
- If RDKit is configured but fails to initialise (e.g. the
.wasmcannot be fetched), generation throws an error namedRdkitLoadErrorrather than silently reporting every molecule as invalid. - Inside a Web Worker there is no DOM to inject a script into; pass an explicit
rdkitLoader(e.g. usingimportScripts).
Threads and Performance¶
onnxruntime-webruns on WebAssembly by default; enable multi-threading and SIMD throughort.env.wasm(e.g.ort.env.wasm.numThreads = 4) before creating the generator. Multi-threading requires cross-origin isolation headers.- The WebGPU execution provider can be selected through the
onnxruntime-websession options if your build supports it; the package passes model paths/bytes straight toort.InferenceSession.create. - Keep
nSamplessmall per call in the browser (1–10) and preferdiffusionStepsof20–50for interactive use. - Run generation in a Web Worker to keep the UI responsive; all package APIs are
asyncand worker-safe given an explicitrdkitLoader.
Smoke Viewer¶
The repository includes a minimal browser trajectory viewer (js/smoke/trajectory_viewer.html) served by npm run smoke, which demonstrates streaming frames from animateGeneration into a 3D view.