Skip to content

Conversation

lan496
Copy link
Member

@lan496 lan496 commented Aug 3, 2024

Closes #515

We need to take absolute value for a determinant of a transformation matrix to calculate cell size.

Copy link

codecov bot commented Aug 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.12%. Comparing base (f0484ce) to head (d64a2e8).
Report is 12 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #517      +/-   ##
===========================================
+ Coverage    83.96%   84.12%   +0.16%     
===========================================
  Files           26       26              
  Lines         8122     8122              
  Branches      1702     1698       -4     
===========================================
+ Hits          6820     6833      +13     
+ Misses        1302     1289      -13     
Flag Coverage Δ
c_api 75.39% <100.00%> (+0.54%) ⬆️
fortran_api 56.29% <100.00%> (ø)
python_api 81.39% <100.00%> (ø)
unit_tests 13.48% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lan496 lan496 marked this pull request as ready for review August 3, 2024 00:57
@lan496 lan496 requested a review from LecrisUT August 3, 2024 00:57
Copy link
Collaborator

@LecrisUT LecrisUT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do a quick review of the other usages of determinant to see if something similar was missed somewhere else?

@lan496
Copy link
Member Author

lan496 commented Aug 3, 2024

I've checked the other parts properly take absolute values of determinants.

@lan496 lan496 requested a review from LecrisUT August 3, 2024 03:00
@LecrisUT
Copy link
Collaborator

LecrisUT commented Aug 4, 2024

Here are a few ones that should be investigated:

if (mat_get_determinant_d3(orig_lattice) > symprec) {

if (mat_get_determinant_d3(orig_lattice) > symprec) {

if (mat_get_determinant_d3(orig_lattice) > symprec) {

if (mat_get_determinant_d3(orig_lattice) > symprec) {

@LecrisUT LecrisUT mentioned this pull request Aug 4, 2024
@lan496
Copy link
Member Author

lan496 commented Aug 5, 2024

I am not confident with the mat_get_determinant_d3 in spacegroup.c.
@atztogo Are these if-statements fine without taking absolute values?

@atztogo
Copy link
Collaborator

atztogo commented Aug 5, 2024

mat_get_determinant_d3(orig_lattice) > symprec in spacegroup.c is used to find (a, b, c) vectors similar to the user input basis vectors.

Depending on symmetry, spglib might result in permutations like (b, c, a), etc., but it tries to align to (a, b, c). If the input basis vectors are in a left-handed coordinate system, spglib does not attempt to align them.

@lan496
Copy link
Member Author

lan496 commented Aug 5, 2024

mat_get_determinant_d3(orig_lattice) > symprec in spacegroup.c is used to find (a, b, c) vectors similar to the user input basis vectors.

I see. I understand abs are not required for these parts.

@LecrisUT
Copy link
Collaborator

LecrisUT commented Aug 5, 2024

I am still lost on this, probably because the naming orig_lattice is not descriptive. What happens if there are 2 permutations of the vector such that it is positive again? What does the determinant and its absolute mean in this case?

@atztogo
Copy link
Collaborator

atztogo commented Aug 6, 2024

I am still lost on this, probably because the naming orig_lattice is not descriptive. What happens if there are 2 permutations of the vector such that it is positive again? What does the determinant and its absolute mean in this case?

I may not understand your question fully, but it happens. The determinant is mostly used for calculating the volume of the unit cell (primitive cell, conventional unit cell, some cell that arises intermediately, etc), for which we take absolute. The volume can be used for various check for consistency check. For example, volume is not around zero, ratio of volumes of two cells is about integer, etc. When we want to check right handed or left handed, we don't take absolute. Positive or negative is checked. If negative, in some routine, the basis vectors are changed to right handed.

@LecrisUT
Copy link
Collaborator

LecrisUT commented Aug 6, 2024

I may not understand your question fully, but it happens. The determinant is mostly used for calculating the volume of the unit cell (primitive cell, conventional unit cell, some cell that arises intermediately, etc), for which we take absolute. The volume can be used for various check for consistency check. For example, volume is not around zero, ratio of volumes of two cells is about integer, etc. When we want to check right handed or left handed, we don't take absolute. Positive or negative is checked. If negative, in some routine, the basis vectors are changed to right handed.

Ok, but what about in the context of the 4 snippets above? According to the explanation it is only checking if the basis set is right-handed, but then why does it completely throw away the left-handed ones? Is it always supposed to be right-handed in that case, and if so an assert should be added to clarify it. Why are some checks against mat_get_determinant_d3() < 0, while the inverse is against mat_get_determinant_d3() > symprec if they are only checking for left/right handiness.

@atztogo
Copy link
Collaborator

atztogo commented Aug 6, 2024

It is not theoretical. It is just for letting users feel better. This is not a mandatory procedure. So we don't need to be strict.

Spglib returns transformation matrix, which suggest basis vectors of a conventinal unit cell (a_s, b_s, c_s) as written athttps://spglib.readthedocs.io/en/latest/definition.html#transformation-matrix-boldsymbol-p-and-origin-shift-boldsymbol-p.

If the user input cell (a, b, c) is right handed and conventional unit cell, I wanted to return similar basis vectors in Cartesian coordinates, (a, b, c) ~ (a_s, b_s, c_s). But since the returned basis vectors must be right handed per definition, if the user input cell is left handed, these never become similar. So searching similar basis vectors is not performed.

Copy link
Collaborator

@LecrisUT LecrisUT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I guess that clarifies that point

@lan496 lan496 enabled auto-merge August 6, 2024 10:51
@lan496 lan496 merged commit adf8bc1 into spglib:develop Aug 9, 2024
56 checks passed
@lan496 lan496 added this to the 2.6 milestone Jan 19, 2025
@lan496 lan496 deleted the fix-det-sign branch January 19, 2025 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation fault in get_magnetic_symmetry_dataset
3 participants