Skip to content

[Bug]: SummaryDoc.structure.site_properties contains selective_dynamics (and other keys) filled with None, which breaks pymatgen → ASE conversion #1050

@Sankek

Description

@Sankek

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?

  • MacOS
  • Windows
  • Linux

Log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions