# 2: Crystal Structures and X-ray Diffraction¶

## Example number 2.1, Page number 2.16¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
r = 1;      #assume value of r as 1

#Calculation
#since 4*r = math.sqrt(3)*a
a = 4*r/math.sqrt(3);
R = (a-(2*r))/2;     #since 2*r+2*R = a
R = math.ceil(R*10**3)/10**3;   #rounding off to 3 decimals

#Result
print "radius of interstitial sphere is",R,"r"

radius of interstitial sphere is 0.155 r


## Example number 2.2, Page number 2.17¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration

#Calculation
a_BCC = (4*r_BCC)/math.sqrt(3);     #In BCC(Angstrom)
a_BCCm = a_BCC*10**-10;      #converting a from Angstrom to m
V_BCC = a_BCCm**3;     #volume of unit cell(m^3)
n_BCC = ((1/8)*8)+1;      #number of atoms per unit cell
V1_BCC = V_BCC/n_BCC;     #volume occupied by 1 atom(m^3)
a_FCC = 2*math.sqrt(2)*r_FCC;     #In FCC(Angstrom)
a_FCCm = a_FCC*10**-10;      #converting a from Angstrom to m
V_FCC = a_FCCm**3;     #volume of unit cell(m^3)
n_FCC = ((1/2)*6) + ((1/8)*8);      #number of atoms per unit cell
V1_FCC = V_FCC/n_FCC;     #volume occupied by 1 atom(m^3)
delta_V = (V1_BCC - V1_FCC)*100/V1_BCC;       #change in volume in %
delta_V = math.ceil(delta_V*10)/10;   #rounding off to 1 decimal

#Result
print "decrease of volume during conversion from BCC to FCC is",delta_V,"%"

decrease of volume during conversion from BCC to FCC is 0.5 %


## Example number 2.3, Page number 2.17¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
a = 0.27;      #nearest neighbour distance(nm)
c = 0.494;     #height of unit cell(nm)
M = 65.37;     #atomic weight(kg)

#Calculation
a_m = a*10**-9;    #nearest neighbour distance(m)
c_m = c*10**-9;     #height of unit cell(m)
V = 3*math.sqrt(3)*(a_m**2)*c_m/2;      #volume of unit cell(m^3)
#if rho is density then mass = V*rho
#V*rho = 6*M/N
rho = (6*M)/(N*V);      #density(kg/m^3)

#Result
print "Volume of the unit cell is",round(V/1e-29,2),"*10^-29 m^3"
print "density of Zinc is",round(rho),"kg/m^3"
print "answer for density given in the book differs due to rounding off errors"

Volume of the unit cell is 9.36 *10^-29 m^3
density of Zinc is 6960.0 kg/m^3
answer for density given in the book differs due to rounding off errors


## Example number 2.4, Page number 2.18¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
r = 1;      #assume value of r as 1

#Calculation
a = 4*r/math.sqrt(2);      #for FCC structure
R = (a/2)-r;     #since 2*r+2*R = a
R = math.ceil(R*10**4)/10**4;   #rounding off to 4 decimals

#Result
print "maximum radius of the sphere that can fit into the void is",R,"r"

maximum radius of the sphere that can fit into the void is 0.4143 r


## Example number 2.5, Page number 2.19¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
a = 0.356;      #cube edge of diamond(nm)
aw = 12.01;      #atomic weight of carbon(kg)

#Calculation
a_m = a*10**-9;      #cube edge of diamond(m)
n = 8/(a_m**3);      #number of atoms(per m^3)
n = n/10**29;
n = math.ceil(n*10**3)/10**3;   #rounding off to 3 decimals
n = n*10**29;
M = aw/N;      #mass of 1 carbon atom(kg)
rho =  M*n;

#Result
print "number of atoms per m^3 is",n
print "density of diamond is",int(rho),"kg/m^3"
print "answer for density given in the book differs due to rounding off errors"

number of atoms per m^3 is 1.774e+29
density of diamond is 3537 kg/m^3
answer for density given in the book differs due to rounding off errors


## Example number 2.6, Page number 2.19¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
MW = 23+35.5;      #molecular weight of NaCl(gm)
rho = 2.18;     #density of NaCl(gm/cm^3)
V = 1;     #volume of unit cube(cm^3)

