Skip to content

Commit eba4c70

Browse files
committed
Refactors for CIF parsing functionality
1 parent e6400e7 commit eba4c70

File tree

2 files changed

+3202
-67
lines changed

2 files changed

+3202
-67
lines changed
Lines changed: 68 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,121 @@
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]
220
# ## Import Library
21+
22+
# %%
323
import easydiffraction as ed
424

525
# %%
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]
634
# ## Step 1: Define Project
7-
project = ed.Project()
8-
#project.tabler.engine = 'rich'
9-
#project.tabler.engine = 'pandas'
1035

1136
# %%
37+
project = ed.Project()
38+
39+
# %% [markdown]
1240
# ## Step 2: Define Sample Model
13-
project.sample_models.add_minimal(name='lbco')
1441

42+
# %%
43+
project.sample_models.add_from_cif_path("data/lbco.cif")
44+
45+
# %%
46+
project.sample_models.show_names()
47+
48+
# %%
1549
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-
)
5150

5251
# %%
52+
sample_model.show_as_cif()
53+
54+
# %% [markdown]
5355
# ## 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-
)
6356

57+
# %%
58+
project.experiments.add_from_cif_path("data/hrpt.cif")
59+
60+
# %%
6461
experiment = project.experiments['hrpt']
62+
63+
# %%
64+
project.experiments.show_names()
65+
66+
# %%
6567
experiment.instrument.setup_wavelength = 1.494
6668
experiment.instrument.calib_twotheta_offset = 0.6
69+
70+
# %%
6771
experiment.peak.broad_gauss_u = 0.1
6872
experiment.peak.broad_gauss_v = -0.1
6973
experiment.peak.broad_gauss_w = 0.1
7074
experiment.peak.broad_lorentz_y = 0.1
75+
76+
# %%
7177
experiment.background.add_from_args(x=10, y=170)
7278
experiment.background.add_from_args(x=30, y=170)
7379
experiment.background.add_from_args(x=50, y=170)
7480
experiment.background.add_from_args(x=110, y=170)
7581
experiment.background.add_from_args(x=165, y=170)
82+
83+
# %%
7684
experiment.excluded_regions.add_from_args(start=0, end=5)
7785
experiment.excluded_regions.add_from_args(start=165, end=180)
78-
experiment.linked_phases.add_from_args(id='lbco', scale=10.0)
7986

8087
# %%
88+
experiment.linked_phases.add_from_args(id='lbco', scale=10.0)
89+
90+
# %% [markdown]
8191
# ## Step 4: Perform Analysis
92+
93+
# %%
8294
sample_model.cell.length_a.free = True
95+
8396
sample_model.atom_sites['La'].b_iso.free = True
8497
sample_model.atom_sites['Ba'].b_iso.free = True
8598
sample_model.atom_sites['Co'].b_iso.free = True
8699
sample_model.atom_sites['O'].b_iso.free = True
87100

101+
# %%
88102
experiment.instrument.calib_twotheta_offset.free = True
103+
89104
experiment.peak.broad_gauss_u.free = True
90105
experiment.peak.broad_gauss_v.free = True
91106
experiment.peak.broad_gauss_w.free = True
92107
experiment.peak.broad_lorentz_y.free = True
108+
93109
experiment.background['10'].y.free = True
94110
experiment.background['30'].y.free = True
95111
experiment.background['50'].y.free = True
96112
experiment.background['110'].y.free = True
97113
experiment.background['165'].y.free = True
114+
98115
experiment.linked_phases['lbco'].scale.free = True
99116

100117
# %%
101-
sample_model.cell.length_a = 3.88
102118
project.analysis.fit()
103119

104120
# %%
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

Comments
 (0)