Convert one or more SDF files into CSV tables using RDKit.
The script extracts molecule properties from SDF records, adds a molecule index, computes canonical SMILES, and attempts to generate an InChIKey for each readable molecule.
- Accepts individual SDF files, directories, or glob patterns.
- Writes one CSV per SDF by default.
- Can combine multiple SDF files into one CSV.
- Recursively searches directories for
.sdffiles. - Attempts to continue when individual molecules cannot be sanitized.
- Adds
mol_index,Name,SMILES, andInChIKeycolumns.
- Python 3.8+
- pandas
- RDKit
Recommended installation with conda:
conda install -c conda-forge rdkit pandasConvert a single SDF file:
python sdf2csv.py compounds.sdfThis writes:
compounds.csv
in the current directory.
Write the CSV file to a specific folder:
python sdf2csv.py compounds.sdf --outdir csv_outor:
python sdf2csv.py compounds.sdf -o csv_outConvert all SDF files in a folder:
python sdf2csv.py sdf_files --outdir csv_outConvert files matching a pattern:
python sdf2csv.py *.sdf --outdir csv_outCombine all input SDF files into a single CSV:
python sdf2csv.py sdf_files --outdir csv_out --combineSet the combined output filename:
python sdf2csv.py sdf_files --outdir csv_out --combine --outname all_compounds.csvWhen --combine is used, the output includes a source_file column.
Print progress and warnings:
python sdf2csv.py sdf_files --outdir csv_out --verboseThe script prioritizes these columns:
mol_indexNameSMILESInChIKey
Any additional SDF properties are preserved as extra CSV columns.
Unreadable molecules are skipped with warnings. If a molecule cannot be sanitized, the script still tries to extract available properties and compute SMILES/InChIKey.