Repository: materialsproject/pymatgen

Issue:
`ImportError`: cannot import name `'SymmetryGroup'` from partially initialized module `'pymatgen.symmetry.groups'`
### Python version

3.13

### Pymatgen version

2025.2.18

### Operating system version

macOS

### Current behavior

```py
from pymatgen.symmetry.groups import SpaceGroup
  File "/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/pymatgen/symmetry/groups.py", line 21, in <module>
    from pymatgen.core.operations import SymmOp
  File "/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/pymatgen/core/__init__.py", line 17, in <module>
    from pymatgen.core.structure import IMolecule, IStructure, Molecule, PeriodicNeighbor, SiteCollection, Structure
  File "/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/pymatgen/core/structure.py", line 44, in <module>
    from pymatgen.symmetry.maggroups import MagneticSpaceGroup
  File "/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/pymatgen/symmetry/maggroups.py", line 17, in <module>
    from pymatgen.symmetry.groups import SymmetryGroup, in_array_list
ImportError: cannot import name 'SymmetryGroup' from partially initialized module 'pymatgen.symmetry.groups' (most likely due to a circular import) (/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/pymatgen/symmetry/groups.py)
```

### Expected Behavior

this same error showed up twice before in 2022 and 2023
- https://github.com/materialsproject/pymatgen/issues/3485
- https://github.com/materialsproject/pymatgen/issues/2470

worth adding a unit test to catch this so that it doesn't slip through a 4th time

### Minimal example

```Python
from pymatgen.symmetry.groups import SpaceGroup
```

### Relevant files to reproduce this bug

showed up in https://github.com/janosh/pymatviz/pull/275

Discussion:
@janosh: depending on use case, viable workaround may be to use `from moyopy import SpaceGroupType` instead

Solution patch:
diff --git a/src/pymatgen/symmetry/groups.py b/src/pymatgen/symmetry/groups.py
index 384f7c6163..96b2bd6a9e 100644
--- a/src/pymatgen/symmetry/groups.py
+++ b/src/pymatgen/symmetry/groups.py
@@ -18,7 +18,6 @@ import numpy as np
 from monty.design_patterns import cached_class
 from monty.serialization import loadfn
 
-from pymatgen.core.operations import SymmOp
 from pymatgen.util.string import Stringify
 
 if TYPE_CHECKING:


Test patch:
diff --git a/tests/symmetry/test_groups.py b/tests/symmetry/test_groups.py
index 51e09fd743..45cff7c9f6 100644
--- a/tests/symmetry/test_groups.py
+++ b/tests/symmetry/test_groups.py
@@ -1,5 +1,8 @@
 from __future__ import annotations
 
+import subprocess
+import sys
+
 import numpy as np
 import pytest
 from pytest import approx
@@ -285,3 +288,7 @@ class TestSpaceGroup:
                 match=f"International number must be between 1 and 230, got {num}",
             ):
                 SpaceGroup.from_int_number(num)
+
+    def test_import(self):
+        # Ensure no circular import
+        subprocess.run([sys.executable, "-c", "from pymatgen.symmetry.groups import SpaceGroup"], check=True)