Skip to content

Commit 5c3dab8

Browse files
committed
Improves tutorials section and adds quick-start tutorial
1 parent fd3938f commit 5c3dab8

File tree

6 files changed

+204
-50
lines changed

6 files changed

+204
-50
lines changed

docs/mkdocs.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ nav:
5454
- Analysis: usage/workflow-steps/analysis.md
5555
- Summary: usage/workflow-steps/summary.md
5656
- Tutorials:
57-
- Getting Started: tutorials/index.md
58-
- Basic vs. Advanced:
59-
- LBCO pd-neut-cwl: tutorials/basic_single-fit_pd-neut-cwl_LBCO-HRPT.ipynb
60-
- PbSO4 pd-neut-xray-cwl: tutorials/advanced_joint-fit_pd-neut-xray-cwl_PbSO4.ipynb
57+
- Tutorials: tutorials/index.md
58+
- Getting Started:
59+
- LBCO quick: tutorials/quick_single-fit_pd-neut-cwl_LBCO-HRPT.ipynb
60+
- LBCO basic: tutorials/basic_single-fit_pd-neut-cwl_LBCO-HRPT.ipynb
61+
- PbSO4 advanced: tutorials/advanced_joint-fit_pd-neut-xray-cwl_PbSO4.ipynb
6162
- Structure Refinement:
6263
- HS pd-neut-cwl: tutorials/cryst-struct_pd-neut-cwl_HS-HRPT.ipynb
6364
- Si pd-neut-tof: tutorials/cryst-struct_pd-neut-tof_Si-SEPD.ipynb

docs/tutorials/index.md

+33-23
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,60 @@ icon: material/school
44

55
# :material-school: Tutorials
66

7-
This section offers a collection of **Jupyter Notebook examples** illustrating
8-
the usage of EasyDiffraction for various tasks. These tutorials act as
9-
**step-by-step guides**, helping users grasp the workflow of diffraction data
10-
analysis within EasyDiffraction.
7+
This section presents a collection of **Jupyter Notebook** tutorials that
8+
demonstrate how to use EasyDiffraction for various tasks. These tutorials serve
9+
as **step-by-step guides** to help users grasp the workflow of diffraction data
10+
analysis using EasyDiffraction.
1111

