## Calculate effective number of lattice point in three cubic space lattice
import math
sc_n = 1/8. ## sharing of one lattice point in a unit cell
sc_N = 8. ## Number of lattice points in Simple cubic
bcc_n_e = 1/4.## sharing of one edge lattice point in a BCC
bcc_N_e = 4.## Number of edge lattice point in a BCC
bcc_n_c = 1.## sharing of one body center lattice point in a BCC
bcc_N_c = 1.## Number of body center lattice point in a BCC
fcc_n_e = 1/8. ## sharing of one corner lattice point in a FCC
fcc_N_e = 8.## Number of corner lattice point in a FCC
fcc_n_f = 1./2. ## sharing of one face center lattice point in a FCC
fcc_N_f = 6.## Number of face center lattice point in a FCC
print("\n Example 3.2 ")
sc_net = sc_n*sc_N
bcc_net = bcc_n_e*bcc_N_e+bcc_n_c*bcc_N_c
fcc_net = fcc_n_e*fcc_N_e+fcc_n_f*fcc_N_f
print("\n Effective number of lattice points are as:")
print( "\n\n Space lattice \t Abbreviation \t Effective number of lattice point in unit cell \n")
print"%s %.2f %s %.2f %s %.2f %s"%("Simple cubic \t\tSC \t\t\t\t ",sc_net,"\n Body center cubic\tBCC \t\t\t\t ",bcc_net," \n Face centered cubic\tFCC \t\t\t\t ",fcc_net," ")
## Determine Interplanar spacing and miller indices
import math
a = 3.16 ## lattice parameter in angstrom
l1 = 1. ## line number
l2 = 2. ## line number
l3 = 3. ## line number
l4 = 4. ## line number
theta1 = 20.3 ## angle for line 1
theta2 = 29.2## angle for line 2
theta3 = 36.7## angle for line 3
theta4 = 43.6## angle for line 4
n = 1 ## order
D = 1.54 ## wavelength in angstrom
print(" Example 3.7")
d1 = D/(2.*math.sin(theta1*math.pi/180.))
d2 = D/(2.*math.sin(theta2*math.pi/180.))
d3 = D/(2.*math.sin(theta3*math.pi/180.))
d4 = D/(2.*math.sin(theta4*math.pi/180.))
x1 = a**2/d1**2
x2 = a**2/d2**2
x3 = a**2/d3**2
x4 = a**2/d4**2 ## where x is function of h,k and l
print'%s %.2f %s'%(" Interplanar spacing is ",x1," angstrom ") ## answer in book is 2.220 angstrom
if math.floor(x1) == 2:
print'%s %.2f %s'%(" For a**2/d**2 = ",x1,"\t Reflection plane is {110}")
if math.floor(x2) == 4 :
print'%s %.2f %s'%(" For a**2/d**2 =",x2," \t Reflection plane is {200}")
if math.floor(x3) == 6:
print'%s %.2f %s'%(" For a**2/d**2 =",x3," \t Reflection plane is {211}")
if math.floor(x4) == 8:
print'%s %.2f %s'%(" For a**2/d**2 =",x4," \t Reflection plane is {220}")
## Determine structure and lattice parameter of material
import math
d = 114.6 ## diameter of power camera in angstrom
D= 1.54 ## wavelength in angstrom
s1 = 86.
s2 = 100.
s3 = 148.
s4 = 180.
s5 = 188.
s6 = 232.
s7 = 272.
print("\n Example 3.8")
R = d/2. ## Radius
if R==57.3 :
k = 1/4. ## Bragg angle factor
a1 = (math.sin(s1*k*math.pi/180))**2.
a2 = (math.sin(s2*k*math.pi/180))**2.
a3 = (math.sin(s3*k*math.pi/180))**2.
a4 = (math.sin(s4*k*math.pi/180))**2.
a5 = (math.sin(s5*k*math.pi/180))**2.
a6 = (math.sin(s6*k*math.pi/180))**2.
a7 = (math.sin(s7*k*math.pi/180))**2.
c = 22. ## constant to convert into integral number
print'%s %.2f%s %.2f%s %.2f%s %.2f%s %.2f%s %.2f%s %.2f%s '%("\n Within experimental error, values are as in integral ratio are as: \n ",math.ceil(c*a1),":",math.ceil(c*a2),":",math.ceil(c*a3),":",math.ceil(c*a4),":",math.ceil(c*a5),":",math.ceil(c*a6)," :",math.ceil(c*a7),"")
print(" So, this structure is FCC and material is copper with 3.62 angstrom lattice parameter")