hackingmaterials / matminer

Data mining for materials science
https://hackingmaterials.github.io/matminer/
Other
466 stars 191 forks source link

Simple composition-based featurization fails due to an upgrade in pymatgen #920

Closed JaGeo closed 7 months ago

JaGeo commented 7 months ago
from matminer.datasets import load_dataset
from matminer.featurizers.composition import ElementProperty
from matminer.featurizers.conversions import StrToComposition

bandgaps = load_dataset('matbench_expt_gap')
bandgaps = bandgaps[bandgaps['gap expt'] > 0].reset_index(drop=True)
bandgaps.head()

str_to_comp = StrToComposition(target_col_id='composition_pmg')
bandgaps_comp = str_to_comp.featurize_dataframe(bandgaps, col_id='composition')

featurizer = ElementProperty.from_preset('magpie')
bandgaps_data_featurized = featurizer.featurize_dataframe(bandgaps_comp, col_id='composition_pmg', ignore_errors=True,
                                                          return_errors=True)
y = bandgaps_data_featurized['gap expt']
bandgaps_data_featurized.head()

fails with:

Traceback (most recent call last):
  File "/hpc-user/jgeorge/PycharmProjects/test_new/use_matminer.py", line 2, in <module>
    from matminer.featurizers.composition import ElementProperty
  File "/home/jgeorge/miniconda3/envs/test_new/lib/python3.10/site-packages/matminer/featurizers/composition/__init__.py", line 1, in <module>
    from matminer.featurizers.composition.alloy import Miedema, WenAlloys, YangSolidSolution
  File "/home/jgeorge/miniconda3/envs/test_new/lib/python3.10/site-packages/matminer/featurizers/composition/alloy.py", line 16, in <module>
    from matminer.featurizers.composition.packing import AtomicPackingEfficiency
  File "/home/jgeorge/miniconda3/envs/test_new/lib/python3.10/site-packages/matminer/featurizers/composition/packing.py", line 13, in <module>
    from matminer.featurizers.composition.element import ElementFraction
  File "/home/jgeorge/miniconda3/envs/test_new/lib/python3.10/site-packages/matminer/featurizers/composition/element.py", line 202, in <module>
    class BandCenter(BaseFeaturizer):
  File "/home/jgeorge/miniconda3/envs/test_new/lib/python3.10/site-packages/matminer/featurizers/composition/element.py", line 210, in BandCenter
    magpie_data = MagpieData()
  File "/home/jgeorge/miniconda3/envs/test_new/lib/python3.10/site-packages/matminer/utils/data.py", line 217, in __init__
    self.all_elemental_props[descriptor_name][Element.from_Z(atomic_no).symbol] = prop_value
  File "/home/jgeorge/miniconda3/envs/test_new/lib/python3.10/site-packages/pymatgen/core/periodic_table.py", line 526, in from_Z
    raise ValueError(f"Unexpected atomic number {Z=}")
ValueError: Unexpected atomic number Z=119

It works, however, fine with pymatgen version "2023.12.18". The periodic table data has been updated. Probably a side effect of: https://github.com/materialsproject/pymatgen/pull/3542

JaGeo commented 7 months ago

I would push a fix but "pip install -e ." from the cloned matminer repo fails

ml-evs commented 7 months ago

Same issue as #919 I think, see the discussion over there (basically no-one is available to maintain matminer anymore and its been left in a state where dep upgrades are tricky to handle).

https://github.com/hackingmaterials/matminer/issues/919#issuecomment-1916764986