This section gives a brief introduction about some of the tools available in pyiron to construct atomic structures.
For the sake of compatibility, our structure class is written to be compatible with the popular Atomistic Simulation Environment package (ASE). This makes it possible to use routines from ASE to help set-up structures.
Furthermore, pyiron uses the NGLview package to visualize the structures and trajectories interactively in 3D using NGLview-widgets.
As preparation for the following discussion we import a few python libraries
import numpy as np
%matplotlib inline
import matplotlib.pylab as plt
and create a pyiron project named 'structures':
from pyiron.project import Project
pr = Project(path='structures')
In this section we discuss various possibilities to create bulk crystal structures.
create_structure()
¶The simplest way to generate simple crystal structures is using the inbuilt create_structure()
function specifying the element symbol, Bravais basis and the lattice constant(s)
Note: The output gives a cubic cell rather than the smallest non-orthogonal unit cell.
structure = pr.create_structure('Al',
bravais_basis='fcc',
lattice_constant=4.05)
To plot the structure interactively in 3D simply use:
structure.plot3d()
Failed to display Jupyter Widget of type NGLWidget
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
create_ase_bulk()
¶Another convenient way to set up structures is using the create_ase_bulk()
function which is built on top of the ASE build package for bulk crystals. This function returns an object which is of the pyiron structure object type.
Example: fcc bulk aluminum in a cubic cell
structure = pr.create_ase_bulk('Al', cubic=True)
structure.plot3d()
Failed to display Jupyter Widget of type NGLWidget
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
Example: wurtzite GaN in a 3x3x3 repeated orthorhombic cell.
Note:
spacefill=False
in the plot3d()
method changes the atomic structure style to "ball and stick".structure = pr.create_ase_bulk('AlN',
crystalstructure='wurtzite',
a=3.5, orthorhombic=True)
structure.set_repeat([3,3,3])
structure.plot3d(spacefill=False)
Failed to display Jupyter Widget of type NGLWidget
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
from ase.spacegroup import crystal
from pyiron import ase_to_pyiron
a = 9.04
skutterudite = crystal(('Co', 'Sb'),
basis=[(0.25, 0.25, 0.25), (0.0, 0.335, 0.158)],
spacegroup=204,
cellpar=[a, a, a, 90, 90, 90])
skutterudite = ase_to_pyiron(skutterudite)
skutterudite.plot3d()
Failed to display Jupyter Widget of type NGLWidget
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
Using the bulk aluminum fcc example from before the structure object can be created by
structure = pr.create_ase_bulk('Al', cubic=True)
A summary of the information about the structure is given by using
print(structure)
Al: [ 0. 0. 0.] Al: [ 0. 2.025 2.025] Al: [ 2.025 0. 2.025] Al: [ 2.025 2.025 0. ] pbc: [ True True True] cell: [[ 4.05 0. 0. ] [ 0. 4.05 0. ] [ 0. 0. 4.05]]
The cell vectors of the structure object can be accessed and edited through
structure.cell
array([[ 4.05, 0. , 0. ], [ 0. , 4.05, 0. ], [ 0. , 0. , 4.05]])
The positions of the atoms in the structure object can be accessed and edited through
structure.positions
array([[ 0. , 0. , 0. ], [ 0. , 2.025, 2.025], [ 2.025, 0. , 2.025], [ 2.025, 2.025, 0. ]])
We start by setting up a 4x4x4 supercell
structure = pr.create_ase_bulk('Al', cubic=True)
structure.set_repeat([4,4,4])
To create the vacancy at position index "0" simply use:
del structure[0]
To plot the structure that now contains a vacancy run:
structure.plot3d()
Failed to display Jupyter Widget of type NGLWidget
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
# First create a 4x4x4 supercell
structure = pr.create_ase_bulk('Al', cubic=True)
structure.set_repeat([4,4,4])
print('Number of atoms in the repeat unit: ',structure.get_number_of_atoms())
Number of atoms in the repeat unit: 256
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
# Generate a list of indices for the vacancies
n_vac = 24
vac_ind_lst = np.random.permutation(len(structure))[:n_vac]
# Remove atoms according to the "vac_ind_lst"
del structure[vac_ind_lst]
# Visualize the structure
print('Number of atoms in the repeat unit: ',structure.get_number_of_atoms())
structure.plot3d()
Number of atoms in the repeat unit: 232
Failed to display Jupyter Widget of type NGLWidget
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
# Create a 4x4x4 supercell
structure = pr.create_ase_bulk('Al', cubic=True)
structure.set_repeat([4,4,4])
Substitutional atoms can be defined by changing the atomic species accessed through its position index.
Here, we set $n_{\text{sub}}$ magnesium substitutional atoms at random positions
n_sub = 24
structure[np.random.permutation(len(structure))[:n_sub]] = 'Mg'
# Visualize the structure and print some additional information about the structure
print('Number of atoms in the repeat unit: ',structure.get_number_of_atoms())
print('Chemical formula: ',structure.get_chemical_formula())
structure.plot3d()
Number of atoms in the repeat unit: 256 Chemical formula: Al232Mg24
Failed to display Jupyter Widget of type NGLWidget
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
You can also set-up structures through the explicit input of the cell parameters and positions
cell = 10.0 * np.eye(3) # Specifying the cell dimensions
positions = [[0.25, 0.25, 0.25], [0.75, 0.75, 0.75]]
elements = ['O', 'O']
# Now use the Atoms class to create the instance.
O_dimer = pr.create_atoms(elements=elements, scaled_positions=positions, cell=cell)
O_dimer.plot3d()
Failed to display Jupyter Widget of type NGLWidget
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
Some more commonly studied surfaces can also be defined with the create_surface()
function based on the ASE surface builder
fcc111 = pr.create_surface("Pt",
surface_type="fcc111",
size=(3, 4, 5),
a=4.2,
vacuum=20)
fcc111.plot3d()
Failed to display Jupyter Widget of type NGLWidget
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
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)
# The COD structures can be accessed through their unique COD identifier
filename = '1008753.cif'
url = 'http://www.crystallography.net/cod/{}'.format(filename)
# Download and save the structure file locally
import urllib
urllib.request.urlretrieve(url=url, filename='strucs.'+filename);
# Using ase parsers to read the structure and then convert to a pyiron instance
import ase
from pyiron import ase_to_pyiron
structure = ase_to_pyiron(ase.io.read(filename='strucs.'+filename,
format='cif'))
structure.plot3d()
Failed to display Jupyter Widget of type NGLWidget
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.