Import EasyDiffraction¶
import easydiffraction as ed
Create a job¶
Create a job — the main object to store all the information
job = ed.Job(type='pd-xray')
print(job.type)
Job type: pd-cwl-unp-1d-xray
Define a model¶
Create a phase object
phase = ed.Phase(name='nacl')
Set space group
phase.space_group.name_hm_alt = 'F m -3 m'
Set cell parameters
phase.cell.length_a = 5.691694
Add atoms
phase.atom_sites.append(label='Na',
type_symbol='Na',
fract_x=0,
fract_y=0,
fract_z=0,
occupancy=1,
u_iso_or_equiv=0.01)
phase.atom_sites.append(label='Cl',
type_symbol='Cl',
fract_x=0,
fract_y=0,
fract_z=0.5,
occupancy=1,
u_iso_or_equiv=0.01)
Add phase to the job object
job.add_phase(phase=phase)
print(job.phases)
Collection of 1 phases: ['nacl']
Show phase info in CIF format
phase = job.phases['nacl']
print(phase.cif)
data_nacl _cell_length_a 5.691694 _cell_length_b 5.691694 _cell_length_c 5.691694 _cell_angle_alpha 90.00000000 _cell_angle_beta 90.00000000 _cell_angle_gamma 90.00000000 _space_group_name_H-M_ref 'F m -3 m' loop_ _atom_site_label _atom_site_type_symbol _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy _atom_site_adp_type _atom_site_U_iso_or_equiv Na Na 0.00000000 0.00000000 0.00000000 1.00000000 Uiso 0.01 Cl Cl 0.00000000 0.00000000 0.5 1.00000000 Uiso 0.01
Display the crystal structure of a given model
job.show_crystal_structure(id='nacl')
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
Define an experiment¶
Although in this example we only simulate the diffraction pattern, some parameters for the ‘virtual experiment’ still need to be set. For example, the wavelength of the X-ray beam, the range of 2-theta angles, etc.
Let's start by setting the range and step of the 2-theta angles. The other parameters will be set later.
job.instrument.twotheta_range_min = 20
job.instrument.twotheta_range_max = 160
job.instrument.twotheta_range_inc = 0.05
Perform an analysis¶
Display the analysis chart before changing the values of other parameters from their default values.
job.show_simulation_chart()
Show the names of all parameters, their values, etc. Parameter names can be used to access the parameter and change its value.
job.show_parameters()
name | value | error | min | max | vary | ||
---|---|---|---|---|---|---|---|
1 | .phases['nacl'].cell.length_a | 5.691694 | Å | 0.0 | inf | ||
2 | .phases['nacl'].atom_sites['Na'].occupancy | 1.000000 | -inf | inf | |||
3 | .phases['nacl'].atom_sites['Na'].fract_x | 0.000000 | -inf | inf | |||
4 | .phases['nacl'].atom_sites['Na'].fract_y | 0.000000 | -inf | inf | |||
5 | .phases['nacl'].atom_sites['Na'].fract_z | 0.000000 | -inf | inf | |||
6 | .phases['nacl'].atom_sites['Na'].u_iso_or_equiv | 0.010000 | Ų | 0.0 | inf | ||
7 | .phases['nacl'].atom_sites['Cl'].occupancy | 1.000000 | -inf | inf | |||
8 | .phases['nacl'].atom_sites['Cl'].fract_x | 0.000000 | -inf | inf | |||
9 | .phases['nacl'].atom_sites['Cl'].fract_y | 0.000000 | -inf | inf | |||
10 | .phases['nacl'].atom_sites['Cl'].fract_z | 0.500000 | -inf | inf | |||
11 | .phases['nacl'].atom_sites['Cl'].u_iso_or_equiv | 0.010000 | Ų | 0.0 | inf | ||
12 | .phases['nacl'].scale | 1.000000 | 0.0 | inf | True | ||
13 | .instrument.wavelength | 1.540560 | Å | -inf | inf | ||
14 | .instrument.resolution_u | 0.000200 | -inf | inf | |||
15 | .instrument.resolution_v | -0.000200 | -inf | inf | |||
16 | .instrument.resolution_w | 0.012000 | -inf | inf | |||
17 | .instrument.resolution_x | 0.000000 | -inf | inf | |||
18 | .instrument.resolution_y | 0.000000 | -inf | inf | |||
19 | .instrument.reflex_asymmetry_p1 | 0.000000 | -inf | inf | |||
20 | .instrument.reflex_asymmetry_p2 | 0.000000 | -inf | inf | |||
21 | .instrument.reflex_asymmetry_p3 | 0.000000 | -inf | inf | |||
22 | .instrument.reflex_asymmetry_p4 | 0.000000 | -inf | inf | |||
23 | .pattern.zero_shift | 0.000000 | deg | -inf | inf |
Change the default value of the wavelength used in the experiment and display the analysis chart again
job.instrument.wavelength = 1.5
job.show_simulation_chart()
Change the default values of the peak profile related parameters and display the analysis chart again
job.instrument.resolution_u = 0.1
job.instrument.resolution_v = -0.1
job.instrument.resolution_w = 0.2
job.show_simulation_chart()
Change the value of the unit cell parameter and display the analysis chart again
job.phases['nacl'].cell.length_a = 5.0
job.show_simulation_chart()