Structure Refinement: HS, HRPT¶
This example demonstrates a Rietveld refinement of HS crystal structure using constant wavelength neutron powder diffraction data from HRPT at PSI.
Import Library¶
In [2]:
Copied!
from easydiffraction import ExperimentFactory
from easydiffraction import Project
from easydiffraction import StructureFactory
from easydiffraction import download_data
from easydiffraction import ExperimentFactory
from easydiffraction import Project
from easydiffraction import StructureFactory
from easydiffraction import download_data
In [3]:
Copied!
structure = StructureFactory.from_scratch(name='hs')
structure = StructureFactory.from_scratch(name='hs')
Set Space Group¶
In [4]:
Copied!
structure.space_group.name_h_m = 'R -3 m'
structure.space_group.it_coordinate_system_code = 'h'
structure.space_group.name_h_m = 'R -3 m'
structure.space_group.it_coordinate_system_code = 'h'
Set Unit Cell¶
In [5]:
Copied!
structure.cell.length_a = 6.9
structure.cell.length_c = 14.1
structure.cell.length_a = 6.9
structure.cell.length_c = 14.1
Set Atom Sites¶
In [6]:
Copied!
structure.atom_sites.create(
label='Zn',
type_symbol='Zn',
fract_x=0,
fract_y=0,
fract_z=0.5,
wyckoff_letter='b',
adp_iso=0.5,
)
structure.atom_sites.create(
label='Cu',
type_symbol='Cu',
fract_x=0.5,
fract_y=0,
fract_z=0,
wyckoff_letter='e',
adp_iso=0.5,
)
structure.atom_sites.create(
label='O',
type_symbol='O',
fract_x=0.21,
fract_y=-0.21,
fract_z=0.06,
wyckoff_letter='h',
adp_iso=0.5,
)
structure.atom_sites.create(
label='Cl',
type_symbol='Cl',
fract_x=0,
fract_y=0,
fract_z=0.197,
wyckoff_letter='c',
adp_iso=0.5,
)
structure.atom_sites.create(
label='H',
type_symbol='2H',
fract_x=0.13,
fract_y=-0.13,
fract_z=0.08,
wyckoff_letter='h',
adp_iso=0.5,
)
structure.atom_sites.create(
label='Zn',
type_symbol='Zn',
fract_x=0,
fract_y=0,
fract_z=0.5,
wyckoff_letter='b',
adp_iso=0.5,
)
structure.atom_sites.create(
label='Cu',
type_symbol='Cu',
fract_x=0.5,
fract_y=0,
fract_z=0,
wyckoff_letter='e',
adp_iso=0.5,
)
structure.atom_sites.create(
label='O',
type_symbol='O',
fract_x=0.21,
fract_y=-0.21,
fract_z=0.06,
wyckoff_letter='h',
adp_iso=0.5,
)
structure.atom_sites.create(
label='Cl',
type_symbol='Cl',
fract_x=0,
fract_y=0,
fract_z=0.197,
wyckoff_letter='c',
adp_iso=0.5,
)
structure.atom_sites.create(
label='H',
type_symbol='2H',
fract_x=0.13,
fract_y=-0.13,
fract_z=0.08,
wyckoff_letter='h',
adp_iso=0.5,
)
In [7]:
Copied!
data_path = download_data(id=11, destination='data')
data_path = download_data(id=11, destination='data')
Getting data...
Data #11: HS, HRPT (PSI)
✅ Data #11 downloaded to 'data/ed-11.xye'
Create Experiment¶
In [8]:
Copied!
expt = ExperimentFactory.from_data_path(name='hrpt', data_path=data_path)
expt = ExperimentFactory.from_data_path(name='hrpt', data_path=data_path)
Set Instrument¶
In [9]:
Copied!
expt.instrument.setup_wavelength = 1.89
expt.instrument.calib_twotheta_offset = 0.0
expt.instrument.setup_wavelength = 1.89
expt.instrument.calib_twotheta_offset = 0.0
Set Peak Profile¶
In [10]:
Copied!
expt.show_supported_peak_profile_types()
expt.show_current_peak_profile_type()
expt.peak_profile_type = 'pseudo-voigt + empirical asymmetry'
expt.peak.broad_gauss_u = 0.1
expt.peak.broad_gauss_v = -0.2
expt.peak.broad_gauss_w = 0.2
expt.peak.broad_lorentz_x = 0.0
expt.peak.broad_lorentz_y = 0
expt.show_supported_peak_profile_types()
expt.show_current_peak_profile_type()
expt.peak_profile_type = 'pseudo-voigt + empirical asymmetry'
expt.peak.broad_gauss_u = 0.1
expt.peak.broad_gauss_v = -0.2
expt.peak.broad_gauss_w = 0.2
expt.peak.broad_lorentz_x = 0.0
expt.peak.broad_lorentz_y = 0
Supported types
| Type | Description | |
|---|---|---|
| 1 | pseudo-voigt | Pseudo-Voigt profile |
| 2 | pseudo-voigt + empirical asymmetry | Pseudo-Voigt with empirical asymmetry correction |
Current peak profile type
pseudo-voigt
⚠️ Switching peak profile type discards existing peak parameters.
Peak profile type for experiment 'hrpt' changed to
pseudo-voigt + empirical asymmetry
Set Background¶
In [11]:
Copied!
expt.background.create(id='1', x=4.4196, y=500)
expt.background.create(id='2', x=6.6207, y=500)
expt.background.create(id='3', x=10.4918, y=500)
expt.background.create(id='4', x=15.4634, y=500)
expt.background.create(id='5', x=45.6041, y=500)
expt.background.create(id='6', x=74.6844, y=500)
expt.background.create(id='7', x=103.4187, y=500)
expt.background.create(id='8', x=121.6311, y=500)
expt.background.create(id='9', x=159.4116, y=500)
expt.background.create(id='1', x=4.4196, y=500)
expt.background.create(id='2', x=6.6207, y=500)
expt.background.create(id='3', x=10.4918, y=500)
expt.background.create(id='4', x=15.4634, y=500)
expt.background.create(id='5', x=45.6041, y=500)
expt.background.create(id='6', x=74.6844, y=500)
expt.background.create(id='7', x=103.4187, y=500)
expt.background.create(id='8', x=121.6311, y=500)
expt.background.create(id='9', x=159.4116, y=500)
Set Linked Phases¶
In [12]:
Copied!
expt.linked_phases.create(id='hs', scale=0.5)
expt.linked_phases.create(id='hs', scale=0.5)
In [13]:
Copied!
project = Project()
project = Project()
Add Structure¶
In [14]:
Copied!
project.structures.add(structure)
project.structures.add(structure)
Add Experiment¶
In [15]:
Copied!
project.experiments.add(expt)
project.experiments.add(expt)
In [16]:
Copied!
project.plotter.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
project.plotter.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
In [17]:
Copied!
project.plotter.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
project.plotter.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
Perform Fit 1/4¶
Set parameters to be refined.
In [18]:
Copied!
structure.cell.length_a.free = True
structure.cell.length_c.free = True
expt.linked_phases['hs'].scale.free = True
expt.instrument.calib_twotheta_offset.free = True
structure.cell.length_a.free = True
structure.cell.length_c.free = True
expt.linked_phases['hs'].scale.free = True
expt.instrument.calib_twotheta_offset.free = True
Show free parameters after selection.
In [19]:
Copied!
project.analysis.display.free_params()
project.analysis.display.free_params()
Free parameters for both structures (🧩 data blocks) and experiments (🔬 data blocks)
| datablock | category | entry | parameter | value | uncertainty | min | max | units | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.90000 | -inf | inf | Å | ||
| 2 | hs | cell | length_c | 14.10000 | -inf | inf | Å | ||
| 3 | hrpt | linked_phases | hs | scale | 0.50000 | -inf | inf | ||
| 4 | hrpt | instrument | twotheta_offset | 0.00000 | -inf | inf | deg |
Run Fitting¶
In [20]:
Copied!
project.analysis.fit()
project.analysis.fit()
Standard fitting
📋 Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit (reduced χ²) change:
| iteration | χ² | improvement [%] | |
|---|---|---|---|
| 1 | 1 | 576.50 | |
| 2 | 8 | 122.02 | 78.8% ↓ |
| 3 | 13 | 115.19 | 5.6% ↓ |
| 4 | 18 | 109.86 | 4.6% ↓ |
| 5 | 23 | 106.68 | 2.9% ↓ |
| 6 | 28 | 104.60 | 2.0% ↓ |
| 7 | 33 | 102.87 | 1.7% ↓ |
| 8 | 38 | 101.13 | 1.7% ↓ |
| 9 | 43 | 99.20 | 1.9% ↓ |
| 10 | 48 | 96.86 | 2.4% ↓ |
| 11 | 53 | 93.93 | 3.0% ↓ |
| 12 | 58 | 90.34 | 3.8% ↓ |
| 13 | 63 | 86.20 | 4.6% ↓ |
| 14 | 68 | 81.66 | 5.3% ↓ |
| 15 | 73 | 76.78 | 6.0% ↓ |
| 16 | 78 | 71.71 | 6.6% ↓ |
| 17 | 83 | 66.82 | 6.8% ↓ |
| 18 | 88 | 62.48 | 6.5% ↓ |
| 19 | 93 | 58.99 | 5.6% ↓ |
| 20 | 98 | 56.41 | 4.4% ↓ |
| 21 | 103 | 54.64 | 3.1% ↓ |
| 22 | 108 | 53.49 | 2.1% ↓ |
| 23 | 113 | 52.76 | 1.4% ↓ |
| 24 | 123 | 52.02 | 1.4% ↓ |
| 25 | 304 | 51.57 |
🏆 Best goodness-of-fit (reduced χ²) is 51.57 at iteration 303
✅ Fitting complete.
In [21]:
Copied!
project.analysis.display.fit_results()
project.analysis.display.fit_results()
Fit results
✅ Success: True
⏱️ Fitting time: 25.53 seconds
📏 Goodness-of-fit (reduced χ²): 51.57
📏 R-factor (Rf): 19.70%
📏 R-factor squared (Rf²): 30.20%
📏 Weighted R-factor (wR): 30.35%
📈 Fitted parameters:
| datablock | category | entry | parameter | start | fitted | uncertainty | units | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.9000 | 6.8623 | 0.0003 | Å | 0.55 % ↓ | |
| 2 | hs | cell | length_c | 14.1000 | 14.1365 | 0.0008 | Å | 0.26 % ↑ | |
| 3 | hrpt | linked_phases | hs | scale | 0.5000 | 0.2548 | 0.0030 | 49.04 % ↓ | |
| 4 | hrpt | instrument | twotheta_offset | 0.0000 | 0.1271 | 0.0051 | deg | N/A |
Plot Measured vs Calculated¶
In [22]:
Copied!
project.plotter.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
project.plotter.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
In [23]:
Copied!
project.plotter.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
project.plotter.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
Perform Fit 2/4¶
Set more parameters to be refined.
In [24]:
Copied!
expt.peak.broad_gauss_u.free = True
expt.peak.broad_gauss_v.free = True
expt.peak.broad_gauss_w.free = True
expt.peak.broad_lorentz_y.free = True
for point in expt.background:
point.y.free = True
expt.peak.broad_gauss_u.free = True
expt.peak.broad_gauss_v.free = True
expt.peak.broad_gauss_w.free = True
expt.peak.broad_lorentz_y.free = True
for point in expt.background:
point.y.free = True
Show free parameters after selection.
In [25]:
Copied!
project.analysis.display.free_params()
project.analysis.display.free_params()
Free parameters for both structures (🧩 data blocks) and experiments (🔬 data blocks)
| datablock | category | entry | parameter | value | uncertainty | min | max | units | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.86229 | 0.00029 | -inf | inf | Å | |
| 2 | hs | cell | length_c | 14.13651 | 0.00084 | -inf | inf | Å | |
| 3 | hrpt | linked_phases | hs | scale | 0.25480 | 0.00305 | -inf | inf | |
| 4 | hrpt | peak | broad_gauss_u | 0.10000 | -inf | inf | deg² | ||
| 5 | hrpt | peak | broad_gauss_v | -0.20000 | -inf | inf | deg² | ||
| 6 | hrpt | peak | broad_gauss_w | 0.20000 | -inf | inf | deg² | ||
| 7 | hrpt | peak | broad_lorentz_y | 0.00000 | -inf | inf | deg | ||
| 8 | hrpt | instrument | twotheta_offset | 0.12712 | 0.00515 | -inf | inf | deg | |
| 9 | hrpt | background | 1 | y | 500.00000 | -inf | inf | ||
| 10 | hrpt | background | 2 | y | 500.00000 | -inf | inf | ||
| 11 | hrpt | background | 3 | y | 500.00000 | -inf | inf | ||
| 12 | hrpt | background | 4 | y | 500.00000 | -inf | inf | ||
| 13 | hrpt | background | 5 | y | 500.00000 | -inf | inf | ||
| 14 | hrpt | background | 6 | y | 500.00000 | -inf | inf | ||
| 15 | hrpt | background | 7 | y | 500.00000 | -inf | inf | ||
| 16 | hrpt | background | 8 | y | 500.00000 | -inf | inf | ||
| 17 | hrpt | background | 9 | y | 500.00000 | -inf | inf |
Run Fitting¶
In [26]:
Copied!
project.analysis.fit()
project.analysis.fit()
Standard fitting
📋 Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit (reduced χ²) change:
| iteration | χ² | improvement [%] | |
|---|---|---|---|
| 1 | 1 | 51.78 | |
| 2 | 21 | 15.91 | 69.3% ↓ |
| 3 | 39 | 15.07 | 5.3% ↓ |
| 4 | 57 | 14.17 | 6.0% ↓ |
| 5 | 75 | 13.42 | 5.3% ↓ |
| 6 | 220 | 13.39 |
🏆 Best goodness-of-fit (reduced χ²) is 13.39 at iteration 219
✅ Fitting complete.
In [27]:
Copied!
project.analysis.display.fit_results()
project.analysis.display.fit_results()
Fit results
✅ Success: True
⏱️ Fitting time: 19.30 seconds
📏 Goodness-of-fit (reduced χ²): 13.39
📏 R-factor (Rf): 10.13%
📏 R-factor squared (Rf²): 14.05%
📏 Weighted R-factor (wR): 13.91%
📈 Fitted parameters:
| datablock | category | entry | parameter | start | fitted | uncertainty | units | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.8623 | 6.8631 | 0.0003 | Å | 0.01 % ↑ | |
| 2 | hs | cell | length_c | 14.1365 | 14.1397 | 0.0009 | Å | 0.02 % ↑ | |
| 3 | hrpt | linked_phases | hs | scale | 0.2548 | 0.4270 | 0.0039 | 67.58 % ↑ | |
| 4 | hrpt | peak | broad_gauss_u | 0.1000 | 0.3338 | 0.0270 | deg² | 233.82 % ↑ | |
| 5 | hrpt | peak | broad_gauss_v | -0.2000 | -0.2705 | 0.0498 | deg² | 35.27 % ↑ | |
| 6 | hrpt | peak | broad_gauss_w | 0.2000 | 0.2067 | 0.0214 | deg² | 3.37 % ↑ | |
| 7 | hrpt | peak | broad_lorentz_y | 0.0000 | 0.1859 | 0.0103 | deg | N/A | |
| 8 | hrpt | instrument | twotheta_offset | 0.1271 | 0.1316 | 0.0040 | deg | 3.49 % ↑ | |
| 9 | hrpt | background | 1 | y | 500.0000 | 595.4716 | 24.8884 | 19.09 % ↑ | |
| 10 | hrpt | background | 2 | y | 500.0000 | 500.0658 | 14.1957 | 0.01 % ↑ | |
| 11 | hrpt | background | 3 | y | 500.0000 | 446.7961 | 10.8562 | 10.64 % ↓ | |
| 12 | hrpt | background | 4 | y | 500.0000 | 423.0736 | 5.6094 | 15.39 % ↓ | |
| 13 | hrpt | background | 5 | y | 500.0000 | 469.5233 | 6.1230 | 6.10 % ↓ | |
| 14 | hrpt | background | 6 | y | 500.0000 | 473.3416 | 5.9675 | 5.33 % ↓ | |
| 15 | hrpt | background | 7 | y | 500.0000 | 431.9294 | 5.7359 | 13.61 % ↓ | |
| 16 | hrpt | background | 8 | y | 500.0000 | 388.9936 | 6.0673 | 22.20 % ↓ | |
| 17 | hrpt | background | 9 | y | 500.0000 | 501.8443 | 5.6961 | 0.37 % ↑ |
Plot Measured vs Calculated¶
In [28]:
Copied!
project.plotter.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
project.plotter.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
In [29]:
Copied!
project.plotter.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
project.plotter.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
Perform Fit 3/4¶
Set more parameters to be refined.
In [30]:
Copied!
structure.atom_sites['O'].fract_x.free = True
structure.atom_sites['O'].fract_z.free = True
structure.atom_sites['Cl'].fract_z.free = True
structure.atom_sites['H'].fract_x.free = True
structure.atom_sites['H'].fract_z.free = True
structure.atom_sites['O'].fract_x.free = True
structure.atom_sites['O'].fract_z.free = True
structure.atom_sites['Cl'].fract_z.free = True
structure.atom_sites['H'].fract_x.free = True
structure.atom_sites['H'].fract_z.free = True
Show free parameters after selection.
In [31]:
Copied!
project.analysis.display.free_params()
project.analysis.display.free_params()
Free parameters for both structures (🧩 data blocks) and experiments (🔬 data blocks)
| datablock | category | entry | parameter | value | uncertainty | min | max | units | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.86308 | 0.00035 | -inf | inf | Å | |
| 2 | hs | cell | length_c | 14.13974 | 0.00094 | -inf | inf | Å | |
| 3 | hs | atom_site | O | fract_x | 0.21000 | -inf | inf | ||
| 4 | hs | atom_site | O | fract_z | 0.06000 | -inf | inf | ||
| 5 | hs | atom_site | Cl | fract_z | 0.19700 | -inf | inf | ||
| 6 | hs | atom_site | H | fract_x | 0.13000 | -inf | inf | ||
| 7 | hs | atom_site | H | fract_z | 0.08000 | -inf | inf | ||
| 8 | hrpt | linked_phases | hs | scale | 0.42699 | 0.00386 | -inf | inf | |
| 9 | hrpt | peak | broad_gauss_u | 0.33382 | 0.02703 | -inf | inf | deg² | |
| 10 | hrpt | peak | broad_gauss_v | -0.27053 | 0.04977 | -inf | inf | deg² | |
| 11 | hrpt | peak | broad_gauss_w | 0.20675 | 0.02144 | -inf | inf | deg² | |
| 12 | hrpt | peak | broad_lorentz_y | 0.18589 | 0.01026 | -inf | inf | deg | |
| 13 | hrpt | instrument | twotheta_offset | 0.13156 | 0.00402 | -inf | inf | deg | |
| 14 | hrpt | background | 1 | y | 595.47160 | 24.88844 | -inf | inf | |
| 15 | hrpt | background | 2 | y | 500.06584 | 14.19569 | -inf | inf | |
| 16 | hrpt | background | 3 | y | 446.79606 | 10.85617 | -inf | inf | |
| 17 | hrpt | background | 4 | y | 423.07355 | 5.60941 | -inf | inf | |
| 18 | hrpt | background | 5 | y | 469.52331 | 6.12295 | -inf | inf | |
| 19 | hrpt | background | 6 | y | 473.34159 | 5.96754 | -inf | inf | |
| 20 | hrpt | background | 7 | y | 431.92940 | 5.73592 | -inf | inf | |
| 21 | hrpt | background | 8 | y | 388.99361 | 6.06730 | -inf | inf | |
| 22 | hrpt | background | 9 | y | 501.84432 | 5.69613 | -inf | inf |
Run Fitting¶
In [32]:
Copied!
project.analysis.fit()
project.analysis.fit()
Standard fitting
📋 Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit (reduced χ²) change:
| iteration | χ² | improvement [%] | |
|---|---|---|---|
| 1 | 1 | 13.41 | |
| 2 | 26 | 5.76 | 57.1% ↓ |
| 3 | 49 | 5.48 | 4.7% ↓ |
| 4 | 211 | 5.47 |
🏆 Best goodness-of-fit (reduced χ²) is 5.47 at iteration 210
✅ Fitting complete.
In [33]:
Copied!
project.analysis.display.fit_results()
project.analysis.display.fit_results()
Fit results
✅ Success: True
⏱️ Fitting time: 18.25 seconds
📏 Goodness-of-fit (reduced χ²): 5.47
📏 R-factor (Rf): 6.71%
📏 R-factor squared (Rf²): 9.26%
📏 Weighted R-factor (wR): 9.33%
📈 Fitted parameters:
| datablock | category | entry | parameter | start | fitted | uncertainty | units | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.8631 | 6.8623 | 0.0002 | Å | 0.01 % ↓ | |
| 2 | hs | cell | length_c | 14.1397 | 14.1357 | 0.0005 | Å | 0.03 % ↓ | |
| 3 | hs | atom_site | O | fract_x | 0.2100 | 0.2059 | 0.0002 | 1.96 % ↓ | |
| 4 | hs | atom_site | O | fract_z | 0.0600 | 0.0627 | 0.0002 | 4.53 % ↑ | |
| 5 | hs | atom_site | Cl | fract_z | 0.1970 | 0.1979 | 0.0002 | 0.46 % ↑ | |
| 6 | hs | atom_site | H | fract_x | 0.1300 | 0.1336 | 0.0002 | 2.75 % ↑ | |
| 7 | hs | atom_site | H | fract_z | 0.0800 | 0.0870 | 0.0001 | 8.72 % ↑ | |
| 8 | hrpt | linked_phases | hs | scale | 0.4270 | 0.3988 | 0.0023 | 6.59 % ↓ | |
| 9 | hrpt | peak | broad_gauss_u | 0.3338 | 0.3426 | 0.0146 | deg² | 2.64 % ↑ | |
| 10 | hrpt | peak | broad_gauss_v | -0.2705 | -0.3774 | 0.0280 | deg² | 39.51 % ↑ | |
| 11 | hrpt | peak | broad_gauss_w | 0.2067 | 0.2762 | 0.0132 | deg² | 33.57 % ↑ | |
| 12 | hrpt | peak | broad_lorentz_y | 0.1859 | 0.1516 | 0.0062 | deg | 18.46 % ↓ | |
| 13 | hrpt | instrument | twotheta_offset | 0.1316 | 0.1182 | 0.0025 | deg | 10.15 % ↓ | |
| 14 | hrpt | background | 1 | y | 595.4716 | 606.8549 | 15.8977 | 1.91 % ↑ | |
| 15 | hrpt | background | 2 | y | 500.0658 | 506.3937 | 9.0721 | 1.27 % ↑ | |
| 16 | hrpt | background | 3 | y | 446.7961 | 446.6115 | 6.9412 | 0.04 % ↓ | |
| 17 | hrpt | background | 4 | y | 423.0736 | 433.4635 | 3.6117 | 2.46 % ↑ | |
| 18 | hrpt | background | 5 | y | 469.5233 | 480.8266 | 3.8602 | 2.41 % ↑ | |
| 19 | hrpt | background | 6 | y | 473.3416 | 504.1347 | 3.7880 | 6.51 % ↑ | |
| 20 | hrpt | background | 7 | y | 431.9294 | 465.0255 | 3.6648 | 7.66 % ↑ | |
| 21 | hrpt | background | 8 | y | 388.9936 | 446.8489 | 3.9092 | 14.87 % ↑ | |
| 22 | hrpt | background | 9 | y | 501.8443 | 457.5213 | 3.8978 | 8.83 % ↓ |
Plot Measured vs Calculated¶
In [34]:
Copied!
project.plotter.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
project.plotter.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
In [35]:
Copied!
project.plotter.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
project.plotter.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
Perform Fit 4/4¶
Set more parameters to be refined.
In [36]:
Copied!
structure.atom_sites['Zn'].adp_iso.free = True
structure.atom_sites['Cu'].adp_iso.free = True
structure.atom_sites['O'].adp_iso.free = True
structure.atom_sites['Cl'].adp_iso.free = True
structure.atom_sites['H'].adp_iso.free = True
expt.peak.asym_empir_1.free = True
expt.peak.asym_empir_2.free = True
expt.peak.asym_empir_3.free = True
expt.peak.asym_empir_4.free = True
structure.atom_sites['Zn'].adp_iso.free = True
structure.atom_sites['Cu'].adp_iso.free = True
structure.atom_sites['O'].adp_iso.free = True
structure.atom_sites['Cl'].adp_iso.free = True
structure.atom_sites['H'].adp_iso.free = True
expt.peak.asym_empir_1.free = True
expt.peak.asym_empir_2.free = True
expt.peak.asym_empir_3.free = True
expt.peak.asym_empir_4.free = True
Show free parameters after selection.
In [37]:
Copied!
project.analysis.display.free_params()
project.analysis.display.free_params()
Free parameters for both structures (🧩 data blocks) and experiments (🔬 data blocks)
| datablock | category | entry | parameter | value | uncertainty | min | max | units | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.86227 | 0.00023 | -inf | inf | Å | |
| 2 | hs | cell | length_c | 14.13575 | 0.00055 | -inf | inf | Å | |
| 3 | hs | atom_site | Zn | adp_iso | 0.50000 | -inf | inf | Ų | |
| 4 | hs | atom_site | Cu | adp_iso | 0.50000 | -inf | inf | Ų | |
| 5 | hs | atom_site | O | fract_x | 0.20588 | 0.00024 | -inf | inf | |
| 6 | hs | atom_site | O | fract_z | 0.06272 | 0.00018 | -inf | inf | |
| 7 | hs | atom_site | O | adp_iso | 0.50000 | -inf | inf | Ų | |
| 8 | hs | atom_site | Cl | fract_z | 0.19790 | 0.00018 | -inf | inf | |
| 9 | hs | atom_site | Cl | adp_iso | 0.50000 | -inf | inf | Ų | |
| 10 | hs | atom_site | H | fract_x | 0.13357 | 0.00018 | -inf | inf | |
| 11 | hs | atom_site | H | fract_z | 0.08697 | 0.00013 | -inf | inf | |
| 12 | hs | atom_site | H | adp_iso | 0.50000 | -inf | inf | Ų | |
| 13 | hrpt | linked_phases | hs | scale | 0.39885 | 0.00233 | -inf | inf | |
| 14 | hrpt | peak | asym_empir_1 | 0.00000 | -inf | inf | |||
| 15 | hrpt | peak | asym_empir_2 | 0.00000 | -inf | inf | |||
| 16 | hrpt | peak | asym_empir_3 | 0.00000 | -inf | inf | |||
| 17 | hrpt | peak | asym_empir_4 | 0.00000 | -inf | inf | |||
| 18 | hrpt | peak | broad_gauss_u | 0.34262 | 0.01459 | -inf | inf | deg² | |
| 19 | hrpt | peak | broad_gauss_v | -0.37742 | 0.02800 | -inf | inf | deg² | |
| 20 | hrpt | peak | broad_gauss_w | 0.27616 | 0.01316 | -inf | inf | deg² | |
| 21 | hrpt | peak | broad_lorentz_y | 0.15157 | 0.00624 | -inf | inf | deg | |
| 22 | hrpt | instrument | twotheta_offset | 0.11821 | 0.00248 | -inf | inf | deg | |
| 23 | hrpt | background | 1 | y | 606.85492 | 15.89775 | -inf | inf | |
| 24 | hrpt | background | 2 | y | 506.39367 | 9.07212 | -inf | inf | |
| 25 | hrpt | background | 3 | y | 446.61148 | 6.94119 | -inf | inf | |
| 26 | hrpt | background | 4 | y | 433.46347 | 3.61166 | -inf | inf | |
| 27 | hrpt | background | 5 | y | 480.82660 | 3.86016 | -inf | inf | |
| 28 | hrpt | background | 6 | y | 504.13466 | 3.78801 | -inf | inf | |
| 29 | hrpt | background | 7 | y | 465.02545 | 3.66479 | -inf | inf | |
| 30 | hrpt | background | 8 | y | 446.84887 | 3.90918 | -inf | inf | |
| 31 | hrpt | background | 9 | y | 457.52127 | 3.89777 | -inf | inf |
Run Fitting¶
In [38]:
Copied!
project.analysis.fit()
project.analysis.fit()
Standard fitting
📋 Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit (reduced χ²) change:
| iteration | χ² | improvement [%] | |
|---|---|---|---|
| 1 | 1 | 5.49 | |
| 2 | 35 | 2.19 | 60.1% ↓ |
| 3 | 67 | 1.97 | 9.8% ↓ |
| 4 | 260 | 1.97 |
🏆 Best goodness-of-fit (reduced χ²) is 1.97 at iteration 259
✅ Fitting complete.
In [39]:
Copied!
project.analysis.display.fit_results()
project.analysis.display.fit_results()
Fit results
✅ Success: True
⏱️ Fitting time: 22.62 seconds
📏 Goodness-of-fit (reduced χ²): 1.97
📏 R-factor (Rf): 4.03%
📏 R-factor squared (Rf²): 4.68%
📏 Weighted R-factor (wR): 4.19%
📈 Fitted parameters:
| datablock | category | entry | parameter | start | fitted | uncertainty | units | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.8623 | 6.8643 | 0.0004 | Å | 0.03 % ↑ | |
| 2 | hs | cell | length_c | 14.1357 | 14.1424 | 0.0010 | Å | 0.05 % ↑ | |
| 3 | hs | atom_site | Zn | adp_iso | 0.5000 | 0.2297 | 0.0611 | Ų | 54.05 % ↓ |
| 4 | hs | atom_site | Cu | adp_iso | 0.5000 | 1.4700 | 0.0379 | Ų | 193.99 % ↑ |
| 5 | hs | atom_site | O | fract_x | 0.2059 | 0.2064 | 0.0002 | 0.24 % ↑ | |
| 6 | hs | atom_site | O | fract_z | 0.0627 | 0.0610 | 0.0001 | 2.76 % ↓ | |
| 7 | hs | atom_site | O | adp_iso | 0.5000 | 0.9782 | 0.0347 | Ų | 95.65 % ↑ |
| 8 | hs | atom_site | Cl | fract_z | 0.1979 | 0.1966 | 0.0001 | 0.63 % ↓ | |
| 9 | hs | atom_site | Cl | adp_iso | 0.5000 | 1.3926 | 0.0369 | Ų | 178.53 % ↑ |
| 10 | hs | atom_site | H | fract_x | 0.1336 | 0.1325 | 0.0001 | 0.79 % ↓ | |
| 11 | hs | atom_site | H | fract_z | 0.0870 | 0.0898 | 0.0001 | 3.27 % ↑ | |
| 12 | hs | atom_site | H | adp_iso | 0.5000 | 2.5006 | 0.0393 | Ų | 400.11 % ↑ |
| 13 | hrpt | linked_phases | hs | scale | 0.3988 | 0.5138 | 0.0025 | 28.83 % ↑ | |
| 14 | hrpt | peak | asym_empir_1 | 0.0000 | -0.2145 | 0.0248 | N/A | ||
| 15 | hrpt | peak | asym_empir_2 | 0.0000 | -0.0506 | 0.0040 | N/A | ||
| 16 | hrpt | peak | asym_empir_3 | 0.0000 | 0.1504 | 0.0553 | N/A | ||
| 17 | hrpt | peak | asym_empir_4 | 0.0000 | 0.0644 | 0.0089 | N/A | ||
| 18 | hrpt | peak | broad_gauss_u | 0.3426 | 0.2371 | 0.0095 | deg² | 30.81 % ↓ | |
| 19 | hrpt | peak | broad_gauss_v | -0.3774 | -0.3015 | 0.0172 | deg² | 20.11 % ↓ | |
| 20 | hrpt | peak | broad_gauss_w | 0.2762 | 0.2705 | 0.0078 | deg² | 2.04 % ↓ | |
| 21 | hrpt | peak | broad_lorentz_y | 0.1516 | 0.1616 | 0.0036 | deg | 6.61 % ↑ | |
| 22 | hrpt | instrument | twotheta_offset | 0.1182 | 0.1512 | 0.0071 | deg | 27.93 % ↑ | |
| 23 | hrpt | background | 1 | y | 606.8549 | 601.1574 | 9.5418 | 0.94 % ↓ | |
| 24 | hrpt | background | 2 | y | 506.3937 | 503.9188 | 5.4442 | 0.49 % ↓ | |
| 25 | hrpt | background | 3 | y | 446.6115 | 445.2163 | 4.1651 | 0.31 % ↓ | |
| 26 | hrpt | background | 4 | y | 433.4635 | 432.9735 | 2.1783 | 0.11 % ↓ | |
| 27 | hrpt | background | 5 | y | 480.8266 | 455.6484 | 2.3910 | 5.24 % ↓ | |
| 28 | hrpt | background | 6 | y | 504.1347 | 492.5767 | 2.3061 | 2.29 % ↓ | |
| 29 | hrpt | background | 7 | y | 465.0255 | 480.8476 | 2.2145 | 3.40 % ↑ | |
| 30 | hrpt | background | 8 | y | 446.8489 | 510.1369 | 2.4165 | 14.16 % ↑ | |
| 31 | hrpt | background | 9 | y | 457.5213 | 498.7801 | 2.5676 | 9.02 % ↑ |
In [40]:
Copied!
project.plotter.plot_param_correlations()
project.plotter.plot_param_correlations()
Plot Measured vs Calculated¶
In [41]:
Copied!
project.plotter.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
project.plotter.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
In [42]:
Copied!
project.plotter.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
project.plotter.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
Summary¶
This final section shows how to review the results of the analysis.
Show Project Summary¶
In [43]:
Copied!
project.summary.show_report()
project.summary.show_report()
———————————— PROJECT INFO ————————————
Title
Untitled Project
————————————————————— CRYSTALLOGRAPHIC DATA —————————————————————
Phase datablock
🧩 hs
Space group
R -3 m
| Parameter | Value | Uncertainty | |
|---|---|---|---|
| 1 | a | 6.86430591 | 0.00043941 |
| 2 | b | 6.86430591 | 0.00043941 |
| 3 | c | 6.86430591 | 0.00043941 |
| 4 | α | 90.00000000 | |
| 5 | β | 90.00000000 | |
| 6 | γ | 120.00000000 |
Atom sites
| label | type | x | y | z | occ | Biso | |
|---|---|---|---|---|---|---|---|
| 1 | Zn | Zn | 0.00000000 | 0.00000000 | 0.50000000 | 1.00000000 | 0.22974071 |
| 2 | Cu | Cu | 0.50000000 | 0.00000000 | 0.00000000 | 1.00000000 | 1.46995633 |
| 3 | O | O | 0.20636507 | -0.20636507 | 0.06098687 | 1.00000000 | 0.97823840 |
| 4 | Cl | Cl | 0.00000000 | 0.00000000 | 0.19664786 | 1.00000000 | 1.39263830 |
| 5 | H | 2H | 0.13251047 | -0.13251047 | 0.08981735 | 1.00000000 | 2.50055965 |
——————————— EXPERIMENTS ———————————
Experiment datablock
🔬 hrpt
Experiment type
powder, neutron, constant wavelength bragg
Calculation engine
cryspy
Wavelength
1.89000
2θ offset
0.15122
Profile type
pseudo-voigt + empirical asymmetry
Peak broadening (Gaussian)
| Parameter | Value | Uncertainty | |
|---|---|---|---|
| 1 | U | 0.23707057 | 0.00945812 |
| 2 | V | -0.30153917 | 0.01721957 |
| 3 | W | 0.27051354 | 0.00780096 |
Peak broadening (Lorentzian)
| Parameter | Value | Uncertainty | |
|---|---|---|---|
| 1 | X | 0.00000000 | |
| 2 | Y | 0.16158673 | 0.00356715 |
Asymmetry (Empirical)
| Parameter | Value | Uncertainty | |
|---|---|---|---|
| 1 | p1 | -0.21445483 | 0.02477167 |
| 2 | p2 | -0.05057848 | 0.00400889 |
| 3 | p3 | 0.15041528 | 0.05532097 |
| 4 | p4 | 0.06443360 | 0.00890042 |
——————— FITTING ———————
Minimization engine
lmfit (leastsq)
Fit quality
| metric | value | |
|---|---|---|
| 1 | Goodness-of-fit (reduced χ²) | 1.97 |