Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/SOF-7438 feat: media creation nb #200

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Prev Previous commit
Next Next commit
update: add nb to generate interfaces
  • Loading branch information
VsevolodX committed Jan 18, 2025
commit a920e17cd8d8981964951b66283a78cc1fdb6817
125 changes: 125 additions & 0 deletions other/media_generation/create_materials.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"cells": [
{
"metadata": {},
"cell_type": "code",
"source": [
"import os\n",
"from pymatgen.ext.matproj import MPRester\n",
"from mat3ra.made.tools.build.slab import SlabConfiguration, get_terminations, create_slab\n",
"from mat3ra.made.tools.build.interface import InterfaceConfiguration, ZSLStrainMatchingParameters, \\\n",
" ZSLStrainMatchingInterfaceBuilder, ZSLStrainMatchingInterfaceBuilderParameters\n",
"from utils.visualize import visualize_materials\n",
"from utils.jupyterlite import set_materials\n",
"\n",
"from mat3ra.standata.materials import Materials\n",
"from mat3ra.made.material import Material\n",
"\n",
"materials = Materials.get_by_categories(\"3D\")\n",
"\n",
"# Map lattice type to Miller Index\n",
"\n",
"lattice_to_miller = {\n",
" \"CUB\": (1, 1, 1),\n",
" \"FCC\": (1, 1, 1),\n",
" \"HEX\": (0, 0, 1),\n",
" \"TRI\": (1, 1, 1)\n",
"}\n",
"\n",
"# Create interfaces\n",
"for i, substrate_json in enumerate(materials):\n",
" for j, film_json in enumerate(materials):\n",
" if i != j:\n",
" print(f\"Creating interface between {substrate_json['name']} and {film_json['name']}\")\n",
"\n",
" substrate = Material(substrate_json)\n",
" film = Material(film_json)\n",
" # Define slab and interface parameters\n",
" slab_params = {\n",
" \"miller_indices\": lattice_to_miller[substrate.lattice.type],\n",
" \"thickness\": 3,\n",
" \"vacuum\": 15.0,\n",
" \"xy_supercell_matrix\": [[1, 0], [0, 1]],\n",
" \"use_conventional_cell\": True,\n",
" \"use_orthogonal_z\": True\n",
" }\n",
"\n",
" interface_params = {\n",
" \"distance_z\": 3.0,\n",
" \"vacuum\": 0.0,\n",
" \"max_area\": 150,\n",
" \"max_area_tol\": 0.10,\n",
" \"max_angle_tol\": 0.04,\n",
" \"max_length_tol\": 0.04\n",
" }\n",
"\n",
"\n",
" # Create slab configurations\n",
" substrate_slab_config = SlabConfiguration(bulk=substrate, **slab_params)\n",
" film_slab_config = SlabConfiguration(bulk=film, **slab_params)\n",
" try:\n",
" # Get terminations\n",
" substrate_terminations = get_terminations(substrate_slab_config)\n",
" film_terminations = get_terminations(film_slab_config)\n",
"\n",
" # Create slabs\n",
" substrate_slabs = [create_slab(substrate_slab_config, t) for t in substrate_terminations]\n",
" film_slabs = [create_slab(film_slab_config, t) for t in film_terminations]\n",
"\n",
" # Select termination pair (example: first pair)\n",
" termination_pair = (film_terminations[0], substrate_terminations[0])\n",
"\n",
" # Create interface configuration\n",
" interface_config = InterfaceConfiguration(\n",
" film_configuration=film_slab_config,\n",
" substrate_configuration=substrate_slab_config,\n",
" film_termination=termination_pair[0],\n",
" substrate_termination=termination_pair[1],\n",
" distance_z=interface_params[\"distance_z\"],\n",
" vacuum=interface_params[\"vacuum\"]\n",
" )\n",
"\n",
" # Set strain matching parameters\n",
" zsl_params = ZSLStrainMatchingParameters(\n",
" max_area=interface_params[\"max_area\"],\n",
" max_area_tol=interface_params[\"max_area_tol\"],\n",
" max_angle_tol=interface_params[\"max_angle_tol\"],\n",
" max_length_tol=interface_params[\"max_length_tol\"]\n",
" )\n",
"\n",
" # Generate interfaces\n",
" builder = ZSLStrainMatchingInterfaceBuilder(\n",
" build_parameters=ZSLStrainMatchingInterfaceBuilderParameters(strain_matching_parameters=zsl_params)\n",
" )\n",
" interfaces = builder.get_materials(configuration=interface_config)\n",
"\n",
" # Visualize and save the interfaces\n",
" interface = interfaces[0]\n",
" visualize_materials(interface, repetitions=[1, 1, 1])\n",
" # set_materials(interface)\n",
" except Exception as e:\n",
" print(f\"Error creating interface between {substrate.name} and {film.name}: {e}\")"
],
"id": "2774de5c47160056",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
"cell_type": "code",
"source": "",
"id": "3572ccacbb4fd25f",
"outputs": [],
"execution_count": null
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"language": "python",
"display_name": "Python 3 (ipykernel)"
}
},
"nbformat": 5,
"nbformat_minor": 9
}
Loading