{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "0",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:11.741760Z",
"iopub.status.busy": "2026-08-18T18:17:11.741552Z",
"iopub.status.idle": "2026-08-18T18:17:11.746052Z",
"shell.execute_reply": "2026-08-18T18:17:11.745343Z"
},
"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": [
"# Structure Refinement: Co2SiO4, D20\n",
"\n",
"This example demonstrates a Rietveld refinement of Co2SiO4 crystal\n",
"structure using constant wavelength neutron powder diffraction data\n",
"from D20 at ILL.\n",
"\n",
"It also shows different ways to set free parameters: standard\n",
"one-by-one and batch setting."
]
},
{
"cell_type": "markdown",
"id": "2",
"metadata": {},
"source": [
"## π οΈ Import Library"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:11.747867Z",
"iopub.status.busy": "2026-08-18T18:17:11.747671Z",
"iopub.status.idle": "2026-08-18T18:17:14.591636Z",
"shell.execute_reply": "2026-08-18T18:17:14.590718Z"
}
},
"outputs": [],
"source": [
"from easydiffraction import ExperimentFactory\n",
"from easydiffraction import Project\n",
"from easydiffraction import StructureFactory\n",
"from easydiffraction import download_data"
]
},
{
"cell_type": "markdown",
"id": "4",
"metadata": {},
"source": [
"## π§© Define Structure\n",
"\n",
"This section shows how to add structures and modify their\n",
"parameters.\n",
"\n",
"### Create Structure"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:14.593681Z",
"iopub.status.busy": "2026-08-18T18:17:14.593360Z",
"iopub.status.idle": "2026-08-18T18:17:14.598717Z",
"shell.execute_reply": "2026-08-18T18:17:14.597876Z"
}
},
"outputs": [],
"source": [
"structure = StructureFactory.from_scratch(name='cosio')"
]
},
{
"cell_type": "markdown",
"id": "6",
"metadata": {},
"source": [
"### Set Space Group"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:14.600343Z",
"iopub.status.busy": "2026-08-18T18:17:14.600171Z",
"iopub.status.idle": "2026-08-18T18:17:14.603587Z",
"shell.execute_reply": "2026-08-18T18:17:14.603002Z"
}
},
"outputs": [],
"source": [
"structure.space_group.name_h_m = 'P n m a'\n",
"structure.space_group.coord_system_code = 'abc'"
]
},
{
"cell_type": "markdown",
"id": "8",
"metadata": {},
"source": [
"### Set Unit Cell"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:14.605528Z",
"iopub.status.busy": "2026-08-18T18:17:14.605340Z",
"iopub.status.idle": "2026-08-18T18:17:14.608847Z",
"shell.execute_reply": "2026-08-18T18:17:14.608172Z"
}
},
"outputs": [],
"source": [
"structure.cell.length_a = 10.3\n",
"structure.cell.length_b = 6.0\n",
"structure.cell.length_c = 4.8"
]
},
{
"cell_type": "markdown",
"id": "10",
"metadata": {},
"source": [
"### Set Atom Sites"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "11",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:14.610615Z",
"iopub.status.busy": "2026-08-18T18:17:14.610426Z",
"iopub.status.idle": "2026-08-18T18:17:14.619902Z",
"shell.execute_reply": "2026-08-18T18:17:14.618924Z"
}
},
"outputs": [],
"source": [
"structure.atom_sites.create(\n",
" id='Co1',\n",
" type_symbol='Co',\n",
" fract_x=0,\n",
" fract_y=0,\n",
" fract_z=0,\n",
" adp_iso=0.5,\n",
")\n",
"structure.atom_sites.create(\n",
" id='Co2',\n",
" type_symbol='Co',\n",
" fract_x=0.279,\n",
" fract_y=0.25,\n",
" fract_z=0.985,\n",
" adp_iso=0.5,\n",
")\n",
"structure.atom_sites.create(\n",
" id='Si',\n",
" type_symbol='Si',\n",
" fract_x=0.094,\n",
" fract_y=0.25,\n",
" fract_z=0.429,\n",
" adp_iso=0.5,\n",
")\n",
"structure.atom_sites.create(\n",
" id='O1',\n",
" type_symbol='O',\n",
" fract_x=0.091,\n",
" fract_y=0.25,\n",
" fract_z=0.771,\n",
" adp_iso=0.5,\n",
")\n",
"structure.atom_sites.create(\n",
" id='O2',\n",
" type_symbol='O',\n",
" fract_x=0.448,\n",
" fract_y=0.25,\n",
" fract_z=0.217,\n",
" adp_iso=0.5,\n",
")\n",
"structure.atom_sites.create(\n",
" id='O3',\n",
" type_symbol='O',\n",
" fract_x=0.164,\n",
" fract_y=0.032,\n",
" fract_z=0.28,\n",
" adp_iso=0.5,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "12",
"metadata": {},
"source": [
"## π¬ Define Experiment\n",
"\n",
"This section shows how to add experiments, configure their parameters,\n",
"and link the structures defined in the previous step.\n",
"\n",
"### Download Data"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "13",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:14.621563Z",
"iopub.status.busy": "2026-08-18T18:17:14.621340Z",
"iopub.status.idle": "2026-08-18T18:17:14.821211Z",
"shell.execute_reply": "2026-08-18T18:17:14.820286Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mGetting data\u001b[0m\u001b[1;36m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data \u001b[32m'meas-cosio-d20'\u001b[0m: Co2SiO4, D20 \u001b[1m(\u001b[0mILL\u001b[1m)\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β
Data \u001b[32m'meas-cosio-d20'\u001b[0m downloaded to \u001b[32m'../../../data/meas-cosio-d20.xye'\u001b[0m\n"
]
}
],
"source": [
"data_path = download_data('meas-cosio-d20', destination='data')"
]
},
{
"cell_type": "markdown",
"id": "14",
"metadata": {},
"source": [
"### Create Experiment"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "15",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:14.823082Z",
"iopub.status.busy": "2026-08-18T18:17:14.822723Z",
"iopub.status.idle": "2026-08-18T18:17:15.038272Z",
"shell.execute_reply": "2026-08-18T18:17:15.037441Z"
}
},
"outputs": [],
"source": [
"expt = ExperimentFactory.from_data_path(name='d20', data_path=data_path)"
]
},
{
"cell_type": "markdown",
"id": "16",
"metadata": {},
"source": [
"### Set Instrument"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "17",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.040583Z",
"iopub.status.busy": "2026-08-18T18:17:15.040391Z",
"iopub.status.idle": "2026-08-18T18:17:15.044171Z",
"shell.execute_reply": "2026-08-18T18:17:15.043482Z"
}
},
"outputs": [],
"source": [
"expt.instrument.setup_wavelength = 1.87\n",
"expt.instrument.calib_twotheta_offset = 0.1"
]
},
{
"cell_type": "markdown",
"id": "18",
"metadata": {},
"source": [
"### Set Peak Profile"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "19",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.045933Z",
"iopub.status.busy": "2026-08-18T18:17:15.045753Z",
"iopub.status.idle": "2026-08-18T18:17:15.054602Z",
"shell.execute_reply": "2026-08-18T18:17:15.053910Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mPeak types\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"
| | Type | Description |
|---|
| 1 | * | pseudo-voigt | CWL pseudo-Voigt profile |
|---|
| 2 | | pseudo-voigt + berar-baldinozzi asymmetry | CWL pseudo-Voigt profile with Berar-Baldinozzi asymmetry correction. |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"expt.peak.show_supported()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "20",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.056510Z",
"iopub.status.busy": "2026-08-18T18:17:15.056309Z",
"iopub.status.idle": "2026-08-18T18:17:15.063887Z",
"shell.execute_reply": "2026-08-18T18:17:15.063065Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"β οΈ Switching peak profile type adds these settings with defaults: \n",
" β’ asym_beba_a0=0.0 \n",
" β’ asym_beba_a1=0.0 \n",
" β’ asym_beba_b0=0.0 \n",
" β’ asym_beba_b1=0.0 \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mPeak profile type for experiment \u001b[0m\u001b[32m'd20'\u001b[0m\u001b[1;36m changed to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"pseudo-voigt + berar-baldinozzi asymmetry\n"
]
}
],
"source": [
"expt.peak.type = 'pseudo-voigt + berar-baldinozzi asymmetry'"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "21",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.065421Z",
"iopub.status.busy": "2026-08-18T18:17:15.065258Z",
"iopub.status.idle": "2026-08-18T18:17:15.068288Z",
"shell.execute_reply": "2026-08-18T18:17:15.067642Z"
}
},
"outputs": [],
"source": [
"expt.peak.broad_gauss_u = 0.3\n",
"expt.peak.broad_gauss_v = -0.5\n",
"expt.peak.broad_gauss_w = 0.4"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "22",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.070166Z",
"iopub.status.busy": "2026-08-18T18:17:15.069981Z",
"iopub.status.idle": "2026-08-18T18:17:15.073382Z",
"shell.execute_reply": "2026-08-18T18:17:15.072611Z"
}
},
"outputs": [],
"source": [
"expt.peak.cutoff_fwhm = 8"
]
},
{
"cell_type": "markdown",
"id": "23",
"metadata": {},
"source": [
"### Set Background"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "24",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.074936Z",
"iopub.status.busy": "2026-08-18T18:17:15.074752Z",
"iopub.status.idle": "2026-08-18T18:17:15.082136Z",
"shell.execute_reply": "2026-08-18T18:17:15.081338Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mBackground types\u001b[0m\n"
]
},
{
"data": {
"text/html": [
" | | Type | Description |
|---|
| 1 | | chebyshev | Chebyshev polynomial background |
|---|
| 2 | * | line-segment | Linear interpolation between points |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"expt.background.show_supported()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "25",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.083902Z",
"iopub.status.busy": "2026-08-18T18:17:15.083718Z",
"iopub.status.idle": "2026-08-18T18:17:15.093021Z",
"shell.execute_reply": "2026-08-18T18:17:15.092264Z"
}
},
"outputs": [],
"source": [
"expt.background.create(id='1', position=8, intensity=500)\n",
"expt.background.create(id='2', position=9, intensity=500)\n",
"expt.background.create(id='3', position=10, intensity=500)\n",
"expt.background.create(id='4', position=11, intensity=500)\n",
"expt.background.create(id='5', position=12, intensity=500)\n",
"expt.background.create(id='6', position=15, intensity=500)\n",
"expt.background.create(id='7', position=25, intensity=500)\n",
"expt.background.create(id='8', position=30, intensity=500)\n",
"expt.background.create(id='9', position=50, intensity=500)\n",
"expt.background.create(id='10', position=70, intensity=500)\n",
"expt.background.create(id='11', position=90, intensity=500)\n",
"expt.background.create(id='12', position=110, intensity=500)\n",
"expt.background.create(id='13', position=130, intensity=500)\n",
"expt.background.create(id='14', position=150, intensity=500)"
]
},
{
"cell_type": "markdown",
"id": "26",
"metadata": {},
"source": [
"### Set Linked Structures"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "27",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.094513Z",
"iopub.status.busy": "2026-08-18T18:17:15.094334Z",
"iopub.status.idle": "2026-08-18T18:17:15.097283Z",
"shell.execute_reply": "2026-08-18T18:17:15.096614Z"
}
},
"outputs": [],
"source": [
"expt.linked_structures.create(structure_id='cosio', scale=1.0)"
]
},
{
"cell_type": "markdown",
"id": "28",
"metadata": {},
"source": [
"## π¦ Define Project\n",
"\n",
"The project object is used to manage the structure, experiment, and\n",
"analysis.\n",
"\n",
"### Create Project"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "29",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.099040Z",
"iopub.status.busy": "2026-08-18T18:17:15.098889Z",
"iopub.status.idle": "2026-08-18T18:17:15.390551Z",
"shell.execute_reply": "2026-08-18T18:17:15.389596Z"
}
},
"outputs": [],
"source": [
"project = Project(name='cosio_d20')"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "30",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.392284Z",
"iopub.status.busy": "2026-08-18T18:17:15.392113Z",
"iopub.status.idle": "2026-08-18T18:17:15.437055Z",
"shell.execute_reply": "2026-08-18T18:17:15.436307Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mSaving project π¦ \u001b[0m\u001b[32m'cosio_d20'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/refine-cosio-d20'\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π project.edi\n",
"βββ π structures/\n",
"βββ π experiments/\n",
"βββ π analysis/\n",
"β βββ π analysis.edi\n",
"βββ π reports/\n",
" βββ π cosio_d20.html\n"
]
}
],
"source": [
"project.save_as(dir_path='projects/refine-cosio-d20')"
]
},
{
"cell_type": "markdown",
"id": "31",
"metadata": {},
"source": [
"### Add Structure"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "32",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.438659Z",
"iopub.status.busy": "2026-08-18T18:17:15.438498Z",
"iopub.status.idle": "2026-08-18T18:17:15.441041Z",
"shell.execute_reply": "2026-08-18T18:17:15.440392Z"
}
},
"outputs": [],
"source": [
"project.structures.add(structure)"
]
},
{
"cell_type": "markdown",
"id": "33",
"metadata": {},
"source": [
"### Add Experiment"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "34",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.442736Z",
"iopub.status.busy": "2026-08-18T18:17:15.442583Z",
"iopub.status.idle": "2026-08-18T18:17:15.445522Z",
"shell.execute_reply": "2026-08-18T18:17:15.444544Z"
}
},
"outputs": [],
"source": [
"project.experiments.add(expt)"
]
},
{
"cell_type": "markdown",
"id": "35",
"metadata": {},
"source": [
"## π Perform Analysis\n",
"\n",
"This section shows the analysis process, including how to set up\n",
"calculation and fitting engines.\n",
"\n",
"### Display Structure"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "36",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.447108Z",
"iopub.status.busy": "2026-08-18T18:17:15.446939Z",
"iopub.status.idle": "2026-08-18T18:17:15.530900Z",
"shell.execute_reply": "2026-08-18T18:17:15.530182Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mStructure π§© \u001b[0m\u001b[32m'cosio'\u001b[0m\u001b[1;36m \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36mAtom view type: \u001b[0m\u001b[32m'covalent'\u001b[0m\u001b[1;36m)\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"
\n",
"
Loading plotβ¦
\n",
"
\n",
"
\n",
"
\n",
"
drag = rotate
wheel = zoom
right-drag = pan
\n",
"
\n",
"
\n",
"\n",
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.structure(struct_name='cosio')"
]
},
{
"cell_type": "markdown",
"id": "37",
"metadata": {},
"source": [
"### Display Pattern"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "38",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.532547Z",
"iopub.status.busy": "2026-08-18T18:17:15.532340Z",
"iopub.status.idle": "2026-08-18T18:17:15.924757Z",
"shell.execute_reply": "2026-08-18T18:17:15.923957Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='d20')"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "39",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:15.928250Z",
"iopub.status.busy": "2026-08-18T18:17:15.928072Z",
"iopub.status.idle": "2026-08-18T18:17:16.157786Z",
"shell.execute_reply": "2026-08-18T18:17:16.156994Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='d20', x_min=41, x_max=54)"
]
},
{
"cell_type": "markdown",
"id": "40",
"metadata": {},
"source": [
"### Set Free Parameters"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "41",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:16.159560Z",
"iopub.status.busy": "2026-08-18T18:17:16.159378Z",
"iopub.status.idle": "2026-08-18T18:17:16.172038Z",
"shell.execute_reply": "2026-08-18T18:17:16.171288Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"β οΈ Parameter 'cosio.atom_site.Co1.fract_x' is constrained by symmetry. Ignoring free=True. \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β οΈ Parameter 'cosio.atom_site.Co1.fract_y' is constrained by symmetry. Ignoring free=True. \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β οΈ Parameter 'cosio.atom_site.Co1.fract_z' is constrained by symmetry. Ignoring free=True. \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β οΈ Parameter 'cosio.atom_site.Co2.fract_y' is constrained by symmetry. Ignoring free=True. \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β οΈ Parameter 'cosio.atom_site.Si.fract_y' is constrained by symmetry. Ignoring free=True. \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β οΈ Parameter 'cosio.atom_site.O1.fract_y' is constrained by symmetry. Ignoring free=True. \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β οΈ Parameter 'cosio.atom_site.O2.fract_y' is constrained by symmetry. Ignoring free=True. \n"
]
}
],
"source": [
"structure.cell.length_a.free = True\n",
"structure.cell.length_b.free = True\n",
"structure.cell.length_c.free = True\n",
"\n",
"for atom_site in structure.atom_sites:\n",
" for parameter in ('fract_x', 'fract_y', 'fract_z'):\n",
" getattr(atom_site, parameter).free = True\n",
"\n",
"for atom_site in structure.atom_sites:\n",
" atom_site.adp_iso.free = True\n",
"\n",
"for label in ('O1', 'O2', 'O3'):\n",
" atom_site = structure.atom_sites[label]\n",
" atom_site.occupancy.free = True"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "42",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:16.173958Z",
"iopub.status.busy": "2026-08-18T18:17:16.173645Z",
"iopub.status.idle": "2026-08-18T18:17:16.177973Z",
"shell.execute_reply": "2026-08-18T18:17:16.177318Z"
}
},
"outputs": [],
"source": [
"expt.linked_structures['cosio'].scale.free = True\n",
"\n",
"expt.instrument.calib_twotheta_offset.free = True\n",
"\n",
"expt.peak.broad_gauss_u.free = True\n",
"expt.peak.broad_gauss_v.free = True\n",
"expt.peak.broad_gauss_w.free = True\n",
"expt.peak.broad_lorentz_y.free = True\n",
"\n",
"expt.peak.asym_beba_b0.free = True\n",
"\n",
"for point in expt.background:\n",
" point.intensity.free = True"
]
},
{
"cell_type": "markdown",
"id": "43",
"metadata": {},
"source": [
"Show free parameters after selection."
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "44",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:16.179760Z",
"iopub.status.busy": "2026-08-18T18:17:16.179591Z",
"iopub.status.idle": "2026-08-18T18:17:16.285972Z",
"shell.execute_reply": "2026-08-18T18:17:16.285093Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mFree parameters for both structures \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36mπ§© data blocks\u001b[0m\u001b[1;36m)\u001b[0m\u001b[1;36m and experiments \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36mπ¬ data blocks\u001b[0m\u001b[1;36m)\u001b[0m\n"
]
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.parameters.free()"
]
},
{
"cell_type": "markdown",
"id": "45",
"metadata": {},
"source": [
"### Set Constraints\n",
"\n",
"Set aliases for parameters."
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "46",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:16.287650Z",
"iopub.status.busy": "2026-08-18T18:17:16.287422Z",
"iopub.status.idle": "2026-08-18T18:17:16.291818Z",
"shell.execute_reply": "2026-08-18T18:17:16.291089Z"
}
},
"outputs": [],
"source": [
"project.analysis.aliases.create(\n",
" id='biso_Co1',\n",
" param=project.structures['cosio'].atom_sites['Co1'].adp_iso,\n",
")\n",
"project.analysis.aliases.create(\n",
" id='biso_Co2',\n",
" param=project.structures['cosio'].atom_sites['Co2'].adp_iso,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "47",
"metadata": {},
"source": [
"Set constraints."
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "48",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:16.293653Z",
"iopub.status.busy": "2026-08-18T18:17:16.293429Z",
"iopub.status.idle": "2026-08-18T18:17:16.297020Z",
"shell.execute_reply": "2026-08-18T18:17:16.296275Z"
},
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"project.analysis.constraints.create(expression='biso_Co2 = biso_Co1')"
]
},
{
"cell_type": "markdown",
"id": "49",
"metadata": {},
"source": [
"### Run Fitting"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "50",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:17:16.298755Z",
"iopub.status.busy": "2026-08-18T18:17:16.298562Z",
"iopub.status.idle": "2026-08-18T18:18:12.168570Z",
"shell.execute_reply": "2026-08-18T18:18:12.167862Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-778439baccbb4f28b643143aea735395-button');\n",
" const status = document.getElementById('ed-fit-stop-778439baccbb4f28b643143aea735395-status');\n",
" const kernelId = '';\n",
" if (!button) {\n",
" return;\n",
" }\n",
"\n",
" function setStatus(text) {\n",
" if (status) {\n",
" status.textContent = text;\n",
" }\n",
" }\n",
"\n",
" function pageConfig() {\n",
" const element = document.getElementById('jupyter-config-data');\n",
" if (!element || !element.textContent) {\n",
" return {};\n",
" }\n",
" try {\n",
" return JSON.parse(element.textContent);\n",
" } catch (error) {\n",
" return {};\n",
" }\n",
" }\n",
"\n",
" function baseUrl(config) {\n",
" const configured = config.baseUrl || config.base_url ||\n",
" (window.Jupyter && Jupyter.notebook && Jupyter.notebook.base_url);\n",
" if (configured) {\n",
" return configured.endsWith('/') ? configured : configured + '/';\n",
" }\n",
" const markers = ['/lab/', '/notebooks/', '/tree/'];\n",
" for (const marker of markers) {\n",
" const index = window.location.pathname.indexOf(marker);\n",
" if (index >= 0) {\n",
" return window.location.pathname.slice(0, index + 1);\n",
" }\n",
" }\n",
" return '/';\n",
" }\n",
"\n",
" function token(config) {\n",
" return config.token || new URLSearchParams(window.location.search).get('token') || '';\n",
" }\n",
"\n",
" function cookie(name) {\n",
" const prefix = name + '=';\n",
" for (const part of document.cookie.split(';')) {\n",
" const trimmed = part.trim();\n",
" if (trimmed.startsWith(prefix)) {\n",
" return decodeURIComponent(trimmed.slice(prefix.length));\n",
" }\n",
" }\n",
" return '';\n",
" }\n",
"\n",
" function notebookPath() {\n",
" const decoded = decodeURIComponent(window.location.pathname);\n",
" const markers = ['/lab/tree/', '/notebooks/', '/tree/'];\n",
" for (const marker of markers) {\n",
" const index = decoded.indexOf(marker);\n",
" if (index >= 0) {\n",
" return decoded.slice(index + marker.length);\n",
" }\n",
" }\n",
" return '';\n",
" }\n",
"\n",
" async function kernelFromSessions(config) {\n",
" const url = new URL(baseUrl(config) + 'api/sessions', window.location.origin);\n",
" const authToken = token(config);\n",
" if (authToken) {\n",
" url.searchParams.set('token', authToken);\n",
" }\n",
" const response = await fetch(url, {credentials: 'same-origin'});\n",
" if (!response.ok) {\n",
" return '';\n",
" }\n",
" const sessions = await response.json();\n",
" const path = notebookPath();\n",
" const session = sessions.find((item) => item.path === path) || sessions[0];\n",
" return session && session.kernel ? session.kernel.id : '';\n",
" }\n",
"\n",
" async function interruptKernel(config, resolvedKernelId) {\n",
" const url = new URL(\n",
" baseUrl(config) + 'api/kernels/' + resolvedKernelId + '/interrupt',\n",
" window.location.origin\n",
" );\n",
" const authToken = token(config);\n",
" if (authToken) {\n",
" url.searchParams.set('token', authToken);\n",
" }\n",
" const xsrfToken = cookie('_xsrf');\n",
" const headers = {};\n",
" if (xsrfToken) {\n",
" headers['X-XSRFToken'] = xsrfToken;\n",
" }\n",
" const response = await fetch(url, {\n",
" method: 'POST',\n",
" credentials: 'same-origin',\n",
" headers: headers\n",
" });\n",
" return response.ok;\n",
" }\n",
"\n",
" button.addEventListener('click', async function() {\n",
" button.disabled = true;\n",
" setStatus('Stopping...');\n",
" const config = pageConfig();\n",
" try {\n",
" const resolvedKernelId = kernelId || await kernelFromSessions(config);\n",
" if (!resolvedKernelId) {\n",
" throw new Error('Could not resolve the current kernel id.');\n",
" }\n",
" const interrupted = await interruptKernel(config, resolvedKernelId);\n",
" if (!interrupted) {\n",
" throw new Error('Jupyter Server rejected the interrupt request.');\n",
" }\n",
" setStatus('Interrupt sent...');\n",
" } catch (error) {\n",
" button.disabled = false;\n",
" setStatus('Use Kernel > Interrupt to stop this fit.');\n",
" }\n",
" });\n",
"})();\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mStandard fitting\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Using experiment π¬ \u001b[32m'd20'\u001b[0m for \u001b[32m'single'\u001b[0m fitting\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 progress:\n"
]
},
{
"data": {
"text/html": [
" | iteration | time (s) | ΟΒ² | change / status |
|---|
| 1 | 1 | 0.06 | 424.43 | |
|---|
| 2 | 47 | 3.65 | 73.81 | 82.6% β |
|---|
| 3 | 91 | 7.17 | 39.81 | 46.1% β |
|---|
| 4 | 136 | 11.56 | 19.19 | 51.8% β |
|---|
| 5 | 178 | 16.96 | 19.19 | |
|---|
| 6 | 180 | 17.27 | 12.76 | 33.5% β |
|---|
| 7 | 219 | 22.31 | 12.76 | |
|---|
| 8 | 224 | 23.17 | 7.64 | 40.1% β |
|---|
| 9 | 265 | 28.21 | 7.64 | |
|---|
| 10 | 268 | 28.44 | 4.61 | 39.6% β |
|---|
| 11 | 308 | 33.50 | 4.61 | |
|---|
| 12 | 312 | 33.81 | 4.38 | 5.0% β |
|---|
| 13 | 353 | 38.84 | 4.38 | |
|---|
| 14 | 409 | 44.09 | 4.38 | |
|---|
| 15 | 472 | 49.41 | 4.38 | |
|---|
| 16 | 533 | 55.79 | 4.38 | |
|---|
"
],
"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;36m4.38\u001b[0m at iteration \u001b[1;36m516\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β
Fitting complete.\n"
]
}
],
"source": [
"project.analysis.fit()"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "51",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:18:12.170384Z",
"iopub.status.busy": "2026-08-18T18:18:12.170187Z",
"iopub.status.idle": "2026-08-18T18:18:12.617662Z",
"shell.execute_reply": "2026-08-18T18:18:12.616866Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"βοΈ Settings used:\n"
]
},
{
"data": {
"text/html": [
" | Name | Value | Description |
|---|
| 1 | max_iterations | 1000 | Maximum solver iterations. |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Least-squares fit results:\n"
]
},
{
"data": {
"text/html": [
" | Metric | Value |
|---|
| 1 | π§ͺ Minimizer | lmfit (leastsq) |
|---|
| 2 | β
Overall status | success |
|---|
| 3 | β±οΈ Fitting time (seconds) | 55.79 |
|---|
| 4 | π Iterations | 530 |
|---|
| 5 | π Goodness-of-fit (reduced ΟΒ²) | 4.38 |
|---|
| 6 | π R-factor (Rf, %) | 2.99 |
|---|
| 7 | π R-factor squared (RfΒ², %) | 4.32 |
|---|
| 8 | π Weighted R-factor (wR, %) | 4.54 |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Refined parameters:\n"
]
},
{
"data": {
"text/html": [
" | datablock | category | entry | parameter | units | start | value | s.u. | change |
|---|
| 1 | cosio | cell | | length_a | Γ
| 10.3000 | 10.3084 | 0.0003 | 0.08 % β |
|---|
| 2 | cosio | cell | | length_b | Γ
| 6.0000 | 6.0036 | 0.0002 | 0.06 % β |
|---|
| 3 | cosio | cell | | length_c | Γ
| 4.8000 | 4.7864 | 0.0001 | 0.28 % β |
|---|
| 4 | cosio | atom_site | Co1 | adp_iso | Γ
Β² | 0.5000 | 0.6716 | 0.1079 | 34.33 % β |
|---|
| 5 | cosio | atom_site | Co2 | fract_x | | 0.2790 | 0.2792 | 0.0007 | 0.07 % β |
|---|
| 6 | cosio | atom_site | Co2 | fract_z | | 0.9850 | 0.9850 | 0.0014 | 0.00 % β |
|---|
| 7 | cosio | atom_site | Si | fract_x | | 0.0940 | 0.0938 | 0.0004 | 0.26 % β |
|---|
| 8 | cosio | atom_site | Si | fract_z | | 0.4290 | 0.4294 | 0.0008 | 0.08 % β |
|---|
| 9 | cosio | atom_site | Si | adp_iso | Γ
Β² | 0.5000 | 0.6864 | 0.0884 | 37.28 % β |
|---|
| 10 | cosio | atom_site | O1 | fract_x | | 0.0910 | 0.0911 | 0.0003 | 0.14 % β |
|---|
| 11 | cosio | atom_site | O1 | fract_z | | 0.7710 | 0.7715 | 0.0006 | 0.07 % β |
|---|
| 12 | cosio | atom_site | O1 | occupancy | | 1.0000 | 0.9148 | 0.0136 | 8.52 % β |
|---|
| 13 | cosio | atom_site | O1 | adp_iso | Γ
Β² | 0.5000 | 0.4662 | 0.0775 | 6.77 % β |
|---|
| 14 | cosio | atom_site | O2 | fract_x | | 0.4480 | 0.4482 | 0.0003 | 0.04 % β |
|---|
| 15 | cosio | atom_site | O2 | fract_z | | 0.2170 | 0.2171 | 0.0007 | 0.04 % β |
|---|
| 16 | cosio | atom_site | O2 | occupancy | | 1.0000 | 0.9588 | 0.0135 | 4.12 % β |
|---|
| 17 | cosio | atom_site | O2 | adp_iso | Γ
Β² | 0.5000 | 0.6713 | 0.0795 | 34.26 % β |
|---|
| 18 | cosio | atom_site | O3 | fract_x | | 0.1640 | 0.1636 | 0.0002 | 0.23 % β |
|---|
| 19 | cosio | atom_site | O3 | fract_y | | 0.0320 | 0.0315 | 0.0003 | 1.47 % β |
|---|
| 20 | cosio | atom_site | O3 | fract_z | | 0.2800 | 0.2802 | 0.0005 | 0.07 % β |
|---|
| 21 | cosio | atom_site | O3 | occupancy | | 1.0000 | 0.9548 | 0.0118 | 4.52 % β |
|---|
| 22 | cosio | atom_site | O3 | adp_iso | Γ
Β² | 0.5000 | 0.8499 | 0.0614 | 69.99 % β |
|---|
| 23 | d20 | linked_structure | cosio | scale | | 1.0000 | 1.3307 | 0.0289 | 33.07 % β |
|---|
| 24 | d20 | peak | | asym_beba_b0 | | 0.0000 | -0.0087 | 0.0019 | N/A |
|---|
| 25 | d20 | peak | | broad_gauss_u | degΒ² | 0.3000 | 0.2422 | 0.0066 | 19.26 % β |
|---|
| 26 | d20 | peak | | broad_gauss_v | degΒ² | -0.5000 | -0.5309 | 0.0143 | 6.17 % β |
|---|
| 27 | d20 | peak | | broad_gauss_w | degΒ² | 0.4000 | 0.3884 | 0.0089 | 2.91 % β |
|---|
| 28 | d20 | peak | | broad_lorentz_y | deg | 0.0000 | 0.0134 | 0.0043 | N/A |
|---|
| 29 | d20 | instrument | | twotheta_offset | deg | 0.1000 | 0.2762 | 0.0033 | 176.23 % β |
|---|
| 30 | d20 | background | 1 | intensity | | 500.0000 | 609.3228 | 14.2442 | 21.86 % β |
|---|
| 31 | d20 | background | 2 | intensity | | 500.0000 | 581.1915 | 9.5285 | 16.24 % β |
|---|
| 32 | d20 | background | 3 | intensity | | 500.0000 | 563.3757 | 9.0531 | 12.68 % β |
|---|
| 33 | d20 | background | 4 | intensity | | 500.0000 | 540.7175 | 8.5904 | 8.14 % β |
|---|
| 34 | d20 | background | 5 | intensity | | 500.0000 | 520.1578 | 5.9256 | 4.03 % β |
|---|
| 35 | d20 | background | 6 | intensity | | 500.0000 | 507.7804 | 3.4171 | 1.56 % β |
|---|
| 36 | d20 | background | 7 | intensity | | 500.0000 | 463.0315 | 3.1418 | 7.39 % β |
|---|
| 37 | d20 | background | 8 | intensity | | 500.0000 | 430.9893 | 2.4269 | 13.80 % β |
|---|
| 38 | d20 | background | 9 | intensity | | 500.0000 | 451.8045 | 2.1831 | 9.64 % β |
|---|
| 39 | d20 | background | 10 | intensity | | 500.0000 | 429.4275 | 1.9786 | 14.11 % β |
|---|
| 40 | d20 | background | 11 | intensity | | 500.0000 | 414.1454 | 2.1448 | 17.17 % β |
|---|
| 41 | d20 | background | 12 | intensity | | 500.0000 | 362.4173 | 2.0131 | 27.52 % β |
|---|
| 42 | d20 | background | 13 | intensity | | 500.0000 | 293.1495 | 1.9075 | 41.37 % β |
|---|
| 43 | d20 | background | 14 | intensity | | 500.0000 | 241.3362 | 2.8958 | 51.73 % β |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
" β’ start = parameter value before refinement
β’ value = refined value from least-squares minimization
β’ s.u. = standard uncertainty (one sigma), from the covariance matrix
β’ change = relative change from start, in %; β = increase, β = decrease
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.fit.results()"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "52",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:18:12.619190Z",
"iopub.status.busy": "2026-08-18T18:18:12.619019Z",
"iopub.status.idle": "2026-08-18T18:18:12.650330Z",
"shell.execute_reply": "2026-08-18T18:18:12.649717Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.fit.correlations()"
]
},
{
"cell_type": "markdown",
"id": "53",
"metadata": {},
"source": [
"### Display Pattern"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "54",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:18:12.652270Z",
"iopub.status.busy": "2026-08-18T18:18:12.652087Z",
"iopub.status.idle": "2026-08-18T18:18:12.735165Z",
"shell.execute_reply": "2026-08-18T18:18:12.734486Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='d20')"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "55",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:18:12.738216Z",
"iopub.status.busy": "2026-08-18T18:18:12.738032Z",
"iopub.status.idle": "2026-08-18T18:18:12.843644Z",
"shell.execute_reply": "2026-08-18T18:18:12.843223Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='d20', x_min=42, x_max=52)"
]
},
{
"cell_type": "markdown",
"id": "56",
"metadata": {},
"source": [
"## π Report\n",
"\n",
"The HTML report is written automatically when the project is saved;\n",
"enable `project.report.pdf` as well for a PDF version."
]
},
{
"cell_type": "markdown",
"id": "57",
"metadata": {},
"source": [
"## πΎ Save Project\n",
"\n",
"Save the fitted parameters and analysis results."
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "58",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:18:12.850190Z",
"iopub.status.busy": "2026-08-18T18:18:12.849982Z",
"iopub.status.idle": "2026-08-18T18:18:13.184780Z",
"shell.execute_reply": "2026-08-18T18:18:13.184010Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mSaving project π¦ \u001b[0m\u001b[32m'cosio_d20'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/refine-cosio-d20'\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π project.edi\n",
"βββ π structures/\n",
"β βββ π cosio.edi\n",
"βββ π experiments/\n",
"β βββ π d20.edi\n",
"βββ π analysis/\n",
"β βββ π analysis.edi\n",
"βββ π reports/\n",
" βββ π cosio_d20.html\n"
]
}
],
"source": [
"project.save()"
]
}
],
"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
}