Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to new MP API, fix failing examples #61

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Runs the complete test suite incl. many external command line dependencies (like Openbabel)
# as well as the pymatgen.ext package. Coverage used to be computed based on this workflow.
# Runs the complete test suite incl. many external dependencies (like Openbabel)
name: Tests

on:
Expand All @@ -19,40 +18,44 @@ jobs:
strategy:
fail-fast: false
matrix:
# pytest-split automatically distributes work load so parallel jobs finish in similar time
os: [ubuntu-latest]
python-version: ["3.11"]

runs-on: ${{ matrix.os }}

env:
PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }}
PMG_VASP_PSP_DIR: /home/runner/work/matgenb/matgenb/psp
PMG_VASP_PSP_DIR: "${{ github.workspace }}/psp"
MPLBACKEND: Agg # non-interactive backend for matplotlib

steps:
- name: Check out repo
uses: actions/checkout@v4

- name: Set up micromamba
uses: mamba-org/setup-micromamba@main

- name: Create mamba environment
run: |
micromamba create -n venv python=${{ matrix.python-version }} --yes
micromamba install -n venv -c conda-forge enumlib packmol bader openbabel openff-toolkit --yes
with:
environment-name: matgenb
condarc: |
channels:
- conda-forge
create-args: >-
python=${{ matrix.python-version }}
enumlib
packmol
bader
openbabel
openff-toolkit

- name: Install uv
run: micromamba run -n venv pip install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"

- name: Install dependencies
run: |
micromamba activate venv
uv pip install numpy cython
uv pip install --upgrade -r requirements-ci.txt
micromamba run -n matgenb uv pip install --upgrade -r requirements-ci.txt

- name: pytest
- name: Run pytest
run: |
micromamba activate venv
cd notebooks
pwd
pytest --ignore-glob=*notest.ipynb --nbmake .
micromamba run -n matgenb pytest --ignore-glob=*notest.ipynb --nbmake notebooks/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: either use notest pattern to ignore file, or insert pytest.skip mark (not sure how to achieve this for ipynb though)

19 changes: 7 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,43 @@ ci:

repos:
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 24.10.0
hooks:
- id: black-jupyter

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]

- repo: https://github.com/asottile/pyupgrade
rev: v3.2.3
rev: v3.19.0
hooks:
- id: pyupgrade
args: [--py39-plus]

- repo: https://github.com/PyCQA/autoflake
rev: v2.0.0
rev: v2.3.1
hooks:
- id: autoflake

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.5.3
rev: 1.9.1
hooks:
- id: nbqa-pyupgrade
args: [--py39-plus]
- id: nbqa-isort

- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
rev: 0.8.1
hooks:
- id: nbstripout
args: [--drop-empty-cells, --keep-output]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ anyone is welcome to contribute.

```sh
# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.
# !pip install pymatgen==2022.2.27
# !pip install -U pymatgen
```

