In [1]:

```
from __future__ import division
import math
# Python Code Ex1.1 Determine the number of edges in a quartz crystal;
#if there are 18 faces and 14 angles in it.: Page-2 (2010)
# Variable declaration
f = 18; # Number of faces of the quartz crystal
c = 14; # Number of angles in the quratz crystal
# Calculations
# The relationship amongst the crystal elements can be
# expressed by the following formula:
# f + c = e + 2;
# Solving for e
e = f + c - 2;
# Result
print "The number of edges of the quartz crystal is : ",e
```

In [4]:

```
from __future__ import division
import math
# Python Code Ex1.2 Primitive unit cell: Page-4 (2010)
#Variable declaration
# Lattice translation vectors along X and Y direction, angstrom
a = 3
b = 3
c_bar = 3; # Assumed translation vector along Z direction, angstrom
# Calculation
c = 1.5*(a+b+c_bar);#Real translation vector along Z direction, angstrom
V_con = a**3; # Volume of conventional unit cell, metre cube
V_primitive = 1/2*V_con; # Volume of primitive unit cell, metre cube
#Result
print "If is the body centered position of a cubic unit cell"
print"Defined by the primitive translation vectors a,b and c_bar.", c
print "\nThe volume of conventional unit cell (angstrom cube):",V_con
print "\nThe volume of primitive unit cell (angstrom cube) :", V_primitive
```

In [5]:

```
from __future__ import division
import math
# Python Code Ex1.3 Calculate the number of atoms per unit cell
# for an fcc lattice of copper crystal. Page-9 (2010)
# Variable declaration
a = 3.60*10**(-10); # Lattice parameter, m:
M = 63.6; # Atomic weight, gram per mole
d = 8960*10**(+03) # Density of copper, g per metre cube
N = 6.023*10**(+23); # Avogadro's No.
#Calculations
# Volume of the unit cell is given by
# a**3 = M*n/(N*d)
# Solving for n
n = a**3*d*N/M; # Number of lattice points per unit cell
# Result
print"Number of atoms per unit cell for an fcc lattice of copper crystal is"
print round(n)
```

In [6]:

```
from __future__ import division
import math
#Python CodeEx1.4 Calculate the lattice constant for a rock salt crystal
#(density=2180 kg per cubic meter)assuming that it has fcc lattice.
#Mol. wt of NaCl=58.5: Page-9 (2010)
# Variable declaration
M = 58.5; # Atomic weight of NaCl, gram per mole
d = 2180*10**03; # Density of rock salt, per metre cube
n = 4; #No. of atoms per unit cell for an fcc lattice of NaCl crystal
N = 6.023*10**23; # Avogadro's No.
#Calculations
# Volume of the unit cell is given by
# a**3 = M*n/(N*d)
# Solving for a
a = (n*M/(d*N))**(1/3); # Lattice constant of unit cell of NaCl
# Result
print "Lattice constant for the rock salt(NaCl) crystal,in angstrom,is"
print round(a/10**(-10),2)
```

In [7]:

```
from __future__ import division
import math
# Python Code Ex 1.5 Calculate the Density of diamond: Page-9 (2010)
# Variable declaration
a = 3.57*10**-10; # Lattice parameter of a diamond crystal
M = 12*10**-03; # Atomic weight of diamond, kg per mole
n1 = 8; # No. of corner atoms in the diamond cubic unit cell
n2 = 6; #No. of face centered atoms in the diamond cubic unit cell
n3 = 4; # No. of atoms completely within the unit cell
N = 6.023*10**+23; # Avogadro's No.
# Calculations
n = 1/8*n1+1/2*n2+1*n3;#No.of atoms per unit cell for an fcc lattice of NaCl
# Volume of the unit cell is given by
# a**3 = M*n/(N*d)
# Solving for d
d = M*n/(N*a**3); # Density of diamond cubic unit cell
# Result
print "Density of diamond cubic unit cell,in kg per metre cube, is:",round(d)
```

In [8]:

