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

Inconsistency in primitive_lattice results between get_magnetic_symmetry_dataset & get_magnetic_symmetry in the Python interface #370

Closed
singularitti opened this issue Dec 2, 2023 · 2 comments · Fixed by #371
Assignees
Labels

Comments

@singularitti
Copy link
Contributor

I've discovered an inconsistency in Spglib: the primitive_lattice results from get_magnetic_symmetry_dataset and get_magnetic_symmetry do not match. Specifically, the latter's output seems to be the transpose of the former's. This issue is consistent across multiple tests, not just a single instance.

Here's a brief code example demonstrating the problem:

>>> import numpy as np
>>> from spglib import get_magnetic_symmetry_dataset, get_magnetic_symmetry
>>> lattice = np.array(
        [
            [1.06949000e01, 0.00000000e00, 0.00000000e00],
            [3.84998337e-16, 6.28750000e00, 0.00000000e00],
            [3.09590711e-16, 3.09590711e-16, 5.05600000e00],
        ]
    )
>>> positions = np.array(
        [
            [0.0, 0.0, 0.0],
            [0.5, 0.0, 0.5],
            [0.5, 0.5, 0.5],
            [0.0, 0.5, 0.0],
            [0.2794, 0.25, 0.9906],
            [0.2206, 0.75, 0.4906],
            [0.7206, 0.75, 0.0094],
            [0.7794, 0.25, 0.5094],
        ]
    )
>>> numbers = [0, 0, 0, 0, 0, 0, 0, 0]
>>> magmoms = np.array(
        [
            [3.0, 0.4, 0.0],
            [-3.0, -0.4, 0.0],
            [-3.0, 0.4, 0.0],
            [3.0, -0.4, 0.0],
            [4.5, 0.0, 0.0],
            [-4.5, 0.0, 0.0],
            [4.5, 0.0, 0.0],
            [-4.5, 0.0, 0.0],
        ]
    )
>>> dataset = get_magnetic_symmetry_dataset((lattice, positions, numbers, magmoms))
>>> symdict = get_magnetic_symmetry((lattice, positions, numbers, magmoms))
>>> dataset
{'uni_number': 544, 'msg_type': 3, 'hall_number': 292, 'tensor_rank': 1, 'n_operations': 8, 'rotations': array([[[ 1,  0,  0],
        [ 0,  1,  0],
        [ 0,  0,  1]],

       [[-1,  0,  0],
        [ 0, -1,  0],
        [ 0,  0, -1]],

       [[-1,  0,  0],
        [ 0, -1,  0],
        [ 0,  0,  1]],

       [[ 1,  0,  0],
        [ 0,  1,  0],
        [ 0,  0, -1]],

       [[ 1,  0,  0],
        [ 0, -1,  0],
        [ 0,  0, -1]],

       [[-1,  0,  0],
        [ 0,  1,  0],
        [ 0,  0,  1]],

       [[-1,  0,  0],
        [ 0,  1,  0],
        [ 0,  0, -1]],

       [[ 1,  0,  0],
        [ 0, -1,  0],
        [ 0,  0,  1]]], dtype=int32), 'translations': array([[-0.00000000e+00, -0.00000000e+00, -0.00000000e+00],
       [-0.00000000e+00, -0.00000000e+00, -0.00000000e+00],
       [ 5.00000000e-01,  0.00000000e+00,  5.00000000e-01],
       [ 5.00000000e-01,  0.00000000e+00,  5.00000000e-01],
       [ 5.00000000e-01,  5.00000000e-01,  5.00000000e-01],
       [ 5.00000000e-01,  5.00000000e-01,  5.00000000e-01],
       [ 6.16297582e-33,  5.00000000e-01,  0.00000000e+00],
       [ 6.16297582e-33,  5.00000000e-01,  0.00000000e+00]]), 'time_reversals': array([False, False, False, False,  True,  True,  True,  True]), 'n_atoms': 8, 'equivalent_atoms': array([0, 0, 0, 0, 4, 4, 4, 4], dtype=int32), 'transformation_matrix': array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]]), 'origin_shift': array([0., 0., 0.]), 'n_std_atoms': 8, 'std_lattice': array([[1.06949000e+01, 0.00000000e+00, 0.00000000e+00],
       [3.84998337e-16, 6.28750000e+00, 0.00000000e+00],
       [3.09590711e-16, 3.09590711e-16, 5.05600000e+00]]), 'std_types': array([0, 0, 0, 0, 0, 0, 0, 0], dtype=int32), 'std_positions': array([[ 1.54074396e-33,  0.00000000e+00,  0.00000000e+00],
       [ 5.00000000e-01,  0.00000000e+00,  5.00000000e-01],
       [ 5.00000000e-01,  5.00000000e-01,  5.00000000e-01],
       [-4.62223187e-33,  5.00000000e-01,  0.00000000e+00],
       [ 2.79400000e-01,  2.50000000e-01,  9.90600000e-01],
       [ 2.20600000e-01,  7.50000000e-01,  4.90600000e-01],
       [ 7.20600000e-01,  7.50000000e-01,  9.40000000e-03],
       [ 7.79400000e-01,  2.50000000e-01,  5.09400000e-01]]), 'std_tensors': array([[ 3. ,  0.4,  0. ],
       [-3. , -0.4,  0. ],
       [-3. ,  0.4,  0. ],
       [ 3. , -0.4,  0. ],
       [ 4.5,  0. ,  0. ],
       [-4.5,  0. ,  0. ],
       [ 4.5,  0. ,  0. ],
       [-4.5,  0. ,  0. ]]), 'std_rotation_matrix': array([[1.00000000e+00, 1.23259516e-32, 0.00000000e+00],
       [0.00000000e+00, 1.00000000e+00, 0.00000000e+00],
       [0.00000000e+00, 0.00000000e+00, 1.00000000e+00]]), 'primitive_lattice': array([[-3.09590711e-16, -3.09590711e-16, -5.05600000e+00],
       [-3.84998337e-16, -6.28750000e+00, -0.00000000e+00],
       [-1.06949000e+01, -0.00000000e+00, -0.00000000e+00]])}
