Two Issues with importing `ElementProperty`

Hi Matminer Team,

I’ve encountered an issue with importing ElementProperty module while following the example code for element-composition featurization in Step 2.1 of the bulk modulus notebook. The error message I received was:

raise ValueError(f"Unexpected atomic number {Z=}")
ValueError: Unexpected atomic number Z=119

Upon investigating the source code at matminer/utils/data.py line 223, it seems the code attempts to access elemental properties beyond the maximum Atomic Number of 118. The relevant code snippet is as follows:

with open(os.path.join(self.data_dir, f"{descriptor_name}.table")) as f:
    self.all_elemental_props[descriptor_name] = dict()
    lines = f.readlines()
    print(_pt_data)
   
for atomic_no in range(1, len(_pt_data) + 1):  # max Z=103

# output:
...
Atomic_no: 118
Atomic_no: 119

After modifying the source code to restrict the loop to a maximum atomic number of 103:

for atomic_no in range(1, 104):  # max Z=103

I was able to successfully parse the periodict_able.json . However, I am now facing another issue related to the ASE integration within PyMatGen, specifically in the file:

/Users/imac/miniconda3/envs/my_jarvis/lib/python3.9/site-packages/pymatgen/io/ase.py

with the error message:

class MSONAtoms(Atoms, MSONable):
NameError: name 'Atoms' is not defined

I am submitting this issue for assistance so that I can duplicate the example above in the notebook.

Bob

I tried to install the pymatgen conda environment.

conda install --channel conda-forge pymatgen
pip install matminer
matminer                  0.9.0

My code is

from matminer.featurizers.composition import ElementProperty
import pandas as pd
from matminer.featurizers.conversions import StrToComposition
from matminer.datasets.convenience_loaders import load_elastic_tensor


df = load_elastic_tensor()  # loads dataset in a pandas DataFrame object
unwanted_columns = ["volume", "nsites", "compliance_tensor", "elastic_tensor", 
                    "elastic_tensor_original", "K_Voigt", "G_Voigt", "K_Reuss", "G_Reuss"]

df = df.drop(unwanted_columns, axis=1)
df = df.head(10)  # Keep only the first 10 rows
print(df)

df = StrToComposition().featurize_dataframe(df, "formula")
ep_feat = ElementProperty.from_preset(preset_name="magpie")
df = ep_feat.featurize_dataframe(df, col_id="composition") 

See:

for details of the first issue, which has since been fixed in the main branch.

The second issue affected pymatgen only for one day and should now be fixed (pending next pymatgen release) Can no longer import some modules without having ASE installed · Issue #3644 · materialsproject/pymatgen · GitHub.

The advice is always to use the pinned dependencies that the project uses for testing. For matminer, these can be found in https://github.com/hackingmaterials/matminer/tree/v0.9.0/requirements (for e.g., v0.9.0).

This should be made clearer (or even made the default) for unmaintained downstream packages like matminer, IMO.

1 Like