Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

sdf-parser

cheminfo8.2kMIT7.0.4

SDF parser

sdf, parser, molfile, v2000, v3000, mdl

readme

sdf-parser

NPM version build status Test coverage npm download

Allow to parse a SDF file and convert it to an array of objects.

Use of the package

npm install sdf-parser

In node script:

// allows to parse a file test.sdf that would be present in the same directory

var { parse } = require('sdf-parser');

var fs = require('fs');
var sdf = fs.readFileSync('./test.sdf', 'utf-8');

var result = parse(sdf);
console.log(result);

require('sdf-parser') (sdf, options)

options:

  • exclude : array of string containing the fields to discard
  • include : array of string containing the fields to keep
  • modifiers : object of functions that need to be converted during the parsing
  • filter : function that allows to filter the result
  • mixedEOL : if set to true will try to deal with mixed End Of Line separator
  • dynamicTyping : convert fields containing only number to numbers (default: true)

Advanced example with filtering and modifiers

var result = parse(sdf, {
  exclude: ['Number of H-Donors'],
  include: ['Number of H-Donors', 'CLogP', 'Code'],
  modifiers: {
    CLogP: function (field) {
      return {
        low: field * 1 - 0.2,
        high: field * 1 + 0.2,
      };
    },
  },
  filter: (entry) => {
    return entry.CLogP && entry.CLogP.low > 4;
  },
});

Iterator

const { iterator } = require('sdf-parser');
const file = await openAsBlob(join(__dirname, 'test.sdf.gz'));

const decompressionStream = new DecompressionStream('gzip');
const textDecoder = new TextDecoderStream();

const stream = file
  .stream()
  .pipeThrough(decompressionStream)
  .pipeThrough(textDecoder);
const results = [];

for await (const entry of iterator(stream)) {
  results.push(entry);
}

License

MIT

changelog

Changelog

7.0.4 (2025-03-05)

Bug Fixes

  • do not yield molfile that has less than 40 characters long (dc0b2d7)

7.0.3 (2025-02-28)

Bug Fixes

  • iterator was adding a CR that yields to non parsable molfiles (5dc3afc)

7.0.2 (2025-02-27)

Bug Fixes

  • extension of rollup.config (6512f04)

7.0.1 (2025-02-27)

Bug Fixes

  • wrong file extension and CDN publication (bcb7572)

7.0.0 (2025-02-27)

⚠ BREAKING CHANGES

  • The stream should be piped through a TextDecoderStream like for example: const textDecoder = new TextDecoderStream(); for await (const entry of iterator(file.stream().pipeThrough(textDecoder)))

Features

  • update iterator implementation for browser compatibility (6a53960)
  • use and expose MolfileStream class (#16) (926b8cf)

Bug Fixes

  • remove side effect on options (2afdfc8)

6.0.1 (2022-10-15)

Bug Fixes

  • update dependencies and remove iterator from browser (f3275be)

6.0.0 (2022-08-22)

⚠ BREAKING CHANGES

  • remove stream function

Features

  • add iterator to parse huge sdf files (5c6fc9a)
  • remove stream function (6320c19)

5.0.2 (2022-08-17)

Bug Fixes

  • infinite loop with files without EOL in the EOF (#7) (9266761)

5.0.1 (2022-03-11)

Bug Fixes

5.0.0 (2021-10-14)

Features

  • migration to es6-module (03a6569)

4.0.2 (2020-06-27)

4.0.1 (2019-06-12)

Bug Fixes

4.0.0 (2019-06-12)

Bug Fixes

  • use pumpify instead of multipipe (aed47fd)

chore

Features

  • add support for stream async iteration (f41105e)

BREAKING CHANGES

  • The "dist" directory is no longer built and published.
  • Bower is no longer supported.

3.1.0 (2018-01-26)

3.0.1 (2018-01-06)

3.0.0 (2018-01-05)

Features

2.3.1 (2017-07-04)

2.3.0 (2017-07-04)

2.2.2 (2016-06-23)

2.2.1 (2016-06-07)

2.2.0 (2016-06-07)

2.1.1 (2016-06-06)

2.1.0 (2016-06-06)

2.0.1 (2016-05-21)

2.0.0 (2016-05-21)

1.0.1 (2015-06-10)

1.0.0 (2015-02-13)