Agentbx
Project description
Agentbx: A Redis-Based Crystallographic Agent System
Overview
Agentbx is a Python-based system for managing crystallographic & electron microscopy computing workflows using a Redis-backed agent architecture. It's designed to handle complex calculations using best-in-class algorithms (like structure factor calculation) through modular, single-responsibility agents that communicate via persistent data bundles.
Vision & Motivation
A key motivation for this architecture is to enable seamless integration between AI models and traditional crystallographic/EM toolkits. By using Redis as middleware and implementing clear separation of concerns, Agentbx allows:
- Technology Stack Independence: AI models (PyTorch, TensorFlow, etc.) can run independently from crystallographic toolkits (CCTBX, Phenix, etc.)
- Event-Driven Architecture: Agents react to status messages placed on Redis queues, enabling asynchronous processing
- Modular Integration: New AI models or crystallographic tools can be added as agents without modifying existing code
- Scalable Workflows: Complex pipelines can be orchestrated across different computational resources
This design enables researchers to combine cutting-edge AI predictions (protein structure prediction, electron density interpretation) with established crystallographic refinement workflows, all coordinated through Redis as the central nervous system.
Core Architecture
1. Agent System
- SinglePurposeAgent: Base class for agents with one clear responsibility
- StructureFactorAgent: Calculates structure factors from atomic models
- TargetAgent: Computes target functions for refinement
- GradientAgent: Calculates gradients for optimization
- ExperimentalDataAgent: Handles experimental data processing
- AI Model Agents: Future agents for protein structure prediction, density interpretation, etc.
2. Redis Manager
- Persistent Storage: Stores data bundles with TTL and metadata
- Message Queues: Status messages and workflow coordination
- Serialization: Handles complex CCTBX objects via pickle/JSON
- Connection Pooling: Robust Redis connections with health monitoring
- Caching: Built-in caching for expensive computations
3. Bundle System
- Data Containers: Bundles hold related crystallographic data assets
- Metadata: Creation time, checksums, provenance information
- Validation: Built-in validation for bundle contents
- Type Safety: Strong typing for different bundle types
4. Utility Framework
- File Handling: PDB/MTZ file reading and validation
- Data Analysis: Complex number analysis, miller array statistics
- Workflow Management: Multi-step workflow orchestration
- CLI Tools: Command-line interface for common operations
Key Features
Modular Design
Each agent does ONE thing well:
- StructureFactorAgent: Only calculates structure factors
- TargetAgent: Only computes target functions
- AI Model Agents: Only handle AI predictions
- No mixing of concerns between agents
Technology Stack Separation
- AI Models: Can run on GPU clusters with PyTorch/TensorFlow
- Crystallographic Tools: Run on CPU clusters with CCTBX/Phenix
- Redis Middleware: Coordinates between different computational resources
- Event-Driven: Agents react to status messages, enabling asynchronous processing
Persistent Data Flow
- Redis stores all intermediate results
- Agents can be restarted without losing data
- Data persists between workflow runs
- Unique bundle IDs for tracking
Crystallographic Integration
- Native CCTBX support for crystallographic calculations
- Handles real PDB/MTZ files
- Structure factor calculations with bulk solvent
- R-factor computation and validation
Scalable Architecture
- Redis enables distributed processing
- Multiple agents can work on same data
- Easy to add new agent types
- Workflow orchestration for complex pipelines
Example Workflow
- Download Data: PDB structure + MTZ reflections
- Create Bundle: Package atomic model data
- Store in Redis: Persistent storage with metadata
- Run Agent: StructureFactorAgent processes data
- Store Results: Structure factors saved back to Redis
- Analyze: Comprehensive data analysis and statistics
Future AI Integration Workflows
AI-Assisted Structure Determination
- AI Model Agent: Predicts initial protein structure from sequence
- StructureFactorAgent: Calculates structure factors from AI prediction
- TargetAgent: Computes target function comparing to experimental data
- RefinementAgent: Optimizes structure using gradients
- ValidationAgent: Assesses structure quality
AI-Enhanced Electron Density Interpretation
- ExperimentalDataAgent: Processes experimental data
- AI Density Agent: Interprets electron density using deep learning
- StructureFactorAgent: Calculates structure factors
- ComparisonAgent: Validates AI interpretation against experimental data
Use Cases
Crystallographic Refinement
- Structure factor calculation from atomic models
- Target function computation for refinement
- Gradient calculation for optimization
- Experimental data integration
AI-Crystallography Integration
- Protein structure prediction integration
- Electron density interpretation with AI
- Automated structure validation
- AI-assisted model building
Data Pipeline Management
- Persistent storage of intermediate results
- Workflow orchestration for complex calculations
- Data validation and quality control
- Reproducible research workflows
Distributed Computing
- Multiple agents working on same dataset
- Redis as central data store
- Scalable architecture for large datasets
- Fault tolerance and recovery
Requirements
- Python 3.10+: Core language
- Redis: Data persistence, caching, and message queues
- CCTBX: Crystallographic calculations
- Pydantic: Data validation and serialization
- Click: Command-line interface
- Poetry: Dependency management
- Future: PyTorch/TensorFlow for AI model agents
Installation
You can install Agentbx via pip from PyPI:
$ pip install agentbx
Or install with Redis support:
$ pip install agentbx[redis-agents]
Quick Start
1. Start Redis Server
redis-server
2. Download Test Data
python examples/download_pdb_data.py 1ubq
3. Run Structure Factor Calculation
python examples/redis_structure_factor_example.py
4. Use CLI Tools
# Validate files
python -m agentbx.utils.cli validate examples/input.pdb examples/input.mtz
# Analyze a bundle
python -m agentbx.utils.cli analyze bundle_id_here
# Run workflow
python -m agentbx.utils.cli workflow examples/input.pdb examples/input.mtz
Code Organization
Contributing
Contributions are very welcome. To learn more, see the Contributor Guide.
License
Distributed under the terms of the MIT license, Agentbx is free and open source software.
Issues
If you encounter any problems, please file an issue along with a detailed description.
Credits
This project was generated from @cjolowicz's Hypermodern Python Cookiecutter template.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentbx-1.0.4.tar.gz.
File metadata
- Download URL: agentbx-1.0.4.tar.gz
- Upload date:
- Size: 40.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce31f2b0969f0755ca2b66d97f01e8fe3001a89acfc68b0f382141f0a5aa7401
|
|
| MD5 |
f82a0ef50b944b53c9b5d794c593ff55
|
|
| BLAKE2b-256 |
b083feed416ceea767bb0c3066f0e24492d89088331382938a6202c12630f81d
|
File details
Details for the file agentbx-1.0.4-py3-none-any.whl.
File metadata
- Download URL: agentbx-1.0.4-py3-none-any.whl
- Upload date:
- Size: 50.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
043c2ec485a270ba38973172130d05267ff24d76824a45f9c50884e1775bd50a
|
|
| MD5 |
d237186ebc90551a77a9ba3a46c248b8
|
|
| BLAKE2b-256 |
f398217ea27a2ea4cac24ecad59ab0a63f11f9cd4e8fd2a96e90b66f449cfd3d
|