diff --git a/other/materials_designer/create_slab.ipynb b/other/materials_designer/create_slab.ipynb index bf6e8856..060f2865 100644 --- a/other/materials_designer/create_slab.ipynb +++ b/other/materials_designer/create_slab.ipynb @@ -42,12 +42,12 @@ "cell_type": "code", "source": [ "# Enable interactive selection of terminations via UI prompt\n", - "IS_TERMINATIONS_SELECTION_INTERACTIVE = False \n", + "IS_TERMINATIONS_SELECTION_INTERACTIVE = False\n", "\n", - "MILLER_INDICES = (0, 0, 1)\n", + "MILLER_INDICES = (0, 1, 1)\n", "THICKNESS = 3 # in atomic layers\n", "VACUUM = 10.0 # in angstroms\n", - "XY_SUPERCELL_MATRIX = [[1, 0], [0, 1]]\n", + "XY_SUPERCELL_MATRIX = [[2, 0], [0, 2]]\n", "USE_ORTHOGONAL_Z = True\n", "USE_CONVENTIONAL_CELL = True\n", "\n", @@ -79,10 +79,11 @@ "\n", "if sys.platform == \"emscripten\":\n", " import micropip\n", - " \n", + "\n", " await micropip.install('mat3ra-api-examples', deps=False)\n", " await micropip.install('mat3ra-utils')\n", " from mat3ra.utils.jupyterlite.packages import install_packages\n", + "\n", " await install_packages(\"\")" ], "metadata": { @@ -108,6 +109,7 @@ "from utils.jupyterlite import get_materials\n", "\n", "materials = get_materials(globals())\n", + "print(globals()[\"materials_in\"][0])\n", "material = materials[0]" ], "metadata": { @@ -131,6 +133,7 @@ "cell_type": "code", "source": [ "from utils.visualize import visualize_materials as visualize\n", + "\n", "visualize(material, repetitions=[3, 3, 1], rotation=\"0x\")\n", "visualize(material, repetitions=[3, 3, 1], rotation=\"-90x\")" ], @@ -155,47 +158,35 @@ "id": "6634dae92a6c07b9" }, { + "metadata": {}, "cell_type": "code", "source": [ - "from mat3ra.made.tools.build.slab import SlabConfiguration\n", + "from mat3ra.made.tools.build.slab.configuration import CrystalLatticePlanes\n", "\n", - "slab_configuration = SlabConfiguration(\n", - " bulk=material,\n", + "crystal_lattice_planes = CrystalLatticePlanes(\n", + " crystal=material,\n", " miller_indices=MILLER_INDICES,\n", - " number_of_layers=THICKNESS, # in atomic layers\n", - " vacuum=VACUUM, # in angstroms\n", - " xy_supercell_matrix=XY_SUPERCELL_MATRIX,\n", - " use_orthogonal_z=USE_ORTHOGONAL_Z,\n", - " use_conventional_cell=USE_CONVENTIONAL_CELL,\n", + " use_conventional_cell=USE_CONVENTIONAL_CELL\n", ")" ], - "metadata": { - "collapsed": false - }, - "id": "3ad6765249610aa4", + "id": "ec30720293c64ecc", "outputs": [], "execution_count": null }, { + "metadata": {}, "cell_type": "markdown", - "source": [ - "### 2.2. Get possible terminations for the slabs" - ], - "metadata": { - "collapsed": false - }, - "id": "afb4c9bb89c8690b" + "source": "## 2.1. Get terminations", + "id": "eb3aeb119d8726ba" }, { + "metadata": {}, "cell_type": "code", "source": [ - "from mat3ra.made.tools.build.slab import get_terminations\n", - "slab_terminations = get_terminations(slab_configuration)" + "terminations = crystal_lattice_planes.get_terminations()\n", + "print(\"Available terminations:\", [str(t) for t in terminations])" ], - "metadata": { - "collapsed": false - }, - "id": "70bec9d69d58b28a", + "id": "68bb05623903b05c", "outputs": [], "execution_count": null }, @@ -212,11 +203,12 @@ { "cell_type": "code", "source": [ - "from mat3ra.made.tools.build.slab import create_slab\n", - "\n", - "slabs = [create_slab(slab_configuration, termination) for termination in slab_terminations]\n", - "\n", - "visualize([{\"material\":slab, \"title\": slab.metadata[\"build\"][\"termination\"]} for slab in slabs ], repetitions=[3, 3, 1], rotation=\"-90x\")" + "# from mat3ra.made.tools.build.slab import create_slab\n", + "#\n", + "# slabs = [create_slab(slab_configuration, termination) for termination in slab_terminations]\n", + "#\n", + "# visualize([{\"material\": slab, \"title\": slab.metadata[\"build\"][\"termination\"]} for slab in slabs], repetitions=[3, 3, 1],\n", + "# rotation=\"-90x\")" ], "metadata": { "collapsed": false @@ -239,7 +231,7 @@ "cell_type": "code", "source": [ "print(\"Terminations\")\n", - "for idx, termination in enumerate(slab_terminations):\n", + "for idx, termination in enumerate(terminations):\n", " print(f\" {idx}: {termination}\")" ], "metadata": { @@ -266,12 +258,13 @@ "\n", "termination_index = TERMINATION_INDEX\n", "\n", - "termination = slab_terminations[termination_index]\n", + "termination = terminations[termination_index]\n", "if IS_TERMINATIONS_SELECTION_INTERACTIVE:\n", " if sys.platform == \"emscripten\":\n", - " termination = await ui_prompt_select_array_element_by_index_pyodide(slab_terminations, element_name=\"termination\")\n", + " termination = await ui_prompt_select_array_element_by_index_pyodide(terminations,\n", + " element_name=\"termination\")\n", " else:\n", - " termination = ui_prompt_select_array_element_by_index(slab_terminations, element_name=\"termination\")" + " termination = ui_prompt_select_array_element_by_index(terminations, element_name=\"termination\")\n" ], "metadata": { "collapsed": false @@ -282,20 +275,84 @@ }, { "cell_type": "markdown", + "source": "## 3. Create Atomic Layers", + "metadata": { + "collapsed": false + }, + "id": "143bc82b430b37d5" + }, + { + "metadata": {}, + "cell_type": "code", "source": [ - "## 3. Create the slab with selected termination" + "from mat3ra.made.tools.build.slab.configuration import AtomicLayersUniqueRepeated\n", + "\n", + "top_termination = termination\n", + "# TODO: should use `from_parameters`\n", + "atomic_layers = AtomicLayersUniqueRepeated(\n", + " crystal=material,\n", + " miller_indices=MILLER_INDICES,\n", + " use_conventional_cell=True,\n", + " number_of_repetitions=THICKNESS,\n", + " termination_top=top_termination,\n", + ")" ], + "id": "f08dc6f4372930e4", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "### 3.1. Specify vacuum", + "id": "c483e6aae37766b1" + }, + { + "metadata": {}, + "cell_type": "code", + "source": [ + "from mat3ra.made.tools.build.slab.configuration import VacuumConfiguration, AxisEnum\n", + "\n", + "vacuum = VacuumConfiguration(direction=AxisEnum.z, size=VACUUM, is_orthogonal=True)" + ], + "id": "ca440d1dad2061da", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "### 3.2. Create slab configuration", + "id": "41066bf389dfd216" + }, + { "metadata": { "collapsed": false }, - "id": "143bc82b430b37d5" + "cell_type": "code", + "source": [ + "from mat3ra.made.tools.build.slab import SlabConfiguration\n", + "\n", + "slab_configuration = SlabConfiguration(\n", + " supercell_xy=XY_SUPERCELL_MATRIX, stack_components=[atomic_layers, vacuum], direction=AxisEnum.z\n", + ")" + ], + "id": "ee1be3faa5341c70", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "### 3.3. Create slab", + "id": "7869f1b09ecd62c6" }, { "cell_type": "code", "source": [ "from mat3ra.made.tools.build.slab import create_slab\n", "\n", - "slab = create_slab(slab_configuration, termination)" + "slab = create_slab(slab_configuration)" ], "metadata": { "collapsed": false @@ -316,9 +373,7 @@ }, { "cell_type": "code", - "source": [ - "visualize(slab, repetitions=[1, 1, 1], rotation=\"0x\")" - ], + "source": "visualize(slab, repetitions=[1, 1, 1], rotation=\"0x\", viewer=\"wave\")", "metadata": { "collapsed": false }, @@ -340,6 +395,7 @@ "cell_type": "code", "source": [ "from utils.jupyterlite import set_materials\n", + "\n", "set_materials(slab)" ], "metadata": { diff --git a/pyproject.toml b/pyproject.toml index 1798bed2..8076a71a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ dependencies = [ "matplotlib>=3.4.1", "pandas>=1.5.3", "pymatgen==2024.4.13", - "mat3ra-made>=2025.4.4.post0", + "mat3ra-made @ git+https://github.com/Exabyte-io/made.git@48bf55d105faac1830ad2c3734a2f1c56a9b8a73", "mat3ra-utils>=2024.6.11.post0", ]