{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:18:54.927513Z", "iopub.status.busy": "2026-08-18T18:18:54.927342Z", "iopub.status.idle": "2026-08-18T18:18:54.931204Z", "shell.execute_reply": "2026-08-18T18:18:54.930609Z" }, "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": [ "# Fe - powder neutron TOF - pseudo-Voigt profile\n", "\n", "Verifies the simple non-convoluted pseudo-Voigt time-of-flight peak\n", "profile.\n", "\n", "**Refinement:** none. The calculation uses parameters from the\n", "FullProf reference directly." ] }, { "cell_type": "code", "execution_count": 2, "id": "2", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:18:54.933021Z", "iopub.status.busy": "2026-08-18T18:18:54.932860Z", "iopub.status.idle": "2026-08-18T18:18:57.682926Z", "shell.execute_reply": "2026-08-18T18:18:57.682112Z" } }, "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:18:57.685503Z", "iopub.status.busy": "2026-08-18T18:18:57.685200Z", "iopub.status.idle": "2026-08-18T18:18:57.971274Z", "shell.execute_reply": "2026-08-18T18:18:57.970491Z" } }, "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:18:57.973449Z", "iopub.status.busy": "2026-08-18T18:18:57.973269Z", "iopub.status.idle": "2026-08-18T18:18:57.978697Z", "shell.execute_reply": "2026-08-18T18:18:57.977905Z" } }, "outputs": [], "source": [ "structure = StructureFactory.from_scratch(name='fe')\n", "structure.space_group.name_h_m = 'I m -3 m' # FullProf Space group symbol\n", "structure.cell.length_a = 2.886 # FullProf a\n", "structure.atom_sites.create(\n", " id='Fe', # FullProf Atom\n", " type_symbol='Fe', # 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.71513, # 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:18:57.980220Z", "iopub.status.busy": "2026-08-18T18:18:57.980050Z", "iopub.status.idle": "2026-08-18T18:18:57.987977Z", "shell.execute_reply": "2026-08-18T18:18:57.987329Z" } }, "outputs": [], "source": [ "FULLPROF_PROJECT_DIR = 'pd-neut-tof_fe_pseudo-voigt'\n", "FULLPROF_PRF_FILE = 'fe_1.prf'\n", "FULLPROF_SUM_FILE = 'fe.sum'\n", "FULLPROF_BAC_FILE = 'fe_1.bac'\n", "FULLPROF_LABEL = verify.fullprof_label(FULLPROF_PROJECT_DIR, FULLPROF_SUM_FILE)\n", "\n", "FULLPROF_ZERO = -10.29183 # FullProf Zero\n", "FULLPROF_SCALE = 401.4629 # FullProf Scale\n", "FULLPROF_TWOTHETA_BANK = 90.0 # FullProf 2ThetaBank\n", "FULLPROF_DTT1 = 54902.18750 # FullProf Dtt1\n", "FULLPROF_DTT2 = 0.0 # FullProf Dtt2\n", "FULLPROF_SIGMA_0 = 893.6397 # FullProf Sigma-0\n", "FULLPROF_SIGMA_1 = 1283.6387 # FullProf Sigma-1\n", "FULLPROF_SIGMA_2 = 311.7041 # FullProf Sigma-2\n", "FULLPROF_GAMMA_0 = 5.0330 # FullProf Gamma-0\n", "FULLPROF_GAMMA_1 = 0.0 # FullProf Gamma-1\n", "FULLPROF_GAMMA_2 = 0.0 # FullProf Gamma-2\n", "FULLPROF_WDT = 12.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:18:57.990114Z", "iopub.status.busy": "2026-08-18T18:18:57.989949Z", "iopub.status.idle": "2026-08-18T18:18:58.505019Z", "shell.execute_reply": "2026-08-18T18:18:58.504245Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "⚠️ Switching peak profile type removes these settings: \n", " • decay_beta_0 \n", " • decay_beta_1 \n", " • rise_alpha_0 \n", " • rise_alpha_1 \n" ] }, { "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'fe'\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='fe',\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='fe', 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 = 'pseudo-voigt'\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.broad_lorentz_gamma_0 = FULLPROF_GAMMA_0\n", "experiment.peak.broad_lorentz_gamma_1 = FULLPROF_GAMMA_1\n", "experiment.peak.broad_lorentz_gamma_2 = FULLPROF_GAMMA_2\n", "\n", "experiment.excluded_regions.create(id='1', start=0.0, end=40000.0)\n", "experiment.excluded_regions.create(id='2', start=130000.0, end=180000.0)\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:18:58.506539Z", "iopub.status.busy": "2026-08-18T18:18:58.506348Z", "iopub.status.idle": "2026-08-18T18:18:58.985139Z", "shell.execute_reply": "2026-08-18T18:18:58.984381Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mCalculator for experiment \u001b[0m\u001b[32m'fe'\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.12 | ✅ |
| 2 | Max deviation (%) | < 6 | 0.11 | ✅ | |
| 3 | Area ratio | 0.99 to 1.01 | 1.0002 | ✅ | |
| 4 | Shape correlation | > 0.999 | 1.0000 | ✅ |