Atoms playground 2

Continuing from the previous section, let us become more familiar with Atoms through examples of its manipulation.

[1]:
from ase import Atoms
from ase.build import molecule, bulk

from pfcc_extras.visualize.view import view_ngl

Super cell

As already explained, the structure of a periodic system can be increased in cell size by using repeat method or multiplication by “*” notation.

[2]:
atoms = bulk("Si") * (2, 3, 4)
atoms222 = atoms * (2, 2, 2)
view_ngl(atoms222, w=400, h=300)

Cell

The periodic structure atoms has a cell property, which is defined in a special class called the Cell class, which has some additional methods.

[3]:
# atoms = bulk("Fe", cubic=True)
atoms = bulk("Fe") * (2, 2, 2)
view_ngl(atoms, w=400, h=300)
[4]:
atoms.cell
[4]:
Cell([[-2.87, 2.87, 2.87], [2.87, -2.87, 2.87], [2.87, 2.87, -2.87]])

04a6f9ece0b9474cbb916980c31a5dd8

Cite from Fractional coordinates

The crystal cell can be represented by a 3x3 array showing the vectors of the a-, b-, and c-axes, respectively, but using fractional coordinates, it can also be represented by the lengths a, b, and c of the axes and the angles α, β, and γ of the axes. Each of the following methods returns the following values

  • cellpar(): (a, b, c, α, β, γ)

  • lengths(): (a, b, c)

  • angles(): (α, β, γ)

[5]:
print("cellpar(): ", atoms.cell.cellpar())
print("lengths(): ", atoms.cell.lengths())
print("angles() : ", atoms.cell.angles())
cellpar():  [  4.97098582   4.97098582   4.97098582 109.47122063 109.47122063
 109.47122063]
lengths():  [4.97098582 4.97098582 4.97098582]
angles() :  [109.47122063 109.47122063 109.47122063]

To access a 3x3 array, use array to get a numpy array.

[6]:
atoms.cell.array
[6]:
array([[-2.87,  2.87,  2.87],
       [ 2.87, -2.87,  2.87],
       [ 2.87,  2.87, -2.87]])

cell can also use numpy functions. For example, the following uses the diagonal method of numpy to get only the diagonal components.

[7]:
atoms.cell.diagonal()
[7]:
array([-2.87, -2.87, -2.87])

You can also get the Bravais lattice with get_bravais_lattice and the bandpath with bandpath method.

[8]:
atoms.cell.get_bravais_lattice()
[8]:
BCC(a=5.7400000000000002132)
[9]:
atoms.cell.bandpath()
[9]:
BandPath(path='GHNGPH,PN', cell=[3x3], special_points={GHNP}, kpts=[25x3])

The standard_form() method computes the cell form rcell which is standardized to the lower triangular matrix and the rotation matrix Q to make it so.

[10]:
rcell, Q = atoms.cell.standard_form()
rcell
[10]:
Cell([[4.970985817722678, 0.0, 0.0], [-1.6569952725742265, 4.686690374525147, 0.0], [-1.6569952725742256, -2.3433451872625737, 4.058792924010784]])

Element substitution

If you want to create a structure for a crystal with a small amount of an additive, you can model it by substituting atoms after creating the base crystal.

The following example shows the addition of V in Fe metal.

*In the bcc111 method, which generates a surface structure, you can specify the length of the vacuum layer along the z-axis by specifying vacuum. The periodic boundary condition is also applied in the z-axis direction by setting periodic=True. Note that if you do not specify this, the cell size will not be fixed, and nglviewer visualization will raise an error.

[11]:
from ase.build import bcc111
from ase.visualize import view

atoms = bcc111("Fe", size=(4, 4, 6), periodic=True)
view_ngl(atoms, w=400, h=300)

At first, the atoms is all Fe (atomic number 26).

[12]:
numbers = atoms.get_atomic_numbers()
numbers
[12]:
array([26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
       26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
       26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
       26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
       26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
       26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26])

This time we will randomly change 5 atoms to V (atomic number 23).

[13]:
import numpy as np

replace_index = np.random.choice(np.arange(len(numbers)), size=5, replace=False)
print(f"Replace {replace_index} atom")
numbers[replace_index] = 23
atoms.set_atomic_numbers(numbers)
Replace [63 70 76 72 49] atom
[14]:
view_ngl(atoms, w=400, h=300)

If you want to know the atomic number of each element, you can refer to ase.data.atomic_numbers.

[15]:
from ase.data import atomic_numbers
print("atomic_numbers: ", atomic_numbers)

