modify_molecule
Transform or analyze molecules with structural verification. Supports name surgery, SMARTS reactions, and custom SMILES edits, returning a diff of atoms and bonds changed to confirm the modification.
Instructions
Analyze or transform a molecule with structural verification.
IMPORTANT: This is the ONLY correct way to modify a molecule. Never edit SMILES strings yourself and pass them directly to draw_molecule — always go through modify_molecule so you get an MCS-based structural diff to verify the change was correct.
Takes a molecule dict (at minimum {"smiles": "..."}) and applies one of 6 operations. Returns the modified molecule with a structural diff showing exactly what atoms/bonds were added, removed, or changed.
Operations: "analyze" — Inspect without modifying: functional groups, IUPAC names, formula, MW, prefix form. No extra kwargs needed. "name_surgery" — Modify via IUPAC name: add/remove substituents. Pass add=[{"locant": "2", "prefix": "fluoro"}] and/or remove=["methyl"] kwargs. "smarts" — Apply a SMARTS reaction transform. Pass smarts= "reaction SMILES" (e.g. "[c:1][F]>>[c:1][Cl]") or reaction_name= from list_reactions output. "set_smiles" — Use when you have edited a SMILES and want to verify the change. Pass the original mol_json and new_smiles=. The MCS diff will confirm exactly what was added/removed. Do NOT generate SMILES from scratch — use resolve_name. "set_name" — Set the display name. Pass new_name=. "reaction" — Apply a named template from list_reactions. Pass reaction_name= and optionally reagent={"smiles": ...} for binary reactions (coupling, etc.).
Args: mol_json: Source molecule dict with at least {"smiles": "..."}. operation: One of: "analyze", "name_surgery", "smarts", "set_smiles", "set_name", "reaction". add: For "name_surgery" — list of {"locant": str, "prefix": str} dicts. remove: For "name_surgery" — list of prefix strings to remove. new_smiles: For "set_smiles" — validated SMILES string. new_name: For "set_name" — new display name string. reaction_name: For "smarts"/"reaction" — template name. reagent: For "reaction" — dict with "smiles" key for the second reagent. smarts: For "smarts" — reaction SMARTS string. description: For "set_smiles" — optional context note.
Returns: For "analyze": ok, input_smiles, canonical_name, alternative_names, functional_groups, prefix_form, bracket_tree, formula, mw. For modifications: ok, input_smiles, output_smiles, input_name, output_name, aligned_names, diff (atoms_added, atoms_removed, atoms_changed, mcs_smarts, delta_formula, delta_mw), formula, mw.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| add | No | ||
| remove | No | ||
| smarts | No | ||
| reagent | No | ||
| mol_json | Yes | ||
| new_name | No | ||
| operation | Yes | ||
| new_smiles | No | ||
| description | No | ||
| reaction_name | No |