{ "cells": [ { "cell_type": "markdown", "id": "b66da806-0ec9-45f1-a31e-543f1d8f3d74", "metadata": {}, "source": [ "# Atomic Structure Generation" ] }, { "cell_type": "code", "execution_count": 1, "id": "0fac04de-3781-499f-8845-65d5bca67502", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'1.0.5a2'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import mdapy as mp\n", "import numpy as np\n", "mp.__version__" ] }, { "cell_type": "markdown", "id": "6c294f15-5658-442b-af02-b635fe30a4f9", "metadata": {}, "source": [ "### Build FCC Cu" ] }, { "cell_type": "code", "execution_count": 2, "id": "37bc3175-c6ca-4218-be4f-697b62cb866b", "metadata": {}, "outputs": [], "source": [ "fcc = mp.build_crystal('Cu', 'fcc', 3.615, nx=3, ny=3, nz=3)" ] }, { "cell_type": "markdown", "id": "511284fb-65c8-4314-8baf-ea061b23de8e", "metadata": {}, "source": [ "### Build BCC Fe" ] }, { "cell_type": "code", "execution_count": 3, "id": "55051121-7a5e-49b4-95c4-7dfa1f069063", "metadata": {}, "outputs": [], "source": [ "bcc = mp.build_crystal('Fe', 'bcc', 2.8, nx=3, ny=3, nz=3)" ] }, { "cell_type": "markdown", "id": "71a8e6aa-a829-4686-bc80-ba410bf8d875", "metadata": {}, "source": [ "### Build HCP Ti" ] }, { "cell_type": "code", "execution_count": 4, "id": "4785e20d-9263-4cb2-95e6-c23f2ff9cd5c", "metadata": {}, "outputs": [], "source": [ "hcp = mp.build_crystal('Ti', 'hcp', 3.0, nx=2, ny=2, nz=2)" ] }, { "cell_type": "code", "execution_count": 5, "id": "481500bc-9117-449b-8119-6f210d6c7d0e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Atom Number: 16\n", "Box information:\n", "[[ 6. 0. 0. ]\n", " [-3. 5.19615242 0. ]\n", " [ 0. 0. 9.79795897]]\n", "Origin: [0. 0. 0.]\n", "Triclinic: True\n", "Boundary: [1 1 1]\n", "Particle Information:\n", "shape: (16, 4)\n", "┌────────────┬──────────┬──────────┬─────────┐\n", "│ x ┆ y ┆ z ┆ element │\n", "│ --- ┆ --- ┆ --- ┆ --- │\n", "│ f64 ┆ f64 ┆ f64 ┆ str │\n", "╞════════════╪══════════╪══════════╪═════════╡\n", "│ 0.0 ┆ 0.0 ┆ 0.0 ┆ Ti │\n", "│ 5.5511e-17 ┆ 1.732051 ┆ 2.44949 ┆ Ti │\n", "│ 0.0 ┆ 0.0 ┆ 4.898979 ┆ Ti │\n", "│ 5.5511e-17 ┆ 1.732051 ┆ 7.348469 ┆ Ti │\n", "│ -1.5 ┆ 2.598076 ┆ 0.0 ┆ Ti │\n", "│ … ┆ … ┆ … ┆ … │\n", "│ 3.0 ┆ 1.732051 ┆ 7.348469 ┆ Ti │\n", "│ 1.5 ┆ 2.598076 ┆ 0.0 ┆ Ti │\n", "│ 1.5 ┆ 4.330127 ┆ 2.44949 ┆ Ti │\n", "│ 1.5 ┆ 2.598076 ┆ 4.898979 ┆ Ti │\n", "│ 1.5 ┆ 4.330127 ┆ 7.348469 ┆ Ti │\n", "└────────────┴──────────┴──────────┴─────────┘" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hcp" ] }, { "cell_type": "code", "execution_count": 6, "id": "88559c84", "metadata": {}, "outputs": [], "source": [ "hcp_ortho = mp.orthogonal_cell(hcp)" ] }, { "cell_type": "code", "execution_count": 7, "id": "eac3af12", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Atom Number: 32\n", "Box information:\n", "[[ 6. 0. 0. ]\n", " [ 0. 10.39230485 0. ]\n", " [ 0. 0. 9.79795897]]\n", "Origin: [0. 0. 0.]\n", "Triclinic: False\n", "Boundary: [1 1 1]\n", "Particle Information:\n", "shape: (32, 4)\n", "┌─────┬──────────┬──────────┬─────────┐\n", "│ x ┆ y ┆ z ┆ element │\n", "│ --- ┆ --- ┆ --- ┆ --- │\n", "│ f64 ┆ f64 ┆ f64 ┆ str │\n", "╞═════╪══════════╪══════════╪═════════╡\n", "│ 0.0 ┆ 0.0 ┆ 0.0 ┆ Ti │\n", "│ 0.0 ┆ 1.732051 ┆ 2.44949 ┆ Ti │\n", "│ 0.0 ┆ 0.0 ┆ 4.898979 ┆ Ti │\n", "│ 0.0 ┆ 1.732051 ┆ 7.348469 ┆ Ti │\n", "│ 3.0 ┆ 0.0 ┆ 0.0 ┆ Ti │\n", "│ … ┆ … ┆ … ┆ … │\n", "│ 1.5 ┆ 9.526279 ┆ 7.348469 ┆ Ti │\n", "│ 4.5 ┆ 7.794229 ┆ 0.0 ┆ Ti │\n", "│ 4.5 ┆ 9.526279 ┆ 2.44949 ┆ Ti │\n", "│ 4.5 ┆ 7.794229 ┆ 4.898979 ┆ Ti │\n", "│ 4.5 ┆ 9.526279 ┆ 7.348469 ┆ Ti │\n", "└─────┴──────────┴──────────┴─────────┘" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hcp_ortho" ] }, { "cell_type": "markdown", "id": "64a07d0d-dccc-42ea-9c39-3e5169fcfd2b", "metadata": {}, "source": [ "### Build Cubic Diamond " ] }, { "cell_type": "code", "execution_count": 8, "id": "fda70944-7122-48a7-bf62-87a5b5ce4679", "metadata": {}, "outputs": [], "source": [ "dia = mp.build_crystal('C', 'diamond', 3.0, nx=2, ny=2, nz=2)" ] }, { "cell_type": "markdown", "id": "d6be5e86-866e-4597-bfe8-480e433ec17b", "metadata": {}, "source": [ "### Build Graphene layer" ] }, { "cell_type": "code", "execution_count": 9, "id": "7e928773-17e6-4d23-869d-7b08e693c3e4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Atom Number: 16\n", "Box information:\n", "[[ 4.92 0. 0. ]\n", " [-4.92 8.52168997 0. ]\n", " [ 0. 0. 10. ]]\n", "Origin: [0. 0. 0.]\n", "Triclinic: True\n", "Boundary: [1 1 1]\n", "Particle Information:\n", "shape: (16, 4)\n", "┌────────────┬──────────┬─────┬─────────┐\n", "│ x ┆ y ┆ z ┆ element │\n", "│ --- ┆ --- ┆ --- ┆ --- │\n", "│ f64 ┆ f64 ┆ f64 ┆ str │\n", "╞════════════╪══════════╪═════╪═════════╡\n", "│ 0.0 ┆ 0.0 ┆ 0.0 ┆ C │\n", "│ 8.5117e-18 ┆ 1.420282 ┆ 0.0 ┆ C │\n", "│ -1.23 ┆ 2.130422 ┆ 0.0 ┆ C │\n", "│ -1.23 ┆ 3.550704 ┆ 0.0 ┆ C │\n", "│ -2.46 ┆ 4.260845 ┆ 0.0 ┆ C │\n", "│ … ┆ … ┆ … ┆ … │\n", "│ 1.23 ┆ 3.550704 ┆ 0.0 ┆ C │\n", "│ 0.0 ┆ 4.260845 ┆ 0.0 ┆ C │\n", "│ 8.5117e-18 ┆ 5.681127 ┆ 0.0 ┆ C │\n", "│ -1.23 ┆ 6.391267 ┆ 0.0 ┆ C │\n", "│ -1.23 ┆ 7.811549 ┆ 0.0 ┆ C │\n", "└────────────┴──────────┴─────┴─────────┘" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gra = mp.build_crystal('C', 'graphene', 2.46, c=10, nx=2, ny=4, nz=1)\n", "gra" ] }, { "cell_type": "markdown", "id": "6e70f231-1917-48c7-8f48-c841d70838c5", "metadata": {}, "source": [ "### Build structure with specific orientations" ] }, { "cell_type": "code", "execution_count": 10, "id": "76cbae39-c06c-4ce6-8404-cf7f585e1f7e", "metadata": {}, "outputs": [], "source": [ "aluminum = mp.build_crystal('Al', 'fcc', 3.615, nx=3, ny=3, nz=3, miller1=[1, 1, 2], miller2=[1, -1, 0], miller3=[1, 1, -1])" ] }, { "cell_type": "code", "execution_count": 11, "id": "1a1ef1e0-73f0-416c-89ca-afeacc7f7682", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Atom Number: 162\n", "Box information:\n", "[[13.28235813 0. 0. ]\n", " [ 0. 7.66857304 0. ]\n", " [ 0. 0. 18.78409101]]\n", "Origin: [0. 0. 0.]\n", "Triclinic: False\n", "Boundary: [1 1 1]\n", "Particle Information:\n", "shape: (162, 4)\n", "┌───────────┬──────────┬───────────┬─────────┐\n", "│ x ┆ y ┆ z ┆ element │\n", "│ --- ┆ --- ┆ --- ┆ --- │\n", "│ f64 ┆ f64 ┆ f64 ┆ str │\n", "╞═══════════╪══════════╪═══════════╪═════════╡\n", "│ 0.0 ┆ 0.0 ┆ 0.0 ┆ Al │\n", "│ 1.475818 ┆ 0.0 ┆ 2.087121 ┆ Al │\n", "│ 2.213726 ┆ 1.278096 ┆ 0.0 ┆ Al │\n", "│ 2.951635 ┆ 0.0 ┆ 4.174242 ┆ Al │\n", "│ 3.689544 ┆ 1.278096 ┆ 2.087121 ┆ Al │\n", "│ … ┆ … ┆ … ┆ … │\n", "│ 10.330723 ┆ 5.112382 ┆ 14.609849 ┆ Al │\n", "│ 11.068632 ┆ 6.390478 ┆ 12.522727 ┆ Al │\n", "│ 11.806541 ┆ 5.112382 ┆ 16.69697 ┆ Al │\n", "│ 12.544449 ┆ 6.390478 ┆ 14.609849 ┆ Al │\n", "│ 9.592814 ┆ 6.390478 ┆ 16.69697 ┆ Al │\n", "└───────────┴──────────┴───────────┴─────────┘" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aluminum" ] }, { "cell_type": "markdown", "id": "d90d3cc3-ca0f-4375-8e3e-4b637712d8ef", "metadata": {}, "source": [ "### Build high-entropy alloy" ] }, { "cell_type": "code", "execution_count": 12, "id": "fb818eec-2cff-4f6b-94d5-338be0ca6a17", "metadata": {}, "outputs": [], "source": [ "hea = mp.build_hea(['Cr', 'Co', 'Ni'], [0.5, 0.3, 0.2], 'fcc', 3.6, nx=10, ny=10, nz=10, random_seed=1)" ] }, { "cell_type": "code", "execution_count": 13, "id": "703af0a2-480e-49ff-b468-5d5e1e3fa584", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Atom Number: 4000\n", "Box information:\n", "[[36. 0. 0.]\n", " [ 0. 36. 0.]\n", " [ 0. 0. 36.]]\n", "Origin: [0. 0. 0.]\n", "Triclinic: False\n", "Boundary: [1 1 1]\n", "Particle Information:\n", "shape: (4_000, 4)\n", "┌──────┬──────┬──────┬─────────┐\n", "│ x ┆ y ┆ z ┆ element │\n", "│ --- ┆ --- ┆ --- ┆ --- │\n", "│ f64 ┆ f64 ┆ f64 ┆ str │\n", "╞══════╪══════╪══════╪═════════╡\n", "│ 0.0 ┆ 0.0 ┆ 0.0 ┆ Cr │\n", "│ 1.8 ┆ 1.8 ┆ 0.0 ┆ Cr │\n", "│ 0.0 ┆ 1.8 ┆ 1.8 ┆ Cr │\n", "│ 1.8 ┆ 0.0 ┆ 1.8 ┆ Co │\n", "│ 0.0 ┆ 0.0 ┆ 3.6 ┆ Cr │\n", "│ … ┆ … ┆ … ┆ … │\n", "│ 34.2 ┆ 32.4 ┆ 30.6 ┆ Ni │\n", "│ 32.4 ┆ 32.4 ┆ 32.4 ┆ Cr │\n", "│ 34.2 ┆ 34.2 ┆ 32.4 ┆ Ni │\n", "│ 32.4 ┆ 34.2 ┆ 34.2 ┆ Cr │\n", "│ 34.2 ┆ 32.4 ┆ 34.2 ┆ Cr │\n", "└──────┴──────┴──────┴─────────┘" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hea" ] }, { "cell_type": "markdown", "id": "0c0f8028-a6f4-4a87-b338-5c9a30022aad", "metadata": {}, "source": [ "### Build polyscrystal" ] }, { "cell_type": "code", "execution_count": 14, "id": "6a39e424-46d9-4bcf-8c60-7ea10f61fb44", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "======================================================================\n", " POLYCRYSTAL GENERATION\n", "======================================================================\n", "[1/5] Generating Voronoi tessellation...\n", " Number of grains: 5\n", " Average volume: 200000.00 A^3\n", " Volume range: 180820.01 - 251770.56 A^3\n", " Random seed: 1\n", "[2/5] Generating atoms for 5 grains...\n", " Grain 1/5: Volume = 251770.56 A^3 Atoms = 15162\n", " Grain 2/5: Volume = 180820.01 A^3 Atoms = 10890\n", " Grain 3/5: Volume = 193528.01 A^3 Atoms = 11653\n", " Grain 4/5: Volume = 191668.31 A^3 Atoms = 11531\n", " Grain 5/5: Volume = 182213.11 A^3 Atoms = 10969\n", " Total atoms generated: 60,205\n", "[3/5] Creating atomic structure...\n", "[4/5] Removing overlapping atoms...\n", " Filtering: Metal-Metal overlaps\n", " Metal-Metal distance: 2.00 Å\n", " Atoms removed: 2,051 (3.41%)\n", " Atoms remaining: 58,154\n", "[5/5] Finalizing structure...\n", "======================================================================\n", " ✓ Polycrystal generation completed successfully!\n", " ✓ Execution time: 0.03 seconds\n", "======================================================================\n" ] } ], "source": [ "unit = mp.build_crystal(\"Al\", \"fcc\", 4.05)\n", "poly = mp.CreatePolycrystal(unit, box=100, seed_number=5, randomseed=1, metal_overlap_dis=2.0)\n", "system = poly.compute()" ] }, { "cell_type": "markdown", "id": "bdb9d63d-0cbe-46a8-9c75-11877c20b405", "metadata": {}, "source": [ "### Build 2D polycrystal" ] }, { "cell_type": "code", "execution_count": 15, "id": "a556da65-471f-44a1-a42a-67c6970510a5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "======================================================================\n", " POLYCRYSTAL GENERATION\n", "======================================================================\n", "[1/5] Generating Voronoi tessellation...\n", " Number of grains: 10\n", " Average volume: 437400.00 A^3\n", " Volume range: 256714.65 - 797106.53 A^3\n", " Random seed: 42\n", "[2/5] Generating atoms for 10 grains...\n", " Grain 1/10: Volume = 362972.67 A^3 Atoms = 21876\n", " Grain 2/10: Volume = 256714.65 A^3 Atoms = 15468\n", " Grain 3/10: Volume = 797106.53 A^3 Atoms = 47796\n", " Grain 4/10: Volume = 391536.22 A^3 Atoms = 23688\n", " Grain 5/10: Volume = 524456.68 A^3 Atoms = 31536\n", " Grain 6/10: Volume = 319233.38 A^3 Atoms = 19188\n", " Grain 7/10: Volume = 345779.30 A^3 Atoms = 20868\n", " Grain 8/10: Volume = 397379.07 A^3 Atoms = 23964\n", " Grain 9/10: Volume = 356555.71 A^3 Atoms = 21516\n", " Grain 10/10: Volume = 622265.80 A^3 Atoms = 37512\n", " Total atoms generated: 263,412\n", "[3/5] Creating atomic structure...\n", "[4/5] Removing overlapping atoms...\n", " Filtering: Metal-Metal overlaps\n", " Metal-Metal distance: 2.00 Å\n", " Atoms removed: 3,516 (1.33%)\n", " Atoms remaining: 259,896\n", "[5/5] Finalizing structure...\n", "======================================================================\n", " ✓ Polycrystal generation completed successfully!\n", " ✓ Execution time: 0.06 seconds\n", "======================================================================\n" ] } ], "source": [ "unit = mp.build_crystal(\"Al\", \"fcc\", 4.05)\n", "random_seed = 42\n", "np.random.seed(random_seed)\n", "box = np.array([[300, 0, 0], [0, 300, 0], [0, 0, unit.box.box[2, 2] * 12]])\n", "seed_number = 10\n", "box_lengths = np.diag(box)\n", "seed_position = np.random.random((seed_number, 3)) * box_lengths\n", "seed_position[:, 2] = box[2, 2] / 2\n", "theta_list = np.random.uniform(-180, 180, (seed_number, 3))\n", "theta_list[:, :2] = 0\n", "poly = mp.CreatePolycrystal(\n", " unit,\n", " box=box,\n", " seed_number=seed_number,\n", " randomseed=random_seed,\n", " metal_overlap_dis=2.0,\n", " theta_list=theta_list,\n", " seed_position=seed_position,\n", ")\n", "system = poly.compute()" ] }, { "cell_type": "markdown", "id": "38f8038a-ab33-436a-93d7-caaa01633eac", "metadata": {}, "source": [ "### Build polycrystal with graphene grain boundary" ] }, { "cell_type": "code", "execution_count": 16, "id": "b03efb63-3bc8-4f48-8a67-0a0cfb40b673", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "======================================================================\n", " POLYCRYSTAL GENERATION\n", "======================================================================\n", "[1/5] Generating Voronoi tessellation...\n", " Number of grains: 5\n", " Average volume: 200000.00 A^3\n", " Volume range: 180820.01 - 251770.56 A^3\n", " Graphene enabled: Yes (threshold = 0.0 A^2)\n", " Random seed: 1\n", "[2/5] Generating atoms for 5 grains...\n", " Grain 1/5: Volume = 251770.56 A^3 Metal = 15162, Carbon = 8611\n", " Grain 2/5: Volume = 180820.01 A^3 Metal = 10890, Carbon = 7273\n", " Grain 3/5: Volume = 193528.01 A^3 Metal = 11653, Carbon = 7489\n", " Grain 4/5: Volume = 191668.31 A^3 Metal = 11531, Carbon = 7549\n", " Grain 5/5: Volume = 182213.11 A^3 Metal = 10969, Carbon = 7579\n", " Total atoms generated: 98,706\n", "[3/5] Creating atomic structure...\n", "[4/5] Removing overlapping atoms...\n", " Filtering: Metal-Metal, C-C, Metal-C overlaps\n", " Metal-Metal distance: 2.00 Å\n", " C-C distance: 1.40 Å\n", " Metal-C distance: 2.80 Å\n", " Atoms removed: 35,520 (35.99%)\n", " Atoms remaining: 63,186\n", "[5/5] Finalizing structure...\n", "======================================================================\n", " ✓ Polycrystal generation completed successfully!\n", " ✓ Execution time: 0.42 seconds\n", "======================================================================\n" ] } ], "source": [ "unit = mp.build_crystal(\"Al\", \"fcc\", 4.05)\n", "poly = mp.CreatePolycrystal(unit, box=100, seed_number=5, randomseed=1, metal_overlap_dis=2.0, add_graphene=True, metal_gra_overlap_dis=2.8)\n", "system = poly.compute()\n", "# system.write_xyz('gra_al.xyz')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.12.0" } }, "nbformat": 4, "nbformat_minor": 5 }