# Disorder variable¶

In this example, disorder variable which was introduced to measure the disorder of a system is explored. We start by importing the necessary modules. We will use :mod:~pyscal.crystal_structures to create the necessary crystal structures.

[1]:

import pyscal as pc
import pyscal.crystal_structures as pcs
import matplotlib.pyplot as plt
import numpy as np


First an fcc structure with a lattice constant of 4.00 is created.

[2]:

fcc_atoms, fcc_box = pcs.make_crystal('fcc', lattice_constant=4, repetitions=[4,4,4])


The created atoms and box are assigned to a :class:~pyscal.core.System object.

[3]:

fcc = pc.System()
fcc.box = fcc_box
fcc.atoms = fcc_atoms


The next step is find the neighbors, and the calculate the Steinhardt parameter based on which we could calculate the disorder variable.

[4]:

fcc.find_neighbors(method='cutoff', cutoff='adaptive')


Once the neighbors are found, we can calculate the Steinhardt parameter value. In this example $$q=6$$ will be used.

[5]:

fcc.calculate_q(6)


Finally, disorder parameter can be calculated.

[6]:

fcc.calculate_disorder()


The calculated disorder value can be accessed for each atom using the :attr:~pyscal.catom.disorder variable.

[7]:

atoms = fcc.atoms

[8]:

disorder = [atom.disorder for atom in atoms]

[9]:

np.mean(disorder)

[9]:

-1.041556887034408e-16


As expected, for a perfect fcc structure, we can see that the disorder is zero. The variation of disorder variable on a distorted lattice can be explored now. We will once again use the noise keyword along with :func:~pyscal.crystal_structures.make_crystal to create a distorted lattice.

[10]:

fcc_atoms_d1, fcc_box_d1 = pcs.make_crystal('fcc', lattice_constant=4, repetitions=[4,4,4], noise=0.01)
fcc_d1 = pc.System()
fcc_d1.box = fcc_box_d1
fcc_d1.atoms = fcc_atoms_d1


Once again, find neighbors and then calculate disorder

[11]:

fcc_d1.find_neighbors(method='cutoff', cutoff='adaptive')
fcc_d1.calculate_q(6)
fcc_d1.calculate_disorder()


Check the value of disorder

[12]:

atoms_d1 = fcc_d1.atoms

[13]:

disorder = [atom.disorder for atom in atoms_d1]

[14]:

np.mean(disorder)

[14]:

0.00026650465454653035


The value of average disorder for the system has increased with noise. Finally trying with a high amount of noise.

[15]:

fcc_atoms_d2, fcc_box_d2 = pcs.make_crystal('fcc', lattice_constant=4, repetitions=[4,4,4], noise=0.1)
fcc_d2 = pc.System()
fcc_d2.box = fcc_box_d2
fcc_d2.atoms = fcc_atoms_d2

[16]:

fcc_d2.find_neighbors(method='cutoff', cutoff='adaptive')
fcc_d2.calculate_q(6)
fcc_d2.calculate_disorder()

[17]:

atoms_d2 = fcc_d2.atoms

[18]:

disorder = [atom.disorder for atom in atoms_d2]
np.mean(disorder)

[18]:

0.030475287944847596


The value of disorder parameter shows an increase with the amount of lattice distortion. An averaged version of disorder parameter, averaged over the neighbors for each atom can also be calculated as shown below.

[19]:

fcc_d2.calculate_disorder(averaged=True)

[20]:

atoms_d2 = fcc_d2.atoms
disorder = [atom.avg_disorder for atom in atoms_d2]
np.mean(disorder)

[20]:

0.030373641570262584


The disorder parameter can also be calculated for values of Steinhardt parameter other than 6. For example,

[21]:

fcc_d2.find_neighbors(method='cutoff', cutoff='adaptive')
fcc_d2.calculate_q([4, 6])
fcc_d2.calculate_disorder(q=4, averaged=True)

[22]:

atoms_d2 = fcc_d2.atoms
disorder = [atom.disorder for atom in atoms_d2]
np.mean(disorder)

[22]:

0.11909705997413539


$$q=4$$, for example, can be useful when measuring disorder in bcc crystals