{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "4142e7f9",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:25.927022Z",
"iopub.status.busy": "2026-01-06T13:55:25.926768Z",
"iopub.status.idle": "2026-01-06T13:55:25.936391Z",
"shell.execute_reply": "2026-01-06T13:55:25.935796Z"
},
"tags": [
"hide-in-docs"
]
},
"outputs": [],
"source": [
"# Check if the easydiffraction library is installed.\n",
"# If not, install it with the 'visualization' extras.\n",
"# Needed when running remotely (e.g. Colab) where the lib is absent.\n",
"import builtins\n",
"import importlib.util\n",
"\n",
"if (hasattr(builtins, '__IPYTHON__') and\n",
" importlib.util.find_spec('easydiffraction') is None):\n",
" !pip install 'easydiffraction[visualization]==0.10.1'"
]
},
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"# Structure Refinement: LBCO+Si, McStas\n",
"\n",
"This example demonstrates a Rietveld refinement of La0.5Ba0.5CoO3\n",
"crystal structure with a small amount of Si phase using time-of-flight\n",
"neutron powder diffraction data simulated with McStas."
]
},
{
"cell_type": "markdown",
"id": "1",
"metadata": {},
"source": [
"## Import Library"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:25.938969Z",
"iopub.status.busy": "2026-01-06T13:55:25.938822Z",
"iopub.status.idle": "2026-01-06T13:55:29.194597Z",
"shell.execute_reply": "2026-01-06T13:55:29.191726Z"
}
},
"outputs": [],
"source": [
"from easydiffraction import ExperimentFactory\n",
"from easydiffraction import Project\n",
"from easydiffraction import SampleModelFactory\n",
"from easydiffraction import download_data"
]
},
{
"cell_type": "markdown",
"id": "3",
"metadata": {},
"source": [
"## Define Sample Models\n",
"\n",
"This section shows how to add sample models and modify their\n",
"parameters.\n",
"\n",
"### Create Sample Model 1: LBCO"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.203076Z",
"iopub.status.busy": "2026-01-06T13:55:29.200411Z",
"iopub.status.idle": "2026-01-06T13:55:29.212264Z",
"shell.execute_reply": "2026-01-06T13:55:29.209641Z"
}
},
"outputs": [],
"source": [
"model_1 = SampleModelFactory.create(name='lbco')"
]
},
{
"cell_type": "markdown",
"id": "5",
"metadata": {},
"source": [
"#### Set Space Group"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.216584Z",
"iopub.status.busy": "2026-01-06T13:55:29.215703Z",
"iopub.status.idle": "2026-01-06T13:55:29.222198Z",
"shell.execute_reply": "2026-01-06T13:55:29.220697Z"
}
},
"outputs": [],
"source": [
"model_1.space_group.name_h_m = 'P m -3 m'\n",
"model_1.space_group.it_coordinate_system_code = '1'"
]
},
{
"cell_type": "markdown",
"id": "7",
"metadata": {},
"source": [
"#### Set Unit Cell"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.225434Z",
"iopub.status.busy": "2026-01-06T13:55:29.224927Z",
"iopub.status.idle": "2026-01-06T13:55:29.227652Z",
"shell.execute_reply": "2026-01-06T13:55:29.227149Z"
}
},
"outputs": [],
"source": [
"model_1.cell.length_a = 3.8909"
]
},
{
"cell_type": "markdown",
"id": "9",
"metadata": {},
"source": [
"#### Set Atom Sites"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "10",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.229985Z",
"iopub.status.busy": "2026-01-06T13:55:29.229242Z",
"iopub.status.idle": "2026-01-06T13:55:29.240706Z",
"shell.execute_reply": "2026-01-06T13:55:29.238246Z"
}
},
"outputs": [],
"source": [
"model_1.atom_sites.add(\n",
" label='La',\n",
" type_symbol='La',\n",
" fract_x=0,\n",
" fract_y=0,\n",
" fract_z=0,\n",
" wyckoff_letter='a',\n",
" b_iso=0.2,\n",
" occupancy=0.5,\n",
")\n",
"model_1.atom_sites.add(\n",
" label='Ba',\n",
" type_symbol='Ba',\n",
" fract_x=0,\n",
" fract_y=0,\n",
" fract_z=0,\n",
" wyckoff_letter='a',\n",
" b_iso=0.2,\n",
" occupancy=0.5,\n",
")\n",
"model_1.atom_sites.add(\n",
" label='Co',\n",
" type_symbol='Co',\n",
" fract_x=0.5,\n",
" fract_y=0.5,\n",
" fract_z=0.5,\n",
" wyckoff_letter='b',\n",
" b_iso=0.2567,\n",
")\n",
"model_1.atom_sites.add(\n",
" label='O',\n",
" type_symbol='O',\n",
" fract_x=0,\n",
" fract_y=0.5,\n",
" fract_z=0.5,\n",
" wyckoff_letter='c',\n",
" b_iso=1.4041,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "11",
"metadata": {},
"source": [
"### Create Sample Model 2: Si"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "12",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.243322Z",
"iopub.status.busy": "2026-01-06T13:55:29.243155Z",
"iopub.status.idle": "2026-01-06T13:55:29.250013Z",
"shell.execute_reply": "2026-01-06T13:55:29.249119Z"
}
},
"outputs": [],
"source": [
"model_2 = SampleModelFactory.create(name='si')"
]
},
{
"cell_type": "markdown",
"id": "13",
"metadata": {},
"source": [
"#### Set Space Group"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "14",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.253704Z",
"iopub.status.busy": "2026-01-06T13:55:29.253356Z",
"iopub.status.idle": "2026-01-06T13:55:29.257336Z",
"shell.execute_reply": "2026-01-06T13:55:29.255947Z"
}
},
"outputs": [],
"source": [
"model_2.space_group.name_h_m = 'F d -3 m'\n",
"model_2.space_group.it_coordinate_system_code = '2'"
]
},
{
"cell_type": "markdown",
"id": "15",
"metadata": {},
"source": [
"#### Set Unit Cell"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "16",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.259442Z",
"iopub.status.busy": "2026-01-06T13:55:29.259317Z",
"iopub.status.idle": "2026-01-06T13:55:29.262261Z",
"shell.execute_reply": "2026-01-06T13:55:29.261315Z"
}
},
"outputs": [],
"source": [
"model_2.cell.length_a = 5.43146"
]
},
{
"cell_type": "markdown",
"id": "17",
"metadata": {},
"source": [
"#### Set Atom Sites"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "18",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.264546Z",
"iopub.status.busy": "2026-01-06T13:55:29.264401Z",
"iopub.status.idle": "2026-01-06T13:55:29.267593Z",
"shell.execute_reply": "2026-01-06T13:55:29.266779Z"
}
},
"outputs": [],
"source": [
"model_2.atom_sites.add(\n",
" label='Si',\n",
" type_symbol='Si',\n",
" fract_x=0.0,\n",
" fract_y=0.0,\n",
" fract_z=0.0,\n",
" wyckoff_letter='a',\n",
" b_iso=0.0,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "19",
"metadata": {},
"source": [
"## Define Experiment\n",
"\n",
"This section shows how to add experiments, configure their parameters,\n",
"and link the sample models defined in the previous step.\n",
"\n",
"#### Download Data"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "20",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.270191Z",
"iopub.status.busy": "2026-01-06T13:55:29.270048Z",
"iopub.status.idle": "2026-01-06T13:55:29.364643Z",
"shell.execute_reply": "2026-01-06T13:55:29.363726Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mGetting data\u001b[0m\u001b[1;34m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data #\u001b[1;36m8\u001b[0m: La0.5Ba0.5CoO3 + Si, McStas simulation\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"โ
Data #\u001b[1;36m8\u001b[0m downloaded to \u001b[32m'data/ed-8.xye'\u001b[0m\n"
]
}
],
"source": [
"data_path = download_data(id=8, destination='data')"
]
},
{
"cell_type": "markdown",
"id": "21",
"metadata": {},
"source": [
"#### Create Experiment"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "22",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.370003Z",
"iopub.status.busy": "2026-01-06T13:55:29.369661Z",
"iopub.status.idle": "2026-01-06T13:55:29.633982Z",
"shell.execute_reply": "2026-01-06T13:55:29.632642Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mData loaded successfully\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Experiment ๐ฌ \u001b[32m'mcstas'\u001b[0m. Number of data points: \u001b[1;36m1000\u001b[0m\n"
]
}
],
"source": [
"experiment = ExperimentFactory.create(\n",
" name='mcstas',\n",
" data_path=data_path,\n",
" sample_form='powder',\n",
" beam_mode='time-of-flight',\n",
" radiation_probe='neutron',\n",
" scattering_type='bragg',\n",
")"
]
},
{
"cell_type": "markdown",
"id": "23",
"metadata": {},
"source": [
"#### Set Instrument"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "24",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.638023Z",
"iopub.status.busy": "2026-01-06T13:55:29.637415Z",
"iopub.status.idle": "2026-01-06T13:55:29.641332Z",
"shell.execute_reply": "2026-01-06T13:55:29.640559Z"
}
},
"outputs": [],
"source": [
"experiment.instrument.setup_twotheta_bank = 94.90931761529106\n",
"experiment.instrument.calib_d_to_tof_offset = 0.0\n",
"experiment.instrument.calib_d_to_tof_linear = 58724.76869981215\n",
"experiment.instrument.calib_d_to_tof_quad = -0.00001"
]
},
{
"cell_type": "markdown",
"id": "25",
"metadata": {},
"source": [
"#### Set Peak Profile"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "26",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.644409Z",
"iopub.status.busy": "2026-01-06T13:55:29.644233Z",
"iopub.status.idle": "2026-01-06T13:55:29.648587Z",
"shell.execute_reply": "2026-01-06T13:55:29.647377Z"
}
},
"outputs": [],
"source": [
"# experiment.peak_profile_type = 'pseudo-voigt * ikeda-carpenter'\n",
"experiment.peak.broad_gauss_sigma_0 = 45137\n",
"experiment.peak.broad_gauss_sigma_1 = -52394\n",
"experiment.peak.broad_gauss_sigma_2 = 22998\n",
"experiment.peak.broad_mix_beta_0 = 0.0055\n",
"experiment.peak.broad_mix_beta_1 = 0.0041\n",
"experiment.peak.asym_alpha_0 = 0\n",
"experiment.peak.asym_alpha_1 = 0.0097"
]
},
{
"cell_type": "markdown",
"id": "27",
"metadata": {},
"source": [
"#### Set Background"
]
},
{
"cell_type": "markdown",
"id": "28",
"metadata": {},
"source": [
"Select the background type."
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "29",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.650682Z",
"iopub.status.busy": "2026-01-06T13:55:29.650546Z",
"iopub.status.idle": "2026-01-06T13:55:29.656287Z",
"shell.execute_reply": "2026-01-06T13:55:29.654354Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mBackground type for experiment \u001b[0m\u001b[32m'mcstas'\u001b[0m\u001b[1;34m changed to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"line-segment\n"
]
}
],
"source": [
"experiment.background_type = 'line-segment'"
]
},
{
"cell_type": "markdown",
"id": "30",
"metadata": {},
"source": [
"Add background points."
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "31",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.659519Z",
"iopub.status.busy": "2026-01-06T13:55:29.659219Z",
"iopub.status.idle": "2026-01-06T13:55:29.666325Z",
"shell.execute_reply": "2026-01-06T13:55:29.665551Z"
}
},
"outputs": [],
"source": [
"experiment.background.add(id='1', x=45000, y=0.2)\n",
"experiment.background.add(id='2', x=50000, y=0.2)\n",
"experiment.background.add(id='3', x=55000, y=0.2)\n",
"experiment.background.add(id='4', x=65000, y=0.2)\n",
"experiment.background.add(id='5', x=70000, y=0.2)\n",
"experiment.background.add(id='6', x=75000, y=0.2)\n",
"experiment.background.add(id='7', x=80000, y=0.2)\n",
"experiment.background.add(id='8', x=85000, y=0.2)\n",
"experiment.background.add(id='9', x=90000, y=0.2)\n",
"experiment.background.add(id='10', x=95000, y=0.2)\n",
"experiment.background.add(id='11', x=100000, y=0.2)\n",
"experiment.background.add(id='12', x=105000, y=0.2)\n",
"experiment.background.add(id='13', x=110000, y=0.2)"
]
},
{
"cell_type": "markdown",
"id": "32",
"metadata": {},
"source": [
"#### Set Linked Phases"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "33",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.669113Z",
"iopub.status.busy": "2026-01-06T13:55:29.668927Z",
"iopub.status.idle": "2026-01-06T13:55:29.672998Z",
"shell.execute_reply": "2026-01-06T13:55:29.672266Z"
}
},
"outputs": [],
"source": [
"experiment.linked_phases.add(id='lbco', scale=4.0)\n",
"experiment.linked_phases.add(id='si', scale=0.2)"
]
},
{
"cell_type": "markdown",
"id": "34",
"metadata": {},
"source": [
"## Define Project\n",
"\n",
"The project object is used to manage sample models, experiments, and\n",
"analysis.\n",
"\n",
"#### Create Project"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "35",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.675414Z",
"iopub.status.busy": "2026-01-06T13:55:29.675293Z",
"iopub.status.idle": "2026-01-06T13:55:29.890286Z",
"shell.execute_reply": "2026-01-06T13:55:29.885059Z"
}
},
"outputs": [],
"source": [
"project = Project()"
]
},
{
"cell_type": "markdown",
"id": "36",
"metadata": {},
"source": [
"#### Add Sample Models"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "37",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.893928Z",
"iopub.status.busy": "2026-01-06T13:55:29.893246Z",
"iopub.status.idle": "2026-01-06T13:55:29.897737Z",
"shell.execute_reply": "2026-01-06T13:55:29.896703Z"
}
},
"outputs": [],
"source": [
"project.sample_models.add(sample_model=model_1)\n",
"project.sample_models.add(sample_model=model_2)"
]
},
{
"cell_type": "markdown",
"id": "38",
"metadata": {},
"source": [
"#### Show Sample Models"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "39",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.900794Z",
"iopub.status.busy": "2026-01-06T13:55:29.900131Z",
"iopub.status.idle": "2026-01-06T13:55:29.912227Z",
"shell.execute_reply": "2026-01-06T13:55:29.910015Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mDefined sample models ๐งฉ\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1m[\u001b[0m\u001b[32m'lbco'\u001b[0m, \u001b[32m'si'\u001b[0m\u001b[1m]\u001b[0m\n"
]
}
],
"source": [
"project.sample_models.show_names()"
]
},
{
"cell_type": "markdown",
"id": "40",
"metadata": {},
"source": [
"#### Add Experiments"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "41",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.915668Z",
"iopub.status.busy": "2026-01-06T13:55:29.914943Z",
"iopub.status.idle": "2026-01-06T13:55:29.925809Z",
"shell.execute_reply": "2026-01-06T13:55:29.921683Z"
}
},
"outputs": [],
"source": [
"project.experiments.add(experiment=experiment)"
]
},
{
"cell_type": "markdown",
"id": "42",
"metadata": {},
"source": [
"#### Set Excluded Regions\n",
"\n",
"Show measured data as loaded from the file."
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "43",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:29.928493Z",
"iopub.status.busy": "2026-01-06T13:55:29.928188Z",
"iopub.status.idle": "2026-01-06T13:55:30.392386Z",
"shell.execute_reply": "2026-01-06T13:55:30.391919Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.plot_meas(expt_name='mcstas')"
]
},
{
"cell_type": "markdown",
"id": "44",
"metadata": {},
"source": [
"Add excluded regions."
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "45",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:30.394617Z",
"iopub.status.busy": "2026-01-06T13:55:30.394471Z",
"iopub.status.idle": "2026-01-06T13:55:30.397284Z",
"shell.execute_reply": "2026-01-06T13:55:30.396715Z"
}
},
"outputs": [],
"source": [
"experiment.excluded_regions.add(id='1', start=0, end=40000)\n",
"experiment.excluded_regions.add(id='2', start=108000, end=200000)"
]
},
{
"cell_type": "markdown",
"id": "46",
"metadata": {},
"source": [
"Show excluded regions."
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "47",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:30.399373Z",
"iopub.status.busy": "2026-01-06T13:55:30.399216Z",
"iopub.status.idle": "2026-01-06T13:55:30.730841Z",
"shell.execute_reply": "2026-01-06T13:55:30.730442Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mExcluded regions\u001b[0m\n"
]
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" start | \n",
" end | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" 0 | \n",
" 40000 | \n",
"
\n",
" \n",
" | 2 | \n",
" 108000 | \n",
" 200000 | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"experiment.excluded_regions.show()"
]
},
{
"cell_type": "markdown",
"id": "48",
"metadata": {},
"source": [
"Show measured data after adding excluded regions."
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "49",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:30.733779Z",
"iopub.status.busy": "2026-01-06T13:55:30.733264Z",
"iopub.status.idle": "2026-01-06T13:55:31.176504Z",
"shell.execute_reply": "2026-01-06T13:55:31.175793Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.plot_meas(expt_name='mcstas')"
]
},
{
"cell_type": "markdown",
"id": "50",
"metadata": {},
"source": [
"Show experiment as CIF."
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "51",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:31.178754Z",
"iopub.status.busy": "2026-01-06T13:55:31.178629Z",
"iopub.status.idle": "2026-01-06T13:55:31.977942Z",
"shell.execute_reply": "2026-01-06T13:55:31.976502Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mExperiment ๐ฌ \u001b[0m\u001b[32m'mcstas'\u001b[0m\u001b[1;34m as cif\u001b[0m\n"
]
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" CIF | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" data_mcstas | \n",
"
\n",
" \n",
" | 2 | \n",
" | \n",
"
\n",
" \n",
" | 3 | \n",
" _expt_type.sample_form powder | \n",
"
\n",
" \n",
" | 4 | \n",
" _expt_type.beam_mode time-of-flight | \n",
"
\n",
" \n",
" | 5 | \n",
" _expt_type.radiation_probe neutron | \n",
"
\n",
" \n",
" | 6 | \n",
" _expt_type.scattering_type bragg | \n",
"
\n",
" \n",
" | 7 | \n",
" | \n",
"
\n",
" \n",
" | 8 | \n",
" _peak.gauss_sigma_0 45137.0000 | \n",
"
\n",
" \n",
" | 9 | \n",
" _peak.gauss_sigma_1 -52394.0000 | \n",
"
\n",
" \n",
" | 10 | \n",
" _peak.gauss_sigma_2 22998.0000 | \n",
"
\n",
" \n",
" | 11 | \n",
" _peak.lorentz_gamma_0 0.0000 | \n",
"
\n",
" \n",
" | 12 | \n",
" _peak.lorentz_gamma_1 0.0000 | \n",
"
\n",
" \n",
" | 13 | \n",
" _peak.lorentz_gamma_2 0.0000 | \n",
"
\n",
" \n",
" | 14 | \n",
" _peak.mix_beta_0 0.0055 | \n",
"
\n",
" \n",
" | 15 | \n",
" _peak.mix_beta_1 0.0041 | \n",
"
\n",
" \n",
" | 16 | \n",
" _peak.asym_alpha_0 0.0000 | \n",
"
\n",
" \n",
" | 17 | \n",
" _peak.asym_alpha_1 0.0097 | \n",
"
\n",
" \n",
" | 18 | \n",
" | \n",
"
\n",
" \n",
" | 19 | \n",
" _instr.2theta_bank 94.9093 | \n",
"
\n",
" \n",
" | 20 | \n",
" _instr.d_to_tof_offset 0.0000 | \n",
"
\n",
" \n",
" | 21 | \n",
" _instr.d_to_tof_linear 58724.7687 | \n",
"
\n",
" \n",
" | 22 | \n",
" _instr.d_to_tof_quad -0.0000 | \n",
"
\n",
" \n",
" | 23 | \n",
" _instr.d_to_tof_recip 0.0000 | \n",
"
\n",
" \n",
" | 24 | \n",
" | \n",
"
\n",
" \n",
" | 25 | \n",
" loop_ | \n",
"
\n",
" \n",
" | 26 | \n",
" _pd_phase_block.id | \n",
"
\n",
" \n",
" | 27 | \n",
" _pd_phase_block.scale | \n",
"
\n",
" \n",
" | 28 | \n",
" lbco 4.0000 | \n",
"
\n",
" \n",
" | 29 | \n",
" si 0.2000 | \n",
"
\n",
" \n",
" | 30 | \n",
" | \n",
"
\n",
" \n",
" | 31 | \n",
" loop_ | \n",
"
\n",
" \n",
" | 32 | \n",
" _excluded_region.id | \n",
"
\n",
" \n",
" | 33 | \n",
" _excluded_region.start | \n",
"
\n",
" \n",
" | 34 | \n",
" _excluded_region.end | \n",
"
\n",
" \n",
" | 35 | \n",
" 1 0.0000 40000.0000 | \n",
"
\n",
" \n",
" | 36 | \n",
" 2 108000.0000 200000.0000 | \n",
"
\n",
" \n",
" | 37 | \n",
" | \n",
"
\n",
" \n",
" | 38 | \n",
" loop_ | \n",
"
\n",
" \n",
" | 39 | \n",
" _pd_meas.time_of_flight | \n",
"
\n",
" \n",
" | 40 | \n",
" _pd_data.point_id | \n",
"
\n",
" \n",
" | 41 | \n",
" _pd_proc.d_spacing | \n",
"
\n",
" \n",
" | 42 | \n",
" _pd_meas.intensity_total | \n",
"
\n",
" \n",
" | 43 | \n",
" _pd_meas.intensity_total_su | \n",
"
\n",
" \n",
" | 44 | \n",
" _pd_calc.intensity_total | \n",
"
\n",
" \n",
" | 45 | \n",
" _pd_calc.intensity_bkg | \n",
"
\n",
" \n",
" | 46 | \n",
" _pd_data.refinement_status | \n",
"
\n",
" \n",
" | 47 | \n",
" 41168.1286 1 0.7010 0.2154 0.0249 0.2544 0.2000 incl | \n",
"
\n",
" \n",
" | 48 | \n",
" 41273.8536 2 0.7028 0.2609 0.0333 0.3380 0.2000 incl | \n",
"
\n",
" \n",
" | 49 | \n",
" 41379.5785 3 0.7046 0.3043 0.0355 0.4664 0.2000 incl | \n",
"
\n",
" \n",
" | 50 | \n",
" 41485.3035 4 0.7064 0.4737 0.0421 0.5860 0.2000 incl | \n",
"
\n",
" \n",
" | 51 | \n",
" 41591.0285 5 0.7082 0.6003 0.0420 0.6236 0.2000 incl | \n",
"
\n",
" \n",
" | 52 | \n",
" 41696.7534 6 0.7100 0.6017 0.0397 0.5577 0.2000 incl | \n",
"
\n",
" \n",
" | 53 | \n",
" 41802.4784 7 0.7118 0.5012 0.0381 0.4329 0.2000 incl | \n",
"
\n",
" \n",
" | 54 | \n",
" 41908.2034 8 0.7136 0.3770 0.0346 0.3153 0.2000 incl | \n",
"
\n",
" \n",
" | 55 | \n",
" 42013.9284 9 0.7154 0.2753 0.0319 0.2457 0.2000 incl | \n",
"
\n",
" \n",
" | 56 | \n",
" 42119.6533 10 0.7172 0.2618 0.0283 0.2273 0.2000 incl | \n",
"
\n",
" \n",
" | 57 | \n",
" ... | \n",
"
\n",
" \n",
" | 58 | \n",
" 145835.8489 991 2.4834 0.2241 0.0113 0.2000 0.2000 excl | \n",
"
\n",
" \n",
" | 59 | \n",
" 145941.5739 992 2.4852 0.2138 0.0107 0.2000 0.2000 excl | \n",
"
\n",
" \n",
" | 60 | \n",
" 146047.2988 993 2.4870 0.2093 0.0109 0.2000 0.2000 excl | \n",
"
\n",
" \n",
" | 61 | \n",
" 146153.0238 994 2.4888 0.2184 0.0109 0.2000 0.2000 excl | \n",
"
\n",
" \n",
" | 62 | \n",
" 146258.7488 995 2.4906 0.2161 0.0110 0.2000 0.2000 excl | \n",
"
\n",
" \n",
" | 63 | \n",
" 146364.4737 996 2.4924 0.2057 0.0111 0.2000 0.2000 excl | \n",
"
\n",
" \n",
" | 64 | \n",
" 146470.1987 997 2.4942 0.2262 0.0114 0.2000 0.2000 excl | \n",
"
\n",
" \n",
" | 65 | \n",
" 146575.9237 998 2.4960 0.2211 0.0115 0.2000 0.2000 excl | \n",
"
\n",
" \n",
" | 66 | \n",
" 146681.6486 999 2.4978 0.2086 0.0110 0.2000 0.2000 excl | \n",
"
\n",
" \n",
" | 67 | \n",
" 146787.3736 1000 2.4996 0.2088 0.0109 0.2000 0.2000 excl | \n",
"
\n",
" \n",
" | 68 | \n",
" | \n",
"
\n",
" \n",
" | 69 | \n",
" loop_ | \n",
"
\n",
" \n",
" | 70 | \n",
" _pd_background.id | \n",
"
\n",
" \n",
" | 71 | \n",
" _pd_background.line_segment_X | \n",
"
\n",
" \n",
" | 72 | \n",
" _pd_background.line_segment_intensity | \n",
"
\n",
" \n",
" | 73 | \n",
" 1 45000.0000 0.2000 | \n",
"
\n",
" \n",
" | 74 | \n",
" 2 50000.0000 0.2000 | \n",
"
\n",
" \n",
" | 75 | \n",
" 3 55000.0000 0.2000 | \n",
"
\n",
" \n",
" | 76 | \n",
" 4 65000.0000 0.2000 | \n",
"
\n",
" \n",
" | 77 | \n",
" 5 70000.0000 0.2000 | \n",
"
\n",
" \n",
" | 78 | \n",
" 6 75000.0000 0.2000 | \n",
"
\n",
" \n",
" | 79 | \n",
" 7 80000.0000 0.2000 | \n",
"
\n",
" \n",
" | 80 | \n",
" 8 85000.0000 0.2000 | \n",
"
\n",
" \n",
" | 81 | \n",
" 9 90000.0000 0.2000 | \n",
"
\n",
" \n",
" | 82 | \n",
" 10 95000.0000 0.2000 | \n",
"
\n",
" \n",
" | 83 | \n",
" 11 100000.0000 0.2000 | \n",
"
\n",
" \n",
" | 84 | \n",
" 12 105000.0000 0.2000 | \n",
"
\n",
" \n",
" | 85 | \n",
" 13 110000.0000 0.2000 | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.experiments['mcstas'].show_as_cif()"
]
},
{
"cell_type": "markdown",
"id": "52",
"metadata": {},
"source": [
"## Perform Analysis\n",
"\n",
"This section outlines the analysis process, including how to configure\n",
"calculation and fitting engines.\n",
"\n",
"#### Set Calculator"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "53",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:31.982974Z",
"iopub.status.busy": "2026-01-06T13:55:31.982623Z",
"iopub.status.idle": "2026-01-06T13:55:31.993799Z",
"shell.execute_reply": "2026-01-06T13:55:31.993215Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mCurrent calculator changed to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"cryspy\n"
]
}
],
"source": [
"project.analysis.current_calculator = 'cryspy'"
]
},
{
"cell_type": "markdown",
"id": "54",
"metadata": {},
"source": [
"#### Set Minimizer"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "55",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:31.995833Z",
"iopub.status.busy": "2026-01-06T13:55:31.995700Z",
"iopub.status.idle": "2026-01-06T13:55:32.004226Z",
"shell.execute_reply": "2026-01-06T13:55:32.003624Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mCurrent minimizer changed to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"lmfit \u001b[1m(\u001b[0mleastsq\u001b[1m)\u001b[0m\n"
]
}
],
"source": [
"project.analysis.current_minimizer = 'lmfit (leastsq)'"
]
},
{
"cell_type": "markdown",
"id": "56",
"metadata": {},
"source": [
"#### Set Fitting Parameters\n",
"\n",
"Set sample model parameters to be optimized."
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "57",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:32.006393Z",
"iopub.status.busy": "2026-01-06T13:55:32.006205Z",
"iopub.status.idle": "2026-01-06T13:55:32.009250Z",
"shell.execute_reply": "2026-01-06T13:55:32.008715Z"
}
},
"outputs": [],
"source": [
"model_1.cell.length_a.free = True\n",
"model_1.atom_sites['Co'].b_iso.free = True\n",
"model_1.atom_sites['O'].b_iso.free = True\n",
"\n",
"model_2.cell.length_a.free = True"
]
},
{
"cell_type": "markdown",
"id": "58",
"metadata": {},
"source": [
"Set experiment parameters to be optimized."
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "59",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:32.011750Z",
"iopub.status.busy": "2026-01-06T13:55:32.011466Z",
"iopub.status.idle": "2026-01-06T13:55:32.015805Z",
"shell.execute_reply": "2026-01-06T13:55:32.015096Z"
}
},
"outputs": [],
"source": [
"experiment.linked_phases['lbco'].scale.free = True\n",
"experiment.linked_phases['si'].scale.free = True\n",
"\n",
"experiment.peak.broad_gauss_sigma_0.free = True\n",
"experiment.peak.broad_gauss_sigma_1.free = True\n",
"experiment.peak.broad_gauss_sigma_2.free = True\n",
"\n",
"experiment.peak.asym_alpha_1.free = True\n",
"experiment.peak.broad_mix_beta_0.free = True\n",
"experiment.peak.broad_mix_beta_1.free = True\n",
"\n",
"for point in experiment.background:\n",
" point.y.free = True"
]
},
{
"cell_type": "markdown",
"id": "60",
"metadata": {},
"source": [
"#### Perform Fit"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "61",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:32.018346Z",
"iopub.status.busy": "2026-01-06T13:55:32.018134Z",
"iopub.status.idle": "2026-01-06T13:55:40.625760Z",
"shell.execute_reply": "2026-01-06T13:55:40.624272Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mUsing experiment ๐ฌ \u001b[0m\u001b[32m'mcstas'\u001b[0m\u001b[1;34m for \u001b[0m\u001b[32m'single'\u001b[0m\u001b[1;34m fitting\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"๐ Starting fit process with \u001b[32m'lmfit \u001b[0m\u001b[32m(\u001b[0m\u001b[32mleastsq\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m\u001b[33m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"๐ Goodness-of-fit \u001b[1m(\u001b[0mreduced ฯยฒ\u001b[1m)\u001b[0m change:\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" iteration | \n",
" ฯยฒ | \n",
" improvement [%] | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" 1 | \n",
" 301.38 | \n",
" | \n",
"
\n",
" \n",
" | 2 | \n",
" 29 | \n",
" 3.36 | \n",
" 98.9% โ | \n",
"
\n",
" \n",
" | 3 | \n",
" 55 | \n",
" 3.24 | \n",
" 3.7% โ | \n",
"
\n",
" \n",
" | 4 | \n",
" 134 | \n",
" 3.24 | \n",
" | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"๐ Best goodness-of-fit \u001b[1m(\u001b[0mreduced ฯยฒ\u001b[1m)\u001b[0m is \u001b[1;36m3.24\u001b[0m at iteration \u001b[1;36m133\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"โ
Fitting complete.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mFit results\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"โ
Success: \u001b[3;92mTrue\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"โฑ๏ธ Fitting time: \u001b[1;36m6.96\u001b[0m seconds\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"๐ Goodness-of-fit \u001b[1m(\u001b[0mreduced ฯยฒ\u001b[1m)\u001b[0m: \u001b[1;36m3.24\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"๐ R-factor \u001b[1m(\u001b[0mRf\u001b[1m)\u001b[0m: \u001b[1;36m4.74\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"๐ R-factor squared \u001b[1m(\u001b[0mRfยฒ\u001b[1m)\u001b[0m: \u001b[1;36m5.12\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"๐ Weighted R-factor \u001b[1m(\u001b[0mwR\u001b[1m)\u001b[0m: \u001b[1;36m5.18\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"๐ Fitted parameters:\n"
]
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" datablock | \n",
" category | \n",
" entry | \n",
" parameter | \n",
" start | \n",
" fitted | \n",
" uncertainty | \n",
" units | \n",
" change | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" lbco | \n",
" cell | \n",
" | \n",
" length_a | \n",
" 3.8909 | \n",
" 3.8904 | \n",
" 0.0001 | \n",
" ร
| \n",
" 0.01 % โ | \n",
"
\n",
" \n",
" | 2 | \n",
" lbco | \n",
" atom_site | \n",
" Co | \n",
" b_iso | \n",
" 0.2567 | \n",
" 0.3233 | \n",
" 0.0853 | \n",
" ร
ยฒ | \n",
" 25.94 % โ | \n",
"
\n",
" \n",
" | 3 | \n",
" lbco | \n",
" atom_site | \n",
" O | \n",
" b_iso | \n",
" 1.4041 | \n",
" 2.1686 | \n",
" 0.0282 | \n",
" ร
ยฒ | \n",
" 54.45 % โ | \n",
"
\n",
" \n",
" | 4 | \n",
" si | \n",
" cell | \n",
" | \n",
" length_a | \n",
" 5.4315 | \n",
" 5.4327 | \n",
" 0.0006 | \n",
" ร
| \n",
" 0.02 % โ | \n",
"
\n",
" \n",
" | 5 | \n",
" mcstas | \n",
" linked_phases | \n",
" lbco | \n",
" scale | \n",
" 4.0000 | \n",
" 4.5577 | \n",
" 0.0318 | \n",
" | \n",
" 13.94 % โ | \n",
"
\n",
" \n",
" | 6 | \n",
" mcstas | \n",
" linked_phases | \n",
" si | \n",
" scale | \n",
" 0.2000 | \n",
" 0.0314 | \n",
" 0.0008 | \n",
" | \n",
" 84.28 % โ | \n",
"
\n",
" \n",
" | 7 | \n",
" mcstas | \n",
" peak | \n",
" | \n",
" gauss_sigma_0 | \n",
" 45137.0000 | \n",
" 45210.8969 | \n",
" 2868.4651 | \n",
" ยตsยฒ | \n",
" 0.16 % โ | \n",
"
\n",
" \n",
" | 8 | \n",
" mcstas | \n",
" peak | \n",
" | \n",
" gauss_sigma_1 | \n",
" -52394.0000 | \n",
" -52476.8991 | \n",
" 3797.9256 | \n",
" ยตs/โซ | \n",
" 0.16 % โ | \n",
"
\n",
" \n",
" | 9 | \n",
" mcstas | \n",
" peak | \n",
" | \n",
" gauss_sigma_2 | \n",
" 22998.0000 | \n",
" 23014.3392 | \n",
" 1193.4306 | \n",
" ยตsยฒ/โซยฒ | \n",
" 0.07 % โ | \n",
"
\n",
" \n",
" | 10 | \n",
" mcstas | \n",
" peak | \n",
" | \n",
" mix_beta_0 | \n",
" 0.0055 | \n",
" 0.0055 | \n",
" 0.0001 | \n",
" deg | \n",
" 0.64 % โ | \n",
"
\n",
" \n",
" | 11 | \n",
" mcstas | \n",
" peak | \n",
" | \n",
" mix_beta_1 | \n",
" 0.0041 | \n",
" 0.0041 | \n",
" 0.0003 | \n",
" deg | \n",
" 0.32 % โ | \n",
"
\n",
" \n",
" | 12 | \n",
" mcstas | \n",
" peak | \n",
" | \n",
" asym_alpha_1 | \n",
" 0.0097 | \n",
" 0.0097 | \n",
" 0.0002 | \n",
" | \n",
" 0.40 % โ | \n",
"
\n",
" \n",
" | 13 | \n",
" mcstas | \n",
" background | \n",
" 1 | \n",
" y | \n",
" 0.2000 | \n",
" 0.2502 | \n",
" 0.0082 | \n",
" | \n",
" 25.09 % โ | \n",
"
\n",
" \n",
" | 14 | \n",
" mcstas | \n",
" background | \n",
" 2 | \n",
" y | \n",
" 0.2000 | \n",
" 0.2498 | \n",
" 0.0080 | \n",
" | \n",
" 24.91 % โ | \n",
"
\n",
" \n",
" | 15 | \n",
" mcstas | \n",
" background | \n",
" 3 | \n",
" y | \n",
" 0.2000 | \n",
" 0.2674 | \n",
" 0.0047 | \n",
" | \n",
" 33.68 % โ | \n",
"
\n",
" \n",
" | 16 | \n",
" mcstas | \n",
" background | \n",
" 4 | \n",
" y | \n",
" 0.2000 | \n",
" 0.2551 | \n",
" 0.0036 | \n",
" | \n",
" 27.53 % โ | \n",
"
\n",
" \n",
" | 17 | \n",
" mcstas | \n",
" background | \n",
" 5 | \n",
" y | \n",
" 0.2000 | \n",
" 0.2463 | \n",
" 0.0035 | \n",
" | \n",
" 23.17 % โ | \n",
"
\n",
" \n",
" | 18 | \n",
" mcstas | \n",
" background | \n",
" 6 | \n",
" y | \n",
" 0.2000 | \n",
" 0.2417 | \n",
" 0.0027 | \n",
" | \n",
" 20.86 % โ | \n",
"
\n",
" \n",
" | 19 | \n",
" mcstas | \n",
" background | \n",
" 7 | \n",
" y | \n",
" 0.2000 | \n",
" 0.2421 | \n",
" 0.0033 | \n",
" | \n",
" 21.07 % โ | \n",
"
\n",
" \n",
" | 20 | \n",
" mcstas | \n",
" background | \n",
" 8 | \n",
" y | \n",
" 0.2000 | \n",
" 0.2374 | \n",
" 0.0021 | \n",
" | \n",
" 18.71 % โ | \n",
"
\n",
" \n",
" | 21 | \n",
" mcstas | \n",
" background | \n",
" 9 | \n",
" y | \n",
" 0.2000 | \n",
" 0.2381 | \n",
" 0.0020 | \n",
" | \n",
" 19.07 % โ | \n",
"
\n",
" \n",
" | 22 | \n",
" mcstas | \n",
" background | \n",
" 10 | \n",
" y | \n",
" 0.2000 | \n",
" 0.2423 | \n",
" 0.0025 | \n",
" | \n",
" 21.14 % โ | \n",
"
\n",
" \n",
" | 23 | \n",
" mcstas | \n",
" background | \n",
" 11 | \n",
" y | \n",
" 0.2000 | \n",
" 0.2258 | \n",
" 0.0022 | \n",
" | \n",
" 12.88 % โ | \n",
"
\n",
" \n",
" | 24 | \n",
" mcstas | \n",
" background | \n",
" 12 | \n",
" y | \n",
" 0.2000 | \n",
" 0.2228 | \n",
" 0.0026 | \n",
" | \n",
" 11.40 % โ | \n",
"
\n",
" \n",
" | 25 | \n",
" mcstas | \n",
" background | \n",
" 13 | \n",
" y | \n",
" 0.2000 | \n",
" 0.2225 | \n",
" 0.0078 | \n",
" | \n",
" 11.23 % โ | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.analysis.fit()\n",
"project.analysis.show_fit_results()"
]
},
{
"cell_type": "markdown",
"id": "62",
"metadata": {},
"source": [
"#### Plot Measured vs Calculated"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "63",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:55:40.631483Z",
"iopub.status.busy": "2026-01-06T13:55:40.631281Z",
"iopub.status.idle": "2026-01-06T13:55:41.118980Z",
"shell.execute_reply": "2026-01-06T13:55:41.118306Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.plot_meas_vs_calc(expt_name='mcstas')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "64",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.13.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}