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

Update for Materials Project v2 API #190

Merged
merged 5 commits into from
Sep 18, 2023
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:
name: Run unit testing suite

env:
PMG_API_KEY: ${{ secrets.PMG_API_KEY }}
MP_API_KEY: ${{ secrets.MP_API_KEY }}

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
python-version: [3.7, 3.8, 3.9, '3.10', 3.11]
python-version: [3.9, '3.10', 3.11]

steps:

Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div align="center">

![sysfs line plot](https://raw.githubusercontent.com/AI-multimodal/Lightshow/master/docs/_static/images/lightshow.jpg)

[![image](https://joss.theoj.org/papers/a9cabcd7f4b85a926a797997c6622b43/status.svg)](https://joss.theoj.org/papers/a9cabcd7f4b85a926a797997c6622b43)
Expand All @@ -8,9 +7,6 @@
[![image](https://app.codacy.com/project/badge/Grade/d31a4e18672c4d71bbaafa719181c140)](https://www.codacy.com/gh/AI-multimodal/Lightshow/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=AI-multimodal/Lightshow&amp;utm_campaign=Badge_Grade)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![python](https://img.shields.io/badge/-Python_3.7+-blue?logo=python&logoColor=white)](https://github.com/pre-commit/pre-commit)



</div>

------------------------------------------------------------------------
Expand Down Expand Up @@ -57,13 +53,13 @@ To install Lightshow, simply use `pip`
pip install lightshow
```

Make sure you've set your Pymatgen legacy API key as well!
Make sure you've set your Materials Project v2 API key as well! You can find some documentation on how to query data [here](https://docs.materialsproject.org/downloading-data/using-the-api/querying-data) and how to set up your new API key [here](https://next-gen.materialsproject.org/api).

```bash
export PMG_API_KEY="your_legacy_materials_project_key"
export MP_API_KEY="your_Materials_Project_v2_API_key"
```

(or preferably, add `PMG_API_KEY` to your bash profile).
(or preferably, add `MP_API_KEY` to your bash profile).

More details can be found at our [documentation](https://ai-multimodal.github.io/Lightshow/installation.html).

Expand Down
24 changes: 4 additions & 20 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ Begin by importing the ``Database`` object.
Databases from the Materials Project
------------------------------------

The database is designed to be constructed via classmethods. The primary classmethod we recommend using is ``from_materials_project``. It interfaces directly with the ``MPRester`` object to make queries and pull data locally. There are three ways to do this:
The database is designed to be constructed via classmethods. The primary classmethod we recommend using is ``from_materials_project``. It interfaces directly with the ``mp_api.client.MPRester`` object to make queries and pull data locally. As of `Lightshow==1.0.0`, this interfaces directly with the `Materials Project v2 API <https://next-gen.materialsproject.org/api>`_ and is a simple passthrough. You should type something like ``mpr.materials.summary.search?`` (check its docstring) for the options you can pass directly through to ``Database.from_materials_project``.

#. Directly pull a list of Materials Project IDs

.. code-block:: python

database = Database.from_materials_project(
query=["mp-390", "mvc-11115"],
query_type="mpids",
material_ids=["mp-390"],
api_key=API_KEY
)

Expand All @@ -54,28 +53,13 @@ The database is designed to be constructed via classmethods. The primary classme
.. code-block:: python

database = Database.from_materials_project(
query=["Ti-O", "Ti-O-*"],
query_type="patterns",
api_key=API_KEY
)

#. Via direct REST query. See the appropriate Pymatgen docs `here <https://pymatgen.org/pymatgen.ext.matproj.html?highlight=mprester#pymatgen.ext.matproj.MPRester.query>`__ for more details.

.. code-block:: python

database = Database.from_materials_project(
query={
"criteria": ...,
"properties": ...,
...
},
query_type="mp_query",
chemsys=["Ti-O", "Ti-O-*"],
api_key=API_KEY
)

.. note::

While the `Pymatgen API Key <https://legacy.materialsproject.org/open>`_ can be provided manually during the use of ``from_materials_project``, we highly recommend setting it in the environment variable ``PMG_API_KEY``. If ``api_key`` in the above arguments is not provided or is set to ``None``, **Lightshow** will check for this environment variable and use it instead.
While the Pymatgen API Key can be provided manually during the use of ``from_materials_project``, we highly recommend setting it in the environment variable ``MP_API_KEY``. If ``api_key`` in the above arguments is not provided or is set to ``None``, **Lightshow** will check for this environment variable and use it instead.

Once the ``database`` has been built, three properties are accessible:

Expand Down
6 changes: 3 additions & 3 deletions lightshow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@


def _get_API_key_from_environ():
"""Checks for an environment variable PMG_API_KEY. If does not exist,
returns None.
"""Checks for an environment variable MP_API_KEY. If does not exist,
returns None. Note that this is now for the Materials Project v2 api.

Returns
-------
str
"""

return environ.get("PMG_API_KEY", None)
return environ.get("MP_API_KEY", None)


def _get_POTCAR_DIRECTORY_from_environ():
Expand Down
2 changes: 1 addition & 1 deletion lightshow/_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def test_structure_names():
return [
"mp-390",
"mvc-11115",
# "mvc-11115", # No longer in v2 API
"mp-1215",
"mp-1840",
"mp-2657",
Expand Down
20 changes: 0 additions & 20 deletions lightshow/_tests/structure_files/mvc-11115/POSCAR

This file was deleted.

4 changes: 2 additions & 2 deletions lightshow/_tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_database_from_disk(database_from_file, test_structure_names):

def test_from_materials_project(test_structure_names):
try:
dat = Database.from_materials_project(test_structure_names)
dat = Database.from_materials_project(material_ids=test_structure_names)
dat.initialize_supercells(9.0)
assert set(dat.structures.keys()) == set(test_structure_names)
assert set(dat.supercells.keys()) == set(test_structure_names)
Expand All @@ -43,7 +43,7 @@ def test_from_materials_project(test_structure_names):
"mpid",
[
"mp-390",
"mvc-11115",
# "mvc-11115",
"mp-1215",
"mp-1840",
"mp-2657",
Expand Down
5 changes: 4 additions & 1 deletion lightshow/_tests/test_vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

@pytest.mark.parametrize(
"mpid",
["mp-390", "mvc-11115"],
[
"mp-390",
# "mvc-11115"
],
)
def test_write(mpid, dummy_potcar_file_directory, database_from_file, tmp_path):
# Load it all in
Expand Down
Loading