Registry / data / sdf-parser

sdf-parser

JSON →
library8.0.0jsnpmunverified

sdf-parser is a JavaScript/TypeScript library designed to parse Structure-Data File (SDF) format files, which are commonly used in cheminformatics to represent chemical structures and associated data. It efficiently converts the content of SDF files into an array of JavaScript objects, where each object represents a chemical entry including its molfile and associated data fields. The current stable version is 8.0.0. The package maintains an active release cadence, with frequent updates. Key features include robust parsing with options for field inclusion/exclusion, custom data transformations via modifiers, and filtering capabilities based on entry properties. For processing large SDF files, it offers an `iterator` API that leverages web streams for memory-efficient handling, compatible with both Node.js and browser environments.

npm install sdf-parser
INSTALL
IMPORT
SIG · SDF-PARSER
S
sdf-parser
datajavascriptv8.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import { parse } from 'sdf-parser';
const { parse } = require('sdf-parser');
Since v8.0.0, sdf-parser is an ESM-only package. CommonJS `require` syntax will not work.
iterator
import { iterator } from 'sdf-parser';
const { iterator } = require('sdf-parser');
v8.0.0 is ESM-only. The `iterator` function, introduced in v6.0.0, requires piping input through a `TextDecoderStream` since v7.0.0 for proper text decoding.
SDFEntry
import type { SDFEntry } from 'sdf-parser';
For TypeScript projects, import `SDFEntry` type for type-safe handling of parsed SDF objects.

This quickstart demonstrates both the synchronous `parse` function for smaller SDF strings, including options for filtering and modifying fields, and the asynchronous `iterator` function for efficient processing of larger SDF data via streams, highlighting the `TextDecoderStream` requirement.

import { parse, iterator } from 'sdf-parser'; import { Readable } from 'node:stream'; // For Node.js to create a stream from string import { TextDecoderStream } from 'node:stream/web'; // For Node.js compatibility with Web Streams API // Example SDF content with multiple entries const sdfData = ` MOLFILE -OEChem-0104201804252D 5 5 0 0 0 0 0 0 0 0999 V2000 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 1.5000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 0.0000 1.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 1.5000 1.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 3.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 1 3 1 0 0 0 0 2 4 1 0 0 0 0 3 4 1 0 0 0 0 2 5 1 0 0 0 0 M END > <ID> CHEM_1 > <CLogP> 2.5 $$$$ MOLFILE -OEChem-0104201804252D 3 2 0 0 0 0 0 0 0 0999 V2000 0.0000 0.0000 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 1.5000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 3.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 2 3 1 0 0 0 0 M END > <ID> CHEM_2 > <CLogP> -1.2 $$$$ `; // --- Example 1: Parsing a full SDF string synchronously --- const parsedEntries = parse(sdfData, { include: ['ID', 'CLogP'], modifiers: { CLogP: (value: string) => parseFloat(value) // Convert CLogP field to a number }, filter: (entry: any) => entry.CLogP > 0 // Keep only entries with positive CLogP }); console.log('Parsed Entries (filtered by CLogP > 0):', parsedEntries); // --- Example 2: Iterating over an SDF stream (for large files) --- async function processSDFStream() { // In Node.js, create a ReadableStream from string data. // For actual files, use `fs.createReadStream('your.sdf').pipeThrough(new TextDecoderStream())` const streamFromData = Readable.from([sdfData]) .pipeThrough(new TextDecoderStream()); // Crucial for v7.0.0+ for iterator const iteratedEntries = []; try { for await (const entry of iterator(streamFromData)) { iteratedEntries.push(entry); } console.log('Iterated Entries (all from stream):', iteratedEntries); } catch (error) { console.error('Error during stream iteration:', error); } } processSDFStream();
Debug
Known issues
breakingVersion 8.0.0 migrated the library to TypeScript and set `type: module` in `package.json`. This means the package is now ESM-only and CommonJS `require()` statements will no longer work.
fix
Update all `require()` calls to `import` statements (e.g., `const { parse } = require('sdf-parser');` becomes `import { parse } from 'sdf-parser';`). Ensure your project is configured for ESM or use a bundler that supports ESM.
affects: >=8.0.0
breakingVersion 7.0.0 introduced a breaking change to the `iterator` function, requiring the input stream to be piped through a `TextDecoderStream`. This was done for browser compatibility and ensures correct text decoding.
fix
When using `iterator`, ensure your stream is processed with `stream.pipeThrough(new TextDecoderStream())`. For example: `for await (const entry of iterator(file.stream().pipeThrough(new TextDecoderStream())))`.
affects: >=7.0.0
breakingVersion 6.0.0 removed the `stream` function entirely. This function was replaced by the more flexible and memory-efficient `iterator` function.
fix
Migrate any usage of the `stream` function to the `iterator` function. The `iterator` function provides an asynchronous iterable interface for processing SDF entries one by one.
affects: >=6.0.0
gotchaWhen working with compressed SDF files (e.g., `.sdf.gz`), you'll need to pipe the stream through a decompression stream *before* piping it through `TextDecoderStream` and feeding it to `iterator`.
fix
For gzipped files, the stream pipeline should look like: `file.stream().pipeThrough(new DecompressionStream('gzip')).pipeThrough(new TextDecoderStream())`.
affects: >=6.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use CommonJS `require` syntax with sdf-parser v8.0.0 or later, which is an ESM-only package.
fix
Change `const { symbol } = require('sdf-parser');` to `import { symbol } from 'sdf-parser';` and ensure your project is configured for ES Modules.
TypeError: 'for await...of' expects an async iterable, but received an object
Attempting to use the `iterator` function in v7.0.0+ without piping the input stream through `new TextDecoderStream()`.
fix
Modify your stream pipeline to include `pipeThrough(new TextDecoderStream())` before passing it to `iterator`. Example: `iterator(yourStream.pipeThrough(new TextDecoderStream()))`.
The stream() method is not defined on this object.
Trying to use the `stream` function which was removed in sdf-parser v6.0.0.
fix
Replace calls to the deprecated `stream` function with the `iterator` function. `iterator` provides similar functionality but with an asynchronous iterable interface.
Upgrade
Version history
8.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
sdf-parser — npm install sdf-parser · libregistry