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

SpacegroupAnalyzer.get_symmetrized_structure() raises TypeError #2723

Closed
janosh opened this issue Nov 7, 2022 · 0 comments · Fixed by #2724
Closed

SpacegroupAnalyzer.get_symmetrized_structure() raises TypeError #2723

janosh opened this issue Nov 7, 2022 · 0 comments · Fixed by #2724
Labels

Comments

@janosh
Copy link
Member

janosh commented Nov 7, 2022

Using pymatgen master @ dd884cf and spglib v2.0.2:

import spglib
from pymatgen.core import Structure
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer

print(f"{spglib.__version__=}")

struct = Structure.from_str('{"@module": "pymatgen.core.structure", "@class": "Structure", "charge": 0.0, "lattice": {"matrix": [[3.6062699446, 0.0, -0.8583713603], [-0.20223522530000002, 3.6005949268, -0.8583713603], [0.0, 0.0, 7.98790154]], "pbc": [true, true, true], "a": 3.7070182499562314, "b": 3.7070182499460818, "c": 7.98790154, "alpha": 103.38852319946483, "beta": 103.3885231994275, "gamma": 89.96878548961709, "volume": 103.72064305511611}, "sites": [{"species": [{"element": "Co", "occu": 1.0}], "abc": [0.626832, 0.626832, 0.253544], "xyz": [2.1337578911682575, 2.2569681191558972, 0.9491752350186207], "label": "Co", "properties": {}}, {"species": [{"element": "Co", "occu": 1.0}], "abc": [0.373168, 0.373168, 0.746456], "xyz": [1.2702768281317425, 1.3436268076441025, 5.321983584381379], "label": "Co", "properties": {}}, {"species": [{"element": "Co", "occu": 1.0}], "abc": [0.5, 0.0, 0.0], "xyz": [1.8031349723, 0.0, -0.42918568015], "label": "Co", "properties": {}}, {"species": [{"element": "Co", "occu": 1.0}], "abc": [0.0, 0.5, 0.0], "xyz": [-0.10111761265000001, 1.8002974634, -0.42918568015], "label": "Co", "properties": {}}, {"species": [{"element": "Co", "occu": 1.0}], "abc": [0.749935, 0.250065, 0.5], "xyz": [2.6538960992889566, 0.900382770370242, 3.1355794097], "label": "Co", "properties": {}}, {"species": [{"element": "Co", "occu": 1.0}], "abc": [0.250065, 0.749935, 0.5], "xyz": [0.7501386200110435, 2.700212156429758, 3.1355794097], "label": "Co", "properties": {}}, {"species": [{"element": "Co", "occu": 1.0}], "abc": [0.879784, 0.879784, 0.759311], "xyz": [2.9948152814846316, 3.167745807079811, 4.554938728538589], "label": "Co", "properties": {}}, {"species": [{"element": "Co", "occu": 1.0}], "abc": [0.12021599999999999, 0.12021599999999999, 0.240689], "xyz": [0.4092194378153688, 0.43284911972018875, 1.7162200908614103], "label": "Co", "properties": {}}]}', fmt="json")

spg_analyzer = SpacegroupAnalyzer(struct, symprec=0.1, angle_tolerance=5)
sym_struct = spg_analyzer.get_symmetrized_structure()
>>> TypeError: 'NoneType' object is not subscriptable
stack trace
TypeError                                 Traceback (most recent call last)
/Users/janosh/dev/matbench-discovery/tmp/spglib_None_symmtries.py in line 6
      9 struct = Structure.from_file("2-12269.json")
      12 spg_analyzer = SpacegroupAnalyzer(struct, symprec=0.1, angle_tolerance=5)
----> 13 sym_struct = spg_analyzer.get_symmetrized_structure()

File ~/dev/pmg/pymatgen/symmetry/analyzer.py:285, in SpacegroupAnalyzer.get_symmetrized_structure(self)
    275 """Get a symmetrized structure. A symmetrized structure is one where the sites
    276 have been grouped into symmetrically equivalent groups.
    277 
    278 Returns:
    279     :class:`pymatgen.symmetry.structure.SymmetrizedStructure` object.
    280 """
    281 ds = self.get_symmetry_dataset()
    282 sg = SpacegroupOperations(
    283     self.get_space_group_symbol(),
    284     self.get_space_group_number(),
--> 285     self.get_symmetry_operations(),
    286 )
    287 return SymmetrizedStructure(self._structure, sg, ds["equivalent_atoms"], ds["wyckoffs"])

File ~/dev/pmg/pymatgen/symmetry/analyzer.py:240, in SpacegroupAnalyzer.get_symmetry_operations(self, cartesian)
    233 def get_symmetry_operations(self, cartesian=False):
    234     """Return symmetry operations as a list of SymmOp objects. By default returns
...
--> 225 for t in d["translations"]:
    226     trans.append([float(Fraction.from_float(c).limit_denominator(1000)) for c in t])
    227 trans = np.array(trans)

TypeError: 'NoneType' object is not subscriptable
@janosh janosh added the bug label Nov 7, 2022
janosh added a commit that referenced this issue Nov 7, 2022
Fix TypeError in SpacegroupAnalyzer.get_symmetrized_structure() if spglib returns no symmetries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant