Skip to content

Prototype: Bandgap Workflow NB #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 200 additions & 0 deletions other/materials_designer/specific_examples/run_bandgap_workflow.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
{
"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",
"### 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": {
"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",
"# Log in to get the API token\n",
"auth_config = await ApiClient().login()"
],
"id": "23626cb27f6e7206",
"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": {},
"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",
"\n",
"material = load_material_from_folder(\"/uploads\", \"MoS2_twisted_interface_60_degrees.json\")\n",
"visualize(material)"
],
"id": "initial_id"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## 4. Import workflow builder and related analyzers",
"id": "f8d7e25a7c9cc2e"
},
{
"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": "markdown",
"source": "## 5. Get workflow and adjust its parameters",
"id": "9bdd00f870caaeeb"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"from mat3ra.wode.workflow.vasp.band_structure import BandStructureWorkflow\n",
"from mat3ra.wode.pseudopotentials import PseudopotentialEnum\n",
"\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"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## 6. Create the job configuration",
"id": "1f15e054ddb9a08c"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"from mat3ra.wode.compute import ComputeConfiguration, QueueEnum\n",
"compute_config = ComputeConfiguration(\n",
" queue = QueueEnum.OR8,\n",
" nodes = 1,\n",
" cores = 8,\n",
")"
],
"id": "60e880dc581dafe1"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## 7. Submit the job and monitor the status",
"id": "8d5740e099512107"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"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",
"# 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
}