Repository: beautiful-atoms/beautiful-atoms (language: python)

Issue:
Update the Materials Project API
@bin told me that the Materials Project API is updated. https://materialsproject.org/api. A new package ``mp-api``is needed.

```
pip install mp-api 
```

In order to import structure from Materials Project, we need to update the code in `batoms.database.pymatgen`



Discussion / hints:

Fix patch:
diff --git a/README.md b/README.md
index fb0a500b..1c74d0bd 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,7 @@ Features:
 * scipy
 * Scikit-image
 * pymatgen
+* mp-api
 * openbabel
 
 ### How to use
diff --git a/batoms/database/mp.py b/batoms/database/mp.py
new file mode 100644
index 00000000..8eb42325
--- /dev/null
+++ b/batoms/database/mp.py
@@ -0,0 +1,14 @@
+"""Search  the Materials Project"""
+
+from batoms import Batoms
+import logging
+logger = logging.getLogger(__name__)
+
+
+def mp_search(key, mpid):
+    from mp_api.client import MPRester
+
+    with MPRester(api_key=key) as mpr:
+        structure = mpr.materials.search(material_ids=[mpid])
+        label = mpid.replace('-', '_')
+        return Batoms(label, from_pymatgen=structure)
diff --git a/batoms/database/pymatgen.py b/batoms/database/pymatgen.py
deleted file mode 100644
index 36491b0b..00000000
--- a/batoms/database/pymatgen.py
+++ /dev/null
@@ -1,23 +0,0 @@
-"""
-Search public database
-
-Pymatgen
-Pubchem
-Nomad
-"""
-
-from batoms import Batoms
-import logging
-# logger = logging.getLogger('batoms')
-logger = logging.getLogger(__name__)
-
-
-def pymatgen_search(key, id):
-    from pymatgen.ext.matproj import MPRester
-    with MPRester(key) as m:
-        # Structure for material id
-        structure = m.get_structure_by_material_id(id)
-        label = id.replace('-', '_')
-        batoms = Batoms(label, from_pymatgen=structure)
-        # Dos for material id
-        return batoms
diff --git a/batoms/gui/gui_io.py b/batoms/gui/gui_io.py
index 5789844c..95ea7185 100644
--- a/batoms/gui/gui_io.py
+++ b/batoms/gui/gui_io.py
@@ -27,9 +27,9 @@ class Batoms_IO_search_material_project(Operator):
     bl_description = ("Search structure by id")
 
     def execute(self, context):
-        from batoms.database.pymatgen import pymatgen_search
+        from batoms.database.mp import mp_search
         io = context.scene.batoms.io
-        batoms = pymatgen_search(io.mp_key, io.mp_id)
+        batoms = mp_search(io.mp_key, io.mp_id)
         return {'FINISHED'}
 
 
diff --git a/install.py b/install.py
index ff3034af..4dd46162 100644
--- a/install.py
+++ b/install.py
@@ -94,8 +94,9 @@
   - curl
   - python={blender_py_ver}
   - numpy={blender_numpy_ver}
-  - pymatgen>=2020.12
+  - pymatgen>=2022.3.7
   - ase>=3.21.0
+  - mp-api>=0.37.5
   - openbabel>=3.1.1
   - scikit-image
   - scipy>=1.6.0


Test patch:
diff --git a/tests/test_database.py b/tests/test_database.py
index ecb23894..e780f6a6 100644
--- a/tests/test_database.py
+++ b/tests/test_database.py
@@ -1,7 +1,7 @@
 import bpy
 import pytest
 from batoms import Batoms
-from batoms.database.pymatgen import pymatgen_search
+from batoms.database.mp import mp_search
 from pymatgen.core.structure import Molecule
 from pymatgen.core import Lattice, Structure