Skip to content

Commit

Permalink
Merge pull request #136 from Exabyte-io/feature/SOF-7402
Browse files Browse the repository at this point in the history
feature/SOF 7402
  • Loading branch information
VsevolodX authored Jul 21, 2024
2 parents a52ef3d + 332da24 commit 1495b96
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 6 deletions.
4 changes: 4 additions & 0 deletions other/materials_designer/Introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"\n",
"This notebook lets user create a single point defect (vacancy, substitution or interstitial). [Click here to open the notebook](create_point_defect.ipynb).\n",
"\n",
"#### [1.5. Adatom on a slab creation](create_adatom_defect.ipynb)\n",
"\n",
"This notebook lets user create a slab and place an adatom at specified location. [Click here to open the notebook](create_adatom_defect.ipynb).\n",
"\n",
"### 2. Data Import\n",
"\n",
"#### [2.1. Materials import from files in ASE-supported formats](import_materials_from_files.ipynb)\n",
Expand Down
293 changes: 293 additions & 0 deletions other/materials_designer/create_adatom_defect.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
"# Create adatom defects in a slab material\n",
"\n",
"Create an adatom by specifying the chemical element, approximate position on surface and distance z, which will be resolved to:\n",
"- the equidistant position between the closes atoms on the surface according to Voronoi tesselation, \n",
"- or the crystal site of the next layer that is closest to specified position.\n",
"\n",
"<h2 style=\"color:green\">Usage</h2>\n",
"\n",
"1. Make sure to select Input Materials (in the outer runtime) before running the notebook.\n",
"1. Set notebook parameters in cell 1.1. below (or use the default values).\n",
"1. Set defects parameters in cell 2.1. (or use default).\n",
"1. Click “Run” > “Run All” to run all cells. \n",
"1. Wait for the run to complete (depending on the parameters can take a few min). \n",
"1. Scroll down to view results. \n",
"\n",
"## Summary\n",
"1. Prepare the Environment: Set up the notebook and install packages, preview the input materials\n",
"1. Create the Defect: Add an adatom defect to the slab material\n",
"2. Visualize the Defect: Visualize the defect structure\n",
"\n",
"## Notes\n",
"\n",
"1. For more information, see [Introduction](Introduction.ipynb)\n",
"<!-- # TODO: use a hashtag-based anchor link to interface creation documention above -->\n"
],
"metadata": {
"collapsed": false
},
"id": "f2e1e795020d7b3f"
},
{
"cell_type": "markdown",
"source": [
"## 1. Prepare the Environment\n",
"### 1.1. Set up defect parameters "
],
"metadata": {
"collapsed": false
},
"id": "5e43ff288847b784"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"DEFECT_TYPE = \"adatom\" \n",
"APPROXIMATE_POSITION_ON_SURFACE = [0.5, 0.5] # Position of the defect in crystal coordinates\n",
"DISTANCE_Z = 2.0 # Distance of the defect from the surface in Angstrom\n",
"CHEMICAL_ELEMENT = \"Si\" # Element to be placed at the site \n",
"MILLER_INDICES = (1, 1, 1) # Miller indices of the surface\n",
"SLAB_THICKNESS = 3 # Thickness of the slab in unit cells\n",
"VACUUM = 6 # Vacuum thickness in Angstrom\n",
"SUPERCELL_MATRIX = [[2, 0, 0], [0, 2, 0], [0, 0, 1]] "
],
"metadata": {
"collapsed": false
},
"id": "9d8b1890b34d850a",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### 1.2. Install Packages\n",
"The step executes only in Pyodide environment. For other environments, the packages should be installed via `pip install` (see [README](../../README.ipynb))."
],
"metadata": {
"collapsed": false
},
"id": "bb64de5ff32649f8"
},
{
"cell_type": "code",
"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_point_defect.ipynb\", \"../../config.yml\")"
],
"metadata": {
"collapsed": false
},
"id": "ef664b14457530fd",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### 1.3. Get input material and \n",
"Materials are loaded with `get_data()`. The first material is assigned as substrate and the second as film."
],
"metadata": {
"collapsed": false
},
"id": "919ad7af8dceeedd"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"from mat3ra.made.material import Material\n",
"from utils.jupyterlite import get_data\n",
"\n",
"# 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\"]))"
],
"metadata": {
"collapsed": false
},
"id": "be38fdda1984c654",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### 1.4. Create and preview Slab"
],
"metadata": {
"collapsed": false
},
"id": "a132fe0ef8bbf0d0"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"from mat3ra.made.tools.build.slab import SlabConfiguration, get_terminations, create_slab\n",
"from utils.visualize import visualize_materials as visualize\n",
"\n",
"material = materials[0]\n",
"slab_config = SlabConfiguration(\n",
" bulk=material,\n",
" miller_indices=MILLER_INDICES,\n",
" thickness=SLAB_THICKNESS,\n",
" vacuum=VACUUM,\n",
" use_orthogonal_z=True,\n",
" xy_supercell_matrix=SUPERCELL_MATRIX\n",
" )\n",
"termination = get_terminations(slab_config)[0]\n",
"slab = create_slab(slab_config, termination)\n",
"visualize([{\"material\":slab , \"rotation\":\"0x\"}, {\"material\": slab, \"rotation\": \"-90x\"}],repetitions=[1, 1, 1])"
],
"metadata": {
"collapsed": false
},
"id": "e2d24109d3068c9e",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"## 2. Create the Defect\n",
"### 2.1. Set adatom parameters"
],
"metadata": {
"collapsed": false
},
"id": "5da5b0380583c952"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"from mat3ra.made.tools.build.defect import AdatomSlabPointDefectConfiguration\n",
"from mat3ra.made.tools.build.defect.builders import EquidistantAdatomSlabDefectBuilder, CrystalSiteAdatomSlabDefectBuilder\n",
"\n",
"adatom_config = AdatomSlabPointDefectConfiguration(crystal=slab, \n",
" defect_type=DEFECT_TYPE, \n",
" chemical_element=CHEMICAL_ELEMENT, \n",
" distance_z=DISTANCE_Z, \n",
" position_on_surface=APPROXIMATE_POSITION_ON_SURFACE\n",
")"
],
"metadata": {
"collapsed": false
},
"id": "e385e50ae11ed2b9",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### 2.2. Create the adatom"
],
"metadata": {
"collapsed": false
},
"id": "489b51f0ee122c48"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"from mat3ra.made.tools.build.defect import create_slab_defect\n",
"slab_with_adatom_at_specified_position = create_slab_defect(adatom_config)\n",
"slab_with_adatom_at_equidistant_position = create_slab_defect(adatom_config, EquidistantAdatomSlabDefectBuilder())\n",
"slab_with_adatom_at_crystal_site = create_slab_defect(adatom_config, CrystalSiteAdatomSlabDefectBuilder())"
],
"metadata": {
"collapsed": false
},
"id": "a990fa35742d7269",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"## 3. Visualize the Slabs with Adatom"
],
"metadata": {
"collapsed": false
},
"id": "462549d016073446"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"from utils.visualize import visualize_materials as visualize\n",
"\n",
"visualize([{\"material\": slab, \"title\": \"Original material\"},\n",
" {\"material\": slab_with_adatom_at_equidistant_position, \"title\": f\"Material with adatom defect at equidistant position\"},\n",
" {\"material\": slab_with_adatom_at_crystal_site, \"title\": f\"Material with adatom defect at crystal site\"}],\n",
" rotation=\"-90x\"\n",
" )\n",
"visualize([{\"material\": slab, \"title\": \"Original material\"},\n",
" {\"material\": slab_with_adatom_at_equidistant_position, \"title\": f\"Material with adatom defect at equidistant position\"},\n",
" {\"material\": slab_with_adatom_at_crystal_site, \"title\": f\"Material with adatom defect at crystal site\"}]\n",
")"
],
"metadata": {
"collapsed": false
},
"id": "509b18661a069e42",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"## 4. Pass data to the outside runtime"
],
"metadata": {
"collapsed": false
},
"id": "d381df29a6bbdd82"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"from utils.jupyterlite import set_data\n",
"\n",
"set_data(\"materials\", [slab_with_adatom_at_equidistant_position.to_json(), slab_with_adatom_at_crystal_site.to_json()])"
],
"metadata": {
"collapsed": false
},
"id": "61daa5afcbc078a9",
"execution_count": null
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
10 changes: 5 additions & 5 deletions other/materials_designer/create_point_defect.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"cell_type": "markdown",
"source": [
"# Create point defects in a bulk material should be the name of the notebook\n",
"# Create point defects in a bulk material\n",
"\n",
"Create a vacancy, add substitution or interstitial atom to provided Material.\n",
"\n",
Expand Down Expand Up @@ -47,8 +47,8 @@
"outputs": [],
"source": [
"DEFECT_TYPE = \"substitution\" # (e.g. \"vacancy\", \"substitution\", \"interstitial\")\n",
"SITE_ID = 1 # Site index of the defect\n",
"POSITION = [0, 0, 0] # Position of the defect in crystal coordinates\n",
"SITE_ID = 0 # Site index of the defect\n",
"POSITION = [0, 0.0, 0.0] # Position of the defect in crystal coordinates\n",
"CHEMICAL_ELEMENT = \"Cu\" # Element to be placed at the site (ignored for vacancy)\n",
"SUPERCELL_MATRIX = [[3, 0, 0], [0, 3, 0], [0, 0, 3]] "
],
Expand Down Expand Up @@ -161,7 +161,7 @@
"from mat3ra.made.tools.build.defect.builders import PointDefectBuilderParameters\n",
"\n",
"defect_configuration_with_site_id = PointDefectConfiguration.from_site_id(crystal=supercell, defect_type=DEFECT_TYPE, site_id=SITE_ID, chemical_element=CHEMICAL_ELEMENT)\n",
"defect_configuration_with_position = PointDefectConfiguration(crystal=supercell, defect_type=DEFECT_TYPE, position=POSITION, chemical_element=CHEMICAL_ELEMENT)\n",
"defect_configuration_with_position = PointDefectConfiguration(crystal=supercell, defect_type=\"interstitial\", position=POSITION, chemical_element=CHEMICAL_ELEMENT)\n",
"\n",
"defect_builder_parameters = PointDefectBuilderParameters(center_defect=False)"
],
Expand Down Expand Up @@ -215,7 +215,7 @@
"visualize([{\"material\": supercell, \"title\": \"Original material\"},\n",
" {\"material\": material_with_defect_at_site_id, \"title\": f\"Material with defect at site_id={SITE_ID}\"},\n",
" {\"material\": material_with_defect_at_position, \"title\": f\"Material with defect at position={POSITION}\"}],\n",
" rotation=\"90y\")"
" rotation=\"-90x\")"
],
"metadata": {
"collapsed": false
Expand Down
3 changes: 2 additions & 1 deletion utils/jupyterlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def set_data_python(key: str, value: Any):
if not os.path.exists(UPLOADS_FOLDER):
os.makedirs(UPLOADS_FOLDER)
for item in value:
file_path = os.path.join(UPLOADS_FOLDER, f"{item['name']}.json")
safe_name = item["name"].replace("%", "pct").replace("/", ":")
file_path = os.path.join(UPLOADS_FOLDER, f"{safe_name}.json")
with open(file_path, "w") as file:
json.dump(item, file)
print(f"Data for {key} written to {file_path}")
Expand Down

0 comments on commit 1495b96

Please sign in to comment.