Task tutorial

Create a descriptor CSV while retaining invalid SMILES rows

Read a SMILES column, calculate descriptors one row at a time, and write parsing failures beside the original input instead of dropping them.

You will make

A CSV report that preserves source-row identity, input SMILES, calculated values, and parse errors.

Steps

  1. Install the required packages with pip install chematic pandas.
  2. Create a CSV with a column named smiles.
  3. Parse each non-empty row with from_smiles and record a descriptor subset.
  4. Write both successful rows and invalid-SMILES rows to one report, then inspect status before filtering.
# pip install chematic pandas
import chematic
import pandas as pd

source = pd.read_csv("compounds.csv")
rows = []
for source_row, smiles in source["smiles"].dropna().astype(str).items():
    try:
        mol = chematic.from_smiles(smiles)
        rows.append({"source_row": source_row + 2, "smiles": smiles, "status": "ok",
                     "mw": mol.mw, "logp": mol.logp, "tpsa": mol.tpsa})
    except ValueError as error:
        rows.append({"source_row": source_row + 2, "smiles": smiles,
                     "status": "invalid_smiles", "error": str(error)})
pd.DataFrame(rows).to_csv("descriptor-report.csv", index=False)

Expected result

descriptor-report.csv has an explicit status for every non-empty input row. Successful rows have MW, LogP, and TPSA; invalid strings retain the input and parser error.

If it does not work

The faster bulk.descriptors API deliberately skips invalid SMILES. Use this row-preserving pattern first when you must reconcile output with a source table; only batch valid rows after that check.

Next action

Read the Python workflow guide