diff --git a/other/materials_designer/specific_examples/Introduction.ipynb b/other/materials_designer/specific_examples/Introduction.ipynb index 7082fa0a7..1dae0b514 100644 --- a/other/materials_designer/specific_examples/Introduction.ipynb +++ b/other/materials_designer/specific_examples/Introduction.ipynb @@ -49,7 +49,7 @@ "| `X-3D-ANL` | Annealed Crystal | *To be added* | — | — |\n", "| `X-2D-PER` | Perturbation | [Ripple Perturbation in Graphene](perturbation_ripple_graphene.ipynb) | *To be added* | [[20]](#ref20) |\n", "| `X-2D-PAS` | Passivated Surface | [Silicon Surface Passivation](passivation_surface_silicon.ipynb) | *To be added* | [[21]](#ref21) |\n", - "| `X-1D-PAS` | Passivated Edge | [Si Nanowire Edge Passivation](passivation_edge_nanowire_silicon.ipynb) | *To be added* | [[22]](#ref22) |\n", + "| `X-1D-PAS` | Passivated Edge | [Si Nanowire Edge Passivation](passivation_edge_nanowire_silicon.ipynb) | [Si Nanowire Band Gap and DOS](passivation_edge_nanowire_silicon_SIMULATION.ipynb) | [[22]](#ref22) |\n", "| `X-0D-PAS` | Passivated Edge | *To be added* | — | — |\n", "| `X-0D-CUT` | Slab Cutout | [Custom Cutout in Etched Silicon](custom_cutout_etched_silicon.ipynb) | *To be added* | [[25]](#ref25) |\n", "\n", diff --git a/other/materials_designer/specific_examples/passivation_edge_nanowire_silicon.ipynb b/other/materials_designer/specific_examples/passivation_edge_nanowire_silicon.ipynb index 8fae46707..54f372c2b 100644 --- a/other/materials_designer/specific_examples/passivation_edge_nanowire_silicon.ipynb +++ b/other/materials_designer/specific_examples/passivation_edge_nanowire_silicon.ipynb @@ -46,7 +46,10 @@ "PASSIVANT = \"H\" # Chemical symbol of the passivant\n", "COORDINATION_SEARCH_RADIUS = 2.5 # in Angstroms (sphere in which to search for neighbors)\n", "COORDINATION_THRESHOLD = 3 # Coordination number below which to passivate\n", - "MAX_BONDS_TO_SATURATE = 2 # Maximum number of bonds to saturate" + "MAX_BONDS_TO_SATURATE = 2 # Maximum number of bonds to saturate\n", + "\n", + "PASSIVATED_NANOWIRE_NAME = \"Si nanowire 110 H-passivated\"\n", + "ONE_PERIOD_NANOWIRE_NAME = \"Si nanowire 110 H-passivated one period\"" ] }, { @@ -250,7 +253,8 @@ "id": "19", "metadata": {}, "source": [ - "## 5. Download the Material" + "## 5. Create the one-period cell\n", + "The manuscript computes the bands on one period of the wire, a√2/2 along ⟨110⟩ (Sec. II): the lower half of the two-period cell." ] }, { @@ -259,12 +263,34 @@ "id": "20", "metadata": {}, "outputs": [], + "source": [ + "lattice_vectors = passivated_nanowire.lattice.vector_arrays\n", + "period = passivated_nanowire.lattice.c / 2\n", + "one_period_nanowire = filter_by_box(passivated_nanowire, [0, 0, 0], [1, 1, 0.5])\n", + "one_period_nanowire.set_lattice_vectors(lattice_vectors[0], lattice_vectors[1], [0.0, 0.0, period])" + ] + }, + { + "cell_type": "markdown", + "id": "21", + "metadata": {}, + "source": [ + "## 6. Download the Material" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "22", + "metadata": {}, + "outputs": [], "source": [ "from mat3ra.notebooks_utils.io import download_content_to_file\n", "from mat3ra.notebooks_utils.material import set_materials\n", "\n", - "passivated_nanowire.name = \"H-Passivated Silicon Nanowire\"\n", - "set_materials(passivated_nanowire)\n", + "passivated_nanowire.name = PASSIVATED_NANOWIRE_NAME\n", + "one_period_nanowire.name = ONE_PERIOD_NANOWIRE_NAME\n", + "set_materials([passivated_nanowire, one_period_nanowire])\n", "download_content_to_file(passivated_nanowire.to_json(), \"passivated_nanowire.json\")" ] } diff --git a/other/materials_designer/specific_examples/passivation_edge_nanowire_silicon_SIMULATION.ipynb b/other/materials_designer/specific_examples/passivation_edge_nanowire_silicon_SIMULATION.ipynb new file mode 100644 index 000000000..034d5cb81 --- /dev/null +++ b/other/materials_designer/specific_examples/passivation_edge_nanowire_silicon_SIMULATION.ipynb @@ -0,0 +1,761 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "0", + "metadata": {}, + "source": [ + "# Band Gap and Density of States of an H-Passivated Si Nanowire\n", + "\n", + "> **B. Aradi, L. E. Ramos, P. Deák, Th. Köhler, F. Bechstedt, R. Q. Zhang, and Th. Frauenheim**\n", + "> \"Theoretical study of the chemical gap tuning in silicon nanowires\"\n", + "> Phys. Rev. B 76, 035305 (2007)\n", + "> [DOI: 10.1103/PhysRevB.76.035305](https://doi.org/10.1103/PhysRevB.76.035305)\n", + "\n", + "Computes the band gap, the bands along the wire and the density of states of the H-passivated ⟨110⟩ silicon nanowire\n", + "of radius 0.51 nm, one period Si₁₈H₁₂ as created in the [structure notebook](passivation_edge_nanowire_silicon.ipynb),\n", + "and the band gap of bulk silicon, and compares them with Aradi et al.'s Table II and\n", + "Fig. 8 (left). The manuscript optimizes the wire with DFTB and computes its gaps with CRYSTAL and a one-parameter global\n", + "hybrid, PBE with an exact-exchange fraction of 0.12, chosen in its ref. 31 (Deák et al. 2005) as the best match to bulk\n", + "silicon (gap 1.16 eV); here the atoms and the period of the wire are relaxed with PBE and the gaps are computed with a\n", + "global hybrid in the PBE0 form, its fraction of exact exchange (cell 1.3) fitted to that bulk gap.\n", + "\n", + "

Usage

\n", + "\n", + "1. Create the material in the [structure notebook](passivation_edge_nanowire_silicon.ipynb), which saves `Si nanowire 110 H-passivated one period` to the `uploads` folder.\n", + "1. Set the parameters in cells 1.2 and 1.3 (or use the defaults).\n", + "1. Click \"Run\" > \"Run All\" to run all cells.\n", + "1. Wait for the jobs to complete.\n", + "1. Scroll down to view the results.\n", + "\n", + "## Summary\n", + "\n", + "1. Set up the environment and parameters: install packages (JupyterLite only) and configure the material names, compute, DFT and plot parameters.\n", + "1. Authenticate and initialize API client: authenticate via browser, initialize the client, then select account and project.\n", + "1. Load the wire by name and bulk silicon from Standata, print provenance and save both to the platform.\n", + "1. Configure the workflows: variable-cell relaxation of the wire, then, with the global hybrid, band structure of the wire, band gap and density of states of the wire and of bulk silicon.\n", + "1. Configure compute: get the list of clusters and create a compute configuration.\n", + "1. Run the jobs: bulk silicon and the relaxation of the wire, then the band structure and the density of states of the relaxed wire.\n", + "1. Retrieve the results: the period of the relaxed wire and the band gaps.\n", + "1. Compare with Aradi et al. (2007): the band gaps, then the bands and the density of states beside Fig. 8 (left)." + ] + }, + { + "cell_type": "markdown", + "id": "1", + "metadata": {}, + "source": [ + "## 1. Set up the environment and parameters\n", + "### 1.1. Install packages (JupyterLite)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2", + "metadata": {}, + "outputs": [], + "source": [ + "from mat3ra.notebooks_utils.packages import install_packages\n", + "\n", + "await install_packages(\"made|api_examples\")" + ] + }, + { + "cell_type": "markdown", + "id": "3", + "metadata": {}, + "source": [ + "### 1.2. Set parameters and configurations for the workflows and jobs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4", + "metadata": {}, + "outputs": [], + "source": [ + "from datetime import datetime\n", + "from mat3ra.ide.compute import QueueName\n", + "\n", + "ORGANIZATION_NAME = None # set to your organization name (full or partial); otherwise, your default one is used\n", + "FOLDER = \"./uploads\"\n", + "WIRE_NAME = \"Si nanowire 110 H-passivated one period\" # saved by the structure notebook\n", + "RELAXED_WIRE_NAME = \"Si nanowire 110 H-passivated relaxed one period\"\n", + "BULK_NAME = \"Silicon\" # Standata\n", + "\n", + "APPLICATION_NAME = \"espresso\"\n", + "RELAX_WORKFLOW_SEARCH_TERM = \"variable_cell_relaxation.json\"\n", + "BANDS_WORKFLOW_SEARCH_TERM = \"band_structure_hse.json\"\n", + "DOS_WORKFLOW_SEARCH_TERM = \"band_gap_dos_hse.json\"\n", + "\n", + "CLUSTER_NAME = None # specify full or partial name i.e. \"cluster-001\" to select\n", + "QUEUE_NAME = QueueName.OF\n", + "PPN = None # None uses the selected queue's maximum cores per job on the selected cluster\n", + "NPOOLS = 2 # k-point pools: must divide the cores and not exceed any job's k-points; each adds exact-exchange memory\n", + "TIME_LIMIT = \"04:00:00\"\n", + "\n", + "timestamp = datetime.now().strftime(\"%Y-%m-%d %H:%M\")\n", + "POLL_INTERVAL = 60 # seconds\n", + "\n", + "ENERGY_WINDOW = (-4.0, 6.0) # eV, the energy range of Fig. 8" + ] + }, + { + "cell_type": "markdown", + "id": "5", + "metadata": {}, + "source": [ + "### 1.3. Set the DFT parameters" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6", + "metadata": {}, + "outputs": [], + "source": [ + "# manuscript: geometry with DFTB, gaps with CRYSTAL and a one-parameter global hybrid fitted to bulk Si;\n", + "# ours: geometry with PBE, GBRV ultrasoft pseudopotentials at their tested cutoffs; gaps with that hybrid in the\n", + "# PBE0 form and PseudoDojo norm-conserving ones, as ultrasoft augmentation of every band pair dominates its cost\n", + "ECUTWFC = 40 # Ry\n", + "ECUTRHO = 200 # Ry\n", + "HSE_PSEUDOPOTENTIAL_TYPE = \"nc\"\n", + "HSE_PSEUDOPOTENTIAL_SEARCH_TEXT = \"dojo-oncv/0.4\" # PseudoDojo 0.4 among norm-conserving files for hybrid functionals\n", + "HSE_ECUTWFC = 72 # Ry, PseudoDojo \"normal\" hint: H 36 Ha, Si 18 Ha\n", + "HSE_ECUTRHO = 4 * HSE_ECUTWFC # Ry, enough for norm-conserving pseudopotentials\n", + "# fraction of exact exchange, fitted (to two decimals) so bulk Si gives the manuscript's 1.16 eV; section 8.1 prints it\n", + "EXX_FRACTION = 0.10\n", + "\n", + "# forces below 1e-4 Ha/Bohr as in the manuscript, in QE's Ry/Bohr; the atoms and the period along the wire relax\n", + "RELAXATION_SETTINGS = {\"control\": {\"forc_conv_thr\": 2e-4, \"nstep\": 100}, \"cell\": {\"cell_dofree\": \"z\"}}\n", + "PRELIMINARY_SCF_SETTINGS = {\"control\": {\"verbosity\": \"high\"}} # so pw.x prints the crystal k-points the hybrid run uses\n", + "# Quantum ESPRESSO computes no hybrid-functional stress with pools; ecutfock (Ry) as in the DOS workflow, since\n", + "# its default, 4 x HSE_ECUTWFC, would multiply each pool's exchange memory\n", + "HSE_SETTINGS = {\"control\": {\"tstress\": False},\n", + " \"system\": {\"input_dft\": \"pbe0\", \"exx_fraction\": EXX_FRACTION, \"ecutfock\": 100}}\n", + "RELAX_KGRID = [1, 1, 8] # manuscript: 1x1x4 on two periods\n", + "BANDS_KGRID = [1, 1, 8]\n", + "QGRID = [1, 1, 4] # exact-exchange q-grid; each dimension divides the one of BANDS_KGRID\n", + "KPATH_STEPS = 20 # even, so every k − q of the path stays on the path for the 1x1x4 q-grid\n", + "# a job is reused by material, workflow name and k-grid, so rename a workflow after changing any other setting it uses\n", + "RELAX_WORKFLOW_NAME = \"Variable-cell Relaxation Si nanowire\"\n", + "BANDS_WORKFLOW_NAME = f\"Band Structure global hybrid {EXX_FRACTION} Si nanowire\"\n", + "WIRE_DOS_WORKFLOW_NAME = f\"Band Gap + DOS global hybrid {EXX_FRACTION} Si nanowire\"\n", + "BULK_DOS_WORKFLOW_NAME = f\"Band Gap + DOS global hybrid {EXX_FRACTION} Si bulk\"\n", + "DOS_KGRID = [1, 1, 8] # the workflow runs odd dimensions as the next even, so 2x2x8\n", + "BULK_KGRID = [8, 8, 8]\n", + "\n", + "RELAX_UNIT = \"pw_vc-relax\"\n", + "PRELIMINARY_SCF_UNIT = \"pw_scf\"\n", + "BANDS_HSE_UNIT = \"pw_scf_bands_hse\"\n", + "BANDS_UNIT = \"bands\"\n", + "DOS_HSE_UNIT = \"pw_scf_hse\"" + ] + }, + { + "cell_type": "markdown", + "id": "7", + "metadata": {}, + "source": [ + "## 2. Authenticate and initialize API client\n", + "### 2.1. Authenticate\n", + "Authenticate in the browser and have credentials stored in environment variable \"OIDC_ACCESS_TOKEN\"." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8", + "metadata": {}, + "outputs": [], + "source": [ + "from mat3ra.notebooks_utils.auth import authenticate\n", + "\n", + "await authenticate()" + ] + }, + { + "cell_type": "markdown", + "id": "9", + "metadata": {}, + "source": [ + "### 2.2. Initialize API client" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "10", + "metadata": {}, + "outputs": [], + "source": [ + "from mat3ra.api_client import APIClient\n", + "\n", + "client = APIClient.authenticate()\n", + "client" + ] + }, + { + "cell_type": "markdown", + "id": "11", + "metadata": {}, + "source": [ + "### 2.3. Select account" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "12", + "metadata": {}, + "outputs": [], + "source": [ + "client.list_accounts()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "13", + "metadata": {}, + "outputs": [], + "source": [ + "selected_account = client.my_account\n", + "\n", + "if ORGANIZATION_NAME:\n", + " selected_account = client.get_account(name=ORGANIZATION_NAME)\n", + "\n", + "ACCOUNT_ID = selected_account.id\n", + "print(f\"✅ Selected account ID: {ACCOUNT_ID}, name: {selected_account.name}\")" + ] + }, + { + "cell_type": "markdown", + "id": "14", + "metadata": {}, + "source": [ + "### 2.4. Select project" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "15", + "metadata": {}, + "outputs": [], + "source": [ + "projects = client.projects.list({\"isDefault\": True, \"owner._id\": ACCOUNT_ID})\n", + "project_id = projects[0][\"_id\"]\n", + "print(f\"✅ Using project: {projects[0]['name']} ({project_id})\")" + ] + }, + { + "cell_type": "markdown", + "id": "16", + "metadata": {}, + "source": [ + "## 3. Load the materials\n", + "### 3.1. Load the wire from the uploads folder or the platform, bulk silicon from Standata, and print provenance" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "17", + "metadata": {}, + "outputs": [], + "source": [ + "from collections import Counter\n", + "from mat3ra.made.material import Material\n", + "from mat3ra.notebooks_utils.core.entity.material.api import load_material\n", + "from mat3ra.standata.materials import Materials\n", + "\n", + "materials = {\n", + " WIRE_NAME: load_material(client, FOLDER, WIRE_NAME, ACCOUNT_ID),\n", + " BULK_NAME: Material.create(Materials.get_by_name_first_match(BULK_NAME)),\n", + "}\n", + "for name, material in materials.items():\n", + " print(f\"{name}: {dict(Counter(material.basis.elements.values))}, {material.basis.number_of_atoms} atoms, \"\n", + " f\"cell {material.lattice.a:.3f} x {material.lattice.b:.3f} x {material.lattice.c:.3f} Å\")" + ] + }, + { + "cell_type": "markdown", + "id": "18", + "metadata": {}, + "source": [ + "### 3.2. Save the materials to the platform" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "19", + "metadata": {}, + "outputs": [], + "source": [ + "from mat3ra.notebooks_utils.core.entity.material.api import get_or_create_material\n", + "\n", + "saved_materials = {name: get_or_create_material(client, material, ACCOUNT_ID) for name, material in materials.items()}" + ] + }, + { + "cell_type": "markdown", + "id": "20", + "metadata": {}, + "source": [ + "## 4. Configure the workflows\n", + "\n", + "The Standata workflows carry their models: PBE for the relaxation and for the preliminary SCF of the band structure,\n", + "HSE06 for the band structure and for the band gap and density of states, all with GBRV ultrasoft pseudopotentials;\n", + "4.2 and 4.3 switch those runs to norm-conserving ones and set the global hybrid in their input files.\n", + "### 4.1. Variable-cell relaxation of the wire" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "21", + "metadata": {}, + "outputs": [], + "source": [ + "from mat3ra.standata.workflows import WorkflowStandata\n", + "from mat3ra.wode.workflows import Workflow\n", + "from mat3ra.notebooks_utils.workflow import apply_planewave_cutoffs, apply_scf_kgrid, patch_workflow_qe_input\n", + "\n", + "workflow_configs = WorkflowStandata.filter_by_application(APPLICATION_NAME)\n", + "wire = materials[WIRE_NAME]\n", + "\n", + "relax_workflow = Workflow.create(workflow_configs.get_by_name_first_match(RELAX_WORKFLOW_SEARCH_TERM))\n", + "relax_workflow.name = RELAX_WORKFLOW_NAME\n", + "apply_planewave_cutoffs(relax_workflow, ECUTWFC, ECUTRHO, unit_name=RELAX_UNIT)\n", + "apply_scf_kgrid(relax_workflow, RELAX_KGRID, material=wire, unit_name=RELAX_UNIT)\n", + "patch_workflow_qe_input(relax_workflow, RELAXATION_SETTINGS, [RELAX_UNIT])" + ] + }, + { + "cell_type": "markdown", + "id": "22", + "metadata": {}, + "source": [ + "### 4.2. Global-hybrid band structure of the wire\n", + "\n", + "The PBE SCF on `BANDS_KGRID` gives the k-points of the hybrid run, which adds the path along the wire (6.2) and\n", + "evaluates the exchange on `QGRID`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "23", + "metadata": {}, + "outputs": [], + "source": [ + "from mat3ra.mode import ModelFactory\n", + "from mat3ra.standata.model_tree import ModelTreeStandata\n", + "from mat3ra.wode.context.providers import PointsGridDataProvider\n", + "\n", + "bands_workflow = Workflow.create(workflow_configs.get_by_name_first_match(BANDS_WORKFLOW_SEARCH_TERM))\n", + "bands_workflow.name = BANDS_WORKFLOW_NAME\n", + "apply_scf_kgrid(bands_workflow, BANDS_KGRID, material=wire, unit_name=PRELIMINARY_SCF_UNIT)\n", + "apply_planewave_cutoffs(bands_workflow, ECUTWFC, ECUTRHO, unit_name=PRELIMINARY_SCF_UNIT)\n", + "apply_planewave_cutoffs(bands_workflow, HSE_ECUTWFC, HSE_ECUTRHO, unit_name=BANDS_HSE_UNIT)\n", + "patch_workflow_qe_input(bands_workflow, PRELIMINARY_SCF_SETTINGS, [PRELIMINARY_SCF_UNIT])\n", + "patch_workflow_qe_input(bands_workflow, HSE_SETTINGS, [BANDS_HSE_UNIT])\n", + "main_hse_subworkflow = next(\n", + " subworkflow for subworkflow in bands_workflow.subworkflows if subworkflow.name == \"Main HSE Run\"\n", + ")\n", + "hse_model_config = ModelTreeStandata.get_model_by_parameters(\n", + " type=\"dft\", subtype=main_hse_subworkflow.model.subtype, functional=main_hse_subworkflow.model.functional\n", + ")\n", + "hse_model_config[\"method\"] = {\n", + " \"type\": \"pseudopotential\",\n", + " \"subtype\": HSE_PSEUDOPOTENTIAL_TYPE,\n", + " \"data\": {\"searchText\": HSE_PSEUDOPOTENTIAL_SEARCH_TEXT},\n", + "}\n", + "main_hse_subworkflow.model = ModelFactory.create(hse_model_config)\n", + "bands_hse_unit = main_hse_subworkflow.get_unit_by_name(name=BANDS_HSE_UNIT)\n", + "bands_hse_unit.add_context(\n", + " PointsGridDataProvider(name=\"qgrid\", material=wire, dimensions=QGRID, isEdited=True).get_context_item_data()\n", + ")\n", + "main_hse_subworkflow.set_unit(bands_hse_unit)\n", + "bands_unit = main_hse_subworkflow.get_unit_by_name(name=BANDS_UNIT)\n", + "bands_unit.results = [{\"name\": \"band_structure\"}, {\"name\": \"band_gaps\"}]\n", + "main_hse_subworkflow.set_unit(bands_unit)" + ] + }, + { + "cell_type": "markdown", + "id": "24", + "metadata": {}, + "source": [ + "### 4.3. Global-hybrid band gap and density of states of the wire and of bulk silicon" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "25", + "metadata": {}, + "outputs": [], + "source": [ + "dos_workflows = {}\n", + "for name, kgrid, workflow_name in ((WIRE_NAME, DOS_KGRID, WIRE_DOS_WORKFLOW_NAME),\n", + " (BULK_NAME, BULK_KGRID, BULK_DOS_WORKFLOW_NAME)):\n", + " workflow = Workflow.create(workflow_configs.get_by_name_first_match(DOS_WORKFLOW_SEARCH_TERM))\n", + " workflow.name = workflow_name\n", + " apply_planewave_cutoffs(workflow, HSE_ECUTWFC, HSE_ECUTRHO, unit_name=DOS_HSE_UNIT)\n", + " apply_scf_kgrid(workflow, kgrid, material=materials[name], unit_name=DOS_HSE_UNIT)\n", + " patch_workflow_qe_input(workflow, HSE_SETTINGS, [DOS_HSE_UNIT])\n", + " workflow.subworkflows[0].model = ModelFactory.create(hse_model_config)\n", + " dos_workflows[name] = workflow" + ] + }, + { + "cell_type": "markdown", + "id": "26", + "metadata": {}, + "source": [ + "## 5. Create the compute configuration\n", + "### 5.1. Get list of clusters" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "27", + "metadata": {}, + "outputs": [], + "source": [ + "clusters = client.clusters.list()\n", + "print(f\"Available clusters: {[c['hostname'] for c in clusters]}\")" + ] + }, + { + "cell_type": "markdown", + "id": "28", + "metadata": {}, + "source": [ + "### 5.2. Create the compute configuration for the jobs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "29", + "metadata": {}, + "outputs": [], + "source": [ + "from mat3ra.ide.compute import Compute\n", + "\n", + "if CLUSTER_NAME:\n", + " cluster = next((c for c in clusters if CLUSTER_NAME in c[\"hostname\"]), None)\n", + " if cluster is None:\n", + " raise ValueError(f\"Cluster '{CLUSTER_NAME}' not found. Available: {[c['hostname'] for c in clusters]}\")\n", + "else:\n", + " cluster = clusters[0]\n", + "ppn = PPN or next(queue[\"maxPPN\"] for queue in cluster[\"queues\"] if queue[\"name\"] == QUEUE_NAME.value)\n", + "compute = Compute(cluster=cluster, queue=QUEUE_NAME, ppn=ppn, timeLimit=TIME_LIMIT, arguments={\"npools\": NPOOLS})\n", + "print(f\"Using cluster: {compute.cluster.hostname}, queue: {QUEUE_NAME}, ppn: {ppn}, \"\n", + " f\"time limit: {TIME_LIMIT}\")" + ] + }, + { + "cell_type": "markdown", + "id": "30", + "metadata": {}, + "source": [ + "## 6. Run the jobs\n", + "\n", + "A submitted, queued, running or finished job for the same material, workflow name and k-grid is reused.\n", + "### 6.1. Bulk silicon and the relaxation of the wire" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "31", + "metadata": {}, + "outputs": [], + "source": [ + "from mat3ra.notebooks_utils.core.entity.job.api import find_job_for_material\n", + "from mat3ra.notebooks_utils.job import create_job\n", + "from mat3ra.notebooks_utils.api.job import submit_jobs, wait_for_jobs_to_finish_async\n", + "\n", + "job_ids = {}\n", + "for workflow, saved_material, kgrid, unit_name in (\n", + " (dos_workflows[BULK_NAME], saved_materials[BULK_NAME], BULK_KGRID, DOS_HSE_UNIT),\n", + " (relax_workflow, saved_materials[WIRE_NAME], RELAX_KGRID, RELAX_UNIT),\n", + "):\n", + " job = find_job_for_material(client, saved_material[\"_id\"], workflow.name, ACCOUNT_ID,\n", + " statuses=(\"submitted\", \"queued\", \"active\", \"finished\"),\n", + " kgrid=kgrid, unit_name=unit_name)\n", + " if job is None:\n", + " job = create_job(api_client=client, materials=[saved_material], workflow=workflow, project_id=project_id,\n", + " owner_id=ACCOUNT_ID, compute=compute.to_dict(), prefix=f\"{workflow.name} {timestamp}\")\n", + " submit_jobs(client.jobs, [job[\"_id\"]])\n", + " print(f\"✅ {workflow.name}: submitted job {job['_id']}\")\n", + " else:\n", + " print(f\"♻️ {workflow.name}: reusing job {job['_id']}\")\n", + " job_ids[workflow.name] = job[\"_id\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "32", + "metadata": {}, + "outputs": [], + "source": [ + "await wait_for_jobs_to_finish_async(client.jobs, [job_ids[relax_workflow.name]], poll_interval=POLL_INTERVAL)" + ] + }, + { + "cell_type": "markdown", + "id": "33", + "metadata": {}, + "source": [ + "### 6.2. Relaxed wire and the path along it\n", + "\n", + "The end of the Brillouin zone along the wire, (0, 0, 1/2), is Z in the manuscript; its name in the k-path depends on\n", + "the lattice type of the relaxed cell, so it is looked up by its coordinates." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "34", + "metadata": {}, + "outputs": [], + "source": [ + "from mat3ra.made.reciprocal.symmetry_points import get_symmetry_points\n", + "from mat3ra.notebooks_utils.core.entity.material.api import get_final_structure_for_job\n", + "from mat3ra.wode.context.providers import PointsPathDataProvider\n", + "\n", + "relaxed_wire = get_final_structure_for_job(client, job_ids[relax_workflow.name])\n", + "client.materials.update(relaxed_wire.id, {\"name\": RELAXED_WIRE_NAME})\n", + "wire_axis_point = next(\n", + " point[\"point\"] for point in get_symmetry_points(relaxed_wire.lattice) if point[\"coordinates\"] == [0, 0, 0.5]\n", + ")\n", + "bands_hse_unit.add_context(\n", + " PointsPathDataProvider(\n", + " name=\"explicitKPath\",\n", + " path=[{\"point\": \"Γ\", \"steps\": KPATH_STEPS}, {\"point\": wire_axis_point, \"steps\": 1}],\n", + " isEdited=True,\n", + " ).get_context_item_data()\n", + ")\n", + "main_hse_subworkflow.set_unit(bands_hse_unit)" + ] + }, + { + "cell_type": "markdown", + "id": "35", + "metadata": {}, + "source": [ + "### 6.3. Band structure and density of states of the relaxed wire" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "36", + "metadata": {}, + "outputs": [], + "source": [ + "for workflow, saved_material, kgrid, unit_name in (\n", + " (bands_workflow, relaxed_wire.to_dict(), BANDS_KGRID, PRELIMINARY_SCF_UNIT),\n", + " (dos_workflows[WIRE_NAME], relaxed_wire.to_dict(), DOS_KGRID, DOS_HSE_UNIT),\n", + "):\n", + " job = find_job_for_material(client, saved_material[\"_id\"], workflow.name, ACCOUNT_ID,\n", + " statuses=(\"submitted\", \"queued\", \"active\", \"finished\"),\n", + " kgrid=kgrid, unit_name=unit_name)\n", + " if job is None:\n", + " job = create_job(api_client=client, materials=[saved_material], workflow=workflow, project_id=project_id,\n", + " owner_id=ACCOUNT_ID, compute=compute.to_dict(), prefix=f\"{workflow.name} {timestamp}\")\n", + " submit_jobs(client.jobs, [job[\"_id\"]])\n", + " print(f\"✅ {workflow.name}: submitted job {job['_id']}\")\n", + " else:\n", + " print(f\"♻️ {workflow.name}: reusing job {job['_id']}\")\n", + " job_ids[workflow.name] = job[\"_id\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "37", + "metadata": {}, + "outputs": [], + "source": [ + "await wait_for_jobs_to_finish_async(client.jobs, list(job_ids.values()), poll_interval=POLL_INTERVAL)" + ] + }, + { + "cell_type": "markdown", + "id": "38", + "metadata": {}, + "source": [ + "## 7. Retrieve the results\n", + "### 7.1. Period of the relaxed wire" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "39", + "metadata": {}, + "outputs": [], + "source": [ + "print(f\"Period along the wire, {WIRE_NAME}:\")\n", + "print(f\"start: {wire.lattice.c:.4f} Å\")\n", + "print(f\"relaxed (PBE): {relaxed_wire.lattice.c:.4f} Å\")" + ] + }, + { + "cell_type": "markdown", + "id": "40", + "metadata": {}, + "source": [ + "### 7.2. Band gaps\n", + "\n", + "The fundamental gap is the `indirect` entry of a job's band gaps: from the valence-band maximum to the conduction-band\n", + "minimum wherever they fall, direct when both are at the same k-point. The gap of the wire comes from the band structure\n", + "job, whose k-points include the path along the wire." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "41", + "metadata": {}, + "outputs": [], + "source": [ + "from mat3ra.notebooks_utils.core.entity.property.api import get_properties_for_job\n", + "\n", + "fundamental_gaps = {}\n", + "for workflow in (bands_workflow, dos_workflows[WIRE_NAME], dos_workflows[BULK_NAME]):\n", + " band_gaps = get_properties_for_job(client, job_ids[workflow.name], \"band_gaps\")[0]\n", + " fundamental_gaps[workflow.name] = next(gap for gap in band_gaps[\"values\"] if gap[\"type\"] == \"indirect\")" + ] + }, + { + "cell_type": "markdown", + "id": "42", + "metadata": {}, + "source": [ + "## 8. Compare with Aradi et al. (2007)\n", + "### 8.1. Band gaps" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "43", + "metadata": {}, + "outputs": [], + "source": [ + "# Aradi et al. 2007: Table II (p. 5) for the wire; bulk Si with the same hybrid, p. 6\n", + "MANUSCRIPT_BAND_GAPS = {WIRE_NAME: (2.21, \"direct\"), BULK_NAME: (1.16, \"indirect\")} # eV\n", + "\n", + "print(f\"Band gap (global hybrid, exact-exchange fraction {EXX_FRACTION}):\")\n", + "for label, gap in ((WIRE_NAME, fundamental_gaps[bands_workflow.name]),\n", + " (BULK_NAME, fundamental_gaps[dos_workflows[BULK_NAME].name])):\n", + " character = \"direct\" if gap[\"kpointValence\"] == gap[\"kpointConduction\"] else \"indirect\"\n", + " print(f\"{label}: {gap['value']:.2f} eV, {character}\")\n", + "\n", + "print(\"\\nBand gap from the manuscript:\")\n", + "for label, (value, character) in MANUSCRIPT_BAND_GAPS.items():\n", + " print(f\"{label}: {value:.2f} eV, {character}\")" + ] + }, + { + "cell_type": "markdown", + "id": "44", + "metadata": {}, + "source": [ + "### 8.2. Bands and density of states (Fig. 8 of the manuscript, left)\n", + "\n", + "The manuscript's Fig. 8 (left): density of states (solid), its projection on the H atoms (dotted) and bands along Γ–Z,\n", + "the valence-band maximum at 0:\n", + "\n", + "\"Aradi" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "45", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "from matplotlib import pyplot as plt\n", + "from mat3ra.notebooks_utils.plot import display_matplotlib_figure\n", + "\n", + "band_structure = get_properties_for_job(client, job_ids[bands_workflow.name], \"band_structure\")[0]\n", + "density_of_states = get_properties_for_job(client, job_ids[dos_workflows[WIRE_NAME].name], \"density_of_states\")[0]\n", + "path_bands = np.array(band_structure[\"yDataSeries\"])[:, -(KPATH_STEPS + 1):]\n", + "path_bands -= fundamental_gaps[bands_workflow.name][\"eigenvalueValence\"]\n", + "dos_energies = np.array(density_of_states[\"xDataArray\"][0])\n", + "dos_energies -= fundamental_gaps[dos_workflows[WIRE_NAME].name][\"eigenvalueValence\"]\n", + "hydrogen_dos = np.sum([series for series, legend in zip(density_of_states[\"yDataSeries\"], density_of_states[\"legend\"])\n", + " if legend.get(\"element\") == \"H\"], axis=0)\n", + "\n", + "figure, (dos_axes, bands_axes) = plt.subplots(1, 2, sharey=True, gridspec_kw={\"width_ratios\": [1, 2], \"wspace\": 0})\n", + "dos_axes.plot(density_of_states[\"yDataSeries\"][0], dos_energies, color=\"black\", label=\"total\")\n", + "dos_axes.plot(hydrogen_dos, dos_energies, color=\"black\", linestyle=\":\", label=\"H\")\n", + "dos_axes.invert_xaxis()\n", + "dos_axes.set_xticks([])\n", + "dos_axes.set_ylabel(\"Energy (eV)\")\n", + "dos_axes.legend()\n", + "bands_axes.plot(path_bands.T, color=\"black\", linewidth=0.8)\n", + "bands_axes.set_xlim(0, KPATH_STEPS)\n", + "bands_axes.set_xticks([0, KPATH_STEPS], [\"Γ\", \"Z\"])\n", + "bands_axes.set_ylim(*ENERGY_WINDOW)\n", + "figure.suptitle(f\"{WIRE_NAME}\\nglobal hybrid, exact-exchange fraction {EXX_FRACTION}\")\n", + "display_matplotlib_figure(figure)" + ] + }, + { + "cell_type": "markdown", + "id": "46", + "metadata": {}, + "source": [ + "## References\n", + "\n", + "[1] B. Aradi, L. E. Ramos, P. Deák, Th. Köhler, F. Bechstedt, R. Q. Zhang and Th. Frauenheim, \"Theoretical study of the chemical gap tuning in silicon nanowires\", Phys. Rev. B 76, 035305 (2007). https://doi.org/10.1103/PhysRevB.76.035305\n", + "\n", + "[2] J. P. Perdew, M. Ernzerhof and K. Burke, \"Rationale for mixing exact exchange with density functional approximations\", J. Chem. Phys. 105, 9982 (1996). https://doi.org/10.1063/1.472933\n", + "\n", + "[3] C. Adamo and V. Barone, \"Toward reliable density functional methods without adjustable parameters: The PBE0 model\", J. Chem. Phys. 110, 6158 (1999). https://doi.org/10.1063/1.478522\n", + "\n", + "[4] K. F. Garrity, J. W. Bennett, K. M. Rabe and D. Vanderbilt, \"Pseudopotentials for high-throughput DFT calculations\", Comput. Mater. Sci. 81, 446 (2014). https://doi.org/10.1016/j.commatsci.2013.08.053\n", + "\n", + "[5] M. J. van Setten, M. Giantomassi, E. Bousquet, M. J. Verstraete, D. R. Hamann, X. Gonze and G.-M. Rignanese, \"The PseudoDojo: Training and grading a 85 element optimized norm-conserving pseudopotential table\", Comput. Phys. Commun. 226, 39 (2018). https://doi.org/10.1016/j.cpc.2018.01.012" + ] + } + ], + "metadata": { + "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.11.2" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}