print(f"V's atomic number is", atomic_numbers['V'])
atomic_numbers:  {'X': 0, 'H': 1, 'He': 2, 'Li': 3, 'Be': 4, 'B': 5, 'C': 6, 'N': 7, 'O': 8, 'F': 9, 'Ne': 10, 'Na': 11, 'Mg': 12, 'Al': 13, 'Si': 14, 'P': 15, 'S': 16, 'Cl': 17, 'Ar': 18, 'K': 19, 'Ca': 20, 'Sc': 21, 'Ti': 22, 'V': 23, 'Cr': 24, 'Mn': 25, 'Fe': 26, 'Co': 27, 'Ni': 28, 'Cu': 29, 'Zn': 30, 'Ga': 31, 'Ge': 32, 'As': 33, 'Se': 34, 'Br': 35, 'Kr': 36, 'Rb': 37, 'Sr': 38, 'Y': 39, 'Zr': 40, 'Nb': 41, 'Mo': 42, 'Tc': 43, 'Ru': 44, 'Rh': 45, 'Pd': 46, 'Ag': 47, 'Cd': 48, 'In': 49, 'Sn': 50, 'Sb': 51, 'Te': 52, 'I': 53, 'Xe': 54, 'Cs': 55, 'Ba': 56, 'La': 57, 'Ce': 58, 'Pr': 59, 'Nd': 60, 'Pm': 61, 'Sm': 62, 'Eu': 63, 'Gd': 64, 'Tb': 65, 'Dy': 66, 'Ho': 67, 'Er': 68, 'Tm': 69, 'Yb': 70, 'Lu': 71, 'Hf': 72, 'Ta': 73, 'W': 74, 'Re': 75, 'Os': 76, 'Ir': 77, 'Pt': 78, 'Au': 79, 'Hg': 80, 'Tl': 81, 'Pb': 82, 'Bi': 83, 'Po': 84, 'At': 85, 'Rn': 86, 'Fr': 87, 'Ra': 88, 'Ac': 89, 'Th': 90, 'Pa': 91, 'U': 92, 'Np': 93, 'Pu': 94, 'Am': 95, 'Cm': 96, 'Bk': 97, 'Cf': 98, 'Es': 99, 'Fm': 100, 'Md': 101, 'No': 102, 'Lr': 103, 'Rf': 104, 'Db': 105, 'Sg': 106, 'Bh': 107, 'Hs': 108, 'Mt': 109, 'Ds': 110, 'Rg': 111, 'Cn': 112, 'Nh': 113, 'Fl': 114, 'Mc': 115, 'Lv': 116, 'Ts': 117, 'Og': 118}
V's atomic number is 23

Conversely, if you want to know the symbol/name of an element from its number, you can use chemical_symbols and atomic_names.

[16]:
from ase.data import atomic_names, chemical_symbols
print("chemical_symbols: ", chemical_symbols)
print("atomic_names    : ", atomic_names)

print(f"atomic number 23 is", chemical_symbols[23], atomic_names[23])
chemical_symbols:  ['X', 'H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg', 'Tl', 'Pb', 'Bi', 'Po', 'At', 'Rn', 'Fr', 'Ra', 'Ac', 'Th', 'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf', 'Es', 'Fm', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og']
atomic_names    :  ['', 'Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', 'Neon', 'Sodium', 'Magnesium', 'Aluminium', 'Silicon', 'Phosphorus', 'Sulfur', 'Chlorine', 'Argon', 'Potassium', 'Calcium', 'Scandium', 'Titanium', 'Vanadium', 'Chromium', 'Manganese', 'Iron', 'Cobalt', 'Nickel', 'Copper', 'Zinc', 'Gallium', 'Germanium', 'Arsenic', 'Selenium', 'Bromine', 'Krypton', 'Rubidium', 'Strontium', 'Yttrium', 'Zirconium', 'Niobium', 'Molybdenum', 'Technetium', 'Ruthenium', 'Rhodium', 'Palladium', 'Silver', 'Cadmium', 'Indium', 'Tin', 'Antimony', 'Tellurium', 'Iodine', 'Xenon', 'Caesium', 'Barium', 'Lanthanum', 'Cerium', 'Praseodymium', 'Neodymium', 'Promethium', 'Samarium', 'Europium', 'Gadolinium', 'Terbium', 'Dysprosium', 'Holmium', 'Erbium', 'Thulium', 'Ytterbium', 'Lutetium', 'Hafnium', 'Tantalum', 'Tungsten', 'Rhenium', 'Osmium', 'Iridium', 'Platinum', 'Gold', 'Mercury', 'Thallium', 'Lead', 'Bismuth', 'Polonium', 'Astatine', 'Radon', 'Francium', 'Radium', 'Actinium', 'Thorium', 'Protactinium', 'Uranium', 'Neptunium', 'Plutonium', 'Americium', 'Curium', 'Berkelium', 'Californium', 'Einsteinium', 'Fermium', 'Mendelevium', 'Nobelium', 'Lawrencium', 'Rutherfordium', 'Dubnium', 'Seaborgium', 'Bohrium', 'Hassium', 'Meitnerium', 'Darmastadtium', 'Roentgenium', 'Copernicium', 'Nihonium', 'Flerovium', 'Moscovium', 'Livermorium', 'Tennessine', 'Oganesson']
atomic number 23 is V Vanadium

Creation of vacancies

It is industrially important to study the behavior of defects in crystal structures.

In ASE, the pop method can be used to delete atoms of a particular index. (Alternatively, the del method can also be used.)

The following is an example of creating a defect structure without the 13th Si atom from a Si crystal.

[17]:
atoms = bulk("Si") * (2, 2, 2)
# `del atoms[13]` also works
atoms.pop(13)
view_ngl(atoms, representations=["ball+stick"], w=400, h=300)

These are just a few examples of how atoms can be handled by looking at the various methods implemented in ASE.

From here on, let’s learn by practice, together with calculation methods and examples.