Convert CSV to SDF
Convert chemical CSV records with SMILES or InChI into validated SDF files.
Convert CSV files online
We don’t have a dedicated online converter for CSV to SDF yet, but you can convert CSV files online to these and more formats:
How to convert csv to sdf file
- Databases
- No ratings yet.
Laboratory and cheminformatics programs often require an SDF file when a spreadsheet, instrument, or database exports compound records as CSV. The conversion works only when the CSV contains a chemical structure representation, such as SMILES; names, formulas, and assay values alone cannot create molecular geometry.
What the CSV format is
CSV is a plain-text tabular format in which records are separated by line breaks and fields are separated by commas or another delimiter. Excel, LibreOffice Calc, laboratory instruments, inventory systems, databases, and scripts commonly produce CSV files.
A chemical CSV may contain columns such as ID, Name, SMILES, InChI, Formula, CAS, and measured properties. Before importing it, identify the delimiter, quoting rules, character encoding, decimal convention, header names, and structure column. A CSV containing only names, formulas, or registry numbers requires an external chemical database lookup before it can become a structure file.
What the SDF format is
In cheminformatics, SDF means Structure Data File, also called an SD file. Each record contains a Molfile structure block followed by tagged property fields, for example > <ID> and > <Activity>. Records end with a line containing $$$$.
SDF can store atom and bond connectivity, formal charges, stereochemistry, 2D or 3D coordinates, and compound metadata in one file. Unlike a normal spreadsheet, it represents the molecular graph required by many chemical editors, registration systems, screening tools, and modelling programs. SDF property names and supported Molfile versions vary between applications, so the receiving program’s requirements should be checked.
The .sdf extension can also refer to a SQL Server Compact database. The procedures below apply to the chemical Structure Data File format; a SQL Server Compact file requires database export or table-level data migration instead.
Convert the file with DataWarrior
- Ensure that the CSV contains a valid
SMILES,InChI, or another notation supported by the software. Keep identifiers and property values on the same row as their structure. - Open DataWarrior and choose File → Open, then select the CSV. In the import dialog, set the delimiter, text encoding, decimal format, and quoted-field handling.
- Verify that DataWarrior has classified the structure column as chemical structures rather than ordinary text. Inspect invalid, blank, and unexpectedly disconnected entries.
- Choose File → Save Special → SD-file and select the structure and metadata columns to export if prompted. Save the result with an
.sdfextension. - Reopen the output in DataWarrior or a second chemical application. Check several structures, stereocenters, charges, coordinates, and property values.
DataWarrior is a practical local graphical option for moderate-sized files because it can interpret chemical columns, display structures, and export SD files. Menu labels can differ between releases.
Convert repeatably with Python and RDKit
RDKit is appropriate for automated or large conversions. This example expects a comma-delimited file with a SMILES column and optionally an ID column. Every other nonempty column becomes an SDF property.
import csv
import sys
from rdkit import Chem
source, target = sys.argv[1], sys.argv[2]
reader = csv.DictReader(open(source, newline='', encoding='utf-8-sig'))
writer = Chem.SDWriter(target)
for row_number, row in enumerate(reader, start=2):
smiles = (row.get('SMILES') or '').strip()
molecule = Chem.MolFromSmiles(smiles)
if molecule is None:
print(f'Skipping row {row_number}: invalid SMILES', file=sys.stderr)
continue
for key, value in row.items():
if key and key != 'SMILES' and value not in (None, ''):
molecule.SetProp(key, value)
writer.write(molecule)
writer.close()
Install RDKit through Conda, save the code as csv_to_sdf.py, and run:
python csv_to_sdf.py input.csv output.sdf
The script parses connectivity and chemical attributes from SMILES but does not generate coordinates. Add RDKit coordinate generation, such as 2D depiction coordinates, or use a chemical editor if the destination application requires 2D or 3D coordinates. Change the reader configuration when the source uses a semicolon, tab, or another delimiter.
Use Open Babel after preprocessing
Open Babel converts recognised chemical text formats, but it is not a general-purpose CSV table importer. First extract the structure column into a SMILES file, retaining identifiers and properties through a separate script or a tool that supports them. Then generate an SDF with:
obabel compounds.smi -O output.sdf --gen2D
Use --gen3D only when calculated conformations are acceptable; generated coordinates are not experimental measurements and may not represent the preferred conformation.
Online options for public data
Generic online file converters normally rename or repackage text and cannot validate SMILES, resolve identifiers, or preserve chemical stereochemistry. For a small list of nonconfidential public compounds, use a chemical resolver such as NIH Chemical Identifier Resolver or PubChem PUG REST to retrieve SDF records from names, CAS numbers, CIDs, or other supported identifiers. These services are lookup interfaces rather than dependable bulk CSV-to-SDF converters; a script is usually needed to submit each row, handle failed matches, and combine the returned records. Do not upload proprietary structures, assay data, or regulated records to an online service without approval.
Quality and compatibility checks
- Count records: compare the number of valid input structures with the number of SDF records, and retain a report of skipped or unresolved rows.
- Check chemical interpretation: malformed SMILES, unsupported valence states, missing charges, tautomer differences, and ambiguous or lost stereochemistry can change the resulting molecule.
- Check coordinates: SMILES normally describes connectivity, not coordinates. A destination that displays or calculates with 3D positions may require coordinate generation and force-field optimization.
- Protect tabular values: spreadsheets can remove leading zeros, convert long identifiers to scientific notation, alter dates, and change decimal separators. Export UTF-8 CSV and quote fields containing commas, line breaks, or quotation marks.
- Check property compatibility: SDF field names are not completely standardized. Duplicate names, punctuation, spaces, field length, data types, and Molfile version support can cause import failures.
- Validate independently: open the output in a second chemical application and inspect representative salts, mixtures, isotopes, charges, stereocenters, and records containing long or multiline properties.