diff --git a/other/job/vbo_build_mock.ipynb b/other/job/vbo_build_mock.ipynb new file mode 100644 index 00000000..92f96df9 --- /dev/null +++ b/other/job/vbo_build_mock.ipynb @@ -0,0 +1,480 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "initial_id", + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Valence bands offset calculation for GaAs/AlAs interface with Mat3ra workflows.py package\n", + "# This script is based on the following paper:\n", + "# \"Accurate and efficient band-offset calculations from density functional theory\" by L. Weston, ..., Van de Walle\n" + ] + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "from mat3ra.workflows import BandOffsetWorkflowConfiguration\n", + "subworkflow_1_configuration = BandOffsetWorkflowConfiguration()\n", + "subworkflow_2_configuration = BandOffsetWorkflowConfiguration()\n", + "workflow_configuration = BandOffsetWorkflowConfiguration(k_points=[6,6,1], k_path=[\"G\", \"M\", \"K\", \"G\"], subworkflow_configurations=[subworkflow_1_configuration, subworkflow_2_configuration])" + ], + "metadata": { + "collapsed": false + }, + "id": "3e82657096c933e9" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "# Enable interactive selection of materials or use default configurations\n", + "IS_INTERACTIVE_SELECTION = False\n", + "\n", + "# Indices to access materials from the loaded list\n", + "INTERFACE_INDEX = 0 # Index for the interface material\n", + "INTERFACE_LEFT_INDEX = 1 # Index for the left material\n", + "INTERFACE_RIGHT_INDEX = 2 # Index for the right material\n", + "\n", + "# Workflow-specific parameters\n", + "MAX_AREA = 50 # Maximum area for strain matching in Angstrom^2\n", + "\n", + "from utils.jupyterlite import get_materials\n", + "\n", + "# Load materials; ensure materials are pre-selected in the outer runtime\n", + "materials = get_materials(globals())\n", + "\n", + "try:\n", + " interface_material = materials[INTERFACE_INDEX]\n", + " interface_left_material = materials[INTERFACE_LEFT_INDEX]\n", + " interface_right_material = materials[INTERFACE_RIGHT_INDEX]\n", + "except IndexError as e:\n", + " print(f\"Error accessing materials: {e}\")\n", + " # Fallback assignments if indices are out of range\n", + " interface_material = materials[0]\n", + " interface_left_material = materials[1] if len(materials) > 1 else materials[0]\n", + " interface_right_material = materials[2] if len(materials) > 2 else materials[0]\n" + ], + "metadata": { + "collapsed": false + }, + "id": "a6e59f40b4c39dc6" + }, + { + "cell_type": "markdown", + "source": [ + "2. Configure VBO Workflow\n", + "Set parameters specific to the VBO workflow, such as calculation methods, indices, and other configurations.\n", + "\n", + "2.1. Define Unit Configurations\n" + ], + "metadata": { + "collapsed": false + }, + "id": "f359dbc78f9ccf08" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "from workflow_package import UnitConfiguration, SubworkflowConfiguration, WorkflowConfiguration\n", + "\n", + "\n", + "# Interface-related Units\n", + "unit_interface_set_index = UnitConfiguration(\n", + " type=\"assignment\",\n", + " attributes={\n", + " \"name\": \"Set Material Index (Interface)\",\n", + " \"value\": \"0\"\n", + " }\n", + ")\n", + "\n", + "unit_interface_find_minima = UnitConfiguration(\n", + " type=\"assignment\",\n", + " attributes={\n", + " \"operand\": \"AVG_ESP_INTERFACE\"\n", + " }\n", + ")\n", + "\n", + "# Interface-left-related Units\n", + "unit_interface_left_set_index = UnitConfiguration(\n", + " type=\"assignment\",\n", + " attributes={\n", + " \"name\": \"Set Material Index (Interface left)\",\n", + " \"value\": \"1\"\n", + " }\n", + ")\n", + "\n", + "unit_interface_left_execution_band_gap = UnitConfiguration(\n", + " type=\"executionBuilder\",\n", + " attributes={\n", + " \"flowchartId\": \"pw-bands-calculate-band-gap-left\"\n", + " }\n", + ")\n", + "\n", + "unit_interface_left_assign_band_gaps = UnitConfiguration(\n", + " type=\"assignment\",\n", + " attributes={\n", + " \"input\": [\n", + " {\"name\": \"band_gaps\", \"scope\": \"pw-bands-calculate-band-gap-left\"}\n", + " ]\n", + " }\n", + ")\n", + "\n", + "unit_interface_left_assign_vbm = UnitConfiguration(\n", + " type=\"assignment\",\n", + " attributes={\n", + " \"operand\": \"VBM_LEFT\"\n", + " }\n", + ")\n", + "\n", + "unit_interface_left_execution_avg_esp = UnitConfiguration(\n", + " type=\"executionBuilder\",\n", + " attributes={\n", + " \"flowchartId\": \"average-electrostatic-potential-left\"\n", + " }\n", + ")\n", + "\n", + "unit_interface_left_assign_avg_potential = UnitConfiguration(\n", + " type=\"assignment\",\n", + " attributes={\n", + " \"input\": [\n", + " {\"name\": \"average_potential_profile\", \"scope\": \"average-electrostatic-potential-left\"}\n", + " ]\n", + " }\n", + ")\n", + "\n", + "unit_interface_left_execution_find_extrema = UnitConfiguration(\n", + " type=\"executionBuilder\",\n", + " attributes={\n", + " \"flowchartId\": \"python-find-extrema-left\"\n", + " }\n", + ")\n", + "\n", + "unit_interface_left_find_minima = UnitConfiguration(\n", + " type=\"assignment\",\n", + " attributes={\n", + " \"operand\": \"AVG_ESP_LEFT\",\n", + " \"input\": [\n", + " {\"name\": \"STDOUT\", \"scope\": \"python-find-extrema-left\"}\n", + " ]\n", + " }\n", + ")\n", + "\n", + "# Interface-right-related Units\n", + "unit_interface_right_set_index = UnitConfiguration(\n", + " type=\"assignment\",\n", + " attributes={\n", + " \"name\": \"Set Material Index (Interface right)\",\n", + " \"value\": \"2\"\n", + " }\n", + ")\n", + "\n", + "unit_interface_right_execution_band_gap = UnitConfiguration(\n", + " type=\"executionBuilder\",\n", + " attributes={\n", + " \"flowchartId\": \"pw-bands-calculate-band-gap-right\"\n", + " }\n", + ")\n", + "\n", + "unit_interface_right_assign_band_gaps = UnitConfiguration(\n", + " type=\"assignment\",\n", + " attributes={\n", + " \"input\": [\n", + " {\"name\": \"band_gaps\", \"scope\": \"pw-bands-calculate-band-gap-right\"}\n", + " ]\n", + " }\n", + ")\n", + "\n", + "unit_interface_right_assign_vbm = UnitConfiguration(\n", + " type=\"assignment\",\n", + " attributes={\n", + " \"operand\": \"VBM_RIGHT\"\n", + " }\n", + ")\n", + "\n", + "unit_interface_right_execution_avg_esp = UnitConfiguration(\n", + " type=\"executionBuilder\",\n", + " attributes={\n", + " \"flowchartId\": \"average-electrostatic-potential-right\"\n", + " }\n", + ")\n", + "\n", + "unit_interface_right_assign_avg_potential = UnitConfiguration(\n", + " type=\"assignment\",\n", + " attributes={\n", + " \"input\": [\n", + " {\"name\": \"average_potential_profile\", \"scope\": \"average-electrostatic-potential-right\"}\n", + " ]\n", + " }\n", + ")\n", + "\n", + "unit_interface_right_execution_find_extrema = UnitConfiguration(\n", + " type=\"executionBuilder\",\n", + " attributes={\n", + " \"flowchartId\": \"python-find-extrema-right\"\n", + " }\n", + ")\n", + "\n", + "unit_interface_right_find_minima = UnitConfiguration(\n", + " type=\"assignment\",\n", + " attributes={\n", + " \"operand\": \"AVG_ESP_RIGHT\",\n", + " \"input\": [\n", + " {\"name\": \"STDOUT\", \"scope\": \"python-find-extrema-right\"}\n", + " ]\n", + " }\n", + ")\n" + ], + "metadata": { + "collapsed": false + }, + "id": "cfe45b95f022a6a9", + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "2.2.Define SubWorkflow Configurations" + ], + "metadata": { + "collapsed": false + }, + "id": "16768fe754798ad9" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "\n", + "# Interface-related SubWorkflows\n", + "subworkflow_interface_avg_esp = SubworkflowConfiguration(\n", + " name=\"BS + Avg ESP (Interface)\",\n", + " unit_configs=[unit_interface_set_index]\n", + ")\n", + "\n", + "subworkflow_interface_find_minima = SubworkflowConfiguration(\n", + " name=\"Find ESP Values (Interface)\",\n", + " unit_configs=[unit_interface_find_minima]\n", + ")\n", + "\n", + "# Interface-left-related SubWorkflows\n", + "subworkflow_interface_left_avg_esp = SubworkflowConfiguration(\n", + " name=\"BS + Avg ESP (interface left)\",\n", + " unit_configs=[\n", + " unit_interface_left_set_index,\n", + " unit_interface_left_execution_band_gap,\n", + " unit_interface_left_assign_band_gaps,\n", + " unit_interface_left_assign_vbm,\n", + " unit_interface_left_execution_avg_esp,\n", + " unit_interface_left_assign_avg_potential\n", + " ]\n", + ")\n", + "\n", + "subworkflow_interface_left_find_minima = SubworkflowConfiguration(\n", + " name=\"Find ESP Value (Interface left)\",\n", + " unit_configs=[\n", + " unit_interface_left_execution_find_extrema,\n", + " unit_interface_left_find_minima\n", + " ]\n", + ")\n", + "\n", + "# Interface-right-related SubWorkflows\n", + "subworkflow_interface_right_avg_esp = SubworkflowConfiguration(\n", + " name=\"BS + Avg ESP (interface right)\",\n", + " unit_configs=[\n", + " unit_interface_right_set_index,\n", + " unit_interface_right_execution_band_gap,\n", + " unit_interface_right_assign_band_gaps,\n", + " unit_interface_right_assign_vbm,\n", + " unit_interface_right_execution_avg_esp,\n", + " unit_interface_right_assign_avg_potential\n", + " ]\n", + ")\n", + "\n", + "subworkflow_interface_right_find_minima = SubworkflowConfiguration(\n", + " name=\"Find ESP Value (Interface right)\",\n", + " unit_configs=[\n", + " unit_interface_right_execution_find_extrema,\n", + " unit_interface_right_find_minima\n", + " ]\n", + ")\n", + "\n", + "# Final VBO Calculation SubWorkflow\n", + "subworkflow_final_vbo = SubworkflowConfiguration(\n", + " name=\"Valence Band Offset Calculation\",\n", + " # ???\n", + ")\n" + ], + "metadata": { + "collapsed": false + }, + "id": "4aefec4924abcb49", + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "2.3. Assemble Main Workflow Configuration" + ], + "metadata": { + "collapsed": false + }, + "id": "e60fec7dbbf8326c" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "\n", + "\n", + "main_workflow = WorkflowConfiguration(\n", + " name=\"Valence Band Offset (2D)\",\n", + " units=[\n", + " # Interface-related SubWorkflows\n", + " subworkflow_interface_avg_esp,\n", + " subworkflow_interface_find_minima,\n", + " \n", + " # Interface-left-related SubWorkflows\n", + " subworkflow_interface_left_avg_esp,\n", + " subworkflow_interface_left_find_minima,\n", + " \n", + " # Interface-right-related SubWorkflows\n", + " subworkflow_interface_right_avg_esp,\n", + " subworkflow_interface_right_find_minima,\n", + " \n", + " # Final VBO Calculation SubWorkflow\n", + " subworkflow_final_vbo\n", + " ]\n", + ")" + ], + "metadata": { + "collapsed": false + }, + "id": "8a5b56f82b0ce5f8", + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "> Submit via API point function or convert to YAML?" + ], + "metadata": { + "collapsed": false + }, + "id": "40aadbb16ed6c1a5" + }, + { + "cell_type": "markdown", + "source": [ + "4.2. Convert to YAML\n", + "Serialize the workflow into a YAML format for platform compatibility." + ], + "metadata": { + "collapsed": false + }, + "id": "e207f20e21500d43" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "import yaml\n", + "\n", + "def serialize_unit(unit):\n", + " if isinstance(unit, Workflow.SubWorkflow):\n", + " return {\n", + " \"name\": unit.name,\n", + " \"type\": unit.type,\n", + " \"config\": unit.config,\n", + " \"unitConfigs\": [\n", + " {\n", + " \"index\": uc.index,\n", + " \"type\": uc.type,\n", + " \"config\": uc.config\n", + " } for uc in unit.unitConfigs\n", + " ]\n", + " }\n", + " else:\n", + " # Handle other unit types if necessary\n", + " return {}\n", + "\n", + "# Convert the workflow to a dictionary\n", + "workflow_dict = {\n", + " \"name\": vbo_workflow.name,\n", + " \"units\": [serialize_unit(u) for u in vbo_workflow.units]\n", + "}\n", + "\n", + "# Serialize the dictionary to a YAML string\n", + "workflow_yaml = yaml.dump(workflow_dict, sort_keys=False)\n", + "print(workflow_yaml)\n" + ], + "metadata": { + "collapsed": false + }, + "id": "98ef62ff144e6002" + }, + { + "cell_type": "markdown", + "source": [ + "4.3. Send to Platform\n", + "Send the serialized YAML workflow to your platform. This step may vary depending on your platform's API or integration method." + ], + "metadata": { + "collapsed": false + }, + "id": "19bcc070b3c4070e" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "import requests\n", + "\n", + "# Example: Send the YAML to a platform endpoint\n", + "platform_url = \"https://your-platform-endpoint/api/workflows\" # Replace with actual URL\n", + "headers = {\n", + " \"Content-Type\": \"application/x-yaml\",\n", + " \"Authorization\": \"Bearer YOUR_API_TOKEN\" # Replace with actual token if needed\n", + "}\n", + "\n", + "response = requests.post(platform_url, data=workflow_yaml, headers=headers)\n", + "\n", + "if response.status_code == 200:\n", + " print(\"Workflow successfully sent to the platform.\")\n", + "else:\n", + " print(f\"Failed to send workflow. Status code: {response.status_code}\")\n", + " print(f\"Response: {response.text}\")\n" + ], + "metadata": { + "collapsed": false + }, + "id": "48729b1e3b64c879" + } + ], + "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 +}