# Open Source SDF (Chemical Table File) Parser in any language

I'm looking to parse a large .sdf file and put it into a .csv file.

The only software I could find that parses .sdf files is OpenBabel's Pybel, but it won't properly install for my El Capitan, for either python2.7 or 3.+. (It's an open issue, and might hopefully be fixed with the next release). Are there any other languages/OSs that can easily parse this file? If there aren't any, is there a recommended operating system I could spin up with VirtualBox that will easily run OpenBabel/Pybel?

• Instead of using python why not use Notepad++ or Atom (both free) to extract the data you want (using column select tool) or use their syntax to convert to csv. Alternatively you could write a small python prog just to read data you have. If you look at some .sdf files you will soon see that the way data is organised is very clear. – porphyrin Jul 13 '16 at 8:07
• afaik, chemsketch has scripting capabilities. But it isn't opensource, just freeware. – permeakra Jul 13 '16 at 12:22
• I'm not sure what "open issue" you indicate. I run Open Babel and Pybel all the time on El Capitan. Please contact me (or the Babel mailing list). As indicated below, there are many tools for parsing SD files. – Geoff Hutchison Jul 28 '16 at 15:54

The free, open-source RDKit chemoinformatics software can read .sdf files. This software is most often used via it's Python API.

I recommend installing it via conda. (If you use python regularly but don't use conda for controlling environments and package distribution, you probably should.) The installation command is conda install -c https://conda.anaconda.org/rdkit rdkit .

The python code to parse an sdf file and write to a csv file is very simple.

import pandas as pd
from rdkit import Chem
from rdkit.Chem import PandasTools

my_sdf_file = '/Users/curt/Desktop/sdf-isothiocyanates.sdf'

smilesName='SMILES',
molColName='Molecule',
includeFingerprints=False)

frame.to_csv('/Users/curt/Desktop/excel_isothiocyanates.csv')


The .png below has some stand alone python that will read .sdf files and produce comma separated output. Its come out rather small but should still be readable. You can run the code from Atom on an apple mac or notepad++ on a pc.

You can also have a look at Bioclipse, which mixes a graphical interface with scripting (JavaScript, Python, and Groovy):

I blogged about an example script for Bioclipse before, which looks like:

hmdbIndex =
molTable.createSDFIndex(
"/WikiPathways/hmdb.sdf"
);
props = new java.util.HashSet();