Closed viljarjf closed 3 months ago
@viljarjf Wow thank you for digging into this! Let me go through this a little bit more tomorrow just to check. It seems like this is correct, but I just have to run some more tests.
I agree, this seems like a bug in orix. Looking forward to review a PR!
I'll have to test that PR change against kikuchipy as well.
@viljarjf Do you want to submit a PR to orix?
Yes, let me just write it up
I'd say we can close this as the bug was fixed by @viljarjf in orix in https://github.com/pyxem/orix/pull/469.
Describe the bug I believe I found the bug making the two simulations different in #201. When a
Phase
-object is initialized, thestructure
is transformed to ensure x || a and z || c*. This changesstructure.lattice
, naturally, but according to the diffpy documentation, the xyz coordinates of the atoms are in the lattice coordinate system, regardless of them being transformed. Still, in https://github.com/CSSFrancis/diffsims/blob/use_phase_class/diffsims/utils/sim_utils.py#L281-L282, the positions of the atoms are transformed according to the lattice basis.Since these lines are really old, I am probably wrong in thinking they should not be there.
Instead, there might be a bug when setting the transformed lattice in the
Phase.structure
-setter, where the positions of the atoms are still expressed as if they were in the old basis. This can be mitigated by copying the old cartesian positions and setting them again after transforming the basis.With either approach (removing the two lines linked, or fixing the coordinates), the simulations are identical, and in both cases they more closely resemble the output of ASTAR diffgen. However, in the case of the transformed basis, the
mat
in the linked lines is NOT the identity matrix. Therefore, I'm leaning more towards this being a bug in thePhase.structure
-setter.As a sidenote: I believe transposing
recbase
in https://github.com/CSSFrancis/diffsims/blob/use_phase_class/diffsims/utils/sim_utils.py#L281 is incorrect, and seems to be the cause of the discrepancy between ASTAR and the old simulation. Since transposing is a new change, not present before this PR, and the "old" simulations we have been comparing have been made with the new transposing.To Reproduce Might not be minimum working example, but at least an example.
Intensities differ by around (0.05 - 0.004) $\approx$ 0.05, i.e. 10x
Expected behavior By removing
.T
in https://github.com/CSSFrancis/diffsims/blob/use_phase_class/diffsims/utils/sim_utils.py#L281, and by adding the following to https://github.com/pyxem/orix/blob/develop/orix/crystal_map/phase_list.py#L137-L139:the output of the example above becomes:
i.e. both practically identical simulations (intensity differences around 1e-11 can probably be attributed to the imprecise euler angle matrix calculations in the old simulations, which are much better now), and both more closely resemble the output of ASTAR (https://github.com/pyxem/diffsims/pull/201#issuecomment-1926638205):
Additional context Using https://github.com/CSSFrancis/diffsims/tree/use_phase_class