Repository: materialsproject/pymatgen

Issue #3166: `label` in `Structure.as_dict()` is `None` in the latest version
Created: 2023-07-19T19:21:16Z
Description
The latest version gives the 'label': None in Structure.as_dict(). I want to confirm if it is expected, as it breaks the tests in our downstream package.
Repro
from pymatgen.core import Structure
import numpy as np
s = Structure(np.eye(3), ["H"], np.zeros((1, 3)), coords_are_cartesian=True)
print(s.as_dict())
{'@module': 'pymatgen.core.structure', '@class': 'Structure', 'charge': 0, 'lattice': {'matrix': [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]], 'pbc': (True, True, True), 'a': 1.0, 'b': 1.0, 'c': 1.0, 'alpha': 90.0, 'beta': 90.0, 'gamma': 90.0, 'volume': 1.0}, 'sites': [{'species': [{'element': 'H', 'occu': 1}], 'abc': [0.0, 0.0, 0.0], 'xyz': [0.0, 0.0, 0.0], 'label': None, 'properties': {}}]}

Expected behavior
In previous versions, label is H.
Environment
Relevant versions and platform info:

OS: Linux
Version  2023.7.17

Additional context

Duplicate issue #3160: `AttributeError`: `attr='label'` not found on `PeriodicNeighbor`
Created: 2023-07-17T17:32:58Z
Can anyone please suggest why I am unable to get structures from pymatgen?
from pymatgen.core import Structure
from pymatgen.analysis.diffusion.neb.pathfinder import DistinctPathFinder

s = Structure.from_file("./system.vasp")

path_finder = DistinctPathFinder(symm_structure, "Ca", max_path_length=6.0)
distinct_paths = path_finder.get_paths()

for p in distinct_paths:
    structures = p.get_structures(nimages=5, vac_mode=True, idpp=False)
    for structure in structures:
        print(structure)
error:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[9], line 2
      1 for p in distinct_paths:
----> 2     structures = p.get_structures(nimages=5, vac_mode=True, idpp=False)
      3     for structure in structures:
      4         print(structure)

File ~/repo/venv/lib/python3.11/site-packages/pymatgen/analysis/diffusion/neb/pathfinder.py:431, in MigrationHop.get_structures(self, nimages, vac_mode, idpp, **idpp_kwargs)
    428 migrating_specie_sites, other_sites = self._split_migrating_and_other_sites(vac_mode)
    430 start_structure = Structure.from_sites([self.isite] + migrating_specie_sites + other_sites)
--> 431 end_structure = Structure.from_sites([self.esite] + migrating_specie_sites + other_sites)
    433 structures = start_structure.interpolate(end_structure, nimages=nimages + 1, pbc=False)
    435 if idpp:

File ~/repo/venv/lib/python3.11/site-packages/pymatgen/core/structure.py:951, in IStructure.from_sites(cls, sites, charge, validate_proximity, to_unit_cell)
    949 prop_keys: list[str] = []
    950 props = {}
--> 951 labels = [site.label for site in sites]
    952 lattice = sites[0].lattice
    953 for idx, site in enumerate(sites):

File ~/repo/venv/lib/python3.11/site-packages/pymatgen/core/structure.py:951, in <listcomp>(.0)
    949 prop_keys: list[str] = []
    950 props = {}
--> 951 labels = [site.label for site in sites]
    952 lattice = sites[0].lattice
    953 for idx, site in enumerate(sites):

File ~/repo/venv/lib/python3.11/site-packages/pymatgen/core/sites.py:81, in Site.__getattr__(self, attr)
     79 if attr in props:
     80     return props[attr]
---> 81 raise AttributeError(f"{attr=} not found on {type(self).__name__}")

AttributeError: attr='label' not found on PeriodicNeighbor

Closing comment (2023-07-19T20:39:33Z): @stefsmeets In case it helps connect the dots, this issue might be related to #3166.