Skip to content

Commit

Permalink
Merge pull request #115 from Exabyte-io/update/SOF-7288
Browse files Browse the repository at this point in the history
Update/SOF-7288
  • Loading branch information
VsevolodX committed Mar 30, 2024
2 parents c45a083 + f68e612 commit 69352b9
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 88 deletions.
14 changes: 10 additions & 4 deletions other/jupyterlite/utils.py
Expand Up @@ -69,22 +69,28 @@ async def install_packages(notebook_name, requirements_path="config.yml", verbos
requirements_hash = str(hash(json.dumps(requirements)))
if os.environ.get("requirements_hash") != requirements_hash:
packages_default_common = requirements.get("default", {}).get("packages_common", []) or []
packages_default_environment_specific = requirements.get("default", {}).get(f"packages_{ENVIRONMENT.value}", []) or []
packages_default_environment_specific = (
requirements.get("default", {}).get(f"packages_{ENVIRONMENT.value}", []) or []
)

notebook_requirements = next(
(cfg for cfg in requirements.get("notebooks", []) if cfg.get("name") == notebook_name), None
)
if notebook_requirements:
packages_notebook_common = notebook_requirements.get("packages_common", []) or []
packages_notebook_environment_specific= notebook_requirements.get(f"packages_{ENVIRONMENT.value}", []) or []
packages_notebook_environment_specific = (
notebook_requirements.get(f"packages_{ENVIRONMENT.value}", []) or []
)
else:
raise ValueError(f"No packages found for notebook {notebook_name}")

# Note: environment specific packages have to be installed first,
# because in Pyodide common packages might depend on them
packages = [
*packages_default_common,
*packages_default_environment_specific,
*packages_notebook_common,
*packages_notebook_environment_specific,
*packages_default_common,
*packages_notebook_common,
]

for pkg in packages:
Expand Down
92 changes: 52 additions & 40 deletions other/materials_designer/create_interface_with_min_strain_zsl.ipynb
Expand Up @@ -10,8 +10,7 @@
"\n",
"<h2 style=\"color:green\">Usage</h2>\n",
"\n",
"0. Make sure to select Input Materials\n",
"1. Execute \"Run first: ...\" cell below to load Input Materials into the current kernel\n",
"1. Make sure to select Input Materials\n",
"2. Set Input Parameters (e.g. `MILLER_INDICES`, `THICKNESS`, `MAX_AREA`) below or use the default values\n",
"3. Click \"Run\" > \"Run All Cells\" to run all cells\n",
"4. Wait for the run to complete (depending on the area, it can take 1-2 min or more). Scroll down to view cell results.\n",
Expand All @@ -31,25 +30,6 @@
"3. When the strain matching is finished, the interface with the lowest strain (and the smallest number of atoms) is selected. We create the corresponding supercells and place them at a specified distance from each other (note no shift is performed currently).\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 style=\"color:red\">Run first: load input materials in current kernel</h2>\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from jupyterlite.utils import get_data\n",
"\n",
"# Get the list of input materials and load them into `materials_in` variable\n",
"get_data(\"materials_in\", globals())"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -75,7 +55,9 @@
" \"MATERIAL_INDEX\": 1, # the index of the material in the materials_in list\n",
" \"MILLER_INDICES\": (0, 0, 1), # the miller indices of the interfacial plane\n",
" \"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"
]
},
{
Expand Down Expand Up @@ -143,12 +125,45 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Create interfaces\n",
"## 3. Load and prepare input Materials\n"
]
},
{
"cell_type": "code",
"outputs": [],
"source": [
"from jupyterlite.utils import get_data\n",
"from pymatgen.analysis.structure_analyzer import SpacegroupAnalyzer\n",
"from src.utils import to_pymatgen\n",
"\n",
"# Get the list of input materials and load them into `materials_in` variable\n",
"get_data(\"materials_in\", globals())\n",
"\n",
"if \"materials_in\" in globals():\n",
" pymatgen_materials = [to_pymatgen(item) for item in materials_in]\n",
" if USE_CONVENTIONAL_CELL: pymatgen_materials = [SpacegroupAnalyzer(item).get_conventional_standard_structure() for\n",
" item in pymatgen_materials]\n",
"\n",
" for material in pymatgen_materials:\n",
" print(material, \"\\n\")"
],
"metadata": {
"collapsed": false
},
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"## 4. Create interfaces\n",
"\n",
"### 3.1. Extract Interfaces and Terminations\n",
"### 4.1. Extract Interfaces and Terminations\n",
"\n",
"Extract all possible layer/substrate supercell combinations within the maximum area including different terminations."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand All @@ -160,14 +175,11 @@
"outputs": [],
"source": [
"from src.pymatgen_coherent_interface_builder import CoherentInterfaceBuilder, ZSLGenerator\n",
"from src.utils import to_pymatgen\n",
"\n",
"if \"materials_in\" in globals():\n",
" pymatgen_materials = [to_pymatgen(item) for item in materials_in]\n",
"for material in pymatgen_materials:\n",
" print(material, \"\\n\")\n",
"\n",
"from src.utils import translate_to_bottom\n",
"\n",
"# Translate the materials to the bottom of the cell to allow for multilayer heterostructures creation\n",
"pymatgen_materials = [translate_to_bottom(item) for item in pymatgen_materials]\n",
" \n",
"def create_interfaces(settings):\n",
" print(\"Creating interfaces...\")\n",
" zsl = ZSLGenerator(\n",
Expand Down Expand Up @@ -221,7 +233,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3.2. Print out the interfaces and terminations"
"### 5.2. Print out the interfaces and terminations"
]
},
{
Expand All @@ -239,9 +251,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Sort interfaces by strain\n",
"## 5. Sort interfaces by strain\n",
"\n",
"### 4.1. Sort all interfaces"
"### 5.1. Sort all interfaces"
]
},
{
Expand Down Expand Up @@ -271,7 +283,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4.2. Print out interfaces with lowest strain for each termination"
"### 5.2. Print out interfaces with lowest strain for each termination"
]
},
{
Expand All @@ -291,7 +303,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Plot the results\n",
"## 6. Plot the results\n",
"\n",
"Plot the number of atoms vs strain. Adjust the parameters as needed.\n"
]
Expand Down Expand Up @@ -367,9 +379,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Select the interface to pass outside this kernel\n",
"## 7. Select the interface to pass outside this kernel\n",
"\n",
"### 6.1. Select the interface with the desired termination and strain\n",
"### 7.1. Select the interface with the desired termination and strain\n",
"\n",
"The data in `sorted_interfaces` now contains an object with the following structure:\n",
"\n",
Expand Down Expand Up @@ -409,7 +421,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 6.2. Pass data to the outside runtime\n"
"### 7.2. Pass data to the outside runtime\n"
]
},
{
Expand Down
Expand Up @@ -11,8 +11,7 @@
"\n",
"<h2 style=\"color:green\">Usage</h2>\n",
"\n",
"0. Make sure to select Input Materials\n",
"1. Execute \"Run first: ...\" cell below to load Input Materials into the current kernel\n",
"1. Make sure to select Input Materials\n",
"2. Set Input Parameters (e.g. `THICKNESS`, `MAX_AREA`, `FMAX`) below or use the default values\n",
"3. Click \"Run\" > \"Run All\" to run all cells\n",
"4. Wait for the run to complete (depending on the parameters it can take a few min or more). Scroll down to view cell results.\n",
Expand All @@ -29,25 +28,6 @@
"2. The interface with the lowest strain is selected and relaxed using the optimizer selected below (BFGS, by default). The EMT potential is used as an energy calculator.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 style=\"color:red\">Run first: load input materials in current kernel</h2>\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from jupyterlite.utils import get_data\n",
"\n",
"# Get the list of input materials and load them into `materials_in` variable\n",
"get_data(\"materials_in\", globals())"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -147,13 +127,45 @@
"await install_packages(\"create_interface_with_min_strain_zsl.ipynb\")"
]
},
{
"cell_type": "markdown",
"source": [
"## 3. Load and prepare Input Materials"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"outputs": [],
"source": [
"from jupyterlite.utils import get_data\n",
"from pymatgen.analysis.structure_analyzer import SpacegroupAnalyzer\n",
"from src.utils import to_pymatgen\n",
"\n",
"# Get the list of input materials and load them into `materials_in` variable\n",
"get_data(\"materials_in\", globals())\n",
"\n",
"if \"materials_in\" in globals():\n",
" pymatgen_materials = [to_pymatgen(item) for item in materials_in]\n",
" if USE_CONVENTIONAL_CELL: pymatgen_materials = [SpacegroupAnalyzer(item).get_conventional_standard_structure() for\n",
" item in pymatgen_materials]\n",
"\n",
" for material in pymatgen_materials:\n",
" print(material, \"\\n\")"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Create interfaces\n",
"## 4. Create interfaces\n",
"\n",
"### 3.1. Extract Interfaces and Terminations\n",
"### 4.1. Extract Interfaces and Terminations\n",
"\n",
"Extract all possible layer/substrate supercell combinations within the maximum area including different terminations.\n"
]
Expand All @@ -168,17 +180,10 @@
"outputs": [],
"source": [
"from src.pymatgen_coherent_interface_builder import CoherentInterfaceBuilder, ZSLGenerator\n",
"from pymatgen.analysis.structure_analyzer import SpacegroupAnalyzer\n",
"from src.utils import to_pymatgen\n",
"\n",
"if \"materials_in\" in globals():\n",
" pymatgen_materials = [to_pymatgen(item) for item in materials_in]\n",
" if USE_CONVENTIONAL_CELL: pymatgen_materials = [SpacegroupAnalyzer(item).get_conventional_standard_structure() for\n",
" item in pymatgen_materials]\n",
"\n",
" for material in pymatgen_materials:\n",
" print(material, \"\\n\")\n",
"from src.utils import translate_to_bottom\n",
"\n",
"# Translate the materials to the bottom of the cell to allow for multilayer heterostructures creation\n",
"pymatgen_materials = [translate_to_bottom(item) for item in pymatgen_materials]\n",
"\n",
"def create_interfaces(settings: dict):\n",
" print(\"Creating interfaces...\")\n",
Expand Down Expand Up @@ -233,7 +238,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3.2. Print out the interfaces and terminations\n"
"### 4.2. Print out the interfaces and terminations\n"
]
},
{
Expand All @@ -251,9 +256,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Sort interfaces by strain\n",
"## 5. Sort interfaces by strain\n",
"\n",
"### 4.1. Sort all interfaces\n"
"### 5.1. Sort all interfaces\n"
]
},
{
Expand Down Expand Up @@ -283,7 +288,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4.2. Print out interfaces with lowest strain for each termination\n"
"### 5.2. Print out interfaces with lowest strain for each termination\n"
]
},
{
Expand All @@ -303,7 +308,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Plot the results\n",
"## 6. Plot the results\n",
"\n",
"Plot the number of atoms vs strain. Adjust the parameters as needed.\n"
]
Expand Down Expand Up @@ -379,7 +384,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Select the interface with the desired termination and strain\n",
"## 7. Select the interface with the desired termination and strain\n",
"\n",
"The data in `sorted_interfaces` now contains an object with the following structure:\n",
"\n",
Expand Down Expand Up @@ -421,9 +426,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 7. Apply relaxation to the interface\n",
"## 8. Apply relaxation to the interface\n",
"\n",
"### 7.1. Apply relaxation to the selected interface with ASE\n",
"### 8.1. Apply relaxation to the selected interface with ASE\n",
"\n",
"Optimizer is set from the available options in the settings and EMT is used as the energy calculator."
]
Expand Down Expand Up @@ -516,7 +521,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 7.2. View structure before and after relaxation\n"
"### 8.2. View structure before and after relaxation\n"
]
},
{
Expand Down Expand Up @@ -579,7 +584,7 @@
"collapsed": false
},
"source": [
"### 7.3. Calculate the energy metrics\n",
"### 8.3. Calculate the energy metrics\n",
"Calculate the energy metrics for the relaxed interface.\n",
"The effective delta energy per area calculation accounts for the energy contribution of each component (substrate and layer) relative to their proportion in the overall interface. \n"
]
Expand Down Expand Up @@ -675,7 +680,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 8. Pass relaxed interface to Materials Designer"
"## 9. Pass relaxed interface to Materials Designer"
]
},
{
Expand Down

0 comments on commit 69352b9

Please sign in to comment.