Task tutorial
Write an SDF record from SMILES with Python
Create a local SDF structure record with a name and the exact source SMILES preserved as SD data.
You will make
An ethanol.sdf file with an ethanol structure, generated 2D coordinates, a record name, and a source_smiles field.
Steps
- Parse one complete SMILES locally and set a human-readable record name.
- Store the exact source SMILES as an SD property before writing the file.
- Use SDWriter to write one SDF record, then inspect the header, property block, and record terminator.
import chematic
smiles = "CCO"
mol = chematic.from_smiles(smiles)
mol.SetProp("_Name", "ethanol")
mol.SetProp("source_smiles", smiles)
with chematic.SDWriter("ethanol.sdf") as writer:
writer.write(mol)
print({"input_smiles": smiles, "file": "ethanol.sdf"})Expected result
ethanol.sdf opens as a V2000 SDF record named ethanol. Its SD data includes source_smiles with CCO, and the record ends with $$$$.
If it does not work
Correct a parsing error before writing a file. The writer creates a structure record and 2D coordinates, not a proof of chemical identity, stereochemical intent, material provenance, safety, or experimental validity. Keep the original source file when converting a batch.