An Open WebUI filter that automatically enriches chemistry and materials science queries with contextual data from multiple scientific databases. Works with any LLM available in Open WebUI, with per-chat toggle control.
- PubChem Integration: Chemical structure data, molecular properties, and descriptions
- ChEMBL Integration: Drug bioactivity, clinical trial phases, therapeutic targets, and indications
- Materials Project Integration: Computational materials properties (band gap, density, formation energy, crystal structure)
- RDKit Calculations: Molecular descriptors, Lipinski rule-of-five compliance, drug-likeness metrics
The tool automatically detects and enriches:
-
Chemical Formulas (e.g., H2O, H2SO4, LiFePO4)
- Looks up materials properties from Materials Project
- Returns band gap, density, formation energy, space group, etc.
-
Drug/Chemical Names (e.g., ibuprofen, aspirin, caffeine)
- Resolves name to structure via PubChem
- Calculates molecular descriptors with RDKit
- Retrieves drug information from ChEMBL
-
Materials Project IDs (e.g., mp-149)
- Direct lookup of computational materials data
- Clone this repository:
git clone https://github.com/yourusername/scientific-enrichment-tool.git
cd scientific-enrichment-tool- Create a
.envfile with your Materials Project API key (optional but recommended):
echo "MATERIALS_PROJECT_API_KEY=your_api_key_here" > .envGet a free API key at: https://next-gen.materialsproject.org/api
- Start the service:
docker-compose up -dThe API will be available at http://localhost:8099
- Install dependencies:
pip install -r requirements.txt- Set your Materials Project API key:
export MATERIALS_PROJECT_API_KEY=your_api_key_here- Run the API service:
python enrichment_api.py- In Open WebUI, navigate to Settings → Filters
- Click + Create New Filter
- Copy the contents of
scientific_enrichment_function.pyand paste into the editor - Click Save
- Configure the global valves (optional):
ENRICHMENT_API_URL: Default ishttp://scientific-enrichment-api:8099(for Docker setup)MATERIALS_PROJECT_API_KEY: Your Materials Project API key (optional, but recommended)
The enrichment filter works on a per-chat basis, giving you full control over when to use it:
- Start a new chat in Open WebUI
- Click the chat settings icon (usually in the sidebar or chat header)
- Find "Scientific Data Enrichment" in the filters list
- Toggle "Enabled" to ON for chemistry/materials questions
- Ask your questions - the filter automatically enriches queries with scientific data!
Default behavior: OFF for all new chats. Enable only when you need chemistry/materials data.
Per-chat control: Each chat has its own toggle, so you can enable enrichment in one chat for chemistry and leave it off in others for general use.
Example queries:
- "What happens if I mix ibuprofen with H2SO4?"
- "What are the properties of LiFePO4?"
- "Tell me about aspirin's mechanism of action"
- "What is the band gap of mp-149?"
The tool will automatically detect relevant chemicals and materials, fetch data from scientific databases, and provide enriched context to the AI for more informed responses.
Resolve chemical name or formula via PubChem.
Request:
{"name": "ibuprofen"}or
{"formula": "C13H18O2"}Response:
{
"success": true,
"cid": 3672,
"description": "Ibuprofen is a nonsteroidal anti-inflammatory drug...",
"properties": {
"MolecularFormula": "C13H18O2",
"MolecularWeight": "206.28",
"IUPACName": "2-[4-(2-methylpropyl)phenyl]propanoic acid"
},
"smiles": "CC(C)CC1=CC=C(C=C1)C(C)C(=O)O",
"iupac": "2-[4-(2-methylpropyl)phenyl]propanoic acid"
}Lookup bioactivity, targets, and drug information from ChEMBL.
Request:
{"name": "aspirin"}Response:
{
"success": true,
"chembl_id": "CHEMBL25",
"pref_name": "ASPIRIN",
"max_phase": 4,
"properties": {
"molecular_weight": 180.16,
"alogp": 1.19
},
"indications": [
{"mesh_heading": "Pain", "max_phase": 4}
],
"bioactivity_targets": [
{"target_id": "CHEMBL233", "target_type": "SINGLE PROTEIN"}
]
}Calculate molecular descriptors and Lipinski rule-of-five compliance.
Request:
{"smiles": "CC(C)CC1=CC=C(C=C1)C(C)C(=O)O"}Response:
{
"success": true,
"lipinski": {
"mw": 206.28,
"hbd": 1,
"hba": 2,
"logp": 3.5,
"tpsa": 37.3,
"passes": true
}
}Lookup materials by formula, Materials Project ID, or elements.
Request:
{"formula": "LiFePO4"}or
{"mp_id": "mp-19017"}or
{"elements": ["Li", "Fe", "O"]}Response:
{
"success": true,
"data": [
{
"material_id": "mp-19017",
"formula_pretty": "LiFePO4",
"band_gap": 3.41,
"density": 3.6,
"formation_energy_per_atom": -2.197,
"e_above_hull": 0.0,
"is_metal": false,
"spacegroup_symbol": "Pnma"
}
]
}When you ask: "What happens if I mix ibuprofen with H2SO4?"
The tool provides:
Scientific Context:
- Materials Project (H2SO4) | ID: mp-558129 | Band gap: 0.00 eV | Density: 1.83 g/cm³ | Metal: No
- PubChem (ibuprofen) | IUPAC: 2-[4-(2-methylpropyl)phenyl]propanoic... | Formula: C13H18O2 | MW: 206.28
- RDKit (ibuprofen) | MW: 206.3 | HBD: 1 | HBA: 2 | LogP: 3.5 | TPSA: 37.3 | Lipinski: ✓
- ChEMBL (ibuprofen) | Drug: IBUPROFEN | Status: Approved | Treats: Pain, Inflammation
User Query: What happens if I mix ibuprofen with H2SO4?
This enriched context helps the AI provide accurate, informed responses about chemical reactions, drug properties, and safety considerations.
- PubChem: Free public database of chemical structures and properties (NIH)
- ChEMBL: Free database of bioactive drug-like molecules (EMBL-EBI)
- Materials Project: Computational materials science database (requires free API key)
- RDKit: Open-source cheminformatics library
- Python 3.11+
- Docker (recommended)
- Open WebUI v0.6.28+ (for filter support)
- Materials Project API key (optional but recommended for best results)
MIT License - feel free to use and modify for your projects.
Contributions welcome! Please open an issue or pull request.
- AB-MCTS Reasoning Engine - Advanced tree search reasoning for Open WebUI