Task tutorial
Export a reaction SMILES diagram to SVG with Python
Write a local, scalable reaction diagram from a reaction SMILES record and retain the exact source alongside the artifact.
You will make
An esterification.svg reaction diagram produced locally from one explicit reaction SMILES string.
Steps
- Set one reaction SMILES record in reactants>>products form.
- Generate an SVG string with chematic.reaction_svg and write it as UTF-8 text.
- Open the file in a browser or vector editor, then retain the exact reaction SMILES and package version with the artifact.
from pathlib import Path
import chematic
reaction_smiles = "CC(=O)O.CCO>>CC(=O)OCC.O"
svg = chematic.reaction_svg(reaction_smiles)
Path("esterification.svg").write_text(svg, encoding="utf-8")
print({"reaction_smiles": reaction_smiles, "file": "esterification.svg"})Expected result
esterification.svg begins with SVG markup and opens with reactants, an arrow, and products. The printed record keeps the exact reaction SMILES and filename together.
If it does not work
If parsing fails, correct the reaction SMILES before writing an artifact. A reaction diagram does not prove atom mapping, balance, conditions, yield, chemical identity, safety, or experimental validity.