Skip to content
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

Duplicate rotations in spglib.get_symmetry #413

Closed
Zhuoying opened this issue Jan 31, 2024 · 8 comments
Closed

Duplicate rotations in spglib.get_symmetry #413

Zhuoying opened this issue Jan 31, 2024 · 8 comments

Comments

@Zhuoying
Copy link

Zhuoying commented Jan 31, 2024

Hi dear developers,
I recently found an inconsistency in get_symmetry_operations() in pymatgen when I update spglib from 1.16.5 to 2.2.0(or 2.3.0).
The details are given in pymatgen issue as linked here materialsproject/pymatgen#3545

I tried a few different versions of pymatgen and spglib and located the issue is caused by spglib.
My example is here:

from pymatgen.ext.matproj import MPRester
from importlib.metadata import version
from pymatgen.analysis.structure_matcher import StructureMatcher
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
import spglib
from pymatgen.core import Structure

sm=StructureMatcher()

print(f"pymatgen: {version('pymatgen')}")
print(f"spglib: {spglib.__version__}")

mpr=MPRester()
s1=mpr.get_structure_by_material_id("mp-2133",conventional_unit_cell=False)
s2=mpr.get_structure_by_material_id("mp-2133",conventional_unit_cell=True)

for symprec in [1e-5,1e-1]:
    for s in [s1,s2]:
        spg=SpacegroupAnalyzer(structure=s,symprec=symprec)
        print(f"symprec={symprec}")
        print("Space group type:", spg.get_space_group_symbol())
        print("Number of operations:", len(spg.get_space_group_operations())) 

When spglib==1.16.5, the output is

pymatgen: 2023.12.18
spglib: 1.16.5
symprec=1e-05
Space group type: P6_3mc
Number of operations: 12
symprec=1e-05
Space group type: P6_3mc
Number of operations: 12
symprec=0.1
Space group type: P6_3mc
Number of operations: 12
symprec=0.1
Space group type: P6_3mc
Number of operations: 12

When spglib==2.2.0, the output is

pymatgen: 2023.12.18
spglib: 2.2.0
symprec=1e-05
Space group type: P6_3mc
Number of operations: 24
symprec=1e-05
Space group type: P6_3mc
Number of operations: 12
symprec=0.1
Space group type: P6_3mc
Number of operations: 24
symprec=0.1
Space group type: P6_3mc
Number of operations: 12

Is there any insight you can give on this issue? Thanks in advance!

@atztogo
Copy link
Collaborator

atztogo commented Jan 31, 2024

Please describe your issue using the crystal structure format written at https://spglib.readthedocs.io/en/stable/python-interface.html#crystal-structure-cell.

@Andrew-S-Rosen
Copy link

@Zhuoying --- it would likely help the spglib developers out if you provide a minimal example that solely depends on spglib.

@Zhuoying
Copy link
Author

@Andrew-S-Rosen @atztogo Thanks for the notice. I provide a minimal example only using spglib here.

import spglib
print (spglib.__version__)

cell=([[1.644551, -2.848447, 0.0], [1.644551, 2.848447, 0.0], [0.0, 0.0, 5.306821]],
 [[0.666667, 0.333333, 0.500548],
  [0.333333, 0.666667, 0.000548],
  [0.666667, 0.333333, 0.879762],
  [0.333333, 0.666667, 0.379762]],
 [1, 1, 2, 2],
 [0.0, 0.0, 0.0, 0.0])

for symprec in [1e-5,1e-1]:
    dataset=spglib.get_symmetry_dataset(cell=cell,symprec=symprec)
    print(f"symprec={symprec}")
    print ("rotations from get_symmetry_dataset: ", len(dataset["rotations"]))
    dct=spglib.get_symmetry(cell=cell,symprec=symprec)
    print ("rotations from get_symmetry dict: ", len(dct["rotations"]))

The output is

2.2.0
symprec=1e-05
rotations from get_symmetry_dataset:  12
rotations from get_symmetry dict:  24
symprec=0.1
rotations from get_symmetry_dataset:  12
rotations from get_symmetry dict:  24

@Zhuoying
Copy link
Author

Basically, there are duplicates in spglib.get_symmetry()["rotations"] for some structures (like the example above).

I tested spglib==1.16.5, it does not have this bug.

@Zhuoying Zhuoying changed the title symmetry operation number depending on whether it is a conventional cell? Inconsistent rotations in spglib.get_symmetry and spglib.get_symmetry_dataset Jan 31, 2024
@Zhuoying Zhuoying changed the title Inconsistent rotations in spglib.get_symmetry and spglib.get_symmetry_dataset Duplicate rotations in spglib.get_symmetry Jan 31, 2024
@atztogo
Copy link
Collaborator

atztogo commented Jan 31, 2024

It is due to the backward incomaptibility.

As of version 2.0, the behavior of get_symmetry with zero magmoms (corresponding to type-II MSG) is changed. When all magmoms are zero, the newer get_symmetry returns the same spatial symmetry with time_reversal=True and time-reversal=False. This doubles the size of symmetry operations compared to the previous version.

https://spglib.readthedocs.io/en/stable/releases.html#get-symmetry

@Zhuoying
Copy link
Author

@atztogo Thanks for the quick feedback.
So for spglib 2.0+, it is safer to use get_symmetry_dataset rather than get_symmetry? If so, I will fix the incompatibility in pymatgen.symmetry.analyzer which massively uses spglib.
Thank you again!

@atztogo
Copy link
Collaborator

atztogo commented Jan 31, 2024

I don't know because I don't know what you want to do.

@lan496
Copy link
Member

lan496 commented Feb 1, 2024

@Zhuoying
If magmom is specified, get_symmetry tries to search for time reversal symmetry. If you would like to ignore the time-reversal symmetry, please use get_symmetry_dataset. I think pymatgen's SpaceGroupAnalyzer already handles it.
materialsproject/pymatgen#2727

@Zhuoying Zhuoying closed this as completed Mar 5, 2024
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

No branches or pull requests

4 participants