AI-Powered Synchrotron X-ray Diffraction Analysis System
Version 0.1.0 | Argonne National Laboratory
Beamline Assistant is an AI-powered system that provides real-time analysis of synchrotron X-ray diffraction data. It combines the MIDAS (Microstructure-Informed Data Analysis Suite) with advanced AI models through Argonne's Argo API gateway, enabling automated diffraction pattern analysis, phase identification, and scientific interpretation.
- macOS 10.15+ or Linux
- Python 3.9+
- Access to Argonne internal network (VPN or on-site)
- ANL domain account with Argo API access
- UV package manager
- MCP (Model Context Protocol) libraries
- MIDAS diffraction analysis tools
- Scientific Python stack (numpy, scipy, matplotlib)
curl -LsSf https://astral.sh/uv/install.sh | sh
source ~/.zshrc # or ~/.bashrc
mkdir beamline-assistant && cd beamline-assistant
uv init
uv add mcp httpx python-dotenv numpy scipy matplotlib pandas
uv add Pillow scikit-image pyFAI fabio plotly seaborn lmfit
uv add orjson rich typer fastapi uvicorn websockets
uv add mcp httpx python-dotenv asyncio-compat
Create a .env
file:
# Required: Your ANL domain username
ANL_USERNAME=your_anl_username
# Default AI model
ARGO_MODEL=gpt4o
# Optional: Path to MIDAS installation
MIDAS_PATH=./MIDAS/utils
chmod +x *.py
The system consists of multiple FastMCP servers connected through a central client:
- MIDAS Server: Diffraction analysis tools
- Command Executor: System command execution
- Filesystem Server: File operations
- Argo Client: AI integration and user interface
uv run argo_mcp_client.py fastmcp_midas_server.py
uv run argo_mcp_client.py midas:fastmcp_midas_server.py executor:command_executor_server.py filesystem:filesystem_server.py
After startup, verify all servers are connected:
Beamline> servers
Connected: ['midas', 'executor', 'filesystem']
Command | Description | Example |
---|---|---|
analyze <file> |
Full diffraction analysis | analyze /data/steel.tif |
models |
List available AI models | models |
model <name> |
Switch AI model | model claudesonnet4 |
tools |
Show all analysis tools | tools |
servers |
Show connected servers | servers |
ls <path> |
List directory contents | ls /data |
run <command> |
Execute system command | run python --version |
help |
Show help information | help |
quit |
Exit the system | quit |
The system understands natural language queries about diffraction data:
# Phase identification
Beamline> I have peaks at 12.5, 18.2, 25.8, 31.4 degrees. What phases are these?
# Data quality assessment
Beamline> Check the quality of my diffraction pattern at /data/sample001.tif
# Pattern analysis
Beamline> Integrate the 2D pattern and find all peaks above 5% intensity
# General questions
Beamline> What's the difference between austenite and ferrite?
Input: List of 2θ peak positions Process: Automatic crystallographic database matching Output: Formatted phase analysis with confidence scores
Beamline> I have peaks at 12.5, 18.2, 25.8, 31.4 degrees. What phases are these?
Expected Output:
PHASE IDENTIFICATION RESULTS
==================================================
Input peaks analyzed: 4
Peak positions: [12.5, 18.2, 25.8, 31.4]
IDENTIFIED PHASES:
--------------------
1. Austenite (γ-Fe)
Crystal System: Cubic
Space Group: Fm-3m
Phase Fraction: 65.0%
Confidence: 92%
Matched Peaks:
• 12.5° → (111) (calc: 12.47°, intensity: 100%)
• 18.2° → (200) (calc: 18.15°, intensity: 60%)
• 25.8° → (220) (calc: 25.84°, intensity: 40%)
ANALYSIS SUMMARY:
-----------------
Total phases found: 1
Peaks matched: 3/4
Match quality: Excellent
Beamline> analyze /beamline/data/steel_sample_RT.tif
Analysis Steps:
- File existence verification
- Ring detection and quality assessment
- 2D to 1D pattern integration
- Peak finding and fitting
- Phase identification
- Scientific interpretation
Beamline> Check the quality of /data/experiment_001.tif
Assessment Includes:
- Signal-to-noise ratio
- Background uniformity
- Peak resolution
- Detector performance metrics
- Recommendations for improvement
gpt4o
- GPT-4o (recommended for most tasks)gpt4turbo
- GPT-4 Turbogpt4
- Standard GPT-4
claudesonnet4
- Claude Sonnet 4gemini25pro
- Gemini 2.5 Progpt5
- GPT-5 (when available)
Beamline> model claudesonnet4
✅ Switched to model: claudesonnet4
Provider: Anthropic
Description: Claude Sonnet 4 (200K input, dev only)
- Images: TIFF, PNG, JPG (2D diffraction patterns)
- Data: DAT, XY, TXT, CSV (1D integrated patterns)
- Configurations: JSON, YAML
# List beamline data directory
Beamline> ls /beamline/data
# Check file information
Beamline> Get info about /data/sample.tif
# Read measurement log
Beamline> Read the file /beamline/logs/experiment.txt
The system allows execution of whitelisted commands for safety:
Allowed Commands:
- File operations:
ls
,cat
,head
,tail
,find
- Python tools:
python
,pip
,uv
- System info:
ps
,df
,whoami
,env
- Development:
git
,which
# Check Python environment
Beamline> run python --version
# List large files
Beamline> run find /data -size +100M -type f
# Check disk usage
Beamline> run df -h
The system recognizes common material systems:
# Steel analysis
Beamline> I have a duplex steel sample with peaks at 12.5, 31.4, 44.7 degrees
# Aluminum alloy
Beamline> Analyze this aluminum alloy pattern with texture
# Ceramic analysis
Beamline> What oxide phases could give peaks at 25.3, 35.1, 43.2 degrees?
Beamline> I have peaks at 800°C: 12.1, 17.9, 25.5 degrees. What phases at this temperature?
Beamline> How can I analyze 100 similar steel samples automatically?
Connection Problems:
# Check server status
Beamline> servers
# Restart with single server
uv run argo_mcp_client.py midas:fastmcp_midas_server.py
File Access Issues:
# Verify file exists
Beamline> ls /path/to/your/file
# Check permissions
Beamline> run ls -la /path/to/file
Analysis Errors:
# Check MIDAS dependencies
Beamline> run python -c "import fabio, pyFAI; print('OK')"
# Test with simple data
Beamline> I have peaks at 12.5, 18.2 degrees. What could these be?
Error | Cause | Solution |
---|---|---|
"Server not connected" | MCP server failed | Restart with single server |
"File not found" | Invalid file path | Use ls to verify path |
"Command not allowed" | Restricted command | Use whitelisted commands only |
"Argo API error" | Network/auth issue | Check VPN connection |
- Use specific queries: "Peaks at 12.5, 18.2 degrees" vs "Analyze my data"
- Include context: Mention material type, temperature, experimental conditions
- Choose appropriate models:
gpt4o
for fast, accurate analysisclaudesonnet4
for detailed scientific interpretationgemini25pro
for complex multi-step analysis
- Large files (>50MB): Use
analyze
command with automatic chunking - Multiple samples: Process individually for better accuracy
- Complex materials: Provide expected phases or material system
- Data Collection: Collect diffraction pattern
- Quick Check:
Beamline> analyze /path/to/new/pattern.tif
- Phase Verification: Ask specific questions about results
- Parameter Optimization: Get AI recommendations for next measurement
# Get measurement suggestions
Beamline> I want to study austenite decomposition in steel. What peaks should I monitor?
# Optimize conditions
Beamline> My peaks are weak at 2θ = 45°. How can I improve the signal?
# Document results
Beamline> Summarize today's phase analysis results for my lab notebook
- All analysis occurs locally on Argonne network
- No diffraction data sent to external services
- User authentication through ANL domain credentials
- Only whitelisted system commands allowed
- No file modification commands in restricted directories
- Automatic timeout for long-running processes
- Technical Issues: Contact system administrator
- Analysis Questions: Ask Beamline Assistant directly
- Feature Requests: Submit through Vector ticketing system
# Update dependencies
uv sync --upgrade
# Check for system updates
Beamline> run uv list --outdated
# Check system status
Beamline> run ps aux | grep midas
# View recent errors
Beamline> Check system logs for any errors
- Be specific with peak positions: "12.5, 18.2, 25.8 degrees"
- Include experimental context: "steel sample at 800°C"
- Ask follow-up questions for clarification
- Use consistent file naming conventions
- Organize data by experiment date/type
- Keep measurement logs accessible
- Start with
gpt4o
for general analysis - Use
claudesonnet4
for detailed interpretation - Try
gemini25pro
for complex multi-phase systems
- Quick phase ID first: check major phases
- Detailed analysis second: quantitative results
- Interpretation last: scientific significance
This system transforms synchrotron diffraction analysis from manual interpretation to AI-assisted scientific discovery, enabling faster insights and better experimental decisions at the beamline.