Open Reaction Database Schema (JavaScript)

raw JSON →
0.5.1 verified Sat Apr 25 auth: no javascript

Compiled protobuf definitions for the Open Reaction Database, a structured format for capturing organic reaction data. This npm package (v0.5.1) provides the generated protobuf messages (e.g., Reaction, Compound) for Node.js and browser via protobuf.js. Updated irregularly alongside the ORD schema. Key differentiator: enables programmatic access to the standardized ORD schema for reaction data interchange, supporting datasets, conditions, outcomes, and analyses. Used for reading/writing reaction records, validating against the ORD spec, and integrating with ORD-compatible datasets. Ships TypeScript declarations.

error Error: Invalid type: expected Message, got Object
cause Passing a plain JavaScript object to a method that expects a protobuf message instance.
fix
Use the .create() static method to construct the message: Reaction.create(obj) instead of plain obj.
error TypeError: Reaction.verify is not a function
cause Importing the package incorrectly (e.g., using namespace import instead of named import).
fix
Use named import: import { Reaction } from 'ord-schema-protobufjs'.
error Error: Value for field 'units' is not a valid enum value.
cause Using a string that does not match the exact enum value (e.g., 'CELSIUS' vs 'CELCIUS' typo).
fix
Use the numeric enum value from the generated constants, e.g., Temperature.TemperatureUnit.CELSIUS.
error Module not found: Can't resolve 'ord-schema-protobufjs'
cause Missing dependency or incorrect npm install.
fix
Run: npm install ord-schema-protobufjs --save
breaking In v0.5.0, the 'write_dataset' function signature changed from (dataset, path) to (dataset, path, options).
fix Update calls to write_dataset(..., { format: 'parquet' }) to match new signature.
deprecated The 'Dataset' message may be replaced by 'DatasetView' in future versions; use DatasetView for new code.
fix Migrate to DatasetView and write_dataset for Parquet support.
gotcha Compound.CompoundIdentifier enumeration values are integers; using string literals will fail validation.
fix Always reference enum fields like Compound.CompoundIdentifier.SMILES instead of 'SMILES'.
gotcha The Reaction message requires nested objects to match proto schema exactly; extra fields will be ignored or throw in strict mode.
fix Use Reaction.create() to ensure correct structure; avoid raw object assignment.
npm install ord-schema-protobufjs
yarn add ord-schema-protobufjs
pnpm add ord-schema-protobufjs

Creates a simple reaction with SMILES identifiers, conditions, and demonstrates encode/decode round-trip.

import { Reaction, Compound } from 'ord-schema-protobufjs';

// Create a new Reaction message
const reaction = Reaction.create({
  identifiers: [{ value: 'OCCO', type: Compound.CompoundIdentifier.SMILES }],
  inputs: {
    'substrate': {
      components: [{
        substance: {
          identifiers: [{ value: 'CCO', type: Compound.CompoundIdentifier.SMILES }]
        }
      }]
    }
  },
  conditions: {
    temperature: { setpoint: { value: 80, units: 'CELSIUS' } },
    time: { duration: { value: 2, units: 'HOUR' } }
  }
});

// Verify the message
const err = Reaction.verify(reaction);
if (err) throw Error(err);

// Encode to binary
const buffer = Reaction.encode(reaction).finish();
console.log('Encoded length:', buffer.length);

// Decode back
const decoded = Reaction.decode(buffer);
console.log('Decoded reaction temperature:', decoded.conditions?.temperature?.setpoint?.value);