A CSV of SMILES can become a table of calculated molecular formulas and molecular weights. Retaining the compound ID and original SMILES on each row makes it easy to join the results back to your working table.
A public question about generating formulas from an Excel or CSV list describes this task. This walkthrough uses five compounds to produce formula-report.csv on your device.
Put the CSV and script in one folder
Download compounds.csv and formula_csv.py. The input has three columns:
source_id,name,smiles
CMP001,acetic acid,CC(=O)O
CMP002,ethanol,CCO
CMP003,aspirin,CC(=O)Oc1ccccc1C(=O)O
The sample also contains ethyl acetate and sodium acetate. For your own table, put a unique tracking ID for each row in source_id and the structure in smiles. The optional name column holds a display name.
Calculate the formulas and molecular weights
Open a terminal in that folder. On macOS or Linux, run:
python3 -m venv .venv
.venv/bin/python -m pip install "chematic==1.1.2"
.venv/bin/python formula_csv.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 use .\.venv\Scripts\python.exe in place of .venv/bin/python. After package installation, file reading and calculations run on your device.
For each SMILES, the script calculates mol.formula and mol.mw. Its output retains source_id and the original smiles, and adds formula, mw_g_mol, processing status, and engine version.
Join the results to your table
These results were checked with the published Python package v1.1.2. mol.mw uses average atomic masses. The CSV records the corresponding molar mass in g/mol to two decimal places.
source_id formula mw_g_mol
CMP001 C2H4O2 60.05
CMP002 C2H6O 46.07
CMP003 C9H8O4 180.16
CMP004 C4H8O2 88.11
CMP005 C2H3NaO2 82.03
The sodium acetate result includes the sodium present in the input. To apply a consistent salt-handling policy, combine the workflow with recorded standardization settings.
Open the example output CSV and join its columns to your original table using source_id. Rows marked status=ok have been calculated. For status=review, check the error column against the original SMILES. The tested package and checks are recorded in the execution record.