12-
An instruction on how to run the tutorials is provided in the
12+
Instructions on how to run the tutorials are provided in the
1313
[:material-cog-box: Installation & Setup](../installation/index.md#running-tutorials)
1414
section of the documentation.
1515

16-
The tutorials are categorized as follows.
16+
The tutorials are organized into the following categories.
1717

18-
## Basic vs. Advanced
18+
## Getting Started
1919

20-
- [LBCO `pd-neut-cwl`](basic_single-fit_pd-neut-cwl_LBCO-HRPT.ipynb) -
21-
Demonstrates usage of the EasyDiffraction API in a simplified,
20+
- [LBCO `quick`](quick_single-fit_pd-neut-cwl_LBCO-HRPT.ipynb) -
21+
A minimal example intended as a quick reference for users already familiar
22+
with the EasyDiffraction API or who want to see an example refinement in
23+
code. This tutorial covers a Rietveld refinement of the La0.5Ba0.5CoO3
24+
crystal structure using constant wavelength neutron powder diffraction data
25+
from HRPT at PSI.
26+
- [LBCO `basic`](basic_single-fit_pd-neut-cwl_LBCO-HRPT.ipynb) -
27+
Demonstrates the use of the EasyDiffraction API in a simplified,
2228
user-friendly manner that closely follows the GUI workflow for a Rietveld
23-
refinement of La0.5Ba0.5CoO3 crystal structure using constant wavelength
24-
neutron powder diffraction data from HRPT at PSI.
25-
- [PbSO4 `pd-neut-xray-cwl`](advanced_joint-fit_pd-neut-xray-cwl_PbSO4.ipynb) -
26-
Demonstrates a more flexible and advanced approach to use the
27-
EasyDiffraction library, intended for users more comfortable with Python
28-
programming. This tutorial covers a Rietveld refinement of PbSO4 crystal
29-
structure based on the joint fit of both X-ray and neutron diffraction data.
29+
refinement of the La0.5Ba0.5CoO3 crystal structure using constant wavelength
30+
neutron powder diffraction data from HRPT at PSI. This tutorial provides a
31+
full explanation of the workflow with detailed comments and descriptions of
32+
every step, making it suitable for users who are new to EasyDiffraction or
33+
those who prefer a more guided approach.
34+
- [PbSO4 `advanced`](advanced_joint-fit_pd-neut-xray-cwl_PbSO4.ipynb) -
35+
Demonstrates a more flexible and advanced approach to using the
36+
EasyDiffraction library, intended for users who are more comfortable with
37+
Python programming. This tutorial covers a Rietveld refinement of the PbSO4
38+
crystal structure based on the joint fit of both X-ray and neutron
39+
diffraction data.
3040

3141
## Standard Diffraction
3242

3343
- [HS `pd-neut-cwl`](cryst-struct_pd-neut-cwl_HS-HRPT.ipynb) -
34-
Demonstrates a Rietveld refinement of HS crystal structure using constant
44+
Demonstrates a Rietveld refinement of the HS crystal structure using constant
3545
wavelength neutron powder diffraction data from HRPT at PSI.
3646
- [Si `pd-neut-tof`](cryst-struct_pd-neut-tof_Si-SEPD.ipynb) -
37-
Demonstrates a Rietveld refinement of Si crystal structure using
47+
Demonstrates a Rietveld refinement of the Si crystal structure using
3848
time-of-flight neutron powder diffraction data from SEPD at Argonne.
3949
- [NCAF `pd-neut-tof`](cryst-struct_pd-neut-tof_NCAF-WISH.ipynb) -
40-
Demonstrates a Rietveld refinement of Na2Ca3Al2F14 crystal structure using
41-
time-of-flight neutron powder diffraction data from WISH at ISIS.
50+
Demonstrates a Rietveld refinement of the Na2Ca3Al2F14 crystal structure
51+
using time-of-flight neutron powder diffraction data from WISH at ISIS.
4252

4353
## Pair Distribution Function (PDF)
4454

4555
- [Ni `pd-neut-cwl`](pdf_pd-neut-cwl_Ni.ipynb) -
46-
Demonstrates a PDF analysis of Ni based on data collected from a constant
56+
Demonstrates a PDF analysis of Ni using data collected from a constant
4757
wavelength neutron powder diffraction experiment.
4858
- [Si `pd-neut-tof`](pdf_pd-neut-tof_Si-NOMAD.ipynb) -
49-
Demonstrates a PDF analysis of Si based on data collected from a
59+
Demonstrates a PDF analysis of Si using data collected from a
5060
time-of-flight neutron powder diffraction experiment at NOMAD at SNS.
5161
- [NaCl `pd-xray`](pdf_pd-xray_NaCl.ipynb) -
52-
Demonstrates a PDF analysis of NaCl based on data collected from an X-ray
62+
Demonstrates a PDF analysis of NaCl using data collected from an X-ray
5363
powder diffraction experiment.

docs/usage/workflow-steps/index.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ flowchart LR
1717
```
1818

1919
- [:material-archive: Project](project.md) - Establish a **project** as a
20-
container for data, settings, and analysis results.
21-
- [:material-puzzle: Model](model.md) - Load an existing
20+
container for sample model and experiment parameters, measured and calculated
21+
data, analysis settings and results.
22+
- [:material-puzzle: Sample Model](model.md) - Load an existing
2223
**crystallographic model** in CIF format or define a new one from scratch.
2324
- [:material-microscope: Experiment](experiment.md) - Import
24-
**experimental diffraction data** and configure **instrumental parameters**.
25+
**experimental diffraction data** and configure **instrumental** and other
26+
relevant parameters.
2527
- [:material-calculator: Analysis](analysis.md) - Calculate the
2628
**diffraction pattern** and optimize the structural model by refining
2729
parameters to match experimental measurements.
2830
- [:material-clipboard-text: Summary](summary.md) - Generate a
29-
**detailed report** summarizing the results of the analysis, including
30-
refined parameters and visualizations.
31+
**report** summarizing the results of the analysis, including
32+
refined parameters.
3133

3234
Each step is described in detail in its respective section, guiding users
3335
through the **entire diffraction data analysis workflow** in

docs/usage/workflow-steps/model.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ the **experimental data** to analyze and refine the structural parameters.
1111
EasyDiffraction allows you to:
1212

1313
- **Manually define** a new model by specifying crystallographic parameters.
14-
- **Load an existing model** from a **CIF file**.
14+
- **Load an existing model** from a file (**CIF** format).
1515

1616
Below, you will find instructions on how to define and manage crystallographic
1717
models in EasyDiffraction. It is assumed that you have already created a

docs/usage/workflow-steps/project.md

+15-17
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ The **Project** serves as a container for all data and metadata associated with
88
a diffraction experiment. It acts as the top-level entity in EasyDiffraction,
99
ensuring structured organization and easy access to relevant information. Each
1010
project can contain multiple **experimental datasets**, with each dataset
11-
containing contribution from multiple **physical models**.
11+
containing contribution from multiple **sample models**.
1212

1313
EasyDiffraction allows you to:
1414

1515
- **Manually create** a new project.
16-
- **Load an existing project** from **CIF files**.
16+
- **Load an existing project** (**CIF** format).
1717

1818
Below, you will find instructions on how to set project in EasyDiffraction.
1919
It is assumed that you have already imported the `easydiffraction` package, as
20-
described in the [Getting started](../getting-started.md) section.
20+
described in the [Getting Started](../getting-started.md) section.
2121

2222
## Creating a Project Manually
2323

24-
You can manually create a new project and specify its **title** and
25-
**description**.
24+
You can manually create a new project and specify its short **name**, **title**
25+
and **description**. All these parameters are optional.
2626

2727
```python
2828
# Create a new project
@@ -41,7 +41,7 @@ HRPT diffractometer (PSI).'''
4141
Saving the initial project requires specifying the directory path:
4242

4343
```python
44-
project.save_as(dir_path='lbco_hrpt', temporary=True)
44+
project.save_as(dir_path='lbco_hrpt')
4545
```
4646

4747
If working in the interactive mode, you can also save the project after every
@@ -67,22 +67,19 @@ project.load_from_file('data/lbco_hrpt.cif')
6767
The example below illustrates a typical **project structure** for a
6868
**constant-wavelength powder neutron diffraction** experiment:
6969

70-
Each file within the **Project** directory plays a crucial role in defining,
71-
analyzing, and refining diffraction experiments.
72-
7370
<!-- prettier-ignore-start -->
7471

7572
<div class="cif">
7673
<pre>
7774
📁 <span class="red"><b>La0.5Ba0.5CoO3</b></span> - Project directory.
7875
├── 📄 <span class="orange"><b>project.cif</b></span> - Main project description file.
79-
├── 📁 models - Folder with individual crystallographic phases.
80-
│ ├── 📄 <span class="orange"><b>lbco.cif</b></span> - File with La0.5Ba0.5CoO3 phase parameters.
76+
├── 📁 sample_models - Folder with sample models (crystallographic structures).
77+
│ ├── 📄 <span class="orange"><b>lbco.cif</b></span> - File with La0.5Ba0.5CoO3 structure parameters.
8178
│ └── ...
8279
├── 📁 experiments - Folder with instrumental parameters and measured data.
83-
│ ├── 📄 <span class="orange"><b>hrpt.cif</b></span> - Measured data from HRPT@PSI & instrumental parameters.
80+
│ ├── 📄 <span class="orange"><b>hrpt.cif</b></span> - Instrumental parameters and measured data from HRPT@PSI.
8481
│ └── ...
85-
├── 📄 <span class="orange"><b>analysis.cif</b></span> - Settings for data analysis.
82+
├── 📄 <span class="orange"><b>analysis.cif</b></span> - Settings for data analysis (calculator, minimizer, etc.).
8683
└── 📁 summary
8784
└── 📄 report.cif - Summary report after structure refinement.
8885
</pre>
@@ -96,19 +93,20 @@ Below is a detailed breakdown of the content within each project file.
9693

9794
### <span class="orange">project.cif</span>
9895

99-
This file provides an overview of the project, linking relevant **models** and
100-
**experimental datasets**.
96+
This file provides an overview of the project, including **sample models** and
97+
**experiments** associated with the project.
10198

10299
<!-- prettier-ignore-start -->
103100

104101
<div class="cif">
105102
<pre>
106103
data_<span class="red"><b>La0.5Ba0.5CoO3</b></span>
107104

105+
<span class="blue"><b>_project</b>.title</span> "La0.5Ba0.5CoO3 from neutron diffraction at HRPT@PSI"
108106
<span class="blue"><b>_project</b>.description</span> "neutrons, powder, constant wavelength, HRPT@PSI"
109107

110108
loop_
111-
<span class="green"><b>_model</b>.cif_file_name</span>
109+
<span class="green"><b>_sample_model</b>.cif_file_name</span>
112110
lbco.cif
113111

114112
loop_
@@ -119,7 +117,7 @@ hrpt.cif
119117

120118
<!-- prettier-ignore-end -->
121119

122-
### models / <span class="orange">lbco.cif</span>
120+
### sample_models / <span class="orange">lbco.cif</span>
123121

124122
This file contains crystallographic information, including **space group**,
125123
**unit cell parameters**, and **atomic positions**.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# %% [markdown]
2+
# # Structure Refinement: LBCO, HRPT
3+
#
4+
# This minimalistic example is designed to be as compact as possible for a
5+
# Rietveld refinement of a crystal structure using constant-wavelength neutron
6+
# 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 essential
11+
# 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 refinement
16+
# might look like in code. For a more detailed explanation of the code, please
17+
# refer to the other tutorials.
18+
19+
# %%
20+
import easydiffraction as ed
21+
22+
# %% [markdown]
23+
# ## Step 1: Project
24+
25+
# %%
26+
project = ed.Project()
27+
28+
# %%
29+
project.plotter.engine = 'plotly'
30+
31+
# %% [markdown]
32+
# ## Step 2: Sample Model
33+
34+
# %%
35+
project.sample_models.add(name='lbco')
36+
37+
# %%
38+
project.sample_models['lbco'].space_group.name_h_m = 'P m -3 m'
39+
project.sample_models['lbco'].space_group.it_coordinate_system_code = '1'
40+
41+
# %%
42+
project.sample_models['lbco'].cell.length_a = 3.88
43+
44+
# %%
45+
project.sample_models['lbco'].atom_sites.add(label='La',
46+
type_symbol='La',
47+
fract_x=0,
48+
fract_y=0,
49+
fract_z=0,
50+
wyckoff_letter='a',
51+
b_iso=0.5,
52+
occupancy=0.5)
53+
project.sample_models['lbco'].atom_sites.add(label='Ba',
54+
type_symbol='Ba',
55+
fract_x=0,
56+
fract_y=0,
57+
fract_z=0,
58+
wyckoff_letter='a',
59+
b_iso=0.5,
60+
occupancy=0.5)
61+
project.sample_models['lbco'].atom_sites.add(label='Co',
62+
type_symbol='Co',
63+
fract_x=0.5,
64+
fract_y=0.5,
65+
fract_z=0.5,
66+
wyckoff_letter='b',
67+
b_iso=0.5)
68+
project.sample_models['lbco'].atom_sites.add(label='O',
69+
type_symbol='O',
70+
fract_x=0,
71+
fract_y=0.5,
72+
fract_z=0.5,
73+
wyckoff_letter='c',
74+
b_iso=0.5)
75+
76+
# %% [markdown]
77+
# ## Step 3: Experiment
78+
79+
# %%
80+
ed.download_from_repository('hrpt_lbco.xye',
81+
branch='docs',
82+
destination='data')
83+
84+
# %%
85+
project.experiments.add(name='hrpt',
86+
sample_form='powder',
87+
beam_mode='constant wavelength',
88+
radiation_probe='neutron',
89+
data_path='data/hrpt_lbco.xye')
90+
91+
# %%
92+
project.experiments['hrpt'].instrument.setup_wavelength = 1.494
93+
project.experiments['hrpt'].instrument.calib_twotheta_offset = 0.6
94+
95+
# %%
96+
project.experiments['hrpt'].peak.broad_gauss_u = 0.1
97+
project.experiments['hrpt'].peak.broad_gauss_v = -0.1
98+
project.experiments['hrpt'].peak.broad_gauss_w = 0.1
99+
project.experiments['hrpt'].peak.broad_lorentz_x = 0
100+
project.experiments['hrpt'].peak.broad_lorentz_y = 0.1
101+
102+
# %%
103+
project.experiments['hrpt'].background.add(x=10, y=170)
104+
project.experiments['hrpt'].background.add(x=30, y=170)
105+
project.experiments['hrpt'].background.add(x=50, y=170)
106+
project.experiments['hrpt'].background.add(x=110, y=170)
107+
project.experiments['hrpt'].background.add(x=165, y=170)
108+
109+
# %%
110+
project.experiments['hrpt'].linked_phases.add(id='lbco', scale=10.0)
111+
112+
# %% [markdown]
113+
# ## Step 4: Analysis
114+
115+
# %%
116+
project.sample_models['lbco'].cell.length_a.free = True
117+
118+
project.sample_models['lbco'].atom_sites['La'].b_iso.free = True
119+
project.sample_models['lbco'].atom_sites['Ba'].b_iso.free = True
120+
project.sample_models['lbco'].atom_sites['Co'].b_iso.free = True
121+
project.sample_models['lbco'].atom_sites['O'].b_iso.free = True
122+
123+
# %%
124+
project.experiments['hrpt'].linked_phases['lbco'].scale.free = True
125+
126+
project.experiments['hrpt'].instrument.calib_twotheta_offset.free = True
127+
128+
project.experiments['hrpt'].background['10'].y.free = True
129+
project.experiments['hrpt'].background['30'].y.free = True
130+
project.experiments['hrpt'].background['50'].y.free = True
131+
project.experiments['hrpt'].background['110'].y.free = True
132+
project.experiments['hrpt'].background['165'].y.free = True
133+
134+
project.experiments['hrpt'].peak.broad_gauss_u.free = True
135+
project.experiments['hrpt'].peak.broad_gauss_v.free = True
136+
project.experiments['hrpt'].peak.broad_gauss_w.free = True
137+
project.experiments['hrpt'].peak.broad_lorentz_y.free = True
138+
139+
# %%
140+
project.analysis.fit()
141+
142+
# %%
143+
project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)

0 commit comments

Comments
 (0)