From 9242fe6a84fadbb5bdea371c55db9fc05dc57a76 Mon Sep 17 00:00:00 2001 From: VsevolodX Date: Sun, 29 Jun 2025 22:13:10 -0700 Subject: [PATCH 1/3] update: bandgap nb prototype (wip) --- .../run_bandgap_workflow.ipynb | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 other/materials_designer/specific_examples/run_bandgap_workflow.ipynb diff --git a/other/materials_designer/specific_examples/run_bandgap_workflow.ipynb b/other/materials_designer/specific_examples/run_bandgap_workflow.ipynb new file mode 100644 index 00000000..5f536ff3 --- /dev/null +++ b/other/materials_designer/specific_examples/run_bandgap_workflow.ipynb @@ -0,0 +1,144 @@ +{ + "cells": [ + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "# Bandgap Workflow Example\n", + " This notebook demonstrates how to build and run a bandgap workflow for a material.\n", + "\n", + "## Process Overview\n", + "### 1. Set up the environment and parameters.\n", + "### 2. Load the target material.\n", + "### 3. Import workflow builder and related analyzers.\n", + "### 4. Analyze material to get parameters for the workflow configuration.\n", + "### 5. Create the workflow configuration.\n", + "### 6. Create a job with material and workflow configuration.\n", + "### 7. Log in to get the API token\n", + "### 8. Submit the job to the server.\n", + "### 9. Monitor the job status and retrieve results." + ], + "id": "ed24b225263ae3c3" + }, + { + "cell_type": "code", + "id": "initial_id", + "metadata": { + "collapsed": true + }, + "source": [ + "from utils.visualize import visualize_materials as visualize\n", + "from utils.jupyterlite import load_material_from_folder\n", + "\n", + "material = load_material_from_folder(\"/uploads\", \"MoS2_twisted_interface_60_degrees.json\")\n", + "visualize(material)" + ], + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "cell_type": "code", + "source": [ + "from mat3ra.api import ApiClient\n", + "# Log in to get the API token\n", + "auth_config = await ApiClient().login()" + ], + "id": "23626cb27f6e7206", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "cell_type": "code", + "outputs": [], + "execution_count": null, + "source": [ + "from mat3ra.wode.analyzers.electronic import KPointAnalyzer, CutoffAnalyzer, SmearingAnalyzer, BandsAnalyzer\n", + "\n", + "kpoint_analyzer = KPointAnalyzer(material=material)\n", + "cutoff_analyzer = CutoffAnalyzer(material=material)\n", + "smearing_analyzer = SmearingAnalyzer(material=material)\n", + "bands_analyzer = BandsAnalyzer(material=material)\n", + "\n", + "kpoints = kpoint_analyzer.get_kpoints()\n", + "cutoff = cutoff_analyzer.get_cutoff()\n", + "smearing = smearing_analyzer.get_smearing()\n", + "number_of_bands = bands_analyzer.get_number_of_bands()\n", + "\n" + ], + "id": "5ead702c417eff62" + }, + { + "metadata": {}, + "cell_type": "code", + "outputs": [], + "execution_count": null, + "source": [ + "from mat3ra.wode.workflow.vasp import create_vasp_workflow\n", + "\n", + "band_gap_workflow = create_vasp_workflow(\n", + " material=material,\n", + " kpoints=kpoints,\n", + " cutoff=cutoff,\n", + " smearing=smearing,\n", + " number_of_bands=number_of_bands)" + ], + "id": "68d43f6c797f2fc4" + }, + { + "metadata": {}, + "cell_type": "code", + "outputs": [], + "execution_count": null, + "source": [ + "from mat3ra.wode.compute import ComputeConfiguration, QueueTypes\n", + "compute_config = ComputeConfiguration(\n", + " queue = QueueTypes.OR8,\n", + " nodes = 1,\n", + " cores = 8,\n", + ")" + ], + "id": "60e880dc581dafe1" + }, + { + "metadata": {}, + "cell_type": "code", + "outputs": [], + "execution_count": null, + "source": [ + "from mat3ra.wode.job import JobConfiguration, create_job\n", + "job_config = JobConfiguration(workflow=band_gap_workflow, material=material, compute = compute_config)\n", + "job = create_job(job_config, auth_config=auth_config)\n", + "job.run()\n", + "job.wait_for_complete()\n", + "# job.check_status()\n", + "# job.get_current_output()\n", + "# AFTER Finished\n", + "job.get_results(PropertyEnum.BANDGAP)" + ], + "id": "53c8a2cd99e5c26d" + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 74069acfa25e64ad42a190db0f04387b84d2674e Mon Sep 17 00:00:00 2001 From: VsevolodX Date: Mon, 30 Jun 2025 10:14:47 -0700 Subject: [PATCH 2/3] update: add headers --- .../run_bandgap_workflow.ipynb | 89 ++++++++++++++----- 1 file changed, 66 insertions(+), 23 deletions(-) diff --git a/other/materials_designer/specific_examples/run_bandgap_workflow.ipynb b/other/materials_designer/specific_examples/run_bandgap_workflow.ipynb index 5f536ff3..1ba93db4 100644 --- a/other/materials_designer/specific_examples/run_bandgap_workflow.ipynb +++ b/other/materials_designer/specific_examples/run_bandgap_workflow.ipynb @@ -9,23 +9,54 @@ "\n", "## Process Overview\n", "### 1. Set up the environment and parameters.\n", - "### 2. Load the target material.\n", - "### 3. Import workflow builder and related analyzers.\n", - "### 4. Analyze material to get parameters for the workflow configuration.\n", - "### 5. Create the workflow configuration.\n", - "### 6. Create a job with material and workflow configuration.\n", - "### 7. Log in to get the API token\n", - "### 8. Submit the job to the server.\n", - "### 9. Monitor the job status and retrieve results." + "### 1. Log in to get the API token\n", + "### 1. Load the target material.\n", + "### 1. Import workflow builder and related analyzers.\n", + "### 1. Analyze material to get parameters for the workflow configuration.\n", + "### 1. Create the workflow configuration.\n", + "### 1. Create a job with material and workflow configuration.\n", + "### 1. Submit the job to the server.\n", + "### 1. Monitor the job status and retrieve results." ], "id": "ed24b225263ae3c3" }, { + "metadata": {}, + "cell_type": "markdown", + "source": "## 1. Set up the environment and parameters", + "id": "598da5f8c4f507ec" + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "## 2. Log in to get the API token", + "id": "51105b005c535ca" + }, + { + "metadata": {}, "cell_type": "code", - "id": "initial_id", + "source": [ + "from mat3ra.api import ApiClient\n", + "# Log in to get the API token\n", + "auth_config = await ApiClient().login()" + ], + "id": "23626cb27f6e7206", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "## 3. Load the target material", + "id": "ba816c64f28f6a3d" + }, + { "metadata": { "collapsed": true }, + "cell_type": "code", + "outputs": [], + "execution_count": null, "source": [ "from utils.visualize import visualize_materials as visualize\n", "from utils.jupyterlite import load_material_from_folder\n", @@ -33,20 +64,13 @@ "material = load_material_from_folder(\"/uploads\", \"MoS2_twisted_interface_60_degrees.json\")\n", "visualize(material)" ], - "outputs": [], - "execution_count": null + "id": "initial_id" }, { "metadata": {}, - "cell_type": "code", - "source": [ - "from mat3ra.api import ApiClient\n", - "# Log in to get the API token\n", - "auth_config = await ApiClient().login()" - ], - "id": "23626cb27f6e7206", - "outputs": [], - "execution_count": null + "cell_type": "markdown", + "source": "## 4. Import workflow builder and related analyzers", + "id": "f8d7e25a7c9cc2e" }, { "metadata": {}, @@ -69,23 +93,36 @@ ], "id": "5ead702c417eff62" }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "## 5. Create workflow", + "id": "9bdd00f870caaeeb" + }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": [ - "from mat3ra.wode.workflow.vasp import create_vasp_workflow\n", + "from mat3ra.wode.workflow.vasp.band_structure import create_band_structure_workflow\n", "\n", - "band_gap_workflow = create_vasp_workflow(\n", + "band_gap_workflow = create_band_structure_workflow(\n", " material=material,\n", " kpoints=kpoints,\n", " cutoff=cutoff,\n", " smearing=smearing,\n", - " number_of_bands=number_of_bands)" + " number_of_bands=number_of_bands\n", + ")" ], "id": "68d43f6c797f2fc4" }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "## 6. Create the job configuration", + "id": "1f15e054ddb9a08c" + }, { "metadata": {}, "cell_type": "code", @@ -101,6 +138,12 @@ ], "id": "60e880dc581dafe1" }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "## 7. Submit the job and monitor the status", + "id": "8d5740e099512107" + }, { "metadata": {}, "cell_type": "code", From 35aa49bdd778773cdf3df9b585a5bffe5d62a90c Mon Sep 17 00:00:00 2001 From: VsevolodX Date: Mon, 30 Jun 2025 14:00:05 -0700 Subject: [PATCH 3/3] update: set pseudo --- .../run_bandgap_workflow.ipynb | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/other/materials_designer/specific_examples/run_bandgap_workflow.ipynb b/other/materials_designer/specific_examples/run_bandgap_workflow.ipynb index 1ba93db4..2cc7efee 100644 --- a/other/materials_designer/specific_examples/run_bandgap_workflow.ipynb +++ b/other/materials_designer/specific_examples/run_bandgap_workflow.ipynb @@ -33,7 +33,12 @@ "id": "51105b005c535ca" }, { - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2025-06-30T17:49:35.443494Z", + "start_time": "2025-06-30T17:49:35.381267Z" + } + }, "cell_type": "code", "source": [ "from mat3ra.api import ApiClient\n", @@ -41,8 +46,20 @@ "auth_config = await ApiClient().login()" ], "id": "23626cb27f6e7206", - "outputs": [], - "execution_count": null + "outputs": [ + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'mat3ra.api'", + "output_type": "error", + "traceback": [ + "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", + "\u001B[0;31mModuleNotFoundError\u001B[0m Traceback (most recent call last)", + "Cell \u001B[0;32mIn[2], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mmat3ra\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mapi\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m ApiClient\n\u001B[1;32m 2\u001B[0m \u001B[38;5;66;03m# Log in to get the API token\u001B[39;00m\n\u001B[1;32m 3\u001B[0m auth_config \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mawait\u001B[39;00m ApiClient()\u001B[38;5;241m.\u001B[39mlogin()\n", + "\u001B[0;31mModuleNotFoundError\u001B[0m: No module named 'mat3ra.api'" + ] + } + ], + "execution_count": 2 }, { "metadata": {}, @@ -96,7 +113,7 @@ { "metadata": {}, "cell_type": "markdown", - "source": "## 5. Create workflow", + "source": "## 5. Get workflow and adjust its parameters", "id": "9bdd00f870caaeeb" }, { @@ -105,15 +122,12 @@ "outputs": [], "execution_count": null, "source": [ - "from mat3ra.wode.workflow.vasp.band_structure import create_band_structure_workflow\n", + "from mat3ra.wode.workflow.vasp.band_structure import BandStructureWorkflow\n", + "from mat3ra.wode.pseudopotentials import PseudopotentialEnum\n", "\n", - "band_gap_workflow = create_band_structure_workflow(\n", - " material=material,\n", - " kpoints=kpoints,\n", - " cutoff=cutoff,\n", - " smearing=smearing,\n", - " number_of_bands=number_of_bands\n", - ")" + "workflow = BandStructureWorkflow()\n", + "workflow.set_kpoints(kpoints)\n", + "workflow.set_pseudopotential(PseudopotentialEnum.PAW_HSE) # elements will be set automatically based on the material" ], "id": "68d43f6c797f2fc4" }, @@ -129,9 +143,9 @@ "outputs": [], "execution_count": null, "source": [ - "from mat3ra.wode.compute import ComputeConfiguration, QueueTypes\n", + "from mat3ra.wode.compute import ComputeConfiguration, QueueEnum\n", "compute_config = ComputeConfiguration(\n", - " queue = QueueTypes.OR8,\n", + " queue = QueueEnum.OR8,\n", " nodes = 1,\n", " cores = 8,\n", ")" @@ -150,9 +164,8 @@ "outputs": [], "execution_count": null, "source": [ - "from mat3ra.wode.job import JobConfiguration, create_job\n", - "job_config = JobConfiguration(workflow=band_gap_workflow, material=material, compute = compute_config)\n", - "job = create_job(job_config, auth_config=auth_config)\n", + "from mat3ra.wode.job import create_job\n", + "job = create_job(workflow=workflow, material=material, compute = compute_config, auth_config=auth_config)\n", "job.run()\n", "job.wait_for_complete()\n", "# job.check_status()\n",