{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:12.382785Z", "iopub.status.busy": "2026-06-30T22:30:12.382617Z", "iopub.status.idle": "2026-06-30T22:30:12.388902Z", "shell.execute_reply": "2026-06-30T22:30:12.388416Z" }, "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": [ "# Calculation Without Data: Si, TOF\n", "\n", "This example shows how to **calculate and plot a time-of-flight\n", "diffraction pattern without any measured data**. As with the\n", "constant-wavelength example, the structure, instrument, peak profile,\n", "and background are defined in code, and the pattern is computed over a\n", "calculation range.\n", "\n", "For a time-of-flight instrument an absolute time window is meaningless\n", "without a calibration, so the default `data_range` is derived from the\n", "instrument's TOF calibration. No data file is downloaded or loaded.\n", "\n", "For this example, a time-of-flight neutron powder experiment for Si is\n", "used." ] }, { "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:30:12.390738Z", "iopub.status.busy": "2026-06-30T22:30:12.390554Z", "iopub.status.idle": "2026-06-30T22:30:15.512135Z", "shell.execute_reply": "2026-06-30T22:30:15.511215Z" } }, "outputs": [], "source": [ "import easydiffraction as edi" ] }, { "cell_type": "markdown", "id": "4", "metadata": {}, "source": [ "## πŸ“¦ Define Project" ] }, { "cell_type": "code", "execution_count": 3, "id": "5", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:15.513726Z", "iopub.status.busy": "2026-06-30T22:30:15.513448Z", "iopub.status.idle": "2026-06-30T22:30:15.755057Z", "shell.execute_reply": "2026-06-30T22:30:15.754209Z" } }, "outputs": [], "source": [ "project = edi.Project(name='si_simulation')" ] }, { "cell_type": "markdown", "id": "6", "metadata": {}, "source": [ "## 🧩 Define Structure" ] }, { "cell_type": "code", "execution_count": 4, "id": "7", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:15.756857Z", "iopub.status.busy": "2026-06-30T22:30:15.756670Z", "iopub.status.idle": "2026-06-30T22:30:15.759832Z", "shell.execute_reply": "2026-06-30T22:30:15.759191Z" } }, "outputs": [], "source": [ "project.structures.create(name='si')" ] }, { "cell_type": "code", "execution_count": 5, "id": "8", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:15.761590Z", "iopub.status.busy": "2026-06-30T22:30:15.761419Z", "iopub.status.idle": "2026-06-30T22:30:15.764563Z", "shell.execute_reply": "2026-06-30T22:30:15.763772Z" } }, "outputs": [], "source": [ "structure = project.structures['si']" ] }, { "cell_type": "code", "execution_count": 6, "id": "9", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:15.765979Z", "iopub.status.busy": "2026-06-30T22:30:15.765827Z", "iopub.status.idle": "2026-06-30T22:30:15.768761Z", "shell.execute_reply": "2026-06-30T22:30:15.768060Z" } }, "outputs": [], "source": [ "structure.space_group.name_h_m = 'F d -3 m'\n", "structure.space_group.coord_system_code = '2'" ] }, { "cell_type": "code", "execution_count": 7, "id": "10", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:15.770445Z", "iopub.status.busy": "2026-06-30T22:30:15.770294Z", "iopub.status.idle": "2026-06-30T22:30:15.772929Z", "shell.execute_reply": "2026-06-30T22:30:15.772297Z" } }, "outputs": [], "source": [ "structure.cell.length_a = 5.431" ] }, { "cell_type": "code", "execution_count": 8, "id": "11", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:15.774544Z", "iopub.status.busy": "2026-06-30T22:30:15.774381Z", "iopub.status.idle": "2026-06-30T22:30:15.778013Z", "shell.execute_reply": "2026-06-30T22:30:15.777310Z" } }, "outputs": [], "source": [ "structure.atom_sites.create(\n", " id='Si',\n", " type_symbol='Si',\n", " fract_x=0.125,\n", " fract_y=0.125,\n", " fract_z=0.125,\n", " adp_iso=0.5,\n", ")" ] }, { "cell_type": "code", "execution_count": 9, "id": "12", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:15.779650Z", "iopub.status.busy": "2026-06-30T22:30:15.779500Z", "iopub.status.idle": "2026-06-30T22:30:16.098825Z", "shell.execute_reply": "2026-06-30T22:30:16.097910Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mStructure 🧩 \u001b[0m\u001b[32m'si'\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='si')" ] }, { "cell_type": "markdown", "id": "13", "metadata": {}, "source": [ "## πŸ”¬ Define Experiment\n", "\n", "### Create Experiment Without Data" ] }, { "cell_type": "code", "execution_count": 10, "id": "14", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:16.100360Z", "iopub.status.busy": "2026-06-30T22:30:16.100196Z", "iopub.status.idle": "2026-06-30T22:30:16.137797Z", "shell.execute_reply": "2026-06-30T22:30:16.137047Z" } }, "outputs": [], "source": [ "project.experiments.create(\n", " name='sim',\n", " sample_form='powder',\n", " beam_mode='time-of-flight',\n", " radiation_probe='neutron',\n", ")" ] }, { "cell_type": "code", "execution_count": 11, "id": "15", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:16.141070Z", "iopub.status.busy": "2026-06-30T22:30:16.140871Z", "iopub.status.idle": "2026-06-30T22:30:16.145996Z", "shell.execute_reply": "2026-06-30T22:30:16.145209Z" } }, "outputs": [], "source": [ "experiment = project.experiments['sim']" ] }, { "cell_type": "markdown", "id": "16", "metadata": {}, "source": [ "### Set Instrument\n", "\n", "The TOF calibration (offset, linear, and quadratic d-to-TOF terms) is\n", "what converts the default d-spacing window into a time window." ] }, { "cell_type": "code", "execution_count": 12, "id": "17", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:16.147826Z", "iopub.status.busy": "2026-06-30T22:30:16.147653Z", "iopub.status.idle": "2026-06-30T22:30:16.156645Z", "shell.execute_reply": "2026-06-30T22:30:16.153034Z" } }, "outputs": [], "source": [ "experiment.instrument.setup_twotheta_bank = 144.845\n", "experiment.instrument.calib_d_to_tof_offset = 0.0\n", "experiment.instrument.calib_d_to_tof_linear = 7476.91\n", "experiment.instrument.calib_d_to_tof_quadratic = -1.54" ] }, { "cell_type": "markdown", "id": "18", "metadata": {}, "source": [ "### Set Peak Profile" ] }, { "cell_type": "code", "execution_count": 13, "id": "19", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:16.159580Z", "iopub.status.busy": "2026-06-30T22:30:16.159401Z", "iopub.status.idle": "2026-06-30T22:30:16.166193Z", "shell.execute_reply": "2026-06-30T22:30:16.165022Z" } }, "outputs": [], "source": [ "experiment.peak.broad_gauss_sigma_0 = 3.0\n", "experiment.peak.broad_gauss_sigma_1 = 40.0\n", "experiment.peak.broad_gauss_sigma_2 = 2.0\n", "experiment.peak.decay_beta_0 = 0.04221\n", "experiment.peak.decay_beta_1 = 0.00946\n", "experiment.peak.rise_alpha_0 = 0.0\n", "experiment.peak.rise_alpha_1 = 0.5971" ] }, { "cell_type": "markdown", "id": "20", "metadata": {}, "source": [ "### Set Background" ] }, { "cell_type": "code", "execution_count": 14, "id": "21", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:16.169212Z", "iopub.status.busy": "2026-06-30T22:30:16.167778Z", "iopub.status.idle": "2026-06-30T22:30:16.185599Z", "shell.execute_reply": "2026-06-30T22:30:16.183110Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mBackground type for experiment \u001b[0m\u001b[32m'sim'\u001b[0m\u001b[1;36m already set to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "line-segment\n" ] } ], "source": [ "experiment.background.type = 'line-segment'\n", "experiment.background.create(id='1', position=10000, intensity=500)\n", "experiment.background.create(id='2', position=40000, intensity=500)" ] }, { "cell_type": "markdown", "id": "22", "metadata": {}, "source": [ "### Set Calculation Range" ] }, { "cell_type": "code", "execution_count": 15, "id": "23", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:16.187562Z", "iopub.status.busy": "2026-06-30T22:30:16.187384Z", "iopub.status.idle": "2026-06-30T22:30:16.193183Z", "shell.execute_reply": "2026-06-30T22:30:16.192014Z" } }, "outputs": [], "source": [ "experiment.data_range.time_of_flight_min = 5000.0\n", "experiment.data_range.time_of_flight_max = 15000.0\n", "experiment.data_range.time_of_flight_inc = 2.0" ] }, { "cell_type": "markdown", "id": "24", "metadata": {}, "source": [ "### Set Linked Structures" ] }, { "cell_type": "code", "execution_count": 16, "id": "25", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:16.197207Z", "iopub.status.busy": "2026-06-30T22:30:16.194736Z", "iopub.status.idle": "2026-06-30T22:30:16.201038Z", "shell.execute_reply": "2026-06-30T22:30:16.199941Z" } }, "outputs": [], "source": [ "experiment.linked_structures.create(structure_id='si', scale=10.0)" ] }, { "cell_type": "markdown", "id": "26", "metadata": {}, "source": [ "## πŸš€ Perform Calculation\n", "\n", "### Display Pattern" ] }, { "cell_type": "code", "execution_count": 17, "id": "27", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:16.205638Z", "iopub.status.busy": "2026-06-30T22:30:16.205475Z", "iopub.status.idle": "2026-06-30T22:30:17.430249Z", "shell.execute_reply": "2026-06-30T22:30:17.429383Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sim')" ] }, { "cell_type": "code", "execution_count": 18, "id": "28", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:17.432827Z", "iopub.status.busy": "2026-06-30T22:30:17.432658Z", "iopub.status.idle": "2026-06-30T22:30:17.483577Z", "shell.execute_reply": "2026-06-30T22:30:17.482937Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sim', x_min=5000, x_max=6000)" ] }, { "cell_type": "markdown", "id": "29", "metadata": {}, "source": [ "### Inspect as Text" ] }, { "cell_type": "code", "execution_count": 19, "id": "30", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:17.485861Z", "iopub.status.busy": "2026-06-30T22:30:17.485673Z", "iopub.status.idle": "2026-06-30T22:30:17.522541Z", "shell.execute_reply": "2026-06-30T22:30:17.521983Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mExperiment πŸ”¬ \u001b[0m\u001b[32m'sim'\u001b[0m\u001b[1;36m as text\u001b[0m\n" ] }, { "data": { "text/html": [ "
Edi
1data_sim
2
3_experiment_type.sample_form powder
4_experiment_type.beam_mode time-of-flight
5_experiment_type.radiation_probe neutron
6_experiment_type.scattering_type bragg
7
8_diffrn.ambient_temperature ?
9_diffrn.ambient_pressure ?
10_diffrn.ambient_magnetic_field ?
11_diffrn.ambient_electric_field ?
12
13_calculator.type cryspy
14
15_data_range.time_of_flight_min 5000.
16_data_range.time_of_flight_max 15000.
17_data_range.time_of_flight_inc 2.
18
19_peak.rise_alpha_0 0.
20_peak.rise_alpha_1 0.5971
21_peak.decay_beta_0 0.04221
22_peak.decay_beta_1 0.00946
23_peak.broad_gauss_sigma_0 3.
24_peak.broad_gauss_sigma_1 40.
25_peak.broad_gauss_sigma_2 2.
26_peak.broad_gauss_size_g 0.
27_peak.broad_gauss_strain_g 0.
28_peak.cutoff_fwhm 0.
29_peak.type tof-jorgensen
30
31_instrument.setup_twotheta_bank 144.845
32_instrument.calib_d_to_tof_offset 0.
33_instrument.calib_d_to_tof_linear 7476.91
34_instrument.calib_d_to_tof_quadratic -1.54
35_instrument.calib_d_to_tof_reciprocal 0.
36
37_absorption.type none
38
39loop_
40_linked_structure.structure_id
41_linked_structure.scale
42si 10.
43
44_background.type line-segment
45
46loop_
47_background.id
48_background.position
49_background.intensity
501 10000 500
512 40000 500
52
53loop_
54_refln.id
55_refln.structure_id
56_refln.d_spacing
57_refln.sin_theta_over_lambda
58_refln.index_h
59_refln.index_k
60_refln.index_l
61_refln.f_calc
62_refln.f_squared_calc
63_refln.time_of_flight
641 si 1.92014846 0.26039653 2 2 0 3.20863212 10.29532007 14351.09932031
652 si 1.63750811 0.305342 3 1 1 2.24018272 5.01841861 12239.37137416
663 si 1.56779466 0.31891932 2 2 2 0. 0. 11718.47425195
674 si 1.35775 0.36825631 4 0 0 3.10167267 9.62037338 10148.9355855
685 si 1.24595685 0.40129801 3 3 1 2.16550644 4.68941815 9313.51652715
696 si 1.21440852 0.41172307 4 2 0 0. 0. 9077.75202306
707 si 1.10859823 0.45102002 4 2 2 2.99827871 8.98967524 8286.9965678
718 si 1.04519644 0.47837897 5 1 1 2.09331949 4.3819865 7813.15734337
729 si 1.04519644 0.47837897 3 3 3 2.09331949 4.3819865 7813.15734337
7310 si 0.96007423 0.52079306 4 4 0 2.89833138 8.40032478 7176.96914365
74...
7515 si 0.82821974 0.60370452 5 3 3 1.95608441 3.82626623 6191.46806257
7616 si 0.81875406 0.610684 6 2 2 0. 0. 6120.71803871
7717 si 0.78389733 0.63783863 4 4 4 2.70832085 7.33500184 5860.18344831
7818 si 0.76049211 0.65746901 5 5 1 1.89087853 3.5754216 5685.24043305
7919 si 0.76049211 0.65746901 7 1 1 1.89087853 3.5754216 5685.24043305
8020 si 0.75314419 0.6638835 6 4 0 0. 0. 5630.317808
8121 si 0.7257479 0.68894446 6 4 2 2.61803924 6.85412944 5425.5406156
8222 si 0.70705598 0.70715759 5 5 3 1.82784627 3.34102199 5285.8240047
8323 si 0.70705598 0.70715759 7 3 1 1.82784627 3.34102199 5285.8240047
8424 si 0.678875 0.73651261 8 0 0 2.53076715 6.40478236 5075.1775345
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.experiments['sim'].show_as_text()" ] }, { "cell_type": "markdown", "id": "31", "metadata": {}, "source": [ "## πŸ’Ύ Save Project" ] }, { "cell_type": "code", "execution_count": 20, "id": "32", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:17.526795Z", "iopub.status.busy": "2026-06-30T22:30:17.526618Z", "iopub.status.idle": "2026-06-30T22:30:17.725597Z", "shell.execute_reply": "2026-06-30T22:30:17.724883Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mSaving project πŸ“¦ \u001b[0m\u001b[32m'si_simulation'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/simulate-si-tof'\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": [ "β”‚ └── πŸ“„ si.edi\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "β”œβ”€β”€ πŸ“ experiments/\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "β”‚ └── πŸ“„ sim.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": [ " └── πŸ“„ si_simulation.html\n" ] } ], "source": [ "project.save_as(dir_path='projects/simulate-si-tof')" ] } ], "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 }