{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:32.369372Z", "iopub.status.busy": "2026-06-30T22:28:32.369178Z", "iopub.status.idle": "2026-06-30T22:28:32.373518Z", "shell.execute_reply": "2026-06-30T22:28:32.372701Z" }, "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.19.1" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "# LiF — powder X-ray CW — absorption\n", "\n", "Verifies the Debye-Scherrer cylindrical absorption correction on the\n", "same single-wavelength LiF reference.\n", "\n", "**Refinement:** none — every parameter is taken from the FullProf\n", "reference; only the calculated patterns are compared." ] }, { "cell_type": "code", "execution_count": 2, "id": "2", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:32.375312Z", "iopub.status.busy": "2026-06-30T22:28:32.375152Z", "iopub.status.idle": "2026-06-30T22:28:35.150249Z", "shell.execute_reply": "2026-06-30T22:28:35.149376Z" } }, "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-06-30T22:28:35.152384Z", "iopub.status.busy": "2026-06-30T22:28:35.151997Z", "iopub.status.idle": "2026-06-30T22:28:35.368502Z", "shell.execute_reply": "2026-06-30T22:28:35.367534Z" } }, "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-06-30T22:28:35.370305Z", "iopub.status.busy": "2026-06-30T22:28:35.370119Z", "iopub.status.idle": "2026-06-30T22:28:35.376532Z", "shell.execute_reply": "2026-06-30T22:28:35.375792Z" } }, "outputs": [], "source": [ "structure = StructureFactory.from_scratch(name='lif')\n", "\n", "structure.space_group.name_h_m = 'F m -3 m' # FullProf Space group symbol\n", "structure.cell.length_a = 4.026700 # FullProf a\n", "\n", "structure.atom_sites.create(\n", " id='Li1', # FullProf Atom\n", " type_symbol='Li', # FullProf Typ\n", " fract_x=0.0, # FullProf X\n", " fract_y=0.0, # FullProf Y\n", " fract_z=0.0, # FullProf Z\n", " adp_type='Biso', # FullProf Biso\n", " adp_iso=1.20000, # FullProf Biso\n", ")\n", "structure.atom_sites.create(\n", " id='F1', # FullProf Atom\n", " type_symbol='F', # FullProf Typ\n", " fract_x=0.5, # FullProf X\n", " fract_y=0.5, # FullProf Y\n", " fract_z=0.5, # FullProf Z\n", " adp_type='Biso', # FullProf Biso\n", " adp_iso=0.80000, # 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-06-30T22:28:35.378209Z", "iopub.status.busy": "2026-06-30T22:28:35.377978Z", "iopub.status.idle": "2026-06-30T22:28:35.392485Z", "shell.execute_reply": "2026-06-30T22:28:35.391601Z" } }, "outputs": [], "source": [ "FULLPROF_PROJECT_DIR = 'pd-xray-cwl_lif'\n", "FULLPROF_PRF_FILE = 'lif_single_absorption.prf'\n", "FULLPROF_SUM_FILE = 'lif_single_absorption.sum'\n", "FULLPROF_BAC_FILE = 'lif_single_absorption.bac'\n", "FULLPROF_LABEL = verify.fullprof_label(FULLPROF_PROJECT_DIR, FULLPROF_SUM_FILE)\n", "\n", "FULLPROF_ZERO = 0.0 # FullProf Zero\n", "FULLPROF_SCALE = 0.01 # FullProf Scale\n", "FULLPROF_WAVELENGTH = 1.540560 # FullProf Lambda1\n", "FULLPROF_U = 0.048457 # FullProf U\n", "FULLPROF_V = -0.083053 # FullProf V\n", "FULLPROF_W = 0.040000 # FullProf W\n", "FULLPROF_X = 0.0 # FullProf X\n", "FULLPROF_Y = 0.049268 # FullProf Y\n", "FULLPROF_WDT = 48.0 # FullProf Wdt\n", "FULLPROF_MU_R = 0.9 # FullProf muR\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-06-30T22:28:35.394130Z", "iopub.status.busy": "2026-06-30T22:28:35.393957Z", "iopub.status.idle": "2026-06-30T22:28:36.271400Z", "shell.execute_reply": "2026-06-30T22:28:36.270112Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mPeak profile type for experiment \u001b[0m\u001b[32m'lif'\u001b[0m\u001b[1;36m changed to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "pseudo-voigt\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mAbsorption type changed to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "cylinder-hewat\n" ] } ], "source": [ "experiment = ExperimentFactory.from_scratch(\n", " name='lif',\n", " sample_form='powder',\n", " beam_mode='constant wavelength',\n", " radiation_probe='xray',\n", " scattering_type='bragg',\n", ")\n", "verify.set_reference_as_measured(experiment, x, calc_fullprof)\n", "\n", "experiment.linked_structures.create(structure_id='lif', scale=FULLPROF_SCALE)\n", "\n", "experiment.instrument.setup_wavelength = FULLPROF_WAVELENGTH\n", "experiment.instrument.calib_twotheta_offset = FULLPROF_ZERO\n", "\n", "experiment.peak.type = 'pseudo-voigt'\n", "experiment.peak.broad_gauss_u = FULLPROF_U\n", "experiment.peak.broad_gauss_v = FULLPROF_V\n", "experiment.peak.broad_gauss_w = FULLPROF_W\n", "experiment.peak.broad_lorentz_x = FULLPROF_X\n", "experiment.peak.broad_lorentz_y = FULLPROF_Y\n", "\n", "experiment.absorption.type = 'cylinder-hewat'\n", "experiment.absorption.mu_r = FULLPROF_MU_R\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-06-30T22:28:36.272984Z", "iopub.status.busy": "2026-06-30T22:28:36.272831Z", "iopub.status.idle": "2026-06-30T22:28:37.297268Z", "shell.execute_reply": "2026-06-30T22:28:37.296240Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mCalculator for experiment \u001b[0m\u001b[32m'lif'\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.19.1 (cryspy 0.12.1) vs FullProf 7.95 | Profile diff (%) | < 2.5 | 0.23 | ✅ |
| 2 | Max deviation (%) | < 6 | 0.18 | ✅ | |
| 3 | Area ratio | 0.99 to 1.01 | 1.0002 | ✅ | |
| 4 | Shape correlation | > 0.999 | 1.0000 | ✅ |