{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:29:43.512845Z", "iopub.status.busy": "2026-08-18T18:29:43.512656Z", "iopub.status.idle": "2026-08-18T18:29:43.517032Z", "shell.execute_reply": "2026-08-18T18:29:43.516168Z" }, "tags": [ "hide-in-docs" ] }, "outputs": [], "source": [ "# Check whether easydiffraction is installed; install it if needed.\n", "# Required for remote environments such as Google Colab.\n", "import importlib.util\n", "\n", "if importlib.util.find_spec('easydiffraction') is None:\n", " %pip install easydiffraction==0.20.1" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "# Si — powder neutron TOF — Jorgensen-Von Dreele + size/strain\n", "\n", "Verifies the isotropic microstructural size/strain broadening on top of\n", "the Jorgensen-Von Dreele pseudo-Voigt profile for a silicon\n", "time-of-flight powder pattern.\n", "\n", "**Reference:** the FullProf scale and all other parameters are\n", "taken from the FullProf reference." ] }, { "cell_type": "code", "execution_count": 2, "id": "2", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:29:43.518474Z", "iopub.status.busy": "2026-08-18T18:29:43.518296Z", "iopub.status.idle": "2026-08-18T18:29:46.322420Z", "shell.execute_reply": "2026-08-18T18:29:46.321645Z" } }, "outputs": [], "source": [ "import easydiffraction as edi\n", "from easydiffraction import ExperimentFactory\n", "from easydiffraction import StructureFactory\n", "from easydiffraction.analysis import verification as verify" ] }, { "cell_type": "markdown", "id": "3", "metadata": {}, "source": [ "## Build the project" ] }, { "cell_type": "code", "execution_count": 3, "id": "4", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:29:46.324904Z", "iopub.status.busy": "2026-08-18T18:29:46.324554Z", "iopub.status.idle": "2026-08-18T18:29:46.626788Z", "shell.execute_reply": "2026-08-18T18:29:46.626022Z" } }, "outputs": [], "source": [ "project = edi.Project()" ] }, { "cell_type": "markdown", "id": "5", "metadata": {}, "source": [ "## Define the structure" ] }, { "cell_type": "code", "execution_count": 4, "id": "6", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:29:46.628977Z", "iopub.status.busy": "2026-08-18T18:29:46.628803Z", "iopub.status.idle": "2026-08-18T18:29:46.633855Z", "shell.execute_reply": "2026-08-18T18:29:46.633086Z" } }, "outputs": [], "source": [ "structure = StructureFactory.from_scratch(name='si')\n", "\n", "structure.space_group.name_h_m = 'F d -3 m' # FullProf Space group symbol\n", "structure.space_group.coord_system_code = '2'\n", "\n", "structure.cell.length_a = 5.431342 # FullProf a\n", "\n", "structure.atom_sites.create(\n", " id='Si', # FullProf Atom\n", " type_symbol='Si', # FullProf Typ\n", " fract_x=0.125, # FullProf X\n", " fract_y=0.125, # FullProf Y\n", " fract_z=0.125, # FullProf Z\n", " adp_type='Biso', # FullProf Biso\n", " adp_iso=0.52448, # FullProf Biso\n", ")\n", "\n", "project.structures.add(structure)" ] }, { "cell_type": "markdown", "id": "7", "metadata": {}, "source": [ "## Load the FullProf reference" ] }, { "cell_type": "code", "execution_count": 5, "id": "8", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:29:46.635407Z", "iopub.status.busy": "2026-08-18T18:29:46.635254Z", "iopub.status.idle": "2026-08-18T18:29:46.644711Z", "shell.execute_reply": "2026-08-18T18:29:46.643901Z" } }, "outputs": [], "source": [ "FULLPROF_PROJECT_DIR = 'pd-neut-tof_si_jorgensen-von-dreele-size-strain'\n", "FULLPROF_PRF_FILE = 'arg_si.prf'\n", "FULLPROF_SUM_FILE = 'arg_si.sum'\n", "FULLPROF_BAC_FILE = 'arg_si.bac'\n", "FULLPROF_LABEL = verify.fullprof_label(FULLPROF_PROJECT_DIR, FULLPROF_SUM_FILE)\n", "\n", "FULLPROF_ZERO = -9.18766 # FullProf Zero\n", "FULLPROF_SCALE = 388.8488 # FullProf Scale\n", "FULLPROF_TWOTHETA_BANK = 144.845 # FullProf 2ThetaBank\n", "FULLPROF_DTT1 = 7476.91016 # FullProf Dtt1\n", "FULLPROF_DTT2 = -1.54 # FullProf Dtt2\n", "# FullProf Sigma-2/Sigma-1 carry the Gaussian size/strain; Gamma-2/Gamma-1\n", "# carry the Lorentzian size/strain (raw coefficients).\n", "FULLPROF_SIGMA_0 = 3.5544 # FullProf Sigma-0\n", "FULLPROF_SIGMA_1 = 38.0419 # FullProf Sigma-1 = base 33.0419 + G-strain 5\n", "FULLPROF_SIGMA_2 = 20.0 # FullProf Sigma-2 = G-size 20\n", "FULLPROF_GAMMA_0 = 0.0 # FullProf Gamma-0\n", "FULLPROF_GAMMA_1 = 3.5430 # FullProf Gamma-1 = base 2.5430 + L-strain 1\n", "FULLPROF_GAMMA_2 = 2.0 # FullProf Gamma-2 = L-size 2\n", "FULLPROF_ALPHA_0 = 0.0 # FullProf alph0\n", "FULLPROF_ALPHA_1 = 0.597100 # FullProf alph1\n", "FULLPROF_BETA_0 = 0.042210 # FullProf beta0\n", "FULLPROF_BETA_1 = 0.009460 # FullProf beta1\n", "FULLPROF_WDT = 8.2 # FullProf Wdt\n", "\n", "# cryspy raw size/strain coefficients (additive to the base sigma/gamma)\n", "SIZE_G = 20.0 # adds to sigma_2 (Gaussian size, d⁴)\n", "STRAIN_G = 5.0 # adds to sigma_1 (Gaussian strain, d²)\n", "SIZE_L = 2.0 # adds to gamma_2 (Lorentzian size, d²)\n", "STRAIN_L = 1.0 # adds to gamma_1 (Lorentzian strain, d)\n", "\n", "x, calc_fullprof = verify.load_fullprof_calc_profile(\n", " FULLPROF_PROJECT_DIR,\n", " FULLPROF_PRF_FILE,\n", " FULLPROF_BAC_FILE,\n", " FULLPROF_ZERO,\n", ")" ] }, { "cell_type": "markdown", "id": "9", "metadata": {}, "source": [ "## Create the experiment" ] }, { "cell_type": "code", "execution_count": 6, "id": "10", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:29:46.646318Z", "iopub.status.busy": "2026-08-18T18:29:46.646165Z", "iopub.status.idle": "2026-08-18T18:29:47.321740Z", "shell.execute_reply": "2026-08-18T18:29:47.320999Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "⚠️ Switching peak profile type adds these settings with defaults: \n", " • broad_lorentz_gamma_0=0.0 \n", " • broad_lorentz_gamma_1=0.0 \n", " • broad_lorentz_gamma_2=0.0 \n", " • broad_lorentz_size=0.0 \n", " • broad_lorentz_strain=0.0 \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mPeak profile type for experiment \u001b[0m\u001b[32m'si'\u001b[0m\u001b[1;36m changed to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "jorgensen-von-dreele\n" ] } ], "source": [ "experiment = ExperimentFactory.from_scratch(\n", " name='si',\n", " sample_form='powder',\n", " beam_mode='time-of-flight',\n", " radiation_probe='neutron',\n", " scattering_type='bragg',\n", ")\n", "verify.set_reference_as_measured(experiment, x, calc_fullprof)\n", "\n", "experiment.linked_structures.create(structure_id='si', scale=FULLPROF_SCALE)\n", "\n", "experiment.instrument.setup_twotheta_bank = FULLPROF_TWOTHETA_BANK\n", "experiment.instrument.calib_d_to_tof_offset = FULLPROF_ZERO\n", "experiment.instrument.calib_d_to_tof_linear = FULLPROF_DTT1\n", "experiment.instrument.calib_d_to_tof_quadratic = FULLPROF_DTT2\n", "\n", "experiment.peak.type = 'jorgensen-von-dreele'\n", "# Base broadening (size/strain are supplied separately as additive terms)\n", "experiment.peak.broad_gauss_sigma_0 = FULLPROF_SIGMA_0\n", "experiment.peak.broad_gauss_sigma_1 = FULLPROF_SIGMA_1 - STRAIN_G\n", "experiment.peak.broad_gauss_sigma_2 = FULLPROF_SIGMA_2 - SIZE_G\n", "experiment.peak.broad_lorentz_gamma_0 = FULLPROF_GAMMA_0\n", "experiment.peak.broad_lorentz_gamma_1 = FULLPROF_GAMMA_1 - STRAIN_L\n", "experiment.peak.broad_lorentz_gamma_2 = FULLPROF_GAMMA_2 - SIZE_L\n", "# Microstructural size/strain components\n", "experiment.peak.broad_gauss_size = SIZE_G\n", "experiment.peak.broad_gauss_strain = STRAIN_G\n", "experiment.peak.broad_lorentz_size = SIZE_L\n", "experiment.peak.broad_lorentz_strain = STRAIN_L\n", "experiment.peak.rise_alpha_0 = FULLPROF_ALPHA_0\n", "experiment.peak.rise_alpha_1 = FULLPROF_ALPHA_1\n", "experiment.peak.decay_beta_0 = FULLPROF_BETA_0\n", "experiment.peak.decay_beta_1 = FULLPROF_BETA_1\n", "\n", "experiment.excluded_regions.create(id='1', start=0, end=5000)\n", "experiment.excluded_regions.create(id='2', start=10000, end=100000)\n", "\n", "experiment.peak.cutoff_fwhm = FULLPROF_WDT\n", "\n", "project.experiments.add(experiment)" ] }, { "cell_type": "markdown", "id": "11", "metadata": {}, "source": [ "## edi-cryspy VS FullProf" ] }, { "cell_type": "code", "execution_count": 7, "id": "12", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:29:47.323625Z", "iopub.status.busy": "2026-08-18T18:29:47.323441Z", "iopub.status.idle": "2026-08-18T18:29:48.047620Z", "shell.execute_reply": "2026-08-18T18:29:48.046390Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mCalculator for experiment \u001b[0m\u001b[32m'si'\u001b[0m\u001b[1;36m already set to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "cryspy\n" ] }, { "data": { "text/html": [ "
| Comparison | Metric | Expected | Actual | OK | |
|---|---|---|---|---|---|
| 1 | edi 0.20.1 (cryspy 0.13.0) vs FullProf 8.40 | Profile diff (%) | < 2.5 | 0.38 | ✅ |
| 2 | Max deviation (%) | < 6 | 0.23 | ✅ | |
| 3 | Area ratio | 0.99 to 1.01 | 1.0041 | ✅ | |
| 4 | Shape correlation | > 0.999 | 1.0000 | ✅ |