Calculation Without Data: Si, TOF¶
This example shows how to calculate and plot a time-of-flight diffraction pattern without any measured data. As with the constant-wavelength example, the structure, instrument, peak profile, and background are defined in code, and the pattern is computed over a calculation range.
For a time-of-flight instrument an absolute time window is meaningless
without a calibration, so the default data_range is derived from the
instrument's TOF calibration. No data file is downloaded or loaded.
For this example, a time-of-flight neutron powder experiment for Si is used.
🛠️ Import Library¶
In [2]:
Copied!
import easydiffraction as edi
import easydiffraction as edi
📦 Define Project¶
In [3]:
Copied!
project = edi.Project(name='si_simulation')
project = edi.Project(name='si_simulation')
🧩 Define Structure¶
In [4]:
Copied!
project.structures.create(name='si')
project.structures.create(name='si')
In [5]:
Copied!
structure = project.structures['si']
structure = project.structures['si']
In [6]:
Copied!
structure.space_group.name_h_m = 'F d -3 m'
structure.space_group.coord_system_code = '2'
structure.space_group.name_h_m = 'F d -3 m'
structure.space_group.coord_system_code = '2'
In [7]:
Copied!
structure.cell.length_a = 5.431
structure.cell.length_a = 5.431
In [8]:
Copied!
structure.atom_sites.create(
id='Si',
type_symbol='Si',
fract_x=0.125,
fract_y=0.125,
fract_z=0.125,
adp_iso=0.5,
)
structure.atom_sites.create(
id='Si',
type_symbol='Si',
fract_x=0.125,
fract_y=0.125,
fract_z=0.125,
adp_iso=0.5,
)
In [9]:
Copied!
project.display.structure(struct_name='si')
project.display.structure(struct_name='si')
Structure 🧩 'si' (Atom view type: 'covalent')
Loading plot…
drag = rotate
wheel = zoom
right-drag = pan
wheel = zoom
right-drag = pan
In [10]:
Copied!
project.experiments.create(
name='sim',
sample_form='powder',
beam_mode='time-of-flight',
radiation_probe='neutron',
)
project.experiments.create(
name='sim',
sample_form='powder',
beam_mode='time-of-flight',
radiation_probe='neutron',
)
In [11]:
Copied!
experiment = project.experiments['sim']
experiment = project.experiments['sim']
Set Instrument¶
The TOF calibration (offset, linear, and quadratic d-to-TOF terms) is what converts the default d-spacing window into a time window.
In [12]:
Copied!
experiment.instrument.setup_twotheta_bank = 144.845
experiment.instrument.calib_d_to_tof_offset = 0.0
experiment.instrument.calib_d_to_tof_linear = 7476.91
experiment.instrument.calib_d_to_tof_quadratic = -1.54
experiment.instrument.setup_twotheta_bank = 144.845
experiment.instrument.calib_d_to_tof_offset = 0.0
experiment.instrument.calib_d_to_tof_linear = 7476.91
experiment.instrument.calib_d_to_tof_quadratic = -1.54
Set Peak Profile¶
In [13]:
Copied!
experiment.peak.broad_gauss_sigma_0 = 3.0
experiment.peak.broad_gauss_sigma_1 = 40.0
experiment.peak.broad_gauss_sigma_2 = 2.0
experiment.peak.decay_beta_0 = 0.04221
experiment.peak.decay_beta_1 = 0.00946
experiment.peak.rise_alpha_0 = 0.0
experiment.peak.rise_alpha_1 = 0.5971
experiment.peak.broad_gauss_sigma_0 = 3.0
experiment.peak.broad_gauss_sigma_1 = 40.0
experiment.peak.broad_gauss_sigma_2 = 2.0
experiment.peak.decay_beta_0 = 0.04221
experiment.peak.decay_beta_1 = 0.00946
experiment.peak.rise_alpha_0 = 0.0
experiment.peak.rise_alpha_1 = 0.5971
Set Background¶
In [14]:
Copied!
experiment.background.type = 'line-segment'
experiment.background.create(id='1', position=10000, intensity=500)
experiment.background.create(id='2', position=40000, intensity=500)
experiment.background.type = 'line-segment'
experiment.background.create(id='1', position=10000, intensity=500)
experiment.background.create(id='2', position=40000, intensity=500)
Background type for experiment 'sim' already set to
line-segment
Set Calculation Range¶
In [15]:
Copied!
experiment.data_range.time_of_flight_min = 5000.0
experiment.data_range.time_of_flight_max = 15000.0
experiment.data_range.time_of_flight_inc = 2.0
experiment.data_range.time_of_flight_min = 5000.0
experiment.data_range.time_of_flight_max = 15000.0
experiment.data_range.time_of_flight_inc = 2.0
Set Linked Structures¶
In [16]:
Copied!
experiment.linked_structures.create(structure_id='si', scale=10.0)
experiment.linked_structures.create(structure_id='si', scale=10.0)
In [17]:
Copied!
project.display.pattern(expt_name='sim')
project.display.pattern(expt_name='sim')
Loading plot…
In [18]:
Copied!
project.display.pattern(expt_name='sim', x_min=5000, x_max=6000)
project.display.pattern(expt_name='sim', x_min=5000, x_max=6000)
Loading plot…
Inspect as Text¶
In [19]:
Copied!
project.experiments['sim'].show_as_text()
project.experiments['sim'].show_as_text()
Experiment 🔬 'sim' as text
| Edi | |
|---|---|
| 1 | data_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 | |
| 39 | loop_ |
| 40 | _linked_structure.structure_id |
| 41 | _linked_structure.scale |
| 42 | si 10. |
| 43 | |
| 44 | _background.type line-segment |
| 45 | |
| 46 | loop_ |
| 47 | _background.id |
| 48 | _background.position |
| 49 | _background.intensity |
| 50 | 1 10000 500 |
| 51 | 2 40000 500 |
| 52 | |
| 53 | loop_ |
| 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 |
| 64 | 1 si 1.92014846 0.26039653 2 2 0 3.20863212 10.29532007 14351.09932031 |
| 65 | 2 si 1.63750811 0.305342 3 1 1 2.24018272 5.01841861 12239.37137416 |
| 66 | 3 si 1.56779466 0.31891932 2 2 2 0. 0. 11718.47425195 |
| 67 | 4 si 1.35775 0.36825631 4 0 0 3.10167267 9.62037338 10148.9355855 |
| 68 | 5 si 1.24595685 0.40129801 3 3 1 2.16550644 4.68941815 9313.51652715 |
| 69 | 6 si 1.21440852 0.41172307 4 2 0 0. 0. 9077.75202306 |
| 70 | 7 si 1.10859823 0.45102002 4 2 2 2.99827871 8.98967524 8286.9965678 |
| 71 | 8 si 1.04519644 0.47837897 5 1 1 2.09331949 4.3819865 7813.15734337 |
| 72 | 9 si 1.04519644 0.47837897 3 3 3 2.09331949 4.3819865 7813.15734337 |
| 73 | 10 si 0.96007423 0.52079306 4 4 0 2.89833138 8.40032478 7176.96914365 |
| 74 | ... |
| 75 | 15 si 0.82821974 0.60370452 5 3 3 1.95608441 3.82626623 6191.46806257 |
| 76 | 16 si 0.81875406 0.610684 6 2 2 0. 0. 6120.71803871 |
| 77 | 17 si 0.78389733 0.63783863 4 4 4 2.70832085 7.33500184 5860.18344831 |
| 78 | 18 si 0.76049211 0.65746901 5 5 1 1.89087853 3.5754216 5685.24043305 |
| 79 | 19 si 0.76049211 0.65746901 7 1 1 1.89087853 3.5754216 5685.24043305 |
| 80 | 20 si 0.75314419 0.6638835 6 4 0 0. 0. 5630.317808 |
| 81 | 21 si 0.7257479 0.68894446 6 4 2 2.61803924 6.85412944 5425.5406156 |
| 82 | 22 si 0.70705598 0.70715759 5 5 3 1.82784627 3.34102199 5285.8240047 |
| 83 | 23 si 0.70705598 0.70715759 7 3 1 1.82784627 3.34102199 5285.8240047 |
| 84 | 24 si 0.678875 0.73651261 8 0 0 2.53076715 6.40478236 5075.1775345 |
💾 Save Project¶
In [20]:
Copied!
project.save_as(dir_path='projects/simulate-si-tof')
project.save_as(dir_path='projects/simulate-si-tof')
Saving project 📦 'si_simulation' to '../../../projects/simulate-si-tof'
├── 📄 project.edi
├── 📁 structures/
│ └── 📄 si.edi
├── 📁 experiments/
│ └── 📄 sim.edi
├── 📁 analysis/
│ └── 📄 analysis.edi
└── 📁 reports/
└── 📄 si_simulation.html