from numpy import degrees, arccos
# Variables
#Miller indices of plane
h_1 = 1.;
k_1 = 1.;
l_1 = 1.;
h_2 = 1.;
k_2 = 2.;
l_2 = 1.;
# Calculation
angle = degrees(arccos((h_1*h_2+k_1*k_2+l_1*l_2)/(((h_1**2+k_1**2+l_1**2)**(1./2))*((h_2**2+k_2**2+l_2**2)**(1./2)))))
# Results
print 'angle Between normals to the planes (111) and (121)(in degrees) = %.2f'%angle
import math
# Variables
r_Na = 0.98; #Radius of Na+(in A)
r_Cl = 1.81; #Radius of Cl-(in A)
a = 2*(r_Na+r_Cl); #Lattice parameter (in A)
# Calculation
pi = 22./7;
V_i = 4*(4./3)*pi*((r_Na**3)+(r_Cl**3)); #Volume of ions present in unit cell
V_u = a**3; #Volume of unit cell
Apf = V_i/V_u; #Atomic packing fraction
Ef_p = (Apf)*100; #Packing efficiency(in %)
AM_sodium = 22.99; #Atomic mass of sodium(in amu)
AM_chlorine = 35.45; #Atomic mass of chlorine(in amu)
M_1 = 4*(AM_sodium+AM_chlorine)*1.66*10**(-27); #Mass of the unit cell
a_1 = a*10**(-10); #Lattice parameter (in meter)
V_u1 = (a_1)**3;
Density = M_1/V_u1;
# Results
print 'Packing efficiency of sodium chloride in = %.1f %%'%Ef_p
print 'density of sodium chloride in = %.0f Kg/m3'%Density
import math
# Variables
Density = 2.7; #(in g/cm**3)
n = 4;
m = 26.98; #atomic weight of Al
# Calculation and Results
N_a = 6.023*10**(23); #avogadro number
a = ((n*m/(Density*N_a))**(1./3)); #Lattice parameter(in Cm)
A = a*10**(8); #Lattice parameter(in A)
print 'radius in = %.3f A'%A
r = A/(2*1.414); #radius for fcp structure
print 'Diameter in %.2f A'%(2*r)
import math
# Variables
r = 1.245; #radius of nickel (in A)
a = 4*r/(2)**(1./2); #Lattice consmath.tant(in A)
#Miller indices of plane 200
h_1 = 2;
k_1 = 0;
l_1 = 0;
#Miller indices of plane 111
h_2 = 1;
k_2 = 1;
l_2 = 1;
# Calculation
d_200 = a/((h_1**2)+(k_1**2)+(l_1**2))**(1./2);
d_111 = a/((h_2**2)+(k_2**2)+(l_2**2))**(1./2);
# Results
print 'interplaner distance of (200) plane of nickel crystal in = %.2f A'%d_200
print 'interplaner distance of (111) plane of nickel crystal in = %.2f A'%d_111
import math
# Variables
a = 3.03*10**(-7); #lattice consmath.tant(in mm)
# Calculation
N_100 = 1/(a**2); #Number of atoms in the (100) plane of a simple cubic structure
N_110 = 0.707/(a**2); #Number of atoms in the (110) plane of a simple cubic structure
N_111 = 0.58/(a**2); #Number of atoms in the (111) plane of a simple cubic structure
# Results
print 'Number of atoms in the (100) plane of a simple cubic structure(in per mm**2) = %.2e'%N_100
print 'Number of atoms in the (110) plane of a simple cubic structure(in per mm**2) = %.1e'%N_110
print 'Number of atoms in the (111) plane of a simple cubic structure(in per mm**2) = %.1e'%N_111
import math
# Variables
r = 1.245*10**(-7); #Radius of the Ni atom(in mm)
# Calculation
NA_100 = 1+(1./4)*4; #Numbers of atom in (100) plane
a = 4*r/(2)**(1./2); #Lattice consmath.tant(in mm)
Area = a**2;
P_density = NA_100/Area;
# Results
print 'the planer density of Ni (in atoms per mm**2) = %.1e'%P_density
import math
# Variables
N_a1 = 4*(1./4)+1; #Number of atoms contained in (100) plane
r = 1.75*10**(-7); #radius of lead atom (in mm)
a_1 = 2*2**(1./2)*r; #edge of unit cell in case of (100) plane
PD_100 = N_a1/(a_1**2); #Planar density of plane (100)
# Calculation
N_a2 = 4*(1./4)+2*(1./2); #Number of atoms contained in (110) plane
a_21 = 4*r; #top edge of the plane (110)
a_22 = 2*2**(1./2)*r; #vertical edge of the plane (110)
PD_110 = N_a2/(a_21*a_22); #Planar density of plane (110)
N_a3 = 3*(1./6)+3./2; #Number of atom contained in (111) plane
Ar_111 = 4*(3**(1./2))*r**2; #area of (111) plane
PD_111 = N_a3/Ar_111; #Planar density of plane (111)
# Results
print 'Planar density of plane 100(in atoms/mm**2) = %.1e'%PD_100
print 'Planar density of plane 110(in atoms/mm**2) = %.1e'%PD_110
print 'Planar density of plane 111(in atoms/mm**2) = %.1e'%PD_111
import math
# Variables
N_a1 = (1./2)+1+(1./2); #Number of diameters of atom along (110) direction
a = 3.61*10**(-7); #lattice consmath.tant of copper in mm
# Calculation
L_d1 = 2**(1./2)*a; #length of the face diagonal in case of (110) direction
p_110 = N_a1/L_d1; #linear atomic density along (110) of copper crystal lattice(in atoms/mm)
N_a2 = (1./2)+(1./2); #Number of diameters of atom along (111) direction
L_d2 = 3**(1./2)*a; #length of the face diagonal in case of (111) direction
p_111 = N_a2/L_d2; #linear atomic density along (110) of copper crystal lattice(in atoms/mm)
# Results
print 'linear atomic density along (110) of copper crystal lattice in = %.2e atoms/mm'%p_110
print 'linear atomic density along (111) of copper crystal lattice in = %.2e atoms/mm'%p_111
import math
# Variables
A = 55.8; #atomic weight of Fe
n = 2; #number of atoms per unit cell
# Calculation
N = 6.02*10**(26); #Avogadro's number
p = 7.87*10**3; #density of Fe(in kg/m**3)
a = ((A*n/(N*p))**(1./3))*10**10; #Value of lattice consmath.tant
# Results
print 'Value of lattice constant in = %.3f A'%a
import math
# Variables
a = 2.9*10**(-10); #lattice parameter(in m)
A = 55.8; #atomic weight of Fe
# Calculation
N = 6.02*10**(26); #Avogadro's number
p = 7.87*10**3; #density of Fe(in kg/m**3
n = (a**3)*N*p/A; #Numbers of atoms per unit cell
# Results
print 'Numbers of atoms per unit cell = ',floor(n)
import math
# Variables
a = 2.87*10**(-10); #lattice parameter for bcc iron
b = a*(3**(1./2))/2; #Magnitude of burgers vector
# Calculation
u = 80*10**9; #shear modulus
E = (1./2)*u*b**2; #line energy of disslocation
# Results
print 'line energy of disslocation in = %.2e J/m'%E
import math
# Variables
N = 6.023*10**23; #avogadro number
T = 1000.; #absolute temperature
R = 8.314; #consmath.tant
# Calculation
H_f = 100*1000; #enthalpy of formation of vacancies(in J/mol)
n = N*math.exp(-(H_f)/(R*T)); #number of vacancies created during heating(in per mol)
V = 5.5*10**(-6); #volume of 1 mole of the crystal in m**3
n_1 = n/V; #number of vacancies created during heating(in per m**3)
# Results
print 'number of vacancies created during heating in = %.2e m**-3'%n_1
import math
# Variables
#bond energy per atom of copper = bond energy per bond*numbers of bond per atom*(1/2)
A = 56.4*1000; #
N = 6.023*10**23; #avogadro number
n_1 = 12.; #numbers of bond per atom
n_2 = 3.; #bonds broken at the surface
# Calculation and Results
E = A*n_1/(2*N); #Energy of total bonds
E_b = E*(n_2/n_1); #Energy of broken bonds on surface
n_a = 1.77*10**19; #no. of atoms on {111} planes in copper(in m**-2)
E_c = n_a*E_b; #Surface energy (enthalpy) of copper
print 'Surface energy (enthalpy) of copper in = %.2f J/m**2'%E_c
import math
# Variables
H_f = 68.*1000; #enthalpy of formation of vacancies(in J/mol)
T_1 = 0; #temp (in K)
T_2 = 300.; #temp (in K)
R = 8.314; #consmath.tant
# Calculation
n = math.exp(-H_f/(R*T_2)); #equilibrium concentration of vacancies in aluminium at 300 K
# Results
print 'equilibrium concentration of vacancies in aluminium at 300 K = %.2e'%n
import math
# Variables
Wavelength = 1.54*10**(-10); #in meter
Angle = 20.3; #in degree
n = 1; #First order
# Calculation
d = Wavelength*n/(2*math.sin(math.radians(Angle))); #the interplanar spacing(in Meter)
# Results
print 'the interplanar spacing between atomic plane in = %.2f A'%(d/(10**-10))
import math
# Variables
wavelength = 0.58; #in Angstrom
angle = 9.5; #in degree
n = 1; #First order
# Calculation
#d_200 = wavelength*n/(2*math.sin(math.radians(angle))); #interplanar spacing(in Angstrom)
d_200 = n/math.sqrt(2**2+0**2+0**2)
#Miller indices of plane
h = 2;
k = 0;
l = 0;
a = 0.58/(math.sin(math.radians(angle))*2*d_200); #Size of unit cell(in Angstrom)
# Results
print 'Size of unit cell in %.2f Angstrom'%a
# book answer is wrong.
import math
# Variables
#Miller indices of plane
h = 1.;
k = 1.;
l = 1.;
wavelength = 0.54; #in angstrom
a = 3.57; #size of a cube
n = 1;
# Calculation
d_111 = a/(h**2+k**2+l**2)**(1./2); #interplanar spacing(in Angstrom)
sinangle = (n*wavelength)/(2*d_111)
angle = math.degrees(math.asin(sinangle))
# Results
print 'Bragg angle(in degree) = %.3f'%angle
# rounding off error
import math
# Variables
d = 1.181; #A
wavelength = 1.540; #in angstrom
angle = 90; #in degrees
# Calculation
n = 2*d*math.sin(math.radians(angle))/(wavelength); #the bragg reflection index
# Results
print 'Bragg reflection index for BCC crystal = %.2f'%n
import math
# Variables
n_1 = 1; #1st order reflection index
angle_1 = 10; #1st order reflection angle
n_3 = 3; #3rd order reflection index
# Calculation
#math.math.sin(math.radians(angle_1)/math.math.sin(math.radians(angle_3) = n_1/n_3
sinangle_3 = n_3 * math.sin(math.radians(angle_1)/n_1); #
angle_3 = math.degrees(math.asin(sinangle_3))
# Results
print '3rd order reflection angle = %.2f'%angle_3
import math
# Variables
angle = 20.3; #in degree
wavelength = 1.54; #in angstrom
n = 1;
a = 3.16; #lattice parameter in angstrom
# Calculation
d = n*wavelength/(2*math.sin(math.radians(angle))); #interplanar spacing
M_indices = a**2/(d**2);
# Results
print 'interplanar spacing of reflection plane %.2f A'%d
print 'miller indices of the reflection plane',floor(M_indices)
print "((110),(101),(011))"
import math
# Variables
#Miller indices of plane
n = 1;
h = 1;
k = 1;
l = 1;
angle = 30; #in degree
wavelength = 2; #in angstrom
# Calculation
d = n*wavelength/(2*math.sin(math.radians(angle))); #interplanar spacing
a = d*(h**2+k**2+l**2)**(1./2); #interatomic spacing
# Results
print 'interatomic spacing(in angstrom) = %.2f'%a