MP API bugfix today

Sorry about the bug, site should be working now

2024-07-01
python materials_project mp_api bugfix

Had a small bug today - essentially mp-api, which is used to get the crystal structure from the Materials Project needed to be updated, as the web API was complaining that my client was out of date. Turns out the version I was using was no longer compliant with the API. It took a little bit of time to figure out that that was the problem, and here is how I ended up fixing it.

I use PDM to manage my python environment, to figure out what mp-api's dependencies were I ran pdm list --tree --reverse mp-api. This is a very handy command that tells you what is requiring a certain package. I realized that I never fully specified mp-api in my pyproject.toml, so I added it with pdm add mp-api.

I also ran pdm update to update all packages, after running pdm update --dry-run to see what it would do. This had the effect of updating h5py, which doesn't have a wheel for it's binary. So I had to pin h5py with pdm add h5py==3.10. After that it worked, but didn't give a meaningful error when the crystal structure wasn't found, and would just return an empty list.

I added a small error message when the output of the crystal structure lookup was a list, and voila, I'm done.