{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Creating structures in pyiron" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This section gives a brief introduction about some of the tools available in pyiron to construct atomic structures. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For the sake of compatibility, our structure class is written to be compatible with the popular Atomistic Simulation Environment package ([ASE](https://wiki.fysik.dtu.dk/ase/)). This makes it possible to use routines from ASE to help set-up structures.\n", "\n", "Furthermore, pyiron uses the [NGLview](http://nglviewer.org/nglview/latest/api.html) package to visualize the structures and trajectories interactively in 3D using NGLview-widgets." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As preparation for the following discussion we import a few python libraries" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:19.212727Z", "start_time": "2021-03-02T22:42:19.194770Z" } }, "outputs": [], "source": [ "import numpy as np\n", "%matplotlib inline\n", "import matplotlib.pylab as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and create a pyiron project named 'structures':" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:23.454336Z", "start_time": "2021-03-02T22:42:19.221070Z" } }, "outputs": [], "source": [ "from pyiron_atomistics import Project\n", "pr = Project(path='structures')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Bulk crystals" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this section we discuss various possibilities to create bulk crystal structures." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Using `create.structure.crystal`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The simplest way to generate simple crystal structures is using methods on the inbuilt `create.structure` attribute. Here we use the `crystal` method by specifying the element symbol, Bravais basis and the lattice constant(s).\n", "\n", "Note: The output gives a cubic cell rather than the smallest non-orthogonal unit cell." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:23.556680Z", "start_time": "2021-03-02T22:42:23.457872Z" } }, "outputs": [], "source": [ "structure = pr.create.structure.crystal(\n", " 'Al', \n", " bravais_basis='fcc',\n", " lattice_constant=4.05\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To plot the structure interactively in 3D simply use:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:23.820197Z", "start_time": "2021-03-02T22:42:23.559959Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9666c75ba3dd49c6931a53550fd6b1e4", "version_major": 2, "version_minor": 0 }, "text/plain": [] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "366e3d0b1beb44bf85aad33553b8e5a5", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "structure.plot3d()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Using `create.structure.bulk`\n", "\n", "Another convenient way to set up structures is using the `create.structure.bulk` function which is built on top of the ASE build package for [bulk crystals](https://wiki.fysik.dtu.dk/ase/ase/build/build.html#ase.build.bulk). This function returns an object which is of the pyiron structure object type." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Example:** fcc bulk aluminum in a cubic cell" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:24.316670Z", "start_time": "2021-03-02T22:42:23.824222Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d7a1684fa1894d9fb54efc9c9817a68c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "structure = pr.create.structure.bulk('Al', cubic=True)\n", "structure.plot3d()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Example:** wurtzite GaN in a 3x3x3 repeated orthorhombic cell.\n", "\n", "Note: \n", "- In contrast to new_structure = structure.repeat() which creates a new object, set_repeat() modifies the existing structure object.\n", "- Setting `spacefill=False` in the `plot3d()` method changes the atomic structure style to \"ball and stick\"." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:24.762809Z", "start_time": "2021-03-02T22:42:24.333106Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "380afc48864c4d57a393d541b692c241", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "structure = pr.create.structure.bulk(\n", " 'AlN', \n", " crystalstructure='wurtzite', \n", " a=3.5, orthorhombic=True\n", ")\n", "structure.set_repeat([3,3,3])\n", "structure.plot3d(spacefill=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating surfaces\n", "\n", "Surfaces can be created using the `create.structure.surface` function which is also built on top of the ASE build package for [surfaces](https://wiki.fysik.dtu.dk/ase/_modules/ase/build/surface.html)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Example:** Creating a 3x4 fcc Al(111) surface with 4 layers and a vacuum of 10 Ångström" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:25.116457Z", "start_time": "2021-03-02T22:42:24.768093Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c90c40d8e4254e66848e9d0140dfd458", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Al_111 = pr.create.structure.surface(\n", " \"Al\", \n", " surface_type=\"fcc111\", \n", " size=(3, 4, 4), \n", " vacuum=10, \n", " orthogonal=True\n", ")\n", "Al_111.plot3d()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating structures without importing the project class\n", "\n", "In all the examples shown above, the structures are create from the pyiron `Project` object. We also offer legacy support for creating structures without importing/initializing this object. For this the appropriate imports must be made." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:25.145124Z", "start_time": "2021-03-02T22:42:25.137420Z" } }, "outputs": [], "source": [ "from pyiron_atomistics import create_ase_bulk, create_surface" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:25.500183Z", "start_time": "2021-03-02T22:42:25.162782Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c4e65d6e32be422799048621d2efdd19", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "structure = create_ase_bulk(\n", " 'AlN', \n", " crystalstructure='wurtzite',\n", " a=3.5, \n", " orthorhombic=True\n", ")\n", "structure.set_repeat([3,3,3])\n", "structure.plot3d(spacefill=False)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:25.857485Z", "start_time": "2021-03-02T22:42:25.508428Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "726b084491b74e70b924b0f312362a5a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Al_111 = create_surface(\n", " \"Al\", \n", " surface_type=\"fcc111\", \n", " size=(3, 4, 4), \n", " vacuum=10, \n", " orthogonal=True\n", ")\n", "Al_111.plot3d()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Using ase bindings\n", "\n", "We also have some direct bindings to ASE methods, which will always maintain *exactly* the same signature and behaviour as the corresponding ASE methods, except that the final result is wrapped as our `Atoms` class where needed.\n", "\n", "Below is an example binding to `ase.spacegroup.crystal`." ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:26.334753Z", "start_time": "2021-03-02T22:42:25.864114Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c08c3ff68fa34982b4e7268eca0999d3", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "skutterudite = pr.create.structure.ase.crystal(('Co', 'Sb'),\n", " basis=[(0.25, 0.25, 0.25), (0.0, 0.335, 0.158)],\n", " spacegroup=204,\n", " cellpar=[9.04, 9.04, 9.04, 90, 90, 90])\n", "skutterudite.plot3d()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Accessing the properties of the structure object" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using the bulk aluminum fcc example from before the structure object can be created by" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:26.416995Z", "start_time": "2021-03-02T22:42:26.344577Z" } }, "outputs": [], "source": [ "structure = pr.create.structure.bulk('Al', cubic=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A summary of the information about the structure is given by using" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:26.428866Z", "start_time": "2021-03-02T22:42:26.421645Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Al: [0. 0. 0.]\n", "Al: [0. 2.025 2.025]\n", "Al: [2.025 0. 2.025]\n", "Al: [2.025 2.025 0. ]\n", "pbc: [ True True True]\n", "cell: \n", "Cell([4.05, 4.05, 4.05])\n", "\n" ] } ], "source": [ "print(structure)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The cell vectors of the structure object can be accessed and edited through" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:26.450054Z", "start_time": "2021-03-02T22:42:26.437640Z" } }, "outputs": [ { "data": { "text/plain": [ "Cell([4.05, 4.05, 4.05])" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "structure.cell" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The positions of the atoms in the structure object can be accessed and edited through" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:26.472167Z", "start_time": "2021-03-02T22:42:26.458727Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[0. , 0. , 0. ],\n", " [0. , 2.025, 2.025],\n", " [2.025, 0. , 2.025],\n", " [2.025, 2.025, 0. ]])" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "structure.positions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Point defects" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Creating a single vacancy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We start by setting up a 4x4x4 supercell" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:26.613807Z", "start_time": "2021-03-02T22:42:26.480390Z" } }, "outputs": [], "source": [ "structure = pr.create.structure.bulk('Al', cubic=True)\n", "structure.set_repeat([4,4,4])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To create the vacancy at position index \"0\" simply use:" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:26.680274Z", "start_time": "2021-03-02T22:42:26.625909Z" } }, "outputs": [], "source": [ "del structure[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To plot the structure that now contains a vacancy run:" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:26.854895Z", "start_time": "2021-03-02T22:42:26.683126Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "134c2f7a56a54c78a6dae560bf56e373", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "structure.plot3d()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Creating multiple vacancies" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:26.912470Z", "start_time": "2021-03-02T22:42:26.859486Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of atoms in the repeat unit: 256\n" ] } ], "source": [ "# First create a 4x4x4 supercell\n", "structure = pr.create.structure.bulk('Al', cubic=True)\n", "structure.set_repeat([4,4,4])\n", "print(f'Number of atoms in the repeat unit: {len(structure)}')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `del` command works for passing a list of indices to the structure object. For example, a random set of n$_{\\text{vac}}$ vacancies can be created by using" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:26.934366Z", "start_time": "2021-03-02T22:42:26.916922Z" } }, "outputs": [], "source": [ "# Generate a list of indices for the vacancies\n", "n_vac = 24\n", "vac_ind_lst = np.random.permutation(len(structure))[:n_vac]\n", "\n", "# Remove atoms according to the \"vac_ind_lst\"\n", "del structure[vac_ind_lst]" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:27.413950Z", "start_time": "2021-03-02T22:42:26.942489Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of atoms in the repeat unit: 232\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9ce0c034066d4cdeb21d4cd3422065fb", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Visualize the structure\n", "print(f'Number of atoms in the repeat unit: {len(structure)}')\n", "structure.plot3d()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Random substitutial alloys" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:27.503293Z", "start_time": "2021-03-02T22:42:27.418168Z" } }, "outputs": [], "source": [ "# Create a 4x4x4 supercell\n", "structure = pr.create.structure.bulk('Al', cubic=True)\n", "structure.set_repeat([4,4,4])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Substitutional atoms can be defined by changing the atomic species accessed through its position index.\n", "\n", "Here, we set $n_{\\text{sub}}$ magnesium substitutional atoms at random positions" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:27.606443Z", "start_time": "2021-03-02T22:42:27.536954Z" } }, "outputs": [], "source": [ "n_sub = 24\n", "structure[np.random.permutation(len(structure))[:n_sub]] = 'Mg'" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:27.788133Z", "start_time": "2021-03-02T22:42:27.618461Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of atoms in the repeat unit: 256\n", "Chemical formula: Al232Mg24\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ad8b5ee55943448f83949d59aae393fb", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Visualize the structure and print some additional information about the structure\n", "print(f'Number of atoms in the repeat unit: {len(structure)}')\n", "print(f'Chemical formula: {structure.get_chemical_formula()}')\n", "structure.plot3d()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Explicit definition of the structure\n", "\n", "You can also set-up structures through the explicit input of the cell parameters and positions" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:28.125950Z", "start_time": "2021-03-02T22:42:27.794921Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "44787375f77945868b330c94174cc757", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cell = 10.0 * np.eye(3) # Specifying the cell dimensions\n", "positions = [[0.25, 0.25, 0.25], [0.75, 0.75, 0.75]]\n", "elements = ['O', 'O']\n", "\n", "# Now use the Atoms class to create the instance.\n", "O_dimer = pr.create_atoms(elements=elements, scaled_positions=positions, cell=cell)\n", "\n", "O_dimer.plot3d()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Importing from cif/other file formats\n", "\n", "Parsers from ASE can be used to import structures from other formats. In this example, we will download and import a Nepheline structure from the [Crystallography Open Database (COD)](http://www.crystallography.net/cod/index.php)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:28.157226Z", "start_time": "2021-03-02T22:42:28.142033Z" } }, "outputs": [], "source": [ "# The COD structures can be accessed through their unique COD identifier\n", "cod = 1008753\n", "filename = '{}.cif'.format(cod)\n", "url = 'http://www.crystallography.net/cod/{}'.format(filename)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:28.211191Z", "start_time": "2021-03-02T22:42:28.172934Z" } }, "outputs": [], "source": [ "cif_structure = \"\"\"\\\n", "#------------------------------------------------------------------------------\n", "#$Date: 2015-01-27 21:58:39 +0200 (Tue, 27 Jan 2015) $\n", "#$Revision: 130149 $\n", "#$URL: svn://www.crystallography.net/cod/cif/1/00/87/1008753.cif $\n", "#------------------------------------------------------------------------------\n", "#\n", "# This file is available in the Crystallography Open Database (COD),\n", "# http://www.crystallography.net/\n", "#\n", "# All data on this site have been placed in the public domain by the\n", "# contributors.\n", "#\n", "data_1008753\n", "loop_\n", "_publ_author_name\n", "'Buerger, M J'\n", "'Klein, G E'\n", "'Donnay, G'\n", "_publ_section_title\n", ";\n", "Determination of the crystal structure of nepheline\n", ";\n", "_journal_coden_ASTM AMMIAY\n", "_journal_name_full 'American Mineralogist'\n", "_journal_page_first 805\n", "_journal_page_last 818\n", "_journal_volume 39\n", "_journal_year 1954\n", "_chemical_formula_structural 'K Na3 Al4 Si4 O16'\n", "_chemical_formula_sum 'Al4 K Na3 O16 Si4'\n", "_chemical_name_mineral Nepheline\n", "_chemical_name_systematic 'Potassium trisodium tetraaluminium silicate'\n", "_space_group_IT_number 173\n", "_symmetry_cell_setting hexagonal\n", "_symmetry_Int_Tables_number 173\n", "_symmetry_space_group_name_Hall 'P 6c'\n", "_symmetry_space_group_name_H-M 'P 63'\n", "_cell_angle_alpha 90\n", "_cell_angle_beta 90\n", "_cell_angle_gamma 120\n", "_cell_formula_units_Z 2\n", "_cell_length_a 10.01\n", "_cell_length_b 10.01\n", "_cell_length_c 8.405\n", "_cell_volume 729.4\n", "_cod_database_code 1008753\n", "loop_\n", "_symmetry_equiv_pos_as_xyz\n", "x,y,z\n", "-y,x-y,z\n", "y-x,-x,z\n", "-x,-y,1/2+z\n", "y,y-x,1/2+z\n", "x-y,x,1/2+z\n", "loop_\n", "_atom_site_label\n", "_atom_site_type_symbol\n", "_atom_site_symmetry_multiplicity\n", "_atom_site_Wyckoff_symbol\n", "_atom_site_fract_x\n", "_atom_site_fract_y\n", "_atom_site_fract_z\n", "_atom_site_occupancy\n", "_atom_site_attached_hydrogens\n", "_atom_site_calc_flag\n", "K1 K1+ 2 a 0. 0. 0. 1. 0 d\n", "Al1 Al3+ 2 b 0.3333 0.6667 0.18 1. 0 d\n", "Si1 Si4+ 2 b 0.3333 0.6667 0.82 1. 0 d\n", "O1 O2- 2 b 0.3333 0.6667 0. 1. 0 d\n", "Na1 Na1+ 6 c 0.008 0.432 0. 1. 0 d\n", "Al2 Al3+ 6 c 0.092 0.33 0.67 1. 0 d\n", "Si2 Si4+ 6 c 0.092 0.33 0.33 1. 0 d\n", "O2 O2- 6 c 0.02 0.33 0.5 1. 0 d\n", "O3 O2- 6 c 0.18 0.5 0.75 1. 0 d\n", "O4 O2- 6 c 0.17 0.53 0.25 1. 0 d\n", "O5 O2- 6 c 0.23 0.28 0.25 1. 0 d\n", "O6 O2- 6 c 0.23 0.28 0.75 1. 0 d\n", "loop_\n", "_atom_type_symbol\n", "_atom_type_oxidation_number\n", "K1+ 1.000\n", "Al3+ 3.000\n", "Si4+ 4.000\n", "O2- -2.000\n", "Na1+ 1.000\"\"\"" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:28.240290Z", "start_time": "2021-03-02T22:42:28.229545Z" } }, "outputs": [], "source": [ "# Download and save the structure file locally\n", "# import urllib\n", "# urllib.request.urlretrieve(url=url, filename='strucs.'+filename);\n", "with open('strucs.'+filename, \"w\") as f:\n", " f.writelines(cif_structure)" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:28.695547Z", "start_time": "2021-03-02T22:42:28.245384Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/huber/anaconda3/envs/pyiron_38/lib/python3.8/site-packages/ase/io/cif.py:377: UserWarning: crystal system 'hexagonal' is not interpreted for space group Spacegroup(173, setting=1). This may result in wrong setting!\n", " warnings.warn(\n" ] } ], "source": [ "# Read the structure from file\n", "structure = pr.create.structure.read(filename='strucs.'+filename, format='cif')\n", "structure.info[\"cod\"] = cod" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:28.958810Z", "start_time": "2021-03-02T22:42:28.704019Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "da78c130db4b40d09854ccec8807ac50", "version_major": 2, "version_minor": 0 }, "text/plain": [ "NGLWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "structure.plot3d()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Structures can be stored indepently from jobs in HDF5 by using the special `StructureContainer` job. To save to disk, call `run()`." ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:30.693243Z", "start_time": "2021-03-02T22:42:28.966960Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2021-03-02 23:42:30,330 - pyiron_log - WARNING - The job nepheline is being loaded instead of running. To re-run use the argument 'delete_existing_job=True in create_job'\n" ] } ], "source": [ "container = pr.create.job.StructureContainer(\"nepheline\")\n", "container.structure = structure\n", "container.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It's also possible to store multiple structures in one container and to store directly from a job. Let's use this here to store the equilibrated structures at finite temperatures." ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:34.661735Z", "start_time": "2021-03-02T22:42:30.706767Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2021-03-02 23:42:31,369 - pyiron_log - WARNING - The job T_400 is being loaded instead of running. To re-run use the argument 'delete_existing_job=True in create_job'\n", "2021-03-02 23:42:32,540 - pyiron_log - WARNING - The job T_600 is being loaded instead of running. To re-run use the argument 'delete_existing_job=True in create_job'\n", "2021-03-02 23:42:33,590 - pyiron_log - WARNING - The job T_800 is being loaded instead of running. To re-run use the argument 'delete_existing_job=True in create_job'\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "The job al_temp was saved and received the ID: 319\n" ] } ], "source": [ "al_container = pr.create.job.StructureContainer(\"al_temp\", delete_existing_job=True)\n", "for T in (400, 600, 800):\n", " j = pr.create.job.Lammps(\"T_{}\".format(T))\n", " j.structure = pr.create.structure.bulk(\"Al\", cubic = True)\n", " j.potential = j.list_potentials()[0]\n", " j.calc_md(temperature=T, n_ionic_steps=1000, pressure=0)\n", " j.run()\n", " structure = j.get_structure()\n", " structure.info[\"T\"] = T\n", " structure.info[\"P\"] = 0\n", " al_container.append(structure)\n", " \n", "al_container.run()" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:34.703519Z", "start_time": "2021-03-02T22:42:34.692435Z" } }, "outputs": [ { "data": { "text/plain": [ "{'T': 400, 'P': 0}" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "al_container.structure_lst[0].info" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "ExecuteTime": { "end_time": "2021-03-02T22:42:34.733351Z", "start_time": "2021-03-02T22:42:34.712347Z" } }, "outputs": [ { "data": { "application/json": [ "Al: [3.93424437 0.07221925 0.08417997]\nAl: [0.10301795 1.89092377 2.04275429]\nAl: [2.09340832 0.10564475 2.11581609]\nAl: [2.04830801 2.02070157 3.93622831]\npbc: [ True True True]\ncell: \nCell([[4.089489326903685, 2.504090007169931e-16, 2.504090007169931e-16], [0.0, 4.089489326903685, 2.504090007169931e-16], [0.0, 0.0, 4.089489326903685]])\n", "Al: [4.01844916 4.0801717 0.23352673]\nAl: [0.08294026 1.90936605 1.88581354]\nAl: [2.20693355 0.01487369 2.13065821]\nAl: [1.9653831 2.26929463 4.02370759]\npbc: [ True True True]\ncell: \nCell([[4.136853033317934, 2.533091912897913e-16, 2.533091912897913e-16], [0.0, 4.136853033317934, 2.533091912897913e-16], [0.0, 0.0, 4.136853033317934]])\n", "Al: [0.20220842 0.35216229 3.99649156]\nAl: [4.00547338 2.01546242 1.92571135]\nAl: [2.29072766 4.03095336 2.19600819]\nAl: [1.84631556 1.94614695 0.22651391]\npbc: [ True True True]\ncell: \nCell([[4.17236250917528, 2.554835195871963e-16, 2.554835195871963e-16], [0.0, 4.17236250917528, 2.554835195871963e-16], [0.0, 0.0, 4.17236250917528]])\n" ], "text/plain": [ "InputList([Al: [3.93424437 0.07221925 0.08417997]\n", "Al: [0.10301795 1.89092377 2.04275429]\n", "Al: [2.09340832 0.10564475 2.11581609]\n", "Al: [2.04830801 2.02070157 3.93622831]\n", "pbc: [ True True True]\n", "cell: \n", "Cell([[4.089489326903685, 2.504090007169931e-16, 2.504090007169931e-16], [0.0, 4.089489326903685, 2.504090007169931e-16], [0.0, 0.0, 4.089489326903685]])\n", ", Al: [4.01844916 4.0801717 0.23352673]\n", "Al: [0.08294026 1.90936605 1.88581354]\n", "Al: [2.20693355 0.01487369 2.13065821]\n", "Al: [1.9653831 2.26929463 4.02370759]\n", "pbc: [ True True True]\n", "cell: \n", "Cell([[4.136853033317934, 2.533091912897913e-16, 2.533091912897913e-16], [0.0, 4.136853033317934, 2.533091912897913e-16], [0.0, 0.0, 4.136853033317934]])\n", ", Al: [0.20220842 0.35216229 3.99649156]\n", "Al: [4.00547338 2.01546242 1.92571135]\n", "Al: [2.29072766 4.03095336 2.19600819]\n", "Al: [1.84631556 1.94614695 0.22651391]\n", "pbc: [ True True True]\n", "cell: \n", "Cell([[4.17236250917528, 2.554835195871963e-16, 2.554835195871963e-16], [0.0, 4.17236250917528, 2.554835195871963e-16], [0.0, 0.0, 4.17236250917528]])\n", "])" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "al_container.structure_lst" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "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.8.6" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": "block", "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }