Task tutorial

Get a molecular formula and molecular weight from SMILES

Parse one SMILES in Python and print two basic calculated identifiers for a compact, traceable report.

You will make

A local record containing the input SMILES, calculated molecular formula, molecular weight, and package version.

Steps

  1. Install a pinned chematic version in a virtual environment.
  2. Parse a known complete SMILES such as CCO.
  3. Print the formula and molecular weight, then retain the exact input and package version with the result.
import chematic

smiles = "CCO"
mol = chematic.from_smiles(smiles)
print(smiles)
print(mol.formula)
print(f"{mol.mw:.2f} g/mol")

Expected result

For CCO, the program prints C2H6O and a molecular weight of about 46.07 g/mol. The input stays beside the calculated values.

If it does not work

A molecular formula does not uniquely identify a structure, and calculated molecular weight is not an experimental measurement. If parsing fails, retain the input and error rather than creating a partial record.

Next action

Read the Python workflow guide