pyxem / diffsims

An open-source Python library providing utilities for simulating diffraction
https://diffsims.readthedocs.io
GNU General Public License v3.0
46 stars 26 forks source link

Improved creation and handling of sets of reciprocal lattice vectors #188

Closed hakonanes closed 2 years ago

hakonanes commented 2 years ago

Description of the change

This PR introduces a new class ReciprocalLatticeVector, replacing ReciprocalLatticePoint for creation and handling of sets of reciprocal lattice vectors hk(i)l. The latter class only supported cubic phases, while the new class supports all crystallographic point groups. It does so by relying on orix for all (symmetrically reduced) vector handling via Miller, while not directly extending that class since the new class does not support direct lattice vectors. A new class is necessary, instead of just using Miller, for easy calculation of structure factors and Bragg angles. This class will be used in kikuchipy for (existing) geometrical and (to come) kinematical EBSD simulations.

This is the last thing I'd like to get released in v0.5.

Closes #144.

Progress of the PR

Minimal example of the bug fix or new feature

>>> from orix.crystal_map import Phase
>>> from diffsims.crystallography import ReciprocalLatticeVector
>>> phase = Phase.from_cif("al.cif")
>>> phase
<name: al. space group: Fm-3m. point group: m-3m. proper point group: 432. color: tab:blue>
>>> phase.structure
[Al   0.000000 0.000000 0.000000 1.0000,
 Al   0.000000 0.500000 0.500000 1.0000,
 Al   0.500000 0.000000 0.500000 1.0000,
 Al   0.500000 0.500000 0.000000 1.0000]
>>> phase.structure.lattice
Lattice(a=4.04958, b=4.04958, c=4.04958, alpha=90, beta=90, gamma=90)
>>> ref = ReciprocalLatticeVector.from_min_dspacing(phase, 0.7)
>>> ref[:10]
ReciprocalLatticeVector (10,), al (m-3m)
[[ 5.  2.  2.]
 [ 5.  2.  1.]
 [ 5.  2.  0.]
 [ 5.  2. -1.]
 [ 5.  2. -2.]
 [ 5.  1.  2.]
 [ 5.  1.  1.]
 [ 5.  1.  0.]
 [ 5.  1. -1.]
 [ 5.  1. -2.]]
>>> ref.calculate_structure_factor("xtables")
>>> ref.calculate_theta(20e3)
>>> ref = ref[ref.structure_factor.real > 0]
>>> ref.print_table()
 h k l      d       I     |F|_hkl  I_Rel.   Mult 
 1 1 1    2.338    72.1     8.5    100.0     8   
 2 0 0    2.025    50.0     7.1     69.3     6   
 2 2 0    1.432    19.8     4.4     27.4     12  
 3 1 1    1.221    13.1     3.6     18.2     24  
 2 2 2    1.169    11.8     3.4     16.3     8   
 4 0 0    1.012    8.1      2.9     11.3     6   
 3 3 1    0.929    6.5      2.5     9.0      24  
 4 2 0    0.906    6.0      2.5     8.4      24  
 4 2 2    0.827    4.7      2.2     6.5      24  
 3 3 3    0.779    4.0      2.0     5.5      8   
 5 1 1    0.779    4.0      2.0     5.5      24  
 4 4 0    0.716    3.1      1.8     4.4      12  
>>> fig = ref.draw_circle(axes_labels=["a", "b"], opening_angle=np.pi / 2 - ref.theta, return_figure=True, linewidth=0.75)
>>> ref.draw_circle(opening_angle=np.pi / 2 + ref.theta, figure=fig, linewidth=0.75)

al_dmin0_7_bands

For reviewers

hakonanes commented 2 years ago

There are many line additions in this PR, however:

I hope the docstring examples and inline comments are sufficient to understand the code.

EDIT: Generation of sets of vectors and calculation of structure factors have been compared for cubic, hexagonal and monoclinic phases to the Bruker DynamicS software.

EDIT 2: See the reference docs generated from this PR for an overview of the new class.

hakonanes commented 2 years ago

No pyxem tests in the current master branch fail when run on Ubuntu with this PR's version of diffsims.

pc494 commented 2 years ago

I'll be able to review this tomorrow, so we can probably get 0.5.0 out next week?

hakonanes commented 2 years ago

That would be fantastic, thank you Phillip. If this is merged tomorrow I suggest we release 0.5.0 right away.

pc494 commented 2 years ago

Tomorrow works for me, will try and get my review in early in that case

hakonanes commented 2 years ago

Fantastic, thank you a lot, Phillip. I'll update the release date in the changelog in #187, then we can merge that and publish 0.5.0.