```
from __future__ import division
import math
#Python Code Ex1.6 Aluminium has an fcc structure.
#Its density is2.7x10^3 kg per metre cube.
# Calculating Unit cell dimensions and the atomic diameter: Page-9 (2010)
# Variable declaration
d = 2.7*10**+03;#Density of fcc structure of aluminium,kg per metre cube
M = 26.98*10**-03;# Atomic weight of aluminium, kg per mole
n = 4; # No. of atoms per unit cell of fcc lattice structure of aluminium
N = 6.023*10**+23; # Avogadro's No.
#Calculations
# Volume of the unit cell is given by
# a**3 = M*n/(N*d)
# Solving for a
a = ((M*n)/(N*d))**(1/3); # Lattice parameter of alumitnium unit cell
# For an fcc cryatal lattice,
# 2**(1/2) = 4R = 2D
# Solving for D
D = (a/2**(1/2)) # Diameter of aluminium atom
# Result
print"Lattice parameter of aluminium, in angstrom, is:",round(a/(1*10**-10),2)
print"Diameter of aluminium atom, in angstrom, is : ",round(D/(1*10**-10),2)
```

In [9]:

```
from __future__ import division
import math
#Python Code Ex1.17 Calculate the Angle between [111] and [001]
# crystal directions in a cubic crystal: Page-23 (2010)
#Variable declaration
h1 = 1;k1 = 1;l1 = 1; # Miller indices of first set of planes
h2 = 0;k2 = 0;l2 = 1; # Miller indices of second set of planes
# Calculations
# We know that
#cos(theta)=
#(h1*h2+k1*k2+l1*l2)/(sqrt(h1**2+k1**2+l1**2)*sqrt(h1**2+k1**2+l1**2))
# Solving for theta
a=(h1*h2+k1*k2+l1*l2)/((h1**2+k1**2+l1**2)**0.5*(h2**2+k2**2+l2**2)**0.5)
theta = math.acos(a);
#Result
print"\nThe angle between [",h1,k1,l1,"] and [",h2,k2,l2,"] directions"
print"in the cubic crystal,in degrees, is :",round(theta*180/math.pi,2)
```

In [10]:

```
from __future__ import division
import math
#Python Code Ex1.18 Angle between two directions of cubic crystal:Page-23(2010)
#Variable declaration
h1 = 1; k1 = 1; l1 = 1 # Miller indices for first set of planes
h2 = -1; k2 = -1; l2 = 1;#Miller indices for second set of planes
# Calculation
# We know that
#cos(theta)=
#(h1*h2+k1*k2+l1*l2)/(sqrt(h1**2+k1**2+l1**2)*sqrt(h2**2+k2**2+l2**2))
# Solving for theta
a=(h1*h2+k1*k2+l1*l2)/((h1**2+k1**2+l1**2)**0.5*(h2**2+k2**2+l2**2)**0.5)
theta=math.acos(a);
# Result
print"\nThe angle between [",h1,k1,l1,"] and [",h2,k2,l2,"] directions"
print" in the cubic crystal, in degrees, is :",round(theta*180/math.pi,2)
```

In [11]:

```
from __future__ import division
import math
#Python Code Ex1.19 Miller indices of the crystal plane: Page-25 (2010)
#Variable declaration
m = 2; n = 3; p = 6; #Coefficients of intercepts along three axes
#Calculation
m_inv = 1/m; # Reciprocate the first coefficient
n_inv = 1/n; # Reciprocate the second coefficient
p_inv = 1/p; # Reciprocate the third coefficient
mul_fact = (m*n*p)/6 # Find l.c.m. of m,n and p
m1 = m_inv*mul_fact; # Clear the first fraction
m2 = n_inv*mul_fact; # Clear the second fraction
m3 = p_inv*mul_fact; # Clear the third fraction
# Result
print"\nThe required miller indices are : ", m1,m2,m3
```

In [12]:

```
from __future__ import division
import math
# Python Code Ex 1.20 Indices of lattice plane: Page-25 (2010)
# Variable declaration
m = 10000; #Coefficient of intercept along x-axis,
n = 2; # Coefficient of intercept along y-axis
p = 1/2; # Coefficient of intercept along z-axis
# Calculations
m_inv = 1/m; # Reciprocate m
n_inv = 1/n; # Reciprocate n
p_inv = 1/p; # Reciprocate p
mul_fact = n; # multiplicative factor
m1 = m_inv*mul_fact; # Clear the first fraction
m2 = n_inv*mul_fact; # Clear the second fraction
m3 = p_inv*mul_fact; # Clear the third fraction
#Results
print"\nThe required miller indices are : ", round(m1),m2,m3
```

