pyxem / orix

Analysing crystal orientations and symmetry in Python
https://orix.readthedocs.io
GNU General Public License v3.0
78 stars 45 forks source link

Automatic plotting of symmetry elements for a point group (`Symmetry`) in the stereographic projection #456

Open hakonanes opened 10 months ago

hakonanes commented 10 months ago

We get the Cartesian coordinates of a direct [uvw] or reciprocal lattice vector (hkl) in any of the seven crystal systems (triclinic, monoclinic, orthorhombic, trigonal, tetragonal, hexagonal, and cubic) by using the structure matrix A. This matrix is constructed by aligning the reference frames of the direct (a, b, c) and reciprocal lattices (a, b, c) with an orthonormal Cartesian reference frame (e1, e2, e3). In orix, we only support one alignment, namely e1 || a, e2 || e3 x e1, and e3 || c. Details are given in this tutorial: https://orix.readthedocs.io/en/stable/tutorials/crystal_reference_frame.html. I suggest we allow any alignment, e.g. e1 || a*, e2 || e3 x e1, and e3 || c, which is used by diffpy.structure. This is a convenience for the user and for developers of other packages relying or planning to rely on orix.

To understand this alignment, the convention, and to debug this addition, we should have automatic plotting of symmetry elements for a point group. There is already functionality for plotting symmetry elements (see this example), but it is not automatic. I've started working on this in a branch in my fork, but haven't found time to continue. I haven't figured out the algorithm yet, either. It would be best if we figure out the visualization based on the symmetry elements dynamically and not by hard-coding... Any help with this would be much appreciated.

My plan is to:

rbjorge commented 10 months ago

Does mtex do this automatically? https://mtex-toolbox.github.io/CrystalReferenceSystem.html

hakonanes commented 10 months ago

Yes, and as you can see from that tutorial, it is very useful to understand crystal axes alignments.

However, if possible, I don't want us to just copy MTEX as this further reduces our chances of re-licensing orix (see https://github.com/pyxem/orix/discussions/389).

CSSFrancis commented 10 months ago

Yea I think some sort of visualization would be very helpful (especially for someone like me who is pretty crystallographically illiterate). It's also on my list of things to do. :) Something like a html representation similar to how dask shows chunks would be nice. Most of that is just fancy html and jinja. I've looked into it a bit and I don't think it would too difficult. We could also just plot with Matplotlib which would be nice as well and would be potentially much easier.

If we wanted to be very fancy I've thought about playing around with ipywidgets as well. That would give us more of an interactive 3d representation.

hakonanes commented 10 months ago

Yea I think some sort of visualization would be very helpful

Note that we already have this tutorial (linked above) for visualizing point groups. It doesn't show which symmetry element rotated which point to where, though, which is what I want with the suggested new plot.

Something like a html representation

I think changing the default of Symmetry.plot(), as I suggested above, is the easiest choice at the moment. We have a stereographic projection that is used in many parts of the code (and for classes in diffsims and in kikuchipy) and we should use this. We already have plotting of symmetry elements, we just need to find the right visualization (elipse, triangle, square, hexagon, mirror plane, or inversion) and position for each element in a group...

That would give us more of an interactive 3d representation.

Real 3D would be nice (and not pseudo-3D as with Matplotlib). I've used PyVista for this in kikuchipy, which works great. Time will tell if anyone finds the time to consider real 3D plotting for orix.

hakonanes commented 10 months ago

Here's a figure I've made of the representation of the eleven Laue classes I'd like (based on the visualization by De Graef and McHenry). The figure has the same licensing as orix as of August 30 2023.

laue_groups_symmetry_elements