{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:23.385843Z", "iopub.status.busy": "2026-06-30T22:27:23.385650Z", "iopub.status.idle": "2026-06-30T22:27:23.390790Z", "shell.execute_reply": "2026-06-30T22:27:23.389914Z" }, "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": [ "# LaB6 - powder neutron CW - basic\n", "\n", "Verifies the baseline LaB6 constant-wavelength neutron powder pattern\n", "with natural boron and no SyCos/SySin, FCJ asymmetry, or absorption.\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:27:23.392585Z", "iopub.status.busy": "2026-06-30T22:27:23.392377Z", "iopub.status.idle": "2026-06-30T22:27:26.314830Z", "shell.execute_reply": "2026-06-30T22:27:26.314074Z" } }, "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:27:26.316967Z", "iopub.status.busy": "2026-06-30T22:27:26.316585Z", "iopub.status.idle": "2026-06-30T22:27:26.532476Z", "shell.execute_reply": "2026-06-30T22:27:26.531634Z" } }, "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:27:26.534181Z", "iopub.status.busy": "2026-06-30T22:27:26.533994Z", "iopub.status.idle": "2026-06-30T22:27:26.540405Z", "shell.execute_reply": "2026-06-30T22:27:26.539541Z" } }, "outputs": [], "source": [ "structure = StructureFactory.from_scratch(name='lab6')\n", "structure.space_group.name_h_m = 'P m -3 m' # FullProf Space group symbol\n", "structure.cell.length_a = 4.156885 # FullProf a\n", "structure.atom_sites.create(\n", " id='La', # FullProf Atom\n", " type_symbol='La', # 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=0.25812, # FullProf Biso\n", ")\n", "structure.atom_sites.create(\n", " id='B', # FullProf Atom\n", " type_symbol='B', # FullProf Typ\n", " fract_x=0.19972, # 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.11925, # 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:27:26.542059Z", "iopub.status.busy": "2026-06-30T22:27:26.541853Z", "iopub.status.idle": "2026-06-30T22:27:26.555607Z", "shell.execute_reply": "2026-06-30T22:27:26.554726Z" } }, "outputs": [], "source": [ "FULLPROF_PROJECT_DIR = 'pd-neut-cwl_lab6'\n", "FULLPROF_PRF_FILE = 'ECH0030684_LaB6_1p622A_baseline.prf'\n", "FULLPROF_SUM_FILE = 'ECH0030684_LaB6_1p622A_baseline.sum'\n", "FULLPROF_BAC_FILE = 'ECH0030684_LaB6_1p622A_baseline.bac'\n", "FULLPROF_LABEL = verify.fullprof_label(FULLPROF_PROJECT_DIR, FULLPROF_SUM_FILE)\n", "\n", "FULLPROF_ZERO = -0.45778 # FullProf Zero\n", "FULLPROF_SCALE = 42.98374 # FullProf Scale\n", "FULLPROF_WAVELENGTH = 1.623899 # FullProf Lambda\n", "FULLPROF_U = 0.143431 # FullProf U\n", "FULLPROF_V = -0.523140 # FullProf V\n", "FULLPROF_W = 0.590412 # FullProf W\n", "FULLPROF_X = 0.0 # FullProf X\n", "FULLPROF_Y = 0.054515 # FullProf Y\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-06-30T22:27:26.557272Z", "iopub.status.busy": "2026-06-30T22:27:26.557087Z", "iopub.status.idle": "2026-06-30T22:27:27.035467Z", "shell.execute_reply": "2026-06-30T22:27:27.034478Z" } }, "outputs": [], "source": [ "experiment = ExperimentFactory.from_scratch(\n", " name='lab6',\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='lab6', scale=FULLPROF_SCALE)\n", "\n", "experiment.instrument.setup_wavelength = FULLPROF_WAVELENGTH\n", "experiment.instrument.calib_twotheta_offset = FULLPROF_ZERO\n", "\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:27:27.037318Z", "iopub.status.busy": "2026-06-30T22:27:27.037064Z", "iopub.status.idle": "2026-06-30T22:27:27.526701Z", "shell.execute_reply": "2026-06-30T22:27:27.525813Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mCalculator for experiment \u001b[0m\u001b[32m'lab6'\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", " 'lab6',\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:27:27.529823Z", "iopub.status.busy": "2026-06-30T22:27:27.529598Z", "iopub.status.idle": "2026-06-30T22:27:27.538768Z", "shell.execute_reply": "2026-06-30T22:27:27.538017Z" } }, "outputs": [ { "data": { "text/html": [ "
ComparisonMetricExpectedActualOK
1edi 0.19.1 (cryspy 0.12.1) vs FullProf 8.40Profile diff (%)< 2.50.87
2Max deviation (%)< 60.46
3Area ratio0.99 to 1.010.9955
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", " (f'{LABEL_ED_CRYSPY} vs {FULLPROF_LABEL}', calc_fullprof, calc_ed_cryspy),\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 }