Code snippet
from mp_api.client import MPRester
from pymatgen.io.ase import AseAtomsAdaptor
with MPRester(MP_API_KEY) as mpr:
mp_docs = mpr.materials.summary.search()
s = mp_docs[0].structure
print(s.site_properties) # {'charge': [None, ... None], 'selective_dynamics': [None, ...}
AseAtomsAdaptor.get_atoms(s) # crashes
What happened?
Description
I’m using mp-api==0.45.15 to fetch SummaryDoc objects from Materials Project. The returned pymatgen.Structure objects contain site_properties keys with lists of None values (e.g. selective_dynamics=[None, ...]), and this crashes ASE conversion via pymatgen.io.ase.AseAtomsAdaptor.
Error:
TypeError: bad operand type for unary ~: 'NoneType'
File .../pymatgen/io/ase.py:184, in get_atoms
cmask_site = (~np.array(selective_dynamics)).tolist()
Warnings during fetch
These warnings appear during mpr.materials.summary.search() (even before I try converting to ASE). They suggest that the incoming documents include site properties that are missing for some sites, and pymatgen fills the missing entries with None. That “None-filled” selective_dynamics then propagates into the Structure object and triggers the ASE conversion crash shown above.
/.../mp_api/client/core/client.py:1326: UserWarning: Omitting a query also includes deprecated documents in the results. Make sure to post-filter them out.
warnings.warn(
/.../pymatgen/core/structure.py:2917: UserWarning: Not all sites have property selective_dynamics. Missing values are set to None.
return cls.from_sites(...)
(and similar warnings for charge/velocities/coordination_no/forces/magmom)
Expected behavior
Either:
- do not include
site_properties keys when values are missing/incomplete (avoid None lists), or
- provide an option to fetch “clean” structures without these optional site properties.
This would prevent common downstream crashes (ASE conversion is one example).
Version
v0.45.15
Which OS?
Log output
Code snippet
What happened?
Description
I’m using
mp-api==0.45.15to fetchSummaryDocobjects from Materials Project. The returnedpymatgen.Structureobjects containsite_propertieskeys with lists ofNonevalues (e.g.selective_dynamics=[None, ...]), and this crashes ASE conversion viapymatgen.io.ase.AseAtomsAdaptor.Error:
Warnings during fetch
These warnings appear during
mpr.materials.summary.search()(even before I try converting to ASE). They suggest that the incoming documents include site properties that are missing for some sites, and pymatgen fills the missing entries withNone. That “None-filled”selective_dynamicsthen propagates into theStructureobject and triggers the ASE conversion crash shown above.Expected behavior
Either:
site_propertieskeys when values are missing/incomplete (avoidNonelists), orThis would prevent common downstream crashes (ASE conversion is one example).
Version
v0.45.15
Which OS?
Log output