Task tutorial
Export a SMILES structure to an SVG file with Python
Create a local, scalable 2D structure file from one SMILES value and retain the exact input beside the artifact.
You will make
An aspirin.svg file created by the installed chematic Python package, with an explicit source SMILES record.
Steps
- Parse one complete SMILES locally with chematic.from_smiles.
- Generate the SVG string with mol.svg and write it as UTF-8 text.
- Open the file in a browser or vector editor, then retain the input and package version with the artifact.
from pathlib import Path
import chematic
smiles = "CC(=O)OC1=CC=CC=C1C(=O)O"
mol = chematic.from_smiles(smiles)
Path("aspirin.svg").write_text(mol.svg(), encoding="utf-8")
print({"input_smiles": smiles, "file": "aspirin.svg"})Expected result
aspirin.svg begins with SVG markup and opens as a scalable 2D aspirin structure. The printed record keeps the exact source SMILES and output filename together.
If it does not work
If parsing fails, correct the input before writing an artifact. An SVG is a 2D depiction, not an exchange format or proof of chemical identity, stereochemical intent, safety, or experimental validity.