Fitting pd-neut-tof NCAF-WISH¶
This example shows how to refine the crystal structure parameters of Si from neutron diffraction data in a time-of-flight experiment performed on WISH diffractometer at ISIS.
Import EasyDiffraction¶
import easydiffraction as ed
Create a job¶
Create a job — the main object to store all the information
job = ed.Job(type='tof')
print(job.type)
Job type: pd-tof-unp-1d-neut
Define a model¶
Download the CIF file from the EasyDiffraction repository on GitHub
ed.download_from_repository('ncaf.cif', destination='data')
Load a phase from the downloaded CIF file
job.add_phase_from_file('data/ncaf.cif')
print(job.phases)
Collection of 1 phases: ['ncaf']
Show phase info in CIF format
phase = job.phases['ncaf']
print(phase.cif)
data_ncaf _cell_length_a 10.250256 _cell_length_b 10.250256 _cell_length_c 10.250256 _cell_angle_alpha 90.00000000 _cell_angle_beta 90.00000000 _cell_angle_gamma 90.00000000 _space_group_name_H-M_ref 'I 21 3' 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 Ca Ca 0.4661 0.00000000 0.25 1.00000000 Biso 0.9 Al Al 0.25171 0.25171 0.25171 1.00000000 Biso 0.66 Na Na 0.08481 0.08481 0.08481 1.00000000 Biso 1.9 F1 F 0.1375 0.3053 0.1195 1.00000000 Biso 0.9 F2 F 0.3626 0.3634 0.1867 1.00000000 Biso 1.28 F3 F 0.4612 0.4612 0.4612 1.00000000 Biso 0.79
Display the crystal structure of a given model
job.show_crystal_structure(id='ncaf')
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('wish.xye', destination='data')
Show content of the downloaded file (first 5 lines)
with open('data/wish.xye') as f:
print(''.join(f.readlines()[:5]))
9001.0830 616.5238 124.5646 9006.8848 578.7690 123.1410 9012.6904 574.1842 120.5078 9018.5000 507.7390 111.3004 9024.3125 404.6729 101.6163
Load experimentally measured data from downloaded file in XYE format
job.add_experiment_from_file('data/wish.xye')
Display the experimentally measured data
job.show_experiment_chart()
Define a point background
background_points = [
( 9162, 465),
( 11136, 593),
( 13313, 497),
( 14906, 546),
( 16454, 533),
( 17352, 496),
( 18743, 428),
( 20179, 452),
( 21368, 397),
( 22176, 468),
( 22827, 477),
( 24644, 380),
( 26439, 381),
( 28257, 378),
( 31196, 343),
( 34034, 328),
( 37265, 310),
( 41214, 323),
( 44827, 283),
( 49830, 273),
( 52905, 257),
( 58204, 260),
( 62916, 261),
( 70186, 262),
( 74204, 262),
( 82103, 268),
( 91958, 268),
(102712, 262)
]
job.set_background(background_points)
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()
Create aliases for the two types of experimental parameters
pattern= job.pattern
instrument = job.instrument
Change the default value of some instrumental parameters and display the analysis chart again
instrument.dtt1 = 20770
instrument.dtt2 = -1.08308
instrument.ttheta_bank = 152.827
job.show_analysis_chart()
Change the scale and display the analysis chart again
phase.scale = 0.5
job.show_analysis_chart()
Change the default values of the peak profile related parameters and display the analysis chart again
instrument.alpha0 = 0
instrument.alpha1 = 0.1
instrument.beta0 = 0.01
instrument.beta1 = 0.01
instrument.sigma0 = 0
instrument.sigma1 = 0
instrument.sigma2 = 5
job.show_analysis_chart()
Select parameters to be refined in the first round
phase.scale.free = True
pattern.zero_shift.free = True
Print parameters to be refined (free parameters) before fitting
job.show_free_parameters()
name | value | error | ||
---|---|---|---|---|
1 | .phases['ncaf'].scale | 0.5 | 0.0 |
Start Least-Squares minimization to refine the selected parameters
job.fit()
Fitting result Status: 🥳 Success Duration: ⌛ 14.03 s Reduced χ²: 👍 19.03
Print the refined parameters after fitting
job.show_free_parameters()
name | value | error | ||
---|---|---|---|---|
1 | .phases['ncaf'].scale | 0.983169 | 0.005159 | |
2 | .pattern.zero_shift | -3.376425 | µs | 0.085604 |
Display the analysis chart after the first fitting
job.show_analysis_chart()
Select more parameters to be refined in the second round
instrument.alpha1.free = True
instrument.beta0.free = True
instrument.beta1.free = True
instrument.sigma2.free = True
Print free parameters before the second fitting
job.show_free_parameters()
name | value | error | ||
---|---|---|---|---|
1 | .phases['ncaf'].scale | 0.983169 | 0.005159 | |
2 | .instrument.sigma2 | 5.000000 | µs²/Å⁴ | 0.000000 |
3 | .instrument.alpha1 | 0.100000 | 0.000000 | |
4 | .instrument.beta0 | 0.010000 | 0.000000 | |
5 | .instrument.beta1 | 0.010000 | 0.000000 | |
6 | .pattern.zero_shift | -3.376425 | µs | 0.085604 |
Start the second round of minimization
job.fit()
Fitting result Status: 🥳 Success Duration: ⌛ 35.04 s Reduced χ²: 👍 6.87
Print free parameters after the third fitting
job.show_free_parameters()
name | value | error | ||
---|---|---|---|---|
1 | .phases['ncaf'].scale | 1.085347 | 0.003434 | |
2 | .instrument.sigma2 | 13.778083 | µs²/Å⁴ | 0.764276 |
3 | .instrument.alpha1 | 0.083958 | 0.001075 | |
4 | .instrument.beta0 | 0.006515 | 0.000041 | |
5 | .instrument.beta1 | 0.012430 | 0.000216 | |
6 | .pattern.zero_shift | -3.440901 | µs | 0.076697 |
Display the analysis chart after the third fitting
job.show_analysis_chart()
Show all parameters after refinement
job.show_parameters()
name | value | error | min | max | vary | ||
---|---|---|---|---|---|---|---|
1 | .phases['ncaf'].cell.length_a | 10.250256 | Å | 0.0 | inf | ||
2 | .phases['ncaf'].atom_sites['Ca'].occupancy | 1.000000 | -inf | inf | |||
3 | .phases['ncaf'].atom_sites['Ca'].fract_x | 0.466100 | -inf | inf | |||
4 | .phases['ncaf'].atom_sites['Ca'].fract_y | 0.000000 | -inf | inf | |||
5 | .phases['ncaf'].atom_sites['Ca'].fract_z | 0.250000 | -inf | inf | |||
6 | .phases['ncaf'].atom_sites['Ca'].b_iso_or_equiv | 0.900000 | Ų | 0.0 | inf | ||
7 | .phases['ncaf'].atom_sites['Al'].occupancy | 1.000000 | -inf | inf | |||
8 | .phases['ncaf'].atom_sites['Al'].fract_x | 0.251710 | -inf | inf | |||
9 | .phases['ncaf'].atom_sites['Al'].fract_y | 0.251710 | -inf | inf | |||
10 | .phases['ncaf'].atom_sites['Al'].fract_z | 0.251710 | -inf | inf | |||
11 | .phases['ncaf'].atom_sites['Al'].b_iso_or_equiv | 0.660000 | Ų | 0.0 | inf | ||
12 | .phases['ncaf'].atom_sites['Na'].occupancy | 1.000000 | -inf | inf | |||
13 | .phases['ncaf'].atom_sites['Na'].fract_x | 0.084810 | -inf | inf | |||
14 | .phases['ncaf'].atom_sites['Na'].fract_y | 0.084810 | -inf | inf | |||
15 | .phases['ncaf'].atom_sites['Na'].fract_z | 0.084810 | -inf | inf | |||
16 | .phases['ncaf'].atom_sites['Na'].b_iso_or_equiv | 1.900000 | Ų | 0.0 | inf | ||
17 | .phases['ncaf'].atom_sites['F1'].occupancy | 1.000000 | -inf | inf | |||
18 | .phases['ncaf'].atom_sites['F1'].fract_x | 0.137500 | -inf | inf | |||
19 | .phases['ncaf'].atom_sites['F1'].fract_y | 0.305300 | -inf | inf | |||
20 | .phases['ncaf'].atom_sites['F1'].fract_z | 0.119500 | -inf | inf | |||
21 | .phases['ncaf'].atom_sites['F1'].b_iso_or_equiv | 0.900000 | Ų | 0.0 | inf | ||
22 | .phases['ncaf'].atom_sites['F2'].occupancy | 1.000000 | -inf | inf | |||
23 | .phases['ncaf'].atom_sites['F2'].fract_x | 0.362600 | -inf | inf | |||
24 | .phases['ncaf'].atom_sites['F2'].fract_y | 0.363400 | -inf | inf | |||
25 | .phases['ncaf'].atom_sites['F2'].fract_z | 0.186700 | -inf | inf | |||
26 | .phases['ncaf'].atom_sites['F2'].b_iso_or_equiv | 1.280000 | Ų | 0.0 | inf | ||
27 | .phases['ncaf'].atom_sites['F3'].occupancy | 1.000000 | -inf | inf | |||
28 | .phases['ncaf'].atom_sites['F3'].fract_x | 0.461200 | -inf | inf | |||
29 | .phases['ncaf'].atom_sites['F3'].fract_y | 0.461200 | -inf | inf | |||
30 | .phases['ncaf'].atom_sites['F3'].fract_z | 0.461200 | -inf | inf | |||
31 | .phases['ncaf'].atom_sites['F3'].b_iso_or_equiv | 0.790000 | Ų | 0.0 | inf | ||
32 | .phases['ncaf'].scale | 1.085347 | 0.003434 | 0.0 | inf | True | |
33 | .instrument.ttheta_bank | 152.827000 | deg | -inf | inf | ||
34 | .instrument.dtt1 | 20770.000000 | µs/Å | -inf | inf | ||
35 | .instrument.dtt2 | -1.083080 | µs/Ų | -inf | inf | ||
36 | .instrument.sigma0 | 0.000000 | µs² | -inf | inf | ||
37 | .instrument.sigma1 | 0.000000 | µs²/Ų | -inf | inf | ||
38 | .instrument.sigma2 | 13.778083 | µs²/Å⁴ | 0.764276 | -inf | inf | True |
39 | .instrument.alpha0 | 0.000000 | -inf | inf | |||
40 | .instrument.alpha1 | 0.083958 | 0.001075 | -inf | inf | True | |
41 | .instrument.beta0 | 0.006515 | 0.000041 | -inf | inf | True | |
42 | .instrument.beta1 | 0.012430 | 0.000216 | -inf | inf | True | |
43 | .pattern.zero_shift | -3.440901 | µs | 0.076697 | -inf | inf | True |
44 | .pattern.backgrounds[0]['9162,0_deg'].intensity | 465.000000 | -inf | inf | |||
45 | .pattern.backgrounds[0]['11136,0_deg'].intensity | 593.000000 | -inf | inf | |||
46 | .pattern.backgrounds[0]['13313,0_deg'].intensity | 497.000000 | -inf | inf | |||
47 | .pattern.backgrounds[0]['14906,0_deg'].intensity | 546.000000 | -inf | inf | |||
48 | .pattern.backgrounds[0]['16454,0_deg'].intensity | 533.000000 | -inf | inf | |||
49 | .pattern.backgrounds[0]['17352,0_deg'].intensity | 496.000000 | -inf | inf | |||
50 | .pattern.backgrounds[0]['18743,0_deg'].intensity | 428.000000 | -inf | inf | |||
51 | .pattern.backgrounds[0]['20179,0_deg'].intensity | 452.000000 | -inf | inf | |||
52 | .pattern.backgrounds[0]['21368,0_deg'].intensity | 397.000000 | -inf | inf | |||
53 | .pattern.backgrounds[0]['22176,0_deg'].intensity | 468.000000 | -inf | inf | |||
54 | .pattern.backgrounds[0]['22827,0_deg'].intensity | 477.000000 | -inf | inf | |||
55 | .pattern.backgrounds[0]['24644,0_deg'].intensity | 380.000000 | -inf | inf | |||
56 | .pattern.backgrounds[0]['26439,0_deg'].intensity | 381.000000 | -inf | inf | |||
57 | .pattern.backgrounds[0]['28257,0_deg'].intensity | 378.000000 | -inf | inf | |||
58 | .pattern.backgrounds[0]['31196,0_deg'].intensity | 343.000000 | -inf | inf | |||
59 | .pattern.backgrounds[0]['34034,0_deg'].intensity | 328.000000 | -inf | inf | |||
60 | .pattern.backgrounds[0]['37265,0_deg'].intensity | 310.000000 | -inf | inf | |||
61 | .pattern.backgrounds[0]['41214,0_deg'].intensity | 323.000000 | -inf | inf | |||
62 | .pattern.backgrounds[0]['44827,0_deg'].intensity | 283.000000 | -inf | inf | |||
63 | .pattern.backgrounds[0]['49830,0_deg'].intensity | 273.000000 | -inf | inf | |||
64 | .pattern.backgrounds[0]['52905,0_deg'].intensity | 257.000000 | -inf | inf | |||
65 | .pattern.backgrounds[0]['58204,0_deg'].intensity | 260.000000 | -inf | inf | |||
66 | .pattern.backgrounds[0]['62916,0_deg'].intensity | 261.000000 | -inf | inf | |||
67 | .pattern.backgrounds[0]['70186,0_deg'].intensity | 262.000000 | -inf | inf | |||
68 | .pattern.backgrounds[0]['74204,0_deg'].intensity | 262.000000 | -inf | inf | |||
69 | .pattern.backgrounds[0]['82103,0_deg'].intensity | 268.000000 | -inf | inf | |||
70 | .pattern.backgrounds[0]['91958,0_deg'].intensity | 268.000000 | -inf | inf | |||
71 | .pattern.backgrounds[0]['102712,0_deg'].intensity | 262.000000 | -inf | inf |