Skip to content

Conversation

@ajjackson
Copy link
Contributor

I have been trying to update the requirements of Euphonic to a recent seekpath and found that some combinations of seekpath and spglib were giving different error messages than expected when the symmetry cannot be detected. Specifically the behaviour is encountered when using seekpath 2.2 with older versions of spglib.

get_dot_access_dataset is a wrapper designed to convert old-style (dictionary access) spglib results to new-style (class attribute access) objects. Currently it does not consider the case that it is passed "None", which is the error signal for spglib<2.7 so if the wrapped spglib call returns None it can raise something like

../../.tox/py310-minrequirements-mac/lib/python3.10/site-packages/seekpath/getpaths.py:181: in get_path
    res = hpkot.get_path(
../../.tox/py310-minrequirements-mac/lib/python3.10/site-packages/seekpath/hpkot/__init__.py:162: in get_path
    dataset = get_dot_access_dataset(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
dataset = None

    def get_dot_access_dataset(dataset):
        """Return dataset with dot access.
    
        From spglib 2.5, dataset is returned as dataclass.
        To emulate it for older versions, this function is used.
    
        """
        spg_version = Version(version('spglib'))
    
        if spg_version < Version('2.5.0'):
            from types import SimpleNamespace
    
>           return SimpleNamespace(**dataset)
E           TypeError: types.SimpleNamespace() argument after ** must be a mapping, not NoneType

../../.tox/py310-minrequirements-mac/lib/python3.10/site-packages/seekpath/hpkot/tools.py:266: TypeError

I think this means the "if dataset is None" code block in seekpath.hpkot.__init__ has become unreachable. To have this work as expected, this PR allows None results to pass through the wrapper unchanged.

Here is a uv script (i.e. Python with dependencies declared in header) that reproduces the behaviour. You can get different results by changing the seekpath and spglib versions!

# /// script
# requires-python = "==3.10"
# dependencies = [
#     "packaging",
#     "seekpath[bz]==2.2.0",
#     "spglib==2.1",
# ]
# ///
import seekpath

cell = ([[2.426175880956926, -4.202259893915576, 0.0],
         [2.426175880956926, 4.202259893915576, 0.0],
         [0.0, 0.0, 5.35030451418839]],
        [],
        [])

output = seekpath.get_path(cell)

if output is None:
    print("Output is None")
else:
    print(f"Output: {output}")

get_dot_access_dataset is a wrapper designed to convert
old-style (dictionary access) spglib results to new-style (class
attribute access) objects. Currently it does not consider the case
that it is passed "None", which is the error signal for spglib<2.7.

This means that "if dataset is None" code block in
seekpath.hpkot.__init__ is probably unreachable. To have this work as
expected, allow None results to pass through the wrapper unchanged.
@t-reents
Copy link
Collaborator

Thank you so much @ajjackson !

I was surprised that this is the case, but I just checked and this was actually integrated 1.5 years ago, after the previous 2.1 release. I initially assumed that this was already part of previous releases, and therefore working, when doing the refactoring for the 2.2 release.

Thanks again for spotting and fixing the issue!

@t-reents t-reents merged commit 2ac6385 into materialscloud-org:main Jan 29, 2026
7 checks passed
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.

2 participants