|
1 | | -# %% |
| 1 | +# %% [markdown] |
| 2 | +# # Structure Refinement: LBCO, HRPT |
| 3 | +# |
| 4 | +# This minimalistic example is designed to be as compact as possible for |
| 5 | +# a Rietveld refinement of a crystal structure using constant-wavelength |
| 6 | +# neutron powder diffraction data for La0.5Ba0.5CoO3 from HRPT at PSI. |
| 7 | +# |
| 8 | +# It does not contain any advanced features or options, and includes no |
| 9 | +# comments or explanations—these can be found in the other tutorials. |
| 10 | +# Default values are used for all parameters if not specified. Only |
| 11 | +# essential and self-explanatory code is provided. |
| 12 | +# |
| 13 | +# The example is intended for users who are already familiar with the |
| 14 | +# EasyDiffraction library and want to quickly get started with a simple |
| 15 | +# refinement. It is also useful for those who want to see what a |
| 16 | +# refinement might look like in code. For a more detailed explanation of |
| 17 | +# the code, please refer to the other tutorials. |
| 18 | + |
| 19 | +# %% [markdown] |
2 | 20 | # ## Import Library |
| 21 | + |
| 22 | +# %% |
3 | 23 | import easydiffraction as ed |
4 | 24 |
|
5 | 25 | # %% |
| 26 | +from easydiffraction.utils.logging import Logger |
| 27 | +Logger.configure( |
| 28 | + level=Logger.Level.INFO, |
| 29 | + mode=Logger.Mode.COMPACT, |
| 30 | + reaction=Logger.Reaction.WARN, |
| 31 | +) |
| 32 | + |
| 33 | +# %% [markdown] |
6 | 34 | # ## Step 1: Define Project |
7 | | -project = ed.Project() |
8 | | -#project.tabler.engine = 'rich' |
9 | | -#project.tabler.engine = 'pandas' |
10 | 35 |
|
11 | 36 | # %% |
| 37 | +project = ed.Project() |
| 38 | + |
| 39 | +# %% [markdown] |
12 | 40 | # ## Step 2: Define Sample Model |
13 | | -project.sample_models.add_minimal(name='lbco') |
14 | 41 |
|
| 42 | +# %% |
| 43 | +project.sample_models.add_from_cif_path("data/lbco.cif") |
| 44 | + |
| 45 | +# %% |
| 46 | +project.sample_models.show_names() |
| 47 | + |
| 48 | +# %% |
15 | 49 | sample_model = project.sample_models['lbco'] |
16 | | -sample_model.space_group.name_h_m = 'P m -3 m' |
17 | | -sample_model.space_group.it_coordinate_system_code = '1' |
18 | | -sample_model.cell.length_a = 3.88 |
19 | | -sample_model.atom_sites.add_from_args( |
20 | | - label='La', |
21 | | - type_symbol='La', |
22 | | - fract_x=0, |
23 | | - fract_y=0, |
24 | | - fract_z=0, |
25 | | - wyckoff_letter='a', |
26 | | - b_iso=0.5, |
27 | | - occupancy=0.5, |
28 | | -) |
29 | | -sample_model.atom_sites.add_from_args( |
30 | | - label='Ba', |
31 | | - type_symbol='Ba', |
32 | | - fract_x=0, |
33 | | - fract_y=0, |
34 | | - fract_z=0, |
35 | | - wyckoff_letter='a', |
36 | | - b_iso=0.5, |
37 | | - occupancy=0.5, |
38 | | -) |
39 | | -sample_model.atom_sites.add_from_args( |
40 | | - label='Co', |
41 | | - type_symbol='Co', |
42 | | - fract_x=0.5, |
43 | | - fract_y=0.5, |
44 | | - fract_z=0.5, |
45 | | - wyckoff_letter='b', |
46 | | - b_iso=0.5, |
47 | | -) |
48 | | -sample_model.atom_sites.add_from_args( |
49 | | - label='O', type_symbol='O', fract_x=0, fract_y=0.5, fract_z=0.5, wyckoff_letter='c', b_iso=0.5 |
50 | | -) |
51 | 50 |
|
52 | 51 | # %% |
| 52 | +sample_model.show_as_cif() |
| 53 | + |
| 54 | +# %% [markdown] |
53 | 55 | # ## Step 3: Define Experiment |
54 | | -ed.download_from_repository('hrpt_lbco.xye', destination='data') |
55 | | - |
56 | | -project.experiments.add_from_data_path( |
57 | | - name='hrpt', |
58 | | - data_path='data/hrpt_lbco.xye', |
59 | | - sample_form='powder', |
60 | | - beam_mode='constant wavelength', |
61 | | - radiation_probe='neutron', |
62 | | -) |
63 | 56 |
|
| 57 | +# %% |
| 58 | +project.experiments.add_from_cif_path("data/hrpt.cif") |
| 59 | + |
| 60 | +# %% |
64 | 61 | experiment = project.experiments['hrpt'] |
| 62 | + |
| 63 | +# %% |
| 64 | +project.experiments.show_names() |
| 65 | + |
| 66 | +# %% |
65 | 67 | experiment.instrument.setup_wavelength = 1.494 |
66 | 68 | experiment.instrument.calib_twotheta_offset = 0.6 |
| 69 | + |
| 70 | +# %% |
67 | 71 | experiment.peak.broad_gauss_u = 0.1 |
68 | 72 | experiment.peak.broad_gauss_v = -0.1 |
69 | 73 | experiment.peak.broad_gauss_w = 0.1 |
70 | 74 | experiment.peak.broad_lorentz_y = 0.1 |
| 75 | + |
| 76 | +# %% |
71 | 77 | experiment.background.add_from_args(x=10, y=170) |
72 | 78 | experiment.background.add_from_args(x=30, y=170) |
73 | 79 | experiment.background.add_from_args(x=50, y=170) |
74 | 80 | experiment.background.add_from_args(x=110, y=170) |
75 | 81 | experiment.background.add_from_args(x=165, y=170) |
| 82 | + |
| 83 | +# %% |
76 | 84 | experiment.excluded_regions.add_from_args(start=0, end=5) |
77 | 85 | experiment.excluded_regions.add_from_args(start=165, end=180) |
78 | | -experiment.linked_phases.add_from_args(id='lbco', scale=10.0) |
79 | 86 |
|
80 | 87 | # %% |
| 88 | +experiment.linked_phases.add_from_args(id='lbco', scale=10.0) |
| 89 | + |
| 90 | +# %% [markdown] |
81 | 91 | # ## Step 4: Perform Analysis |
| 92 | + |
| 93 | +# %% |
82 | 94 | sample_model.cell.length_a.free = True |
| 95 | + |
83 | 96 | sample_model.atom_sites['La'].b_iso.free = True |
84 | 97 | sample_model.atom_sites['Ba'].b_iso.free = True |
85 | 98 | sample_model.atom_sites['Co'].b_iso.free = True |
86 | 99 | sample_model.atom_sites['O'].b_iso.free = True |
87 | 100 |
|
| 101 | +# %% |
88 | 102 | experiment.instrument.calib_twotheta_offset.free = True |
| 103 | + |
89 | 104 | experiment.peak.broad_gauss_u.free = True |
90 | 105 | experiment.peak.broad_gauss_v.free = True |
91 | 106 | experiment.peak.broad_gauss_w.free = True |
92 | 107 | experiment.peak.broad_lorentz_y.free = True |
| 108 | + |
93 | 109 | experiment.background['10'].y.free = True |
94 | 110 | experiment.background['30'].y.free = True |
95 | 111 | experiment.background['50'].y.free = True |
96 | 112 | experiment.background['110'].y.free = True |
97 | 113 | experiment.background['165'].y.free = True |
| 114 | + |
98 | 115 | experiment.linked_phases['lbco'].scale.free = True |
99 | 116 |
|
100 | 117 | # %% |
101 | | -sample_model.cell.length_a = 3.88 |
102 | 118 | project.analysis.fit() |
103 | 119 |
|
104 | 120 | # %% |
105 | | -#project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True) |
106 | | - |
107 | | -# %% |
108 | | -project.analysis.show_all_params() |
109 | | - |
110 | | -# %% |
111 | | -project.analysis.show_fittable_params() |
112 | | - |
113 | | -# %% |
114 | | -project.analysis.show_free_params() |
115 | | - |
116 | | -# %% |
117 | | -project.analysis.how_to_access_parameters() |
118 | | - |
119 | | -# %% |
120 | | -project.analysis.show_parameter_cif_uids() |
| 121 | +project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True) |
0 commit comments