{ "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": [ "
| Comparison | Metric | Expected | Actual | OK | |
|---|---|---|---|---|---|
| 1 | edi 0.19.1 (cryspy 0.12.1) vs FullProf 8.40 | Profile diff (%) | < 2.5 | 0.76 | ✅ |
| 2 | Max deviation (%) | < 6 | 3.88 | ✅ | |
| 3 | Area ratio | 0.99 to 1.01 | 0.9991 | ✅ | |
| 4 | Shape correlation | > 0.999 | 1.0000 | ✅ | |
| 5 | edi 0.19.1 (crysfml 0.7.0) vs FullProf 8.40 | Profile diff (%) | < 2.5 | 0.60 | ✅ |
| 6 | Max deviation (%) | < 6 | 4.25 | ✅ | |
| 7 | Area ratio | 0.99 to 1.01 | 0.9994 | ✅ | |
| 8 | Shape correlation | > 0.999 | 1.0000 | ✅ |