Chemistry Query Agent v1.4.1
Overview
Full-stack chemistry toolkit combining PubChem data retrieval with RDKit molecule processing, visualization, analysis, retrosynthesis, and synthesis planning. All outputs are structured JSON for easy downstream chaining. Generates PNG/SVG images on demand.
Key capabilities:
- PubChem compound lookup (info, structure, synthesis refs, similarity search)
- RDKit molecular properties (MW, logP, TPSA, HBD/HBA, rotatable bonds, aromatic rings)
- 2D molecule visualization (PNG/SVG)
- BRICS retrosynthesis with recursive depth control
- Multi-step synthesis route planning
- Forward reaction simulation with SMARTS templates
- Morgan fingerprints and similarity/substructure search
- 21 named reaction templates (Suzuki, Heck, Grignard, Wittig, Diels-Alder, etc.)
Quick Start
# PubChem compound info
exec python scripts/query_pubchem.py --compound "aspirin" --type info
# Molecular properties from SMILES
exec python scripts/rdkit_mol.py --smiles "CC(=O)Oc1ccccc1C(=O)O" --action props
# Retrosynthesis
exec python scripts/rdkit_mol.py --target "CC(=O)Oc1ccccc1C(=O)O" --action retro --depth 2
# Full chain (name → props + draw + retro)
exec python scripts/chain_entry.py --input-json '{"name": "caffeine", "context": "user"}'
Scripts
scripts/query_pubchem.py
PubChem REST API queries with automatic name→CID resolution and timeout handling.
--compound <name|CID> --type <info|structure|synthesis|similar> [--format smiles|inchi|image|json] [--threshold 80]
- info: Formula, MW, IUPAC name, InChIKey (JSON)
- structure: SMILES, InChI, image URL, or full JSON
- synthesis: Synonyms/references for a compound
- similar: Similar compounds by 2D fingerprint (top 20)
scripts/rdkit_mol.py
RDKit cheminformatics engine. Resolves names via PubChem automatically.
--smiles <SMILES> --action <props|draw|fingerprint|similarity|substruct|xyz|react|retro|plan>
| Action |
Description |
Key Args |
| props |
MW, logP, TPSA, HBD, HBA, rotB, aromRings |
--smiles |
| draw |
2D PNG/SVG (300×300) |
--smiles --output file.png --format png|svg |
| retro |
BRICS recursive retrosynthesis |
--target <SMILES|name> --depth N |
| plan |
Multi-step retro route |
--target <SMILES|name> --steps N |
| react |
Forward reaction via SMARTS |
--reactants "smi1 smi2" --smarts "<SMARTS>" |
| fingerprint |
Morgan fingerprint bitvector |
--smiles --radius 2 |
| similarity |
Tanimoto similarity scoring |
--query_smiles --target_smiles "smi1,smi2" |
| substruct |
Substructure matching |
--query_smiles --target_smiles "smi1,smi2" |
| xyz |
3D coordinates (MMFF optimized) |
--smiles |
scripts/chain_entry.py
Standard agent chain interface. Accepts {"smiles": "...", "context": "..."} or {"name": "...", "context": "..."}. Returns unified JSON with props, visualization, and retrosynthesis.
python scripts/chain_entry.py --input-json '{"name": "sotorasib", "context": "user"}'
Output schema:
{
"agent": "chemistry-query",
"version": "1.4.0",
"smiles": "<canonical>",
"status": "success|error",
"report": {"props": {...}, "draw": {...}, "retro": {...}},
"risks": [],
"viz": ["path/to/image.png"],
"recommend_next": ["pharmacology", "toxicology"],
"confidence": 0.95,
"warnings": [],
"timestamp": "ISO8601"
}
scripts/templates.json
21 named reaction templates with SMARTS, expected yields, conditions, and references. Includes: Suzuki, Heck, Buchwald-Hartwig, Grignard, Wittig, Diels-Alder, Click, Sonogashira, Negishi, and more.
Chaining
- Name → Full Profile:
chain_entry.py with {"name": "ibuprofen"} → props + draw + retro
- Chemistry → Pharmacology: Output feeds directly into
pharma-pharmacology-agent
- Retro + Viz: Get precursors, then draw each one
- Suzuki Test:
--action react --reactants "c1ccccc1Br c1ccccc1B(O)O" --smarts "[c:1][Br:2].[c:3][B]([c:4])(O)O>>[c:1][c:3]"
Tested With
All features verified end-to-end with RDKit 2024.03+:
| Molecule |
SMILES |
Tests Passed |
| Caffeine |
CN1C=NC2=C1C(=O)N(C(=O)N2C)C |
info, structure, props, draw, retro, plan, chain |
| Aspirin |
CC(=O)Oc1ccccc1C(=O)O |
info, structure, props, draw, retro, plan, chain |
| Sotorasib |
PubChem name lookup |
info, structure, props, draw, retro, chain |
| Ibuprofen |
PubChem name lookup |
info, structure, props, chain |
| Invalid SMILES |
XXXINVALID |
Graceful JSON error |
| Empty input |
{} |
Graceful JSON error |
Resources
references/api_endpoints.md — PubChem API endpoint reference and rate limits
scripts/rdkit_reaction.py — Legacy reaction module
scripts/chembl_query.py, scripts/pubmed_search.py, scripts/admet_predict.py — Additional query modules
scripts/advanced_chem.py
Advanced cheminformatics engine with 6 Tier 1 capabilities.
--action <standardize|descriptors|scaffold|mcs|mmpa|chemspace> --smiles <SMILES> [options]
| Action |
Description |
Key Args |
| standardize |
Salt stripping, charge normalization, tautomer enumeration |
--smiles |
| descriptors |
217+ molecular descriptors (RDKit full set), QED, SA Score, Lipinski/Veber rules |
--smiles --descriptor_set all|druglike|physical|topological |
| scaffold |
Murcko scaffold extraction, generic scaffolds, diversity analysis, R-group decomposition |
--smiles or --target_smiles "smi1,smi2,..." --rgroup_core <SMARTS> |
| mcs |
Maximum Common Substructure across 2+ molecules |
--target_smiles "smi1,smi2,..." |
| mmpa |
Matched Molecular Pair Analysis — find single-point transformations |
--target_smiles "smi1,smi2,..." |
| chemspace |
Chemical space visualization (PCA/t-SNE/UMAP scatter plot PNG) |
--target_smiles "smi1,smi2,..." --method pca|tsne|umap --output plot.png |
Examples:
# Standardize a salt form
python scripts/advanced_chem.py --action standardize --smiles "[Na+].CC(=O)[O-]"
# Full descriptors (217+)
python scripts/advanced_chem.py --action descriptors --smiles "CC(=O)Oc1ccccc1C(=O)O" --descriptor_set all
# Scaffold diversity of a set
python scripts/advanced_chem.py --action scaffold --target_smiles "CC(=O)Oc1ccccc1C(=O)O,CN1C=NC2=C1C(=O)N(C(=O)N2C)C,CC(C)Cc1ccc(cc1)C(C)C(=O)O"
# MCS of aspirin and salicylic acid
python scripts/advanced_chem.py --action mcs --target_smiles "CC(=O)Oc1ccccc1C(=O)O,c1ccccc1C(=O)O"
# Matched molecular pairs
python scripts/advanced_chem.py --action mmpa --target_smiles "c1ccc(CC(=O)O)cc1,c1ccc(CCC(=O)O)cc1"
# Chemical space PCA plot
python scripts/advanced_chem.py --action chemspace --target_smiles "CC(=O)Oc1ccccc1C(=O)O,CN1C=NC2=C1C(=O)N(C(=O)N2C)C,c1ccccc1" --method pca --output space.png
Changelog
v2.0.0 (2026-02-28)
- NEW:
advanced_chem.py with 6 Tier 1 cheminformatics capabilities
- Molecular Standardization & Tautomer Enumeration (salt stripping, charge normalization, canonical tautomers)
- Extended Descriptors (217+ RDKit descriptors, QED, SA Score, Lipinski, Veber)
- Scaffold Analysis (Murcko, generic scaffolds, diversity ratio, R-group decomposition)
- Maximum Common Substructure (rdFMCS with coverage per molecule)
- Matched Molecular Pair Analysis (rdMMPA fragmentation, transformation detection)
- Chemical Space Visualization (PCA/t-SNE/UMAP with matplotlib scatter plots)
- Dependencies: scikit-learn, matplotlib (added)
v1.4.1 (2026-02-25)
- Security hardening: input sanitization for all subprocess calls (SMILES, compound names, output paths)
- Added
_sanitize_input() — length limits, null-byte rejection for all user inputs
- Added
_sanitize_output_path() — prevents path traversal, restricts extensions, blocks arbitrary file writes
- Added shell metacharacter rejection in
resolve_target()
- Added SMILES validation via RDKit in
chem_ui.py before subprocess calls
- Added compound input validation in
query_pubchem.py (length/null-byte checks)
- Added timeout to
resolve_target() PubChem subprocess call
- Addresses VirusTotal "suspicious" classification for argument injection vectors
v1.4.0 (2026-02-14)
- Fixed PubChem SMILES/InChI endpoint (property/CanonicalSMILES/TXT)
- Fixed chain_entry.py HTML entity corruption
- Fixed brics_retro to handle BRICSDecompose string output correctly
- Added request timeouts (15s) to all PubChem calls
- Graceful error handling for invalid SMILES and empty input
- Updated chain output version and schema
- Comprehensive end-to-end testing
v1.3.0
- RDKit props NoneType fixes, invalid SMILES graceful errors
- React fix: ReactionFromSmarts import
- Name resolution via PubChem for all RDKit actions
v1.2.0
- BRICS retrosynthesis + 21 reaction templates library
- Multi-step synthesis planning
1---2name: pharmaclaw-chemistry-query3description: Chemistry agent skill for PubChem API queries (compound info/properties, structures/SMILES/images, synthesis routes/references) + RDKit cheminformatics (SMILES to molecule props/logP/TPSA, 2D PNG/SVG viz, Morgan fingerprints, retrosynthesis/BRICS disconnects, multi-step synth planning). Use for chemistry tasks involving compounds, molecules, structures, PubChem data, RDKit analysis, SMILES processing, synthesis routes, retrosynthesis, reaction simulation. Triggers on chemistry, compounds, molecules, chemical data/properties, PubChem, RDKit, SMILES, structures, synthesis, reactions, retrosynthesis, synth plan/route.4---56# Chemistry Query Agent v1.4.178## Overview910Full-stack chemistry toolkit combining PubChem data retrieval with RDKit molecule processing, visualization, analysis, retrosynthesis, and synthesis planning. All outputs are structured JSON for easy downstream chaining. Generates PNG/SVG images on demand.1112**Key capabilities:**13- PubChem compound lookup (info, structure, synthesis refs, similarity search)14- RDKit molecular properties (MW, logP, TPSA, HBD/HBA, rotatable bonds, aromatic rings)15- 2D molecule visualization (PNG/SVG)16- BRICS retrosynthesis with recursive depth control17- Multi-step synthesis route planning18- Forward reaction simulation with SMARTS templates19- Morgan fingerprints and similarity/substructure search20- 21 named reaction templates (Suzuki, Heck, Grignard, Wittig, Diels-Alder, etc.)2122## Quick Start2324```bash25# PubChem compound info26exec python scripts/query_pubchem.py --compound "aspirin" --type info2728# Molecular properties from SMILES29exec python scripts/rdkit_mol.py --smiles "CC(=O)Oc1ccccc1C(=O)O" --action props3031# Retrosynthesis32exec python scripts/rdkit_mol.py --target "CC(=O)Oc1ccccc1C(=O)O" --action retro --depth 23334# Full chain (name → props + draw + retro)35exec python scripts/chain_entry.py --input-json '{"name": "caffeine", "context": "user"}'36```3738## Scripts3940### `scripts/query_pubchem.py`41PubChem REST API queries with automatic name→CID resolution and timeout handling.4243```44--compound <name|CID> --type <info|structure|synthesis|similar> [--format smiles|inchi|image|json] [--threshold 80]45```4647- **info:** Formula, MW, IUPAC name, InChIKey (JSON)48- **structure:** SMILES, InChI, image URL, or full JSON49- **synthesis:** Synonyms/references for a compound50- **similar:** Similar compounds by 2D fingerprint (top 20)5152### `scripts/rdkit_mol.py`53RDKit cheminformatics engine. Resolves names via PubChem automatically.5455```56--smiles <SMILES> --action <props|draw|fingerprint|similarity|substruct|xyz|react|retro|plan>57```5859| Action | Description | Key Args |60|--------|-------------|----------|61| props | MW, logP, TPSA, HBD, HBA, rotB, aromRings | `--smiles` |62| draw | 2D PNG/SVG (300×300) | `--smiles --output file.png --format png\|svg` |63| retro | BRICS recursive retrosynthesis | `--target <SMILES\|name> --depth N` |64| plan | Multi-step retro route | `--target <SMILES\|name> --steps N` |65| react | Forward reaction via SMARTS | `--reactants "smi1 smi2" --smarts "<SMARTS>"` |66| fingerprint | Morgan fingerprint bitvector | `--smiles --radius 2` |67| similarity | Tanimoto similarity scoring | `--query_smiles --target_smiles "smi1,smi2"` |68| substruct | Substructure matching | `--query_smiles --target_smiles "smi1,smi2"` |69| xyz | 3D coordinates (MMFF optimized) | `--smiles` |7071### `scripts/chain_entry.py`72Standard agent chain interface. Accepts `{"smiles": "...", "context": "..."}` or `{"name": "...", "context": "..."}`. Returns unified JSON with props, visualization, and retrosynthesis.7374```bash75python scripts/chain_entry.py --input-json '{"name": "sotorasib", "context": "user"}'76```7778Output schema:79```json80{81 "agent": "chemistry-query",82 "version": "1.4.0",83 "smiles": "<canonical>",84 "status": "success|error",85 "report": {"props": {...}, "draw": {...}, "retro": {...}},86 "risks": [],87 "viz": ["path/to/image.png"],88 "recommend_next": ["pharmacology", "toxicology"],89 "confidence": 0.95,90 "warnings": [],91 "timestamp": "ISO8601"92}93```9495### `scripts/templates.json`9621 named reaction templates with SMARTS, expected yields, conditions, and references. Includes: Suzuki, Heck, Buchwald-Hartwig, Grignard, Wittig, Diels-Alder, Click, Sonogashira, Negishi, and more.9798## Chaining991001. **Name → Full Profile:** `chain_entry.py` with `{"name": "ibuprofen"}` → props + draw + retro1012. **Chemistry → Pharmacology:** Output feeds directly into `pharma-pharmacology-agent`1023. **Retro + Viz:** Get precursors, then draw each one1034. **Suzuki Test:** `--action react --reactants "c1ccccc1Br c1ccccc1B(O)O" --smarts "[c:1][Br:2].[c:3][B]([c:4])(O)O>>[c:1][c:3]"`104105## Tested With106107All features verified end-to-end with RDKit 2024.03+:108109| Molecule | SMILES | Tests Passed |110|----------|--------|-------------|111| Caffeine | `CN1C=NC2=C1C(=O)N(C(=O)N2C)C` | info, structure, props, draw, retro, plan, chain |112| Aspirin | `CC(=O)Oc1ccccc1C(=O)O` | info, structure, props, draw, retro, plan, chain |113| Sotorasib | PubChem name lookup | info, structure, props, draw, retro, chain |114| Ibuprofen | PubChem name lookup | info, structure, props, chain |115| Invalid SMILES | `XXXINVALID` | Graceful JSON error |116| Empty input | `{}` | Graceful JSON error |117118## Resources119120- `references/api_endpoints.md` — PubChem API endpoint reference and rate limits121- `scripts/rdkit_reaction.py` — Legacy reaction module122- `scripts/chembl_query.py`, `scripts/pubmed_search.py`, `scripts/admet_predict.py` — Additional query modules123124### `scripts/advanced_chem.py`125Advanced cheminformatics engine with 6 Tier 1 capabilities.126127```128--action <standardize|descriptors|scaffold|mcs|mmpa|chemspace> --smiles <SMILES> [options]129```130131| Action | Description | Key Args |132|--------|-------------|----------|133| standardize | Salt stripping, charge normalization, tautomer enumeration | `--smiles` |134| descriptors | 217+ molecular descriptors (RDKit full set), QED, SA Score, Lipinski/Veber rules | `--smiles --descriptor_set all\|druglike\|physical\|topological` |135| scaffold | Murcko scaffold extraction, generic scaffolds, diversity analysis, R-group decomposition | `--smiles` or `--target_smiles "smi1,smi2,..."` `--rgroup_core <SMARTS>` |136| mcs | Maximum Common Substructure across 2+ molecules | `--target_smiles "smi1,smi2,..."` |137| mmpa | Matched Molecular Pair Analysis — find single-point transformations | `--target_smiles "smi1,smi2,..."` |138| chemspace | Chemical space visualization (PCA/t-SNE/UMAP scatter plot PNG) | `--target_smiles "smi1,smi2,..." --method pca\|tsne\|umap --output plot.png` |139140**Examples:**141```bash142# Standardize a salt form143python scripts/advanced_chem.py --action standardize --smiles "[Na+].CC(=O)[O-]"144145# Full descriptors (217+)146python scripts/advanced_chem.py --action descriptors --smiles "CC(=O)Oc1ccccc1C(=O)O" --descriptor_set all147148# Scaffold diversity of a set149python scripts/advanced_chem.py --action scaffold --target_smiles "CC(=O)Oc1ccccc1C(=O)O,CN1C=NC2=C1C(=O)N(C(=O)N2C)C,CC(C)Cc1ccc(cc1)C(C)C(=O)O"150151# MCS of aspirin and salicylic acid152python scripts/advanced_chem.py --action mcs --target_smiles "CC(=O)Oc1ccccc1C(=O)O,c1ccccc1C(=O)O"153154# Matched molecular pairs155python scripts/advanced_chem.py --action mmpa --target_smiles "c1ccc(CC(=O)O)cc1,c1ccc(CCC(=O)O)cc1"156157# Chemical space PCA plot158python scripts/advanced_chem.py --action chemspace --target_smiles "CC(=O)Oc1ccccc1C(=O)O,CN1C=NC2=C1C(=O)N(C(=O)N2C)C,c1ccccc1" --method pca --output space.png159```160161## Changelog162163**v2.0.0** (2026-02-28)164- NEW: `advanced_chem.py` with 6 Tier 1 cheminformatics capabilities165 - Molecular Standardization & Tautomer Enumeration (salt stripping, charge normalization, canonical tautomers)166 - Extended Descriptors (217+ RDKit descriptors, QED, SA Score, Lipinski, Veber)167 - Scaffold Analysis (Murcko, generic scaffolds, diversity ratio, R-group decomposition)168 - Maximum Common Substructure (rdFMCS with coverage per molecule)169 - Matched Molecular Pair Analysis (rdMMPA fragmentation, transformation detection)170 - Chemical Space Visualization (PCA/t-SNE/UMAP with matplotlib scatter plots)171- Dependencies: scikit-learn, matplotlib (added)172173**v1.4.1** (2026-02-25)174- Security hardening: input sanitization for all subprocess calls (SMILES, compound names, output paths)175- Added `_sanitize_input()` — length limits, null-byte rejection for all user inputs176- Added `_sanitize_output_path()` — prevents path traversal, restricts extensions, blocks arbitrary file writes177- Added shell metacharacter rejection in `resolve_target()`178- Added SMILES validation via RDKit in `chem_ui.py` before subprocess calls179- Added compound input validation in `query_pubchem.py` (length/null-byte checks)180- Added timeout to `resolve_target()` PubChem subprocess call181- Addresses VirusTotal "suspicious" classification for argument injection vectors182183**v1.4.0** (2026-02-14)184- Fixed PubChem SMILES/InChI endpoint (property/CanonicalSMILES/TXT)185- Fixed chain_entry.py HTML entity corruption186- Fixed brics_retro to handle BRICSDecompose string output correctly187- Added request timeouts (15s) to all PubChem calls188- Graceful error handling for invalid SMILES and empty input189- Updated chain output version and schema190- Comprehensive end-to-end testing191192**v1.3.0**193- RDKit props NoneType fixes, invalid SMILES graceful errors194- React fix: ReactionFromSmarts import195- Name resolution via PubChem for all RDKit actions196197**v1.2.0**198- BRICS retrosynthesis + 21 reaction templates library199- Multi-step synthesis planning