-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: construct interface between two materials
- Loading branch information
Showing
1 changed file
with
282 additions
and
0 deletions.
There are no files selected for viewing
282 changes: 282 additions & 0 deletions
282
other/two_dimensional_materials/layer_on_a_surface.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,282 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 28, | ||
"id": "ccd22c95-511c-4a63-851f-7d108f53f979", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"/Users/mat3ra/.pyenv/versions/3.11.4/bin/python3.11\n", | ||
"8.6.13\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import sys\n", | ||
"print(sys.executable)\n", | ||
"#!{sys.executable} -m pip install ase\n", | ||
"#!{sys.executable} -m pip install tk\n", | ||
"import tkinter\n", | ||
"print(tkinter.Tcl().eval('info patchlevel'))\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"id": "c34ddf68-341f-4f81-89de-9a314dee52c6", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from ase.visualize import view\n", | ||
"import ase.build\n", | ||
"show = False\n", | ||
"\n", | ||
"crystal = ase.build.bulk(\"Ni\", cubic=True)\n", | ||
"if show : view(crystal*[4,4,1])\n", | ||
"\n", | ||
"graphene = ase.build.graphene()\n", | ||
"if show : view(graphene*[2,2,1])\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 129, | ||
"id": "fad3fa15-8b61-409e-aedc-a13f8bf83bb5", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# data\n", | ||
"global data\n", | ||
"substrate_poscars = [\"\"\"Ni4\n", | ||
"1.0\n", | ||
" 3.4751458659480110 0.0000000000000000 0.0000000000000002\n", | ||
" 0.0000000000000006 3.4751458659480110 0.0000000000000002\n", | ||
" 0.0000000000000000 0.0000000000000000 3.4751458659480110\n", | ||
"Ni\n", | ||
"4\n", | ||
"direct\n", | ||
" 0.0000000000000000 0.0000000000000000 0.0000000000000000 Ni\n", | ||
" 0.0000000000000000 0.5000000000000000 0.5000000000000000 Ni\n", | ||
" 0.5000000000000000 0.0000000000000000 0.5000000000000000 Ni\n", | ||
" 0.5000000000000000 0.5000000000000000 0.0000000000000000 Ni\n", | ||
"\"\"\",\n", | ||
"\"\"\"Cu4\n", | ||
"1.0\n", | ||
" 3.5774306715697510 0.0000000000000000 0.0000000000000002\n", | ||
" 0.0000000000000006 3.5774306715697510 0.0000000000000002\n", | ||
" 0.0000000000000000 0.0000000000000000 3.5774306715697510\n", | ||
"Cu\n", | ||
"4\n", | ||
"direct\n", | ||
" 0.0000000000000000 0.0000000000000000 0.0000000000000000 Cu\n", | ||
" 0.0000000000000000 0.5000000000000000 0.5000000000000000 Cu\n", | ||
" 0.5000000000000000 0.0000000000000000 0.5000000000000000 Cu\n", | ||
" 0.5000000000000000 0.5000000000000000 0.0000000000000000 Cu\n", | ||
"\"\"\",\n", | ||
"\"\"\"Au4\n", | ||
"1.0\n", | ||
" 4.1712885314747270 0.0000000000000000 0.0000000000000003\n", | ||
" 0.0000000000000007 4.1712885314747270 0.0000000000000003\n", | ||
" 0.0000000000000000 0.0000000000000000 4.1712885314747270\n", | ||
"Au\n", | ||
"4\n", | ||
"direct\n", | ||
" 0.0000000000000000 0.0000000000000000 0.0000000000000000 Au\n", | ||
" 0.0000000000000000 0.5000000000000000 0.5000000000000000 Au\n", | ||
" 0.5000000000000000 0.0000000000000000 0.5000000000000000 Au\n", | ||
" 0.5000000000000000 0.5000000000000000 0.0000000000000000 Au\n", | ||
"\"\"\",\n", | ||
"\"\"\"Si4 C4\n", | ||
"1.0\n", | ||
" 4.3539932475828609 0.0000000000000000 0.0000000000000003\n", | ||
" 0.0000000000000007 4.3539932475828609 0.0000000000000003\n", | ||
" 0.0000000000000000 0.0000000000000000 4.3539932475828609\n", | ||
"Si C\n", | ||
"4 4\n", | ||
"direct\n", | ||
" 0.7500000000000000 0.2500000000000000 0.7500000000000000 Si4+\n", | ||
" 0.7500000000000000 0.7500000000000000 0.2500000000000000 Si4+\n", | ||
" 0.2500000000000000 0.2500000000000000 0.2500000000000000 Si4+\n", | ||
" 0.2500000000000000 0.7500000000000000 0.7500000000000000 Si4+\n", | ||
" 0.0000000000000000 0.0000000000000000 0.0000000000000000 C4-\n", | ||
" 0.0000000000000000 0.5000000000000000 0.5000000000000000 C4-\n", | ||
" 0.5000000000000000 0.0000000000000000 0.5000000000000000 C4-\n", | ||
" 0.5000000000000000 0.5000000000000000 0.0000000000000000 C4-\n", | ||
"\"\"\"]\n", | ||
"\n", | ||
"material_poscars = [\"\"\"Graphene\n", | ||
"1.0\n", | ||
" 2.467291000\t 0.000000000\t 0.000000000\n", | ||
" -1.233645000\t 2.136737000\t 0.000000000\n", | ||
" 0.000000000\t 0.000000000\t 7.803074000\n", | ||
"C\n", | ||
"2\n", | ||
"direct\n", | ||
" 0.000000000 0.000000000 0.000000000 C\n", | ||
" 0.333333000 0.666667000 0.000000000 C\n", | ||
"\"\"\",\n", | ||
"\"\"\"Au4\n", | ||
"1.0\n", | ||
" 4.1712885314747270 0.0000000000000000 0.0000000000000003\n", | ||
" 0.0000000000000007 4.1712885314747270 0.0000000000000003\n", | ||
" 0.0000000000000000 0.0000000000000000 4.1712885314747270\n", | ||
"Au\n", | ||
"4\n", | ||
"direct\n", | ||
" 0.0000000000000000 0.0000000000000000 0.0000000000000000 Au\n", | ||
" 0.0000000000000000 0.5000000000000000 0.5000000000000000 Au\n", | ||
" 0.5000000000000000 0.0000000000000000 0.5000000000000000 Au\n", | ||
" 0.5000000000000000 0.5000000000000000 0.0000000000000000 Au\n", | ||
"\"\"\"]\n", | ||
"\n", | ||
"substrate_poscar = substrate_poscars[0]\n", | ||
"material_poscar = material_poscars[0]\n", | ||
"data = [substrate_poscar, material_poscar]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 149, | ||
"id": "06ac0aac-d41a-4e95-962b-6de7557cf654", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# settings\n", | ||
"global settings \n", | ||
"settings = {\"slab_settings\": {\"h\":1, \"k\":1, \"l\":0, \"vacuum\":0.5}, \n", | ||
" \"interface_settings\": {\"substrate\":{\"n\":1, \"m\":2}, \"material\":{\"n\": 3, \"m\": 4}}, \n", | ||
" \"supercell_settings\":{\"n\":3, \"m\":3}}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 150, | ||
"id": "491ed5a5-5d3d-47c8-9226-211fff34f7e2", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Atoms(symbols='Ni4', pbc=True, cell=[[3.475145865948011, 0.0, 2e-16], [6e-16, 3.475145865948011, 2e-16], [0.0, 0.0, 3.475145865948011]])\n", | ||
"Atoms(symbols='C2', pbc=True, cell=[[2.467291, 0.0, 0.0], [-1.233645, 2.136737, 0.0], [0.0, 0.0, 7.803074]])\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from ase import Atoms\n", | ||
"from ase.build import surface\n", | ||
"from ase.io import read, write\n", | ||
"import io\n", | ||
"from operator import itemgetter\n", | ||
"\n", | ||
"def poscar_to_atoms(poscar):\n", | ||
" input = io.StringIO(poscar)\n", | ||
" atoms = read(input, format=\"vasp\")\n", | ||
" return atoms\n", | ||
" \n", | ||
"def write_atoms_to_poscar(atoms) :\n", | ||
" output = io.StringIO()\n", | ||
" write(output, atoms, format=\"vasp\")\n", | ||
" content = output.getvalue()\n", | ||
" output.close()\n", | ||
" return content\n", | ||
"\n", | ||
"class MaterialInterface:\n", | ||
" def __init__(self, substrate, material, settings=None):\n", | ||
" self.substrate = substrate\n", | ||
" self.material = material\n", | ||
" self.settings = {\n", | ||
" \"slab_settings\": {\"h\": 1, \"k\": 0, \"l\": 0, \"layers\": 3, \"vacuum\": 0.5},\n", | ||
" \"interface_settings\": {\"substrate\":{\"n\":1, \"m\":1}, \"material\": {\"n\":1, \"m\":1}, \"distance\": 2.0},\n", | ||
" \"supercell_settings\": {\"n\":1, \"m\":1}\n", | ||
" }\n", | ||
" if settings:\n", | ||
" for key in self.settings.keys():\n", | ||
" if key in settings:\n", | ||
" self.settings[key].update(settings[key])\n", | ||
" self.structure = self.create_structure()\n", | ||
" \n", | ||
" def create_structure(self):\n", | ||
" h, k, l, layers, vacuum = itemgetter('h', 'k', 'l', 'layers','vacuum')(self.settings[\"slab_settings\"])\n", | ||
" \n", | ||
" distance = itemgetter('distance')(self.settings[\"interface_settings\"])\n", | ||
" substrate_supercell = self.settings[\"interface_settings\"][\"substrate\"]\n", | ||
" material_supercell = self.settings[\"interface_settings\"][\"material\"]\n", | ||
" \n", | ||
" slab = surface(self.substrate, (h, k, l), layers, vacuum)\n", | ||
" slab = slab * [substrate_supercell[\"n\"], substrate_supercell[\"m\"], 1]\n", | ||
" material = self.material * [material_supercell[\"n\"], material_supercell[\"m\"], 1]\n", | ||
"\n", | ||
" z_max_slab = max(slab.positions[:, 2])\n", | ||
" z_min_material = min(material.positions[:, 2])\n", | ||
" z_offset = z_max_slab - z_min_material + distance\n", | ||
" material.positions[:, 2] += z_offset\n", | ||
"\n", | ||
" return slab + material\n", | ||
" \n", | ||
" def create_supercell(self):\n", | ||
" n, m = itemgetter(\"n\", \"m\")(self.settings[\"supercell_settings\"])\n", | ||
" self.structure = self.structure * [n, m, 1]\n", | ||
"\n", | ||
" def calculate_strain():\n", | ||
" return \"not implemetned\"\n", | ||
" \n", | ||
" def view(self):\n", | ||
" view(self.structure)\n", | ||
"\n", | ||
"def func() :\n", | ||
" \"\"\"This function is meant to be a gateway to Pyodide in Materials Designer\"\"\"\n", | ||
" \n", | ||
" poscars = globals()[\"data\"]\n", | ||
" settings = globals()[\"settings\"]\n", | ||
" materials = []\n", | ||
" for poscar in poscars :\n", | ||
" print(poscar_to_atoms(poscar))\n", | ||
" materials.append(poscar_to_atoms(poscar))\n", | ||
"\n", | ||
" \n", | ||
" interface = MaterialInterface(materials[0], materials[1], settings)\n", | ||
" write(\"structure.poscar\", interface.structure, format='vasp')\n", | ||
" \n", | ||
" interface.create_supercell()\n", | ||
" view(interface.structure)\n", | ||
"\n", | ||
"func()\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "fdff4bfa-eaae-41ba-b8de-f56951090c03", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |