SDF to SVG
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.
Examples
Command Line Usage
$ sdftosvg ./input.sdf ./output.svg
Command Line Arguments
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
NPM Package Usage
var renderer = ; // Convert SDF as string to SVGvar fs = ;var sdf = fs;renderer; // Convert SDF file to SVG filerenderer;
Methods
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
Options
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"
Todo
A number of features remain to be added:
- Allow specifying custom color scheme on the command line.
- Allow further customization of output