From 656a527a4d9d604006bcf0ac6b1359c38b1efca2 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:25:47 -0700 Subject: [PATCH 01/29] update: move directories to the top level --- other/materials_designer/config.yml => config.yml | 0 other/__init__.py | 0 other/materials_designer/__init__.py | 0 other/materials_designer/jupyterlite | 1 - other/jupyterlite/utils.py => utils/jupyterlite.py | 0 5 files changed, 1 deletion(-) rename other/materials_designer/config.yml => config.yml (100%) create mode 100644 other/__init__.py create mode 100644 other/materials_designer/__init__.py delete mode 120000 other/materials_designer/jupyterlite rename other/jupyterlite/utils.py => utils/jupyterlite.py (100%) diff --git a/other/materials_designer/config.yml b/config.yml similarity index 100% rename from other/materials_designer/config.yml rename to config.yml diff --git a/other/__init__.py b/other/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/other/materials_designer/__init__.py b/other/materials_designer/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/other/materials_designer/jupyterlite b/other/materials_designer/jupyterlite deleted file mode 120000 index 54394022..00000000 --- a/other/materials_designer/jupyterlite +++ /dev/null @@ -1 +0,0 @@ -../jupyterlite \ No newline at end of file diff --git a/other/jupyterlite/utils.py b/utils/jupyterlite.py similarity index 100% rename from other/jupyterlite/utils.py rename to utils/jupyterlite.py From 4d18ec94efc3796975d81e2d64bfea25f1a84050 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:26:18 -0700 Subject: [PATCH 02/29] update: allow for instalation only of default --- utils/jupyterlite.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/utils/jupyterlite.py b/utils/jupyterlite.py index 238eead0..ca3eda14 100644 --- a/utils/jupyterlite.py +++ b/utils/jupyterlite.py @@ -69,16 +69,21 @@ async def install_packages(notebook_name, requirements_path="config.yml", verbos requirements_hash = str(hash(json.dumps(requirements))) if os.environ.get("requirements_hash") != requirements_hash: packages_default_common = requirements.get("default", {}).get("packages_common", []) or [] - packages_default_environment_specific = requirements.get("default", {}).get(f"packages_{ENVIRONMENT.value}", []) or [] + packages_default_environment_specific = ( + requirements.get("default", {}).get(f"packages_{ENVIRONMENT.value}", []) or [] + ) notebook_requirements = next( (cfg for cfg in requirements.get("notebooks", []) if cfg.get("name") == notebook_name), None ) if notebook_requirements: packages_notebook_common = notebook_requirements.get("packages_common", []) or [] - packages_notebook_environment_specific= notebook_requirements.get(f"packages_{ENVIRONMENT.value}", []) or [] + packages_notebook_environment_specific = ( + notebook_requirements.get(f"packages_{ENVIRONMENT.value}", []) or [] + ) else: - raise ValueError(f"No packages found for notebook {notebook_name}") + packages_notebook_common = [] + packages_notebook_environment_specific = [] packages = [ *packages_default_common, From 8ec1d2a27d374aa3004aeeadc54d6b34921c29e1 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:38:53 -0700 Subject: [PATCH 03/29] feature: add python server to distribute wheels during local development --- server.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 server.py diff --git a/server.py b/server.py new file mode 100644 index 00000000..1449ccea --- /dev/null +++ b/server.py @@ -0,0 +1,28 @@ +# This script is used to serve the static files from the 'dist' directory for installation of python wheels. +# Install deps with `pip install ".[dev]"`, build tool `pip install build` and run `python -m build` +# Run the server with `python server.py` +# The server will be available at http://localhost:8080, use micropip in pyodide to install wheel from that URL, i.e: +# await micropip.install("http://localhost:8080/mat3ra_api_examples-2024.3.30.post2-py3-none-any.whl", deps=False) + +from http.server import HTTPServer, SimpleHTTPRequestHandler +import os + + +class CORSHTTPRequestHandler(SimpleHTTPRequestHandler): + def end_headers(self): + self.send_header("Access-Control-Allow-Origin", "*") + self.send_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS") + self.send_header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type") + return super(CORSHTTPRequestHandler, self).end_headers() + + +if __name__ == "__main__": + port = 8080 + bind_addr = "localhost" + directory = "./dist" # make sure this is the correct relative path to your 'dist' directory + + os.chdir(directory) # Change the current working directory to the specified 'directory' + + httpd = HTTPServer((bind_addr, port), CORSHTTPRequestHandler) + print(f"Serving at http://{bind_addr}:{port}") + httpd.serve_forever() From 1e20844859dc7eeab46f6a334354d04951d11739 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:41:13 -0700 Subject: [PATCH 04/29] chore: rename file --- server.py => wheel_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename server.py => wheel_server.py (96%) diff --git a/server.py b/wheel_server.py similarity index 96% rename from server.py rename to wheel_server.py index 1449ccea..55c06048 100644 --- a/server.py +++ b/wheel_server.py @@ -1,6 +1,6 @@ # This script is used to serve the static files from the 'dist' directory for installation of python wheels. # Install deps with `pip install ".[dev]"`, build tool `pip install build` and run `python -m build` -# Run the server with `python server.py` +# Run the server with `python wheel_server.py` # The server will be available at http://localhost:8080, use micropip in pyodide to install wheel from that URL, i.e: # await micropip.install("http://localhost:8080/mat3ra_api_examples-2024.3.30.post2-py3-none-any.whl", deps=False) From 6955e6afa1581521726d6403e11fcbdac4f69c8b Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:47:48 -0700 Subject: [PATCH 05/29] chore: move common package to commons --- config.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/config.yml b/config.yml index 2aebc396..74696793 100644 --- a/config.yml +++ b/config.yml @@ -6,6 +6,7 @@ # The default packages are installed for all the notebooks. default: packages_common: + - pandas==1.5.3 - ase==3.22.1 packages_python: - pymatgen==2023.9.10 @@ -21,10 +22,10 @@ default: - tabulate==0.9.0 - sympy==1.12 - uncertainties==3.1.6 + - notebooks: - name: create_interface_with_min_strain_zsl.ipynb packages_common: - - pandas==1.5.3 - ipywidgets - plotly==5.18 - nbformat>=4.2.0 @@ -32,7 +33,6 @@ notebooks: packages_pyodide: - name: import_material_from_jarvis_db_entry.ipynb packages_common: - - pandas==1.5.3 - express-py==2024.2.2.post2 - mat3ra-esse - jarvis-tools @@ -44,7 +44,6 @@ notebooks: - https://files.mat3ra.com:44318/uploads/watchdog-2.3.1-py3-none-any.whl - name: import_materials_from_files.ipynb packages_common: - - pandas==1.5.3 - express-py==2024.2.2.post2 - mat3ra-esse - munch From e4a59bf10162979340313fce51b9b94000ba5200 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:48:06 -0700 Subject: [PATCH 06/29] update: 1st iteration of imports in pyodide --- .../api_interoperability_showcase.ipynb | 26 ++++- examples/material/create_material.ipynb | 103 ++++++++++++++++-- .../material/get_materials_by_formula.ipynb | 20 +++- ...port_materials_from_materialsproject.ipynb | 20 +++- .../upload_materials_from_file_poscar.ipynb | 23 +++- 5 files changed, 176 insertions(+), 16 deletions(-) diff --git a/examples/material/api_interoperability_showcase.ipynb b/examples/material/api_interoperability_showcase.ipynb index 0396a645..8bb7ddf6 100644 --- a/examples/material/api_interoperability_showcase.ipynb +++ b/examples/material/api_interoperability_showcase.ipynb @@ -77,7 +77,31 @@ " )\n", " )\n", "\n", - " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash" + " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", + "\n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " apiConfig = data_from_host.get(\"apiConfig\")\n", + " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", + " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\")\n", + " os.environ.update(\n", + " dict(\n", + " ACCOUNT_ID=ACCOUNT_ID,\n", + " AUTH_TOKEN=AUTH_TOKEN,\n", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " )\n", + " )\n", + "\n", + " import micropip\n", + " # TODO: update to use the latest version of the package on PyPI\n", + " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post2-py3-none-any.whl', deps=False)\n", + " await micropip.install(\"exabyte-api-client\")\n", + " from utils.jupyterlite import install_packages\n", + "\n", + " await install_packages(\"\")\n", + " await micropip.install(\"mp_api\")\n", + " await micropip.install(\"https://files.mat3ra.com:44318/uploads/pymatgen-2023.9.10-py3-none-any.whl\", deps=False)" ] }, { diff --git a/examples/material/create_material.ipynb b/examples/material/create_material.ipynb index a7c2a9e2..00d3430f 100644 --- a/examples/material/create_material.ipynb +++ b/examples/material/create_material.ipynb @@ -46,11 +46,28 @@ }, { "cell_type": "code", - "execution_count": null, + "outputs": [], + "source": [], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-03-29T03:52:07.106265Z", + "start_time": "2024-03-29T03:52:07.093977Z" + } + }, + "execution_count": 11 + }, + { + "cell_type": "code", + "execution_count": 12, "metadata": { "cellView": "form", "id": "63oC9xGZsuyy", - "outputId": "1419f649-9ac2-4e50-a197-ff90c3769987" + "outputId": "1419f649-9ac2-4e50-a197-ff90c3769987", + "ExecuteTime": { + "end_time": "2024-03-29T03:52:07.124519Z", + "start_time": "2024-03-29T03:52:07.102506Z" + } }, "outputs": [], "source": [ @@ -72,7 +89,28 @@ " )\n", " )\n", "\n", - " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash" + " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", + "\n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " apiConfig = data_from_host.get(\"apiConfig\")\n", + " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", + " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\")\n", + " os.environ.update(\n", + " dict(\n", + " ACCOUNT_ID=ACCOUNT_ID,\n", + " AUTH_TOKEN=AUTH_TOKEN,\n", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " )\n", + " )\n", + "\n", + " import micropip\n", + " # await micropip.install(\"tabulate\")\n", + " # await micropip.install(\"jinja2\")\n", + " # await micropip.install(\"pandas\")\n", + " await micropip.install('https://files.mat3ra.com/uploads/mat3ra_api_examples-2024.3.28post0-py3-none-any.whl')\n", + " await micropip.install(\"exabyte-api-client\")" ] }, { @@ -87,11 +125,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": { - "id": "eohqW-ICsRA-" + "id": "eohqW-ICsRA-", + "ExecuteTime": { + "end_time": "2024-03-29T19:07:04.067531Z", + "start_time": "2024-03-29T19:07:04.056714Z" + } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['localhost', 443, 'ufcPKWGcExZr5o4sJ', '4CDd3xpCOi4kaAMoRZTrsEHKOjsRQOPlpFvrpSxCcCE=', '2018-10-01', False]\n" + ] + } + ], "source": [ "from utils.settings import ENDPOINT_ARGS\n", "from utils.generic import display_JSON\n", @@ -113,9 +163,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": { - "id": "YrcuQGZSsRA_" + "id": "YrcuQGZSsRA_", + "ExecuteTime": { + "end_time": "2024-03-29T18:52:15.708331Z", + "start_time": "2024-03-29T18:52:15.700530Z" + } }, "outputs": [], "source": [ @@ -163,13 +217,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": { - "id": "sEr2jm5wsRBA" + "id": "sEr2jm5wsRBA", + "ExecuteTime": { + "end_time": "2024-03-29T19:27:54.488356Z", + "start_time": "2024-03-29T19:27:52.612100Z" + } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['localhost', 3000, 'ufcPKWGcExZr5o4sJ', 'ZAq7_tH8BIdvs9UObZDqHGVqKLl1JFrsWOcDiPXGtqG', '2018-10-01', False]\n", + "\n" + ] + } + ], "source": [ + "ENDPOINT_ARGS[0] = 'localhost'\n", + "ENDPOINT_ARGS[1] = 3000\n", + "ENDPOINT_ARGS[2] = \"ufcPKWGcExZr5o4sJ\"\n", + "ENDPOINT_ARGS[3] = \"ZAq7_tH8BIdvs9UObZDqHGVqKLl1JFrsWOcDiPXGtqG\"\n", + "ENDPOINT_ARGS[5] = False\n", + "print(ENDPOINT_ARGS)\n", "endpoint = MaterialEndpoints(*ENDPOINT_ARGS)\n", + "print(endpoint)\n", + "material = endpoint.list({})\n", + "material\n", "material = endpoint.create(CONFIG)" ] }, @@ -188,7 +264,10 @@ "execution_count": null, "metadata": { "id": "NGMxmSLUsRBB", - "outputId": "0f8e0efa-e94b-4292-968c-a6252658c14a" + "outputId": "0f8e0efa-e94b-4292-968c-a6252658c14a", + "ExecuteTime": { + "start_time": "2024-03-29T03:52:07.870660Z" + } }, "outputs": [], "source": [ diff --git a/examples/material/get_materials_by_formula.ipynb b/examples/material/get_materials_by_formula.ipynb index b2a80275..77c54a7a 100644 --- a/examples/material/get_materials_by_formula.ipynb +++ b/examples/material/get_materials_by_formula.ipynb @@ -73,7 +73,25 @@ " )\n", " )\n", "\n", - " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash" + " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", + " \n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " apiConfig = data_from_host.get(\"apiConfig\")\n", + " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", + " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\")\n", + " os.environ.update(\n", + " dict(\n", + " ACCOUNT_ID=ACCOUNT_ID,\n", + " AUTH_TOKEN=AUTH_TOKEN,\n", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " )\n", + " )\n", + "\n", + " import micropip\n", + " await micropip.install('https://files.mat3ra.com/uploads/mat3ra_api_examples-2024.3.28post0-py3-none-any.whl')\n", + " await micropip.install(\"exabyte-api-client\")" ] }, { diff --git a/examples/material/import_materials_from_materialsproject.ipynb b/examples/material/import_materials_from_materialsproject.ipynb index 880324c4..e06c9b41 100644 --- a/examples/material/import_materials_from_materialsproject.ipynb +++ b/examples/material/import_materials_from_materialsproject.ipynb @@ -73,7 +73,25 @@ " )\n", " )\n", "\n", - " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash" + " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", + " \n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " apiConfig = data_from_host.get(\"apiConfig\")\n", + " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", + " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\")\n", + " os.environ.update(\n", + " dict(\n", + " ACCOUNT_ID=ACCOUNT_ID,\n", + " AUTH_TOKEN=AUTH_TOKEN,\n", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " )\n", + " )\n", + "\n", + " import micropip\n", + " await micropip.install('https://files.mat3ra.com/uploads/mat3ra_api_examples-2024.3.28post0-py3-none-any.whl')\n", + " await micropip.install(\"exabyte-api-client\")" ] }, { diff --git a/examples/material/upload_materials_from_file_poscar.ipynb b/examples/material/upload_materials_from_file_poscar.ipynb index b4c1bdb8..bfca910d 100644 --- a/examples/material/upload_materials_from_file_poscar.ipynb +++ b/examples/material/upload_materials_from_file_poscar.ipynb @@ -76,7 +76,28 @@ " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; export IS_USING_GIT_LFS=true; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", " from examples.utils.notebook import get_notebook_info\n", "\n", - " os.chdir(os.path.join(\"api-examples\", os.path.dirname(get_notebook_info()[\"notebook_path\"])))" + " os.chdir(os.path.join(\"api-examples\", os.path.dirname(get_notebook_info()[\"notebook_path\"])))\n", + "\n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " apiConfig = data_from_host.get(\"apiConfig\")\n", + " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", + " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(\n", + " dict(\n", + " ACCOUNT_ID=ACCOUNT_ID,\n", + " AUTH_TOKEN=AUTH_TOKEN,\n", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " )\n", + " )\n", + "\n", + " import micropip\n", + " await micropip.install(\"tabulate\")\n", + " await micropip.install(\"jinja2\")\n", + " await micropip.install(\"pandas\")\n", + " await micropip.install('https://files.mat3ra.com/uploads/mat3ra_api_examples-2024.3.28post0-py3-none-any.whl')\n", + " await micropip.install(\"exabyte-api-client\")" ] }, { From 24d1fd90c5cd81d0382adb2ef8e4159a337527e7 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:40:33 -0700 Subject: [PATCH 07/29] update: install from relative config --- utils/jupyterlite.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils/jupyterlite.py b/utils/jupyterlite.py index febdc425..98e49388 100644 --- a/utils/jupyterlite.py +++ b/utils/jupyterlite.py @@ -62,7 +62,13 @@ async def install_packages(notebook_name, requirements_path="config.yml", verbos await micropip.install("pyyaml") import yaml - with open(requirements_path, "r") as f: + base_path = os.getcwd() + if requirements_path is None: + requirements_file = os.path.normpath(os.path.join(base_path, "./config.yml")) + else: + requirements_file = os.path.normpath(os.path.join(base_path, requirements_path)) + + with open(requirements_file, "r") as f: requirements = yaml.safe_load(f) # Hash the requirements to avoid re-installing packages From 5dde546e9b5eb5c0e14ba577c827978e5bfd6857 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:41:09 -0700 Subject: [PATCH 08/29] update: adjust material AX to work in pyodide --- .../api_interoperability_showcase.ipynb | 12 +-- examples/material/create_material.ipynb | 93 ++++--------------- .../material/get_materials_by_formula.ipynb | 12 ++- ...port_materials_from_materialsproject.ipynb | 12 ++- .../upload_materials_from_file_poscar.ipynb | 11 +-- 5 files changed, 40 insertions(+), 100 deletions(-) diff --git a/examples/material/api_interoperability_showcase.ipynb b/examples/material/api_interoperability_showcase.ipynb index 8bb7ddf6..0f17bcfa 100644 --- a/examples/material/api_interoperability_showcase.ipynb +++ b/examples/material/api_interoperability_showcase.ipynb @@ -83,7 +83,7 @@ " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", " os.environ.update(\n", " dict(\n", " ACCOUNT_ID=ACCOUNT_ID,\n", @@ -92,16 +92,12 @@ " ORGANIZATION_ID=ORGANIZATION_ID,\n", " )\n", " )\n", - "\n", + " \n", " import micropip\n", - " # TODO: update to use the latest version of the package on PyPI\n", - " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post2-py3-none-any.whl', deps=False)\n", + " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", - "\n", - " await install_packages(\"\")\n", - " await micropip.install(\"mp_api\")\n", - " await micropip.install(\"https://files.mat3ra.com:44318/uploads/pymatgen-2023.9.10-py3-none-any.whl\", deps=False)" + " await install_packages(\"api_interoperability_showcase.ipynb\",\"../../config.yml\")" ] }, { diff --git a/examples/material/create_material.ipynb b/examples/material/create_material.ipynb index 00d3430f..a8cc429d 100644 --- a/examples/material/create_material.ipynb +++ b/examples/material/create_material.ipynb @@ -46,28 +46,11 @@ }, { "cell_type": "code", - "outputs": [], - "source": [], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-03-29T03:52:07.106265Z", - "start_time": "2024-03-29T03:52:07.093977Z" - } - }, - "execution_count": 11 - }, - { - "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": { "cellView": "form", "id": "63oC9xGZsuyy", - "outputId": "1419f649-9ac2-4e50-a197-ff90c3769987", - "ExecuteTime": { - "end_time": "2024-03-29T03:52:07.124519Z", - "start_time": "2024-03-29T03:52:07.102506Z" - } + "outputId": "1419f649-9ac2-4e50-a197-ff90c3769987" }, "outputs": [], "source": [ @@ -95,7 +78,7 @@ " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", " os.environ.update(\n", " dict(\n", " ACCOUNT_ID=ACCOUNT_ID,\n", @@ -104,13 +87,12 @@ " ORGANIZATION_ID=ORGANIZATION_ID,\n", " )\n", " )\n", - "\n", + " \n", " import micropip\n", - " # await micropip.install(\"tabulate\")\n", - " # await micropip.install(\"jinja2\")\n", - " # await micropip.install(\"pandas\")\n", - " await micropip.install('https://files.mat3ra.com/uploads/mat3ra_api_examples-2024.3.28post0-py3-none-any.whl')\n", - " await micropip.install(\"exabyte-api-client\")" + " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install(\"exabyte-api-client\")\n", + " from utils.jupyterlite import install_packages\n", + " await install_packages(\"\",\"../../config.yml\")" ] }, { @@ -125,23 +107,11 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": null, "metadata": { - "id": "eohqW-ICsRA-", - "ExecuteTime": { - "end_time": "2024-03-29T19:07:04.067531Z", - "start_time": "2024-03-29T19:07:04.056714Z" - } + "id": "eohqW-ICsRA-" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['localhost', 443, 'ufcPKWGcExZr5o4sJ', '4CDd3xpCOi4kaAMoRZTrsEHKOjsRQOPlpFvrpSxCcCE=', '2018-10-01', False]\n" - ] - } - ], + "outputs": [], "source": [ "from utils.settings import ENDPOINT_ARGS\n", "from utils.generic import display_JSON\n", @@ -163,13 +133,9 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": null, "metadata": { - "id": "YrcuQGZSsRA_", - "ExecuteTime": { - "end_time": "2024-03-29T18:52:15.708331Z", - "start_time": "2024-03-29T18:52:15.700530Z" - } + "id": "YrcuQGZSsRA_" }, "outputs": [], "source": [ @@ -217,35 +183,13 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": null, "metadata": { - "id": "sEr2jm5wsRBA", - "ExecuteTime": { - "end_time": "2024-03-29T19:27:54.488356Z", - "start_time": "2024-03-29T19:27:52.612100Z" - } + "id": "sEr2jm5wsRBA" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['localhost', 3000, 'ufcPKWGcExZr5o4sJ', 'ZAq7_tH8BIdvs9UObZDqHGVqKLl1JFrsWOcDiPXGtqG', '2018-10-01', False]\n", - "\n" - ] - } - ], + "outputs": [], "source": [ - "ENDPOINT_ARGS[0] = 'localhost'\n", - "ENDPOINT_ARGS[1] = 3000\n", - "ENDPOINT_ARGS[2] = \"ufcPKWGcExZr5o4sJ\"\n", - "ENDPOINT_ARGS[3] = \"ZAq7_tH8BIdvs9UObZDqHGVqKLl1JFrsWOcDiPXGtqG\"\n", - "ENDPOINT_ARGS[5] = False\n", - "print(ENDPOINT_ARGS)\n", "endpoint = MaterialEndpoints(*ENDPOINT_ARGS)\n", - "print(endpoint)\n", - "material = endpoint.list({})\n", - "material\n", "material = endpoint.create(CONFIG)" ] }, @@ -264,10 +208,7 @@ "execution_count": null, "metadata": { "id": "NGMxmSLUsRBB", - "outputId": "0f8e0efa-e94b-4292-968c-a6252658c14a", - "ExecuteTime": { - "start_time": "2024-03-29T03:52:07.870660Z" - } + "outputId": "0f8e0efa-e94b-4292-968c-a6252658c14a" }, "outputs": [], "source": [ diff --git a/examples/material/get_materials_by_formula.ipynb b/examples/material/get_materials_by_formula.ipynb index 77c54a7a..07470f51 100644 --- a/examples/material/get_materials_by_formula.ipynb +++ b/examples/material/get_materials_by_formula.ipynb @@ -74,12 +74,12 @@ " )\n", "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", - " \n", + "\n", "if \"/home/pyodide\" in os.environ.get('HOME'):\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", " os.environ.update(\n", " dict(\n", " ACCOUNT_ID=ACCOUNT_ID,\n", @@ -88,10 +88,12 @@ " ORGANIZATION_ID=ORGANIZATION_ID,\n", " )\n", " )\n", - "\n", + " \n", " import micropip\n", - " await micropip.install('https://files.mat3ra.com/uploads/mat3ra_api_examples-2024.3.28post0-py3-none-any.whl')\n", - " await micropip.install(\"exabyte-api-client\")" + " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install(\"exabyte-api-client\")\n", + " from utils.jupyterlite import install_packages\n", + " await install_packages(\"\",\"../../config.yml\")" ] }, { diff --git a/examples/material/import_materials_from_materialsproject.ipynb b/examples/material/import_materials_from_materialsproject.ipynb index e06c9b41..7ceb4423 100644 --- a/examples/material/import_materials_from_materialsproject.ipynb +++ b/examples/material/import_materials_from_materialsproject.ipynb @@ -74,12 +74,12 @@ " )\n", "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", - " \n", + "\n", "if \"/home/pyodide\" in os.environ.get('HOME'):\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", " os.environ.update(\n", " dict(\n", " ACCOUNT_ID=ACCOUNT_ID,\n", @@ -88,10 +88,12 @@ " ORGANIZATION_ID=ORGANIZATION_ID,\n", " )\n", " )\n", - "\n", + " \n", " import micropip\n", - " await micropip.install('https://files.mat3ra.com/uploads/mat3ra_api_examples-2024.3.28post0-py3-none-any.whl')\n", - " await micropip.install(\"exabyte-api-client\")" + " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install(\"exabyte-api-client\")\n", + " from utils.jupyterlite import install_packages\n", + " await install_packages(\"\",\"../../config.yml\")" ] }, { diff --git a/examples/material/upload_materials_from_file_poscar.ipynb b/examples/material/upload_materials_from_file_poscar.ipynb index bfca910d..2f3b9930 100644 --- a/examples/material/upload_materials_from_file_poscar.ipynb +++ b/examples/material/upload_materials_from_file_poscar.ipynb @@ -91,13 +91,12 @@ " ORGANIZATION_ID=ORGANIZATION_ID,\n", " )\n", " )\n", - "\n", + " \n", " import micropip\n", - " await micropip.install(\"tabulate\")\n", - " await micropip.install(\"jinja2\")\n", - " await micropip.install(\"pandas\")\n", - " await micropip.install('https://files.mat3ra.com/uploads/mat3ra_api_examples-2024.3.28post0-py3-none-any.whl')\n", - " await micropip.install(\"exabyte-api-client\")" + " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install(\"exabyte-api-client\")\n", + " from utils.jupyterlite import install_packages\n", + " await install_packages(\"\",\"../../config.yml\")" ] }, { From 7b57fef8a021217818f22f316b86e3e90aed023a Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:41:48 -0700 Subject: [PATCH 09/29] update: add reqs for a notebook --- config.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/config.yml b/config.yml index 74696793..da00debe 100644 --- a/config.yml +++ b/config.yml @@ -22,7 +22,6 @@ default: - tabulate==0.9.0 - sympy==1.12 - uncertainties==3.1.6 - - notebooks: - name: create_interface_with_min_strain_zsl.ipynb packages_common: @@ -52,3 +51,9 @@ notebooks: packages_pyodide: - https://files.mat3ra.com:44318/uploads/paginate-0.5.6-py3-none-any.whl - https://files.mat3ra.com:44318/uploads/watchdog-2.3.1-py3-none-any.whl + - name: api_interoperability_showcase.ipynb + packages_pyodide: + - mp_api==0.31.1 + - mpcontribs-client + - tqdm + - plotly \ No newline at end of file From d04a26942cf07a9e90b28dc23a875928d78e71f2 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:57:17 -0700 Subject: [PATCH 10/29] update: adjust material AX to work in pyodide 2 --- examples/job/create_and_submit_job.ipynb | 22 ++++++++++++++++++- examples/job/get-file-from-job.ipynb | 22 ++++++++++++++++++- .../ml-train-model-predict-properties.ipynb | 22 ++++++++++++++++++- ...n-simulations-and-extract-properties.ipynb | 22 ++++++++++++++++++- .../system/get_authentication_params.ipynb | 2 +- examples/workflow/get_workflows.ipynb | 22 ++++++++++++++++++- examples/workflow/qe_scf_calculation.ipynb | 22 ++++++++++++++++++- 7 files changed, 127 insertions(+), 7 deletions(-) diff --git a/examples/job/create_and_submit_job.ipynb b/examples/job/create_and_submit_job.ipynb index 7a9d8535..d7d5fffe 100644 --- a/examples/job/create_and_submit_job.ipynb +++ b/examples/job/create_and_submit_job.ipynb @@ -77,7 +77,27 @@ " )\n", " )\n", "\n", - " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash" + " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", + " \n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " apiConfig = data_from_host.get(\"apiConfig\")\n", + " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", + " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(\n", + " dict(\n", + " ACCOUNT_ID=ACCOUNT_ID,\n", + " AUTH_TOKEN=AUTH_TOKEN,\n", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " )\n", + " )\n", + " \n", + " import micropip\n", + " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install(\"exabyte-api-client\")\n", + " from utils.jupyterlite import install_packages\n", + " await install_packages(\"\",\"../../config.yml\")" ] }, { diff --git a/examples/job/get-file-from-job.ipynb b/examples/job/get-file-from-job.ipynb index c808e8ae..8652cbd2 100644 --- a/examples/job/get-file-from-job.ipynb +++ b/examples/job/get-file-from-job.ipynb @@ -99,7 +99,27 @@ " )\n", " )\n", "\n", - " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash" + " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", + " \n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " apiConfig = data_from_host.get(\"apiConfig\")\n", + " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", + " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(\n", + " dict(\n", + " ACCOUNT_ID=ACCOUNT_ID,\n", + " AUTH_TOKEN=AUTH_TOKEN,\n", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " )\n", + " )\n", + " \n", + " import micropip\n", + " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install(\"exabyte-api-client\")\n", + " from utils.jupyterlite import install_packages\n", + " await install_packages(\"\",\"../../config.yml\")" ] }, { diff --git a/examples/job/ml-train-model-predict-properties.ipynb b/examples/job/ml-train-model-predict-properties.ipynb index 720123c3..21634caf 100644 --- a/examples/job/ml-train-model-predict-properties.ipynb +++ b/examples/job/ml-train-model-predict-properties.ipynb @@ -99,7 +99,27 @@ " )\n", " )\n", "\n", - " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash" + " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", + " \n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " apiConfig = data_from_host.get(\"apiConfig\")\n", + " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", + " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(\n", + " dict(\n", + " ACCOUNT_ID=ACCOUNT_ID,\n", + " AUTH_TOKEN=AUTH_TOKEN,\n", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " )\n", + " )\n", + " \n", + " import micropip\n", + " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install(\"exabyte-api-client\")\n", + " from utils.jupyterlite import install_packages\n", + " await install_packages(\"\",\"../../config.yml\")" ] }, { diff --git a/examples/job/run-simulations-and-extract-properties.ipynb b/examples/job/run-simulations-and-extract-properties.ipynb index 7d14ddae..96ad3837 100644 --- a/examples/job/run-simulations-and-extract-properties.ipynb +++ b/examples/job/run-simulations-and-extract-properties.ipynb @@ -106,7 +106,27 @@ " )\n", " )\n", "\n", - " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash" + " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", + " \n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " apiConfig = data_from_host.get(\"apiConfig\")\n", + " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", + " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(\n", + " dict(\n", + " ACCOUNT_ID=ACCOUNT_ID,\n", + " AUTH_TOKEN=AUTH_TOKEN,\n", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " )\n", + " )\n", + " \n", + " import micropip\n", + " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install(\"exabyte-api-client\")\n", + " from utils.jupyterlite import install_packages\n", + " await install_packages(\"\",\"../../config.yml\")" ] }, { diff --git a/examples/system/get_authentication_params.ipynb b/examples/system/get_authentication_params.ipynb index e8b49cff..51ff4405 100644 --- a/examples/system/get_authentication_params.ipynb +++ b/examples/system/get_authentication_params.ipynb @@ -61,7 +61,7 @@ "import os\n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", - " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash" + " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n" ] }, { diff --git a/examples/workflow/get_workflows.ipynb b/examples/workflow/get_workflows.ipynb index 637150bb..982b1717 100644 --- a/examples/workflow/get_workflows.ipynb +++ b/examples/workflow/get_workflows.ipynb @@ -77,7 +77,27 @@ " )\n", " )\n", "\n", - " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash" + " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", + " \n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " apiConfig = data_from_host.get(\"apiConfig\")\n", + " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", + " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(\n", + " dict(\n", + " ACCOUNT_ID=ACCOUNT_ID,\n", + " AUTH_TOKEN=AUTH_TOKEN,\n", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " )\n", + " )\n", + " \n", + " import micropip\n", + " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install(\"exabyte-api-client\")\n", + " from utils.jupyterlite import install_packages\n", + " await install_packages(\"\",\"../../config.yml\")" ] }, { diff --git a/examples/workflow/qe_scf_calculation.ipynb b/examples/workflow/qe_scf_calculation.ipynb index d6edd70b..6ad38883 100644 --- a/examples/workflow/qe_scf_calculation.ipynb +++ b/examples/workflow/qe_scf_calculation.ipynb @@ -72,7 +72,27 @@ " )\n", " )\n", "\n", - " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash" + " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", + " \n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " apiConfig = data_from_host.get(\"apiConfig\")\n", + " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", + " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", + " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(\n", + " dict(\n", + " ACCOUNT_ID=ACCOUNT_ID,\n", + " AUTH_TOKEN=AUTH_TOKEN,\n", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " )\n", + " )\n", + " \n", + " import micropip\n", + " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install(\"exabyte-api-client\")\n", + " from utils.jupyterlite import install_packages\n", + " await install_packages(\"\",\"../../config.yml\")" ] }, { From ddfa85c6eee1cbc5bd35775fe4626ad224770271 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:57:30 -0700 Subject: [PATCH 11/29] chore: add jinja2 --- config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config.yml b/config.yml index da00debe..15195519 100644 --- a/config.yml +++ b/config.yml @@ -22,6 +22,7 @@ default: - tabulate==0.9.0 - sympy==1.12 - uncertainties==3.1.6 + - jinja2 notebooks: - name: create_interface_with_min_strain_zsl.ipynb packages_common: From e628071f9a9d393e7b29294e1d764622f25bffe1 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 1 Apr 2024 16:32:41 -0700 Subject: [PATCH 12/29] chore: update url for local test --- examples/job/create_and_submit_job.ipynb | 2 +- examples/job/get-file-from-job.ipynb | 2 +- examples/job/ml-train-model-predict-properties.ipynb | 2 +- examples/job/run-simulations-and-extract-properties.ipynb | 2 +- examples/material/api_interoperability_showcase.ipynb | 2 +- examples/material/create_material.ipynb | 2 +- examples/material/get_materials_by_formula.ipynb | 2 +- examples/material/import_materials_from_materialsproject.ipynb | 2 +- examples/material/upload_materials_from_file_poscar.ipynb | 2 +- examples/workflow/get_workflows.ipynb | 2 +- examples/workflow/qe_scf_calculation.ipynb | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/job/create_and_submit_job.ipynb b/examples/job/create_and_submit_job.ipynb index d7d5fffe..3a385dde 100644 --- a/examples/job/create_and_submit_job.ipynb +++ b/examples/job/create_and_submit_job.ipynb @@ -94,7 +94,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/job/get-file-from-job.ipynb b/examples/job/get-file-from-job.ipynb index 8652cbd2..90b0c363 100644 --- a/examples/job/get-file-from-job.ipynb +++ b/examples/job/get-file-from-job.ipynb @@ -116,7 +116,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/job/ml-train-model-predict-properties.ipynb b/examples/job/ml-train-model-predict-properties.ipynb index 21634caf..f4a5eb19 100644 --- a/examples/job/ml-train-model-predict-properties.ipynb +++ b/examples/job/ml-train-model-predict-properties.ipynb @@ -116,7 +116,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/job/run-simulations-and-extract-properties.ipynb b/examples/job/run-simulations-and-extract-properties.ipynb index 96ad3837..422dd6e4 100644 --- a/examples/job/run-simulations-and-extract-properties.ipynb +++ b/examples/job/run-simulations-and-extract-properties.ipynb @@ -123,7 +123,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/material/api_interoperability_showcase.ipynb b/examples/material/api_interoperability_showcase.ipynb index 0f17bcfa..09a67eb3 100644 --- a/examples/material/api_interoperability_showcase.ipynb +++ b/examples/material/api_interoperability_showcase.ipynb @@ -94,7 +94,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"api_interoperability_showcase.ipynb\",\"../../config.yml\")" diff --git a/examples/material/create_material.ipynb b/examples/material/create_material.ipynb index a8cc429d..5027152e 100644 --- a/examples/material/create_material.ipynb +++ b/examples/material/create_material.ipynb @@ -89,7 +89,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/material/get_materials_by_formula.ipynb b/examples/material/get_materials_by_formula.ipynb index 07470f51..3c952bed 100644 --- a/examples/material/get_materials_by_formula.ipynb +++ b/examples/material/get_materials_by_formula.ipynb @@ -90,7 +90,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/material/import_materials_from_materialsproject.ipynb b/examples/material/import_materials_from_materialsproject.ipynb index 7ceb4423..a8104c34 100644 --- a/examples/material/import_materials_from_materialsproject.ipynb +++ b/examples/material/import_materials_from_materialsproject.ipynb @@ -90,7 +90,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/material/upload_materials_from_file_poscar.ipynb b/examples/material/upload_materials_from_file_poscar.ipynb index 2f3b9930..45a976ed 100644 --- a/examples/material/upload_materials_from_file_poscar.ipynb +++ b/examples/material/upload_materials_from_file_poscar.ipynb @@ -93,7 +93,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/workflow/get_workflows.ipynb b/examples/workflow/get_workflows.ipynb index 982b1717..66e59cef 100644 --- a/examples/workflow/get_workflows.ipynb +++ b/examples/workflow/get_workflows.ipynb @@ -94,7 +94,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/workflow/qe_scf_calculation.ipynb b/examples/workflow/qe_scf_calculation.ipynb index 6ad38883..ac1b736d 100644 --- a/examples/workflow/qe_scf_calculation.ipynb +++ b/examples/workflow/qe_scf_calculation.ipynb @@ -89,7 +89,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8001/mat3ra_api_examples-2024.3.30.post4.dev7+gb154eef-py3-none-any.whl', deps=False)\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" From bda97e194abd3ff31a3d51fea6e8d9ad66738288 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 1 Apr 2024 16:47:01 -0700 Subject: [PATCH 13/29] update: adjust jl/md notebooks imports --- ...create_interface_with_min_strain_zsl.ipynb | 9 +- ...te_interface_with_relaxation_ase_emt.ipynb | 9 +- ...import_material_from_jarvis_db_entry.ipynb | 557 +++++++++--------- .../import_materials_from_files.ipynb | 9 +- 4 files changed, 295 insertions(+), 289 deletions(-) diff --git a/other/materials_designer/create_interface_with_min_strain_zsl.ipynb b/other/materials_designer/create_interface_with_min_strain_zsl.ipynb index c02b225b..c53a8a10 100644 --- a/other/materials_designer/create_interface_with_min_strain_zsl.ipynb +++ b/other/materials_designer/create_interface_with_min_strain_zsl.ipynb @@ -116,9 +116,12 @@ "metadata": {}, "outputs": [], "source": [ - "from jupyterlite.utils import install_packages\n", - "\n", - "await install_packages(\"create_interface_with_min_strain_zsl.ipynb\")" + "import os\n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " import micropip\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + "from utils.jupyterlite import install_packages\n", + "await install_packages(\"create_interface_with_min_strain_zsl.ipynb\",\"../../config.yml\")" ] }, { diff --git a/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb b/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb index 8f8f5474..d56d9654 100644 --- a/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb +++ b/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb @@ -122,9 +122,12 @@ "metadata": {}, "outputs": [], "source": [ - "from jupyterlite.utils import install_packages\n", - "\n", - "await install_packages(\"create_interface_with_min_strain_zsl.ipynb\")" + "import os\n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " import micropip\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + "from utils.jupyterlite import install_packages\n", + "await install_packages(\"create_interface_with_min_strain_zsl.ipynb\",\"../../config.yml\")" ] }, { diff --git a/other/materials_designer/import_material_from_jarvis_db_entry.ipynb b/other/materials_designer/import_material_from_jarvis_db_entry.ipynb index 52c72dae..f7e6c881 100644 --- a/other/materials_designer/import_material_from_jarvis_db_entry.ipynb +++ b/other/materials_designer/import_material_from_jarvis_db_entry.ipynb @@ -1,283 +1,280 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "826fcc4c", - "metadata": {}, - "source": [ - "# Import 2D material from JARVIS database\n", - "\n", - "Import a structure from the NIST JARVIS database by its ID. Use data at JARVIS-DFT to find the ID of the structure you are interested in.\n", - "\n", - "

Usage

\n", - "\n", - "1. Set Input Parameters (e.g. `JARVIS_ID`) below or use the default value\n", - "1. Click \"Run\" > \"Run All Cells\" to run all cells\n", - "1. Wait for the run to complete (it should take ~30 sec first time to install packages). Scroll down to view cell results.\n", - "\n", - "## Methodology\n", - "\n", - "The following happens in the script below:\n", - "\n", - "1. Install `express-py` alongside the necessary packages\n", - "2. Import the material from JARVIS database\n", - "3. Convert the material to ESSE format\n", - "4. Pass the material to the outside runtime" - ] - }, - { - "cell_type": "markdown", - "id": "4299768d", - "metadata": {}, - "source": [ - "## 1. Set Parameters" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "9c1f4e9e", - "metadata": {}, - "outputs": [], - "source": [ - "# Note: JVASP-670 is an entry for MoTe2 and JVASP-6838 is an entry for GaTe\n", - "JARVIS_IDS = [\n", - " \"JVASP-670\",\n", - " \"JVASP-6838\",\n", - "]" - ] - }, - { - "cell_type": "markdown", - "id": "8b00ab6854f2263b", - "metadata": {}, - "source": [ - "## 2. Install Packages" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ef2b38a5-de7e-419e-b605-110e9e0095f5", - "metadata": { - "trusted": true - }, - "outputs": [], - "source": [ - "from jupyterlite.utils import install_packages\n", - "\n", - "await install_packages(\"import_material_from_jarvis_db_entry.ipynb\")" - ] - }, - { - "cell_type": "markdown", - "id": "f418c51a7f794f9f", - "metadata": {}, - "source": [ - "## 3. Data Processing\n", - "\n", - "### 3.1. Get data and wrap it in dataframe" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b1ee775d1476f884", - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - }, - "trusted": true - }, - "outputs": [], - "source": [ - "import pandas as pd\n", - "from jarvis.db.figshare import data\n", - "\n", - "dft_2d = data(\"dft_2d\")\n", - "dft_3d = data(\"dft_3d\")\n", - "dataframe_2d = pd.DataFrame(dft_2d)\n", - "dataframe_3d = pd.DataFrame(dft_3d)\n", - "dataframe= pd.concat([dataframe_2d, dataframe_3d])" - ] - }, - { - "cell_type": "markdown", - "id": "57b0d358", - "metadata": {}, - "source": [ - "### 3.2. Preview the dataframe" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0e34472a", - "metadata": {}, - "outputs": [], - "source": [ - "dataframe" - ] - }, - { - "cell_type": "markdown", - "id": "15fe5f9de299c935", - "metadata": {}, - "source": [ - "### 3.3. Filter data" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a771a36a", - "metadata": {}, - "outputs": [], - "source": [ - "import json\n", - "from express import ExPrESS\n", - "\n", - "dataframe_entries_for_jarvis_ids = dataframe[(dataframe[\"jid\"].isin(JARVIS_IDS))]\n", - "dataframe_entries_as_json = dataframe_entries_for_jarvis_ids.to_json(orient=\"records\")\n", - "jarvis_db_entries = json.loads(dataframe_entries_as_json)" - ] - }, - { - "cell_type": "markdown", - "id": "ef5f9e9d", - "metadata": {}, - "source": [ - "### 3.4. Convert to ESSE format" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c41fb68c6d25fe48", - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - }, - "trusted": true - }, - "outputs": [], - "source": [ - "def convert_jarvis_entry_to_esse(jarvis_db_entry):\n", - " jarvis_db_entry_json = json.dumps(jarvis_db_entry)\n", - " kwargs = {\n", - " \"structure_string\": jarvis_db_entry_json,\n", - " \"cell_type\": \"original\",\n", - " \"structure_format\": \"jarvis-db-entry\",\n", - " }\n", - " handler = ExPrESS(\"structure\", **kwargs)\n", - " esse = handler.property(\"material\", **kwargs)\n", - " poscar = handler.parser.jarvis_db_entry_json_to_poscar(jarvis_db_entry_json)\n", - " return (esse, poscar)\n", - "\n", - "esse_entries = list(map(lambda e: convert_jarvis_entry_to_esse(e)[0], jarvis_db_entries))\n", - "poscars = list(map(lambda e: convert_jarvis_entry_to_esse(e)[1], jarvis_db_entries))" - ] - }, - { - "cell_type": "markdown", - "id": "8770ec48", - "metadata": {}, - "source": [ - "### 3.5. Preview the data" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "860b5c1b", - "metadata": {}, - "outputs": [], - "source": [ - "from src.utils import poscar_to_ase\n", - "from ase.visualize import view\n", - "from ase.io import write\n", - "from ase.build import make_supercell\n", - "from IPython.display import Image\n", - "\n", - "# Uncomment to see the JSON\n", - "# print(json.dumps(data, indent=4))\n", - "\n", - "\n", - "materials = list(map(lambda p: poscar_to_ase(p), poscars))\n", - "\n", - "def visualize_material(material, index: int, number_of_repetitions: int = 3):\n", - " \"\"\"\n", - " Visualize the material using ASE's visualization tool\n", - " Repeat the unit cell to make it easier to see.\n", - "\n", - " Args:\n", - " material: The material to visualize (Ase.Atoms object)\n", - " index: The index of the material\n", - " number_of_repetitions: The number of unit cell repetitions to visualize\n", - " \"\"\"\n", - " # Set the number of unit cell repetition for the structure to make it easier to see\n", - " n = number_of_repetitions\n", - " material_repeat = make_supercell(material, [[n,0,0],[0,n,0],[0,0,n]])\n", - " filename = f\"material-{index}.png\"\n", - " write(filename, material_repeat)\n", - " img = Image(filename=filename)\n", - " print(filename, \"-\", material.symbols)\n", - " display(img)\n", - "\n", - "for idx, material in enumerate(materials):\n", - " visualize_material(material, idx)" - ] - }, - { - "cell_type": "markdown", - "id": "a4a48479c7ea090f", - "metadata": {}, - "source": [ - "## 4. Pass data to the outside runtime" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "00b187ab", - "metadata": {}, - "outputs": [], - "source": [ - "from jupyterlite.utils import set_data\n", - "\n", - "output_materials = esse_entries\n", - "set_data(\"materials\", output_materials)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": ".venv", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.4" - }, - "widgets": { - "application/vnd.jupyter.widget-state+json": { - "state": {}, - "version_major": 2, - "version_minor": 0 - } - } + "cells": [ + { + "cell_type": "markdown", + "id": "826fcc4c", + "metadata": {}, + "source": [ + "# Import 2D material from JARVIS database\n", + "\n", + "Import a structure from the NIST JARVIS database by its ID. Use data at JARVIS-DFT to find the ID of the structure you are interested in.\n", + "\n", + "

Usage

\n", + "\n", + "1. Set Input Parameters (e.g. `JARVIS_ID`) below or use the default value\n", + "1. Click \"Run\" > \"Run All Cells\" to run all cells\n", + "1. Wait for the run to complete (it should take ~30 sec first time to install packages). Scroll down to view cell results.\n", + "\n", + "## Methodology\n", + "\n", + "The following happens in the script below:\n", + "\n", + "1. Install `express-py` alongside the necessary packages\n", + "2. Import the material from JARVIS database\n", + "3. Convert the material to ESSE format\n", + "4. Pass the material to the outside runtime" + ] }, - "nbformat": 4, - "nbformat_minor": 5 + { + "cell_type": "markdown", + "id": "4299768d", + "metadata": {}, + "source": [ + "## 1. Set Parameters" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "9c1f4e9e", + "metadata": {}, + "outputs": [], + "source": [ + "# Note: JVASP-670 is an entry for MoTe2 and JVASP-6838 is an entry for GaTe\n", + "JARVIS_IDS = [\n", + " \"JVASP-670\",\n", + " \"JVASP-6838\",\n", + "]" + ] + }, + { + "cell_type": "markdown", + "id": "8b00ab6854f2263b", + "metadata": {}, + "source": [ + "## 2. Install Packages" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ef2b38a5-de7e-419e-b605-110e9e0095f5", + "metadata": { + "trusted": true + }, + "outputs": [], + "source": [ + "import os\n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " import micropip\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + "from utils.jupyterlite import install_packages\n", + "await install_packages(\"import_material_from_jarvis_db_entry.ipynb\",\"../../config.yml\")" + ] + }, + { + "cell_type": "markdown", + "id": "f418c51a7f794f9f", + "metadata": {}, + "source": [ + "## 3. Data Processing\n", + "\n", + "### 3.1. Get data and wrap it in dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b1ee775d1476f884", + "metadata": { + "collapsed": false, + "trusted": true + }, + "outputs": [], + "source": [ + "import pandas as pd\n", + "from jarvis.db.figshare import data\n", + "\n", + "dft_2d = data(\"dft_2d\")\n", + "dft_3d = data(\"dft_3d\")\n", + "dataframe_2d = pd.DataFrame(dft_2d)\n", + "dataframe_3d = pd.DataFrame(dft_3d)\n", + "dataframe= pd.concat([dataframe_2d, dataframe_3d])" + ] + }, + { + "cell_type": "markdown", + "id": "57b0d358", + "metadata": {}, + "source": [ + "### 3.2. Preview the dataframe" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0e34472a", + "metadata": {}, + "outputs": [], + "source": [ + "dataframe" + ] + }, + { + "cell_type": "markdown", + "id": "15fe5f9de299c935", + "metadata": {}, + "source": [ + "### 3.3. Filter data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a771a36a", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "from express import ExPrESS\n", + "\n", + "dataframe_entries_for_jarvis_ids = dataframe[(dataframe[\"jid\"].isin(JARVIS_IDS))]\n", + "dataframe_entries_as_json = dataframe_entries_for_jarvis_ids.to_json(orient=\"records\")\n", + "jarvis_db_entries = json.loads(dataframe_entries_as_json)" + ] + }, + { + "cell_type": "markdown", + "id": "ef5f9e9d", + "metadata": {}, + "source": [ + "### 3.4. Convert to ESSE format" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c41fb68c6d25fe48", + "metadata": { + "collapsed": false, + "trusted": true + }, + "outputs": [], + "source": [ + "def convert_jarvis_entry_to_esse(jarvis_db_entry):\n", + " jarvis_db_entry_json = json.dumps(jarvis_db_entry)\n", + " kwargs = {\n", + " \"structure_string\": jarvis_db_entry_json,\n", + " \"cell_type\": \"original\",\n", + " \"structure_format\": \"jarvis-db-entry\",\n", + " }\n", + " handler = ExPrESS(\"structure\", **kwargs)\n", + " esse = handler.property(\"material\", **kwargs)\n", + " poscar = handler.parser.jarvis_db_entry_json_to_poscar(jarvis_db_entry_json)\n", + " return (esse, poscar)\n", + "\n", + "esse_entries = list(map(lambda e: convert_jarvis_entry_to_esse(e)[0], jarvis_db_entries))\n", + "poscars = list(map(lambda e: convert_jarvis_entry_to_esse(e)[1], jarvis_db_entries))" + ] + }, + { + "cell_type": "markdown", + "id": "8770ec48", + "metadata": {}, + "source": [ + "### 3.5. Preview the data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "860b5c1b", + "metadata": {}, + "outputs": [], + "source": [ + "from src.utils import poscar_to_ase\n", + "from ase.visualize import view\n", + "from ase.io import write\n", + "from ase.build import make_supercell\n", + "from IPython.display import Image\n", + "\n", + "# Uncomment to see the JSON\n", + "# print(json.dumps(data, indent=4))\n", + "\n", + "\n", + "materials = list(map(lambda p: poscar_to_ase(p), poscars))\n", + "\n", + "def visualize_material(material, index: int, number_of_repetitions: int = 3):\n", + " \"\"\"\n", + " Visualize the material using ASE's visualization tool\n", + " Repeat the unit cell to make it easier to see.\n", + "\n", + " Args:\n", + " material: The material to visualize (Ase.Atoms object)\n", + " index: The index of the material\n", + " number_of_repetitions: The number of unit cell repetitions to visualize\n", + " \"\"\"\n", + " # Set the number of unit cell repetition for the structure to make it easier to see\n", + " n = number_of_repetitions\n", + " material_repeat = make_supercell(material, [[n,0,0],[0,n,0],[0,0,n]])\n", + " filename = f\"material-{index}.png\"\n", + " write(filename, material_repeat)\n", + " img = Image(filename=filename)\n", + " print(filename, \"-\", material.symbols)\n", + " display(img)\n", + "\n", + "for idx, material in enumerate(materials):\n", + " visualize_material(material, idx)" + ] + }, + { + "cell_type": "markdown", + "id": "a4a48479c7ea090f", + "metadata": {}, + "source": [ + "## 4. Pass data to the outside runtime" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "00b187ab", + "metadata": {}, + "outputs": [], + "source": [ + "from jupyterlite.utils import set_data\n", + "\n", + "output_materials = esse_entries\n", + "set_data(\"materials\", output_materials)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.4" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 } diff --git a/other/materials_designer/import_materials_from_files.ipynb b/other/materials_designer/import_materials_from_files.ipynb index 369baac9..04fbd017 100644 --- a/other/materials_designer/import_materials_from_files.ipynb +++ b/other/materials_designer/import_materials_from_files.ipynb @@ -70,9 +70,12 @@ }, "outputs": [], "source": [ - "from jupyterlite.utils import install_packages\n", - "\n", - "await install_packages(\"import_materials_from_files.ipynb\")" + "import os\n", + "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + " import micropip\n", + " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + "from utils.jupyterlite import install_packages\n", + "await install_packages(\"import_materials_from_files.ipynb\",\"../../config.yml\")" ] }, { From 7b4ea10de742392914ea89fb2881e9a78bda1e0f Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:25:03 -0700 Subject: [PATCH 14/29] update: adjust jl/md notebooks imports of utils --- .../create_interface_with_min_strain_zsl.ipynb | 4 ++-- .../create_interface_with_relaxation_ase_emt.ipynb | 4 ++-- .../import_material_from_jarvis_db_entry.ipynb | 2 +- other/materials_designer/import_materials_from_files.ipynb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/other/materials_designer/create_interface_with_min_strain_zsl.ipynb b/other/materials_designer/create_interface_with_min_strain_zsl.ipynb index c53a8a10..907c35bc 100644 --- a/other/materials_designer/create_interface_with_min_strain_zsl.ipynb +++ b/other/materials_designer/create_interface_with_min_strain_zsl.ipynb @@ -135,7 +135,7 @@ "cell_type": "code", "outputs": [], "source": [ - "from jupyterlite.utils import get_data\n", + "from utils.jupyterlite import get_data\n", "from pymatgen.analysis.structure_analyzer import SpacegroupAnalyzer\n", "from src.utils import to_pymatgen\n", "\n", @@ -434,7 +434,7 @@ "outputs": [], "source": [ "from src.utils import from_pymatgen\n", - "from jupyterlite.utils import set_data\n", + "from utils.jupyterlite import set_data\n", "\n", "materials = list(map(lambda interface_config: from_pymatgen(interface_config[\"interface\"]), selected_interfaces))\n", "\n", diff --git a/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb b/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb index d56d9654..ae98fdab 100644 --- a/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb +++ b/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb @@ -143,7 +143,7 @@ "cell_type": "code", "outputs": [], "source": [ - "from jupyterlite.utils import get_data\n", + "from utils.jupyterlite import get_data\n", "from pymatgen.analysis.structure_analyzer import SpacegroupAnalyzer\n", "from src.utils import to_pymatgen\n", "\n", @@ -692,7 +692,7 @@ "metadata": {}, "outputs": [], "source": [ - "from jupyterlite.utils import set_data\n", + "from utils.jupyterlite import set_data\n", "from src.utils import from_pymatgen\n", "\n", "esse_final_interface = from_pymatgen(ase_to_pymatgen(ase_final_interface))\n", diff --git a/other/materials_designer/import_material_from_jarvis_db_entry.ipynb b/other/materials_designer/import_material_from_jarvis_db_entry.ipynb index f7e6c881..7a88a3a6 100644 --- a/other/materials_designer/import_material_from_jarvis_db_entry.ipynb +++ b/other/materials_designer/import_material_from_jarvis_db_entry.ipynb @@ -242,7 +242,7 @@ "metadata": {}, "outputs": [], "source": [ - "from jupyterlite.utils import set_data\n", + "from utils.jupyterlite import set_data\n", "\n", "output_materials = esse_entries\n", "set_data(\"materials\", output_materials)" diff --git a/other/materials_designer/import_materials_from_files.ipynb b/other/materials_designer/import_materials_from_files.ipynb index 04fbd017..f4103f85 100644 --- a/other/materials_designer/import_materials_from_files.ipynb +++ b/other/materials_designer/import_materials_from_files.ipynb @@ -262,7 +262,7 @@ "metadata": {}, "outputs": [], "source": [ - "from jupyterlite.utils import set_data\n", + "from utils.jupyterlite import set_data\n", "\n", "output_materials = esse_entries\n", "set_data(\"materials\", output_materials)" From 6193236bdc1ef843e4cdabaffb5c26c542f733a2 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:32:24 -0700 Subject: [PATCH 15/29] update: rename package to pypi --- examples/job/create_and_submit_job.ipynb | 2 +- examples/job/get-file-from-job.ipynb | 2 +- examples/job/ml-train-model-predict-properties.ipynb | 2 +- examples/job/run-simulations-and-extract-properties.ipynb | 2 +- examples/material/api_interoperability_showcase.ipynb | 2 +- examples/material/create_material.ipynb | 2 +- examples/material/get_materials_by_formula.ipynb | 2 +- examples/material/import_materials_from_materialsproject.ipynb | 2 +- examples/material/upload_materials_from_file_poscar.ipynb | 2 +- examples/workflow/get_workflows.ipynb | 2 +- examples/workflow/qe_scf_calculation.ipynb | 2 +- .../create_interface_with_min_strain_zsl.ipynb | 2 +- .../create_interface_with_relaxation_ase_emt.ipynb | 2 +- .../import_material_from_jarvis_db_entry.ipynb | 2 +- other/materials_designer/import_materials_from_files.ipynb | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/job/create_and_submit_job.ipynb b/examples/job/create_and_submit_job.ipynb index 3a385dde..264ba1cd 100644 --- a/examples/job/create_and_submit_job.ipynb +++ b/examples/job/create_and_submit_job.ipynb @@ -94,7 +94,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/job/get-file-from-job.ipynb b/examples/job/get-file-from-job.ipynb index 90b0c363..8124b57e 100644 --- a/examples/job/get-file-from-job.ipynb +++ b/examples/job/get-file-from-job.ipynb @@ -116,7 +116,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/job/ml-train-model-predict-properties.ipynb b/examples/job/ml-train-model-predict-properties.ipynb index f4a5eb19..7bff848c 100644 --- a/examples/job/ml-train-model-predict-properties.ipynb +++ b/examples/job/ml-train-model-predict-properties.ipynb @@ -116,7 +116,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/job/run-simulations-and-extract-properties.ipynb b/examples/job/run-simulations-and-extract-properties.ipynb index 422dd6e4..3e5c69b9 100644 --- a/examples/job/run-simulations-and-extract-properties.ipynb +++ b/examples/job/run-simulations-and-extract-properties.ipynb @@ -123,7 +123,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/material/api_interoperability_showcase.ipynb b/examples/material/api_interoperability_showcase.ipynb index 09a67eb3..a461c94f 100644 --- a/examples/material/api_interoperability_showcase.ipynb +++ b/examples/material/api_interoperability_showcase.ipynb @@ -94,7 +94,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"api_interoperability_showcase.ipynb\",\"../../config.yml\")" diff --git a/examples/material/create_material.ipynb b/examples/material/create_material.ipynb index 5027152e..bbdbe539 100644 --- a/examples/material/create_material.ipynb +++ b/examples/material/create_material.ipynb @@ -89,7 +89,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/material/get_materials_by_formula.ipynb b/examples/material/get_materials_by_formula.ipynb index 3c952bed..0eff922b 100644 --- a/examples/material/get_materials_by_formula.ipynb +++ b/examples/material/get_materials_by_formula.ipynb @@ -90,7 +90,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/material/import_materials_from_materialsproject.ipynb b/examples/material/import_materials_from_materialsproject.ipynb index a8104c34..ad566c57 100644 --- a/examples/material/import_materials_from_materialsproject.ipynb +++ b/examples/material/import_materials_from_materialsproject.ipynb @@ -90,7 +90,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/material/upload_materials_from_file_poscar.ipynb b/examples/material/upload_materials_from_file_poscar.ipynb index 45a976ed..9767cada 100644 --- a/examples/material/upload_materials_from_file_poscar.ipynb +++ b/examples/material/upload_materials_from_file_poscar.ipynb @@ -93,7 +93,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/workflow/get_workflows.ipynb b/examples/workflow/get_workflows.ipynb index 66e59cef..ab3d1a1b 100644 --- a/examples/workflow/get_workflows.ipynb +++ b/examples/workflow/get_workflows.ipynb @@ -94,7 +94,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/examples/workflow/qe_scf_calculation.ipynb b/examples/workflow/qe_scf_calculation.ipynb index ac1b736d..f9f472d7 100644 --- a/examples/workflow/qe_scf_calculation.ipynb +++ b/examples/workflow/qe_scf_calculation.ipynb @@ -89,7 +89,7 @@ " )\n", " \n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", " await install_packages(\"\",\"../../config.yml\")" diff --git a/other/materials_designer/create_interface_with_min_strain_zsl.ipynb b/other/materials_designer/create_interface_with_min_strain_zsl.ipynb index 907c35bc..1bb91655 100644 --- a/other/materials_designer/create_interface_with_min_strain_zsl.ipynb +++ b/other/materials_designer/create_interface_with_min_strain_zsl.ipynb @@ -119,7 +119,7 @@ "import os\n", "if \"/home/pyodide\" in os.environ.get('HOME'):\n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", "from utils.jupyterlite import install_packages\n", "await install_packages(\"create_interface_with_min_strain_zsl.ipynb\",\"../../config.yml\")" ] diff --git a/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb b/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb index ae98fdab..f98f209c 100644 --- a/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb +++ b/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb @@ -125,7 +125,7 @@ "import os\n", "if \"/home/pyodide\" in os.environ.get('HOME'):\n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", "from utils.jupyterlite import install_packages\n", "await install_packages(\"create_interface_with_min_strain_zsl.ipynb\",\"../../config.yml\")" ] diff --git a/other/materials_designer/import_material_from_jarvis_db_entry.ipynb b/other/materials_designer/import_material_from_jarvis_db_entry.ipynb index 7a88a3a6..0a9f4cd0 100644 --- a/other/materials_designer/import_material_from_jarvis_db_entry.ipynb +++ b/other/materials_designer/import_material_from_jarvis_db_entry.ipynb @@ -67,7 +67,7 @@ "import os\n", "if \"/home/pyodide\" in os.environ.get('HOME'):\n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", "from utils.jupyterlite import install_packages\n", "await install_packages(\"import_material_from_jarvis_db_entry.ipynb\",\"../../config.yml\")" ] diff --git a/other/materials_designer/import_materials_from_files.ipynb b/other/materials_designer/import_materials_from_files.ipynb index f4103f85..c2e8112b 100644 --- a/other/materials_designer/import_materials_from_files.ipynb +++ b/other/materials_designer/import_materials_from_files.ipynb @@ -73,7 +73,7 @@ "import os\n", "if \"/home/pyodide\" in os.environ.get('HOME'):\n", " import micropip\n", - " await micropip.install('http://localhost:8080/mat3ra_api_examples-2024.3.30.post4.dev10+g7b57fef-py3-none-any.whl', deps=False)\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", "from utils.jupyterlite import install_packages\n", "await install_packages(\"import_materials_from_files.ipynb\",\"../../config.yml\")" ] From 1fc8bfc514317fbce392b97883ec7d8c249b0cbe Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 1 Apr 2024 21:04:16 -0700 Subject: [PATCH 16/29] chore: move non-working notebook to other --- README.md | 2 +- ...port_materials_from_materialsproject.ipynb | 222 ------------------ .../import_materials_from_materialsproject.py | 93 -------- 3 files changed, 1 insertion(+), 316 deletions(-) delete mode 100644 examples/material/import_materials_from_materialsproject.ipynb delete mode 100644 examples/material/import_materials_from_materialsproject.py diff --git a/README.md b/README.md index 58c482a8..11f39a12 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Below, we list the contents of this repository, in roughly the order that a user | [Examples/Workflow](examples/workflow/) | [Quantum Espresso Workflow and Job](examples/workflow/qe_scf_calculation.ipynb) | Create Quantum Espresso workflow starting from QE input file; create and submit job; after the job is finished, download output file, and finally perform postprocessing analysis. | [Examples/Material](examples/material/) | [Get Materials by Formula](examples/material/get_materials_by_formula.ipynb) | Shows how [queries](https://docs.mat3ra.com/rest-api/query-structure/) can be made to search for materials stored on your account by their formula. In this example, we search for a system containing Si. | [Examples/Material](examples/material/) | [Create Material](examples/material/create_material.ipynb) | Gives an overview of how materials can be generated in [JSON format](https://docs.mat3ra.com/materials/data/) and uploaded to your user account. In this example, we create an FCC Si crystal and upload it. -| [Examples/Material](examples/material/) | [Import Materials from Materials Project](examples/material/import_materials_from_materialsproject.ipynb) | Demonstrates how materials can be imported from [Materials Project](https://materialsproject.org/about), if their Materials Project ID is known. In this example, we import monoclinic and hexagonal SiGe cells. +| [Examples/Material](examples/material/) | [Import Materials from Materials Project](other/materialsproject/import_materials_from_materialsproject.ipynb) | Demonstrates how materials can be imported from [Materials Project](https://materialsproject.org/about), if their Materials Project ID is known. In this example, we import monoclinic and hexagonal SiGe cells. | [Examples/Material](examples/material/) | [Import Materials from Poscar](examples/material/upload_materials_from_file_poscar.ipynb) | Provides an example of how materials can be imported directly from Poscar files (a common chemical file format best-known [for its use in VASP](https://www.vasp.at/wiki/index.php/Input)). In this example, we import the unit cell of SiGe. | [Examples/Material](examples/material/) | [Interoperability between Mat3ra and Materials Project](examples/material/api_interoperability_showcase.ipynb) | In this notebook, we showcase a major advantage of APIs: interoperability. We begin by performing a query using the [Materials Project](https://materialsproject.org) API for all systems containing Iron and Oxygen. We then filter our results (for demonstraiton purposes, we keep only the first 10 materials found). Finally, we upload our results to the Mat3ra platform, where further calculations could be performed to characterize these materials. | [Examples/Job](examples/job/) | [Create and Submit Job](examples/job/create_and_submit_job.ipynb) | Shows how to use the Mat3ra API to [create jobs](https://docs.mat3ra.com/jobs/data/) and run them on our cluster. In this example, we run a DFT calculation to get the total energy of an FCC Si unit cell using Quantum Espresso. diff --git a/examples/material/import_materials_from_materialsproject.ipynb b/examples/material/import_materials_from_materialsproject.ipynb deleted file mode 100644 index ad566c57..00000000 --- a/examples/material/import_materials_from_materialsproject.ipynb +++ /dev/null @@ -1,222 +0,0 @@ -{ - "cells": [ - { - "attachments": {}, - "cell_type": "markdown", - "metadata": { - "id": "y_SM_JBc9vrV" - }, - "source": [ - "\n", - "\"Open\n", - "" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": { - "id": "amffxwKY9vrX" - }, - "source": [ - "# Overview\n", - "\n", - "This example demonstrates how to import materials from the materials project database via [Material](https://docs.mat3ra.com/api/Material/post_materials_import) endpoint." - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": { - "id": "c-nHvPSy9vrY" - }, - "source": [ - "# Complete Authorization Form and Initialize Settings\n", - "\n", - "This will also determine environment and set all environment variables. We determine if we are using Jupyter Notebooks or Google Colab to run this tutorial.\n", - "\n", - "If you are running this notebook from Google Colab, Colab takes ~1 min to execute the following cell.\n", - "\n", - "ACCOUNT_ID and AUTH_TOKEN - Authentication parameters needed for when making requests to [Mat3ra.com's API Endpoints](https://docs.mat3ra.com/rest-api/endpoints/).\n", - "\n", - "MATERIALS_PROJECT_API_KEY - Authentication parameter needed for when making requests to [Material Project's API](https://materialsproject.org/open)\n", - "\n", - "ORGANIZATION_ID - Authentication parameter needed for when working with collaborative accounts https://docs.mat3ra.com/collaboration/organizations/overview/\n", - "\n", - "> **NOTE**: If you are running this notebook from Jupyter, the variables ACCOUNT_ID, AUTH_TOKEN, MATERIALS_PROJECT_API_KEY, and ORGANIZATION_ID should be set in the file [settings.json](../../utils/settings.json) if you need to use these variables. To obtain API token parameters, please see the following link to the documentation explaining how to get them: https://docs.mat3ra.com/accounts/ui/preferences/api/" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "6KqWoLdv9vrY" - }, - "outputs": [], - "source": [ - "# @title Authorization Form\n", - "ACCOUNT_ID = \"ACCOUNT_ID\" # @param {type:\"string\"}\n", - "AUTH_TOKEN = \"AUTH_TOKEN\" # @param {type:\"string\"}\n", - "MATERIALS_PROJECT_API_KEY = \"MATERIALS_PROJECT_API_KEY\" # @param {type:\"string\"}\n", - "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", - "\n", - "import os\n", - "\n", - "if \"COLAB_JUPYTER_IP\" in os.environ:\n", - " os.environ.update(\n", - " dict(\n", - " ACCOUNT_ID=ACCOUNT_ID,\n", - " AUTH_TOKEN=AUTH_TOKEN,\n", - " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", - " ORGANIZATION_ID=ORGANIZATION_ID,\n", - " )\n", - " )\n", - "\n", - " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", - "\n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", - " apiConfig = data_from_host.get(\"apiConfig\")\n", - " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", - " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", - " os.environ.update(\n", - " dict(\n", - " ACCOUNT_ID=ACCOUNT_ID,\n", - " AUTH_TOKEN=AUTH_TOKEN,\n", - " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", - " ORGANIZATION_ID=ORGANIZATION_ID,\n", - " )\n", - " )\n", - " \n", - " import micropip\n", - " await micropip.install('mat3ra-api-examples', deps=False)\n", - " await micropip.install(\"exabyte-api-client\")\n", - " from utils.jupyterlite import install_packages\n", - " await install_packages(\"\",\"../../config.yml\")" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": { - "id": "5wAnsWE-9vrZ" - }, - "source": [ - "# Imports" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "e9EGeIkg9vrZ" - }, - "outputs": [], - "source": [ - "from utils.settings import ENDPOINT_ARGS, MATERIALS_PROJECT_API_KEY\n", - "from utils.generic import display_JSON\n", - "\n", - "from exabyte_api_client.endpoints.materials import MaterialEndpoints" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": { - "id": "C2Dxa1qZ9vra" - }, - "source": [ - "## Set Parameters\n", - "\n", - "- **MATERIALS_PROJECT_IDS**: a list of material IDs to be imported\n", - "\n", - "- **TAGS**: a list of [tags](https://docs.mat3ra.com/entities-general/data/#tags) to assign to imported materials" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "6xpZA6M_9vra" - }, - "outputs": [], - "source": [ - "MATERIALS_PROJECT_IDS = [\"mp-978534\", \"mp-1096549\"]\n", - "TAGS = [\"tag1\", \"tag2\"]" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": { - "id": "11YzfvYk9vrb" - }, - "source": [ - "## Import materials\n", - "\n", - "Initialize `MaterialEndpoints` class and call `import_from_materialsproject` function to import materials." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "Ar05ANgq9vrb" - }, - "outputs": [], - "source": [ - "endpoint = MaterialEndpoints(*ENDPOINT_ARGS)\n", - "materials = endpoint.import_from_materialsproject(MATERIALS_PROJECT_API_KEY, MATERIALS_PROJECT_IDS, tags=TAGS)" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": { - "id": "DPMW1MDy9vrc" - }, - "source": [ - "## Print imported materials\n", - "\n", - "Print the list of imported materials in pretty JSON below." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "n7WgbbkJ9vrc" - }, - "outputs": [], - "source": [ - "display_JSON(materials)" - ] - } - ], - "metadata": { - "colab": { - "name": "import_materials_from_materialsproject.ipynb", - "provenance": [] - }, - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.6" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} diff --git a/examples/material/import_materials_from_materialsproject.py b/examples/material/import_materials_from_materialsproject.py deleted file mode 100644 index 2952c4f0..00000000 --- a/examples/material/import_materials_from_materialsproject.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# -# Open in Google Colab -# - -# # Overview -# -# This example demonstrates how to import materials from the materials project database via [Material](https://docs.mat3ra.com/api/Material/post_materials_import) endpoint. - -# # Complete Authorization Form and Initialize Settings -# -# This will also determine environment and set all environment variables. We determine if we are using Jupyter Notebooks or Google Colab to run this tutorial. -# -# If you are running this notebook from Google Colab, Colab takes ~1 min to execute the following cell. -# -# ACCOUNT_ID and AUTH_TOKEN - Authentication parameters needed for when making requests to [Mat3ra.com's API Endpoints](https://docs.mat3ra.com/rest-api/endpoints/). -# -# MATERIALS_PROJECT_API_KEY - Authentication parameter needed for when making requests to [Material Project's API](https://materialsproject.org/open) -# -# ORGANIZATION_ID - Authentication parameter needed for when working with collaborative accounts https://docs.mat3ra.com/collaboration/organizations/overview/ -# -# > **NOTE**: If you are running this notebook from Jupyter, the variables ACCOUNT_ID, AUTH_TOKEN, MATERIALS_PROJECT_API_KEY, and ORGANIZATION_ID should be set in the file [settings.json](../../utils/settings.json) if you need to use these variables. To obtain API token parameters, please see the following link to the documentation explaining how to get them: https://docs.mat3ra.com/accounts/ui/preferences/api/ - -# In[ ]: - - -# @title Authorization Form -ACCOUNT_ID = "ACCOUNT_ID" # @param {type:"string"} -AUTH_TOKEN = "AUTH_TOKEN" # @param {type:"string"} -MATERIALS_PROJECT_API_KEY = "MATERIALS_PROJECT_API_KEY" # @param {type:"string"} -ORGANIZATION_ID = "ORGANIZATION_ID" # @param {type:"string"} - -import os - -if "COLAB_JUPYTER_IP" in os.environ: - os.environ.update( - dict( - ACCOUNT_ID=ACCOUNT_ID, - AUTH_TOKEN=AUTH_TOKEN, - MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY, - ORGANIZATION_ID=ORGANIZATION_ID, - ) - ) - - get_ipython().system('GIT_BRANCH="dev"; export GIT_BRANCH; curl -s "https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh" | bash') - - -# # Imports - -# In[ ]: - - -from utils.settings import ENDPOINT_ARGS, MATERIALS_PROJECT_API_KEY -from utils.generic import display_JSON - -from exabyte_api_client.endpoints.materials import MaterialEndpoints - - -# ## Set Parameters -# -# - **MATERIALS_PROJECT_IDS**: a list of material IDs to be imported -# -# - **TAGS**: a list of [tags](https://docs.mat3ra.com/entities-general/data/#tags) to assign to imported materials - -# In[ ]: - - -MATERIALS_PROJECT_IDS = ["mp-978534", "mp-1096549"] -TAGS = ["tag1", "tag2"] - - -# ## Import materials -# -# Initialize `MaterialEndpoints` class and call `import_from_materialsproject` function to import materials. - -# In[ ]: - - -endpoint = MaterialEndpoints(*ENDPOINT_ARGS) -materials = endpoint.import_from_materialsproject(MATERIALS_PROJECT_API_KEY, MATERIALS_PROJECT_IDS, tags=TAGS) - - -# ## Print imported materials -# -# Print the list of imported materials in pretty JSON below. - -# In[ ]: - - -display_JSON(materials) - From f41951bc39a70168b3781538294d967cb8bbcbd6 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 1 Apr 2024 21:04:38 -0700 Subject: [PATCH 17/29] update: read endpoint args from environment --- utils/settings.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/settings.py b/utils/settings.py index aef87561..da0552b0 100644 --- a/utils/settings.py +++ b/utils/settings.py @@ -49,8 +49,8 @@ # VERSION: RESTFul API version. Defaults to 2018-10-01. # SECURE: Whether to use secure connection. Defaults to True. -PORT = 443 -SECURE = True -VERSION = "2018-10-01" -HOST = "platform.mat3ra.com" +PORT = os.environ.get("API_PORT", 443) +SECURE = os.environ.get("API_SECURE") != "false" +VERSION = os.environ.get("API_VERSION", "2018-10-01") +HOST = os.environ.get("API_HOST", "platform.mat3ra.com") ENDPOINT_ARGS = [HOST, PORT, ACCOUNT_ID, AUTH_TOKEN, VERSION, SECURE] From 0f91ee82db38bd63b230405f945bcb6543f0b39c Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:28:59 -0700 Subject: [PATCH 18/29] chore: adjust notebook --- examples/material/api_interoperability_showcase.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/material/api_interoperability_showcase.ipynb b/examples/material/api_interoperability_showcase.ipynb index a461c94f..40f5d7f5 100644 --- a/examples/material/api_interoperability_showcase.ipynb +++ b/examples/material/api_interoperability_showcase.ipynb @@ -66,6 +66,7 @@ "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", "\n", "import os\n", + "import sys\n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", " os.environ.update(\n", @@ -79,7 +80,7 @@ "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", "\n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", From 7e123f9d153dd4e0ccd7cc4193cf8d7924bd6d63 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:58:13 -0700 Subject: [PATCH 19/29] chore: adjust notebooks --- examples/job/create_and_submit_job.ipynb | 3 ++- examples/job/get-file-from-job.ipynb | 3 ++- examples/job/ml-train-model-predict-properties.ipynb | 3 ++- examples/job/run-simulations-and-extract-properties.ipynb | 3 ++- examples/material/create_material.ipynb | 3 ++- examples/material/get_materials_by_formula.ipynb | 3 ++- examples/material/upload_materials_from_file_poscar.ipynb | 3 ++- examples/workflow/get_workflows.ipynb | 3 ++- examples/workflow/qe_scf_calculation.ipynb | 3 ++- 9 files changed, 18 insertions(+), 9 deletions(-) diff --git a/examples/job/create_and_submit_job.ipynb b/examples/job/create_and_submit_job.ipynb index 264ba1cd..d005a987 100644 --- a/examples/job/create_and_submit_job.ipynb +++ b/examples/job/create_and_submit_job.ipynb @@ -66,6 +66,7 @@ "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", "\n", "import os\n", + "import sys\n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", " os.environ.update(\n", @@ -79,7 +80,7 @@ "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", " \n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", diff --git a/examples/job/get-file-from-job.ipynb b/examples/job/get-file-from-job.ipynb index 8124b57e..6efbe3f3 100644 --- a/examples/job/get-file-from-job.ipynb +++ b/examples/job/get-file-from-job.ipynb @@ -88,6 +88,7 @@ "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", "\n", "import os\n", + "import sys\n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", " os.environ.update(\n", @@ -101,7 +102,7 @@ "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", " \n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", diff --git a/examples/job/ml-train-model-predict-properties.ipynb b/examples/job/ml-train-model-predict-properties.ipynb index 7bff848c..ba4dbe28 100644 --- a/examples/job/ml-train-model-predict-properties.ipynb +++ b/examples/job/ml-train-model-predict-properties.ipynb @@ -88,6 +88,7 @@ "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", "\n", "import os\n", + "import sys\n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", " os.environ.update(\n", @@ -101,7 +102,7 @@ "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", " \n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", diff --git a/examples/job/run-simulations-and-extract-properties.ipynb b/examples/job/run-simulations-and-extract-properties.ipynb index 3e5c69b9..89b5bace 100644 --- a/examples/job/run-simulations-and-extract-properties.ipynb +++ b/examples/job/run-simulations-and-extract-properties.ipynb @@ -95,6 +95,7 @@ "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", "\n", "import os\n", + "import sys\n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", " os.environ.update(\n", @@ -108,7 +109,7 @@ "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", " \n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", diff --git a/examples/material/create_material.ipynb b/examples/material/create_material.ipynb index bbdbe539..72ed5346 100644 --- a/examples/material/create_material.ipynb +++ b/examples/material/create_material.ipynb @@ -61,6 +61,7 @@ "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", "\n", "import os\n", + "import sys\n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", " os.environ.update(\n", @@ -74,7 +75,7 @@ "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", "\n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", diff --git a/examples/material/get_materials_by_formula.ipynb b/examples/material/get_materials_by_formula.ipynb index 0eff922b..c8e7d9a2 100644 --- a/examples/material/get_materials_by_formula.ipynb +++ b/examples/material/get_materials_by_formula.ipynb @@ -62,6 +62,7 @@ "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", "\n", "import os\n", + "import sys\n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", " os.environ.update(\n", @@ -75,7 +76,7 @@ "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", "\n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", diff --git a/examples/material/upload_materials_from_file_poscar.ipynb b/examples/material/upload_materials_from_file_poscar.ipynb index 9767cada..3de33335 100644 --- a/examples/material/upload_materials_from_file_poscar.ipynb +++ b/examples/material/upload_materials_from_file_poscar.ipynb @@ -62,6 +62,7 @@ "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", "\n", "import os\n", + "import sys \n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", " os.environ.update(\n", @@ -78,7 +79,7 @@ "\n", " os.chdir(os.path.join(\"api-examples\", os.path.dirname(get_notebook_info()[\"notebook_path\"])))\n", "\n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", diff --git a/examples/workflow/get_workflows.ipynb b/examples/workflow/get_workflows.ipynb index ab3d1a1b..063f495a 100644 --- a/examples/workflow/get_workflows.ipynb +++ b/examples/workflow/get_workflows.ipynb @@ -66,6 +66,7 @@ "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", "\n", "import os\n", + "import sys \n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", " os.environ.update(\n", @@ -79,7 +80,7 @@ "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", " \n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", diff --git a/examples/workflow/qe_scf_calculation.ipynb b/examples/workflow/qe_scf_calculation.ipynb index f9f472d7..82cd64db 100644 --- a/examples/workflow/qe_scf_calculation.ipynb +++ b/examples/workflow/qe_scf_calculation.ipynb @@ -61,6 +61,7 @@ "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", "\n", "import os\n", + "import sys\n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", " os.environ.update(\n", @@ -74,7 +75,7 @@ "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", " \n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", From a53c9b97b4ff2ea1852448893e2ee37485a7d04f Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 2 Apr 2024 12:44:32 -0700 Subject: [PATCH 20/29] update: remove unused nb --- config.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/config.yml b/config.yml index 15195519..50a51ee4 100644 --- a/config.yml +++ b/config.yml @@ -52,9 +52,3 @@ notebooks: packages_pyodide: - https://files.mat3ra.com:44318/uploads/paginate-0.5.6-py3-none-any.whl - https://files.mat3ra.com:44318/uploads/watchdog-2.3.1-py3-none-any.whl - - name: api_interoperability_showcase.ipynb - packages_pyodide: - - mp_api==0.31.1 - - mpcontribs-client - - tqdm - - plotly \ No newline at end of file From 792b18fa626e1b217cd2dba5cbce565486d2aa50 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 2 Apr 2024 12:44:59 -0700 Subject: [PATCH 21/29] update: pass environ from webapp --- examples/material/create_material.ipynb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/material/create_material.ipynb b/examples/material/create_material.ipynb index 72ed5346..1e4b3108 100644 --- a/examples/material/create_material.ipynb +++ b/examples/material/create_material.ipynb @@ -77,15 +77,13 @@ "\n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", - " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", - " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(data_from_host.get(\"environ\", {}))\n", " os.environ.update(\n", " dict(\n", - " ACCOUNT_ID=ACCOUNT_ID,\n", - " AUTH_TOKEN=AUTH_TOKEN,\n", + " ACCOUNT_ID=apiConfig.get(\"accountId\"),\n", + " AUTH_TOKEN=apiConfig.get(\"authToken\"),\n", " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", - " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", " \n", From efa0836d7b1b80f968df31cd78ee51a83281bca0 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 2 Apr 2024 12:50:05 -0700 Subject: [PATCH 22/29] update: pass environ from webapp to all nbs --- examples/job/create_and_submit_job.ipynb | 10 ++++------ examples/job/get-file-from-job.ipynb | 10 ++++------ examples/job/ml-train-model-predict-properties.ipynb | 10 ++++------ .../job/run-simulations-and-extract-properties.ipynb | 10 ++++------ examples/material/get_materials_by_formula.ipynb | 10 ++++------ .../material/upload_materials_from_file_poscar.ipynb | 10 ++++------ examples/workflow/get_workflows.ipynb | 10 ++++------ examples/workflow/qe_scf_calculation.ipynb | 10 ++++------ 8 files changed, 32 insertions(+), 48 deletions(-) diff --git a/examples/job/create_and_submit_job.ipynb b/examples/job/create_and_submit_job.ipynb index d005a987..6d8b4077 100644 --- a/examples/job/create_and_submit_job.ipynb +++ b/examples/job/create_and_submit_job.ipynb @@ -82,15 +82,13 @@ " \n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", - " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", - " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(data_from_host.get(\"environ\", {}))\n", " os.environ.update(\n", " dict(\n", - " ACCOUNT_ID=ACCOUNT_ID,\n", - " AUTH_TOKEN=AUTH_TOKEN,\n", + " ACCOUNT_ID=apiConfig.get(\"accountId\"),\n", + " AUTH_TOKEN=apiConfig.get(\"authToken\"),\n", " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", - " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", " \n", diff --git a/examples/job/get-file-from-job.ipynb b/examples/job/get-file-from-job.ipynb index 6efbe3f3..a1c8db0a 100644 --- a/examples/job/get-file-from-job.ipynb +++ b/examples/job/get-file-from-job.ipynb @@ -104,15 +104,13 @@ " \n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", - " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", - " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(data_from_host.get(\"environ\", {}))\n", " os.environ.update(\n", " dict(\n", - " ACCOUNT_ID=ACCOUNT_ID,\n", - " AUTH_TOKEN=AUTH_TOKEN,\n", + " ACCOUNT_ID=apiConfig.get(\"accountId\"),\n", + " AUTH_TOKEN=apiConfig.get(\"authToken\"),\n", " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", - " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", " \n", diff --git a/examples/job/ml-train-model-predict-properties.ipynb b/examples/job/ml-train-model-predict-properties.ipynb index ba4dbe28..32e84260 100644 --- a/examples/job/ml-train-model-predict-properties.ipynb +++ b/examples/job/ml-train-model-predict-properties.ipynb @@ -104,15 +104,13 @@ " \n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", - " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", - " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(data_from_host.get(\"environ\", {}))\n", " os.environ.update(\n", " dict(\n", - " ACCOUNT_ID=ACCOUNT_ID,\n", - " AUTH_TOKEN=AUTH_TOKEN,\n", + " ACCOUNT_ID=apiConfig.get(\"accountId\"),\n", + " AUTH_TOKEN=apiConfig.get(\"authToken\"),\n", " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", - " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", " \n", diff --git a/examples/job/run-simulations-and-extract-properties.ipynb b/examples/job/run-simulations-and-extract-properties.ipynb index 89b5bace..f0801c44 100644 --- a/examples/job/run-simulations-and-extract-properties.ipynb +++ b/examples/job/run-simulations-and-extract-properties.ipynb @@ -111,15 +111,13 @@ " \n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", - " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", - " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(data_from_host.get(\"environ\", {}))\n", " os.environ.update(\n", " dict(\n", - " ACCOUNT_ID=ACCOUNT_ID,\n", - " AUTH_TOKEN=AUTH_TOKEN,\n", + " ACCOUNT_ID=apiConfig.get(\"accountId\"),\n", + " AUTH_TOKEN=apiConfig.get(\"authToken\"),\n", " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", - " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", " \n", diff --git a/examples/material/get_materials_by_formula.ipynb b/examples/material/get_materials_by_formula.ipynb index c8e7d9a2..35d81c07 100644 --- a/examples/material/get_materials_by_formula.ipynb +++ b/examples/material/get_materials_by_formula.ipynb @@ -78,15 +78,13 @@ "\n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", - " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", - " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(data_from_host.get(\"environ\", {}))\n", " os.environ.update(\n", " dict(\n", - " ACCOUNT_ID=ACCOUNT_ID,\n", - " AUTH_TOKEN=AUTH_TOKEN,\n", + " ACCOUNT_ID=apiConfig.get(\"accountId\"),\n", + " AUTH_TOKEN=apiConfig.get(\"authToken\"),\n", " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", - " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", " \n", diff --git a/examples/material/upload_materials_from_file_poscar.ipynb b/examples/material/upload_materials_from_file_poscar.ipynb index 3de33335..4dba92a6 100644 --- a/examples/material/upload_materials_from_file_poscar.ipynb +++ b/examples/material/upload_materials_from_file_poscar.ipynb @@ -81,15 +81,13 @@ "\n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", - " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", - " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(data_from_host.get(\"environ\", {}))\n", " os.environ.update(\n", " dict(\n", - " ACCOUNT_ID=ACCOUNT_ID,\n", - " AUTH_TOKEN=AUTH_TOKEN,\n", + " ACCOUNT_ID=apiConfig.get(\"accountId\"),\n", + " AUTH_TOKEN=apiConfig.get(\"authToken\"),\n", " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", - " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", " \n", diff --git a/examples/workflow/get_workflows.ipynb b/examples/workflow/get_workflows.ipynb index 063f495a..45697c66 100644 --- a/examples/workflow/get_workflows.ipynb +++ b/examples/workflow/get_workflows.ipynb @@ -82,15 +82,13 @@ " \n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", - " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", - " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(data_from_host.get(\"environ\", {}))\n", " os.environ.update(\n", " dict(\n", - " ACCOUNT_ID=ACCOUNT_ID,\n", - " AUTH_TOKEN=AUTH_TOKEN,\n", + " ACCOUNT_ID=apiConfig.get(\"accountId\"),\n", + " AUTH_TOKEN=apiConfig.get(\"authToken\"),\n", " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", - " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", " \n", diff --git a/examples/workflow/qe_scf_calculation.ipynb b/examples/workflow/qe_scf_calculation.ipynb index 82cd64db..52e6865d 100644 --- a/examples/workflow/qe_scf_calculation.ipynb +++ b/examples/workflow/qe_scf_calculation.ipynb @@ -77,15 +77,13 @@ " \n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", - " ACCOUNT_ID = apiConfig.get(\"accountId\")\n", - " AUTH_TOKEN = apiConfig.get(\"authToken\")\n", - " ORGANIZATION_ID = apiConfig.get(\"organizationId\") or \"\"\n", + " os.environ.update(data_from_host.get(\"environ\", {}))\n", " os.environ.update(\n", " dict(\n", - " ACCOUNT_ID=ACCOUNT_ID,\n", - " AUTH_TOKEN=AUTH_TOKEN,\n", + " ACCOUNT_ID=apiConfig.get(\"accountId\"),\n", + " AUTH_TOKEN=apiConfig.get(\"authToken\"),\n", " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", - " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", " \n", From 8f96aed173764aa8dbdf4640f6a29e3aa16198dd Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 2 Apr 2024 12:53:23 -0700 Subject: [PATCH 23/29] update: change detection in jl nbs --- .../create_interface_with_min_strain_zsl.ipynb | 4 ++-- .../create_interface_with_relaxation_ase_emt.ipynb | 4 ++-- .../import_material_from_jarvis_db_entry.ipynb | 4 ++-- other/materials_designer/import_materials_from_files.ipynb | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/other/materials_designer/create_interface_with_min_strain_zsl.ipynb b/other/materials_designer/create_interface_with_min_strain_zsl.ipynb index 1bb91655..f79109e0 100644 --- a/other/materials_designer/create_interface_with_min_strain_zsl.ipynb +++ b/other/materials_designer/create_interface_with_min_strain_zsl.ipynb @@ -116,8 +116,8 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "import sys\n", + "if sys.platform == \"emscripten\":\n", " import micropip\n", " await micropip.install('mat3ra-api-examples', deps=False)\n", "from utils.jupyterlite import install_packages\n", diff --git a/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb b/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb index f98f209c..ab11390a 100644 --- a/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb +++ b/other/materials_designer/create_interface_with_relaxation_ase_emt.ipynb @@ -122,8 +122,8 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "import sys\n", + "if sys.platform == \"emscripten\":\n", " import micropip\n", " await micropip.install('mat3ra-api-examples', deps=False)\n", "from utils.jupyterlite import install_packages\n", diff --git a/other/materials_designer/import_material_from_jarvis_db_entry.ipynb b/other/materials_designer/import_material_from_jarvis_db_entry.ipynb index 0a9f4cd0..4fca8f10 100644 --- a/other/materials_designer/import_material_from_jarvis_db_entry.ipynb +++ b/other/materials_designer/import_material_from_jarvis_db_entry.ipynb @@ -64,8 +64,8 @@ }, "outputs": [], "source": [ - "import os\n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "import sys\n", + "if sys.platform == \"emscripten\":\n", " import micropip\n", " await micropip.install('mat3ra-api-examples', deps=False)\n", "from utils.jupyterlite import install_packages\n", diff --git a/other/materials_designer/import_materials_from_files.ipynb b/other/materials_designer/import_materials_from_files.ipynb index c2e8112b..7e207bd7 100644 --- a/other/materials_designer/import_materials_from_files.ipynb +++ b/other/materials_designer/import_materials_from_files.ipynb @@ -70,8 +70,8 @@ }, "outputs": [], "source": [ - "import os\n", - "if \"/home/pyodide\" in os.environ.get('HOME'):\n", + "import sys\n", + "if sys.platform == \"emscripten\":\n", " import micropip\n", " await micropip.install('mat3ra-api-examples', deps=False)\n", "from utils.jupyterlite import install_packages\n", From 25370d654ae6da68160673bc568eed33720d5d4d Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:28:23 -0700 Subject: [PATCH 24/29] update: adjust get auth nb --- .../system/get_authentication_params.ipynb | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/examples/system/get_authentication_params.ipynb b/examples/system/get_authentication_params.ipynb index 51ff4405..d4cacfbe 100644 --- a/examples/system/get_authentication_params.ipynb +++ b/examples/system/get_authentication_params.ipynb @@ -59,9 +59,27 @@ "PASSWORD = getpass(\"Please enter password: \")\n", "\n", "import os\n", + "import sys\n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", - " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n" + " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", + "\n", + "if sys.platform == \"emscripten\":\n", + " apiConfig = data_from_host.get(\"apiConfig\")\n", + " os.environ.update(data_from_host.get(\"environ\", {}))\n", + " os.environ.update(\n", + " dict(\n", + " ACCOUNT_ID=apiConfig.get(\"accountId\"),\n", + " AUTH_TOKEN=apiConfig.get(\"authToken\"),\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", + " )\n", + " )\n", + " \n", + " import micropip\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", + " await micropip.install(\"exabyte-api-client\")\n", + " from utils.jupyterlite import install_packages\n", + " await install_packages(\"\",\"../../config.yml\")" ] }, { From 129414b826751f93294af77901ccfffcd15d1c67 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:05:25 -0700 Subject: [PATCH 25/29] chore: isort --- utils/jupyterlite.py | 3 ++- wheel_server.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/jupyterlite.py b/utils/jupyterlite.py index 98e49388..9ed6d6ef 100644 --- a/utils/jupyterlite.py +++ b/utils/jupyterlite.py @@ -1,8 +1,9 @@ -from IPython.display import display, Javascript import json import os from enum import Enum +from IPython.display import Javascript, display + UPLOADS_FOLDER = "uploads" diff --git a/wheel_server.py b/wheel_server.py index 55c06048..b2580ee0 100644 --- a/wheel_server.py +++ b/wheel_server.py @@ -4,8 +4,8 @@ # The server will be available at http://localhost:8080, use micropip in pyodide to install wheel from that URL, i.e: # await micropip.install("http://localhost:8080/mat3ra_api_examples-2024.3.30.post2-py3-none-any.whl", deps=False) -from http.server import HTTPServer, SimpleHTTPRequestHandler import os +from http.server import HTTPServer, SimpleHTTPRequestHandler class CORSHTTPRequestHandler(SimpleHTTPRequestHandler): From d413ec3061e7c3eacdd8c90cc1eea4f391b89ecf Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Wed, 3 Apr 2024 10:06:21 -0700 Subject: [PATCH 26/29] chore: format with black --- examples/job/create_and_submit_job.ipynb | 10 ++++++---- examples/job/get-file-from-job.ipynb | 10 ++++++---- examples/job/ml-train-model-predict-properties.ipynb | 10 ++++++---- .../job/run-simulations-and-extract-properties.ipynb | 10 ++++++---- examples/material/create_material.ipynb | 8 +++++--- examples/material/get_materials_by_formula.ipynb | 8 +++++--- .../material/upload_materials_from_file_poscar.ipynb | 10 ++++++---- examples/system/get_authentication_params.ipynb | 8 +++++--- examples/workflow/get_workflows.ipynb | 12 +++++++----- examples/workflow/qe_scf_calculation.ipynb | 10 ++++++---- 10 files changed, 58 insertions(+), 38 deletions(-) diff --git a/examples/job/create_and_submit_job.ipynb b/examples/job/create_and_submit_job.ipynb index 6d8b4077..c23581f0 100644 --- a/examples/job/create_and_submit_job.ipynb +++ b/examples/job/create_and_submit_job.ipynb @@ -79,7 +79,7 @@ " )\n", "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", - " \n", + "\n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " os.environ.update(data_from_host.get(\"environ\", {}))\n", @@ -91,12 +91,14 @@ " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", - " \n", + "\n", " import micropip\n", - " await micropip.install('mat3ra-api-examples', deps=False)\n", + "\n", + " await micropip.install(\"mat3ra-api-examples\", deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", - " await install_packages(\"\",\"../../config.yml\")" + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { diff --git a/examples/job/get-file-from-job.ipynb b/examples/job/get-file-from-job.ipynb index a1c8db0a..dcc5e80f 100644 --- a/examples/job/get-file-from-job.ipynb +++ b/examples/job/get-file-from-job.ipynb @@ -101,7 +101,7 @@ " )\n", "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", - " \n", + "\n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " os.environ.update(data_from_host.get(\"environ\", {}))\n", @@ -113,12 +113,14 @@ " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", - " \n", + "\n", " import micropip\n", - " await micropip.install('mat3ra-api-examples', deps=False)\n", + "\n", + " await micropip.install(\"mat3ra-api-examples\", deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", - " await install_packages(\"\",\"../../config.yml\")" + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { diff --git a/examples/job/ml-train-model-predict-properties.ipynb b/examples/job/ml-train-model-predict-properties.ipynb index 32e84260..022ec1ee 100644 --- a/examples/job/ml-train-model-predict-properties.ipynb +++ b/examples/job/ml-train-model-predict-properties.ipynb @@ -101,7 +101,7 @@ " )\n", "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", - " \n", + "\n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " os.environ.update(data_from_host.get(\"environ\", {}))\n", @@ -113,12 +113,14 @@ " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", - " \n", + "\n", " import micropip\n", - " await micropip.install('mat3ra-api-examples', deps=False)\n", + "\n", + " await micropip.install(\"mat3ra-api-examples\", deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", - " await install_packages(\"\",\"../../config.yml\")" + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { diff --git a/examples/job/run-simulations-and-extract-properties.ipynb b/examples/job/run-simulations-and-extract-properties.ipynb index f0801c44..d162191c 100644 --- a/examples/job/run-simulations-and-extract-properties.ipynb +++ b/examples/job/run-simulations-and-extract-properties.ipynb @@ -108,7 +108,7 @@ " )\n", "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", - " \n", + "\n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " os.environ.update(data_from_host.get(\"environ\", {}))\n", @@ -120,12 +120,14 @@ " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", - " \n", + "\n", " import micropip\n", - " await micropip.install('mat3ra-api-examples', deps=False)\n", + "\n", + " await micropip.install(\"mat3ra-api-examples\", deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", - " await install_packages(\"\",\"../../config.yml\")" + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { diff --git a/examples/material/create_material.ipynb b/examples/material/create_material.ipynb index 1e4b3108..bae57ad7 100644 --- a/examples/material/create_material.ipynb +++ b/examples/material/create_material.ipynb @@ -86,12 +86,14 @@ " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", - " \n", + "\n", " import micropip\n", - " await micropip.install('mat3ra-api-examples', deps=False)\n", + "\n", + " await micropip.install(\"mat3ra-api-examples\", deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", - " await install_packages(\"\",\"../../config.yml\")" + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { diff --git a/examples/material/get_materials_by_formula.ipynb b/examples/material/get_materials_by_formula.ipynb index 35d81c07..2125b821 100644 --- a/examples/material/get_materials_by_formula.ipynb +++ b/examples/material/get_materials_by_formula.ipynb @@ -87,12 +87,14 @@ " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", - " \n", + "\n", " import micropip\n", - " await micropip.install('mat3ra-api-examples', deps=False)\n", + "\n", + " await micropip.install(\"mat3ra-api-examples\", deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", - " await install_packages(\"\",\"../../config.yml\")" + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { diff --git a/examples/material/upload_materials_from_file_poscar.ipynb b/examples/material/upload_materials_from_file_poscar.ipynb index 4dba92a6..563dcf3f 100644 --- a/examples/material/upload_materials_from_file_poscar.ipynb +++ b/examples/material/upload_materials_from_file_poscar.ipynb @@ -62,7 +62,7 @@ "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", "\n", "import os\n", - "import sys \n", + "import sys\n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", " os.environ.update(\n", @@ -90,12 +90,14 @@ " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", - " \n", + "\n", " import micropip\n", - " await micropip.install('mat3ra-api-examples', deps=False)\n", + "\n", + " await micropip.install(\"mat3ra-api-examples\", deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", - " await install_packages(\"\",\"../../config.yml\")" + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { diff --git a/examples/system/get_authentication_params.ipynb b/examples/system/get_authentication_params.ipynb index d4cacfbe..ca6a7ba0 100644 --- a/examples/system/get_authentication_params.ipynb +++ b/examples/system/get_authentication_params.ipynb @@ -74,12 +74,14 @@ " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", - " \n", + "\n", " import micropip\n", - " await micropip.install('mat3ra-api-examples', deps=False)\n", + "\n", + " await micropip.install(\"mat3ra-api-examples\", deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", - " await install_packages(\"\",\"../../config.yml\")" + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { diff --git a/examples/workflow/get_workflows.ipynb b/examples/workflow/get_workflows.ipynb index 45697c66..b52e41b8 100644 --- a/examples/workflow/get_workflows.ipynb +++ b/examples/workflow/get_workflows.ipynb @@ -66,7 +66,7 @@ "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", "\n", "import os\n", - "import sys \n", + "import sys\n", "\n", "if \"COLAB_JUPYTER_IP\" in os.environ:\n", " os.environ.update(\n", @@ -79,7 +79,7 @@ " )\n", "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", - " \n", + "\n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " os.environ.update(data_from_host.get(\"environ\", {}))\n", @@ -91,12 +91,14 @@ " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", - " \n", + "\n", " import micropip\n", - " await micropip.install('mat3ra-api-examples', deps=False)\n", + "\n", + " await micropip.install(\"mat3ra-api-examples\", deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", - " await install_packages(\"\",\"../../config.yml\")" + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { diff --git a/examples/workflow/qe_scf_calculation.ipynb b/examples/workflow/qe_scf_calculation.ipynb index 52e6865d..c4966141 100644 --- a/examples/workflow/qe_scf_calculation.ipynb +++ b/examples/workflow/qe_scf_calculation.ipynb @@ -74,7 +74,7 @@ " )\n", "\n", " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash\n", - " \n", + "\n", "if sys.platform == \"emscripten\":\n", " apiConfig = data_from_host.get(\"apiConfig\")\n", " os.environ.update(data_from_host.get(\"environ\", {}))\n", @@ -86,12 +86,14 @@ " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", " )\n", " )\n", - " \n", + "\n", " import micropip\n", - " await micropip.install('mat3ra-api-examples', deps=False)\n", + "\n", + " await micropip.install(\"mat3ra-api-examples\", deps=False)\n", " await micropip.install(\"exabyte-api-client\")\n", " from utils.jupyterlite import install_packages\n", - " await install_packages(\"\",\"../../config.yml\")" + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { From fcff330f22678e099c03c8e2074251484d116838 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Wed, 3 Apr 2024 11:18:16 -0700 Subject: [PATCH 27/29] chore: add explanation --- utils/jupyterlite.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/jupyterlite.py b/utils/jupyterlite.py index 9ed6d6ef..a69ede46 100644 --- a/utils/jupyterlite.py +++ b/utils/jupyterlite.py @@ -61,6 +61,7 @@ async def install_packages(notebook_name, requirements_path="config.yml", verbos """ if ENVIRONMENT == EnvironmentEnum.PYODIDE: await micropip.install("pyyaml") + # PyYAML has to be installed before being imported in Pyodide and can't appear at the top of the file import yaml base_path = os.getcwd() From 6a29573d801e68e96a1caa974431a308912228fc Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Wed, 3 Apr 2024 11:18:38 -0700 Subject: [PATCH 28/29] chore: silence mypy issue --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index d64f835a..33f3b57e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -83,3 +83,7 @@ target-version = "py38" profile = "black" multi_line_output = 3 include_trailing_comma = true + +[[tool.mypy.overrides]] +module = "yaml" +ignore_missing_imports = true From b205cdd3f210a89d8a137a8c50df7023f0136fde Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Wed, 3 Apr 2024 11:25:43 -0700 Subject: [PATCH 29/29] chore: move non-working nb --- other/materialsproject/__init__.py | 0 ...port_materials_from_materialsproject.ipynb | 202 ++++++++++++++++++ .../import_materials_from_materialsproject.py | 93 ++++++++ 3 files changed, 295 insertions(+) create mode 100644 other/materialsproject/__init__.py create mode 100644 other/materialsproject/import_materials_from_materialsproject.ipynb create mode 100644 other/materialsproject/import_materials_from_materialsproject.py diff --git a/other/materialsproject/__init__.py b/other/materialsproject/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/other/materialsproject/import_materials_from_materialsproject.ipynb b/other/materialsproject/import_materials_from_materialsproject.ipynb new file mode 100644 index 00000000..880324c4 --- /dev/null +++ b/other/materialsproject/import_materials_from_materialsproject.ipynb @@ -0,0 +1,202 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "y_SM_JBc9vrV" + }, + "source": [ + "\n", + "\"Open\n", + "" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "amffxwKY9vrX" + }, + "source": [ + "# Overview\n", + "\n", + "This example demonstrates how to import materials from the materials project database via [Material](https://docs.mat3ra.com/api/Material/post_materials_import) endpoint." + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "c-nHvPSy9vrY" + }, + "source": [ + "# Complete Authorization Form and Initialize Settings\n", + "\n", + "This will also determine environment and set all environment variables. We determine if we are using Jupyter Notebooks or Google Colab to run this tutorial.\n", + "\n", + "If you are running this notebook from Google Colab, Colab takes ~1 min to execute the following cell.\n", + "\n", + "ACCOUNT_ID and AUTH_TOKEN - Authentication parameters needed for when making requests to [Mat3ra.com's API Endpoints](https://docs.mat3ra.com/rest-api/endpoints/).\n", + "\n", + "MATERIALS_PROJECT_API_KEY - Authentication parameter needed for when making requests to [Material Project's API](https://materialsproject.org/open)\n", + "\n", + "ORGANIZATION_ID - Authentication parameter needed for when working with collaborative accounts https://docs.mat3ra.com/collaboration/organizations/overview/\n", + "\n", + "> **NOTE**: If you are running this notebook from Jupyter, the variables ACCOUNT_ID, AUTH_TOKEN, MATERIALS_PROJECT_API_KEY, and ORGANIZATION_ID should be set in the file [settings.json](../../utils/settings.json) if you need to use these variables. To obtain API token parameters, please see the following link to the documentation explaining how to get them: https://docs.mat3ra.com/accounts/ui/preferences/api/" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "6KqWoLdv9vrY" + }, + "outputs": [], + "source": [ + "# @title Authorization Form\n", + "ACCOUNT_ID = \"ACCOUNT_ID\" # @param {type:\"string\"}\n", + "AUTH_TOKEN = \"AUTH_TOKEN\" # @param {type:\"string\"}\n", + "MATERIALS_PROJECT_API_KEY = \"MATERIALS_PROJECT_API_KEY\" # @param {type:\"string\"}\n", + "ORGANIZATION_ID = \"ORGANIZATION_ID\" # @param {type:\"string\"}\n", + "\n", + "import os\n", + "\n", + "if \"COLAB_JUPYTER_IP\" in os.environ:\n", + " os.environ.update(\n", + " dict(\n", + " ACCOUNT_ID=ACCOUNT_ID,\n", + " AUTH_TOKEN=AUTH_TOKEN,\n", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=ORGANIZATION_ID,\n", + " )\n", + " )\n", + "\n", + " !GIT_BRANCH=\"dev\"; export GIT_BRANCH; curl -s \"https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh\" | bash" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "5wAnsWE-9vrZ" + }, + "source": [ + "# Imports" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "e9EGeIkg9vrZ" + }, + "outputs": [], + "source": [ + "from utils.settings import ENDPOINT_ARGS, MATERIALS_PROJECT_API_KEY\n", + "from utils.generic import display_JSON\n", + "\n", + "from exabyte_api_client.endpoints.materials import MaterialEndpoints" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "C2Dxa1qZ9vra" + }, + "source": [ + "## Set Parameters\n", + "\n", + "- **MATERIALS_PROJECT_IDS**: a list of material IDs to be imported\n", + "\n", + "- **TAGS**: a list of [tags](https://docs.mat3ra.com/entities-general/data/#tags) to assign to imported materials" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "6xpZA6M_9vra" + }, + "outputs": [], + "source": [ + "MATERIALS_PROJECT_IDS = [\"mp-978534\", \"mp-1096549\"]\n", + "TAGS = [\"tag1\", \"tag2\"]" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "11YzfvYk9vrb" + }, + "source": [ + "## Import materials\n", + "\n", + "Initialize `MaterialEndpoints` class and call `import_from_materialsproject` function to import materials." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Ar05ANgq9vrb" + }, + "outputs": [], + "source": [ + "endpoint = MaterialEndpoints(*ENDPOINT_ARGS)\n", + "materials = endpoint.import_from_materialsproject(MATERIALS_PROJECT_API_KEY, MATERIALS_PROJECT_IDS, tags=TAGS)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "DPMW1MDy9vrc" + }, + "source": [ + "## Print imported materials\n", + "\n", + "Print the list of imported materials in pretty JSON below." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "n7WgbbkJ9vrc" + }, + "outputs": [], + "source": [ + "display_JSON(materials)" + ] + } + ], + "metadata": { + "colab": { + "name": "import_materials_from_materialsproject.ipynb", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.6" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/other/materialsproject/import_materials_from_materialsproject.py b/other/materialsproject/import_materials_from_materialsproject.py new file mode 100644 index 00000000..2952c4f0 --- /dev/null +++ b/other/materialsproject/import_materials_from_materialsproject.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +# coding: utf-8 + +# +# Open in Google Colab +# + +# # Overview +# +# This example demonstrates how to import materials from the materials project database via [Material](https://docs.mat3ra.com/api/Material/post_materials_import) endpoint. + +# # Complete Authorization Form and Initialize Settings +# +# This will also determine environment and set all environment variables. We determine if we are using Jupyter Notebooks or Google Colab to run this tutorial. +# +# If you are running this notebook from Google Colab, Colab takes ~1 min to execute the following cell. +# +# ACCOUNT_ID and AUTH_TOKEN - Authentication parameters needed for when making requests to [Mat3ra.com's API Endpoints](https://docs.mat3ra.com/rest-api/endpoints/). +# +# MATERIALS_PROJECT_API_KEY - Authentication parameter needed for when making requests to [Material Project's API](https://materialsproject.org/open) +# +# ORGANIZATION_ID - Authentication parameter needed for when working with collaborative accounts https://docs.mat3ra.com/collaboration/organizations/overview/ +# +# > **NOTE**: If you are running this notebook from Jupyter, the variables ACCOUNT_ID, AUTH_TOKEN, MATERIALS_PROJECT_API_KEY, and ORGANIZATION_ID should be set in the file [settings.json](../../utils/settings.json) if you need to use these variables. To obtain API token parameters, please see the following link to the documentation explaining how to get them: https://docs.mat3ra.com/accounts/ui/preferences/api/ + +# In[ ]: + + +# @title Authorization Form +ACCOUNT_ID = "ACCOUNT_ID" # @param {type:"string"} +AUTH_TOKEN = "AUTH_TOKEN" # @param {type:"string"} +MATERIALS_PROJECT_API_KEY = "MATERIALS_PROJECT_API_KEY" # @param {type:"string"} +ORGANIZATION_ID = "ORGANIZATION_ID" # @param {type:"string"} + +import os + +if "COLAB_JUPYTER_IP" in os.environ: + os.environ.update( + dict( + ACCOUNT_ID=ACCOUNT_ID, + AUTH_TOKEN=AUTH_TOKEN, + MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY, + ORGANIZATION_ID=ORGANIZATION_ID, + ) + ) + + get_ipython().system('GIT_BRANCH="dev"; export GIT_BRANCH; curl -s "https://raw.githubusercontent.com/Exabyte-io/api-examples/${GIT_BRANCH}/scripts/env.sh" | bash') + + +# # Imports + +# In[ ]: + + +from utils.settings import ENDPOINT_ARGS, MATERIALS_PROJECT_API_KEY +from utils.generic import display_JSON + +from exabyte_api_client.endpoints.materials import MaterialEndpoints + + +# ## Set Parameters +# +# - **MATERIALS_PROJECT_IDS**: a list of material IDs to be imported +# +# - **TAGS**: a list of [tags](https://docs.mat3ra.com/entities-general/data/#tags) to assign to imported materials + +# In[ ]: + + +MATERIALS_PROJECT_IDS = ["mp-978534", "mp-1096549"] +TAGS = ["tag1", "tag2"] + + +# ## Import materials +# +# Initialize `MaterialEndpoints` class and call `import_from_materialsproject` function to import materials. + +# In[ ]: + + +endpoint = MaterialEndpoints(*ENDPOINT_ARGS) +materials = endpoint.import_from_materialsproject(MATERIALS_PROJECT_API_KEY, MATERIALS_PROJECT_IDS, tags=TAGS) + + +# ## Print imported materials +# +# Print the list of imported materials in pretty JSON below. + +# In[ ]: + + +display_JSON(materials) +