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,
adp_iso=0.5,
)
structure.atom_sites.create(
label='Cu',
type_symbol='Cu',
fract_x=0.5,
fract_y=0,
fract_z=0,
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,
adp_iso=0.5,
)
structure.atom_sites.create(
label='Cl',
type_symbol='Cl',
fract_x=0,
fract_y=0,
fract_z=0.197,
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,
adp_iso=0.5,
)
structure.atom_sites.create(
label='Zn',
type_symbol='Zn',
fract_x=0,
fract_y=0,
fract_z=0.5,
adp_iso=0.5,
)
structure.atom_sites.create(
label='Cu',
type_symbol='Cu',
fract_x=0.5,
fract_y=0,
fract_z=0,
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,
adp_iso=0.5,
)
structure.atom_sites.create(
label='Cl',
type_symbol='Cl',
fract_x=0,
fract_y=0,
fract_z=0.197,
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,
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.peak.show_supported()
expt.peak.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.peak.show_supported()
expt.peak.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
Peak types
| Type | Description | ||
|---|---|---|---|
| 1 | * | pseudo-voigt | CWL pseudo-Voigt profile |
| 2 | pseudo-voigt + empirical asymmetry | CWL pseudo-Voigt profile with empirical asymmetry correction. |
⚠️ Switching peak profile type adds these settings with defaults: • asym_empir_1=0.0 • asym_empir_2=0.0 • asym_empir_3=0.0 • asym_empir_4=0.0
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(name='hs_hrpt')
project = Project(name='hs_hrpt')
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.display.structure(struct_name='hs')
project.display.structure(struct_name='hs')
Structure 🧩 'hs' (Atom view type: 'covalent')
Loading plot…
drag = rotate
wheel = zoom
right-drag = pan
wheel = zoom
right-drag = pan
Display Pattern¶
In [17]:
Copied!
project.display.pattern(expt_name='hrpt')
project.display.pattern(expt_name='hrpt')
Loading plot…
In [18]:
Copied!
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
Loading plot…
Perform Fit 1/4¶
Set parameters to be refined.
In [19]:
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 [20]:
Copied!
project.display.parameters.free()
project.display.parameters.free()
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 [21]:
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.11 | 576.50 | |
| 2 | 8 | 0.84 | 122.02 | 78.8% ↓ |
| 3 | 13 | 1.35 | 115.19 | 5.6% ↓ |
| 4 | 18 | 2.11 | 109.86 | 4.6% ↓ |
| 5 | 23 | 2.64 | 106.68 | 2.9% ↓ |
| 6 | 28 | 3.15 | 104.60 | 2.0% ↓ |
| 7 | 33 | 3.67 | 102.87 | 1.7% ↓ |
| 8 | 38 | 4.46 | 101.13 | 1.7% ↓ |
| 9 | 43 | 4.99 | 99.20 | 1.9% ↓ |
| 10 | 48 | 5.51 | 96.86 | 2.4% ↓ |
| 11 | 53 | 6.03 | 93.93 | 3.0% ↓ |
| 12 | 58 | 6.54 | 90.34 | 3.8% ↓ |
| 13 | 63 | 7.32 | 86.20 | 4.6% ↓ |
| 14 | 68 | 7.83 | 81.66 | 5.3% ↓ |
| 15 | 73 | 8.34 | 76.78 | 6.0% ↓ |
| 16 | 78 | 8.85 | 71.71 | 6.6% ↓ |
| 17 | 83 | 9.61 | 66.82 | 6.8% ↓ |
| 18 | 88 | 10.12 | 62.48 | 6.5% ↓ |
| 19 | 93 | 10.66 | 58.99 | 5.6% ↓ |
| 20 | 98 | 11.19 | 56.41 | 4.4% ↓ |
| 21 | 103 | 11.71 | 54.64 | 3.1% ↓ |
| 22 | 108 | 12.52 | 53.49 | 2.1% ↓ |
| 23 | 113 | 13.04 | 52.76 | 1.4% ↓ |
| 24 | 123 | 14.08 | 52.02 | 1.4% ↓ |
| 25 | 167 | 19.18 | 51.59 | |
| 26 | 210 | 24.24 | 51.58 | |
| 27 | 254 | 29.34 | 51.58 | |
| 28 | 297 | 34.43 | 51.57 | |
| 29 | 304 | 35.18 | 51.57 |
🏆 Best goodness-of-fit (reduced χ²) is 51.57 at iteration 303
✅ Fitting complete.
In [22]:
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) | 35.18 |
| 4 | 🔁 Iterations | 301 |
| 5 | 📏 Goodness-of-fit (reduced χ²) | 51.57 |
| 6 | 📏 R-factor (Rf, %) | 19.70 |
| 7 | 📏 R-factor squared (Rf², %) | 30.20 |
| 8 | 📏 Weighted R-factor (wR, %) | 30.35 |
📈 Refined parameters:
| datablock | category | entry | parameter | units | start | value | s.u. | 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 | deg | 0.0000 | 0.1271 | 0.0051 | N/A |
• 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
Display Pattern¶
In [23]:
Copied!
project.display.pattern(expt_name='hrpt')
project.display.pattern(expt_name='hrpt')
Loading plot…
In [24]:
Copied!
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
Loading plot…
Perform Fit 2/4¶
Set more parameters to be refined.
In [25]:
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 [26]:
Copied!
project.display.parameters.free()
project.display.parameters.free()
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 [27]:
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.15 | 51.78 | |
| 2 | 21 | 2.85 | 15.91 | 69.3% ↓ |
| 3 | 39 | 5.28 | 15.07 | 5.3% ↓ |
| 4 | 57 | 7.68 | 14.17 | 6.0% ↓ |
| 5 | 75 | 10.12 | 13.42 | 5.3% ↓ |
| 6 | 115 | 15.20 | 13.39 | |
| 7 | 152 | 20.26 | 13.39 | |
| 8 | 191 | 25.43 | 13.39 | |
| 9 | 220 | 29.20 | 13.39 |
🏆 Best goodness-of-fit (reduced χ²) is 13.39 at iteration 219
✅ Fitting complete.
In [28]:
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) | 29.20 |
| 4 | 🔁 Iterations | 217 |
| 5 | 📏 Goodness-of-fit (reduced χ²) | 13.39 |
| 6 | 📏 R-factor (Rf, %) | 10.13 |
| 7 | 📏 R-factor squared (Rf², %) | 14.05 |
| 8 | 📏 Weighted R-factor (wR, %) | 13.91 |
📈 Refined parameters:
| datablock | category | entry | parameter | units | start | value | s.u. | 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 | deg² | 0.1000 | 0.3338 | 0.0270 | 233.82 % ↑ | |
| 5 | hrpt | peak | broad_gauss_v | deg² | -0.2000 | -0.2705 | 0.0498 | 35.27 % ↑ | |
| 6 | hrpt | peak | broad_gauss_w | deg² | 0.2000 | 0.2067 | 0.0214 | 3.37 % ↑ | |
| 7 | hrpt | peak | broad_lorentz_y | deg | 0.0000 | 0.1859 | 0.0103 | N/A | |
| 8 | hrpt | instrument | twotheta_offset | deg | 0.1271 | 0.1316 | 0.0040 | 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 % ↑ |
• 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
Display Pattern¶
In [29]:
Copied!
project.display.pattern(expt_name='hrpt')
project.display.pattern(expt_name='hrpt')
Loading plot…
In [30]:
Copied!
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
Loading plot…
Perform Fit 3/4¶
Set more parameters to be refined.
In [31]:
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 [32]:
Copied!
project.display.parameters.free()
project.display.parameters.free()
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 [33]:
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.14 | 13.41 | |
| 2 | 26 | 3.33 | 5.76 | 57.1% ↓ |
| 3 | 49 | 6.30 | 5.48 | 4.7% ↓ |
| 4 | 88 | 11.35 | 5.47 | |
| 5 | 130 | 16.70 | 5.47 | |
| 6 | 172 | 21.81 | 5.47 | |
| 7 | 211 | 26.96 | 5.47 |
🏆 Best goodness-of-fit (reduced χ²) is 5.47 at iteration 210
✅ Fitting complete.
In [34]:
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) | 26.96 |
| 4 | 🔁 Iterations | 208 |
| 5 | 📏 Goodness-of-fit (reduced χ²) | 5.47 |
| 6 | 📏 R-factor (Rf, %) | 6.71 |
| 7 | 📏 R-factor squared (Rf², %) | 9.26 |
| 8 | 📏 Weighted R-factor (wR, %) | 9.33 |
📈 Refined parameters:
| datablock | category | entry | parameter | units | start | value | s.u. | 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 | deg² | 0.3338 | 0.3426 | 0.0146 | 2.64 % ↑ | |
| 10 | hrpt | peak | broad_gauss_v | deg² | -0.2705 | -0.3774 | 0.0280 | 39.51 % ↑ | |
| 11 | hrpt | peak | broad_gauss_w | deg² | 0.2067 | 0.2762 | 0.0132 | 33.57 % ↑ | |
| 12 | hrpt | peak | broad_lorentz_y | deg | 0.1859 | 0.1516 | 0.0062 | 18.46 % ↓ | |
| 13 | hrpt | instrument | twotheta_offset | deg | 0.1316 | 0.1182 | 0.0025 | 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 % ↓ |
• 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
Display Pattern¶
In [35]:
Copied!
project.display.pattern(expt_name='hrpt')
project.display.pattern(expt_name='hrpt')
Loading plot…
In [36]:
Copied!
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
Loading plot…
Perform Fit 4/4¶
Set more parameters to be refined.
In [37]:
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 [38]:
Copied!
project.display.parameters.free()
project.display.parameters.free()
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 [39]:
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.14 | 5.49 | |
| 2 | 35 | 4.63 | 2.19 | 60.1% ↓ |
| 3 | 67 | 8.64 | 1.97 | 9.8% ↓ |
| 4 | 106 | 13.73 | 1.97 | |
| 5 | 145 | 18.84 | 1.97 | |
| 6 | 186 | 23.92 | 1.97 | |
| 7 | 224 | 28.92 | 1.97 | |
| 8 | 260 | 34.03 | 1.97 |
🏆 Best goodness-of-fit (reduced χ²) is 1.97 at iteration 259
✅ Fitting complete.
In [40]:
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) | 34.03 |
| 4 | 🔁 Iterations | 257 |
| 5 | 📏 Goodness-of-fit (reduced χ²) | 1.97 |
| 6 | 📏 R-factor (Rf, %) | 4.03 |
| 7 | 📏 R-factor squared (Rf², %) | 4.68 |
| 8 | 📏 Weighted R-factor (wR, %) | 4.19 |
📈 Refined parameters:
| datablock | category | entry | parameter | units | start | value | s.u. | 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 | deg² | 0.3426 | 0.2371 | 0.0095 | 30.81 % ↓ | |
| 19 | hrpt | peak | broad_gauss_v | deg² | -0.3774 | -0.3015 | 0.0172 | 20.11 % ↓ | |
| 20 | hrpt | peak | broad_gauss_w | deg² | 0.2762 | 0.2705 | 0.0078 | 2.04 % ↓ | |
| 21 | hrpt | peak | broad_lorentz_y | deg | 0.1516 | 0.1616 | 0.0036 | 6.61 % ↑ | |
| 22 | hrpt | instrument | twotheta_offset | deg | 0.1182 | 0.1512 | 0.0071 | 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 % ↑ |
• 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 [41]:
Copied!
project.display.fit.correlations()
project.display.fit.correlations()
Loading plot…
Display Pattern¶
In [42]:
Copied!
project.display.pattern(expt_name='hrpt')
project.display.pattern(expt_name='hrpt')
Loading plot…
In [43]:
Copied!
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
Loading plot…
📊 Report¶
The HTML report is written automatically when the project is saved;
enable project.report.pdf as well for a PDF version.
💾 Save Project¶
In [44]:
Copied!
project.save_as(dir_path='projects/ed_6_hs_hrpt')
project.save_as(dir_path='projects/ed_6_hs_hrpt')
Saving project 📦 'hs_hrpt' to '../../../projects/ed_6_hs_hrpt'
├── 📄 project.cif
├── 📁 structures/
│ └── 📄 hs.cif
├── 📁 experiments/
│ └── 📄 hrpt.cif
├── 📁 analysis/
│ └── 📄 analysis.cif
└── 📁 reports/
└── 📄 hs_hrpt.html