Bug: Import statements from Pymatgen are outdated w/ newest version

Hello everyone,

Leaving this here because the instructions seemed unclear about where to drop bug reports… Hope that this is the right place. Happy to open this as a GitHub issue if that was the appropriate location.

A recent update to Pymatgen removed the __init__.py file from the main pymatgen directory, meaning that import statements of the form from pymatgen import x across atomate will no longer work. For example:

from pymatgen import MPRester
will fail without an explicit path being re-written to:
from pymatgen.ext.matproj import MPRester.

I made a branch that fixes all of the ones I could find: Should I just open a PR on the repo?

Yes a PR would be great, thanks!

(btw, you should be able detect all instances by searching for the text "from pymatgen import ")

PR is up. Thanks, Anubhav :slight_smile: Wasn’t sure if a random PR would be welcome without an explanation / flag beforehand.

I am not sure if this is related, but I thought I would pass it along. On the front page of the pymatgen project there is an explicit announcement that root level convenience imports have been removed. A small fraction of the update text from the pymatgen page is pasted below.

A backwards incompatible change has been introduced in v2022.0.*. Pymatgen root-level convenience imports have been removed from in preparation for a change to a more modular, extensible namespace package architecture that will allow more developers to contribute. If your existing code uses from pymatgen import , you will need to make modifications. MPRester should now be imported from pymatgen.ext.matproj. All other convenience objects such as Element, Species, Lattice, Structure, etc. should be imported from pymatgen.core. There are a few simple ways you can respond to this change:

Another heads up matminer is broken due to the above change (from pymatgen.core import Element doesn’t work.