In [13]:

```
from __future__ import division
import math
# Python Code Ex 1.21 Length of the intercepts: Page-26 (2010)
# Variable declaration
a = 1.21*10**-10; # Lattice parameter of the unit cell, m
b = 1.84*10**-10; # Lattice parameter of the unit cell, m
c = 1.97*10**-10; # Lattice parameter of the unit cell, m
p = 1/2; # Reciprocal of miller index on x-axis
q = 1/3; # Reciprocal of miller index on y-axis
r = 1/(-1); # Reciprocal of miller index on z-axis
l1 = 1.21*10**-10; # Actual length of the intercept along x-axis, m
#Calculation
mul_fact = l1/(p*a); # Calculate multiplication factor
l2 = mul_fact*q*b; # Actual length of the interceptalong y-axis, m
l3 = mul_fact*r*c; # Actual length of the intercept along z-axis, m
# Result
print"Length of the intercept along y-axis,in angstrom,is",round(l2/10**-10,2)
print"Length of the intercept along z-axis, in angstrom, is : ",l3/10**-10
```

In [14]:

```
from __future__ import division
import math
# Python Code
'''
Ex 1.22 Determine the Miller indices of lattice plane that makes
intercepts of 2,3,4,(in angstroms) on the
coordinate axes of an orthorombic crystal with a:b:c=4:3:2 ,Page-26(2010)
'''
# Variable declaration
a = 4 # Lattice parameter of the unit cell
b = 3 # Lattice parameter of the unit cell
c = 2 # Lattice parameter of the unit cell
l1 = 2 # Length of the intercept along x-axis, m
l2 = 3 # Length of the intercept along y-axis, m
l3 = 4 # Length of the intercept along z-axis, m
# Calculation
l = l1/a # Intercept per unit translation along x-axis
m = l2/b # Intercept per unit translation along y-axis
n = l3/c # Intercept per unit translation along z-axis
r1 = 1/l # Reciprocal of l
r2 = 1/m # Reciprocal of m
r3 = 1/n # Reciprocal of n
m1 = 2*r1 # miller index along x-axis
m2 = 2*r2 # miller index along y-axis
m3 = 2*r3 # miller index along z-axis
# Result
print"The required miller indices of the plane are :", m1, m2, m3
```

In [15]:

```
from __future__ import division
import math
# Python Code Ex 1.23 Indices of tetragonal lattice: Page-26 (2010)
# For a tetragonal system we have a = b
# Variable declaration
a = 1; # Lattice parameter of the unit cell along x-axis
b = 1; # Lattice parameter of the unit cell along y-axis
c = 1.5; # Lattice parameter of the unit cell along z-axis
l1 = 3; # Length of the intercept along x-axis, angstrom
l2 = 4; # Length of the intercept along y-axis, angstrom
l3 = 3; # Length of the intercept along z-axis, angstrom
#Calculation
l = l1/a; # Intercept per unit translation along x-axis
m = l2/b; # Intercept per unit translation along y-axis
n = l3/c; # Intercept per unit translation along z-axis
r1 = 1/l; # Reciprocal of l
r2 = 1/m; # Reciprocal of m
r3 = 1/n; # Reciprocal of n
mul_fact = (l*m*n)/2
m1 = mul_fact*r1; # miller index along x-axis
m2 = mul_fact*r2; # miller index along y-axis
m3 = mul_fact*r3; # miller index along z-axis
#Result
print "The required miller indices of the plane are :", m1, m2, m3
```

In [16]:

```
from __future__ import division
import math
#Python Code Ex 1.24 Miller-Bravias indices for Miller indices:Page-29 (2010)
#Function declaration and calculations
def f(h,k):
i = -(h + k);
return i
# Variable declaration
h1 = 1; k1 = 1; l1 = 0 ; # First set of Miller indices
h2 = 1; k2 = -1; l2 = 0; # Second set of miller indices
h3 = 3; k3 = 4; l3 = 5; # Third set of miller indices
h4 = 3; k4 = -4; l4 = 5; # Fourth set of miller indices
#Result
print"\nThe Miller-Bravias indices corresponding to "
print" the miller indices(",h1, k1, l1,"), = (", h1, k1, f(h1,k1), l1,")"
print"\nThe Miller-Bravias indices corresponding to "
print "the miller indices(",h2, k2, l2,"),= (", h2, k2, f(h2,k2), l2,")"
print"\nThe Miller-Bravias indices corresponding to "
print"the miller indices (",h3, k3, l3,"),=(", h3, k3, f(h3,k3), l3,")"
print"\nThe Miller-Bravias indices corresponding to "
print" the miller indices(",h4, k4, l4,"),=(", h4, k4, f(h4,k4), l4,")"
```