>>> symdict
{'rotations': array([[[ 1,  0,  0],
        [ 0,  1,  0],
        [ 0,  0,  1]],

       [[-1,  0,  0],
        [ 0, -1,  0],
        [ 0,  0, -1]],

       [[-1,  0,  0],
        [ 0, -1,  0],
        [ 0,  0,  1]],

       [[ 1,  0,  0],
        [ 0,  1,  0],
        [ 0,  0, -1]],

       [[ 1,  0,  0],
        [ 0, -1,  0],
        [ 0,  0, -1]],

       [[-1,  0,  0],
        [ 0,  1,  0],
        [ 0,  0,  1]],

       [[-1,  0,  0],
        [ 0,  1,  0],
        [ 0,  0, -1]],

       [[ 1,  0,  0],
        [ 0, -1,  0],
        [ 0,  0,  1]]], dtype=int32), 'translations': array([[-0.00000000e+00, -0.00000000e+00, -0.00000000e+00],
       [-0.00000000e+00, -0.00000000e+00, -0.00000000e+00],
       [ 5.00000000e-01,  0.00000000e+00,  5.00000000e-01],
       [ 5.00000000e-01,  0.00000000e+00,  5.00000000e-01],
       [ 5.00000000e-01,  5.00000000e-01,  5.00000000e-01],
       [ 5.00000000e-01,  5.00000000e-01,  5.00000000e-01],
       [ 6.16297582e-33,  5.00000000e-01,  0.00000000e+00],
       [ 6.16297582e-33,  5.00000000e-01,  0.00000000e+00]]), 'time_reversals': array([False, False, False, False,  True,  True,  True,  True]), 'equivalent_atoms': array([0, 0, 0, 0, 4, 4, 4, 4], dtype=int32), 'primitive_lattice': array([[-3.09590711e-16, -3.84998337e-16, -1.06949000e+01],
       [-3.09590711e-16, -6.28750000e+00, -0.00000000e+00],
       [-5.05600000e+00, -0.00000000e+00, -0.00000000e+00]])}
>>> symdict['primitive_lattice'] == dataset['primitive_lattice']
array([[ True, False, False],
       [False,  True,  True],
       [False,  True,  True]])
>>> symdict['primitive_lattice'] == dataset['primitive_lattice'].T
array([[ True,  True,  True],
       [ True,  True,  True],
       [ True,  True,  True]])
>>> import spglib
>>> spglib.get_version()
(2, 1, 0)

The comparison shows that symdict['primitive_lattice'] is indeed the transpose of dataset['primitive_lattice']. This inconsistency might affect users needing accurate lattice information. I hope this information helps in resolving the issue.

@singularitti singularitti changed the title Inconsistency in primitive_lattice Results between get_magnetic_symmetry_dataset & get_magnetic_symmetry in the Python interface Inconsistency in primitive_lattice results between get_magnetic_symmetry_dataset & get_magnetic_symmetry in the Python interface Dec 2, 2023
@lan496
Copy link
Member

lan496 commented Dec 2, 2023

@singularitti
Thank you for reporting the issue! I've found get_magnetic_symmetry does not transpose basis vectors from C-API.
https://github.com/spglib/spglib/blob/39a95560dd831c2d16f162126921ac1e519efa31/python/spglib/spglib.py#L318C43-L318C43

@singularitti
Copy link
Contributor Author

Glad to see it's fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants