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 98127836..a29aee20 100644 --- a/other/materials_designer/create_interface_with_min_strain_zsl.ipynb +++ b/other/materials_designer/create_interface_with_min_strain_zsl.ipynb @@ -36,13 +36,18 @@ "source": [ "## 1. Set Input Parameters\n", "\n", - "### 1.1. Select Substrate and Layer from Input Materials" + "### 1.1. Set Substrate and Layer Parameters " ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 1, + "metadata": { + "ExecuteTime": { + "end_time": "2024-05-07T20:04:36.375492Z", + "start_time": "2024-05-07T20:04:36.353678Z" + } + }, "outputs": [], "source": [ "SUBSTRATE_PARAMETERS = {\n", @@ -56,8 +61,9 @@ "}\n", "\n", "USE_CONVENTIONAL_CELL = True # if True, the surface plane is constructed using miller indices of the conventional cell\n", + "\n", "IS_TERMINATION_SELECTION_INTERACTIVE = True # if True, the user can select the termination interactively\n", - "DEFAULT_TERMINATION_INDEX = 0 # the default termination index to use if the interactive mode is disabled" + "TERMINATION_INDEX = 0 # the default termination index that is used if no termination selected" ] }, { @@ -71,13 +77,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 2, + "metadata": { + "ExecuteTime": { + "end_time": "2024-05-07T20:04:36.397714Z", + "start_time": "2024-05-07T20:04:36.378928Z" + } + }, "outputs": [], "source": [ "INTERFACE_PARAMETERS = {\n", " \"DISTANCE_Z\": 3.0, # in Angstroms\n", - " \"MAX_AREA\": 400, # in Angstroms^2\n", + " \"MAX_AREA\": 50, # in Angstroms^2\n", "}" ] }, @@ -90,8 +101,13 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 3, + "metadata": { + "ExecuteTime": { + "end_time": "2024-05-07T20:04:36.399968Z", + "start_time": "2024-05-07T20:04:36.389404Z" + } + }, "outputs": [], "source": [ "ZSL_PARAMETERS = {\n", @@ -122,16 +138,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 4, + "metadata": { + "ExecuteTime": { + "end_time": "2024-05-07T20:04:36.411153Z", + "start_time": "2024-05-07T20:04:36.402637Z" + } + }, "outputs": [], "source": [ "import sys\n", + "\n", "if sys.platform == \"emscripten\":\n", " import micropip\n", + "\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\")" + "\n", + " await install_packages(\"create_interface_with_min_strain_zsl.ipynb\", \"../../config.yml\")" ] }, { @@ -143,7 +167,35 @@ }, { "cell_type": "code", - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Data from 0-Ni has been read successfully.\n", + "Data from 1-Graphene has been read successfully.\n", + "Data from 3-WS2 has been read successfully.\n", + "Data from 4-BN has been read successfully.\n", + "Data from 4-Te2Mo has been read successfully.\n", + "Data from B43 Te42 Mo21 W27 S54 N43 has been read successfully.\n", + "Data from Ni12 C8 has been read successfully.\n", + "Data from Ni3 C2 has been read successfully.\n", + "Data from Te14 Mo7 W9 S18 has been read successfully.\n" + ] + }, + { + "data": { + "text/plain": "GridBox(children=(VBox(children=(Label(value='Ni - Material 0', layout=Layout(height='30px', overflow='hidden'…", + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "868aae6d9d254aafb6e75472bb1fd341" + } + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "from mat3ra.made.material import Material\n", "from utils.jupyterlite import get_data\n", @@ -156,8 +208,13 @@ "visualize(materials, repetitions=[1, 1, 1], rotation=\"0x\")" ], "metadata": { - "collapsed": false - } + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-05-07T20:04:40.253729Z", + "start_time": "2024-05-07T20:04:36.407859Z" + } + }, + "execution_count": 5 }, { "cell_type": "markdown", @@ -179,18 +236,25 @@ "from mat3ra.made.tools.build import init_interface_builder\n", "\n", "interface_builder = init_interface_builder(\n", - " materials[5],\n", - " materials[3], settings=interface_settings\n", - " )" + " materials[0],\n", + " materials[1],\n", + " settings=interface_settings\n", + ")" ], "metadata": { - "collapsed": false - } + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-05-07T20:04:41.283030Z", + "start_time": "2024-05-07T20:04:40.296061Z" + } + }, + "execution_count": 6 }, { "cell_type": "markdown", "source": [ - "### 4.2. Select the termination" + "### 4.2. Select the termination\n", + "Possible terminations for the interface are found by the interface builder. The user can select the termination interactively or use the default one." ], "metadata": { "collapsed": false @@ -198,36 +262,29 @@ }, { "cell_type": "code", - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Selected termination: ('C_P6/mmm_2', 'Ni_R-3m_1')\n" + ] + } + ], "source": [ "terminations = interface_builder.terminations\n", + "from utils.io import user_select_object_by_index\n", "\n", - "\n", - "# TODO: move to utils (ot made?)\n", - "def select_termination():\n", - " prompt_text = \"Select termination by index:\\n\" + \"\\n\".join(\n", - " f\"{i}: {t}\" for i, t in enumerate(terminations))\n", - "\n", - " selected_termination_index = input(prompt_text)\n", - "\n", - " try:\n", - " selected_termination_index = int(selected_termination_index)\n", - " except ValueError:\n", - " print(\"Invalid input. Please enter a valid integer.\")\n", - " return\n", - "\n", - " if selected_termination_index < 0 or selected_termination_index >= len(terminations):\n", - " print(\"Invalid index. Please try again.\")\n", - " else:\n", - " selected_termination = terminations[selected_termination_index]\n", - " print(\"Selected termination: \", selected_termination)\n", - " return selected_termination\n", - "\n", - "selected_termination = select_termination() if IS_TERMINATION_SELECTION_INTERACTIVE else DEFAULT_TERMINATION_INDEX" + "selected_termination = user_select_object_by_index(terminations, object_name=\"termination\") if IS_TERMINATION_SELECTION_INTERACTIVE else terminations[TERMINATION_INDEX]" ], "metadata": { - "collapsed": false - } + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-05-07T20:04:42.802069Z", + "start_time": "2024-05-07T20:04:41.284164Z" + } + }, + "execution_count": 7 }, { "cell_type": "markdown", @@ -240,23 +297,35 @@ }, { "cell_type": "code", - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Creating interfaces...\n", + "Found 9 unique interfaces.\n" + ] + } + ], "source": [ "from mat3ra.made.tools.build import create_interfaces\n", "\n", "interface_data_holder = create_interfaces(\n", - " substrate=materials[5],\n", - " layer=materials[3],\n", " settings=interface_settings,\n", " sort_by_strain_and_size=True,\n", " remove_duplicates=True,\n", " interface_builder=interface_builder,\n", - " selected_termination=selected_termination,\n", + " termination=selected_termination,\n", ")" ], "metadata": { - "collapsed": false - } + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-05-07T20:04:44.416835Z", + "start_time": "2024-05-07T20:04:42.759877Z" + } + }, + "execution_count": 8 }, { "cell_type": "markdown", @@ -269,7 +338,17 @@ }, { "cell_type": "code", - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Interface with lowest strain for termination ('C_P6/mmm_2', 'Ni_R-3m_1') (index 0):\n", + " strain: 0.105%\n", + " number of atoms: 5\n" + ] + } + ], "source": [ "print(f\"Interface with lowest strain for termination {selected_termination} (index 0):\")\n", "interfaces = interface_data_holder.get_interfaces_for_termination(selected_termination)\n", @@ -278,8 +357,13 @@ "print(\" number of atoms:\", first_interface.num_sites)" ], "metadata": { - "collapsed": false - } + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-05-07T20:04:44.422060Z", + "start_time": "2024-05-07T20:04:44.416243Z" + } + }, + "execution_count": 9 }, { "cell_type": "markdown", @@ -294,7 +378,1009 @@ }, { "cell_type": "code", - "outputs": [], + "outputs": [ + { + "data": { + "text/html": " \n " + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.plotly.v1+json": { + "data": [ + { + "hoverinfo": "text", + "mode": "markers", + "name": "Index: 0", + "text": [ + "Index: 0
Strain: 0.11%
Atoms: 5" + ], + "x": [ + 0.10500000000000001 + ], + "y": [ + 5 + ], + "type": "scatter" + }, + { + "hoverinfo": "text", + "mode": "markers", + "name": "Index: 1", + "text": [ + "Index: 1
Strain: 0.11%
Atoms: 10" + ], + "x": [ + 0.10500000000000001 + ], + "y": [ + 10 + ], + "type": "scatter" + }, + { + "hoverinfo": "text", + "mode": "markers", + "name": "Index: 2", + "text": [ + "Index: 2
Strain: 0.11%
Atoms: 15" + ], + "x": [ + 0.10500000000000001 + ], + "y": [ + 15 + ], + "type": "scatter" + }, + { + "hoverinfo": "text", + "mode": "markers", + "name": "Index: 3", + "text": [ + "Index: 3
Strain: 0.11%
Atoms: 20" + ], + "x": [ + 0.10500000000000001 + ], + "y": [ + 20 + ], + "type": "scatter" + }, + { + "hoverinfo": "text", + "mode": "markers", + "name": "Index: 4", + "text": [ + "Index: 4
Strain: 0.11%
Atoms: 25" + ], + "x": [ + 0.10500000000000001 + ], + "y": [ + 25 + ], + "type": "scatter" + }, + { + "hoverinfo": "text", + "mode": "markers", + "name": "Index: 5", + "text": [ + "Index: 5
Strain: 0.11%
Atoms: 30" + ], + "x": [ + 0.10500000000000001 + ], + "y": [ + 30 + ], + "type": "scatter" + }, + { + "hoverinfo": "text", + "mode": "markers", + "name": "Index: 6", + "text": [ + "Index: 6
Strain: 0.11%
Atoms: 35" + ], + "x": [ + 0.10500000000000001 + ], + "y": [ + 35 + ], + "type": "scatter" + }, + { + "hoverinfo": "text", + "mode": "markers", + "name": "Index: 7", + "text": [ + "Index: 7
Strain: 0.11%
Atoms: 40" + ], + "x": [ + 0.10500000000000001 + ], + "y": [ + 40 + ], + "type": "scatter" + }, + { + "hoverinfo": "text", + "mode": "markers", + "name": "Index: 8", + "text": [ + "Index: 8
Strain: 0.11%
Atoms: 45" + ], + "x": [ + 0.10500000000000001 + ], + "y": [ + 45 + ], + "type": "scatter" + } + ], + "layout": { + "height": 600, + "hovermode": "closest", + "legend": { + "title": { + "text": "Interfaces Indices" + } + }, + "xaxis": { + "title": { + "text": "Strain (%)" + }, + "type": "log" + }, + "yaxis": { + "title": { + "text": "Number of atoms" + }, + "type": "log" + }, + "template": { + "data": { + "histogram2dcontour": [ + { + "type": "histogram2dcontour", + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0.0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1.0, + "#f0f921" + ] + ] + } + ], + "choropleth": [ + { + "type": "choropleth", + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + } + ], + "histogram2d": [ + { + "type": "histogram2d", + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0.0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1.0, + "#f0f921" + ] + ] + } + ], + "heatmap": [ + { + "type": "heatmap", + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0.0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1.0, + "#f0f921" + ] + ] + } + ], + "heatmapgl": [ + { + "type": "heatmapgl", + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0.0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1.0, + "#f0f921" + ] + ] + } + ], + "contourcarpet": [ + { + "type": "contourcarpet", + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + } + ], + "contour": [ + { + "type": "contour", + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0.0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1.0, + "#f0f921" + ] + ] + } + ], + "surface": [ + { + "type": "surface", + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0.0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1.0, + "#f0f921" + ] + ] + } + ], + "mesh3d": [ + { + "type": "mesh3d", + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + } + ], + "scatter": [ + { + "fillpattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + }, + "type": "scatter" + } + ], + "parcoords": [ + { + "type": "parcoords", + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + } + } + ], + "scatterpolargl": [ + { + "type": "scatterpolargl", + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + } + } + ], + "bar": [ + { + "error_x": { + "color": "#2a3f5f" + }, + "error_y": { + "color": "#2a3f5f" + }, + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "bar" + } + ], + "scattergeo": [ + { + "type": "scattergeo", + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + } + } + ], + "scatterpolar": [ + { + "type": "scatterpolar", + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + } + } + ], + "histogram": [ + { + "marker": { + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "histogram" + } + ], + "scattergl": [ + { + "type": "scattergl", + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + } + } + ], + "scatter3d": [ + { + "type": "scatter3d", + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + } + } + ], + "scattermapbox": [ + { + "type": "scattermapbox", + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + } + } + ], + "scatterternary": [ + { + "type": "scatterternary", + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + } + } + ], + "scattercarpet": [ + { + "type": "scattercarpet", + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + } + } + ], + "carpet": [ + { + "aaxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "baxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "type": "carpet" + } + ], + "table": [ + { + "cells": { + "fill": { + "color": "#EBF0F8" + }, + "line": { + "color": "white" + } + }, + "header": { + "fill": { + "color": "#C8D4E3" + }, + "line": { + "color": "white" + } + }, + "type": "table" + } + ], + "barpolar": [ + { + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "barpolar" + } + ], + "pie": [ + { + "automargin": true, + "type": "pie" + } + ] + }, + "layout": { + "autotypenumbers": "strict", + "colorway": [ + "#636efa", + "#EF553B", + "#00cc96", + "#ab63fa", + "#FFA15A", + "#19d3f3", + "#FF6692", + "#B6E880", + "#FF97FF", + "#FECB52" + ], + "font": { + "color": "#2a3f5f" + }, + "hovermode": "closest", + "hoverlabel": { + "align": "left" + }, + "paper_bgcolor": "white", + "plot_bgcolor": "#E5ECF6", + "polar": { + "bgcolor": "#E5ECF6", + "angularaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "radialaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "ternary": { + "bgcolor": "#E5ECF6", + "aaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "baxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "caxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "coloraxis": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "colorscale": { + "sequential": [ + [ + 0.0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1.0, + "#f0f921" + ] + ], + "sequentialminus": [ + [ + 0.0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1.0, + "#f0f921" + ] + ], + "diverging": [ + [ + 0, + "#8e0152" + ], + [ + 0.1, + "#c51b7d" + ], + [ + 0.2, + "#de77ae" + ], + [ + 0.3, + "#f1b6da" + ], + [ + 0.4, + "#fde0ef" + ], + [ + 0.5, + "#f7f7f7" + ], + [ + 0.6, + "#e6f5d0" + ], + [ + 0.7, + "#b8e186" + ], + [ + 0.8, + "#7fbc41" + ], + [ + 0.9, + "#4d9221" + ], + [ + 1, + "#276419" + ] + ] + }, + "xaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "automargin": true, + "zerolinewidth": 2 + }, + "yaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "automargin": true, + "zerolinewidth": 2 + }, + "scene": { + "xaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white", + "gridwidth": 2 + }, + "yaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white", + "gridwidth": 2 + }, + "zaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white", + "gridwidth": 2 + } + }, + "shapedefaults": { + "line": { + "color": "#2a3f5f" + } + }, + "annotationdefaults": { + "arrowcolor": "#2a3f5f", + "arrowhead": 0, + "arrowwidth": 1 + }, + "geo": { + "bgcolor": "white", + "landcolor": "#E5ECF6", + "subunitcolor": "white", + "showland": true, + "showlakes": true, + "lakecolor": "white" + }, + "title": { + "x": 0.05 + }, + "mapbox": { + "style": "light" + } + } + } + }, + "config": { + "plotlyServerURL": "https://plot.ly" + } + }, + "text/html": "
" + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Terminations: \n", + " [('C_P6/mmm_2', 'Ni_R-3m_1')]\n" + ] + } + ], "source": [ "from utils.plot import plot_strain_vs_atoms\n", "\n", @@ -309,8 +1395,13 @@ "print(\"Terminations: \\n\", interface_data_holder.terminations)" ], "metadata": { - "collapsed": false - } + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-05-07T20:04:44.633104Z", + "start_time": "2024-05-07T20:04:44.420896Z" + } + }, + "execution_count": 10 }, { "cell_type": "markdown", @@ -337,8 +1428,13 @@ " interfaces_slice_range_or_index)" ], "metadata": { - "collapsed": false - } + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-05-07T20:04:44.633708Z", + "start_time": "2024-05-07T20:04:44.630001Z" + } + }, + "execution_count": 11 }, { "cell_type": "markdown", @@ -351,13 +1447,31 @@ }, { "cell_type": "code", - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": "GridBox(children=(VBox(children=(Label(value='Ni3C2 - Material 0', layout=Layout(height='30px', overflow='hidd…", + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "015146a9876848f1a0b0fbebd9340312" + } + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "visualize(selected_interfaces, repetitions=[1,1,1], rotation=\"0x\")" + "visualize(selected_interfaces, repetitions=[1, 1, 1], rotation=\"0x\")" ], "metadata": { - "collapsed": false - } + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-05-07T20:04:44.633998Z", + "start_time": "2024-05-07T20:04:44.630076Z" + } + }, + "execution_count": 12 }, { "cell_type": "markdown", @@ -368,11 +1482,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": { + "ExecuteTime": { + "end_time": "2024-05-07T20:04:44.634051Z", + "start_time": "2024-05-07T20:04:44.630525Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Data for materials written to uploads/Ni3 C2.json\n" + ] + } + ], "source": [ "from utils.jupyterlite import set_data\n", + "\n", "set_data(\"materials\", selected_interfaces)" ] } diff --git a/utils/io.py b/utils/io.py new file mode 100644 index 00000000..ce6f9750 --- /dev/null +++ b/utils/io.py @@ -0,0 +1,24 @@ +from typing import Any, List, Optional + + +def user_select_object_by_index( + objects: List[Any], object_name: str = "object", prompt_head: Optional[str] = None +) -> Any: + prompt_head = prompt_head or f"Select {object_name} by index:\n" + prompt_body = "\n".join(f"{i}: {t}" for i, t in enumerate(objects)) + + selected_index_str = input(prompt_head + prompt_body) + try: + selected_index = int(selected_index_str) + except ValueError: + print("Invalid input. Please enter a valid integer.") + return user_select_object_by_index(objects, object_name, prompt_head) + + assert isinstance(selected_index, int) + + if selected_index < 0 or selected_index >= len(objects): + print("Invalid index.") + return user_select_object_by_index(objects, object_name, prompt_head) + + print(f"Selected {object_name}: ", objects[selected_index]) + return objects[selected_index]