# Lattice spacing from Miller indices
import math
# Intercepts are in the ratio 3a:4b along X,Y and parallel to Z axis
# x-intercept 3, y-intercept 4 and z-intercept infinity
#variable declaration
a=2.0*10**-10 # 2 Angstrom
h=4.0 # Miller indices wrt X-axis
k=3.0 # Miller indices wrt Y-axis
l=0.0 # Miller indices wrt Z-axis
#calculation
d=a/math.sqrt(h**2+k**2+l**2)
#result
print('The lattice spacing for the plane (%d%d%d) is %.1f*10^-10 m'%(h,k,l,d*10**10))
#Lattice constant of Sodium
import math
#variable declaration
d=9.6*10**2 # Density of sodium in kg/m^3
awt=23 # Atomic weight of sodium
n=2 # No of sodium atoms present in one unit cell
avg=6.023*10**26 # Avogadro number
#calculation
m=n*awt/avg
a=(m/d)**(1.0/3.0)
#Result
print('The lattice constant of sodium is %.1f A°'%(a*10**10))
#Avogadro Constant
import math
#variable declaration
d=4.0*10**3 # Density of CsCl in kg/m^3
awtcs=132.9 # Atomic weigt of Cs
awtcl=35.5 # Atomic weigt of Cl
a=4.12*10**-10 # Lattice constant
#Calculations
m=d*a**3
N=(awtcs+awtcl)/m
#Result
print('The value of Avogadro Constant %.4f *10^26 per kg mole'%(N*10**-26))
# Interatomic spacing
import math
#variable declaration
lam=1.5418*10**-10 # Wavelength of X-rays
theta=30.0 # Angle of diffracted angle
h=1.0 # Miller indices wrt X-axis
k=1.0 # Miller indices wrt Y-axis
l=1.0 # Miller indices wrt Z-axis
#Calculation
a=lam*math.sqrt(h**2+k**2+l**2)/(2*math.sin(theta*math.pi/180))
#Result
print('The lattice constant is %.4f *10^-10 m'%(a*10**10))
#Lattice spacing in a rock salt
import math
#variable cdeclaration
h=1.0 # Miller indices wrt X-axis
k=0.0 # Miller indices wrt Y-axis
l=0.0 # Miller indices wrt Z-axis
a=2.814*10**-10 # interatomic spacing
#calculations
d=a/math.sqrt(h**2+k**2+l**2)
#Result
print('The lattice spacing for the plane(%d%d%d) is %.3f*10^-10 m'%(h,k,l,d*10**10))
#Lattice spacing from Miller indices
import math
#variable declaration
h=3.0 # Miller indices wrt X-axis
k=2.0 # Miller indices wrt Y-axis
l=1.0 # Miller indices wrt Z-axis
a=4.12*10**-10 # interatomic spacing
#calculation
d=a/math.sqrt(h**2+k**2+l**2)
#result
print('The lattice spacing for the plane(%d%d%d) is %.4f*10^-10 m'%(h,k,l,d*10**10))
#Lattice spacing from Miller indices
import math
#(i)
#variable declaration
h=1.0 # Miller indices wrt X-axis
k=0.0 # Miller indices wrt Y-axis
l=1.0 # Miller indices wrt Z-axis
a=4.2*10**-10 # lattice constant
#calculation
d=a/math.sqrt(h**2+k**2+l**2)
#Result
print('\nThe lattice spacing for the plane(%d%d%d) is %.4f*10^-10 m'%(h,k,l,d*10**10))
#(ii)
#variable declaration
h=2 # Miller indices wrt X-axis
k=2 # Miller indices wrt Y-axis
l=1 # Miller indices wrt Z-axis
a=4.12*10**-10 # Lattice constant
#calculation
d=a/math.sqrt(h**2+k**2+l**2)
#Result
print('\nThe lattice spacing for the plane(%d%d%d) is %.1f*10^-10 m'%(h,k,l,d*10**10))
#Answer in the book for plane(101) is wrong
#Lattice spacing from Miller indices
import math
#(i)
#variable declaration
h=1.0 # Miller indices wrt X-axis
k=1.0 # Miller indices wrt Y-axis
l=1.0 # Miller indices wrt Z-axis
a=4.12*10**-10 # lattice Constant
#calculation
d=a/math.sqrt(h**2+k**2+l**2)
#Result
print('\nFor (%d%d%d) plane\nThe lattice spacing is %.4f*10^-10 m'%(h,k,l,d*10**10))
#(ii)
#variable declaration
h=1.0 # Miller indices wrt X-axis
k=1.0 # Miller indices wrt Y-axis
l=2.0 # Miller indices wrt Z-axis
a=4.12*10**-10 # Lattice Constant
#calculation
d=a/math.sqrt(h**2+k**2+l**2)
#Result
print('\n\nFor (%d%d%d) plane\nThe lattice spacing is %.4f*10^-10 m'%(h,k,l,d*10**10))
#(iii)
#variable declaration
h=1.0 # Miller indices wrt X-axis
k=2.0 # Miller indices wrt Y-axis
l=3.0 # Miller indices wrt Z-axis
a=4.12*10**-10 # Lattice Constant
#calculation
d=a/math.sqrt(h**2+k**2+l**2)
#Result
print('\n\nFor (%d%d%d) plane\nThe lattice spacing is %.4f*10^-10 m'%(h,k,l,d*10**10))
# Lattice spacing from Miller indice
import math
#variable declaration
h=2.0 # Miller indices wrt X-axis
k=2.0 # Miller indices wrt Y-axis
l=0.0 # Miller indices wrt Z-axis
a=4.938*10**-10 # Lattice Constant
#calculation
d=a/math.sqrt(h**2+k**2+l**2)
#Result
print('\nThe lattice spacing for (%d%d%d) plane is %.4f*10^-10 m'%(h,k,l,d*10**10))
#Note: Final answer in the book is as follow:
# The lattice spacing for the plane (110) is 2.968 x 10^-10 m
#Number of atoms in Al foil
import math
#variable declaration
a=0.405*10**-10 # lattice constant
t=0.005 # thickness of Al foil
A=25*10**-2 # side length of Al foil
#calculation
n=t*A/a**3
#Result
print('The number of atoms in the Al foil is %.2f * 10^28'%(n*10**-28))
#no of unit cells in 1 kg metal
import math
#variable declaration
a=2.88*10**-10 # lattice constant
d=7200.0 # Density of metal in k/m^3
#calculation
n=1/(d*a**3)
#Result
print('The number of unit cells present in 1 kg metal is %.4f *10^24'%(n*10**-24))
#percentage volume change during structural changes
import math
#variable declaration
rbcc=0.1258*10**-9 # Atomic radius at bcc state
rfcc=0.1292*10**-9 # Atomic radius at fcc state
#calculation
a=4*rbcc/math.sqrt(3)
vbcc=(a**3)/2
a1=4*rfcc/math.sqrt(2)
vfcc=(a1**3)/4
vp=(vbcc-vfcc)
vp=math.floor(vp*10**32)
vp=vp*10**-32/vbcc
#Result
print('The volume change in %% duringg the structural change is %.4f'%(vp*100))
#Copper Density
import math
#variable declaration
awt=63.5*10**-3 # Atomic weight of copper
avg=6.023*10**26 # Avagadro No.
r=1.273*10**-10 # Atomic radius for fcc system
n=4.0 # No of atoms per unit cell for fcc
#calculation
a=4*r/math.sqrt(2)
a= math.floor(a*10**11)/10**11
d=n*awt/(avg*a**3)
#Result
print('The density of copper is %.5f gm/m^3'%d)
# Atomic Radius
import math
#variable declaration
d=7860.0 # Density of alfa-iron
m=55.85 # atomic weight of alfa-iron
n=2.0 # No of atoms per unit cell for Bcc
avg=6.023*10**26 # Avoigadro's Number
#calculation
a=(n*m*10**-3/(avg*d))**(1.0/3.0)
r=a*math.sqrt(3)/4.0
#Result
print('\nThe lattice constant of alfa-iron is %.4f A°'%(a*10**10))
print('\nThe atomic radius of alfa-iron is %.5f *10^-10 m'%(r*10**10))
#Lattice constant
import math
#variable declaration
d=8960.0 # Density of copper
m=63.54 # Atomic weight of copper
n=4.0 # No of atoms per unit cell for Fcc
avg=6.023*10**26 # Avogadro's number
#calculation
a=(n*m*10**-3/(avg*d))**(1.0/3.0)
#Result
print('\nThe lattice constant of copper is %.4f A°'%(a*10**10))
# Glancing angle
import math
#variable declaration
a=3.81*10**-10 # lattice spacing
h=1.0 # Miller indices wrt X-axis
k=3.0 # Miller indices wrt Y-axis
l=2.0 # Miller indices wrt Z-axis
lam=0.58*10**-10 # Wavelength of X-rays
n=2.0 # order of diffraction
#calculation
d=a/math.sqrt(h**2+k**2+l**2)
theta=math.asin(n*lam/(2*d))
#Result
print('The angle of glancing at which 2nd order diffraction pattern of NaCl occurs is %.2f°'%(theta*180/math.pi))
# Lattice constant
import math
#variable declaration
h=3.0 # Miller indices wrt X-axis
k=0.0 # Miller indices wrt Y-axis
l=2.0 # Miller indices wrt Z-axis
theta=35 # glancing angle
lam=0.7*10**-10 # wavelength of X-rays
n=1.0 # order of diffraction
#calculations
d=n*lam/(2*math.sin(theta*math.pi/180))
a=d*math.sqrt(h**2+k**2+l**2)
#Result
print('\nThe interplanar distance for(302) plane is %.3f*10^-11 m'%(d*10**11))
print('\nThe lattice constance is %.2f*10^-10 m'%(a*10**10))
# Plane drawing 1
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
point = np.array([0, 0, 1])
normal = np.array([0, 0, 1])
# calculations
d = -point.dot(normal)
x, y = np.meshgrid(range(10), range(10)) # create x,y
z = (-normal[0] * x - normal[1] * y - d) * 1. / normal[2] # calculate corresponding z
# Result
plt3d = plt.figure().gca(projection='3d')
plt3d.plot_surface(x, y, z, rstride=1, cstride=1)
plt.show()
# Plane drawing 2
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
point = np.array([1, 0, 1])
normal = np.array([1, 0, 1])
# calculations
d = -point.dot(normal)
x, y = np.meshgrid(range(10), range(10)) # create x,y
z = (-normal[0] * x - normal[1] * y - d) * 1. / normal[2] # calculate corresponding z
# Result
plt3d = plt.figure().gca(projection='3d')
plt3d.plot_surface(x, y, z, rstride=1, cstride=1)
plt.show()
# Plane drawing 3
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
point = np.array([1, 1, 1])
normal = np.array([1, 1, 1])
# calculations
d = -point.dot(normal)
x, y = np.meshgrid(range(10), range(10)) # create x,y
z = (-normal[0] * x - normal[1] * y - d) * 1. / normal[2] # calculate corresponding z
# Result
plt3d = plt.figure().gca(projection='3d')
plt3d.plot_surface(x, y, z, rstride=1, cstride=1)
plt.show()
# InterPlanar Spacing
import math
#Variable Declaration
theta=12 # glancing angle
lam=2.82*10**-10 # interplanar spacing
n=1.0 # order of diffraction
#Calculation
d=n*lam/(2*math.sin(theta*math.pi/180))
#Result
print('The interplanar spacing is %.3f *10^-10 m'%(d*10**10))
# Lattice spacing and deBroglie wavelength
import math
#variable Declaration
theta=27.5/2 # glancing angle
a=0.563*10**-9 # lattice constant
n=1.0 # order of diffraction
h=1.0 # Miller indices wrt X-axis
k=1.0 # Miller indices wrt Y-axis
l=1.0 # Miller indices wrt Z-axis
#calaculation
d=a/math.sqrt(h**2+k**2+l**2)
lam=2*d*math.sin(theta*math.pi/180)/n
#Result
print('\nThe lattice spacing for the plane (111) is %.2f * 10^-10 m'%(d*10**10))
print('\nThe deBroglie wavelength of the neutrons is %.3f *10^-10 m'%(lam*10**10))
# Lattice constant and atomic radius
import math
#variable declaration
h=1.0 # Miller indices wrt X-axis
k=1.0 # Miller indices wrt Y-axis
l=0.0 # Miller indices wrt Z-axis
d=2*10**-10 #interplanar spacing
#Calculation
a=d*math.sqrt(h**2+k**2+l**2)
R=a/(2*math.sqrt(2))
#Result
print('The lattice constant is %.3f*10^-10 m\nThe atomic radius of the crystal is %.1f *10^-10 m'%(a*10**10,R*10**10))
#Answer in the book for lattice constant is wrong
#energy of the neutron
import math
#variable declaration
theta=22 # glancing angle
d=1.8*10**-10 # interplanar spacing
n=1.0 # order of diffraction
h=6.626*10**-34 # planck's constant
m=9.11*10**-31 # mass of an atom kg
e=1.609*10**-19 # Charge of an electron
#calculations
lam=2*d*math.sin(theta*math.pi/180)/n
lam= math.ceil(lam*10**13)/10**13
E=(1/(2*m))*(h/lam)**(2)
#result
print('\nThe deBroglie wavelength of the neutron is %.3f *10^-10\nthe energy of the neutron is %.3f eV'%(lam*10**10,E/e))
# InterPlanar Spacing
import math
#variable declaration
h=1.0 # Miller indices wrt X-axis
k=1.0 # Miller indices wrt Y-axis
l=1.0 # Miller indices wrt Z-axis
a=3*10**-10 # lattice spacing
#calculation
d=a/math.sqrt(h**2+k**2+l**2)
#Result
print('\nThe interplanar spacing for the plane(%d%d%d) is %.3f*10^-10 m'%(h,k,l,d*10**10))
# Lattice spacing from Miller indices
import math
#variable declaration
h=3.0 # Miller indices wrt X-axis
k=2.0 # Miller indices wrt Y-axis
l=1.0 # Miller indices wrt Z-axis
rfcc=0.1278*10**-9 # Atomic radius at Fcc State
#calculation
a=4*rfcc/math.sqrt(2)
d=a/math.sqrt(h**2+k**2+l**2)
#Result
print('\nThe lattice constant = %.3f *10^-10\nThe interplanar spacing for the plane(%d%d%d) is %.2f*10^-11 m'%(a*10**10,h,k,l,d*10**11))
# Number of atoms in Al foil
import math
#variable declaration
a=0.4049*10**-10 # lattice constant
t=0.005 # thickness of the coil
A=25*10**-2 # Area of the foil
#calculation
n=t*A/a**3
#Result
print('The number of atoms in the Al foil is %.2f * 10^28'%(n*10**-28))
# energy of the neutron
import math
#variable declaration
theta=20 # glancing angle
d=2*10**-10 # interplanar spacing
n=1.0 # order of diffraction
h=6.626*10**-34 # planck's constant
m=1.67*10**-27 # mass of an atom
e=1.609*10**-19 # charge of an electron
#Calculation
lam=2*d*math.sin(theta*math.pi/180)/n
E=(1/(2*m))*(h/lam)**(2)
#Result
print('\nThe deBroglie wavelength of the neutron is %.3f *10^-10\nthe energy of the neutron is %.5f eV'%(lam*10**10,E/e))
# deBroglie wavelength of electrons
import math
#variable declaration
e=1.602*10**-19 # charge of an electron
h=6.626*10**-34 # planck's constant
m=9.11*10**-31 # mass of an electron
ek=235.2*e # kinetic energy
n=1.0 # order of diffraction
theta=9.21 # glancing angle
#Calculation
lam=h/math.sqrt(2*m*ek)
d=n*lam/(2*math.sin(theta*math.pi/180))
#Result
print('\nThe deBroglie wavelength of electron is %.3f *10^-11 m\nThe interplanar spacing is %.3f *10^-10 m'%(lam*10**11,d*10**10))
# Lattice spacing from Miller indices
import math
# Intercepts are in the ratio 3a:4b along X,Y and parallel to Z axis
# x-intercept 3, y-intercept 4 and z-intercept infinity
#variable declaration
a=2.0*10**-10 # 2 Angstrom
h=4.0 # Miller indices wrt X-axis
k=3.0 # Miller indices wrt Y-axis
l=0.0 # Miller indices wrt Z-axis
#calculation
d=a/math.sqrt(h**2+k**2+l**2)
#result
print('The lattice spacing for the plane (%d%d%d) is %.1f*10^-10 m'%(h,k,l,d*10**10))
# Plane Drawing
print('Same as example 2.24 of the same chapter')