Skip to content

Commit

Permalink
Merge pull request #123 from Exabyte-io/feature/SOF-7352
Browse files Browse the repository at this point in the history
feature/SOF 7352
  • Loading branch information
VsevolodX committed May 13, 2024
2 parents 9aeadce + 3e51a12 commit aa30aaf
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 67 deletions.
172 changes: 115 additions & 57 deletions other/materials_designer/create_interface_with_min_strain_zsl.ipynb
Expand Up @@ -36,7 +36,8 @@
"source": [
"## 1. Set Input Parameters\n",
"\n",
"### 1.1. Select Substrate and Layer from Input Materials"
"### 1.1. Set Substrate and Layer Parameters \n",
"Additionally, specify if the termination selection is done using interactive prompt, or the via selecting the termination index in the code."
]
},
{
Expand All @@ -55,7 +56,10 @@
" \"THICKNESS\": 1, # in layers\n",
"}\n",
"\n",
"USE_CONVENTIONAL_CELL = True # if True, the surface plane is constructed using miller indices of the conventional cell"
"USE_CONVENTIONAL_CELL = True # if True, the surface plane is constructed using miller indices of the conventional cell\n",
"\n",
"IS_TERMINATION_SELECTION_INTERACTIVE = False # if True, the user can select the termination interactively\n",
"TERMINATION_INDEX = 0 # the default termination index that is used if no termination selected, ignored in interactive mode"
]
},
{
Expand Down Expand Up @@ -98,6 +102,15 @@
" \"MAX_LENGTH_TOL\": 0.03, # supercell lattice vectors lengths within this tolerance are considered equal\n",
" \"MAX_ANGLE_TOL\": 0.01, # supercell lattice angles within this tolerance are considered equal\n",
" \"STRAIN_TOL\": 10e-6, # strains within this tolerance are considered equal\n",
"}\n",
"\n",
"# unify the parameters\n",
"interface_settings = {\n",
" \"SUBSTRATE_PARAMETERS\": SUBSTRATE_PARAMETERS,\n",
" \"LAYER_PARAMETERS\": LAYER_PARAMETERS,\n",
" \"USE_CONVENTIONAL_CELL\": USE_CONVENTIONAL_CELL,\n",
" \"ZSL_PARAMETERS\": ZSL_PARAMETERS,\n",
" \"INTERFACE_PARAMETERS\": INTERFACE_PARAMETERS,\n",
"}"
]
},
Expand All @@ -116,11 +129,12 @@
"outputs": [],
"source": [
"import sys\n",
"\n",
"if sys.platform == \"emscripten\":\n",
" import micropip\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\")"
" await install_packages(\"create_interface_with_min_strain_zsl.ipynb\", \"../../config.yml\")"
]
},
{
Expand All @@ -142,7 +156,7 @@
"# Get the list of input materials and load them into `materials_in` variable\n",
"get_data(\"materials_in\", globals())\n",
"materials = list(map(Material, globals()[\"materials_in\"]))\n",
"visualize(materials, repetitions=[1,1,1], rotation=\"0x\")"
"visualize(materials, repetitions=[1, 1, 1], rotation=\"0x\")"
],
"metadata": {
"collapsed": false
Expand All @@ -154,91 +168,126 @@
"source": [
"## 4. Create interfaces\n",
"\n",
"### 4.1. Extract Interfaces and Terminations\n",
"### 4.1. Initialize the interface builder\n",
"\n",
"Extract all possible layer/substrate supercell combinations within the maximum area including different terminations."
"Initialize the interface builder with the materials and interface settings."
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [],
"trusted": true
},
"outputs": [],
"source": [
"from mat3ra.made.tools.build import create_interfaces\n",
"from mat3ra.made.tools.build import init_interface_builder\n",
"\n",
"interface_data_holder = create_interfaces(\n",
"interface_builder = init_interface_builder(\n",
" substrate=materials[0],\n",
" layer=materials[1],\n",
" settings={\n",
" \"SUBSTRATE_PARAMETERS\": SUBSTRATE_PARAMETERS,\n",
" \"LAYER_PARAMETERS\": LAYER_PARAMETERS,\n",
" \"USE_CONVENTIONAL_CELL\": USE_CONVENTIONAL_CELL,\n",
" \"ZSL_PARAMETERS\": ZSL_PARAMETERS,\n",
" \"INTERFACE_PARAMETERS\": INTERFACE_PARAMETERS,\n",
" },\n",
" sort_by_strain_and_size=True,\n",
" remove_duplicates=True,\n",
" settings=interface_settings\n",
")"
]
],
"metadata": {
"collapsed": false
},
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4.2. Print out the interfaces and terminations"
]
"### 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
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"Found terminations:\", interface_data_holder.terminations)\n",
"print(f\"Number of interfaces for a termination: {len(interface_data_holder.get_interfaces_for_termination(0))}\")"
]
"from utils.io import ui_prompt_select_array_element_by_index, ui_prompt_select_array_element_by_index_pyodide\n",
"terminations = interface_builder.terminations\n",
"\n",
"if IS_TERMINATION_SELECTION_INTERACTIVE:\n",
" if sys.platform == \"emscripten\":\n",
" selected_termination = await ui_prompt_select_array_element_by_index_pyodide(terminations, element_name=\"termination\")\n",
" else:\n",
" selected_termination = ui_prompt_select_array_element_by_index(terminations, element_name=\"termination\")\n",
"else: \n",
" selected_termination = terminations[TERMINATION_INDEX]"
],
"metadata": {
"collapsed": false
},
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4.2. Print out interfaces with the lowest strain for each termination"
]
"### 4.3. Create interfaces for the selected termination"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for termination in interface_data_holder.terminations:\n",
" print(f\"Interface with lowest strain for termination {termination} (index 0):\")\n",
" interfaces = interface_data_holder.get_interfaces_for_termination(termination)\n",
" first_interface = interfaces[0]\n",
" print(f\" strain: {first_interface.get_mean_abs_strain() * 100:.3f}%\")\n",
" print(\" number of atoms:\", first_interface.num_sites)"
]
"from mat3ra.made.tools.build import create_interfaces\n",
"\n",
"interface_data_holder = create_interfaces(\n",
" settings=interface_settings,\n",
" sort_by_strain_and_size=True,\n",
" remove_duplicates=True,\n",
" interface_builder=interface_builder,\n",
" termination=selected_termination,\n",
")"
],
"metadata": {
"collapsed": false
},
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### 4.3. Print out interface with the lowest strain for selected termination"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"outputs": [],
"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",
"first_interface = interfaces[0]\n",
"print(f\" strain: {first_interface.get_mean_abs_strain() * 100:.3f}%\")\n",
"print(\" number of atoms:\", first_interface.num_sites)"
],
"metadata": {
"collapsed": false
},
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Plot the results\n",
"\n",
"Plot the number of atoms vs strain. Adjust the parameters as needed.\n"
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from utils.plot import plot_strain_vs_atoms\n",
Expand All @@ -252,31 +301,39 @@
"plot_strain_vs_atoms(interface_data_holder, PLOT_SETTINGS)\n",
"\n",
"print(\"Terminations: \\n\", interface_data_holder.terminations)"
]
],
"metadata": {
"collapsed": false
},
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Select the interface to pass outside this kernel\n",
"\n",
"### 6.1. Select the interface with the desired termination and strain\n",
"\n",
"Select the index for termination first, and for it - the index in the list of corresponding interfaces sorted by strain (index 0 has minimum strain)."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Could be either the termination as tuple, e.g. `('Ni_P6/mmm_1', 'C_C2/m_2')` or its index: `0`\n",
"termination_or_its_index = 0\n",
"termination_or_its_index = selected_termination\n",
"# select the first interface with the lowest strain and the smallest number of atoms\n",
"interfaces_slice_range_or_index = slice(0,1)\n",
"interfaces_slice_range_or_index = slice(0, 1)\n",
"selected_interfaces = interface_data_holder.get_interfaces_as_materials(termination_or_its_index, interfaces_slice_range_or_index)"
]
],
"metadata": {
"collapsed": false
},
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -291,7 +348,7 @@
"cell_type": "code",
"outputs": [],
"source": [
"visualize(selected_interfaces, repetitions=[1,1,1], rotation=\"0x\")"
"visualize(selected_interfaces, repetitions=[1, 1, 1], rotation=\"0x\")"
],
"metadata": {
"collapsed": false
Expand All @@ -302,7 +359,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 6.3. Pass data to the outside runtime\n"
"### 6.3. Pass data to the outside runtime"
]
},
{
Expand All @@ -312,6 +369,7 @@
"outputs": [],
"source": [
"from utils.jupyterlite import set_data\n",
"\n",
"set_data(\"materials\", selected_interfaces)"
]
}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -10,7 +10,7 @@ dependencies = [
"matplotlib>=3.4.1",
"pandas>=1.5.3",
"pymatgen>=2024.4.13",
"mat3ra-made>=2024.5.3.post0",
"mat3ra-made>=2024.5.9.post0",
"mat3ra-utils"
]

Expand Down

0 comments on commit aa30aaf

Please sign in to comment.