Silent Spring Institute

subscribe via RSS, or follow us on Github.

Developer Blog

What do chemicals look like?

sdftosvg is an NPM package for rendering chemical structures

If you look at the structures of chemicals within a family, you can see striking similarities. Take PCBs, which are industrial chemicals that were banned in the 1970s, as an example:

PCB 11 PCB 105 PCB 201

We wanted a way to generate beautiful chemical structure visualizations, like the ones you see above, for use in our materials. We developed a lightweight tool called sdftosvg that does just that: it takes as input SDF files, downloadable from repositories like PubChem, and outputs SVG renderings.

Installation

sdftosvg is available as an NPM package.

$ npm install -g sdftosvg

Example

The chemical triclosan is used as an anti-microbial in soaps, oral care products, and other consumer products. The PubChem page for triclosan has an SDF file available that defines triclosan’s structure. We can convert the SDF to an svg using sdftosvg:

$ sdftosvg triclosan.sdf triclosan.svg

Triclosan

Full documentation for the project is available on the project’s Github page.