#Calculation
M = MW/N;       #mass of NaCl molecule(gm)
n = rho/M;      #number of molecules per unit volume
n = 2*n;        #since NaCl is diatomic(atoms/cm^3)
#length of edge of unit cube is n*a
#volume V = n^3*a^3 = 1 cm^3
a = (V/n)**(1/3);      #distance between two adjacent atoms(cm)
a = a*10**8;       #distance between two adjacent atoms(A)
a = math.ceil(a*10**3)/10**3;   #rounding off to 3 decimals

#Result
print "distance between two adjacent atoms is",a,"Angstrom"

distance between two adjacent atoms is 2.814 Angstrom


## Example number 2.7, Page number 2.20¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
AW = 63.5;    #atomic weight of Cu(gm/mol)
n = 4;     #number of atoms in unit cell

#Calculation
M = AW/N;      #mass of each Copper atom(gm)
a = 4*r/math.sqrt(2);      #lattice constant(cm)
m = n*M;    #mass of unit cell(gm)
rho = m/a**3;     #density of copper crystal(gm/cm^3)
rho = math.ceil(rho*10**3)/10**3;   #rounding off to 3 decimals

#Result
print "density of Copper crystal is",rho,"gm/cm^3"

density of Copper crystal is 8.929 gm/cm^3


## Example number 2.8, Page number 2.21¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
PF = 0.68;      #packing factor for BCC

#Calculation
a = 4*r/math.sqrt(3);      #lattice constant(nm)
a_m = a*10**-9;        #lattice constant(m)
V = a_m**3;       #volume of unit cell(m^3)
FV = 1-PF;      #free volume
FV1 = FV*V;      #free volume per unit cell(m^3)

#Result
print "free volume per unit cell is",round(FV1/1e-30,4),"*10^-30 m^3"

free volume per unit cell is 7.6795 *10^-30 m^3


## Example number 2.11, Page number 2.27¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
#in (100) plane the total number of atoms are n
n = (1/4)*4;

#Calculation
#in (111) plane, area = (1/2)*base*height = (1/2)*a*sqrt(2)*a*sqrt(2)*cosd(30)
x = math.cos(30);
#area = (1/2)*a*sqrt(2)*a*sqrt(2)*x = 0.866*a^2 = 0.58/a^2
n1 = (1/360)*60*3;

#Result
print "number of atoms in (100) plane are",n;
#A = a^2. number of atoms per mm^2 is n/a^2
print "number of atoms per mm^2 is 1/a^2";
print "number of atoms in (110) plane is 1";
#in (110) plane, area is sqrt(2)*a*a = sqrt(2)*a^2
print "unit area contains 1/(sqrt(2)*a^2) = 0.707/a^2 atoms/mm^2";
print "total number of atoms in (111) plane is",n1
#number of atoms per unit area is 0.5/(0.866*a^2)
print "number of atoms per unit area is 0.58/a^2 atoms/mm^2";

number of atoms in (100) plane are 1.0
number of atoms per mm^2 is 1/a^2
number of atoms in (110) plane is 1
unit area contains 1/(sqrt(2)*a^2) = 0.707/a^2 atoms/mm^2
total number of atoms in (111) plane is 0.5
number of atoms per unit area is 0.58/a^2 atoms/mm^2


## Example number 2.12, Page number 2.28¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
h1 = 1;
k1 = 1;
l1 = 0;     #for (110) plane
h2 = 2;
k2 = 1;
l2 = 2;     #for (212) plane

#Calculation
x1 = math.sqrt(h1**2+k1**2+l1**2);
a = 4*r/x1;     #nearest neighbouring distance(m)
a = a*10**9;     #nearest neighbouring distance(nm)
d_110 = a/x1;    #interplanar spacing for (110),(nm)
x2 = math.sqrt(h2**2+k2**2+l2**2);
d_212 = a/x2;    #interplanar spacing for (212),(nm)
d_212 = math.ceil(d_212*10**4)/10**4;   #rounding off to 4 decimals

#Result
print "interplanar spacing for (110) is",d_110,"nm"
print "interplanar spacing for (212) is",d_212,"nm"

