When another molecular application needs structures from your spreadsheet, an SDF can carry both the molecular records and your compound IDs. This recipe converts a SMILES CSV to SDF, retaining each compound’s ID, name, source SMILES, and input record number.
A public question about converting an Excel SMILES column to molecular files began with a downstream application that did not accept Excel. Changing the file extension does not convert a CSV table into SDF records. The structures need to be parsed and written in the destination format.
Prepare the input
Save compounds.csv and csv_to_sdf.py in the same directory.
source_id,name,smiles
CMP001,acetic acid,CC(=O)O
CMP002,ethanol,CCO
CMP003,aspirin,CC(=O)Oc1ccccc1C(=O)O
The sample contains five compounds. For your own table, put the structures in smiles and your identifiers in source_id. Give every row a nonempty, unique ID so you can join the exported structures to experimental or calculated results later.
Write the SDF
In the directory containing the CSV and script, run these commands on macOS or Linux:
python3 -m venv .venv
.venv/bin/python -m pip install "chematic==1.1.2"
.venv/bin/python csv_to_sdf.py compounds.csv
These commands require Python; the examples were checked on macOS arm64 with Python 3.13.6. On Windows, use py -m venv .venv for the first line and replace .venv/bin/python with .\.venv\Scripts\python.exe. After package installation, conversion happens on your computer. The outputs are compounds.sdf and sdf-export-report.csv, which records each input row.
The script uses SDWriter to save structures with 2D depiction coordinates. It puts the compound ID in the record’s title line and writes these SDF properties:
compound_id: the source identifiercompound_name: the source namesource_smiles: the SMILES exactly as suppliedsource_row: the input record number, starting at 2 after the headerengine_version: the chematic version used for conversion
The coordinates in this output are two-dimensional. For computational chemistry that requires 3D structures, choose a subsequent coordinate-generation and optimization procedure.
Read the IDs back
Before handing the SDF to another application, read back the saved identifiers. Save this as check_sdf.py in the same directory:
import chematic
for mol in chematic.SDMolSupplier("compounds.sdf"):
print(mol.GetProp("compound_id"), mol.formula, mol.GetProp("source_smiles"))
.venv/bin/python check_sdf.py
The sample produces this output with the published chematic Python package v1.1.2:
CMP001 C2H4O2 CC(=O)O
CMP002 C2H6O CCO
CMP003 C9H8O4 CC(=O)Oc1ccccc1C(=O)O
CMP004 C4H8O2 CCOC(C)=O
CMP005 C2H3NaO2 CC(=O)[O-].[Na+]
We checked that all five IDs and their source SMILES could be read back. Count status=written rows in the export report to reconcile the record count with your input. In applications that display a property beside each structure, select compound_id to connect the structures to your original table.
Download the output SDF, export report, and execution record. The API implementation is available in the Python format I/O source.