Convert sdf to csv

Convert SDF to CSV

Export chemical SDF records, SD tags, and SMILES to CSV with Open Babel, RDKit, or KNIME.

Make CSV files online

We can't read SDF files yet, so this conversion isn't available. If you can export your work to one of these formats - or others - we'll turn it into CSV:

How to convert sdf to csv file

Compound libraries are often supplied as chemical SDF files, but Excel, LIMS imports, reporting systems, and database loaders usually require a flat CSV table. Exporting SD tags and a structure identifier lets each compound occupy one CSV row while retaining data needed for filtering or matching.

Identify the type of SDF file

This procedure applies to a chemical Structure Data File, also called an SD file. It stores one or more molecular connection tables (atoms and bonds), optional named properties called SD tags, and normally ends each record with $$$$.

ChemDraw, BIOVIA software, RDKit, Open Babel, docking tools, compound-registration systems, and chemical databases such as PubChem use chemical SDF files. A chemical SDF is plain text and can usually be recognized by atom/bond blocks and $$$$ separators.

The .sdf extension is ambiguous. SQL Server Compact databases and Autodesk spatial-data files may also use it; they are databases, not chemical SD files. Export a selected table from SQL Server Compact or a selected spatial layer from compatible GIS/CAD software, because a multi-table or multi-layer database cannot be faithfully converted into one CSV without choosing or joining data first.

What CSV retains

CSV stores tabular values as delimiter-separated columns. Spreadsheet programs, R, Python pandas, database import utilities, and many LIMS/reporting products can read it.

CSV can contain compound names, identifiers, SD tags, assay results, calculated descriptors, and a structure string such as isomeric SMILES or InChI. It cannot natively store an SDF connection table, molecular coordinates, or original record layout. Keep the original SDF as the structure archive, and include SMILES when the recipient must reconstruct molecules.

Convert with Open Babel

Open Babel is a suitable local option for quick command-line conversion. After installing it, run the following command from the folder containing the source file:

obabel input.sdf -ocsv -O output.csv

Open the result and verify its headings, delimiter, and included properties before importing it elsewhere. Open Babel CSV output and property handling can differ by version, so use RDKit when a receiving system requires exact column names, ordering, or all SD tags.

Convert with RDKit

Install RDKit, for example with conda install -c conda-forge rdkit. The following script creates one row per valid molecule, writes the record title and isomeric SMILES, and copies every ordinary SD tag.

from rdkit import Chem
import csv

supplier = Chem.SDMolSupplier("input.sdf", removeHs=False)
rows = []
tags = set()

for mol in supplier:
    if mol is None:
        continue
    properties = list(mol.GetPropNames())
    tags.update(properties)
    row = {
        "Record_name": mol.GetProp("_Name") if mol.HasProp("_Name") else "",
        "Isomeric_SMILES": Chem.MolToSmiles(mol, isomericSmiles=True)
    }
    for tag in properties:
        row[tag] = mol.GetProp(tag)
    rows.append(row)

columns = ["Record_name", "Isomeric_SMILES"] + sorted(tags)
with open("output.csv", "w", newline="", encoding="utf-8") as file:
    writer = csv.DictWriter(file, fieldnames=columns, extrasaction="ignore")
    writer.writeheader()
    writer.writerows(rows)

Save it as sdf_to_csv.py and run python sdf_to_csv.py. Replace columns with a fixed list if an importer demands a particular schema or column order. RDKit skips records it cannot parse, so compare the output row count with the expected number of $$$$-separated records and inspect parsing warnings.

Use a desktop workflow

KNIME Analytics Platform provides a graphical, repeatable workflow for users who do not want to script. Use an SDF Reader node, convert the molecular column to SMILES with the RDKit integration, select the SD-tag columns required by the destination, and connect a CSV Writer node. Configure the delimiter, quote character, and UTF-8 encoding in the writer.

DataWarrior can inspect an SDF, expose SD tags as columns, filter records, and calculate descriptors before export. Confirm its selected text-export delimiter and include a SMILES column rather than assuming an exported table preserves molecular structures.

Online services and import caveats

Do not upload proprietary, regulated, or large compound collections to generic conversion websites. Many online converters do not preserve SD tags or molecular structures. PubChem PUG-REST can return CSV properties for known public PubChem CIDs, but it does not convert arbitrary local SDF files or preserve their original tags.

CSV fields containing commas, quotation marks, or line breaks must be quoted; Python's csv module does this automatically. Use UTF-8, and import the file in Excel through Data → From Text/CSV rather than opening it directly. Assign identifiers such as 00123, long registry numbers, and scientific-notation-like values the Text type to prevent unwanted numeric conversion.

Canonical SMILES generally preserves defined molecular connectivity and ordinary stereochemistry, but it does not preserve 2D/3D coordinates, drawing layout, all enhanced stereochemical-group information, or every SDF-specific record feature. Include InChI or InChIKey for identity matching where required, but do not treat a compound name as a unique structural identifier.