AutoInsituXRD is a Python-based automation framework designed for fully coordinated in-situ X-ray diffraction (XRD) experiments. It seamlessly integrates UR5e robot motion, screw-driven sample loading, angle changer actuation, and Anton Paar XRD instrument control into a unified, high-throughput automation workflow and REST API.
- In-Situ XRD Instrument Control: Interfaces with Anton Paar XRDynamic / XRDrive 500 instrument APIs via robust HTTP requests.
- UR5e Robotic Manipulation: Supports UR5e robot program execution using direct dashboard socket controls.
- Automated Sample Loader: Manages screw automation mechanisms and linear rail hardware via TMCM and Arduino serial interfaces.
- Angle Changer Actuation: Elevates the crucible during in-situ XRD runs to dynamically change the gripping point from a vertical to a horizontal orientation.
- Provides lightweight Flask-based web endpoints for sample loading, unloading, door handling, and core experiment execution.
- Includes clean, modern frontend UI assets located under
templates/andstatic/for a centralized browser-based control dashboard.
- Python 3.9 or newer
- Conda (strongly recommended) or an equivalent Python environment manager
- Global hardware parameters configured inside
config.py - Valid
.urprobot program files loaded underrobot_arm_ur5e/templates/within your robot controller (teach pendant)
git clone https://github.com/CederGroupHub/AutoInsituXRD.git
cd AutoInsituXRDconda env create -f cond_env.yaml
conda activate insituXRD
3. Configure your hardware profile: Open config.py and map your specific instrument deployment parameters:
ROBOT_HOSTSCREW_TMCM_PORTSCREW_LINEAR_RAIL_PORTANGLE_CHANGER_PORTXRD_BASE_URL
python app.py- Spawns a Flask server listening on port
8000. - Access the browser UI directly at
http://127.0.0.1:8000/. - Available API Endpoints:
POST /api/home— Return hardware components to home positionPOST /api/load_sample— Trigger automated sample loading sequencePOST /api/unload_sample— Trigger automated sample unloading sequencePOST /api/door_open— Open XRD enclosure door (executes predefined.urpmotion planning)POST /api/door_close— Close XRD enclosure door (executes predefined.urpmotion planning)
python main_restAPI.py- Spawns an infrastructure-ready Flask server on port
5000. - Core Experiment Control Endpoints:
POST /insituXRD/run_experiment— Initialize and run a new execution blockGET /insituXRD/status— Query active hardware and sequence status
curl -X POST [http://127.0.0.1:5000/insituXRD/run_experiment](http://127.0.0.1:5000/insituXRD/run_experiment) \
-H "Content-Type: application/json" \
-d '{
"experiment_name": "Adaptive_Run_001",
"user_name": "researcher",
"base_storage_path": "C:/Users/XRDynamic/AutoExperiments",
"xrd_scan_mode": "adaptive",
"crucible_index": 0
}'
python main.py- Directly connects to the UR5e robot, angle changer, screw setup, and the XRD unit.
- Programmatically executes the comprehensive, standalone
run_full_sequence()workflow. - Generates runtime execution logs and stores them under
Logger/.
The repository is highly modularized and structured as follows:
AutoInsituXRD/
├── Adaptive_insituXRD/ # Anton Paar XRD API client and adaptive scan helper classes
├── AngleChanger/ # Arduino serial interface for the angle changer actuator
├── Logger/ # Logging utilities and runtime log storage directory
├── robot_arm_ur5e/ # UR5e robot dashboard interface and program execution drivers
├── SampleLoader/ # Screw automation and linear rail sample handling drivers
├── static/ # Frontend JavaScript and CSS assets for the web interface
├── templates/ # Flask HTML templates for the browser control panel
├── XRD_recipe_template/ # Reference JSON templates for defining XRD experimental recipes
│
├── app.py # Flask server hosting the sample loader/unloader UI & manual controls
├── main_restAPI.py # Production REST API server for external orchestrator (AlabOS) integration
├── main.py # Core sequencing script running the native in-situ automation routine
├── config.py # Central configuration file for hardware ports and system constants
└── cond_env.yaml # Conda environment file specifying exact dependencies