interplanar spacing for (110) is 0.2556 nm
interplanar spacing for (212) is 0.1205 nm


## Example number 2.13, Page number 2.29¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
h1 = 1;
k1 = 0;
l1 = 0;    #for (100) plane
h2 = 1;
k2 = 1;
l2 = 0;    #for (110) plane
h3 = 1;
k3 = 1;
l3 = 1;    #for (111) plane

#Calculation
x1 = math.sqrt(1/(h1**2+k1**2+l1**2));      #for (100) plane
x2 = math.sqrt(1/(h2**2+k2**2+l2**2));      #for (110) plane
x3 = math.sqrt(1/(h3**2+k3**2+l3**2));      #for (111) plane
x2 = math.ceil(x2*10**2)/10**2;   #rounding off to 2 decimals
x3 = math.ceil(x3*10**2)/10**2;   #rounding off to 2 decimals

#Result
print "ratio of the seperation between successive lattice planes is %d:%.2f:%.2f"%(x1,x2,x3)

ratio of the seperation between successive lattice planes is 1:0.71:0.58


## Example number 2.14, Page number 2.30¶

In :
#importing modules
import math
from __future__ import division

#Calculation
#plane intercepts at a,b/2,3*c
#therefore intercepts are (1 1/2 3)
x = 1;
y = 1/2;
z = 3;
def lcm(x, y):
if y > z:
greater = y
else:
greater = z

while(True):
if((greater % y == 0) and (greater % z == 0)):
lcm = greater
break
greater += 1

return lcm

lcm = lcm(y,z);
x_dash = (1/x)*lcm;      #miller index of x plane
y_dash = (1/y)*lcm;      #miller index of y plane
z_dash = (1/z)*lcm;      #miller index of z plane

#Result
print "miller indices of the plane are (",x_dash,y_dash,z_dash,")"

miller indices of the plane are ( 3.0 6.0 1.0 )


## Example number 2.15, Page number 2.37¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
d = 0.282;     #lattice spacing(nm)
n = 1;     #first order
theeta = 90;     #maximum value possible(degrees)

#Calculation
theeta = theeta*math.pi/180;       #maximum value possible(radian)
d = d*10**-9;      #lattice spacing(m)
lamda = 2*d*math.sin(theta)/n;     #wavelength of X-rays(m)
lamda_nm = lamda*10**9;     #wavelength of X-rays(nm)
lamda_nm = math.ceil(lamda_nm*10**4)/10**4;   #rounding off to 4 decimals
n1 = 2*d*math.sin(theeta)/lamda;       #maximum order of diffraction possible

#Result
print "wavelength of X-rays is",lamda_nm,"nm"
print "maximum order of diffraction possible is",int(n1)

wavelength of X-rays is 0.0842 nm
maximum order of diffraction possible is 6


## Example number 2.16, Page number 2.37¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
lamda = 1.5;      #wavelength(A.U)
d = 1.6;      #interplanar spacing(A.U)
theta = 90;     #maximum glancing angle possible(degrees)

#Calculation
theta = theta*math.pi/180;       #maximum glancing angle possible(radian)
n = 2*d*math.sin(theta)/lamda;      #maximum possible diffraction order

#Result
print "maximum possible diffraction order is",int(n)

maximum possible diffraction order is 2


## Example number 2.17, Page number 2.38¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
h = 1;
k = 1;
l = 1;      #for (111) plane
theta = 30;    #glancing angle(degrees)
n = 1;     #first order
lamda = 1.5418;     #wavelength of X-rays(A)

#Calculation
x = math.sqrt(h**2+k**2+l**2);
lamda = lamda*10**-10;     #wavelength of X-rays(m)
d = lamda/(2*math.sin(theta));
a = d*x;      #interatomic spacing(m)
a = a*10**10;      #interatomic spacing(A)
a = math.ceil(a*10**4)/10**4;   #rounding off to 4 decimals

#Result
print "the interatomic spacing is",a,"Angstrom"

the interatomic spacing is 2.6705 Angstrom


## Example number 2.18, Page number 2.38¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
d100 = 0.28;     #lattice constant(nm)
h = 1;
k = 1;
l = 0;      #for (110) plane
n = 2;      #second order
lamda = 0.071;     #wavelength of X-rays(nm)

