Skip to content

SOF-7599 update: use new made for slab generation #227

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
144 changes: 100 additions & 44 deletions other/materials_designer/create_slab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
"cell_type": "code",
Copy link
Member

@timurbazhirov timurbazhirov May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use get_slabs from crystal_lattice_planes


Reply via ReviewNB

Copy link
Member

@timurbazhirov timurbazhirov Jun 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line #2.    print("Available terminations:", [str(t) for t in terminations])

The numbering needs to be fixed, the logic should be:

2. Find possible terminations and select one

  • Create CrystalPlanes
  • Get all unique slabs and their corresponding terminations
  • Visualize all slabs
  • Select termination (or use the first one, with index zero by default)

3. Create a slab for the selected termination


Reply via ReviewNB

"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",
Expand Down Expand Up @@ -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": {
Expand All @@ -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": {
Expand All @@ -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\")"
],
Expand All @@ -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
},
Expand All @@ -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
Expand All @@ -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": {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
},
Expand All @@ -340,6 +395,7 @@
"cell_type": "code",
"source": [
"from utils.jupyterlite import set_materials\n",
"\n",
"set_materials(slab)"
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

Expand Down