Simulation of the diffraction pattern
Contents
Simulation of the diffraction pattern#
This notebook shows how we can create a sample (phase) from atoms and calculate diffraction profile using constant wavelength experiment type.
# EasyScience, technique-independent
from easyCore import np
from easyCore.Fitting.Fitting import Fitter
# EasyScience, diffraction
from easyDiffractionLib import Site, Phase, Phases
from easyDiffractionLib.Jobs import Powder1DCW
# Vizualization
import py3Dmol
from bokeh.io import show, output_notebook
from bokeh.plotting import figure
# Misc
import xarray as xr
Warning: GSAS-2 is not installed
Sample#
Create an atom using Site
interface#
atom = Site.from_pars(label="Cl",
specie="Cl",
fract_x=0.0,
fract_y=0.0,
fract_z=0.0)
Create a phase, set space group, add atom#
phase = Phase(name="salt")
phase.spacegroup.space_group_HM_name = "F m -3 m"
phase.add_atom(atom)
Add another atom (using Phase
interface)#
phase.add_atom('Na', 'Na', 0.5, 0.5, 0.5)
Visualise the structure#
viewer = py3Dmol.view()
viewer.addModel(phase.to_cif_str(),'cif',{'doAssembly':True,'duplicateAssemblyAtoms':True,'normalizeAssembly':True})
viewer.setStyle({'sphere':{'colorscheme':'Jmol','scale':.2},'stick':{'colorscheme':'Jmol', 'radius': 0.1}})
viewer.addUnitCell()
viewer.replicateUnitCell(2,2,2)
viewer.zoomTo()
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol
<py3Dmol.view at 0x7f87af50b370>
Create Phases object#
phases = Phases()
phases.append(phase)
Experiment#
Create Dataset
#
data = xr.Dataset()
Create Job
#
job = Powder1DCW('NaCl', data, phases=phases)
Modify instrumental parameters#
job.parameters.resolution_u = 0.1447
job.parameters.resolution_v = -0.4252
job.parameters.resolution_w = 0.3864
job.parameters.resolution_x = 0.0
job.parameters.resolution_y = 0.0
Modify pattern parameters#
job.pattern.zero_shift = 0.0
job.pattern.scale = 100.0
Create calculator#
calculator = job.interface # CrysPy is default
print(f"Current calculator engine: {calculator.current_interface_name}")
Current calculator engine: CrysPy
print(f"Available calculator engines: {calculator.available_interfaces}")
print(f"Available calculators for CW: {calculator.interface_compatability('Npowder1DCWunp')}")
Available calculator engines: ['CrysPy', 'CrysFML']
Available calculators for CW: ['CrysPy', 'CrysFML']
Analysis#
Calculate the profile using the calculator we defined previously.#
x_data = np.linspace(20, 170, 500)
_ = job.create_simulation(x_data)
y_data = np.array(data['sim_NaCl'])
fig = figure(width=FIGURE_WIDTH, height=FIGURE_HEIGHT)
fig.line(x_data, y_data, legend_label='CW Simulation', color='orangered', line_width=2)
show(fig)