{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "0",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:36:34.986126Z",
"iopub.status.busy": "2026-06-30T22:36:34.985894Z",
"iopub.status.idle": "2026-06-30T22:36:34.990219Z",
"shell.execute_reply": "2026-06-30T22:36:34.989401Z"
},
"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": [
"# 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-06-30T22:36:34.992122Z",
"iopub.status.busy": "2026-06-30T22:36:34.991906Z",
"iopub.status.idle": "2026-06-30T22:36:37.831856Z",
"shell.execute_reply": "2026-06-30T22:36:37.830853Z"
}
},
"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-06-30T22:36:37.833639Z",
"iopub.status.busy": "2026-06-30T22:36:37.833358Z",
"iopub.status.idle": "2026-06-30T22:36:37.838197Z",
"shell.execute_reply": "2026-06-30T22:36:37.837380Z"
}
},
"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-06-30T22:36:37.839580Z",
"iopub.status.busy": "2026-06-30T22:36:37.839429Z",
"iopub.status.idle": "2026-06-30T22:36:37.842593Z",
"shell.execute_reply": "2026-06-30T22:36:37.841534Z"
}
},
"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-06-30T22:36:37.843945Z",
"iopub.status.busy": "2026-06-30T22:36:37.843792Z",
"iopub.status.idle": "2026-06-30T22:36:37.846657Z",
"shell.execute_reply": "2026-06-30T22:36:37.845964Z"
}
},
"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-06-30T22:36:37.848074Z",
"iopub.status.busy": "2026-06-30T22:36:37.847916Z",
"iopub.status.idle": "2026-06-30T22:36:37.856329Z",
"shell.execute_reply": "2026-06-30T22:36:37.855631Z"
}
},
"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-06-30T22:36:37.858069Z",
"iopub.status.busy": "2026-06-30T22:36:37.857832Z",
"iopub.status.idle": "2026-06-30T22:36:38.109856Z",
"shell.execute_reply": "2026-06-30T22:36:38.108819Z"
}
},
"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-06-30T22:36:38.111579Z",
"iopub.status.busy": "2026-06-30T22:36:38.111427Z",
"iopub.status.idle": "2026-06-30T22:36:38.320334Z",
"shell.execute_reply": "2026-06-30T22:36:38.319555Z"
}
},
"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-06-30T22:36:38.321936Z",
"iopub.status.busy": "2026-06-30T22:36:38.321773Z",
"iopub.status.idle": "2026-06-30T22:36:38.324754Z",
"shell.execute_reply": "2026-06-30T22:36:38.323932Z"
}
},
"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-06-30T22:36:38.326219Z",
"iopub.status.busy": "2026-06-30T22:36:38.326044Z",
"iopub.status.idle": "2026-06-30T22:36:38.336153Z",
"shell.execute_reply": "2026-06-30T22:36:38.335301Z"
}
},
"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-06-30T22:36:38.337586Z",
"iopub.status.busy": "2026-06-30T22:36:38.337420Z",
"iopub.status.idle": "2026-06-30T22:36:38.343927Z",
"shell.execute_reply": "2026-06-30T22:36:38.343122Z"
}
},
"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-06-30T22:36:38.345270Z",
"iopub.status.busy": "2026-06-30T22:36:38.345122Z",
"iopub.status.idle": "2026-06-30T22:36:38.348236Z",
"shell.execute_reply": "2026-06-30T22:36:38.347396Z"
}
},
"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-06-30T22:36:38.349796Z",
"iopub.status.busy": "2026-06-30T22:36:38.349613Z",
"iopub.status.idle": "2026-06-30T22:36:38.352392Z",
"shell.execute_reply": "2026-06-30T22:36:38.351807Z"
}
},
"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-06-30T22:36:38.354127Z",
"iopub.status.busy": "2026-06-30T22:36:38.353971Z",
"iopub.status.idle": "2026-06-30T22:36:38.360603Z",
"shell.execute_reply": "2026-06-30T22:36:38.359809Z"
}
},
"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-06-30T22:36:38.362001Z",
"iopub.status.busy": "2026-06-30T22:36:38.361862Z",
"iopub.status.idle": "2026-06-30T22:36:38.369713Z",
"shell.execute_reply": "2026-06-30T22:36:38.368848Z"
}
},
"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-06-30T22:36:38.371370Z",
"iopub.status.busy": "2026-06-30T22:36:38.371188Z",
"iopub.status.idle": "2026-06-30T22:36:38.374631Z",
"shell.execute_reply": "2026-06-30T22:36:38.373683Z"
}
},
"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-06-30T22:36:38.376009Z",
"iopub.status.busy": "2026-06-30T22:36:38.375866Z",
"iopub.status.idle": "2026-06-30T22:36:38.588811Z",
"shell.execute_reply": "2026-06-30T22:36:38.587977Z"
}
},
"outputs": [],
"source": [
"project = Project(name='cosio_d20')"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "30",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:36:38.590452Z",
"iopub.status.busy": "2026-06-30T22:36:38.590291Z",
"iopub.status.idle": "2026-06-30T22:36:38.639627Z",
"shell.execute_reply": "2026-06-30T22:36:38.638831Z"
}
},
"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"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π structures/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π experiments/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π analysis/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π analysis.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π reports/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" βββ π 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-06-30T22:36:38.641134Z",
"iopub.status.busy": "2026-06-30T22:36:38.640968Z",
"iopub.status.idle": "2026-06-30T22:36:38.643645Z",
"shell.execute_reply": "2026-06-30T22:36:38.642901Z"
}
},
"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-06-30T22:36:38.645301Z",
"iopub.status.busy": "2026-06-30T22:36:38.645166Z",
"iopub.status.idle": "2026-06-30T22:36:38.647856Z",
"shell.execute_reply": "2026-06-30T22:36:38.647063Z"
}
},
"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-06-30T22:36:38.649212Z",
"iopub.status.busy": "2026-06-30T22:36:38.649061Z",
"iopub.status.idle": "2026-06-30T22:36:38.745404Z",
"shell.execute_reply": "2026-06-30T22:36:38.744737Z"
}
},
"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-06-30T22:36:38.746938Z",
"iopub.status.busy": "2026-06-30T22:36:38.746766Z",
"iopub.status.idle": "2026-06-30T22:36:39.280492Z",
"shell.execute_reply": "2026-06-30T22:36:39.279745Z"
}
},
"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-06-30T22:36:39.284354Z",
"iopub.status.busy": "2026-06-30T22:36:39.284190Z",
"iopub.status.idle": "2026-06-30T22:36:39.332468Z",
"shell.execute_reply": "2026-06-30T22:36:39.331794Z"
}
},
"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-06-30T22:36:39.334118Z",
"iopub.status.busy": "2026-06-30T22:36:39.333949Z",
"iopub.status.idle": "2026-06-30T22:36:39.345913Z",
"shell.execute_reply": "2026-06-30T22:36:39.345171Z"
}
},
"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-06-30T22:36:39.347466Z",
"iopub.status.busy": "2026-06-30T22:36:39.347304Z",
"iopub.status.idle": "2026-06-30T22:36:39.351306Z",
"shell.execute_reply": "2026-06-30T22:36:39.350596Z"
}
},
"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-06-30T22:36:39.352732Z",
"iopub.status.busy": "2026-06-30T22:36:39.352572Z",
"iopub.status.idle": "2026-06-30T22:36:39.454130Z",
"shell.execute_reply": "2026-06-30T22:36:39.453287Z"
}
},
"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-06-30T22:36:39.455657Z",
"iopub.status.busy": "2026-06-30T22:36:39.455500Z",
"iopub.status.idle": "2026-06-30T22:36:39.459254Z",
"shell.execute_reply": "2026-06-30T22:36:39.458490Z"
}
},
"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-06-30T22:36:39.460684Z",
"iopub.status.busy": "2026-06-30T22:36:39.460531Z",
"iopub.status.idle": "2026-06-30T22:36:39.463793Z",
"shell.execute_reply": "2026-06-30T22:36:39.462953Z"
},
"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-06-30T22:36:39.465337Z",
"iopub.status.busy": "2026-06-30T22:36:39.465177Z",
"iopub.status.idle": "2026-06-30T22:37:20.512899Z",
"shell.execute_reply": "2026-06-30T22:37:20.512034Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-d1f77d81dcbe40bfb572035f20588d5c-button');\n",
" const status = document.getElementById('ed-fit-stop-d1f77d81dcbe40bfb572035f20588d5c-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.07 | 424.43 | |
|---|
| 2 | 47 | 3.38 | 73.81 | 82.6% β |
|---|
| 3 | 91 | 6.63 | 39.81 | 46.1% β |
|---|
| 4 | 136 | 10.14 | 19.19 | 51.8% β |
|---|
| 5 | 180 | 13.34 | 12.76 | 33.5% β |
|---|
| 6 | 224 | 16.54 | 7.64 | 40.1% β |
|---|
| 7 | 268 | 19.72 | 4.61 | 39.6% β |
|---|
| 8 | 312 | 22.98 | 4.38 | 5.0% β |
|---|
| 9 | 378 | 28.02 | 4.38 | |
|---|
| 10 | 447 | 33.02 | 4.38 | |
|---|
| 11 | 513 | 38.06 | 4.38 | |
|---|
| 12 | 533 | 40.66 | 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"
]
},
{
"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"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π structures/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π cosio.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π experiments/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π d20.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π analysis/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π analysis.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π reports/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" βββ π cosio_d20.html\n"
]
}
],
"source": [
"project.analysis.fit()"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "51",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:20.514450Z",
"iopub.status.busy": "2026-06-30T22:37:20.514296Z",
"iopub.status.idle": "2026-06-30T22:37:20.899793Z",
"shell.execute_reply": "2026-06-30T22:37:20.899014Z"
}
},
"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) | 40.66 |
|---|
| 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-06-30T22:37:20.901615Z",
"iopub.status.busy": "2026-06-30T22:37:20.901457Z",
"iopub.status.idle": "2026-06-30T22:37:20.930542Z",
"shell.execute_reply": "2026-06-30T22:37:20.929712Z"
}
},
"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-06-30T22:37:20.932338Z",
"iopub.status.busy": "2026-06-30T22:37:20.932185Z",
"iopub.status.idle": "2026-06-30T22:37:21.005009Z",
"shell.execute_reply": "2026-06-30T22:37:21.004119Z"
}
},
"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-06-30T22:37:21.007813Z",
"iopub.status.busy": "2026-06-30T22:37:21.007635Z",
"iopub.status.idle": "2026-06-30T22:37:21.101871Z",
"shell.execute_reply": "2026-06-30T22:37:21.100912Z"
}
},
"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."
]
}
],
"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
}