Parse, validate, lightly clean, and summarise SMILES strings using RDKit.
The script can read SMILES directly from the command line or from a text file, then writes a CSV report containing parsing status, canonical SMILES, formula, molecular weight, InChIKey, and atom counts.
- Accepts SMILES from command-line arguments or a plain text file.
- Validates structures with RDKit.
- Optionally applies a simple cleanup pass for noisy explicit-hydrogen strings.
- Calculates useful molecular properties.
- Writes a structured CSV report with one row per input SMILES.
- Python 3.8+
- RDKit
Recommended installation with conda:
conda install -c conda-forge rdkitPass one or more SMILES strings with --smiles:
python parse_smiles.py --smiles "CCO" "O=C(O)C" -o results.csvUse --infile for a text file containing one SMILES string per line.
An example file, my_smiles.txt, is included in this folder and can be used for a quick test:
python parse_smiles.py --infile my_smiles.txt --out smiles_parsed.csvBy default, the script tries a simple cleanup pass if RDKit cannot parse the original SMILES.
The cleanup is intentionally basic and targets noisy explicit hydrogen patterns such as:
O[H][H]- Empty parentheses left after removing
[H]
This can help with exported or messy SMILES, but it may alter the intended chemistry. To disable this behavior:
python parse_smiles.py --infile my_smiles.txt --out smiles_parsed.csv --no-cleanThe output CSV contains:
input_smiles: original input stringused_smiles: original or cleaned string used for successful parsingstatus: parsing resulterror: error details when parsing failscanonical_smilesisomeric_smilesformulamol_wtexact_mwinchi_keynum_atomsnum_heavy_atoms
python parse_smiles.py --infile my_smiles.txt --out smiles_parsed.csvExpected terminal output:
Wrote 7 rows to smiles_parsed.csv
Open smiles_parsed.csv to inspect which structures parsed successfully and which, if any, failed.