Load Project and Fit: LBCO, HRPT¶
This is the most minimal example of using EasyDiffraction. It shows how to load a previously saved project from a directory and run refinement — all in just a few lines of code.
For this example, constant-wavelength neutron powder diffraction data for La0.5Ba0.5CoO3 from HRPT at PSI is used.
It does not contain any advanced features or options, and includes no comments or explanations — these can be found in the other tutorials.
🛠️ Import Library¶
In [2]:
Copied!
from easydiffraction import Project
from easydiffraction import download_data
from easydiffraction import Project
from easydiffraction import download_data
📂 Load Project¶
Download Project¶
In [3]:
Copied!
project_dir = download_data(id=36, destination='projects')
project_dir = download_data(id=36, destination='projects')
Getting data...
Data #36: La0.5Ba0.5CoO3, HRPT (PSI), 300 K
✅ Data #36 downloaded and extracted to '../../../projects/ed-36/lbco_hrpt'
Load Project¶
In [4]:
Copied!
project = Project.load(project_dir)
project = Project.load(project_dir)
🚀 Perform Analysis¶
Display Structure¶
In [5]:
Copied!
project.display.structure(struct_name='lbco')
project.display.structure(struct_name='lbco')
Structure 🧩 'lbco' (Atom view type: 'covalent')
Loading plot…
drag = rotate
wheel = zoom
right-drag = pan
wheel = zoom
right-drag = pan
Run Fitting¶
In [6]:
Copied!
project.analysis.fit()
project.analysis.fit()
Standard fitting
📋 Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit progress:
| iteration | time (s) | χ² | change / status | |
|---|---|---|---|---|
| 1 | 1 | 0.30 | 1.29 | |
| 2 | 68 | 3.78 | 1.29 |
🏆 Best goodness-of-fit (reduced χ²) is 1.29 at iteration 67
✅ Fitting complete.
Saving project 📦 'lbco_hrpt' to '../../../projects/ed-36/lbco_hrpt'
├── 📄 project.cif
├── 📁 structures/
│ └── 📄 lbco.cif
├── 📁 experiments/
│ └── 📄 hrpt.cif
├── 📁 analysis/
│ └── 📄 analysis.cif
└── 📁 reports/
└── 📄 lbco_hrpt.html
Display Fit Results¶
In [7]:
Copied!
project.display.fit.results()
project.display.fit.results()
⚙️ Settings used:
| Name | Value | Description | |
|---|---|---|---|
| 1 | max_iterations | 1000 | Maximum solver iterations. |
📋 Least-squares fit results:
| Metric | Value | |
|---|---|---|
| 1 | 🧪 Minimizer | lmfit (leastsq) |
| 2 | ✅ Overall status | success |
| 3 | ⏱️ Fitting time (seconds) | 3.78 |
| 4 | 🔁 Iterations | 65 |
| 5 | 📏 Goodness-of-fit (reduced χ²) | 1.29 |
| 6 | 📏 R-factor (Rf, %) | 5.63 |
| 7 | 📏 R-factor squared (Rf², %) | 5.27 |
| 8 | 📏 Weighted R-factor (wR, %) | 4.41 |
📈 Refined parameters:
| datablock | category | entry | parameter | units | start | value | s.u. | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | lbco | cell | length_a | Å | 3.8908 | 3.8909 | 0.0000 | 0.00 % ↑ | |
| 2 | lbco | atom_site | La | adp_iso | Ų | 0.5150 | 0.5051 | 0.0278 | 1.93 % ↓ |
| 3 | lbco | atom_site | Co | adp_iso | Ų | 0.2190 | 0.2370 | 0.0564 | 8.22 % ↑ |
| 4 | lbco | atom_site | O | adp_iso | Ų | 1.3920 | 1.3935 | 0.0160 | 0.11 % ↑ |
| 5 | hrpt | linked_phases | lbco | scale | 9.1440 | 9.1351 | 0.0538 | 0.10 % ↓ | |
| 6 | hrpt | peak | broad_gauss_u | deg² | 0.0817 | 0.0816 | 0.0031 | 0.16 % ↓ | |
| 7 | hrpt | peak | broad_gauss_v | deg² | -0.1164 | -0.1159 | 0.0066 | 0.41 % ↓ | |
| 8 | hrpt | peak | broad_gauss_w | deg² | 0.1205 | 0.1204 | 0.0032 | 0.04 % ↓ | |
| 9 | hrpt | peak | broad_lorentz_y | deg | 0.0847 | 0.0844 | 0.0021 | 0.30 % ↓ | |
| 10 | hrpt | instrument | twotheta_offset | deg | 0.6204 | 0.6226 | 0.0010 | 0.35 % ↑ | |
| 11 | hrpt | background | 1 | y | 169.7000 | 168.5585 | 1.3669 | 0.67 % ↓ | |
| 12 | hrpt | background | 2 | y | 164.8000 | 164.3357 | 0.9990 | 0.28 % ↓ | |
| 13 | hrpt | background | 3 | y | 167.0200 | 166.8881 | 0.7386 | 0.08 % ↓ | |
| 14 | hrpt | background | 4 | y | 175.2700 | 175.4005 | 0.6488 | 0.07 % ↑ | |
| 15 | hrpt | background | 5 | y | 175.1200 | 174.2812 | 0.8944 | 0.48 % ↓ |
• start = parameter value before refinement
• value = refined value from least-squares minimization
• s.u. = standard uncertainty (one sigma), from the covariance matrix
• change = relative change from start, in %; ↑ = increase, ↓ = decrease
• value = refined value from least-squares minimization
• s.u. = standard uncertainty (one sigma), from the covariance matrix
• change = relative change from start, in %; ↑ = increase, ↓ = decrease
In [8]:
Copied!
project.display.fit.correlations()
project.display.fit.correlations()
Loading plot…
In [9]:
Copied!
project.display.pattern(expt_name='hrpt')
project.display.pattern(expt_name='hrpt')
Loading plot…
💾 Save Project¶
In [10]:
Copied!
project.save_as(dir_path='projects/ed_18_lbco_hrpt')
project.save_as(dir_path='projects/ed_18_lbco_hrpt')
Saving project 📦 'lbco_hrpt' to '../../../projects/ed_18_lbco_hrpt'
├── 📄 project.cif
├── 📁 structures/
│ └── 📄 lbco.cif
├── 📁 experiments/
│ └── 📄 hrpt.cif
├── 📁 analysis/
│ └── 📄 analysis.cif
└── 📁 reports/
└── 📄 lbco_hrpt.html