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
Changelog
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-query
3description: 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.
4type: code
5dependencies:
6 python: ">=3.10"
7 python-packages:
8 - rdkit
9 - gradio
10 - pandas
11 - Pillow
12 system:
13 - java (JRE 8+ for OPSIN, optional — only needed for IUPAC name→SMILES conversion)
14 external-apis:
15 - PubChem REST API (public, no key required)
16 - ChEMBL API (public, no key required)
17 - PubMed/NCBI E-utilities (public, no key required)
18 notes: >
19 OPSIN JAR (13.8MB) is auto-downloaded on first use of IUPAC name conversion
20 with pinned SHA-256 checksum verification (d25bc08f...). All other functionality
21 works without Java/OPSIN.
22metadata:
23 source: https://skillmd.com/skills/modbender/pharmaclaw-chemistry-query
24---
25
26# Chemistry Query Agent v1.4.1
27
28## Overview
29
30Full-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.
31
32**Key capabilities:**
33- PubChem compound lookup (info, structure, synthesis refs, similarity search)
34- RDKit molecular properties (MW, logP, TPSA, HBD/HBA, rotatable bonds, aromatic rings)
35- 2D molecule visualization (PNG/SVG)
36- BRICS retrosynthesis with recursive depth control
37- Multi-step synthesis route planning
38- Forward reaction simulation with SMARTS templates
39- Morgan fingerprints and similarity/substructure search
40- 21 named reaction templates (Suzuki, Heck, Grignard, Wittig, Diels-Alder, etc.)
41
42## Quick Start
43
44```bash
45# PubChem compound info
46exec python scripts/query_pubchem.py --compound "aspirin" --type info
47
48# Molecular properties from SMILES
49exec python scripts/rdkit_mol.py --smiles "CC(=O)Oc1ccccc1C(=O)O" --action props
50
51# Retrosynthesis
52exec python scripts/rdkit_mol.py --target "CC(=O)Oc1ccccc1C(=O)O" --action retro --depth 2
53
54# Full chain (name → props + draw + retro)
55exec python scripts/chain_entry.py --input-json '{"name": "caffeine", "context": "user"}'
56```
57
58## Scripts
59
60### `scripts/query_pubchem.py`
61PubChem REST API queries with automatic name→CID resolution and timeout handling.
62
63```
64--compound <name|CID> --type <info|structure|synthesis|similar> [--format smiles|inchi|image|json] [--threshold 80]
65```
66
67- **info:** Formula, MW, IUPAC name, InChIKey (JSON)
68- **structure:** SMILES, InChI, image URL, or full JSON
69- **synthesis:** Synonyms/references for a compound
70- **similar:** Similar compounds by 2D fingerprint (top 20)
71
72### `scripts/rdkit_mol.py`
73RDKit cheminformatics engine. Resolves names via PubChem automatically.
74
75```
76--smiles <SMILES> --action <props|draw|fingerprint|similarity|substruct|xyz|react|retro|plan>
77```
78
79| Action | Description | Key Args |
80|--------|-------------|----------|
81| props | MW, logP, TPSA, HBD, HBA, rotB, aromRings | `--smiles` |
82| draw | 2D PNG/SVG (300×300) | `--smiles --output file.png --format png\|svg` |
83| retro | BRICS recursive retrosynthesis | `--target <SMILES\|name> --depth N` |
84| plan | Multi-step retro route | `--target <SMILES\|name> --steps N` |
85| react | Forward reaction via SMARTS | `--reactants "smi1 smi2" --smarts "<SMARTS>"` |
86| fingerprint | Morgan fingerprint bitvector | `--smiles --radius 2` |
87| similarity | Tanimoto similarity scoring | `--query_smiles --target_smiles "smi1,smi2"` |
88| substruct | Substructure matching | `--query_smiles --target_smiles "smi1,smi2"` |
89| xyz | 3D coordinates (MMFF optimized) | `--smiles` |
90
91### `scripts/chain_entry.py`
92Standard agent chain interface. Accepts `{"smiles": "...", "context": "..."}` or `{"name": "...", "context": "..."}`. Returns unified JSON with props, visualization, and retrosynthesis.
93
94```bash
95python scripts/chain_entry.py --input-json '{"name": "sotorasib", "context": "user"}'
96```
97
98Output schema:
99```json
100{
101 "agent": "chemistry-query",
102 "version": "1.4.0",
103 "smiles": "<canonical>",
104 "status": "success|error",
105 "report": {"props": {...}, "draw": {...}, "retro": {...}},
106 "risks": [],
107 "viz": ["path/to/image.png"],
108 "recommend_next": ["pharmacology", "toxicology"],
109 "confidence": 0.95,
110 "warnings": [],
111 "timestamp": "ISO8601"
112}
113```
114
115### `scripts/templates.json`
11621 named reaction templates with SMARTS, expected yields, conditions, and references. Includes: Suzuki, Heck, Buchwald-Hartwig, Grignard, Wittig, Diels-Alder, Click, Sonogashira, Negishi, and more.
117
118## Chaining
119
1201. **Name → Full Profile:** `chain_entry.py` with `{"name": "ibuprofen"}` → props + draw + retro
1212. **Chemistry → Pharmacology:** Output feeds directly into `pharma-pharmacology-agent`
1223. **Retro + Viz:** Get precursors, then draw each one
1234. **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]"`
124
125## Tested With
126
127All features verified end-to-end with RDKit 2024.03+:
128
129| Molecule | SMILES | Tests Passed |
130|----------|--------|-------------|
131| Caffeine | `CN1C=NC2=C1C(=O)N(C(=O)N2C)C` | info, structure, props, draw, retro, plan, chain |
132| Aspirin | `CC(=O)Oc1ccccc1C(=O)O` | info, structure, props, draw, retro, plan, chain |
133| Sotorasib | PubChem name lookup | info, structure, props, draw, retro, chain |
134| Ibuprofen | PubChem name lookup | info, structure, props, chain |
135| Invalid SMILES | `XXXINVALID` | Graceful JSON error |
136| Empty input | `{}` | Graceful JSON error |
137
138## Resources
139
140- `references/api_endpoints.md` — PubChem API endpoint reference and rate limits
141- `scripts/rdkit_reaction.py` — Legacy reaction module
142- `scripts/chembl_query.py`, `scripts/pubmed_search.py`, `scripts/admet_predict.py` — Additional query modules
143
144## Changelog
145
146**v1.4.1** (2026-02-25)
147- Security hardening: input sanitization for all subprocess calls (SMILES, compound names, output paths)
148- Added `_sanitize_input()` — length limits, null-byte rejection for all user inputs
149- Added `_sanitize_output_path()` — prevents path traversal, restricts extensions, blocks arbitrary file writes
150- Added shell metacharacter rejection in `resolve_target()`
151- Added SMILES validation via RDKit in `chem_ui.py` before subprocess calls
152- Added compound input validation in `query_pubchem.py` (length/null-byte checks)
153- Added timeout to `resolve_target()` PubChem subprocess call
154- Addresses VirusTotal "suspicious" classification for argument injection vectors
155
156**v1.4.0** (2026-02-14)
157- Fixed PubChem SMILES/InChI endpoint (property/CanonicalSMILES/TXT)
158- Fixed chain_entry.py HTML entity corruption
159- Fixed brics_retro to handle BRICSDecompose string output correctly
160- Added request timeouts (15s) to all PubChem calls
161- Graceful error handling for invalid SMILES and empty input
162- Updated chain output version and schema
163- Comprehensive end-to-end testing
164
165**v1.3.0**
166- RDKit props NoneType fixes, invalid SMILES graceful errors
167- React fix: ReactionFromSmarts import
168- Name resolution via PubChem for all RDKit actions
169
170**v1.2.0**
171- BRICS retrosynthesis + 21 reaction templates library
172- Multi-step synthesis planning