{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:40:36.509441Z", "iopub.status.busy": "2026-06-30T22:40:36.509234Z", "iopub.status.idle": "2026-06-30T22:40:36.515057Z", "shell.execute_reply": "2026-06-30T22:40:36.513859Z" }, "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 — doublet\n", "\n", "Verifies Cu Kα₁/Kα₂ doublet handling on the LiF pseudo-Voigt\n", "reference.\n", "\n", "**Note:** the Kα₁/Kα₂ doublet is produced by an EasyDiffraction-level\n", "implementation on top of the calculation engine — the engine is run\n", "twice (at λ₁ and λ₂) and the two patterns are summed by the intensity\n", "ratio — because neither cryspy nor the CFL-based crysfml API computes\n", "the doublet natively.\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:40:36.516987Z", "iopub.status.busy": "2026-06-30T22:40:36.516778Z", "iopub.status.idle": "2026-06-30T22:40:40.707421Z", "shell.execute_reply": "2026-06-30T22:40:40.705335Z" } }, "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:40:40.710054Z", "iopub.status.busy": "2026-06-30T22:40:40.709666Z", "iopub.status.idle": "2026-06-30T22:40:41.050238Z", "shell.execute_reply": "2026-06-30T22:40:41.048723Z" } }, "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:40:41.052738Z", "iopub.status.busy": "2026-06-30T22:40:41.052508Z", "iopub.status.idle": "2026-06-30T22:40:41.060801Z", "shell.execute_reply": "2026-06-30T22:40:41.060087Z" } }, "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:40:41.062364Z", "iopub.status.busy": "2026-06-30T22:40:41.062214Z", "iopub.status.idle": "2026-06-30T22:40:41.071724Z", "shell.execute_reply": "2026-06-30T22:40:41.070772Z" } }, "outputs": [], "source": [ "FULLPROF_PROJECT_DIR = 'pd-xray-cwl_lif'\n", "FULLPROF_PRF_FILE = 'lif_doublet_unpolarized.prf'\n", "FULLPROF_SUM_FILE = 'lif_doublet_unpolarized.sum'\n", "FULLPROF_BAC_FILE = 'lif_doublet_unpolarized.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 = 1.540560 # FullProf Lambda1\n", "FULLPROF_WAVELENGTH_2 = 1.544400 # FullProf Lambda2\n", "FULLPROF_WAVELENGTH_2_TO_1_RATIO = 0.50000 # FullProf Ratio\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", "\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:40:41.073243Z", "iopub.status.busy": "2026-06-30T22:40:41.073051Z", "iopub.status.idle": "2026-06-30T22:40:42.316691Z", "shell.execute_reply": "2026-06-30T22:40:42.315909Z" } }, "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" ] } ], "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_1\n", "experiment.instrument.setup_wavelength_2 = FULLPROF_WAVELENGTH_2\n", "experiment.instrument.setup_wavelength_2_to_1_ratio = FULLPROF_WAVELENGTH_2_TO_1_RATIO\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.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:40:42.318974Z", "iopub.status.busy": "2026-06-30T22:40:42.318739Z", "iopub.status.idle": "2026-06-30T22:40:44.025431Z", "shell.execute_reply": "2026-06-30T22:40:44.024878Z" } }, "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": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "experiment.calculator.type = 'cryspy'\n", "\n", "project.analysis.calculate()\n", "calc_ed_cryspy = experiment.data.intensity_calc\n", "LABEL_ED_CRYSPY = verify.engine_label('cryspy')\n", "\n", "project.display.pattern_comparison(\n", " 'lif',\n", " reference=calc_fullprof,\n", " candidate=calc_ed_cryspy,\n", " reference_label=FULLPROF_LABEL,\n", " candidate_label=LABEL_ED_CRYSPY,\n", ")" ] }, { "cell_type": "markdown", "id": "13", "metadata": {}, "source": [ "## Agreement check" ] }, { "cell_type": "code", "execution_count": 8, "id": "14", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:40:44.033903Z", "iopub.status.busy": "2026-06-30T22:40:44.033648Z", "iopub.status.idle": "2026-06-30T22:40:44.042848Z", "shell.execute_reply": "2026-06-30T22:40:44.041868Z" } }, "outputs": [ { "data": { "text/html": [ "
ComparisonMetricExpectedActualOK
1edi 0.19.1 (cryspy 0.12.1) vs FullProf 7.95Profile diff (%)< 2.50.21
2Max deviation (%)< 60.19
3Area ratio0.99 to 1.011.0003
4Shape correlation> 0.9991.0000
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "True" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# cryspy matches FullProf, so it is gated as a regression test.\n", "verify.assert_patterns_agree(\n", " [\n", " (f'{LABEL_ED_CRYSPY} vs {FULLPROF_LABEL}', calc_fullprof, calc_ed_cryspy),\n", " ],\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "15", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.5" } }, "nbformat": 4, "nbformat_minor": 5 }