diff --git a/README.md b/README.md index de998104..9e229eb6 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/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. | [Examples/Job](examples/job/) | [Get File from Job](examples/job/get-file-from-job.ipynb) | Uses the Mat3ra API to query for a list of files produced by a job, describes the metadata assigned to each file, and ends by demonstrating how to download any remote file generated by a job to the local disk. diff --git a/other/materials_designer/config.yml b/config.yml similarity index 96% rename from other/materials_designer/config.yml rename to config.yml index 2aebc396..50a51ee4 100644 --- a/other/materials_designer/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 + - jinja2 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 diff --git a/examples/job/create_and_submit_job.ipynb b/examples/job/create_and_submit_job.ipynb index 7a9d8535..c23581f0 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", @@ -77,7 +78,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 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", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", + " )\n", + " )\n", + "\n", + " import micropip\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", + "\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..dcc5e80f 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", @@ -99,7 +100,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 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", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", + " )\n", + " )\n", + "\n", + " import micropip\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", + "\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..022ec1ee 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", @@ -99,7 +100,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 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", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", + " )\n", + " )\n", + "\n", + " import micropip\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", + "\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..d162191c 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", @@ -106,7 +107,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 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", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", + " )\n", + " )\n", + "\n", + " import micropip\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", + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { diff --git a/examples/material/create_material.ipynb b/examples/material/create_material.ipynb index a7c2a9e2..bae57ad7 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", @@ -72,7 +73,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 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", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", + " )\n", + " )\n", + "\n", + " import micropip\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", + "\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 b2a80275..2125b821 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", @@ -73,7 +74,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 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", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", + " )\n", + " )\n", + "\n", + " import micropip\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", + "\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 b4c1bdb8..563dcf3f 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", @@ -76,7 +77,27 @@ " !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 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", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", + " )\n", + " )\n", + "\n", + " import micropip\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", + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { diff --git a/examples/system/get_authentication_params.ipynb b/examples/system/get_authentication_params.ipynb index e8b49cff..ca6a7ba0 100644 --- a/examples/system/get_authentication_params.ipynb +++ b/examples/system/get_authentication_params.ipynb @@ -59,9 +59,29 @@ "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" + " !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", + "\n", + " await micropip.install(\"mat3ra-api-examples\", deps=False)\n", + " await micropip.install(\"exabyte-api-client\")\n", + " from utils.jupyterlite import install_packages\n", + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { diff --git a/examples/workflow/get_workflows.ipynb b/examples/workflow/get_workflows.ipynb index 637150bb..b52e41b8 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", @@ -77,7 +78,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 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", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", + " )\n", + " )\n", + "\n", + " import micropip\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", + "\n", + " await install_packages(\"\", \"../../config.yml\")" ] }, { diff --git a/examples/workflow/qe_scf_calculation.ipynb b/examples/workflow/qe_scf_calculation.ipynb index d6edd70b..c4966141 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", @@ -72,7 +73,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 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", + " MATERIALS_PROJECT_API_KEY=MATERIALS_PROJECT_API_KEY,\n", + " ORGANIZATION_ID=apiConfig.get(\"organizationId\") or \"\",\n", + " )\n", + " )\n", + "\n", + " import micropip\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", + "\n", + " await install_packages(\"\", \"../../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/create_interface_with_min_strain_zsl.ipynb b/other/materials_designer/create_interface_with_min_strain_zsl.ipynb index c02b225b..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,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 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", + "await install_packages(\"create_interface_with_min_strain_zsl.ipynb\",\"../../config.yml\")" ] }, { @@ -132,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", @@ -431,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 8f8f5474..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,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 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", + "await install_packages(\"create_interface_with_min_strain_zsl.ipynb\",\"../../config.yml\")" ] }, { @@ -140,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", @@ -689,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 52c72dae..4fca8f10 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 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", + "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 utils.jupyterlite 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..7e207bd7 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 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", + "await install_packages(\"import_materials_from_files.ipynb\",\"../../config.yml\")" ] }, { @@ -259,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)" 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/materialsproject/__init__.py b/other/materialsproject/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/other/materialsproject/api_interoperability_showcase.ipynb b/other/materialsproject/api_interoperability_showcase.ipynb index 0396a645..40f5d7f5 100644 --- a/other/materialsproject/api_interoperability_showcase.ipynb +++ b/other/materialsproject/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", @@ -77,7 +78,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 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(\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(\"api_interoperability_showcase.ipynb\",\"../../config.yml\")" ] }, { diff --git a/examples/material/import_materials_from_materialsproject.ipynb b/other/materialsproject/import_materials_from_materialsproject.ipynb similarity index 100% rename from examples/material/import_materials_from_materialsproject.ipynb rename to other/materialsproject/import_materials_from_materialsproject.ipynb diff --git a/examples/material/import_materials_from_materialsproject.py b/other/materialsproject/import_materials_from_materialsproject.py similarity index 100% rename from examples/material/import_materials_from_materialsproject.py rename to other/materialsproject/import_materials_from_materialsproject.py 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 diff --git a/other/jupyterlite/utils.py b/utils/jupyterlite.py similarity index 93% rename from other/jupyterlite/utils.py rename to utils/jupyterlite.py index e133816b..a69ede46 100644 --- a/other/jupyterlite/utils.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" @@ -60,9 +61,16 @@ 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 - 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 @@ -82,7 +90,8 @@ async def install_packages(notebook_name, requirements_path="config.yml", verbos 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 = [] # Note: environment specific packages have to be installed first, # because in Pyodide common packages might depend on them 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] diff --git a/wheel_server.py b/wheel_server.py new file mode 100644 index 00000000..b2580ee0 --- /dev/null +++ b/wheel_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 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) + +import os +from http.server import HTTPServer, SimpleHTTPRequestHandler + + +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()