crystalpy.diffraction package
Submodules
crystalpy.diffraction.Diffraction module
Defines a crystal diffraction experiment setup.
- class crystalpy.diffraction.Diffraction.Diffraction[source]
Bases:
objectThis class contains methods to to make different diffraction calculations. It does not contain data.
- classmethod calculateDiffractedComplexAmplitudePhoton(diffraction_setup, photon, calculation_method=0, is_thick=0, use_transfer_matrix=0, calculation_strategy_flag=0)[source]
- Parameters:
diffraction_setup –
photon –
calculation_method (int, optional) – 0: Zachariasen, 1: Guigay (Default value = 0)
is_thick (int, optional) – 0: No, 1: Yes (Default value = 0)
use_transfer_matrix (int, optional) – 0: No, 1: Yes (Default value = 0)
calculation_strategy_flag (int, optional) – For computing exp, sin, cos: 0: use mpmath, 1: use numpy, 2=use numpy truncated.
- Return type:
ComplexAmplitudePhoton instance
- classmethod calculateDiffractedComplexAmplitudePhotonBunch(diffraction_setup, incoming_bunch, calculation_method=0, is_thick=0, use_transfer_matrix=0, calculation_strategy_flag=0)[source]
Calculates the diffraction/transmission given by the setup.
- Parameters:
diffraction_setup (DiffractionSetup instance) – The diffraction setup.
incoming_bunch (ComplexAmplitudePhotonBeam instance) –
calculation_method (int, optional) – 0: Zachariasen, 1: Guigay (Default value = 0)
is_thick (int, optional) – 0: No, 1: Yes (Default value = 0)
use_transfer_matrix (int, optional) – 0: No, 1: Yes (Default value = 0)
calculation_strategy_flag (int, optional) – For computing exp, sin, cos: 0: use mpmath, 1: use numpy, 2=use numpy truncated.
- Returns:
Bunch made of diffracted/transmitted photons.
- Return type:
ComplexAmplitudePhotonBeam instance
- classmethod calculateDiffractedComplexAmplitudes(diffraction_setup, incoming_photon, calculation_method=0, is_thick=0, use_transfer_matrix=0, calculation_strategy_flag=0)[source]
Calculates the diffracted complex amplitude
- Parameters:
diffraction_setup –
incoming_photon –
calculation_method (int, optional) – 0: Zachariasen, 1: Guigay (Default value = 0)
is_thick (int, optional) – 0: No, 1: Yes (Default value = 0)
use_transfer_matrix (int, optional) – 0: No, 1: Yes (Default value = 0)
calculation_strategy_flag (int, optional) – For computing exp, sin, cos: 0: use mpmath, 1: use numpy, 2=use numpy truncated.
- Returns:
the complex amplitudes for sigma and pi polarizations: {“S”: float, “P”: float}
- Return type:
dict
- classmethod calculateDiffractedPolarizedPhoton(diffraction_setup, incoming_polarized_photon, inclination_angle, calculation_method=0, is_thick=0, use_transfer_matrix=0, calculation_strategy_flag=0)[source]
Calculates the diffraction/transmission given by the setup.
- Parameters:
diffraction_setup (DiffractionSetup instance) – The diffraction setup.
incoming_polarized_photon (ComplexAmplitudePhoton instance) –
inclination_angle (float) – The inclination angle in rad.
calculation_method (int, optional) – 0: Zachariasen, 1: Guigay (Default value = 0)
is_thick (int, optional) – 0: No, 1: Yes (Default value = 0)
use_transfer_matrix (int, optional) – 0: No, 1: Yes (Default value = 0)
calculation_strategy_flag (int, optional) – For computing exp, sin, cos: 0: use mpmath, 1: use numpy, 2=use numpy truncated.
- Returns:
Photon diffracted/transmitted.
- Return type:
ComplexAmplitudePhoton instance
- classmethod calculateDiffractedPolarizedPhotonBunch(diffraction_setup, incoming_bunch, inclination_angle, calculation_method=0, is_thick=0, use_transfer_matrix=0, calculation_strategy_flag=0)[source]
Calculates the diffraction/transmission bunch given by the crystal in the setup.
- Parameters:
diffraction_setup (DiffractionSetup instance) – The diffraction setup.
incoming_bunch (ComplexAmplitudePhotonBunch instance) –
inclination_angle (float) – The inclination angle in rad.
calculation_method (int, optional) – 0: Zachariasen, 1: Guigay (Default value = 0)
is_thick (int, optional) – 0: No, 1: Yes (Default value = 0)
use_transfer_matrix (int, optional) – 0: No, 1: Yes (Default value = 0)
calculation_strategy_flag (int, optional) – For computing exp, sin, cos: 0: use mpmath, 1: use numpy, 2=use numpy truncated.
- Returns:
PhotonBunch object made up of diffracted/transmitted photons.
- Return type:
- classmethod calculateDiffraction(diffraction_setup, calculation_method=0, is_thick=0, use_transfer_matrix=0, calculation_strategy_flag=0)[source]
Calculates the diffraction/transmission given by the setup.
- Parameters:
diffraction_setup (DiffractionSetup instance) –
calculation_method (int, optional) – 0: Zachariasen, 1: Guigay (Default value = 0)
is_thick (int, optional) – 0: No, 1: Yes (Default value = 0)
use_transfer_matrix (int, optional) – 0: No, 1: Yes (Default value = 0)
calculation_strategy_flag (int, optional) – For computing exp, sin, cos: 0: use mpmath, 1: use numpy, 2=use numpy truncated.
- Returns:
DiffractionResult with the input setup.
- Return type:
DiffractionResult instance
crystalpy.diffraction.DiffractionExceptions module
Exception classes with ad-hoc messages.
- exception crystalpy.diffraction.DiffractionExceptions.DiffractionException(exception_text)[source]
Bases:
Exception
- exception crystalpy.diffraction.DiffractionExceptions.ReflectionImpossibleException[source]
Bases:
DiffractionException
- exception crystalpy.diffraction.DiffractionExceptions.StructureFactorF0isZeroException[source]
Bases:
DiffractionException
- exception crystalpy.diffraction.DiffractionExceptions.StructureFactorFHbarIsZeroException[source]
Bases:
DiffractionException
- exception crystalpy.diffraction.DiffractionExceptions.StructureFactorFHisZeroException[source]
Bases:
DiffractionException
- exception crystalpy.diffraction.DiffractionExceptions.TransmissionImpossibleException[source]
Bases:
DiffractionException
crystalpy.diffraction.DiffractionResult module
Object to hold the diffraction results.
self._intensities = numpy.array((number_energies,number_angles,index_polarization)) self._phases = numpy.array((number_energies,number_angles,index_polarization))
- index_polarization:
INDEX_POLARIZATION_S = 0 INDEX_POLARIZATION_P = 1 INDEX_DIFFERENCE_PS = 2
- Note that INDEX_DIFFERENCE_PS=2 means for:
self._intensities: the RATIO of p-intensity / s-intensity self._phases: the DIFFERENCE of p-intensity - s-intensity
- class crystalpy.diffraction.DiffractionResult.DiffractionResult(diffraction_setup, bragg_angle)[source]
Bases:
objectConstructor.
- Parameters:
diffraction_setup (DiffractionSetup instance) – Setup used for these results.
bragg_angle (float) – Bragg angle in rad of the setup.
- INDEX_DIFFERENCE_PS = 2
- INDEX_POLARIZATION_P = 1
- INDEX_POLARIZATION_S = 0
- add(energy, deviation, s_complex_amplitude, p_complex_amplitude, difference_complex_amplitude)[source]
Adds a new result for a given energy and deviation.
- Parameters:
energy (float) – The photon energy in eV.
deviation (float) – The deviation angle in rad.
s_complex_amplitude (float) – The complex amplitude for sigma polarization.
p_complex_amplitude (float) – The complex amplitude for pi polarization.
difference_complex_amplitude (float) – The ratio between the intensities of pi over sigma polarizations.
- angleDeviations()[source]
Returns the angle deviations used for these results.
- Returns:
Angle deviations used for these results.
- Return type:
numpy array
- angles()[source]
Returns the angles used for calculation of these results.
- Returns:
The angles used for the calculation of these results.
- Return type:
numpy array
- braggAngle()[source]
Returns Bragg angle used for these results.
- Returns:
Bragg angle used for these results.
- Return type:
float
- differenceIntensityByDeviation(deviation)[source]
Returns the intensities ratio for the two polarizations P/S .
- Parameters:
deviation (float) – Deviation to return intensity for.
- Returns:
Intensity ratio P / S for the two polarizations.
- Return type:
float
- differenceIntensityByEnergy(energy)[source]
Returns the ratio of the intensity between P over S polarizations.
- Parameters:
energy (float) – Energy to return intensity for.
- Returns:
Ratio of the intensities P / S.
- Return type:
float
- differencePhaseByDeviation(deviation, deg=False)[source]
Returns the difference of the phase between P and S polarizations.
- Parameters:
deviation (float) – Deviation to return phase for.
deg (boolean, optional) – if True the phase is converted into degrees. (Default value = False)
- Returns:
Different of phase between P and S polarization.
- Return type:
float
- differencePhaseByEnergy(energy, deg=False)[source]
Returns the difference of phase between P and S polarizations.
- Parameters:
energy (float) – Energy to return phase for.
deg (boolean, optional) – if True the phase is converted into degrees. (Default deg = False)
- Returns:
Phase of the difference between S and P polarization.
- Return type:
float
- diffractionSetup()[source]
Returns the diffraction setup used for the calculation of these results. :return:
- Returns:
The diffraction setup used for the calculation of these results (referenced, not copied).
- Return type:
DiffractionSetup instance
- energies()[source]
Returns the energies used for these results.
- Returns:
Energies used for these results.
- Return type:
numpy array
- pIntensityByDeviation(deviation)[source]
Returns the intensity of the P polarization.
- Parameters:
deviation (float) – Deviation to return intensity for.
- Returns:
Intensity of the P polarization.
- Return type:
float
- pIntensityByEnergy(energy)[source]
Returns the intensity of the P polarization.
- Parameters:
energy (float) – Energy for the intensity we are loking for.
- Returns:
Intensity of the S polarization.
- Return type:
float
- pPhaseByDeviation(deviation, deg=False)[source]
Returns the phase of the P polarization.
- Parameters:
deviation (float) – Deviation to return phase for.
deg (boolean, optional) – if True the phase is converted into degrees. (Default value = False)
- Returns:
Phase of the P polarization.
- Return type:
float
- pPhaseByEnergy(energy, deg=False)[source]
Returns the phase of the P polarization.
- Parameters:
energy (float) – Energy for the phase we are loking for.
deg (boolean, optional) – if True the phase is converted into degrees. (Default deg = False)
- Returns:
Phase of the S polarization.
- Return type:
float
- sIntensityByDeviation(deviation)[source]
Returns the intensity of the S polarization.
- Parameters:
deviation (float) – Deviation to return intensity for.
- Returns:
Intensity of the S polarization.
- Return type:
float
- sIntensityByEnergy(energy)[source]
Returns the intensity of the S polarization.
- Parameters:
energy (float) – Energy for the intensity we are loking for.
- Returns:
Intensity of the S polarization.
- Return type:
float
- sPhaseByDeviation(deviation, deg=False)[source]
Returns the phase of the S polarization.
- Parameters:
deviation (float) – Deviation to return phase for.
deg (boolean, optional) – if True the phase is converted into degrees. (Default value = False)
- Returns:
Phase of the S polarization.
- Return type:
float
- sPhaseByEnergy(energy, deg=False)[source]
Returns the phase of the S polarization.
- Parameters:
energy (float) – Energy for the phase we are loking for.
deg (boolean, optional) – if True the phase is converted into degrees. (Default deg = False)
- Returns:
Phase of the S polarization.
- Return type:
float
crystalpy.diffraction.DiffractionSetupAbstract module
Represents a diffraction setup abstract class. The super class should implement the methods to calculate structure factors
- class crystalpy.diffraction.DiffractionSetupAbstract.DiffractionSetupAbstract(geometry_type=None, crystal_name='', thickness=1e-06, miller_h=1, miller_k=1, miller_l=1, asymmetry_angle=0.0, azimuthal_angle=0.0, debye_waller=1.0)[source]
Bases:
objectConstructor.
- Parameters:
geometry_type (instance of BraggDiffraction, LaueDiffraction, BraggTransmission, or LaueTransmission) –
crystal_name (str) – The name of the crystal, e.g. “Si”.
thickness (float) – The crystal thickness in m.
miller_h (int) – Miller index H.
miller_k (int) – Miller index K.
miller_l (int) – Miller index L.
asymmetry_angle (float) – The asymmetry angle between surface normal and Bragg normal (radians).
azimuthal_angle (float) – The angle between the projection of the Bragg normal on the crystal surface plane and the Y axis (radians). It can also be called inclination angle.
debye_waller (float) – The Debye-Waller factor exp(-M).
- F0(energy=8000.0)[source]
Calculate the structure factor F0.
- Parameters:
energy (float) – photon energy in eV. (Default value = 8000.0)
- Returns:
F0
- Return type:
complex
- FH(energy=8000.0)[source]
Calculate the structure factor FH.
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
- Returns:
FH
- Return type:
complex
- FH_bar(energy=8000.0)[source]
Calculate the structure factor FH_bar.
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
- Returns:
FH_bar
- Return type:
complex
- Fall(energy=8000.0)[source]
Calculate the all structure factor (F0, FH, FH_bar).
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
- Returns:
(F0, FH, FH_bar).
- Return type:
tuple
- angleBragg(energy=8000.0)[source]
Returns the Bragg angle for a given energy in radians.
- Parameters:
energy – Energy to calculate the Bragg angle for. (Default value = 8000.0)
- Returns:
Bragg angle in radians.
- Return type:
float
- angleBraggCorrected(energy=8000.0, use_exact_equation=True)[source]
Returns the Bragg angle corrected for refraction for a given energy. An approximated formula is found in Zachariasen equation 3.145a. The exact formula is in Guigay % Sanchez del Rio equation 21.
- Parameters:
energy (float or numpy array) – Energy in eV for calculating the Bragg angle. (Default value = 8000.0)
- Returns:
Bragg angle(s) corrected.
- Return type:
float or numpy array
- asymmetryAngle()[source]
Returns the asymmetry angle between surface normal and Bragg normal in degrees.
- Returns:
Asymmetry angle.
- Return type:
float
- asymmetryFactor(energy, vector_k_in=None)[source]
Returns asymmetric factor (after Zachariasen equation [3.115]).
- Parameters:
energy (float or numpy array) – The photon energy in eV.
vector_k_in (Vector instance, optional) – The incident K0 (Default value = None, meaning that K0 is used.)
- Return type:
float or numpy array
- azimuthalAngle()[source]
Returns the angle between the Bragg normal projection on the crystal surface plane and the x axis in degrees.
- Returns:
Azimuthal angle.
- Return type:
float
- clone()[source]
Returns a copy of this instance.
- Returns:
A copy of this instance.
- Return type:
DiffractionSetup instance
- dSpacing()[source]
Returns the lattice spacing d in A.
- Returns:
Lattice spacing. in A
- Return type:
float
- dSpacingSI()[source]
Returns the lattice spacing d in SI units (meters).
- Returns:
Lattice spacing. in m
- Return type:
float
- darwinHalfwidthP(energy)[source]
- energyfloat or numpy array
Energy in eV for calculating the Bragg angle. (Default value = 8000.0)
- Returns:
1/2 of the Darwin width(s) for pi polarization in radians.
- Return type:
float or numpy array
- darwinHalfwidthS(energy=8000.0)[source]
- energyfloat or numpy array
Energy in eV for calculating the Bragg angle. (Default value = 8000.0)
- Returns:
1/2 of the Darwin width(s) for sigma polarization in radians.
- Return type:
float or numpy array
- deviationOfIncomingPhoton(photon_in)[source]
Calculates deviation from the Bragg angle of an incoming photon in radians.
- Parameters:
photon_in – Incoming photon.
- Returns:
Deviation from Bragg angle in radians.
- Return type:
float
- duplicate()[source]
Returns a copy of this instance.
- Returns:
A copy of this instance.
- Return type:
DiffractionSetup instance
- geometryType()[source]
Returns the GeometryType, e.g. BraggDiffraction, LaueTransmission,…
- Returns:
The GeometryType.
- Return type:
instance of BraggDiffraction, LaueDiffraction, BraggTransmission, or LaueTransmission.
- psi0(energy)[source]
Calculate the structure factor psi0 (defined in Zachariasen [3-95]).
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
- Returns:
psi0
- Return type:
complex
- psiAll(energy1, rel_angle=1.0)[source]
Calculate the psi structure factors (psi0, psiH, psiH_bar) (defined in Zachariasen [3-95]).
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
rel_angle (float, optional) – (Default = 1.0)
- Returns:
(psi0, psiH, psiH_bar).
- Return type:
tuple
- psiH(energy, rel_angle=1.0)[source]
Calculate the structure factor psiH (defined in Zachariasen [3-95]).
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
rel_angle (float, optional) – (Default = 1.0)
- Returns:
psiH
- Return type:
complex
- psiH_bar(energy, rel_angle=1.0)[source]
Calculate the structure factor psiH_bar (defined in Zachariasen [3-95]).
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
rel_angle (float, optional) – (Default = 1.0)
- Returns:
psiH_bar
- Return type:
complex
- thickness()[source]
Returns the crystal thickness in meters
- Returns:
he crystal thickness.
- Return type:
float
- toDictionary()[source]
Returns info of this setup in a dictionary.
- Returns:
Info dictionary form of this setup.
- Return type:
dict
- unitcellVolume()[source]
Returns the unit cell volume in A^3
- Returns:
Unit cell volume in A^3.
- Return type:
float
- unitcellVolumeSI()[source]
Returns the unit cell volume in SI units (m^3)
- Returns:
Unit cell volume in m^3.
- Return type:
float
- vectorH()[source]
Calculates the H vector, normal on the reflection lattice plane, with modulus 2 pi / d_spacing (SI).
The normal to Bragg planes is obtained by rotating vnor an angle equal to minuns asymmetry angle (-alphaXOP) around X using rodrigues rotation (in the screw direction (cw) when looking in the axis direction), and then an angle phi (azimuthal angle) around Z
- Returns:
H vector
- Return type:
vector instance
References
Sanchez del Rio, M., Perez-Bocanegra, N., Shi, X., Honkimäki, V. & Zhang, L. (2015). Simulation of X-ray diffraction profiles for bent anisotropic crystals. J. Appl. Cryst. 48, 477–491. http://dx.doi.org/10.1107/S1600576715002782
- vectorHdirection()[source]
Calculates the unitary vector parallel to the H vector (normal on the reflection lattice plane, with modulus 2 pi / d_spacing (SI)).
The normal to the Bragg planes is obtained by rotating vnor an angle equal to minuns asymmetry angle (-alphaXOP) around X using rodrigues rotation (in the screw direction (cw) when looking in the axis direction), and then an angle phi (azimuthal angle) around Z
- Returns:
normal vector in direction of H.
- Return type:
Vector instance
- vectorIncomingPhotonDirection(energy, deviation, angle_center_flag=2)[source]
Calculates the direction of the incoming photon (or photon stack). Parallel to k_0.
- Parameters:
energy (float of numpy array/) – Energy in eV.
deviation (float or array.) – Deviation from the uncorrected Bragg angle. A positive deviation means the photon direction lies closer to the surface normal.
angle_center_flag (int, optional) – Flag from where “deviation: is measured: 0: absolute angle, 1: from Bragg angle corrected for refraction, 2: from Bragg angle.
- Returns:
Direction(s) of the incoming photon(s).
- Return type:
Vector instance
- vectorK0(energy)[source]
Calculates the vector K0(along the Bragg position)
- Parameters:
energy (float or numpy array.) – The photon energy in eV.
- Returns:
The K0.
- Return type:
Vector instance
- vectorK0corrected(energy)[source]
Calculates the vector K0corrected (along the corrected Bragg position)
- Parameters:
energy (float or numpy array.) – The photon energy in eV.
- Returns:
The K0corrected.
- Return type:
Vector instance
- vectorK0direction(energy)[source]
Calculates the unitary vector parallel to the K0 vector (along the Bragg position)
- Parameters:
energy (float or numpy array.) – The photon energy in eV.
- Returns:
The normalized vector (or stack of vectors) with the directions of K0.
- Return type:
Vector instance
- vectorK0directionCorrected(energy)[source]
Calculates the unitary vector parallel to the K0corrected vector (along the Bragg position corrected for refraction)
- Parameters:
energy (float or numpy array.) – The photon energy in eV.
- Returns:
The normalized vector (or stack of vectors) with the directions of K0corrected.
- Return type:
Vector instance
- vectorKh(energy)[source]
returns KH that verifies Laue equation with K0
- Parameters:
energy (float or numpy array) – The energy or energy array
- Returns:
The KH vector or vector stack
- Return type:
Vector instance
- vectorKhdirection(energy)[source]
returns an unitary vector along the KH direction (that that verifies Laue equation with K0).
- Parameters:
energy (float or numpy array) – The energy or energy array
- Returns:
The unitary vector(s) along the KH direction(s).
- Return type:
Vector instance
- vectorKscattered(K_IN=None, energy=8000.0)[source]
- returns the scattered K vector following the scattering equation at a surface:
- Parameters:
K_IN (instance of Vector, optional) – The K vector. If None, used the vectorK0corrected(energy)
energy (float, optional) – The energy value in eV (used only if K_IN=None)
- Returns:
Vector with the scattered K.
- Return type:
Vector instance
- vectorNormalSurface()[source]
Returns the normal to the surface. (0,0,1) by definition.
- Returns:
Vector instance with Surface normal Vnor.
- Return type:
Vector instance
crystalpy.diffraction.DiffractionSetupDabax module
Represents a diffraction setup implementation using DABAX photon energy in eV dSpacing returns A units are in SI.
- class crystalpy.diffraction.DiffractionSetupDabax.DiffractionSetupDabax(geometry_type=None, crystal_name='', thickness=1e-06, miller_h=1, miller_k=1, miller_l=1, asymmetry_angle=0.0, azimuthal_angle=0.0, crystal_data=None, dabax=None)[source]
Bases:
DiffractionSetupAbstractConstructor.
- Parameters:
geometry_type (instance of BraggDiffraction, LaueDiffraction, BraggTransmission, or LaueTransmission) –
crystal_name (str) – The name of the crystal, e.g. “Si”.
thickness (float) – The crystal thickness in m.
miller_h (int) – Miller index H.
miller_k (int) – Miller index K.
miller_l (int) – Miller index L.
asymmetry_angle (float) – The asymmetry angle between surface normal and Bragg normal (radians).
azimuthal_angle (float) – The angle between the projection of the Bragg normal on the crystal surface plane and the Y axis (radians). It can also be called inclination angle.
debye_waller (float) – The Debye-Waller factor exp(-M).
crystal_data (None or dict) – If None, the crystal data is loaded from dabax Crystals.dat file (entry: crystal_name). Alternatively, we can force using a user-structure entered here as a dictionary with the xraylib format.
dabax (DabaxXraylib instance, optional) – Default : None, use DabaxXraylib()
- F0(energy)[source]
Calculate the structure factor F0.
- Parameters:
energy (float) – photon energy in eV. (Default value = 8000.0)
- Returns:
F0
- Return type:
complex
- FH(energy, rel_angle=1.0)[source]
Calculate the structure factor FH.
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
rel_angle (float, optional) – ratio of the incident angle and the Bragg angle (Default : rel_angle=1.0)
- Returns:
FH
- Return type:
complex
- FH_bar(energy, rel_angle=1.0)[source]
Calculate the structure factor FH_bar.
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
rel_angle (float, optional) – ratio of the incident angle and the Bragg angle (Default : rel_angle=1.0)
- Returns:
FH_bar
- Return type:
complex
- Fall(energy, rel_angle=1.0)[source]
Calculate the all structure factor (F0, FH, FH_bar).
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
rel_angle (float, optional) – ratio of the incident angle and the Bragg angle (Default : rel_angle=1.0)
- Returns:
(F0, FH, FH_bar).
- Return type:
tuple
- angleBragg(energy)[source]
Returns the Bragg angle for a given energy in radians.
- Parameters:
energy – Energy to calculate the Bragg angle for. (Default value = 8000.0)
- Returns:
Bragg angle in radians.
- Return type:
float
crystalpy.diffraction.DiffractionSetupShadowPreprocessorV1 module
Represents a diffraction setup implementation using material data from shadow bragg preprocessor V1 photon energy in eV dSpacing returns A units are in SI.
- class crystalpy.diffraction.DiffractionSetupShadowPreprocessorV1.DiffractionSetupShadowPreprocessorV1(geometry_type=None, crystal_name='', thickness=1e-06, miller_h=1, miller_k=1, miller_l=1, asymmetry_angle=0.0, azimuthal_angle=0.0, preprocessor_file='')[source]
Bases:
DiffractionSetupAbstractConstructor.
- Parameters:
geometry_type (instance of BraggDiffraction, LaueDiffraction, BraggTransmission, or LaueTransmission) –
crystal_name (str) – The name of the crystal, e.g. “Si”.
thickness (float) – The crystal thickness in m.
miller_h (int) – Miller index H.
miller_k (int) – Miller index K.
miller_l (int) – Miller index L.
asymmetry_angle (float) – The asymmetry angle between surface normal and Bragg normal (radians).
azimuthal_angle (float) – The angle between the projection of the Bragg normal on the crystal surface plane and the Y axis (radians). It can also be called inclination angle.
debye_waller (float) – The Debye-Waller factor exp(-M).
preprocessor_file (str) – The preprocessor file name.
- F0(energy)[source]
Calculate the structure factor F0.
- Parameters:
energy (float) – photon energy in eV. (Default value = 8000.0)
- Returns:
F0
- Return type:
complex
- FH(energy, rel_angle=1.0)[source]
Calculate the structure factor FH.
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
rel_angle (float, optional) – ratio of the incident angle and the Bragg angle (Default : rel_angle=1.0)
- Returns:
FH
- Return type:
complex
- FH_bar(energy, rel_angle=1.0)[source]
Calculate the structure factor FH_bar.
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
rel_angle (float, optional) – ratio of the incident angle and the Bragg angle (Default : rel_angle=1.0)
- Returns:
FH_bar
- Return type:
complex
- Fall(energy, rel_angle=1.0)[source]
Calculate the all structure factor (F0, FH, FH_bar).
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
rel_angle (float, optional) – ratio of the incident angle and the Bragg angle (Default : rel_angle=1.0)
- Returns:
(F0, FH, FH_bar).
- Return type:
tuple
- angleBragg(energy)[source]
Returns the Bragg angle for a given energy in radians.
- Parameters:
energy – Energy to calculate the Bragg angle for. (Default value = 8000.0)
- Returns:
Bragg angle in radians.
- Return type:
float
- dSpacing()[source]
Returns the lattice spacing d in A.
- Returns:
Lattice spacing. in A
- Return type:
float
crystalpy.diffraction.DiffractionSetupShadowPreprocessorV2 module
Represents a diffraction setup implementation using material data from shadow bragg preprocessor V1 photon energy in eV dSpacing returns A units are in SI.
- class crystalpy.diffraction.DiffractionSetupShadowPreprocessorV2.DiffractionSetupShadowPreprocessorV2(geometry_type=None, crystal_name='', thickness=1e-06, miller_h=1, miller_k=1, miller_l=1, asymmetry_angle=0.0, azimuthal_angle=0.0, preprocessor_file='')[source]
Bases:
DiffractionSetupAbstractConstructor.
- Parameters:
geometry_type (instance of BraggDiffraction, LaueDiffraction, BraggTransmission, or LaueTransmission) – The crystal geometry.
crystal_name (str, optional) – The name of the crystal, e.g. “Si”.
thickness (float, optional) – The crystal thickness in m.
miller_h (int, optional) – Miller index H.
miller_k (int, optional) – Miller index K.
miller_l (int, optional) – Miller index L.
asymmetry_angle (float, optional) – The asymmetry angle between surface normal and Bragg normal (radians).
azimuthal_angle (float, optional) – The angle between the projection of the Bragg normal on the crystal surface plane and the x axis (radians).
debye_waller (float, optional) – The Debye-Waller factor exp(-M).
preprocessor_file (str, optional) – The preprocessor file name.
- Return type:
instance of DiffractionSetupShadowPreprocessorV2.
- F0(energy)[source]
Calculate the structure factor F0.
- Parameters:
energy (float or numpy array) – photon energy in eV. (Default value = 8000.0).
- Returns:
F0.
- Return type:
complex or numpy array
- FH(energy, rel_angle=1.0)[source]
Calculate the structure factor FH.
- Parameters:
energy (float or numpy array) – photon energy in eV.
rel_angle (float or numpy array, optional) – ratio of the incident angle and the Bragg angle (Default : rel_angle=1.0)
- Returns:
FH.
- Return type:
complex or numpy array
- FH_bar(energy, rel_angle=1.0)[source]
Calculate the structure factor FH_bar.
- Parameters:
energy (float or numpy array) – photon energy in eV.
rel_angle (float or numpy array, optional) – ratio of the incident angle and the Bragg angle (Default : rel_angle=1.0).
- Returns:
FH_bar.
- Return type:
complex or numpy array
- Fall(energy, rel_angle=1.0)[source]
Calculate the all structure factor (F0, FH, FH_bar).
- Parameters:
energy (float or numpy array) – photon energy in eV.
rel_angle (float or numpy array, optional) – ratio of the incident angle and the Bragg angle (Default : rel_angle=1.0).
- Returns:
(F0, FH, FH_bar).
- Return type:
tuple
- angleBragg(energy)[source]
Returns the Bragg angle for a given energy in radians.
- Parameters:
energy (float or numpy array) – Energy to calculate the Bragg angle for. (Default value = 8000.0).
- Returns:
Bragg angle in radians.
- Return type:
float or numpy array
- crystalpy.diffraction.DiffractionSetupShadowPreprocessorV2.crystal_fh(input_dictionary, phot_in, theta=None, forceratio=0)[source]
Computes the structure factors and other parameters for a given photon energy (or array).
- Parameters:
input_dictionary (dict) – as resulting from bragg_calc().
phot_in (float or numpy array) – photon energy in eV.
theta (float or numpy array, optional) – incident angle (half of scattering angle) in rad (Default value = None).
forceratio (int, float or numpy array, optional) – Value of sin(theta)/lambda to be used when calculating F0. By default, forceratio=0, it means that this ratio is automatically calculated used the Bragg angle.
- Returns:
return {“PHOT”:phot, “WAVELENGTH”:r_lam0*1e-2 ,”THETA”:itheta, “F_0”:F_0, “FH”:FH, “FH_BAR”:FH_BAR, “STRUCT”:STRUCT, “psi_0”:psi_0, “psi_h”:psi_h, “psi_hbar”:psi_hbar, “DELTA_REF”:DELTA_REF, “REFRAC”:REFRAC, “ABSORP”:ABSORP, “RATIO”:ratio, “ssr”:ssr, “spr”:spr, “psi_over_f”:psi_over_f, “info”:txt}.
- Return type:
dict
crystalpy.diffraction.DiffractionSetupSweeps module
Represents a diffraction setup (from where it inherits) and includes a photon beam with scanning photon energy and deviation angle (scattering plane is YZ plane)
Units are in SI except for photon energy in eV. Angles in radians.
- class crystalpy.diffraction.DiffractionSetupSweeps.DiffractionSetupSweeps(geometry_type, crystal_name, thickness, miller_h, miller_k, miller_l, asymmetry_angle, azimuthal_angle, energy_min, energy_max, energy_points, angle_deviation_min, angle_deviation_max, angle_deviation_points)[source]
Bases:
DiffractionSetupXraylibConstructor.
- Parameters:
geometry_type (instance of BraggDiffraction, LaueDiffraction, BraggTransmission, or LaueTransmission) –
crystal_name (str) – The name of the crystal, e.g. “Si”.
thickness (float) – The crystal thickness in m.
miller_h (int) – Miller index H.
miller_k (int) – Miller index K.
miller_l (int) – Miller index L.
asymmetry_angle (float) – The asymmetry angle between surface normal and Bragg normal (radians).
azimuthal_angle (float) – The angle between the projection of the Bragg normal on the crystal surface plane and the Y axis (radians). It can also be called the inclination angle.
energy_min (float) – The minimum energy in eV.
energy_max (float) – The maximum energy in eV.
energy_points (int) – Number of energy points.
angle_deviation_min (float) – Minimal angle deviation in rad.
angle_deviation_max (float) – Maximal angle in rad.
angle_deviation_points (int) – Number of deviations points.
- angleDeviationGrid()[source]
Returns the grid of angle deviations according to this setup. :return: The angle deviations grid.
crystalpy.diffraction.DiffractionSetupXraylib module
Represents a diffraction setup implementation using xraylib photon energy in eV dSpacing returns A units are in SI.
- class crystalpy.diffraction.DiffractionSetupXraylib.DiffractionSetupXraylib(geometry_type=None, crystal_name='', thickness=1e-06, miller_h=1, miller_k=1, miller_l=1, asymmetry_angle=0.0, azimuthal_angle=0.0, crystal_data=None)[source]
Bases:
DiffractionSetupAbstractConstructor.
- Parameters:
geometry_type (instance of BraggDiffraction, LaueDiffraction, BraggTransmission, or LaueTransmission) –
crystal_name (str) – The name of the crystal, e.g. “Si”.
thickness (float) – The crystal thickness in m.
miller_h (int) – Miller index H.
miller_k (int) – Miller index K.
miller_l (int) – Miller index L.
asymmetry_angle (float) – The asymmetry angle between surface normal and Bragg normal (radians).
azimuthal_angle (float) – The angle between the projection of the Bragg normal on the crystal surface plane and the Y axis (radians). It can also be called inclination angle.
crystal_data (None or dict) – If None, the crystal data is loaded from xraylib (entry: crystal_name). Alternatively, we can force using a user-structure entered here as a dictionary with the xraylib format.
debye_waller (float) – The Debye-Waller factor exp(-M).
- F0(energy)[source]
Calculate the structure factor F0.
- Parameters:
energy (float) – photon energy in eV. (Default value = 8000.0)
- Returns:
F0
- Return type:
complex
- FH(energy, rel_angle=1.0)[source]
Calculate the structure factor FH.
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
rel_angle (float, optional) – ratio of the incident angle and the Bragg angle (Default : rel_angle=1.0)
- Returns:
FH
- Return type:
complex
- FH_bar(energy, rel_angle=1.0)[source]
Calculate the structure factor FH_bar.
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
rel_angle (float, optional) – ratio of the incident angle and the Bragg angle (Default : rel_angle=1.0)
- Returns:
FH_bar
- Return type:
complex
- Fall(energy, rel_angle=1.0)[source]
Calculate the all structure factor (F0, FH, FH_bar).
- Parameters:
energy – photon energy in eV. (Default value = 8000.0)
rel_angle (float, optional) – ratio of the incident angle and the Bragg angle (Default : rel_angle=1.0)
- Returns:
(F0, FH, FH_bar).
- Return type:
tuple
- angleBragg(energy)[source]
Returns the Bragg angle for a given energy in radians.
- Parameters:
energy – Energy to calculate the Bragg angle for. (Default value = 8000.0)
- Returns:
Bragg angle in radians.
- Return type:
float
crystalpy.diffraction.GeometryType module
Represents geometry types/setups: Bragg diffraction, BraggTransmission, Laue diffraction, Laue transmission.
- class crystalpy.diffraction.GeometryType.BraggDiffraction[source]
Bases:
GeometryTypeRepresents Bragg diffraction.
- class crystalpy.diffraction.GeometryType.BraggTransmission[source]
Bases:
GeometryTypeRepresents Bragg transmission.
- class crystalpy.diffraction.GeometryType.GeometryType(description)[source]
Bases:
objectConstructor.
- Parameters:
description – Description of the geometry type, e.g. “Bragg transmission”
- class crystalpy.diffraction.GeometryType.LaueDiffraction[source]
Bases:
GeometryTypeRepresents Laue diffraction.
- class crystalpy.diffraction.GeometryType.LaueTransmission[source]
Bases:
GeometryTypeRepresents Laue transmission.
crystalpy.diffraction.PerfectCrystalDiffraction module
Calculates crystal diffraction according to Guigay and Zachariasen formalisms of the dynamic theory of crystal diffraction for perfect crystals. Except for energy all units are in SI. Energy is in eV.
- class crystalpy.diffraction.PerfectCrystalDiffraction.PerfectCrystalDiffraction(geometry_type, bragg_normal, surface_normal, bragg_angle, psi_0, psi_H, psi_H_bar, thickness, d_spacing, calculation_strategy_flag)[source]
Bases:
objectPerfectCrystalDiffraction is the calculator of the perfect crystal.
Two steps: * create the PerfectCrystalDiffraction instance with the crystal data (usually picked up from DiffractionSetup). * call PerfectCrystalDiffraction.calculateDiffraction( photon(s) )
Notes: * arrays can be used, but compatible arrays in photons and in bragg_angle, psi_0, psi_H, psi_H, etc. * Both sigma and pi amplitudes can be calculated in the same call, not need to create different
instances for sigma and pi.
Constructor.
- Parameters:
geometry_type (instance of BraggDiffraction, LaueDiffraction, BraggTransmission, or LaueTransmission) –
bragg_normal (instance of Vector) – The H vector.
surface_normal (instance of Vector) – The n vector.
bragg_angle (float or numpy array) – The Bragg angle(s).
psi_0 (complex of numpy array) – The structire factor Psi0.
psi_H (complex of numpy array) – The structire factor PsiH.
psi_H_bar (complex of numpy array) – The structire factor Psi(-H).
thickness (float) – the crystal thickness in m.
d_spacing (float) – the crystal dSpacing in m.
calculation_strategy_flag (int) – For computing exp, sin, cos: 0: use mpmath, 1: use numpy, 2=use numpy truncated.
- Psi0()[source]
Returns Psi0 as defined in Zachariasen [3-95].
- Returns:
The Psi0 value.
- Return type:
complex or numpy array
- PsiH()[source]
Returns PsiH as defined in Zachariasen [3-95].
- Returns:
The PsiH value.
- Return type:
complex or numpy array
- PsiHBar()[source]
Returns PsiHBar as defined in Zachariasen [3-95].
- Returns:
The PsiHBar value.
- Return type:
complex or numpy array
- braggAngle()[source]
Returns the Bragg angle.
- Returns:
The Bragg angle in rad.
- Return type:
float or numpy array
- braggNormal()[source]
Returns the Bragg normal, i.e. normal on the reflection planes with modulus 2 pi / d_spacing.
- Returns:
The H vector (normal to Bragg planes, modulus 2 pi / d_spacing in m^-1))
- Return type:
instance of Vector
- calculateDiffraction(photon_in, calculation_method=0, is_thick=0, use_transfer_matrix=0)[source]
Calculate diffraction for incoming photon.
- Parameters:
photon_in (instance of ComplexAmplitudePhoton) – Incoming photon or Photon bunch.
calculation_method (int) – 0 : Zachariasen, 1 : Guigay
is_thick (int) – 0=No, 1=Yes (for calculation_method=1 only)
use_transfer_matrix (int) – 0=No, 1=Yes (for calculation_method=1 only)
- Returns:
The complex amplitudes of the diffraction weighted for power for the two polarizations are found in the kwys [“S”] and [“P”].
- Return type:
dict
- calculateDiffractionGuigay(photon_in, debug=0, s_ratio=None, is_thick=0, use_transfer_matrix=0)[source]
Calculate diffraction for incoming photon.
- Parameters:
photon_in (instance of ComplexAmplitudePhoton) – Incoming photon or photon bunch.
debug (int) – 0=No, 1=Yes.
s_ratio (float) – the sin(theta)/lambda ratio (if None (default) it is calculated from Bragg law).
is_thick (int) – 0=No, 1=Yes.
use_transfer_matrix (int) – 0=No, 1=Yes. It is is faster to use use_transfer_matrix=0.
- Returns:
The complex amplitudes of the diffraction weighted for power for the two polarizations are found in the kwys [“S”] and [“P”]. If use_transfer_matrix=1, other optional parameters are found at the keys: * sigma-polarized reflectivity: “s” * pi-polarized reflectivity: “p” * Transfer matrix: “m11_s” “m12_s” “m21_s” “m22_s” “m11_p” “m12_p” “m21_p” “m22_p” * Scattering matrix: “s11_s” “s12_s” “s21_s” “s22_s” “s11_p” “s12_p” “s21_p” “s22_p” * “gamma_0” * “alpha” * “b”
- Return type:
dict
- calculateDiffractionZachariasen(photon_in)[source]
Calculate diffraction for incoming photon.
- Parameters:
photon_in (instance of ComplexAmplitudePhoton) – Incoming photon or photon bunch.
- Returns:
The complex amplitudes of the diffraction weighted for power for the two polarizations are found in the kwys [“S”] and [“P”].
- Return type:
dict
- calculatePhotonOut(photon_in, method=1, apply_reflectivity=False, calculation_method=0, is_thick=0, use_transfer_matrix=0)[source]
Solves the scattering equation to calculates the outgoing photon from the incoming photon and the Bragg normal.
In case of diffracted photon (Laue or Bragg) 1) Calculates the parallel component of K: k_out_par = k_in_par + H_par 2) Uses the conservation of the wavevector modulus to calculate the k_out_perp
todo: In case of forward diffracted (transmitted) Bragg or Laue:
It is valid for diffraction not at the Bragg angle.
Warning
Note that the new photon has correct direction, but the complex amplitudes are not changed, just copied from the photon in.
- Parameters:
photon_in (instance of ComplexAmplitudePhoton) – Incoming photon or photon bunch.
method (int) – select the calculated method: 0=old (to be deleted), 1=new
- Returns:
Outgoing photon or photon bunch
- Return type:
instance of ComplexAmplitudePhoton
- calculateScatteringMatrix(photon_in, polarization=0, alpha=None, guigay_b=None, T=None)[source]
Calculates the terms of the scattering matrix (see equation XXX in Guigay and Sanchez del Rio). :param photon_in: Incoming photon or photon bunch. :type photon_in: instance of ComplexAmplitudePhoton :param polarization: 0=sigma, 1=pi. :type polarization: int :param is_thick: Use thick crystal approximation: 0=No, 1=Yes. :type is_thick: int :param alpha: The alpha value (if None, it is internally calculated). :type alpha: float or numpy array :param guigay_b: The b (asymmetry factor) value (if None, it is internally calculated). :type guigay_b: float or numpy array :param T: The T (thickness along s0) value (if None, it is internally calculated). :type T: float or numpy array
- Returns:
the terms of the scattering matrix: (s11, s12, s21, s22).
- Return type:
tuple
- classmethod calculateScatteringMatrixFromTransferMatrix(transfer_matrix)[source]
Calculate the scattering matrix from the known transfer matrix (see equation XXX in Guigay and Sanchez del Rio).
- Parameters:
transfer_matrix (tuple) – the terms of the transfer matrix: (m11, m12, m21, m22).
- Returns:
the terms of the scattering matrix: (s11, s12, s21, s22).
- Return type:
tuple
- calculateTransferMatrix(photon_in, polarization=0, is_thick=0, alpha=None, guigay_b=None, T=None)[source]
Calculates the transfer matrix (see equation XXX in Guigay and Sanchez del Rio).
- Parameters:
photon_in (instance of ComplexAmplitudePhoton) – Incoming photon or photon bunch.
polarization (int) – 0=sigma, 1=pi.
is_thick (int) – Use thick crystal approximation: 0=No, 1=Yes.
alpha (float or numpy array) – The alpha value (if None, it is internally calculated).
guigay_b (float or numpy array) – The b (asymmetry factor) value (if None, it is internally calculated).
T (float or numpy array) – The T (thickness along s0) value (if None, it is internally calculated).
- Returns:
the terms of the transfer matrix: (m11, m12, m21, m22).
- Return type:
tuple
- dSpacing()[source]
Returns the distance between the reflection planes in A.
- Returns:
Distance between the reflection planes in A.
- Return type:
float or numpy array
- geometryType()[source]
Returns the geometry types, i.e. BraggTransmission, LaueDiffraction,…
- Returns:
geometry_type
- Return type:
instance of BraggDiffraction, LaueDiffraction, BraggTransmission, or LaueTransmission
- classmethod initializeFromDiffractionSetupAndEnergy(diffraction_setup, energy, geometry_type=None, bragg_normal=None, surface_normal=None, thickness=None, d_spacing=None, calculation_strategy_flag=0)[source]
Creates a PerfectCrystalDiffraction instance from parameters in a DiffractionSetupAbstract instance and a photon energy array.
- Parameters:
diffraction_setup (instance of PerfectCrystalDiffraction) –
energy (numpy array) –
geometry_type (instance of BraggDiffraction, LaueDiffraction, BraggTransmission, or LaueTransmission) –
bragg_normal (instance of Vector, optional) – if None, retrieve from DiffractionSetup
surface_normal (instance of Vector, optional) – if None, retrieve from DiffractionSetup
thickness (float or numpy array, optional) – crystal thickness in m. If None, retrieve from DiffractionSetup
d_spacing (float or numpy array) – d-spacing in m. If None, retrieve from DiffractionSetup
calculation_strategy_flag (int, optional) – For computing exp, sin, cos: 0: use mpmath, 1: use numpy, 2=use numpy truncated.
- Return type:
PerfectCrystalDiffraction instance
- isDebug = False
- surfaceNormal()[source]
Returns the surface normal that points outwards the crystal.
- Returns:
The normal to the surface.
- Return type:
instance of Vector