4. Ideally, please update notebooks as needed to use more modern versions of the codes, and you may update the date of
Expand Down
10 changes: 5 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Visit the [Github Pages](http://matgenb.materialsvirtuallab.org) for a nicely fo

# Introduction

This repo is started by the [Materials Virtual Lab](http://www.materialsvirtuallab.org) as a useful collection of
This repo is started by the [Materials Virtual Lab](http://www.materialsvirtuallab.org) as a useful collection of
Jupyter notebooks that demonstrate the utilization of open-source codes for the study of materials science.

We frequently get requests (from students, postdocs, collaborators, or just general users) for example codes that
demonstrate various capabilities in the open-source software we maintain and contribute to, such as the Materials
Project software stack comprising [Python Materials Genomics (pymatgen)](http://www.pymatgen.org),
Project software stack comprising [Python Materials Genomics (pymatgen)](http://www.pymatgen.org),
[Custodian](https://materialsprojecthub.io/custodian/), and [Fireworks](https://pythonhosted.org/FireWorks/). This
repo is a start at building a more sustainable path towards sharing of code examples.

Expand All @@ -18,7 +18,7 @@ anyone is welcome to contribute.

## Option 1: Google Colab

You can easily run all the notebooks via [Google Colab](https://colab.research.google.com/).
You can easily run all the notebooks via [Google Colab](https://colab.research.google.com/).

## Option 2: BinderHub

Expand Down Expand Up @@ -46,13 +46,13 @@ output.

3. Notebooks should be well-documented and simple. The idea here is to be pedagogical. A newcomer to the software
(with the right materials science background) should be able to follow the logic without too much difficulty. Feel
free to add authorship and contact information, as well as works to cite and acknowledge your contributions. In view
free to add authorship and contact information, as well as works to cite and acknowledge your contributions. In view
that scientific codes tend to be continuously being updated, please put in a list of the key pinned dependencies so
that other users can install the exact version of software to run the notebook if needed. The best practice is to put
a section that provides a commented out pip install instructure that can be used in Google Colab. For example,
```sh
# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.
# !pip install pymatgen==2022.2.27
# !pip install -U pymatgen
```

4. Ideally, please update notebooks as needed to use more modern versions of the codes, and you may update the date of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19"
"# !pip install -U pymatgen"
]
},
{
Expand Down Expand Up @@ -47,18 +47,18 @@
}
],
"source": [
"from mp_api.client import MPRester\n",
"from pymatgen.analysis.reaction_calculator import ComputedReaction\n",
"from pymatgen.core import Composition\n",
"from pymatgen.core.units import FloatWithUnit\n",
"from pymatgen.entries.computed_entries import ComputedEntry\n",
"from pymatgen.ext.matproj import MPRester\n",
"\n",
"# This initializes the REST adaptor. Put your own API key in if necessary.\n",
"mpr = MPRester()\n",
"\n",
"# This gets all entries belonging to the Ca-C-O system.\n",
"all_entries = mpr.get_entries_in_chemsys([\"Ca\", \"C\", \"O\"])\n",
"\n",
"\n",
"# This method simply gets the lowest energy entry for all entry with the same composition.\n",
"def get_most_stable_entry(formula):\n",
" relevant_entries = [\n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/2013-01-01-Calculating XRD patterns.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.2.27"
"# !pip install -U pymatgen"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19\n",
"from __future__ import annotations"
"# !pip install -U pymatgen"
]
},
{
Expand All @@ -35,7 +34,7 @@
"metadata": {},
"outputs": [],
"source": [
"from pymatgen.ext.matproj import MPRester\n",
"from mp_api.client import MPRester\n",
"\n",
"# Note that you will need to add your Materials API key in your .pmgrc.yaml file as \"PMG_MAPI_KEY\".\n",
"# Alternatively, you will need to supply the API key as an arg to MPRester.\n",
Expand Down
3 changes: 1 addition & 2 deletions notebooks/2013-01-01-Molecule.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19\n",
"from __future__ import annotations"
"# !pip install -U pymatgen"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion notebooks/2013-01-01-Ordering Disordered Structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19"
"# !pip install -U pymatgen"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19\n",
"from __future__ import annotations"
"# !pip install -U pymatgen"
]
},
{
Expand All @@ -26,8 +25,8 @@
"metadata": {},
"outputs": [],
"source": [
"from mp_api.client import MPRester\n",
"from pymatgen.analysis.phase_diagram import PDPlotter, PhaseDiagram\n",
"from pymatgen.ext.matproj import MPRester\n",
"\n",
"%matplotlib inline"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19\n",
"from __future__ import annotations"
"# !pip install -U pymatgen"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions notebooks/2013-01-01-Units.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19\n",
"from __future__ import annotations"
"# !pip install -U pymatgen"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19\n",
"from __future__ import annotations"
"# !pip install -U pymatgen"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19 pymatgen-analysis-diffusion\n",
"from __future__ import annotations"
"# !pip install -U pymatgen pymatgen-analysis-diffusion"
]
},
{
Expand All @@ -40,6 +39,7 @@
"\n",
"import matplotlib as mpl\n",
"import palettable\n",
"from mp_api.client import MPRester\n",
"from pymatgen.analysis.phase_diagram import (\n",
" CompoundPhaseDiagram,\n",
" PDPlotter,\n",
Expand All @@ -48,7 +48,6 @@
"from pymatgen.core import Composition, Element\n",
"from pymatgen.entries.compatibility import MaterialsProjectCompatibility\n",
"from pymatgen.entries.computed_entries import ComputedEntry\n",
"from pymatgen.ext.matproj import MPRester\n",
"from pymatgen.io.vasp import Vasprun\n",
"from pymatgen.util.plotting import pretty_plot"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19 pymatgen-analysis-diffusion\n",
"from __future__ import annotations"
"# !pip install -U pymatgen pymatgen-analysis-diffusion"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19 phonopy\n",
"from __future__ import annotations"
"# !pip install -U pymatgen phonopy"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19"
"# !pip install -U pymatgen"
]
},
{
Expand All @@ -26,10 +26,9 @@
"outputs": [],
"source": [
"import pprint\n",
"import re\n",
"\n",
"from mp_api.client import MPRester\n",
"from pymatgen.core import Composition\n",
"from pymatgen.ext.matproj import MPRester\n",
"\n",
"# Make sure that you have the Materials API key. Put the key in the call to\n",
"# MPRester if needed, e.g, MPRester(\"MY_API_KEY\")\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/2017-04-03-Slab generation and Wulff shape.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19"
"# !pip install -U pymatgen"
]
},
{
Expand All @@ -37,7 +37,7 @@
"outputs": [],
"source": [
"# Import the necessary tools for making a Wulff shape\n",
"from __future__ import annotations\n",
"\n",
"\n",
"from pymatgen.analysis.wulff import WulffShape\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"outputs": [],
"source": [
"# Uncomment the subsequent lines in this cell to install dependencies for Google Colab.\n",
"# !pip install pymatgen==2022.7.19"
"# !pip install -U pymatgen"
]
},
{
Expand Down
Loading
Loading