DanPorter / Dans_Diffraction

Reads crystallographic cif files and simulates diffraction
Apache License 2.0
44 stars 13 forks source link

[Question] how do phi, mu, chi, eta affect the detector image? #18

Closed SchrodingersCattt closed 1 month ago

SchrodingersCattt commented 1 month ago

Hi, Dan,

I hope this message finds you well.

I am currently studying diffraction simulation using your code and have encountered a few questions.

In the example example_detector_image.py, you pass mu as follows:

# Reflection
tth = xtl.Cell.tth([0, 0, 2], energy_kev=energy_kev)[0]
# Orient crystal to scattering position
xtl.Cell.orientation.rotate_6circle(mu=tth/2)
# Rotate detector to two-theta
delta, gamma = 0, tth

# Generate detector image
xx, yy, mesh, reflist = xtl.Scatter.detector_image(
    detector_distance_mm=detector_distance,
    delta=delta,
    gamma=gamma,
    height_mm=400.,
    width_mm=100.,
    pixel_size_mm=0.1,
    energy_range_ev=1.,
    peak_width_deg=0.5,
    wavelength_a=dif.fc.energy2wave(energy_kev),
    background=0
)

Upon examining the function rotate_6circle, I noticed that it only affects the rotation attribute instead of the labframe. However, in the detector_image function, it appears that the rotation attribute does not influence the result. Instead, the labframe seems to affect the position_mm and ultimately the generated image.

Could you please help me understand this discrepancy?

Thank you very much for your assistance.

Best regards!

DanPorter commented 1 month ago

Hi SchrodingersCattt!

Thanks very much for your interest in Dans_Diffraction :)

I'm afraid the rotation function is a little hidden in this context, but what xtl.Cell.orientation.rotate_6circle(mu=tth/2) is doing is rotating the crystal with respect to the lab frame, where the detector is defined. This appears in the detector_image function in the line:

qxqyqz = self.xtl.Cell.calculateQ(hkl)

Which calculates the reflection positions in the lab frame, because the unit cell of the crystal is rotated in the lab frame: https://github.com/DanPorter/Dans_Diffraction/blob/4665a159bc8704f3a027ca5c861b5336fb48d07e/Dans_Diffraction/classes_crystal.py#L639-L650

This uses Cell.UVstar() - the reciprocal unit cell, defined by the unit cell in cell.UV() which shows that the unit cell is rotated by 'Cell.orientation': https://github.com/DanPorter/Dans_Diffraction/blob/4665a159bc8704f3a027ca5c861b5336fb48d07e/Dans_Diffraction/classes_crystal.py#L588-L593

https://github.com/DanPorter/Dans_Diffraction/blob/4665a159bc8704f3a027ca5c861b5336fb48d07e/Dans_Diffraction/classes_orientation.py#L129-L131

I hope this clears thing up for you, but if not or if you have any other questions please ask!

I'll close this issue in a few days otherwise (or feel free to close yourself).

SchrodingersCattt commented 1 month ago

Thank you very much for the reply. It helps a lot!