Fitting pd-neut-cwl LBCO-HRPT¶
This example shows how to refine the crystal structure parameters of La0.5Ba0.5CoO3 from neutron diffraction data in a constant wavelength experiment performed on HRPT diffractometer at PSI.
Import EasyDiffraction¶
import easydiffraction as ed
Create a job¶
Create a job — the main object to store all the information
job = ed.Job()
print(job.type)
Job type: pd-cwl-unp-1d-neut
Define a model¶
Download the CIF file from the EasyDiffraction repository on GitHub
ed.download_from_repository('lbco.cif', destination='data')
Load a phase from the downloaded CIF file
job.add_phase_from_file('data/lbco.cif')
print(job.phases)
Collection of 1 phases: ['lbco']
Show phase info in CIF format
print(job.phases['lbco'].cif)
data_lbco _cell_length_a 3.88 _cell_length_b 3.88 _cell_length_c 3.88 _cell_angle_alpha 90.00000000 _cell_angle_beta 90.00000000 _cell_angle_gamma 90.00000000 _space_group_name_H-M_ref 'P m -3 m' loop_ _atom_site_label _atom_site_type_symbol _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy _atom_site_adp_type _atom_site_B_iso_or_equiv La La 0.00000000 0.00000000 0.00000000 0.5 Biso 0.1 Ba Ba 0.00000000 0.00000000 0.00000000 0.5 Biso 0.1 Co Co 0.5 0.5 0.5 1.00000000 Biso 0.1 O O 0.00000000 0.5 0.5 1.00000000 Biso 0.1
Display the crystal structure of a given model
job.show_crystal_structure(id='lbco')
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
Define an experiment¶
Download the data file from the EasyDiffraction repository on GitHub
ed.download_from_repository('hrpt.xye', destination='data')
Show content of the downloaded file (first 6 lines)
with open('data/hrpt.xye') as f:
print(''.join(f.readlines()[:6]))
# 2theta intensity su 10.00 167.00 12.60 10.05 157.00 12.50 10.10 187.00 13.30 10.15 197.00 14.00 10.20 164.00 12.50
Load experimentally measured data from a file in XYE format
job.add_experiment_from_file('data/hrpt.xye')
Display the experimentally measured data
job.show_experiment_chart()
Define a point background
job.set_background([(10.0, 170),
(165.0, 170)])
Display the experiment chart after setting the background
job.show_experiment_chart()
Perform an analysis¶
Display the analysis chart before setting initial parameter values
job.show_analysis_chart()
Show all parameters before refinement
job.show_parameters()
name | value | error | min | max | vary | ||
---|---|---|---|---|---|---|---|
1 | .phases['lbco'].cell.length_a | 3.88000 | Å | 0.0 | inf | ||
2 | .phases['lbco'].atom_sites['La'].occupancy | 0.50000 | -inf | inf | |||
3 | .phases['lbco'].atom_sites['La'].fract_x | 0.00000 | -inf | inf | |||
4 | .phases['lbco'].atom_sites['La'].fract_y | 0.00000 | -inf | inf | |||
5 | .phases['lbco'].atom_sites['La'].fract_z | 0.00000 | -inf | inf | |||
6 | .phases['lbco'].atom_sites['La'].b_iso_or_equiv | 0.10000 | Ų | 0.0 | inf | ||
7 | .phases['lbco'].atom_sites['Ba'].occupancy | 0.50000 | -inf | inf | |||
8 | .phases['lbco'].atom_sites['Ba'].fract_x | 0.00000 | -inf | inf | |||
9 | .phases['lbco'].atom_sites['Ba'].fract_y | 0.00000 | -inf | inf | |||
10 | .phases['lbco'].atom_sites['Ba'].fract_z | 0.00000 | -inf | inf | |||
11 | .phases['lbco'].atom_sites['Ba'].b_iso_or_equiv | 0.10000 | Ų | 0.0 | inf | ||
12 | .phases['lbco'].atom_sites['Co'].occupancy | 1.00000 | -inf | inf | |||
13 | .phases['lbco'].atom_sites['Co'].fract_x | 0.50000 | -inf | inf | |||
14 | .phases['lbco'].atom_sites['Co'].fract_y | 0.50000 | -inf | inf | |||
15 | .phases['lbco'].atom_sites['Co'].fract_z | 0.50000 | -inf | inf | |||
16 | .phases['lbco'].atom_sites['Co'].b_iso_or_equiv | 0.10000 | Ų | 0.0 | inf | ||
17 | .phases['lbco'].atom_sites['O'].occupancy | 1.00000 | -inf | inf | |||
18 | .phases['lbco'].atom_sites['O'].fract_x | 0.00000 | -inf | inf | |||
19 | .phases['lbco'].atom_sites['O'].fract_y | 0.50000 | -inf | inf | |||
20 | .phases['lbco'].atom_sites['O'].fract_z | 0.50000 | -inf | inf | |||
21 | .phases['lbco'].atom_sites['O'].b_iso_or_equiv | 0.10000 | Ų | 0.0 | inf | ||
22 | .phases['lbco'].scale | 1.00000 | 0.0 | inf | True | ||
23 | .instrument.wavelength | 1.54056 | Å | -inf | inf | ||
24 | .instrument.resolution_u | 0.00020 | -inf | inf | |||
25 | .instrument.resolution_v | -0.00020 | -inf | inf | |||
26 | .instrument.resolution_w | 0.01200 | -inf | inf | |||
27 | .instrument.resolution_x | 0.00000 | -inf | inf | |||
28 | .instrument.resolution_y | 0.00000 | -inf | inf | |||
29 | .instrument.reflex_asymmetry_p1 | 0.00000 | -inf | inf | |||
30 | .instrument.reflex_asymmetry_p2 | 0.00000 | -inf | inf | |||
31 | .instrument.reflex_asymmetry_p3 | 0.00000 | -inf | inf | |||
32 | .instrument.reflex_asymmetry_p4 | 0.00000 | -inf | inf | |||
33 | .pattern.zero_shift | 0.00000 | deg | -inf | inf | ||
34 | .pattern.backgrounds[0]['10,0_deg'].intensity | 170.00000 | -inf | inf | |||
35 | .pattern.backgrounds[0]['165,0_deg'].intensity | 170.00000 | -inf | inf |
Change the default value of the wavelength used in the experiment and display the analysis chart again
job.instrument.wavelength = 1.494
job.show_analysis_chart()
Change the scale and display the analysis chart again
job.phases['lbco'].scale = 3
job.show_analysis_chart()
Change the default values of the peak profile related parameters and display the analysis chart again
job.instrument.resolution_u = 0.1
job.instrument.resolution_v = -0.1
job.instrument.resolution_w = 0.2
job.instrument.resolution_x = 0
job.instrument.resolution_y = 0
job.show_analysis_chart()
Select parameters to be refined in the 1st round
job.phases['lbco'].scale.free = True
job.phases['lbco'].cell.length_a.free = True
job.pattern.zero_shift.free = True
job.pattern.backgrounds[0][0].y.free = True
job.pattern.backgrounds[0][1].y.free = True
Print parameters to be refined (free parameters) before fitting
job.show_free_parameters()
name | value | error | ||
---|---|---|---|---|
1 | .phases['lbco'].cell.length_a | 3.88 | Å | 0.0 |
2 | .phases['lbco'].scale | 3.00 | 0.0 | |
3 | .pattern.backgrounds[0]['10,0_deg'].intensity | 170.00 | 0.0 | |
4 | .pattern.backgrounds[0]['165,0_deg'].intensity | 170.00 | 0.0 |
Start Least-Squares minimization to refine the selected parameters
job.fit()
Fitting result Status: 🥳 Success Duration: ⌛ 1.69 s Reduced χ²: 👍 5.45
Print the refined parameters after fitting
job.show_free_parameters()
name | value | error | ||
---|---|---|---|---|
1 | .phases['lbco'].cell.length_a | 3.890872 | Å | 0.000076 |
2 | .phases['lbco'].scale | 5.275057 | 0.035223 | |
3 | .pattern.zero_shift | 0.620519 | deg | 0.002732 |
4 | .pattern.backgrounds[0]['10,0_deg'].intensity | 171.084712 | 1.115637 | |
5 | .pattern.backgrounds[0]['165,0_deg'].intensity | 182.964912 | 1.168906 |
Display the analysis chart after the 1st fitting
job.show_analysis_chart()
Select more parameters to be refined in the 2nd round
job.instrument.resolution_u.free = True
job.instrument.resolution_v.free = True
job.instrument.resolution_w.free = True
job.instrument.resolution_y.free = True
Print free parameters before the 2nd fitting
job.show_free_parameters()
name | value | error | ||
---|---|---|---|---|
1 | .phases['lbco'].cell.length_a | 3.890872 | Å | 0.000076 |
2 | .phases['lbco'].scale | 5.275057 | 0.035223 | |
3 | .instrument.resolution_u | 0.100000 | 0.000000 | |
4 | .instrument.resolution_v | -0.100000 | 0.000000 | |
5 | .instrument.resolution_w | 0.200000 | 0.000000 | |
6 | .instrument.resolution_y | 0.000000 | 0.000000 | |
7 | .pattern.zero_shift | 0.620519 | deg | 0.002732 |
8 | .pattern.backgrounds[0]['10,0_deg'].intensity | 171.084712 | 1.115637 | |
9 | .pattern.backgrounds[0]['165,0_deg'].intensity | 182.964912 | 1.168906 |
Start 2nd round of minimization
job.fit()
Fitting result Status: 🥳 Success Duration: ⌛ 1.97 s Reduced χ²: 👍 4.14
Print free parameters after the 2nd fitting
job.show_free_parameters()
name | value | error | ||
---|---|---|---|---|
1 | .phases['lbco'].cell.length_a | 3.890895 | Å | 0.000067 |
2 | .phases['lbco'].scale | 5.923453 | 0.041978 | |
3 | .instrument.resolution_u | 0.081104 | 0.005878 | |
4 | .instrument.resolution_v | -0.100658 | 0.013213 | |
5 | .instrument.resolution_w | 0.099670 | 0.006739 | |
6 | .instrument.resolution_y | 0.095296 | 0.004040 | |
7 | .pattern.zero_shift | 0.622543 | deg | 0.002240 |
8 | .pattern.backgrounds[0]['10,0_deg'].intensity | 168.345270 | 0.990891 | |
9 | .pattern.backgrounds[0]['165,0_deg'].intensity | 175.687739 | 1.068832 |
Display the analysis chart after the 2nd fitting
job.show_analysis_chart()
Select atomic displacement parameters (ADPs) to be refined in the 3rd round
job.phases['lbco'].atom_sites['La'].b_iso_or_equiv.free = True
job.phases['lbco'].atom_sites['Ba'].b_iso_or_equiv.free = True
job.phases['lbco'].atom_sites['Co'].b_iso_or_equiv.free = True
job.phases['lbco'].atom_sites['O'].b_iso_or_equiv.free = True
Print free parameters before the 3rd fitting
job.show_free_parameters()
name | value | error | ||
---|---|---|---|---|
1 | .phases['lbco'].cell.length_a | 3.890895 | Å | 0.000067 |
2 | .phases['lbco'].atom_sites['La'].b_iso_or_equiv | 0.100000 | Ų | 0.000000 |
3 | .phases['lbco'].atom_sites['Ba'].b_iso_or_equiv | 0.100000 | Ų | 0.000000 |
4 | .phases['lbco'].atom_sites['Co'].b_iso_or_equiv | 0.100000 | Ų | 0.000000 |
5 | .phases['lbco'].atom_sites['O'].b_iso_or_equiv | 0.100000 | Ų | 0.000000 |
6 | .phases['lbco'].scale | 5.923453 | 0.041978 | |
7 | .instrument.resolution_u | 0.081104 | 0.005878 | |
8 | .instrument.resolution_v | -0.100658 | 0.013213 | |
9 | .instrument.resolution_w | 0.099670 | 0.006739 | |
10 | .instrument.resolution_y | 0.095296 | 0.004040 | |
11 | .pattern.zero_shift | 0.622543 | deg | 0.002240 |
12 | .pattern.backgrounds[0]['10,0_deg'].intensity | 168.345270 | 0.990891 | |
13 | .pattern.backgrounds[0]['165,0_deg'].intensity | 175.687739 | 1.068832 |
Start 3rd round of minimization
job.fit()
Fitting result Status: 🥳 Success Duration: ⌛ 4.18 s Reduced χ²: 👍 1.25
Print free parameters after the 3rd fitting
job.show_free_parameters()
name | value | error | ||
---|---|---|---|---|
1 | .phases['lbco'].cell.length_a | 3.890879 | Å | 0.000039 |
2 | .phases['lbco'].atom_sites['La'].b_iso_or_equiv | 0.498536 | Ų | 134.085337 |
3 | .phases['lbco'].atom_sites['Ba'].b_iso_or_equiv | 0.498478 | Ų | 217.821188 |
4 | .phases['lbco'].atom_sites['Co'].b_iso_or_equiv | 0.248419 | Ų | 0.061584 |
5 | .phases['lbco'].atom_sites['O'].b_iso_or_equiv | 1.384822 | Ų | 0.016852 |
6 | .phases['lbco'].scale | 9.114855 | 0.064300 | |
7 | .instrument.resolution_u | 0.080997 | 0.003182 | |
8 | .instrument.resolution_v | -0.113611 | 0.006805 | |
9 | .instrument.resolution_w | 0.119284 | 0.003303 | |
10 | .instrument.resolution_y | 0.084484 | 0.002146 | |
11 | .pattern.zero_shift | 0.622739 | deg | 0.001054 |
12 | .pattern.backgrounds[0]['10,0_deg'].intensity | 165.323254 | 0.556002 | |
13 | .pattern.backgrounds[0]['165,0_deg'].intensity | 176.987816 | 0.606535 |
Display the analysis chart after the 3rd fitting
job.show_analysis_chart()
Show all parameters after refinement
job.show_parameters()
name | value | error | min | max | vary | ||
---|---|---|---|---|---|---|---|
1 | .phases['lbco'].cell.length_a | 3.890879 | Å | 0.000039 | 0.0 | inf | True |
2 | .phases['lbco'].atom_sites['La'].occupancy | 0.500000 | -inf | inf | |||
3 | .phases['lbco'].atom_sites['La'].fract_x | 0.000000 | -inf | inf | |||
4 | .phases['lbco'].atom_sites['La'].fract_y | 0.000000 | -inf | inf | |||
5 | .phases['lbco'].atom_sites['La'].fract_z | 0.000000 | -inf | inf | |||
6 | .phases['lbco'].atom_sites['La'].b_iso_or_equiv | 0.498536 | Ų | 134.085337 | 0.0 | inf | True |
7 | .phases['lbco'].atom_sites['Ba'].occupancy | 0.500000 | -inf | inf | |||
8 | .phases['lbco'].atom_sites['Ba'].fract_x | 0.000000 | -inf | inf | |||
9 | .phases['lbco'].atom_sites['Ba'].fract_y | 0.000000 | -inf | inf | |||
10 | .phases['lbco'].atom_sites['Ba'].fract_z | 0.000000 | -inf | inf | |||
11 | .phases['lbco'].atom_sites['Ba'].b_iso_or_equiv | 0.498478 | Ų | 217.821188 | 0.0 | inf | True |
12 | .phases['lbco'].atom_sites['Co'].occupancy | 1.000000 | -inf | inf | |||
13 | .phases['lbco'].atom_sites['Co'].fract_x | 0.500000 | -inf | inf | |||
14 | .phases['lbco'].atom_sites['Co'].fract_y | 0.500000 | -inf | inf | |||
15 | .phases['lbco'].atom_sites['Co'].fract_z | 0.500000 | -inf | inf | |||
16 | .phases['lbco'].atom_sites['Co'].b_iso_or_equiv | 0.248419 | Ų | 0.061584 | 0.0 | inf | True |
17 | .phases['lbco'].atom_sites['O'].occupancy | 1.000000 | -inf | inf | |||
18 | .phases['lbco'].atom_sites['O'].fract_x | 0.000000 | -inf | inf | |||
19 | .phases['lbco'].atom_sites['O'].fract_y | 0.500000 | -inf | inf | |||
20 | .phases['lbco'].atom_sites['O'].fract_z | 0.500000 | -inf | inf | |||
21 | .phases['lbco'].atom_sites['O'].b_iso_or_equiv | 1.384822 | Ų | 0.016852 | 0.0 | inf | True |
22 | .phases['lbco'].scale | 9.114855 | 0.0643 | 0.0 | inf | True | |
23 | .instrument.wavelength | 1.494000 | Å | -inf | inf | ||
24 | .instrument.resolution_u | 0.080997 | 0.003182 | -inf | inf | True | |
25 | .instrument.resolution_v | -0.113611 | 0.006805 | -inf | inf | True | |
26 | .instrument.resolution_w | 0.119284 | 0.003303 | -inf | inf | True | |
27 | .instrument.resolution_x | 0.000000 | -inf | inf | |||
28 | .instrument.resolution_y | 0.084484 | 0.002146 | -inf | inf | True | |
29 | .instrument.reflex_asymmetry_p1 | 0.000000 | -inf | inf | |||
30 | .instrument.reflex_asymmetry_p2 | 0.000000 | -inf | inf | |||
31 | .instrument.reflex_asymmetry_p3 | 0.000000 | -inf | inf | |||
32 | .instrument.reflex_asymmetry_p4 | 0.000000 | -inf | inf | |||
33 | .pattern.zero_shift | 0.622739 | deg | 0.001054 | -inf | inf | True |
34 | .pattern.backgrounds[0]['10,0_deg'].intensity | 165.323254 | 0.556002 | -inf | inf | True | |
35 | .pattern.backgrounds[0]['165,0_deg'].intensity | 176.987816 | 0.606535 | -inf | inf | True |