Skip to content

Commit

Permalink
Merge branch 'dev' into feature/SOF-7352
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed May 7, 2024
2 parents 22d7e48 + 9aeadce commit f1ebb87
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 47 deletions.
81 changes: 39 additions & 42 deletions other/materials_designer/create_interface_with_min_strain_zsl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"outputs": [],
"source": [
"SUBSTRATE_PARAMETERS = {\n",
" \"MILLER_INDICES\": (0, 0, 1), # the miller indices of the interfacial plane\n",
" \"THICKNESS\": 1, # in layers\n",
" \"MILLER_INDICES\": (1, 1, 1), # the miller indices of the interfacial plane\n",
" \"THICKNESS\": 3, # in layers\n",
"}\n",
"\n",
"LAYER_PARAMETERS = {\n",
Expand Down Expand Up @@ -127,14 +127,11 @@
"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",
"\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 @@ -151,7 +148,7 @@
"from mat3ra.made.material import Material\n",
"from utils.jupyterlite import get_data\n",
"\n",
"from utils.visualize import visualize\n",
"from utils.visualize import visualize_materials as visualize\n",
"\n",
"# Get the list of input materials and load them into `materials_in` variable\n",
"get_data(\"materials_in\", globals())\n",
Expand All @@ -160,8 +157,7 @@
],
"metadata": {
"collapsed": false
},
"execution_count": null
}
},
{
"cell_type": "markdown",
Expand All @@ -183,14 +179,13 @@
"from mat3ra.made.tools.build import init_interface_builder\n",
"\n",
"interface_builder = init_interface_builder(\n",
" materials[5], \n",
" materials[5],\n",
" materials[3], settings=interface_settings\n",
" )"
],
"metadata": {
"collapsed": false
},
"execution_count": null
}
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -219,7 +214,7 @@
" selected_termination_index = int(selected_termination_index)\n",
" except ValueError:\n",
" print(\"Invalid input. Please enter a valid integer.\")\n",
" return \n",
" return\n",
"\n",
" if selected_termination_index < 0 or selected_termination_index >= len(terminations):\n",
" print(\"Invalid index. Please try again.\")\n",
Expand All @@ -232,8 +227,7 @@
],
"metadata": {
"collapsed": false
},
"execution_count": null
}
},
{
"cell_type": "markdown",
Expand All @@ -246,11 +240,6 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [],
"trusted": true
},
"outputs": [],
"source": [
"from mat3ra.made.tools.build import create_interfaces\n",
Expand All @@ -264,41 +253,47 @@
" interface_builder=interface_builder,\n",
" selected_termination=selected_termination,\n",
")"
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4.3. Print out interface with the lowest strain for selected termination"
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"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
}
},
{
"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 @@ -312,23 +307,26 @@
"plot_strain_vs_atoms(interface_data_holder, PLOT_SETTINGS)\n",
"\n",
"print(\"Terminations: \\n\", interface_data_holder.terminations)"
]
],
"metadata": {
"collapsed": false
}
},
{
"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",
Expand All @@ -337,7 +335,10 @@
"interfaces_slice_range_or_index = slice(0, 1)\n",
"selected_interfaces = interface_data_holder.get_interfaces_as_materials(termination_or_its_index,\n",
" interfaces_slice_range_or_index)"
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
Expand All @@ -352,14 +353,11 @@
"cell_type": "code",
"outputs": [],
"source": [
"from utils.visualize import visualize\n",
"\n",
"visualize(selected_interfaces, repetitions=[1, 1, 1], rotation=\"-90x\")"
"visualize(selected_interfaces, repetitions=[1,1,1], rotation=\"0x\")"
],
"metadata": {
"collapsed": false
},
"execution_count": null
}
},
{
"cell_type": "markdown",
Expand All @@ -375,7 +373,6 @@
"outputs": [],
"source": [
"from utils.jupyterlite import set_data\n",
"\n",
"set_data(\"materials\", selected_interfaces)"
]
}
Expand Down
10 changes: 5 additions & 5 deletions utils/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from mat3ra.utils.array import convert_to_array_if_not


def get_material_visualization_html(material: Material, title: str, rotation="0x,0y,0z", repetitions=[1, 1, 1]):
def get_material_image(material: Material, title: str, rotation="0x,0y,0z", repetitions=[1, 1, 1]):
"""
Returns an image of the material structure with the specified title.
Args:
material (Material): Material object to visualize.
title (str): Title of the image.
rotation (str): Rotation of the image.
rotation (str): Rotation of the image, in degrees around the x, y, and z axes (e.g., "-90x,90y,0z").
repetitions (list): Repetitions alongside a,b,c lattice vectors.
Returns:
Expand Down Expand Up @@ -68,7 +68,7 @@ def create_responsive_image_grid(image_tuples, max_columns=3):
return grid


def visualize(
def visualize_materials(
materials: Union[List[Material], Material],
title: str = "Material",
repetitions=[1, 1, 1],
Expand All @@ -79,15 +79,15 @@ def visualize(
Args:
materials (list|Material): Single Material or a List of Material objects to visualize.
title (str): Title to add to each image.
repetitions (list): Repetitions alongside a,b,c lattice vectors.
repetitions (List[int]): Repetitions alongside a,b,c lattice vectors.
rotation (str): Rotation of the image, in degrees around the x, y, and z axes (e.g., "-90x,90y,0z").
Returns:
"""
materials = convert_to_array_if_not(materials)
items = [
get_material_visualization_html(material, title=f"{title} {i}", rotation=rotation, repetitions=repetitions)
get_material_image(material, title=f"{title} {i}", rotation=rotation, repetitions=repetitions)
for i, material in enumerate(materials)
]

Expand Down

0 comments on commit f1ebb87

Please sign in to comment.