Skip to content

Commit

Permalink
completed scherrer example
Browse files Browse the repository at this point in the history
  • Loading branch information
srio committed Jan 18, 2024
1 parent 9706fe3 commit 5b09572
Show file tree
Hide file tree
Showing 14 changed files with 72,132 additions and 5 deletions.
30 changes: 28 additions & 2 deletions crystalpy/util/calc_xcrystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def get_diffraction_setup(
miller_l=1,
geometry_type_index=0,
asymmetry_angle=0.0,
dabax=None, # only used if material_constants_library_flag > 0
):

# Create a diffraction setup.
Expand Down Expand Up @@ -50,7 +51,9 @@ def get_diffraction_setup(
miller_k = miller_k, # int
miller_l = miller_l, # int
asymmetry_angle = asymmetry_angle, # radians
azimuthal_angle = 0.0) # radians
azimuthal_angle = 0.0, # radians
dabax = dabax,
)

return diffraction_setup

Expand All @@ -73,6 +76,7 @@ def calc_xcrystal_angular_scan(
use_transfer_matrix=0,
do_plot=0,
calculation_strategy_flag=0, # 0=mpmath 1=numpy 2=numpy-truncated
dabax=None, # only used if material_constants_library_flag > 0
):

print("material_constants_library_flag = ", material_constants_library_flag)
Expand All @@ -91,6 +95,10 @@ def calc_xcrystal_angular_scan(
print("is_thick = ", is_thick)
print("use_transfer_matrix = ", use_transfer_matrix)
print("geometry_type_index = ", geometry_type_index)
if dabax is None:
print("dabax = ", dabax)
else:
print("dabax = \n", dabax.info())

# Create a diffraction setup.
diffraction_setup = get_diffraction_setup(
Expand All @@ -102,6 +110,7 @@ def calc_xcrystal_angular_scan(
asymmetry_angle=asymmetry_angle,
geometry_type_index=geometry_type_index,
material_constants_library_flag=material_constants_library_flag,
dabax=dabax,
)


Expand Down Expand Up @@ -166,6 +175,7 @@ def calc_xcrystal_alphazachariasen_scan(
use_transfer_matrix=0,
do_plot=0,
calculation_strategy_flag=0, # 0=mpmath 1=numpy 2=numpy-truncated
dabax=None, # only used if material_constants_library_flag > 0
):

print("material_constants_library_flag = ", material_constants_library_flag)
Expand All @@ -183,6 +193,10 @@ def calc_xcrystal_alphazachariasen_scan(
print("is_thick = ", is_thick)
print("use_transfer_matrix = ", use_transfer_matrix)
print("geometry_type_index = ", geometry_type_index)
if dabax is None:
print("dabax = ", dabax)
else:
print("dabax = \n", dabax.info())

# Create a diffraction setup.
diffraction_setup = get_diffraction_setup(
Expand All @@ -194,6 +208,7 @@ def calc_xcrystal_alphazachariasen_scan(
asymmetry_angle=asymmetry_angle,
geometry_type_index=geometry_type_index,
material_constants_library_flag=material_constants_library_flag,
dabax=dabax,
)


Expand Down Expand Up @@ -262,6 +277,7 @@ def calc_xcrystal_energy_scan(
use_transfer_matrix=0,
do_plot=0,
calculation_strategy_flag=0, # 0=mpmath 1=numpy 2=numpy-truncated
dabax=None, # only used if material_constants_library_flag > 0
):

print("material_constants_library_flag = ", material_constants_library_flag)
Expand All @@ -279,6 +295,10 @@ def calc_xcrystal_energy_scan(
print("is_thick = ", is_thick)
print("use_transfer_matrix = ", use_transfer_matrix)
print("geometry_type_index = ", geometry_type_index)
if dabax is None:
print("dabax = ", dabax)
else:
print("dabax = \n", dabax.info())

# Create a diffraction setup.
diffraction_setup = get_diffraction_setup(
Expand All @@ -290,6 +310,7 @@ def calc_xcrystal_energy_scan(
asymmetry_angle=asymmetry_angle,
geometry_type_index=geometry_type_index,
material_constants_library_flag=material_constants_library_flag,
dabax=dabax,
)

if theta is None:
Expand Down Expand Up @@ -354,6 +375,7 @@ def calc_xcrystal_double_scan(
geometry_type_index=0,
do_plot=0,
calculation_strategy_flag=0, # 0=mpmath 1=numpy 2=numpy-truncated
dabax=None, # only used if material_constants_library_flag > 0
):


Expand All @@ -375,7 +397,10 @@ def calc_xcrystal_double_scan(
print("is_thick = ", is_thick)
print("use_transfer_matrix = ", use_transfer_matrix)
print("geometry_type_index = ", geometry_type_index)

if dabax is None:
print("dabax = ", dabax)
else:
print("dabax = \n", dabax.info())

# Create a diffraction setup.
diffraction_setup = get_diffraction_setup(
Expand All @@ -387,6 +412,7 @@ def calc_xcrystal_double_scan(
asymmetry_angle=asymmetry_angle,
geometry_type_index=geometry_type_index,
material_constants_library_flag=material_constants_library_flag,
dabax=dabax,
)

if energy_points == 1:
Expand Down
48 changes: 48 additions & 0 deletions examples/scherrer/Readme.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
==============================================================
Test of test Scherrer equation vs dynamical diffracion results
==============================================================

The dynamical diffraction profile is calculated for several cases of hkl reflections and crystal thickness, and
the results are compared with the Scherrer equation for two crystals LaB6 and Tripalmitin.

----
LaB6
----

For LaB6 the results are calculated using the scripts:

- scherrer_LaB6.py : comparison as a function of 2theta.

.. image:: ./scherrer_LaB6.png

- scherrer_vs_xtal_thickness_LaB6.py : comparison vs crystal thickness.

.. image:: ./scherrer_vs_xtal_thickness_LaB6.png

-----------
Tripalmitin
-----------

Tripalmitin crystal is not available in the standard crystalpy material libraries (xraylib and dabax).
To include it, a new entry has been created in the dabax data file ./dabax/Crystals.dat, that is used for calculations
in the scripts

- scherrer_Tripalmitin.py : comparison as a function of 2theta.

.. image:: ./scherrer_Tripalmitin.png

- scherrer_vs_xtal_thickness_tripalmitin.py : comparison vs crystal thickness.

.. image:: ./scherrer_vs_xtal_thickness_Tripalmitin.png

This new entry in dabax has been created:

- using the cif file from: https://www.ccdc.cam.ac.uk/structures/Search?Compound=tripalmitin&DatabaseToSearch=Published

- calculating the 1x1x1 supercell using cif2cell (files here: https://github.com/srio/shadow3-scripts/tree/master/cif131755 )

- copying this structure to Crystals.dat

The selected [intense] reflections are obtained making a powder diffraction simulation runing oasys/powder with the cif
file (files: https://github.com/srio/shadow3-scripts/tree/master/cif131755 ).

41 changes: 41 additions & 0 deletions examples/scherrer/crystal_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# crystal tests
#
import numpy
from dabax.dabax_xraylib import DabaxXraylib

dx = DabaxXraylib(dabax_repository='./dabax/')
print(dx.info())
# dx.set_verbose()

print("DABAX crystal list: \n", dx.Crystal_GetCrystalsList())

crystal = 'Tripalmitin'
siD = dx.Crystal_GetCrystal(crystal)

print("DABAX crystal: \n", siD)

print("%s 111 d-spacing: DABAX: %g" % \
(crystal, dx.Crystal_dSpacing(siD, 1, 1, 1)))

print("%s 111 bragg angle at 10 keV [deg]: DABAX: %g" % ( crystal, \
180 / numpy.pi * dx.Bragg_angle(siD, 10, 1, 1, 1), ))

# F0 = dx.Crystal_F_H_StructureFactor(siD,8.0,0,0,0,1.0,ratio_theta_thetaB=1.0)
dabax_all_F = dx.Crystal_F_0_F_H_F_H_bar_StructureFactor(siD, 8.0, 1, 1, 1, 1.0, rel_angle=1.0)

print("F0 dabax: ",
dx.Crystal_F_H_StructureFactor(siD, 8.0, 0, 0, 0, 1.0, 1.0), dabax_all_F[0],
)

print("F111 dabax: ",
dx.Crystal_F_H_StructureFactor(siD, 8.1, 1, 1, 1, 1.0, 1.0), dabax_all_F[1],
)

print("F-1-1-1 dabax: ",
dx.Crystal_F_H_StructureFactor(siD, 8.1, -1, -1, -1, 1.0, 1.0), dabax_all_F[2],
)

print("F001 dabax F2: ", numpy.abs(dx.Crystal_F_H_StructureFactor(siD, 8.1, 0, 0, 1, 1.0, 1.0))**2)
print("F002 dabax F2: ", numpy.abs(dx.Crystal_F_H_StructureFactor(siD, 8.1, 0, 0, 2, 1.0, 1.0))**2)
print("F003 dabax F2: ", numpy.abs(dx.Crystal_F_H_StructureFactor(siD, 8.1, 0, 0, 3, 1.0, 1.0))**2)
Loading

0 comments on commit 5b09572

Please sign in to comment.