import math
#variable declaration
p = 6250; # Density of crystal in kg/m**3
N = 6.023*10**26; #Avagadros number in atoms/kilomole
M = 60.2; #molecular weight per mole
n = 4; #No. of atoms per unit cell for FCC
#Calculations
a = ((n*M)/float(N*p))**(1/float(3)); #Lattice Constant Å
#result
print'Lattice Constant a = %3.2f'%(a*10**10),'Å';
import math
#variable declaration
h1 = 1; #miller indice
k1 = 1; # miller indice
l1 = 1; # miller indice
h0 = 0; # miller indice
k0 = 0; # miller indice
l0 = 0; # miller indice
p = 1980; # Density of KCl in kg/m**3
N = 6.023*10**26; # Avagadros number in atoms/kilomole
M = 74.5; # molecular weight of KCl
n = 4; # No. of atoms per unit cell for FCC
# calculations
a = ((n*M)/float(N*p))**(1/float(3));
#dhkl = a/math.sqrt((h**2)+(k**2)+(l**2)); #interplanar distance
d100 = a/math.sqrt((h1**2)+(k0**2)+(l0**2)); # interplanar distance
d110 = a/math.sqrt((h1**2)+(k1**2)+(l0**2)); # interplanar distance
d111 = a/math.sqrt((h1**2)+(k1**2)+(l1**2)); # interplanar distance
# Output
print'd100 = %3.2f'%(d100*10**10),'Å';
print'd110 = %3.2f'%(d110*10**10),'Å';
print'd111 = %3.2f'%(d111*10**10),'Å';
import math
import fractions
#variable declaration
h = 4; #miller indices
k = 1; #miller indices
l = 2; #miller indices
#calculation
d = fractions.gcd(h,k);
lcm = (h*k)/float(d);
e = fractions.gcd(lcm,l);
lc = (lcm*l)/float(e); #finding lcm
h1 =1/float(h);
k1 =1/float(k);
l1 =1/float(l);
a = h1*lc; #miller indices
b = k1*lc; #miller indices
c = l1*lc; #miller indices
#result
print'miller indices = %d '%a,'%d'%b,'%d'%c;
import fractions
#variable declaration
#intercepts given are 3a,4b,2c
#from the law of rational indices
#3a:4b:2c=a/h:b/k:c/l
#Variable Declaration
h1 = 3; #miller indices
k1 = 4; #miller indices
l1 = 2; #miller indices
#calculation
d = fractions.gcd(h1,k1);
lcm = (h1*k1)/float(d);
e = fractions.gcd(lcm,l1);
lc = (lcm*l1)/float(e); #finding lcm
h = lc*1/float(h1); #miller indices
k = lc*1/float(k1); #miller indices
l= lc*1/float(l1); #miller indices
#result
print'miller indices = %d'%h,'%d'%k,'%d'%l;
import fractions
#variable declaration
#intercepts given are a,2b,-3c/2
#from the law of rational indices
#a:2b:-3c/2=a/h:b/k:c/l
#variable declaration
h1 = 1; #miller indices
k1 = 2; #miller indices
l1 = 3; #miller indices
#calculation
d = fractions.gcd(h1,k1);
lcm = (h1*k1)/float(d);
e = fractions.gcd(lcm,l1);
lc = (lcm*l1)/float(e);
h2 = 1;
k2 = 1/float(k1);
l2 = -2/float(l1)
h = h2*lc; #miller indices
k = (k2)*(lc); #miller indices
l = (l2)*(lc); #miller indices
#result
print'miller indices = %3.0f'%h,'%3.0f'%k,'%3.0f'%l;
import fractions
#variable declaration
#intercepts given are 3a,3b,2c
#from the law of rational indices
#3a:3b:2c=a/h:b/k:c/l
#variable declaration
a = 4;
b = 4;
c = 2;
a1 = 2;
b1 = 1;
c1 = 1;
a3 = 1;
b3 = 1;
c3 = 1;
h12 = 1/float(2); #miller indices
k12 = 1; #miller indices
#l12 = 1/math.inf; #miller indices
l12 =0;
h13 = 1; #miller indices
k13 = 2; #miller indices
l13 = 1; #miller indices
#calculation
d = fractions.gcd(a,b);
lcm = (a*b)/float(d);
e = fractions.gcd(lcm,c);
lc = (lcm*c)/float(e); #finding lcm
h1 = 1/float(4); #miller indices
k1 = 1/float(4); #miller indices
l1 = 1/float(2); #miller indices
h = h1*(lc); #miller indices
k = (k1)*(lc); #miller indices
l = (l1)*(lc); #miller indices
d = fractions.gcd(a1,b1);
lcm = (a1*b1)/float(d);
e = fractions.gcd(lcm,c1);
lc1 = (lcm*c1)/float(e);
# 1/%inf = 0 ; (1/2 1/1 0/1) hence lcm is taken for [2 1 1]
h3 = h12*(lc1); #miller indices
k3 = (k12)*(lc1); #miller indices
l3 = (l12)*(lc1); #miller indices
d = fractions.gcd(a3,b3);
lcm = (a3*b3)/float(d);
e = fractions.gcd(lcm,c3);
lc2 = (lcm*c3)/float(e);
h4 = h13*(lc2); #miller indices
k4 = k13*(lc2); #miller indices
l4 = l13*(lc2); #miller indices
#result
print'miller indices = %d'%h,'%d'%k,'%d'%l;
print'Note:printing mistake of miller indices in textbook \n';
print'\nmiller indices = %d'%h3,'%d'%k3,'%d'%l3;
print'\nmiller indices = %d'%h4,'%d'%k4,'%d'%lc2;
print'Note:calculation mistake in textbook\n';
import math
#variable declaration
h = 1; #miller indices
k = 0; #miller indices
l = 0; #miller indices
h1 = 1; #miller indices
k1 = 1; #miller indices
l1 = 1; #miller indices
#calculations
d100 = 1/float(math.sqrt((h**2)+(k**2)+(l**2)));
d111 = 1/float(math.sqrt((h1**2)+(k1**2)+(l1**2)));
#result
print'd100 = %3.2f a'%d100;
print'd111 = %3.2f a'%d111;
import fractions
#variable declaration
#intercepts given are a,2b,-3c/2
#from the law of rational indices
#a:2b:-3c/2=a/h:b/k:c/l
#variable declaration
h1 = 1;
k1 = 2;
l1 = 1;
a = 10*10**-9;
#calculation
h12 = 1; #miller indices
k12 = 1/float(k1); #miller indices
l12 = 0; #miller indices
#1/%inf = 0 ; (1/2 1/1 0/1) hence lcm is taken for [2 1 1]
d = fractions.gcd(h1,k1);
lcm = (h1*k1)/float(d);
e = fractions.gcd(lcm,l1);
lc = (lcm*l1)/float(e);
h = h12*(lcm); #miller indices
k = (k12)*(lcm); #miller indices
l = (l12)*(lcm); #miller indices
d = a/float(((h**2)+(k**2)+(l**2))**(1/float(2)));
#result
print'miller indices = %d'%h,'%d'%k,'%d'%l;
print'interplanar distance is =%3.2f'%(d*10**9),'Å';
import math
#variable Declaration
r = 0.175*10**-9; #radius in m
h = 2; #miller indices
k = 3; #miller indices
l = 1; #miller indices
#calculation
a = (4*r)/math.sqrt(2);
dhkl = a/float(math.sqrt((h**2)+(k**2)+(l**2)));
#result
print'inter planar spacing =%3.2e'%dhkl,'m/n';
print'Note : calculation mistake in textbook in calculating in dhkl,r value istaken as 0.125*10**-9 instead of 0.175*10**-9 ';
import math
a = 4; #lattice constant in Å
#calculation
d = (math.sqrt(3)*a)/float(4); #distance between two atoms in Å
#result
print'distance between two atoms =%3.3f'%d,'Å';
import math
#variable declaration
d = 1.41; #lattice constant in Å
theta = 8.8; # angle in degrees
n = 1;
#calculation
lamda = (2*d*(math.sin(theta*math.pi/float(180))))/float(n); #wavelength in Å
#result
print'wavelength=%3.3f'%lamda,'Å';
import math
d = 2.5; #spacing in angstroms
theta = 9; #glancing angle in degrees
n1 = 1;
n2 = 2;
#calculation
lamda = (2*math.sin(theta*(math.pi/180))*d); #wavelength Å
theta = math.asin((2*lamda)/float(2*d)); #glancing angle in °
#result
print'wavelength =%3.4f'%lamda,'Å';
print'glancing angle =%3.1f'%(theta*(180/math.pi)),'°';
import math
#variable declaration
lamda = 2; #wavelength in angstroms
theta1 = 60; #angle in degrees
n = 1;
#formula
#2*d*math.sin(theta)=n*lamda
#calculation
d = (n*lamda)/(2*math.sin(theta1*math.pi/float(180))); #lattice constant in Å
#result
print'lattice constant=%3.2f'%d,'Å';
print'note:printing mistake in textbook in calculation part,n value is printed as 2';
import math
#variable declaration
lamda = 1.4*10**-10; #wavelength in angstroms
a = 2*10**-10; #lattice parameter in angstroms
h = 1; #miller indices
k = 1; #miller indices
l = 1; #miller indices
n = 1;
#formula
#2*d*math.sin(theta)=n*lamda
#calculation
dhkl = a/float(math.sqrt((h**2)+(k**2)+(l**2))); #inter planar spacing
theta = math.asin((n*lamda)/float(2*dhkl)); #angle in °
#result
print'angle=%3.2f'%(theta*(180/float(math.pi))),'°';
import math
#variabledeclaration
d = 3.84 *10**-10; #spacing between planes in m
theta = 45; #glancing angle in degrees
m = 1.67*10**-27; #mass ef electron
h = 6.62*10**-34; #planck's constant
n = 1; #braggg reflextion
v = 5.41*10**-10;
#calculation
#lamda = 2*d*(1/math.sqrt(2));
lamda = (n*h)/float(m*v); #wavelength of neutron
#result
print'wavelength of neutron =%3.2e'%lamda,'m/n';
print' Note:calculation mistake in text book in calculating wavelength ';
import math
#variable declaration
m = 9.1*10**-31; # mass of electron in kilograms
e = 1.6*10**-19; #charge of electron in coulombs
n = 1; #bragg's reflection
h1 = 6.62*10**-34; #planck's constant J.s
n = 1; #bragg reflecton
V = 200; #voltage in V
theta = 22; #observed reflection
#calculation
lamda = h1/math.sqrt(2*m*e*V);
dhkl = (n*lamda)/float(2*math.sin(theta*math.pi/180));
a = dhkl*math.sqrt(3); #lattice parameter in Å
#result
print'lattice parameter =%3.0f'%(a*10**10),'Å';