In [17]:

```
from __future__ import division
import math
#Python Code Ex 1.25 Miller Bravias indices of lattice planes:Page-30 (2010)
# Function declaration and Calculations
def fh(H,K):
h = (2*H - K)/3;
return h
def fk(H,K):
k = (2*K - H)/3;
return k
def f(h,k):
i = -(h + k);
return i
def fl(L):
l = L;
return l
# Variable declaration
H1 = 1; K1 = 0; L1 = 0 ; # First set of Miller indices
H2 = 0; K2 = 1; L2 = 0; # Second set of miller indices
H3 = 1; K3 = 1; L3 = 0; # Third set of miller indices
h1 = fh(H1,K1)*3; # Call function fh
k1 = fk(H1,K1)*3; # Call function fk
l1 = fl(L1)*3; # Call function fl
i1 = f(h1,k1); # Call function
h2 = fh(H2,K2)*3; # Call function fh
k2 = fk(H2,K2)*3; # Call function fk
l2 = fl(L2)*3; # Call function l2
i2 = f(h2,k2); # Call function f
h3 = fh(H3,K3)*3; # Call function fh
k3 = fk(H3,K3)*3; # Call function fk
l3 = fl(L3)*3; # Call function l3
i3 = f(h3,k3); # Call function f
# Result
print"\nThe Miller Bravias indices of [",H1,K1,L1,"] are [",h1,k1,i1,l1,"]"
print"\nThe Miller Bravias indices of [",H2,K2,L2,"] are [",h2,k2,i2,l2,"]"
print"\nThe Miller Bravias indices of [",H3,K3,L3,"] are [",h3,k3,i3,l3,"]"
```

In [18]:

```
from __future__ import division
import math
# Python Code Ex 1.26 The distance between consecutive(111) planes
#in a cubic crystal is 2 angstrom.Determine the Lattice parameter.Page-33(2010)
# Variable declaration
h = 1; k = 1; l = 1;#Miller Indices for planes in a cubic crystal
d = 2*10**-10; # Interplanar spacing, m
#Calculations
# For cubic crystals, the interplanar spacing is given by
# d = a/(h**2+k**2+l**2)**1/2;
# Solving for a
a = (h**2+k**2+l**2)**(1/2)*d;#lattice parameter of cubic crystal, m
#Result
print "The lattice parameter of the cubic crystal,"
print" in angstrom, is :",round(a/10**(-10),2)
```

In [19]:

```
from __future__ import division
import math
# Python Code Ex 1.27 Interplanar spacing between consecutive (101) planes
#in tetragonal crystal: Page-33 (2010)
# Variable declaration
h = 1; # Miller Indices for planes in a cubic crystal
k = 0;
l = 1;
a = 2.42*10**-10;#Lattice parameters of a tetragonal crystal, each in m
b = 2.42*10**-10;
c = 1.74*10**-10;
#Calculations
# The interplanar spacing for cubic crystal, m
d = ((h**2+k**2)/a**2 + l**2/c**2)**(-1/2);
# Result
print "The interplanar spacing between consecutive (101) planes ,"
print "in angstrom, is :",round(d/(1*10**-10),2)
```

In [20]:

```
from __future__ import division
import math
# Python Code Ex 1.28 Interplanar spacing in cubic crystal: Page-36 (2010)
# Variable declaration
h = 3; k = 2; l = 1;# Miller Indices for planes in a cubic crystal
a = 4.21*10**-10; # Interatomic spacing, m
#Calculations
d = a/(h**2+k**2+l**2)**(1/2);#The interplanar spacing for cubic crystals, m
# Result
print "The interplanar spacing between consecutive (321) planes :"
print" in angstrom, is :",round(d/(1*10**-10),2)
```