How ai4chems/mof_chemunity works
Purpose and entry points
MOF-ChemUnity builds and queries a Neo4j knowledge graph linking MOF computational data with LLM-extracted literature facts through CSD codes and DOI. Primary user entry point is QueryGenerationAgent.run_full_query() in src/MOF_ChemUnity/Agents/QueryAgent.py. Dataset extension is notebook-led: src/ChemUnity_Matching.ipynb then src/ChemUnity_Extraction.ipynb; graph loading is src/Knowledge Graph Creation/neo4j_import.py.
Agent layer
BaseAgent provides the shared agent foundation, specialized by extraction, entity matching, and natural-language graph querying:
• src/MOF_ChemUnity/Agents/BaseAgent.py
• src/MOF_ChemUnity/Agents/ExtractionAgent.py
• src/MOF_ChemUnity/Agents/MatchingAgent.py
• src/MOF_ChemUnity/Agents/QueryAgent.py
This separates LLM-driven interpretation from data preparation and graph persistence.
Literature ingestion and normalization
Documents are converted into usable text/Markdown before extraction. Extraction agents produce structured information such as MOF names, properties, applications, synthesis, and water stability; matching connects literature mentions to CSD identifiers. Prompt modules define task-specific LLM instructions:
• src/MOF_ChemUnity/utils/DocProcessor.py
• src/MOF_ChemUnity/utils/XML_to_MD.py
• src/MOF_ChemUnity/Prompts/Extraction_Prompts.py
• src/MOF_ChemUnity/Prompts/Matching_Prompts.py
Example PDF/XML inputs and derived Markdown demonstrate the ingestion boundary under src/Examples/PDF/ and src/Examples/XML/.
Data quality, identity, and enrichment
Utilities prepare, filter, model, and reconcile extracted records before graph import. The CSD code is the central identity boundary joining paper-derived facts to computational sources; MOF/CSD reference data supports this linkage.
• src/MOF_ChemUnity/utils/DataModels.py
• src/MOF_ChemUnity/utils/DataPrep.py
• src/MOF_ChemUnity/utils/FilterTools.py
• src/MOF_ChemUnity/utils/csd_dict.py
• data/MOF_names_and_CSD_codes.csv
Knowledge-graph persistence
Neo4j is the material runtime and system of record. Import expects relational CSV exports for matching, experimental properties, applications, synthesis, water stability, descriptors, and computational properties, then creates the graph and relationships:
• src/Knowledge Graph Creation/neo4j_import.py
• src/Examples/KG_Data/matching.csv
• src/Examples/KG_Data/computational_properties.csv
• src/Examples/KG_Data/filtered_experimental_properties.csv
Connection credentials are supplied through NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD, keeping infrastructure access outside package code.
Query and retrieval flow
A user question enters QueryGenerationAgent, which translates it into Neo4j-oriented retrieval and returns a Pandas DataFrame. Query prompts are isolated from the agent implementation:
• src/MOF_ChemUnity/Agents/QueryAgent.py
• src/MOF_ChemUnity/Prompts/Query_Generation_Prompts.py
Semantic/similarity retrieval artifacts use FAISS indexes, with neighboring-record logic in:
• src/MOF_ChemUnity/utils/NeighbourFinder.py
• src/Examples/vs/10.1016_j.molstruc.2017.11.128/index.faiss
External services and expansion
OpenAI/GPT-4o is the intended LLM service for extraction and query generation; users provide their own API key. Neo4j hosts the graph. Cross-document expansion utilities support finding related literature and appending new extractions:
• src/MOF_ChemUnity/utils/cross_doc_utils.py
• src/Cross_Document.ipynb
Main entry points: ExtractionAgent.py Extraction agent · MatchingAgent.py Matching agent · QueryAgent.py Query generation agent · BaseAgent.py Base agent
Components 18
Literature ingestion
- PDF/XML literature · Example inputs and derived Markdown establish the ingestion boundary.
- Document processing
src/MOF_ChemUnity/utils/DocProcessor.py - XML to Markdown
src/MOF_ChemUnity/utils/XML_to_MD.py
Agent layer
- Extraction agent · Extracts MOF facts including properties, applications, synthesis, and stability.
src/MOF_ChemUnity/Agents/ExtractionAgent.py - Matching agent · Links literature mentions to CSD identifiers.
src/MOF_ChemUnity/Agents/MatchingAgent.py - Base agent · Shared foundation for specialized agents.
src/MOF_ChemUnity/Agents/BaseAgent.py - Extraction prompts
src/MOF_ChemUnity/Prompts/Extraction_Prompts.py - Matching prompts
src/MOF_ChemUnity/Prompts/Matching_Prompts.py
Data preparation
- Record preparation · Models, prepares, filters, and reconciles extracted records.
src/MOF_ChemUnity/utils/DataPrep.py - MOF/CSD reference · CSD code is the join boundary between literature and computational data.
data/MOF_names_and_CSD_codes.csv - Cross-document expansion · Finds related literature and appends new extractions.
src/MOF_ChemUnity/utils/cross_doc_utils.py
Knowledge graph
- Relational CSV exports · Includes matching, experimental, computational, and literature-derived facts.
src/Examples/KG_Data/matching.csv - Neo4j importer · Creates graph nodes and relationships from CSV exports.
src/Knowledge Graph Creation/neo4j_import.py - Neo4j knowledge graph · Persists linked MOF computational and literature knowledge.
Query and similarity
- Query generation agent · Primary user entry point: run_full_query() returns a Pandas DataFrame.
src/MOF_ChemUnity/Agents/QueryAgent.py - Query prompts
src/MOF_ChemUnity/Prompts/Query_Generation_Prompts.py - FAISS similarity index · Supports neighboring-record similarity retrieval.
src/Examples/vs/10.1016_j.molstruc.2017.11.128/index.faiss
Other components
- OpenAI GPT-4o · User-supplied API key enables extraction and query generation.
Connections 23
- PDF/XML literature → Document processing: normalize
- PDF/XML literature → XML to Markdown: convert XML
- Document processing → Extraction agent: text/Markdown
- XML to Markdown → Extraction agent: Markdown
- Base agent → Extraction agent: specializes
- Base agent → Matching agent: specializes
- Base agent → Query generation agent: specializes
- Extraction prompts → Extraction agent: instructions
- Matching prompts → Matching agent: instructions
- Extraction agent → OpenAI GPT-4o: LLM calls
- Matching agent → OpenAI GPT-4o: LLM calls
- Extraction agent → Record preparation: structured facts
- Record preparation → Matching agent: normalized records
- MOF/CSD reference → Matching agent: CSD lookup
- Matching agent → Relational CSV exports: matched records
- Record preparation → Relational CSV exports: filtered facts
- Cross-document expansion → Extraction agent: related documents
- Relational CSV exports → Neo4j importer: load input
- Neo4j importer → Neo4j knowledge graph: create graph
- Query prompts → Query generation agent: instructions
- Query generation agent → OpenAI GPT-4o: generate retrieval
- Query generation agent → Neo4j knowledge graph: Neo4j retrieval
- FAISS similarity index → Query generation agent: similarity context