#Calculation
lamda_m = lamda*10**-9;     #wavelength of X-rays(m)
d110 = d100/math.sqrt(h**2+k**2+l**2);     #interatomic spacing(nm)
d110 = d110*10**-9;      #interatomic spacing(m)
theta = theta*180/math.pi;        #glancing angle(degrees)

#Result
print "the glancing angle is",int(theta),"degrees"

the glancing angle is 21 degrees


## Example number 2.19, Page number 2.39¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
a = 0.38;      #lattice constant(nm)
h = 1;
k = 1;
l = 0;      #for (110) plane

#Calculation
d = a/math.sqrt(h**2+k**2+l**2);
d = math.ceil(d*10**2)/10**2;   #rounding off to 2 decimals

#Result
print "the distance between (110) planes is",d,"nm"

the distance between (110) planes is 0.27 nm


## Example number 2.20, Page number 2.39¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
#area of (110) plane is a*sqrt(2)*a = sqrt(2)*a^2
theta = 30;      #glancing angle(degrees)

#Calculation
n = (1/4)*4;     #number of atoms
x = math.cos(theta);
#area of (111) plane is (a/sqrt(2))*x*a*sqrt(2)
#hence area is (sqrt(3)/2)*a^2
n1 = 3*(1/6);     #number of atoms

#Result
print "area of (110) plane contains",n,"atom"
print "density of lattice points is 1/(sqrt(2)*a^2)"
print "area of (111) plane contains",n1,"atom"
#density of lattice points is (1/2)/(sqrt(3)*a^2/2)
print "density of lattice points is 1/(sqrt(3)*a^2)"
#density of lattice points (111) plane : (110) plane is 1/(sqrt(3)*a^2) : 1/(sqrt(2)*a^2) = sqrt(2):sqrt(3)
print "density of lattice points (111) plane : (110) plane is sqrt(2):sqrt(3)"

area of (110) plane contains 1.0 atom
density of lattice points is 1/(sqrt(2)*a^2)
area of (111) plane contains 0.5 atom
density of lattice points is 1/(sqrt(3)*a^2)
density of lattice points (111) plane : (110) plane is sqrt(2):sqrt(3)


## Example number 2.21, Page number 2.40¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
n = 2;     #second order
h = 1;
k = 1;
l = 0;   #plane (110)
lamda = 0.065;     #wavelength of X-rays(nm)
a = 0.26;      #axial length(nm)

#Calculation
lamda_m = lamda*10**-9;    #wavelength of X-rays(m)
a_m = a*10**-9;    #axial length(m)
x = math.sqrt(h**2+k**2+l**2);
theta = theta*180/math.pi;          #glancing angle(degrees)
deg = int(theta);       #glancing angle(degrees)
t = 60*(theta-deg);
mint = int(t);         #glancing angle(minutes)

#Result
print "the glancing angle is",deg,"degrees",mint,"minutes"

the glancing angle is 20 degrees 42 minutes


## Example number 2.22, Page number 2.41¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
n = 1;    #first order
h = 1;
k = 1;
l = 1;     #for (111) plane
lamda = 1.54;      #wavelength(A.U)
theta = 19.2;      #Bragg's angle(degrees)

#Calculation
lamda_m = lamda*10**-10;      #wavelength(m)
d = n*lamda_m/(2*math.sin(theta));     #interplanar spacing(m)
a = d*math.sqrt(h**2+k**2+l**2);      #cube edge(m)
a_AU = a*10**10;      #cube edge(A.U)
a_AU = math.ceil(a_AU*10**4)/10**4;   #rounding off to 4 decimals

#Result
print "the cube edge is",a_AU,"A.U"

the cube edge is 4.0554 A.U


## Example number 2.23, Page number 2.41¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
n = 1;    #first order
h = 1;
k = 1;
l = 1;     #for (111) plane
lamda = 1.54;    #wavelength(A.U)
theta = 19.2;      #Bragg's angle(degrees)

#Calculation
lamda_m = lamda*10**-10;      #wavelength(m)

the cube edge is 4.055 *10^-10 m