Skip to content

Commit 6a52ea9

Browse files
Add single-crystal diffraction support via cryspy (#127)
* Implement the extinction category * Implement the linked crystal category * Add base class for single crystal experiments * Clarify sy handling; move background property * Update BraggScExperiment class * Add SC Bragg reflection data and linked crystal * Add single-crystal Bragg CW data mapping * Remove unused linked crystal validator * Add minimizer flag to calculator API * Remove lru_cache; update data index hash * Add single-crystal Tb2TiO7 HEiDi tutorial * Add TODO about sy handling when loading CIF * Add single-crystal support to Cryspy calculator * Add stol propagation and d-spacing for SC data * Add d-spacing computation and fix plotting checks * Update SC tutorial * Use Cryspy-calculated intensity output * Update SC tutorial * Update data index checksum * Add new SC-TOF tutorial * Add TOF single-crystal support via Cryspy * Apply formatting * Cache tutorials index; adjust Bragg SC test * Add single-crystal F2 meas-vs-calc plot * Update SG tutorials * Add Single Crystal Diffraction section to docs * Update SC tutorial * Lower coverage threshold to 60% * Clarify Miller index and intensity descriptions * Add TODOs and fix docstring * Remove ED tutorial data; tidy pyproject comments * Remove kwargs from Refln init; add return type * Add units to extinction parameters * Add single-crystal neutron fitting tests * Reduce Ruff excludes; lint/format tests * Simplify single-crystal category initializers * Rename refln_id to id per coreCIF * Add CW/TOF SC ASCII import with wavelength * Rename plot_sg to plot_sc for single-crystal * Add single-crystal scatter comparison plotting * Extract scatter trace creation to helper * Rename traces for powder and single-crystal * Use Plotly autorange; drop fixed axis limits * Extract Plotly config to helper * Centralize Plotly figure display logic * Refactor Plotly figure creation and formatting * Draw identity line in paper coordinates * Add reusable Plotly layout helper * Extract diagonal reference line helper * Rename plot methods for powder/single-crystal * Reformat Plotly plotter for readability * Clarify diffraction plotter docstrings * Add single-crystal plotting tests * Remove deprecated plot alias; update tests * Add sin(theta)/lambda to d-spacing conversion * Update SC data API; compute d-spacing via util * Fix reflection index attribute names * Add single-crystal support to plotter base * Unify powder/SC plotting with axis auto-detect * Unify plotting API; replace d_spacing with x * Rename all_x to unfiltered_x * Rename meas/calc to intensity_*; add axis aliases * Rename TotalData module to total_pd * Update tests for sample-form and intensity API * Log read/validation errors; import numpy globally * Move instrument and extinction to SC base * Split Bragg SC into CWL/TOF; update factory * Refactor single-crystal instrument support * Move instrument init to BraggPdExperiment * Update tests for Pd/Sc instrument classes * Add scattering-type aware x-axis defaults * Increase CIF float precision to 8 decimals * Update pixi lock * Update docs code examples for style consistency * Pin scipp for ARM macOS; use editable local pkg * Refactor plotting; unify axis and data prep * Add macOS 14.0 minimum version requirement * Update plot_meas_vs_calc calls to use 'x' parameter for d_spacing
1 parent 90aeca0 commit 6a52ea9

66 files changed

Lines changed: 7200 additions & 3861 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/mkdocs.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ nav:
7373
- LBCO quick code: tutorials/ed-2.ipynb
7474
- LBCO basic: tutorials/ed-3.ipynb
7575
- PbSO4 advanced: tutorials/ed-4.ipynb
76-
- Standard Diffraction:
76+
- Powder Diffraction:
7777
- Co2SiO4 pd-neut-cwl: tutorials/ed-5.ipynb
7878
- HS pd-neut-cwl: tutorials/ed-6.ipynb
7979
- Si pd-neut-tof: tutorials/ed-7.ipynb
8080
- NCAF pd-neut-tof: tutorials/ed-8.ipynb
8181
- LBCO+Si McStas: tutorials/ed-9.ipynb
82+
- Single Crystal Diffraction:
83+
- Tb2TiO7 sg-neut-cwl: tutorials/ed-14.ipynb
84+
- Taurine sg-neut-tof: tutorials/ed-15.ipynb
8285
- Pair Distribution Function:
8386
- Ni pd-neut-cwl: tutorials/ed-10.ipynb
8487
- Si pd-neut-tof: tutorials/ed-11.ipynb

docs/tutorials/index.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The tutorials are organized into the following categories.
4242
refinement of the PbSO4 crystal structure based on the joint fit of both X-ray
4343
and neutron diffraction data.
4444

45-
## Standard Diffraction
45+
## Powder Diffraction
4646

4747
- [Co2SiO4 `pd-neut-cwl`](ed-5.ipynb) – Demonstrates a Rietveld refinement of
4848
the Co2SiO4 crystal structure using constant wavelength neutron powder
@@ -61,6 +61,15 @@ The tutorials are organized into the following categories.
6161
secondary phase using time-of-flight neutron powder diffraction data simulated
6262
with McStas.
6363

64+
## Single Crystal Diffraction
65+
66+
- [Tb2TiO7 `sg-neut-cwl`](ed-14.ipynb) – Demonstrates structure refinement of
67+
Tb2TiO7 using constant wavelength neutron single crystal diffraction data from
68+
HEiDi at FRM II.
69+
- [Taurine `sg-neut-tof`](ed-15.ipynb) – Demonstrates structure refinement of
70+
Taurine using time-of-flight neutron single crystal diffraction data from
71+
SENJU at J-PARC.
72+
6473
## Pair Distribution Function (PDF)
6574

6675
- [Ni `pd-neut-cwl`](ed-10.ipynb) – Demonstrates a PDF analysis of Ni using data

docs/user-guide/analysis-workflow/analysis.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,21 @@ An example of setting aliases for parameters in a sample model:
271271
# Set aliases for the atomic displacement parameters
272272
project.analysis.aliases.add(
273273
label='biso_La',
274-
param_uid=project.sample_models['lbco'].atom_sites['La'].b_iso.uid
274+
param_uid=project.sample_models['lbco'].atom_sites['La'].b_iso.uid,
275275
)
276276
project.analysis.aliases.add(
277277
label='biso_Ba',
278-
param_uid=project.sample_models['lbco'].atom_sites['Ba'].b_iso.uid
278+
param_uid=project.sample_models['lbco'].atom_sites['Ba'].b_iso.uid,
279279
)
280280

281281
# Set aliases for the occupancies of the atom sites
282282
project.analysis.aliases.add(
283283
label='occ_La',
284-
param_uid=project.sample_models['lbco'].atom_sites['La'].occupancy.uid
284+
param_uid=project.sample_models['lbco'].atom_sites['La'].occupancy.uid,
285285
)
286286
project.analysis.aliases.add(
287287
label='occ_Ba',
288-
param_uid=project.sample_models['lbco'].atom_sites['Ba'].occupancy.uid
288+
param_uid=project.sample_models['lbco'].atom_sites['Ba'].occupancy.uid,
289289
)
290290
```
291291

@@ -302,12 +302,12 @@ An example of setting constraints for the aliases defined above:
302302
```python
303303
project.analysis.constraints.add(
304304
lhs_alias='biso_Ba',
305-
rhs_expr='biso_La'
305+
rhs_expr='biso_La',
306306
)
307307

308308
project.analysis.constraints.add(
309309
lhs_alias='occ_Ba',
310-
rhs_expr='1 - occ_La'
310+
rhs_expr='1 - occ_La',
311311
)
312312
```
313313

docs/user-guide/analysis-workflow/experiment.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,24 @@ explicitly defined:
105105

106106
```python
107107
# Add an experiment with default parameters, based on the specified type.
108-
project.experiments.add_from_data_path(name='hrpt',
109-
data_path='data/hrpt_lbco.xye',
110-
sample_form='powder',
111-
beam_mode='constant wavelength',
112-
radiation_probe='neutron',
113-
scattering_type='bragg')
108+
project.experiments.add_from_data_path(
109+
name='hrpt',
110+
data_path='data/hrpt_lbco.xye',
111+
sample_form='powder',
112+
beam_mode='constant wavelength',
113+
radiation_probe='neutron',
114+
scattering_type='bragg',
115+
)
114116
```
115117

116118
To add an experiment of default type, you can simply do:
117119

118120
```python
119121
# Add an experiment of default type
120-
project.experiments.add_from_data_path(name='hrpt',
121-
data_path='data/hrpt_lbco.xye')
122+
project.experiments.add_from_data_path(
123+
name='hrpt',
124+
data_path='data/hrpt_lbco.xye',
125+
)
122126
```
123127

124128
If you do not have measured data for fitting and only want to view the simulated
@@ -127,10 +131,12 @@ pattern, you can define an experiment without measured data using the
127131

128132
```python
129133
# Add an experiment without measured data
130-
project.experiments.add_without_data(name='hrpt',
131-
sample_form='powder',
132-
beam_mode='constant wavelength',
133-
radiation_probe='x-ray')
134+
project.experiments.add_without_data(
135+
name='hrpt',
136+
sample_form='powder',
137+
beam_mode='constant wavelength',
138+
radiation_probe='x-ray',
139+
)
134140
```
135141

136142
Finally, you can also add an experiment by passing the experiment object
@@ -139,11 +145,14 @@ directly using the `add` method:
139145
```python
140146
# Add an experiment by passing the experiment object directly
141147
from easydiffraction import Experiment
142-
experiment = Experiment(name='hrpt',
143-
sample_form='powder',
144-
beam_mode='constant wavelength',
145-
radiation_probe='neutron',
146-
scattering_type='bragg')
148+
149+
experiment = Experiment(
150+
name='hrpt',
151+
sample_form='powder',
152+
beam_mode='constant wavelength',
153+
radiation_probe='neutron',
154+
scattering_type='bragg',
155+
)
147156
project.experiments.add(experiment)
148157
```
149158

docs/user-guide/analysis-workflow/model.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ project.sample_models['nacl'].atom_sites.append(
104104
fract_y=0,
105105
fract_z=0,
106106
occupancy=1,
107-
b_iso_or_equiv=0.5
107+
b_iso_or_equiv=0.5,
108108
)
109109
project.sample_models['nacl'].atom_sites.append(
110110
label='Cl',
@@ -113,7 +113,7 @@ project.sample_models['nacl'].atom_sites.append(
113113
fract_y=0,
114114
fract_z=0.5,
115115
occupancy=1,
116-
b_iso_or_equiv=0.5
116+
b_iso_or_equiv=0.5,
117117
)
118118
```
119119

docs/user-guide/analysis-workflow/project.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ project = ed.Project(name='lbco_hrpt')
3030

3131
# Define project info
3232
project.info.title = 'La0.5Ba0.5CoO3 from neutron diffraction at HRPT@PSI'
33-
project.info.description = '''This project demonstrates a standard refinement
33+
project.info.description = """This project demonstrates a standard refinement
3434
of La0.5Ba0.5CoO3, which crystallizes in a perovskite-type structure, using
3535
neutron powder diffraction data collected in constant wavelength mode at the
36-
HRPT diffractometer (PSI).'''
36+
HRPT diffractometer (PSI)."""
3737
```
3838

3939
## Saving a Project

docs/user-guide/first-steps.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ example, you can import the `Project`, `SampleModel`, `Experiment` classes and
4141
`download_from_repository` method like this:
4242

4343
```python
44-
from easydiffraction import (
45-
Project,
46-
SampleModel,
47-
Experiment,
48-
download_from_repository
49-
)
44+
from easydiffraction import Project
45+
from easydiffraction import SampleModel
46+
from easydiffraction import Experiment
47+
from easydiffraction import download_from_repository
5048
```
5149

5250
This enables you to use these classes and methods directly without the package
@@ -73,9 +71,11 @@ For example, you can download a sample data file like this:
7371
```python
7472
import easydiffraction as ed
7573

76-
ed.download_from_repository('hrpt_lbco.xye',
77-
branch='docs',
78-
destination='data')
74+
ed.download_from_repository(
75+
'hrpt_lbco.xye',
76+
branch='docs',
77+
destination='data',
78+
)
7979
```
8080

8181
This command will download the `hrpt_lbco.xye` file from the `docs` branch of

0 commit comments

Comments
 (0)