Unique hkls from calculate_diffraction1d are not correct for a non-cubic system
Describe the bug When using the calculate_diffraction1d function with a tetragonal crystal, the hkl values that were returned are only those valid for a cubic crystal. For example, calculate_diffraction1d with a tetragonal PdO crystal will only return (211) even though it should also return (112).
To Reproduce Steps to reproduce the behavior:
@wiscott24 Hmmm. Do you know what happens for the 2D case?
Yea the caclulate 1D is a little wonky, it should be using the from_min_dspacing function like the 2D case.
The 2D case seems fine. After doing at bit of digging it seems like it might be coming from the get_unique_families function which is called from get_intensities_params in calculate_diffraction1d. This function just sorts the hkl list and checks if it has recorded it before.
How about something like this:
from diffsims.generators.simulation_generator import SimulationGenerator
from diffsims.crystallography import ReciprocalLatticeVector
from orix.crystal_map import Phase
import numpy as np
import matplotlib.pyplot as plt
p = Phase.from_cif("AMS_DATA-2.cif") #PdO
rpl = ReciprocalLatticeVector.from_min_dspacing(p)
rpl.calculate_structure_factor()
rpl = rpl.unique(use_symmetry=True)
x = np.linspace(0, 1.5,1000)
intensity = np.abs(rpl.structure_factor)*rpl.multiplicity
y = np.zeros(1000)
sorted_g_ind = np.argsort(rpl.gspacing)
sorted_g = rpl.gspacing[sorted_g_ind]
sorted_hkl =rpl.hkl[sorted_g_ind]
indexes = np.searchsorted(x, rpl.gspacing)
y[indexes] = (rpl.structure_factor*rpl.structure_factor.conjugate()).real*rpl.multiplicity
inten = ((rpl.structure_factor*rpl.structure_factor.conjugate()).real*rpl.multiplicity)[sorted_g_ind]
plt.figure()
plt.plot(x, y)
for hkl, g, inte in zip(sorted_hkl, sorted_g, inten):
if inte>10:
plt.annotate( str(hkl), [g, inte], rotation=90)
Edit: using rpl.structure_factor*rpl.structure_factor.conjugate()).real
@viljarjf @hakonanes (did I do this right 😅)
And the HKL
[0., 0., 2.],
[0., 0., 3.],
[0., 0., 4.],
[0., 0., 5.],
[0., 0., 6.],
[0., 0., 7.],
[1., 0., 0.],
[1., 0., 1.],
[1., 0., 2.],
[1., 0., 3.],
[1., 0., 4.],
[1., 0., 5.],
[1., 0., 6.],
[1., 0., 7.],
[2., 0., 0.],
[2., 0., 1.],
[2., 0., 2.],
[2., 0., 3.],
[2., 0., 4.],
[2., 0., 5.],
[2., 0., 6.],
[3., 0., 0.],
[3., 0., 1.],
[3., 0., 2.],
[3., 0., 3.],
[3., 0., 4.],
[3., 0., 5.],
[4., 0., 0.],
[4., 0., 1.],
[4., 0., 2.],
[1., 1., 0.],
[1., 1., 1.],
[1., 1., 2.],
[1., 1., 3.],
[1., 1., 4.],
[1., 1., 5.],
[1., 1., 6.],
[1., 1., 7.],
[2., 1., 0.],
[2., 1., 1.],
[2., 1., 2.],
[2., 1., 3.],
[2., 1., 4.],
[2., 1., 5.],
[2., 1., 6.],
[3., 1., 0.],
[3., 1., 1.],
[3., 1., 2.],
[3., 1., 3.],
[3., 1., 4.],
[3., 1., 5.],
[4., 1., 0.],
[4., 1., 1.],
[4., 1., 2.],
[2., 2., 0.],
[2., 2., 1.],
[2., 2., 2.],
[2., 2., 3.],
[2., 2., 4.],
[2., 2., 5.],
[3., 2., 0.],
[3., 2., 1.],
[3., 2., 2.],
[3., 2., 3.],
[3., 2., 4.],
[3., 3., 0.],
[3., 3., 1.]])
With #238