|
| 1 | +# %% [markdown] |
| 2 | +# # Structure Refinement: BSFTO, HRPT |
| 3 | +# |
| 4 | +# This example demonstrates a Rietveld refinement of Bi1−xSmxFe0.94Ti0.06O3 |
| 5 | +# crystal and magnetic structure... |
| 6 | + |
| 7 | +# %% [markdown] |
| 8 | +# ## Import Library |
| 9 | + |
| 10 | +# %% |
| 11 | +from easydiffraction import ( |
| 12 | + Project, |
| 13 | + SampleModel, |
| 14 | + Experiment, |
| 15 | + download_from_repository |
| 16 | +) |
| 17 | + |
| 18 | +# %% [markdown] |
| 19 | +# ## Define Sample Models |
| 20 | +# |
| 21 | +# This section shows how to add sample models and modify their parameters. |
| 22 | +# |
| 23 | +# ### Create Sample Model 1: Orthorhombic phase |
| 24 | + |
| 25 | +# %% |
| 26 | +model_1 = SampleModel('ort') |
| 27 | + |
| 28 | +# %% [markdown] |
| 29 | +# #### Set Space Group |
| 30 | + |
| 31 | +# %% |
| 32 | +model_1.space_group.name_h_m = 'P b a m' |
| 33 | +model_1.space_group.it_coordinate_system_code = 'abc' |
| 34 | + |
| 35 | +# %% [markdown] |
| 36 | +# #### Set Unit Cell |
| 37 | + |
| 38 | +# %% |
| 39 | +model_1.cell.length_a = 5.588 |
| 40 | +model_1.cell.length_b = 11.125 |
| 41 | +model_1.cell.length_c = 7.876 |
| 42 | + |
| 43 | +# %% [markdown] |
| 44 | +# #### Set Atom Sites |
| 45 | + |
| 46 | +# %% |
| 47 | +model_1.atom_sites.add('Bi1', 'Bi', 0.702, 0.114, 0, wyckoff_letter='g', b_iso=0.0, occupancy=0.88) |
| 48 | +model_1.atom_sites.add('Sm1', 'Sm', 0.702, 0.114, 0, wyckoff_letter='g', b_iso=0.0, occupancy=0.12) |
| 49 | +model_1.atom_sites.add('Bi2', 'Bi', 0.751, 0.132, 0.5, wyckoff_letter='h', b_iso=0.0, occupancy=0.88) |
| 50 | +model_1.atom_sites.add('Sm2', 'Sm', 0.751, 0.132, 0.5, wyckoff_letter='h', b_iso=0.0, occupancy=0.12) |
| 51 | +model_1.atom_sites.add('Fe', 'Fe', 0.236, 0.121, 0.259, wyckoff_letter='i', b_iso=0.0, occupancy=0.94) |
| 52 | +model_1.atom_sites.add('Ti', 'Ti', 0.236, 0.121, 0.259, wyckoff_letter='i', b_iso=0.0, occupancy=0.06) |
| 53 | +model_1.atom_sites.add('O1', 'O', 0.258, 0.151, 0, wyckoff_letter='g', b_iso=0.0, occupancy=1.0) |
| 54 | +model_1.atom_sites.add('O2', 'O', 0.316, 0.093, 0.5, wyckoff_letter='h', b_iso=0.0, occupancy=1.0) |
| 55 | +model_1.atom_sites.add('O3', 'O', 0.002, 0.258, 0.299, wyckoff_letter='i', b_iso=0.0, occupancy=1.0) |
| 56 | +model_1.atom_sites.add('O4', 'O', 0, 0.5, 0.264, wyckoff_letter='f', b_iso=0.0, occupancy=1.0) |
| 57 | +model_1.atom_sites.add('O5', 'O', 0, 0, 0.198, wyckoff_letter='e', b_iso=0.0, occupancy=1.0) |
| 58 | + |
| 59 | +# %% [markdown] |
| 60 | +# ### Create Sample Model 2: Rhombohedral phase |
| 61 | + |
| 62 | +# %% |
| 63 | +model_2 = SampleModel('rho') |
| 64 | + |
| 65 | +# %% [markdown] |
| 66 | +# #### Set Space Group |
| 67 | + |
| 68 | +# %% |
| 69 | +model_2.space_group.name_h_m = 'R 3 c' |
| 70 | +model_2.space_group.it_coordinate_system_code = 'h' |
| 71 | + |
| 72 | +# %% [markdown] |
| 73 | +# #### Set Unit Cell |
| 74 | + |
| 75 | +# %% |
| 76 | +model_2.cell.length_a = 5.568 |
| 77 | +model_2.cell.length_c = 13.758 |
| 78 | + |
| 79 | +# %% [markdown] |
| 80 | +# #### Set Atom Sites |
| 81 | + |
| 82 | +# %% |
| 83 | +model_2.atom_sites.add('Bi', 'Bi', 0, 0, 0, wyckoff_letter='a', b_iso=0.0, occupancy=0.88) |
| 84 | +model_2.atom_sites.add('Sm', 'Sm', 0, 0, 0, wyckoff_letter='a', b_iso=0.0, occupancy=0.12) |
| 85 | +model_2.atom_sites.add('Fe', 'Fe', 0, 0, 0.223, wyckoff_letter='a', b_iso=0.0, occupancy=0.94) |
| 86 | +model_2.atom_sites.add('Ti', 'Ti', 0, 0, 0.223, wyckoff_letter='a', b_iso=0.0, occupancy=0.06) |
| 87 | +model_2.atom_sites.add('O', 'O', 0.436, 0.022, 0.958, wyckoff_letter='b', b_iso=0.0, occupancy=1.0) |
| 88 | + |
| 89 | +# %% [markdown] |
| 90 | +# ## Define Experiment |
| 91 | +# |
| 92 | +# This section shows how to add experiments, configure their parameters, and |
| 93 | +# link the sample models defined in the previous step. |
| 94 | +# |
| 95 | +# #### Download Data |
| 96 | + |
| 97 | +# %% |
| 98 | +#download_from_repository('hrpt_n_Bi0p88Sm0p12Fe0p94Ti0p06O3_DW_V_9x8x52_1p49_HI.xye', |
| 99 | +# branch='develop', |
| 100 | +# destination='data') |
| 101 | + |
| 102 | +# %% [markdown] |
| 103 | +# #### Create Experiment |
| 104 | + |
| 105 | +# %% |
| 106 | +experiment = Experiment('hrpt', |
| 107 | + data_path='data/hrpt_n_Bi0p88Sm0p12Fe0p94Ti0p06O3_DW_V_9x8x52_1p49_HI.xye') |
| 108 | + |
| 109 | +# %% [markdown] |
| 110 | +# #### Set Instrument |
| 111 | + |
| 112 | +# %% |
| 113 | +experiment.instrument.setup_wavelength = 1.494 |
| 114 | +experiment.instrument.calib_twotheta_offset = 0.14 |
| 115 | + |
| 116 | +# %% [markdown] |
| 117 | +# #### Set Peak Profile |
| 118 | + |
| 119 | +# %% |
| 120 | +experiment.peak.broad_gauss_u = 0.7 |
| 121 | +experiment.peak.broad_gauss_v = -0.41 |
| 122 | +experiment.peak.broad_gauss_w = 0.18 |
| 123 | +experiment.peak.broad_lorentz_x = 0 |
| 124 | +experiment.peak.broad_lorentz_y = 0.21 |
| 125 | + |
| 126 | +# %% [markdown] |
| 127 | +# #### Set Background |
| 128 | + |
| 129 | +# %% [markdown] |
| 130 | +# Select the background type. |
| 131 | + |
| 132 | +# %% |
| 133 | +experiment.background_type = 'line-segment' |
| 134 | + |
| 135 | +# %% [markdown] |
| 136 | +# Add background points. |
| 137 | + |
| 138 | +# %% |
| 139 | +experiment.background.add(x=10, y=865) |
| 140 | +experiment.background.add(x=30, y=888) |
| 141 | +experiment.background.add(x=50, y=893) |
| 142 | +experiment.background.add(x=110, y=874) |
| 143 | +experiment.background.add(x=165, y=702) |
| 144 | + |
| 145 | +# %% [markdown] |
| 146 | +# #### Set Linked Phases |
| 147 | + |
| 148 | +# %% |
| 149 | +experiment.linked_phases.add('ort', scale=0.07) |
| 150 | +experiment.linked_phases.add('rho', scale=0.21) |
| 151 | + |
| 152 | +# %% [markdown] |
| 153 | +# ## Define Project |
| 154 | +# |
| 155 | +# The project object is used to manage sample models, experiments, and analysis. |
| 156 | +# |
| 157 | +# #### Create Project |
| 158 | + |
| 159 | +# %% |
| 160 | +project = Project() |
| 161 | + |
| 162 | +# %% [markdown] |
| 163 | +# #### Set Plotting Engine |
| 164 | + |
| 165 | +# %% |
| 166 | +project.plotter.engine = 'plotly' |
| 167 | + |
| 168 | +# %% [markdown] |
| 169 | +# #### Add Sample Models |
| 170 | + |
| 171 | +# %% |
| 172 | +project.sample_models.add(model_1) |
| 173 | +project.sample_models.add(model_2) |
| 174 | + |
| 175 | +# %% [markdown] |
| 176 | +# #### Show Sample Models |
| 177 | + |
| 178 | +# %% |
| 179 | +project.sample_models.show_names() |
| 180 | + |
| 181 | +# %% [markdown] |
| 182 | +# #### Add Experiments |
| 183 | + |
| 184 | +# %% |
| 185 | +project.experiments.add(experiment) |
| 186 | + |
| 187 | +# %% [markdown] |
| 188 | +# #### Set Excluded Regions |
| 189 | +# |
| 190 | +# Show measured data as loaded from the file. |
| 191 | + |
| 192 | +# %% |
| 193 | +project.plot_meas(expt_name='hrpt') |
| 194 | + |
| 195 | +# %% [markdown] |
| 196 | +# Add excluded regions. |
| 197 | + |
| 198 | +# %% |
| 199 | +experiment.excluded_regions.add(minimum=0, maximum=10) |
| 200 | +experiment.excluded_regions.add(minimum=160, maximum=180) |
| 201 | + |
| 202 | +# %% [markdown] |
| 203 | +# Show excluded regions. |
| 204 | + |
| 205 | +# %% |
| 206 | +experiment.excluded_regions.show() |
| 207 | + |
| 208 | +# %% [markdown] |
| 209 | +# Show measured data after adding excluded regions. |
| 210 | + |
| 211 | +# %% |
| 212 | +project.plot_meas(expt_name='hrpt') |
| 213 | + |
| 214 | +# %% [markdown] |
| 215 | +# Show experiment as CIF. |
| 216 | + |
| 217 | +# %% |
| 218 | +project.experiments['hrpt'].show_as_cif() |
| 219 | + |
| 220 | +# %% [markdown] |
| 221 | +# ## Perform Analysis |
| 222 | +# |
| 223 | +# This section outlines the analysis process, including how to configure |
| 224 | +# calculation and fitting engines. |
| 225 | +# |
| 226 | +# #### Set Calculator |
| 227 | + |
| 228 | +# %% |
| 229 | +project.analysis.current_calculator = 'cryspy' |
| 230 | + |
| 231 | +# %% [markdown] |
| 232 | +# #### Set Minimizer |
| 233 | + |
| 234 | +# %% |
| 235 | +project.analysis.current_minimizer = 'lmfit (leastsq)' |
| 236 | + |
| 237 | +# %% [markdown] |
| 238 | +# #### Set Fitting Parameters |
| 239 | +# |
| 240 | +# Set sample model parameters to be optimized. |
| 241 | + |
| 242 | +# %% |
| 243 | +#model_1.cell.length_a.free = True |
| 244 | +#model_1.atom_sites['Co'].b_iso.free = True |
| 245 | +#model_1.atom_sites['O'].b_iso.free = True |
| 246 | + |
| 247 | +#model_2.cell.length_a.free = True |
| 248 | + |
| 249 | +# %% [markdown] |
| 250 | +# Set experiment parameters to be optimized. |
| 251 | + |
| 252 | +# %% |
| 253 | +experiment.instrument.calib_twotheta_offset.free = True |
| 254 | + |
| 255 | +# %% |
| 256 | +experiment.peak.broad_gauss_u.free = True |
| 257 | +experiment.peak.broad_gauss_v.free = True |
| 258 | +experiment.peak.broad_gauss_w.free = True |
| 259 | +experiment.peak.broad_lorentz_y.free = True |
| 260 | + |
| 261 | +# %% |
| 262 | +experiment.linked_phases['ort'].scale.free = True |
| 263 | +experiment.linked_phases['rho'].scale.free = True |
| 264 | + |
| 265 | +for point in experiment.background: |
| 266 | + point.y.free = True |
| 267 | + |
| 268 | +# %% [markdown] |
| 269 | +# #### Perform Fit |
| 270 | + |
| 271 | +# %% |
| 272 | +project.analysis.fit() |
| 273 | + |
| 274 | +# %% [markdown] |
| 275 | +# #### Plot Measured vs Calculated |
| 276 | + |
| 277 | +# %% |
| 278 | +project.plot_meas_vs_calc(expt_name='hrpt') |
0 commit comments