-
Notifications
You must be signed in to change notification settings - Fork 835
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
Spacegroup P212121 does not give a valid pointgroup #3735
Comments
The complete bug reproduction code snippet is shown below: In [12]: from pymatgen.symmetry.groups import SpaceGroup, PointGroup
...:
...: # Create an instance of the SpaceGroup for 'P212121'
...: sg = SpaceGroup('P212121')
...:
...: # Fetch the point group symbol from the space group
...: point_group_symbol = sg.point_group
...:
...: # Display the space group and its point group symbol
...: print(f"Space Group: {sg.symbol}")
...: print(f"Point Group Symbol: {point_group_symbol}")
...:
...: # Now let's try creating the PointGroup.
...: try:
...: pg = PointGroup(point_group_symbol)
...: print(f"Processed Point Group: {pg}")
...: except Exception as e:
...: print(f"Error: {e}")
...:
Space Group: P212121
Point Group Symbol: D2^4
Error: 'D2^4' |
Here's a complete patch generated under the help of gpt-4o that includes the specific fix for recognizing the P212121 space group's point group symbol, along with the general bug fixes and improvements: --- a/pymatgen/symmetry/groups.py
+++ b/pymatgen/symmetry/groups.py
@@ -71,6 +71,7 @@ class SpaceGroup(SymmetryGroup):
sg_encoding = SYMM_DATA["space_group_encoding"]
abbrev_sg_mapping = SYMM_DATA["abbreviated_spacegroup_symbols"]
translations = {k: Fraction(v) for k, v in SYMM_DATA["translations"].items()}
+ underscore_sg_mapping = {k.replace("_", ""): v for k, v in sg_encoding.items()}
full_sg_mapping = {v["full_symbol"]: k for k, v in SYMM_DATA["space_group_encoding"].items()}
def __init__(self, int_symbol: str) -> None:
@@ -96,6 +97,10 @@ class SpaceGroup(SymmetryGroup):
self._symmetry_ops: set[SymmOp] | None
+ # Handle symbols with and without underscores
+ if int_symbol in SpaceGroup.underscore_sg_mapping:
+ int_symbol = SpaceGroup.underscore_sg_mapping[int_symbol]
+
for spg in SpaceGroup.SYMM_OPS:
if int_symbol in [spg["hermann_mauguin"], spg["universal_h_m"]]:
ops = [SymmOp.from_xyz_str(s) for s in spg["symops"]]
@@ -125,7 +130,7 @@ class PointGroup(SymmetryGroup):
SYMM_DATA["generator_matrices"][enc] for enc in SYMM_DATA["point_group_encoding"][int_symbol]
]
self._symmetry_ops = {SymmOp.from_rotation_and_translation(m) for m in self._generate_full_symmetry_ops()}
- self.order = len(self._symmetry_ops)
+ self.order = len(self._symmetry_ops) if self._symmetry_ops else 0
@property
def symmetry_ops(self) -> set[SymmOp]:
@@ -128,7 +133,7 @@ class PointGroup(SymmetryGroup):
"""
return self._symmetry_ops
- def _generate_full_symmetry_ops(self) -> list[SymmOp]:
+ def _generate_full_symmetry_ops(self) -> list[np.ndarray]:
symm_ops = list(self.generators)
new_ops = self.generators
while len(new_ops) > 0:
@@ -146,9 +151,9 @@ class PointGroup(SymmetryGroup):
return symm_ops
def get_orbit(self, p: ArrayLike, tol: float = 1e-5) -> list[np.ndarray]:
- """Returns the orbit for a point.
+ """Returns the orbit for a point in the group.
- Args:
+ Parameters:
p: Point as a 3x1 array.
tol: Tolerance for determining if sites are the same. 1e-5 should
be sufficient for most purposes. Set to 0 for exact matching
@@ -156,7 +161,7 @@ class PointGroup(SymmetryGroup):
list[array]: Orbit for point.
"""
orbit: list[np.ndarray] = []
- for o in self.symmetry_ops:
+ for o in self.symmetry_ops or []:
pp = o.operate(p)
if not in_array_list(orbit, pp, tol=tol):
orbit.append(pp)
@@ -169,9 +174,9 @@ class PointGroup(SymmetryGroup):
bool: True if this group is a subgroup of the supplied group.
"""
warnings.warn("This is not fully functional. Only trivial subsets are tested right now. ")
- return set(self.symmetry_ops).issubset(supergroup.symmetry_ops)
+ return self._symmetry_ops and set(self.symmetry_ops).issubset(supergroup.symmetry_ops)
def is_supergroup(self, subgroup: SymmetryGroup) -> bool:
- """True if this group is a supergroup of the supplied group.
+ """True if this group is a supergroup of the supplied group.
Args:
subgroup (SymmetryGroup): Subgroup to test.
@@ -226,7 +231,7 @@ class SpaceGroup(SymmetryGroup):
for spg in SpaceGroup.SYMM_OPS:
if int_number == spg["number"]:
- symbols.extend((spg["hermann_mauguin"], spg["universal_h_m"]))
+ symbols.extend([spg["hermann_mauguin"], spg["universal_h_m"]])
return set(symbols)
@property Explanation of the Patch To apply this patch, save it to a file (e.g., fix_spacegroup.patch) and apply it to your local pymatgen source code using the patch command:
This should resolve the issue where the point group symbol D2^4 is incorrectly reported for the space group P212121 and ensure it correctly returns 222, while also including general improvements to the code. |
Python version
Python 3.9.18
Pymatgen version
2024.2.8
Operating system version
Fedora 38
Current behavior
Loading the SpaceGroup
P212121
works fine, but thepoint_group
symbol it reports (D2^4
) is not recognised. I believe it should be222
. The issue appears to be here:pymatgen/pymatgen/symmetry/groups.py
Line 223 in 81dc677
P212121
is not inSpaceGroup.sg_encoding
- instead it appears there with the underscoresP2_12_12_1
and the correct pointgroup (222
). As it can't find it here it uses theschoenflies
entry of the spacegroup (D2^4
) instead. I don't know what this is, or how to use it to find the 222 space group..?At the top of this class some effort is made to duplicate entries for the
SG_SYMBOLS
so they also contain copies without underscores. If this was also done for thesg_encoding
then the problem would be fixed, but I don't know if that is a reasonable thing to do or if it would cause other problems?Expected Behavior
I should be able to instantiate a PointGroup from a SpaceGroup by using the associated point_group symbol
Minimal example
Relevant files to reproduce this bug
No response
The text was updated successfully, but these errors were encountered: