This is a javascript package for rendering SDF chemical structure files as SVGs.
sdftosvg
is built with PubChem SDF files in mind, because PubChem includes extra helpful annotations in their structure files.
$ sdftosvg ./input.sdf ./output.svg
Usage: convert [options] <input> <output>
Options:
-h, --help output usage information
-V, --version output the version number
-w, --width <n> Output width
-h, --height <n> Output height
-b, --background <background> Background color
var renderer = require('sdftosvg');
// Convert SDF as string to SVG
var fs = require('fs');
var sdf = fs.readFileSync('./pcb-138.sdf');
renderer.renderSdfToSvg(sdf, {}, function(svg) {
console.log(svg);
});
// Convert SDF file to SVG file
renderer.renderSdfToSvgFile('./pcb-138.sdf', './pcb-138.svg');
renderSdfToSvg(sdf, options, callback)
Renders an SDF string to an SVG string.
sdf
: string containing SDF file contentsoptions
: options object, defined belowcallback
: function called after rendering that is given output SVG as a string
renderSdfToSvgFile(inputFile, outputFile, options)
Renders an SDF file to an SVG file.
inputFile
: path to input SDF fileoutputFile
: path to save output SVG fileoptions
: options object, defined below
The options object can contain the following keys:
-
width
: output width, in pixels -
height
: output height, in pixels -
atomRadius
: radius of atom circles -
bondStrokeWidth
: stroke width of bond lines -
backgroundColor
: background color -
colors
: object mapping chemical abbreviations to colors. By default, sdftosvg uses the JMol color scheme. For example, to override:{ "C": "red", "O": "blue", "H": "green" }
A number of features remain to be added:
- Allow specifying custom color scheme on the command line.
- Allow further customization of output