{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:14:16.181256Z", "iopub.status.busy": "2026-08-18T18:14:16.181071Z", "iopub.status.idle": "2026-08-18T18:14:16.185065Z", "shell.execute_reply": "2026-08-18T18:14:16.184334Z" }, "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": [ "# Diamond — powder neutron TOF — DREAM (ESS, McStas)\n", "\n", "Verifies the Jorgensen back-to-back exponential TOF profile against a\n", "FullProf reference fitted to McStas-simulated reduced data from the\n", "DREAM diffractometer at ESS.\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:14:16.186602Z", "iopub.status.busy": "2026-08-18T18:14:16.186417Z", "iopub.status.idle": "2026-08-18T18:14:18.984498Z", "shell.execute_reply": "2026-08-18T18:14:18.983605Z" } }, "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:14:18.986185Z", "iopub.status.busy": "2026-08-18T18:14:18.985924Z", "iopub.status.idle": "2026-08-18T18:14:19.268967Z", "shell.execute_reply": "2026-08-18T18:14:19.268079Z" } }, "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:14:19.271276Z", "iopub.status.busy": "2026-08-18T18:14:19.271116Z", "iopub.status.idle": "2026-08-18T18:14:19.276262Z", "shell.execute_reply": "2026-08-18T18:14:19.275534Z" } }, "outputs": [], "source": [ "structure = StructureFactory.from_scratch(name='diamond')\n", "\n", "structure.space_group.name_h_m = 'F d -3 m' # FullProf Space group symbol\n", "structure.space_group.coord_system_code = '1' # FullProf \":1\" origin choice\n", "\n", "structure.cell.length_a = 3.567 # FullProf a\n", "\n", "structure.atom_sites.create(\n", " id='C', # FullProf Atom\n", " type_symbol='C', # 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.89263, # 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:14:19.278114Z", "iopub.status.busy": "2026-08-18T18:14:19.277945Z", "iopub.status.idle": "2026-08-18T18:14:19.284920Z", "shell.execute_reply": "2026-08-18T18:14:19.284124Z" } }, "outputs": [], "source": [ "FULLPROF_PROJECT_DIR = 'pd-neut-tof_diamond_dream'\n", "FULLPROF_PRF_FILE = 'diamond.prf'\n", "FULLPROF_SUM_FILE = 'diamond.sum'\n", "FULLPROF_BAC_FILE = 'diamond.bac'\n", "FULLPROF_LABEL = verify.fullprof_label(FULLPROF_PROJECT_DIR, FULLPROF_SUM_FILE)\n", "\n", "FULLPROF_ZERO = 0.0 # FullProf Zero\n", "FULLPROF_SCALE = 14.56963 # FullProf Scale\n", "FULLPROF_TWOTHETA_BANK = 90.0 # FullProf 2ThetaBank\n", "FULLPROF_DTT1 = 28385.86133 # FullProf Dtt1\n", "FULLPROF_DTT2 = 0.0 # FullProf Dtt2\n", "FULLPROF_SIGMA_0 = 46937.7188 # FullProf Sigma-0\n", "FULLPROF_SIGMA_1 = 4887.9180 # FullProf Sigma-1\n", "FULLPROF_SIGMA_2 = 0.0 # FullProf Sigma-2\n", "FULLPROF_ALPHA_0 = 0.0 # FullProf alph0\n", "FULLPROF_ALPHA_1 = 0.022544 # FullProf alph1\n", "FULLPROF_BETA_0 = 0.014330 # FullProf beta0\n", "FULLPROF_BETA_1 = 0.0 # FullProf beta1\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-08-18T18:14:19.286552Z", "iopub.status.busy": "2026-08-18T18:14:19.286312Z", "iopub.status.idle": "2026-08-18T18:14:19.512586Z", "shell.execute_reply": "2026-08-18T18:14:19.511831Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mPeak profile type for experiment \u001b[0m\u001b[32m'diamond'\u001b[0m\u001b[1;36m changed to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "jorgensen\n" ] } ], "source": [ "experiment = ExperimentFactory.from_scratch(\n", " name='diamond',\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='diamond', 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'\n", "experiment.peak.broad_gauss_sigma_0 = FULLPROF_SIGMA_0\n", "experiment.peak.broad_gauss_sigma_1 = FULLPROF_SIGMA_1\n", "experiment.peak.broad_gauss_sigma_2 = FULLPROF_SIGMA_2\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=10000)\n", "experiment.excluded_regions.create(id='2', start=70000, end=200000)\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:14:19.514403Z", "iopub.status.busy": "2026-08-18T18:14:19.514227Z", "iopub.status.idle": "2026-08-18T18:14:20.229144Z", "shell.execute_reply": "2026-08-18T18:14:20.228394Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mCalculator for experiment \u001b[0m\u001b[32m'diamond'\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", "experiment.linked_structures['diamond'].scale = FULLPROF_SCALE\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", " 'diamond',\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-08-18T18:14:20.231683Z", "iopub.status.busy": "2026-08-18T18:14:20.231520Z", "iopub.status.idle": "2026-08-18T18:14:20.238980Z", "shell.execute_reply": "2026-08-18T18:14:20.238154Z" } }, "outputs": [ { "data": { "text/html": [ "
ComparisonMetricExpectedActualOK
1edi 0.20.1 (cryspy 0.13.0) vs FullProf 8.40Profile diff (%)< 2.50.21
2Max deviation (%)< 60.23
3Area ratio0.99 to 1.010.9984
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": [ "verify.assert_patterns_agree(\n", " [\n", " (\n", " f'{LABEL_ED_CRYSPY} vs {FULLPROF_LABEL}',\n", " verify.restrict_to_included(experiment, calc_fullprof),\n", " calc_ed_cryspy,\n", " ),\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.6" } }, "nbformat": 4, "nbformat_minor": 5 }