New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix order of primitive basis for get_magnetic_symmetry #371
Conversation
@atztogo This PR fixes my mistake of not transposing in Python API. I've checked other lattices like |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #371 +/- ##
========================================
Coverage 83.80% 83.80%
========================================
Files 24 24
Lines 8167 8167
========================================
Hits 6844 6844
Misses 1323 1323
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I think this needs a bit more rethinking. Why are the lattices transposed when both C and python use the same row-major? Also, isn't all of the api supposed to go through |
They are transposed each other. https://spglib.readthedocs.io/en/latest/python-spglib.html#crystal-structure-cell This is due to historical reasons by my decisions. I started to develop phonopy in python and so I wanted to make the python interface of spglib. I thought it was a good idea to follow the convention of the ASE's Atoms class, because at that time, python was not popular in science, but ASE and GPAW did good jobs in implementation in python. Of course I could never expecte that spglib becomes so popular, so I decided it without deep consideration.
It is done in C for space group and magnetic space group. But the transpose has to be made for basis vecotrs in python. We made this mistake due to complication introduced to have compatibility to my old implementation. If I understand correctly, |
I also find the convention confusing, particularly the Python interface's need for lattice transposition. What's worse is that Julia uses column-major order, in contrast to C and Python's row-major order. This difference added an extra layer of confusion during the development of the Julia interface. To address this, I wrote documentation for my users. Nevertheless, I'm glad it's all sorted out.
Wow, that's some awesome work @lan496! |
If we have many wrappers, it may be good to have consensus about the definition of the basis vector matrix, where we can consider the python wrapper is an exception (because it is too late) and the others may, for example, follow the memory order in C. By this, in Fortran, it is transposed. However, in fact, we can introduce another confusion for atomic points either (num_points, 3) or (3, num_points). Finally @singularitti is right, documentation should ease the issue and developers have to be careful about it, if people think it is a better solution than developing an spglib-althernative with your favorite array definitions from scratch. |
You may (already) realize column-major basis vectors are so natural in implementing crystallographic algorithms, but at the same time, we want to use row-major ones in the row-major preferred languages like Python 😇 @atztogo Can I merge this PR? |
For the Python/C interface, the column/row major is not a problem, and the choice of column vectors is also perfectly fine. The issues here are rather:
|
Have you seen my comment above? Transpose of numpy array doesn't change data in memory, i.e., the order becomes 'F'. I prefer |
|
aeb969e
to
07e31ae
Compare
@atztogo Do you add comments on the code? If so, I cannot see it now. Anyway, I copied the array. |
Sorry, I didn't realize that I had to push the button to submit request the change. |
Not a problem at all. I have also had the same trouble before. |
07e31ae
to
6bbcb7d
Compare
Fixes: #370