LBCO Resume¶
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!
import easydiffraction as edi
import easydiffraction as edi
📂 Load Project¶
Locate Project¶
Download and extract the saved project from the EasyDiffraction data repository.
In [3]:
Copied!
project_dir = edi.download_data('proj-lbco-hrpt', destination='projects')
project_dir = edi.download_data('proj-lbco-hrpt', destination='projects')
Getting data...
Data 'proj-lbco-hrpt': La0.5Ba0.5CoO3, HRPT (PSI), 300 K
✅ Data 'proj-lbco-hrpt' downloaded and extracted to '../../../projects/proj-lbco-hrpt-69567a192590'
Load Project¶
In [4]:
Copied!
project = edi.Project.load(project_dir)
project = edi.Project.load(project_dir)
Re-save the project to a fresh working directory so fitting below writes there instead of the bundled read-only copy.
In [5]:
Copied!
project.save_as(dir_path='projects/load-and-fit-lbco-hrpt')
project.save_as(dir_path='projects/load-and-fit-lbco-hrpt')
Saving project 📦 'lbco_hrpt' to '../../../projects/load-and-fit-lbco-hrpt'
├── 📄 project.edi
├── 📁 structures/
│ └── 📄 lbco.edi
├── 📁 experiments/
│ └── 📄 hrpt.edi
├── 📁 analysis/
│ └── 📄 analysis.edi
└── 📁 reports/
└── 📄 lbco_hrpt.html
🚀 Perform Analysis¶
Display Structure¶
In [6]:
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 [7]:
Copied!
project.analysis.minimizer.chi_square_change_tolerance = 1e-2
project.analysis.minimizer.chi_square_change_tolerance = 1e-2
In [8]:
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.05 | 1.27 | |
| 2 | 20 | 0.89 | 1.26 |
🏆 Best goodness-of-fit (reduced χ²) is 1.26 at iteration 19
✅ Fitting complete.
Display Fit Results¶
In [9]:
Copied!
project.display.fit.results()
project.display.fit.results()
⚙️ Settings used:
| Name | Value | Description | |
|---|---|---|---|
| 1 | max_iterations | 1000 | Maximum solver iterations. |
| 2 | chi_square_change_tolerance | 0.01 | Relative change in the objective (chi-square) used to stop fitting. |
| 3 | parameter_change_tolerance | 1e-08 | Relative change in fitted parameters used to stop fitting. |
| 4 | gradient_tolerance | 0.0 | Gradient orthogonality used to stop fitting; zero disables it. |
📋 Least-squares fit results:
| Metric | Value | |
|---|---|---|
| 1 | 🧪 Minimizer | lmfit |
| 2 | ✅ Overall status | success |
| 3 | ⏱️ Fitting time (seconds) | 0.89 |
| 4 | 🔁 Iterations | 17 |
| 5 | 📏 Goodness-of-fit (reduced χ²) | 1.26 |
| 6 | 📏 R-factor (Rf, %) | 5.57 |
| 7 | 📏 R-factor squared (Rf², %) | 5.23 |
| 8 | 📏 Weighted R-factor (wR, %) | 7.13 |
📈 Refined parameters:
| datablock | category | entry | parameter | units | start | value | s.u. | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | lbco | cell | length_a | Å | 3.8908 | 3.8908 | 0.0000 | 0.00 % ↑ | |
| 2 | lbco | atom_site | La | adp_iso | Ų | 0.4920 | 0.4651 | 0.0302 | 5.47 % ↓ |
| 3 | lbco | atom_site | Co | adp_iso | Ų | 0.2490 | 0.2891 | 0.0447 | 16.10 % ↑ |
| 4 | lbco | atom_site | O | adp_iso | Ų | 1.4040 | 1.4066 | 0.0146 | 0.19 % ↑ |
| 5 | hrpt | linked_structure | lbco | scale | 9.1280 | 9.1103 | 0.0588 | 0.19 % ↓ | |
| 6 | hrpt | peak | broad_gauss_u | deg² | 0.0803 | 0.0813 | 0.0032 | 1.19 % ↑ | |
| 7 | hrpt | peak | broad_gauss_v | deg² | -0.1125 | -0.1153 | 0.0068 | 2.44 % ↑ | |
| 8 | hrpt | peak | broad_gauss_w | deg² | 0.1195 | 0.1203 | 0.0033 | 0.66 % ↑ | |
| 9 | hrpt | peak | broad_lorentz_y | deg | 0.0836 | 0.0843 | 0.0021 | 0.79 % ↑ | |
| 10 | hrpt | instrument | twotheta_offset | deg | 0.6205 | 0.6204 | 0.0008 | 0.00 % ↓ | |
| 11 | hrpt | background | 1 | intensity | 166.9200 | 166.9117 | 0.8920 | 0.00 % ↓ | |
| 12 | hrpt | background | 2 | intensity | 167.6100 | 167.6729 | 0.6889 | 0.04 % ↑ | |
| 13 | hrpt | background | 3 | intensity | 172.8800 | 172.6700 | 0.7111 | 0.12 % ↓ | |
| 14 | hrpt | background | 4 | intensity | 180.9200 | 181.0439 | 0.8757 | 0.07 % ↑ | |
| 15 | hrpt | background | 5 | intensity | 168.7000 | 162.6407 | 1.2406 | 3.59 % ↓ |
• 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 [10]:
Copied!
project.display.fit.correlations()
project.display.fit.correlations()
Loading plot…
In [11]:
Copied!
project.display.pattern(expt_name='hrpt')
project.display.pattern(expt_name='hrpt')
Loading plot…
💾 Save Project¶
In [12]:
Copied!
project.save_as(dir_path='projects/load-and-fit-lbco-hrpt')
project.save_as(dir_path='projects/load-and-fit-lbco-hrpt')
Saving project 📦 'lbco_hrpt' to '../../../projects/load-and-fit-lbco-hrpt'
├── 📄 project.edi
├── 📁 structures/
│ └── 📄 lbco.edi
├── 📁 experiments/
│ └── 📄 hrpt.edi
├── 📁 analysis/
│ └── 📄 analysis.edi
└── 📁 reports/
└── 📄 lbco_hrpt.html