{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:28.948148Z", "iopub.status.busy": "2026-06-30T22:36:28.947957Z", "iopub.status.idle": "2026-06-30T22:36:28.952646Z", "shell.execute_reply": "2026-06-30T22:36:28.951926Z" }, "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": [ "# PbSO₄ — powder neutron CW — basic pseudo-Voigt\n", "\n", "Verifies the baseline constant-wavelength neutron powder pattern for\n", "anglesite with a pseudo-Voigt peak shape and no asymmetry correction.\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:36:28.954628Z", "iopub.status.busy": "2026-06-30T22:36:28.954436Z", "iopub.status.idle": "2026-06-30T22:36:31.805844Z", "shell.execute_reply": "2026-06-30T22:36:31.804892Z" } }, "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:36:31.807819Z", "iopub.status.busy": "2026-06-30T22:36:31.807481Z", "iopub.status.idle": "2026-06-30T22:36:32.025492Z", "shell.execute_reply": "2026-06-30T22:36:32.024260Z" } }, "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:36:32.027073Z", "iopub.status.busy": "2026-06-30T22:36:32.026920Z", "iopub.status.idle": "2026-06-30T22:36:32.036359Z", "shell.execute_reply": "2026-06-30T22:36:32.035558Z" } }, "outputs": [], "source": [ "structure = StructureFactory.from_scratch(name='pbso4')\n", "\n", "structure.space_group.name_h_m = 'P n m a' # FullProf Space group symbol\n", "\n", "structure.cell.length_a = 8.477992 # FullProf a\n", "structure.cell.length_b = 5.396482 # FullProf b\n", "structure.cell.length_c = 6.957715 # FullProf c\n", "\n", "structure.atom_sites.create(\n", " id='Pb', # FullProf Atom\n", " type_symbol='Pb', # FullProf Typ\n", " fract_x=0.18754, # FullProf X\n", " fract_y=0.25, # FullProf Y\n", " fract_z=0.16709, # FullProf Z\n", " adp_type='Biso', # FullProf Biso\n", " adp_iso=1.38058, # FullProf Biso\n", ")\n", "structure.atom_sites.create(\n", " id='S', # FullProf Atom\n", " type_symbol='S', # FullProf Typ\n", " fract_x=0.06532, # FullProf X\n", " fract_y=0.25, # FullProf Y\n", " fract_z=0.68401, # FullProf Z\n", " adp_type='Biso', # FullProf Biso\n", " adp_iso=0.36192, # FullProf Biso\n", ")\n", "structure.atom_sites.create(\n", " id='O1', # FullProf Atom\n", " type_symbol='O', # FullProf Typ\n", " fract_x=0.90822, # FullProf X\n", " fract_y=0.25, # FullProf Y\n", " fract_z=0.59542, # FullProf Z\n", " adp_type='Biso', # FullProf Biso\n", " adp_iso=2.03661, # FullProf Biso\n", ")\n", "structure.atom_sites.create(\n", " id='O2', # FullProf Atom\n", " type_symbol='O', # FullProf Typ\n", " fract_x=0.19390, # FullProf X\n", " fract_y=0.25, # FullProf Y\n", " fract_z=0.54359, # FullProf Z\n", " adp_type='Biso', # FullProf Biso\n", " adp_iso=1.50417, # FullProf Biso\n", ")\n", "structure.atom_sites.create(\n", " id='O3', # FullProf Atom\n", " type_symbol='O', # FullProf Typ\n", " fract_x=0.08114, # FullProf X\n", " fract_y=0.02713, # FullProf Y\n", " fract_z=0.80863, # FullProf Z\n", " adp_type='Biso', # FullProf Biso\n", " adp_iso=1.34347, # 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:36:32.038067Z", "iopub.status.busy": "2026-06-30T22:36:32.037923Z", "iopub.status.idle": "2026-06-30T22:36:32.044523Z", "shell.execute_reply": "2026-06-30T22:36:32.043688Z" } }, "outputs": [], "source": [ "FULLPROF_PROJECT_DIR = 'pd-neut-cwl_pbso4_basic'\n", "FULLPROF_PRF_FILE = 'pbso4.prf'\n", "FULLPROF_SUM_FILE = 'pbso4.sum'\n", "FULLPROF_BAC_FILE = 'pbso4.bac'\n", "FULLPROF_LABEL = verify.fullprof_label(FULLPROF_PROJECT_DIR, FULLPROF_SUM_FILE)\n", "\n", "FULLPROF_ZERO = -0.14357 # FullProf Zero\n", "FULLPROF_SCALE = 1.467900 # FullProf Scale\n", "FULLPROF_WAVELENGTH = 1.912000 # FullProf Lambda\n", "FULLPROF_U = 0.139488 # FullProf U\n", "FULLPROF_V = -0.414074 # FullProf V\n", "FULLPROF_W = 0.388200 # FullProf W\n", "FULLPROF_X = 0.0 # FullProf X\n", "FULLPROF_Y = 0.086383 # FullProf Y\n", "FULLPROF_WDT = 30.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:36:32.046026Z", "iopub.status.busy": "2026-06-30T22:36:32.045838Z", "iopub.status.idle": "2026-06-30T22:36:32.537917Z", "shell.execute_reply": "2026-06-30T22:36:32.537196Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mPeak profile type for experiment \u001b[0m\u001b[32m'pbso4'\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='pbso4',\n", " sample_form='powder',\n", " beam_mode='constant wavelength',\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='pbso4', 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.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:36:32.539416Z", "iopub.status.busy": "2026-06-30T22:36:32.539256Z", "iopub.status.idle": "2026-06-30T22:36:32.900073Z", "shell.execute_reply": "2026-06-30T22:36:32.899259Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mCalculator for experiment \u001b[0m\u001b[32m'pbso4'\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", " 'pbso4',\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": [ "## edi-crysfml VS FullProf" ] }, { "cell_type": "code", "execution_count": 8, "id": "14", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:32.903649Z", "iopub.status.busy": "2026-06-30T22:36:32.903479Z", "iopub.status.idle": "2026-06-30T22:36:33.016331Z", "shell.execute_reply": "2026-06-30T22:36:33.015543Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mCalculator for experiment \u001b[0m\u001b[32m'pbso4'\u001b[0m\u001b[1;36m changed to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "crysfml\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "⚠️ [CrysfmlCalculator] peak.cutoff_fwhm is not applied by the CrysFML backend (it uses a fixed CFL peak window); the value is \n", " ignored. \n" ] }, { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "experiment.calculator.type = 'crysfml'\n", "\n", "project.analysis.calculate()\n", "calc_ed_crysfml = experiment.data.intensity_calc\n", "LABEL_ED_CRYSFML = verify.engine_label('crysfml')\n", "\n", "project.display.pattern_comparison(\n", " 'pbso4',\n", " reference=calc_fullprof,\n", " candidate=calc_ed_crysfml,\n", " reference_label=FULLPROF_LABEL,\n", " candidate_label=LABEL_ED_CRYSFML,\n", ")" ] }, { "cell_type": "markdown", "id": "15", "metadata": {}, "source": [ "## Agreement check" ] }, { "cell_type": "code", "execution_count": 9, "id": "16", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:33.019689Z", "iopub.status.busy": "2026-06-30T22:36:33.019527Z", "iopub.status.idle": "2026-06-30T22:36:33.027475Z", "shell.execute_reply": "2026-06-30T22:36:33.026744Z" } }, "outputs": [ { "data": { "text/html": [ "
ComparisonMetricExpectedActualOK
1edi 0.19.1 (cryspy 0.12.1) vs FullProf 8.40Profile diff (%)< 2.50.76
2Max deviation (%)< 63.88
3Area ratio0.99 to 1.010.9991
4Shape correlation> 0.9991.0000
5edi 0.19.1 (crysfml 0.7.0) vs FullProf 8.40Profile diff (%)< 2.50.60
6Max deviation (%)< 64.25
7Area ratio0.99 to 1.010.9994
8Shape correlation> 0.9991.0000
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "True" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "verify.assert_patterns_agree(\n", " [\n", " (f'{LABEL_ED_CRYSPY} vs {FULLPROF_LABEL}', calc_fullprof, calc_ed_cryspy),\n", " (f'{LABEL_ED_CRYSFML} vs {FULLPROF_LABEL}', calc_fullprof, calc_ed_crysfml),\n", " ],\n", ")" ] } ], "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 }