{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 3 : Crystal Geometry Structure and Defects"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.10 Page No : 91"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "angle Between normals to the planes (111) and (121)(in degrees) = 19.47\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "from numpy import degrees, arccos\n",
    "\n",
    "# Variables\n",
    "#Miller indices of plane\n",
    "h_1 = 1.;\n",
    "k_1 = 1.;\n",
    "l_1 = 1.;\n",
    "h_2 = 1.;\n",
    "k_2 = 2.;\n",
    "l_2 = 1.;\n",
    "\n",
    "# Calculation\n",
    "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)))))\n",
    "\n",
    "# Results\n",
    "print 'angle Between normals to the planes (111) and (121)(in degrees) = %.2f'%angle\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.11 Page No : 91"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Packing efficiency of sodium chloride in = 66.3 %\n",
      "density of sodium chloride in = 2233 Kg/m3\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "r_Na = 0.98;\t\t\t#Radius of Na+(in A)\n",
    "r_Cl = 1.81;\t\t\t#Radius of Cl-(in A)\n",
    "a = 2*(r_Na+r_Cl);\t\t\t#Lattice parameter (in A)\n",
    "\n",
    "# Calculation\n",
    "pi = 22./7;\n",
    "V_i = 4*(4./3)*pi*((r_Na**3)+(r_Cl**3));\t\t\t#Volume of ions present in unit cell\n",
    "V_u = a**3;\t\t\t#Volume of unit cell\n",
    "Apf = V_i/V_u;\t\t\t#Atomic packing fraction\n",
    "Ef_p = (Apf)*100;\t\t\t#Packing efficiency(in %)\n",
    "AM_sodium = 22.99;\t\t\t#Atomic mass of sodium(in amu)\n",
    "AM_chlorine = 35.45;\t\t\t#Atomic mass of chlorine(in amu)\n",
    "M_1 = 4*(AM_sodium+AM_chlorine)*1.66*10**(-27);\t\t\t#Mass of the unit cell\n",
    "a_1 = a*10**(-10);\t\t\t#Lattice parameter (in meter)\n",
    "V_u1 = (a_1)**3;\n",
    "Density = M_1/V_u1;\n",
    "\n",
    "# Results\n",
    "print 'Packing efficiency of sodium chloride in = %.1f %%'%Ef_p\n",
    "print 'density of sodium chloride in = %.0f Kg/m3'%Density\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.12 Page No : 91"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "radius in = 4.049 A\n",
      "Diameter in 2.86 A\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "Density = 2.7;\t\t\t#(in g/cm**3)\n",
    "n = 4;\n",
    "m = 26.98;\t\t\t#atomic weight of Al\n",
    "\n",
    "# Calculation and Results\n",
    "N_a = 6.023*10**(23);\t\t\t            #avogadro number\n",
    "a = ((n*m/(Density*N_a))**(1./3));\t\t\t#Lattice parameter(in Cm)\n",
    "A = a*10**(8);\t\t\t                    #Lattice parameter(in A)\n",
    "print 'radius in = %.3f A'%A\n",
    "r = A/(2*1.414);\t\t\t#radius for fcp structure\n",
    "print 'Diameter in %.2f A'%(2*r)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.13 Page No : 92"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "interplaner distance of (200) plane of nickel crystal in = 1.76 A\n",
      "interplaner distance of (111) plane of nickel crystal in = 2.03 A\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "r = 1.245;\t\t\t#radius of nickel (in A)\n",
    "a = 4*r/(2)**(1./2);\t\t\t#Lattice consmath.tant(in A)\n",
    "#Miller indices of plane 200\n",
    "h_1 = 2;\n",
    "k_1 = 0;\n",
    "l_1 = 0;\n",
    "#Miller indices of plane 111\n",
    "h_2 = 1;\n",
    "k_2 = 1;\n",
    "l_2 = 1;\n",
    "\n",
    "# Calculation\n",
    "d_200 = a/((h_1**2)+(k_1**2)+(l_1**2))**(1./2);\n",
    "d_111 = a/((h_2**2)+(k_2**2)+(l_2**2))**(1./2);\n",
    "\n",
    "# Results\n",
    "print 'interplaner distance of (200) plane of nickel crystal in = %.2f A'%d_200\n",
    "print 'interplaner distance of (111) plane of nickel crystal in = %.2f A'%d_111\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.14 Page No : 92"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of atoms in the (100) plane of a simple cubic structure(in per mm**2) = 1.09e+13\n",
      "Number of atoms in the (110) plane of a simple cubic structure(in per mm**2) = 7.7e+12\n",
      "Number of atoms in the (111) plane of a simple cubic structure(in per mm**2) = 6.3e+12\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "a = 3.03*10**(-7);\t\t\t#lattice consmath.tant(in mm)\n",
    "\n",
    "# Calculation\n",
    "N_100 = 1/(a**2);\t\t\t#Number of atoms in the (100) plane of a simple cubic structure\n",
    "N_110 = 0.707/(a**2);\t\t\t#Number of atoms in the (110) plane of a simple cubic structure\n",
    "N_111 = 0.58/(a**2);\t\t\t#Number of atoms in the (111) plane of a simple cubic structure\n",
    "\n",
    "# Results\n",
    "print 'Number of atoms in the (100) plane of a simple cubic structure(in per mm**2) = %.2e'%N_100\n",
    "print 'Number of atoms in the (110) plane of a simple cubic structure(in per mm**2) = %.1e'%N_110\n",
    "print 'Number of atoms in the (111) plane of a simple cubic structure(in per mm**2) = %.1e'%N_111\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.15 Page No : 92"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the planer density of Ni (in atoms per mm**2) = 1.6e+13\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "r = 1.245*10**(-7);\t\t\t#Radius of the Ni atom(in mm)\n",
    "\n",
    "# Calculation\n",
    "NA_100 = 1+(1./4)*4;\t\t\t#Numbers of atom in (100) plane\n",
    "a = 4*r/(2)**(1./2);\t\t\t#Lattice consmath.tant(in mm)\n",
    "Area = a**2;\n",
    "P_density = NA_100/Area;\n",
    "\n",
    "# Results\n",
    "print 'the planer density of Ni (in atoms per mm**2) = %.1e'%P_density\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.16 Page No : 93"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Planar density of plane 100(in atoms/mm**2) = 8.2e+12\n",
      "Planar density of plane 110(in atoms/mm**2) = 5.8e+12\n",
      "Planar density of plane 111(in atoms/mm**2) = 9.4e+12\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "N_a1 = 4*(1./4)+1;\t\t\t#Number of atoms contained in (100) plane\n",
    "r = 1.75*10**(-7);\t\t\t#radius of lead atom (in mm)\n",
    "a_1 = 2*2**(1./2)*r;\t\t\t#edge of unit  cell in case of (100) plane\n",
    "PD_100 = N_a1/(a_1**2);\t\t\t#Planar density of plane (100)\n",
    "\n",
    "# Calculation\n",
    "N_a2 = 4*(1./4)+2*(1./2);\t\t\t#Number of atoms contained in (110) plane\n",
    "a_21 = 4*r;\t\t\t#top edge of the plane (110)\n",
    "a_22 = 2*2**(1./2)*r;\t\t\t#vertical edge of the plane (110)\n",
    "PD_110 = N_a2/(a_21*a_22);\t\t\t#Planar density of plane (110)\n",
    "N_a3 = 3*(1./6)+3./2;\t\t\t#Number of atom contained in (111) plane\n",
    "Ar_111 = 4*(3**(1./2))*r**2;\t\t\t#area of (111) plane\n",
    "PD_111 = N_a3/Ar_111;\t\t\t#Planar density of plane (111)\n",
    "\n",
    "# Results\n",
    "print 'Planar density of plane 100(in atoms/mm**2) = %.1e'%PD_100\n",
    "print 'Planar density of plane 110(in atoms/mm**2) = %.1e'%PD_110\n",
    "print 'Planar density of plane 111(in atoms/mm**2) = %.1e'%PD_111\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.17 Page No : 94"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "linear atomic density along (110) of copper crystal lattice in = 3.92e+06 atoms/mm\n",
      "linear atomic density along (111) of copper crystal lattice in = 1.60e+06 atoms/mm\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "N_a1 = (1./2)+1+(1./2);\t\t\t#Number of diameters of atom along (110) direction\n",
    "a = 3.61*10**(-7);\t\t\t#lattice consmath.tant of copper in mm\n",
    "\n",
    "# Calculation\n",
    "L_d1 = 2**(1./2)*a;\t\t\t#length of the face diagonal in case of (110) direction\n",
    "p_110 = N_a1/L_d1;\t\t\t#linear atomic density along (110) of copper crystal lattice(in atoms/mm)\n",
    "N_a2 = (1./2)+(1./2);\t\t\t#Number of diameters of atom along (111) direction\n",
    "L_d2 = 3**(1./2)*a;\t\t\t#length of the face diagonal in case of (111) direction\n",
    "p_111 = N_a2/L_d2;\t\t\t#linear atomic density along (110) of copper crystal lattice(in atoms/mm)\n",
    "\n",
    "# Results\n",
    "print 'linear atomic density along (110) of copper crystal lattice in = %.2e atoms/mm'%p_110\n",
    "print 'linear atomic density along (111) of copper crystal lattice in = %.2e atoms/mm'%p_111\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.18 Page No : 95"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Value of lattice constant in = 2.867 A\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "A = 55.8;\t\t\t#atomic weight of Fe\n",
    "n = 2;\t\t\t#number of atoms per unit cell\n",
    "\n",
    "# Calculation\n",
    "N = 6.02*10**(26);\t\t\t#Avogadro's number\n",
    "p = 7.87*10**3;\t\t\t#density of Fe(in kg/m**3)\n",
    "a = ((A*n/(N*p))**(1./3))*10**10;\t\t\t#Value of lattice consmath.tant\n",
    "\n",
    "# Results\n",
    "print 'Value of lattice constant in = %.3f A'%a\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.19 Page No : 95"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Numbers of atoms per unit cell =  2.0\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "\n",
    "# Variables\n",
    "a = 2.9*10**(-10);\t\t\t#lattice parameter(in m)\n",
    "A = 55.8;\t\t\t#atomic weight of Fe\n",
    "\n",
    "# Calculation\n",
    "N = 6.02*10**(26);\t\t\t#Avogadro's number\n",
    "p = 7.87*10**3;\t\t\t#density of Fe(in kg/m**3\n",
    "n = (a**3)*N*p/A;\t\t\t#Numbers of atoms per unit cell\n",
    "\n",
    "# Results\n",
    "print 'Numbers of atoms per unit cell = ',floor(n)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.20 Page No : 109"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "line energy of disslocation in = 2.47e-09 J/m\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "a = 2.87*10**(-10);\t\t\t#lattice parameter for bcc iron\n",
    "b = a*(3**(1./2))/2;\t\t\t#Magnitude of burgers vector\n",
    "\n",
    "# Calculation\n",
    "u = 80*10**9;\t\t\t#shear modulus\n",
    "E = (1./2)*u*b**2;\t\t\t#line energy of disslocation\n",
    "\n",
    "# Results\n",
    "print 'line energy of disslocation in = %.2e J/m'%E\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.22 Page No : 109"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of vacancies created during heating in = 6.54e+23 m**-3\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "N = 6.023*10**23;\t\t\t#avogadro number\n",
    "T = 1000.;\t\t\t#absolute temperature\n",
    "R = 8.314;\t\t\t#consmath.tant\n",
    "\n",
    "# Calculation\n",
    "H_f = 100*1000;\t\t\t#enthalpy of formation of vacancies(in J/mol)\n",
    "n = N*math.exp(-(H_f)/(R*T));\t\t\t#number of vacancies created during heating(in per mol)\n",
    "V = 5.5*10**(-6);\t\t\t#volume of 1 mole of the crystal in m**3\n",
    "n_1 = n/V;\t\t\t#number of vacancies created during heating(in per m**3)\n",
    "\n",
    "# Results\n",
    "print 'number of vacancies created during heating in = %.2e m**-3'%n_1\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.23 Page No : 109"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Surface energy (enthalpy) of copper in = 2.49 J/m**2\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "#bond energy per atom of copper = bond energy per bond*numbers of bond per atom*(1/2)\n",
    "A = 56.4*1000;\t\t\t#\n",
    "N = 6.023*10**23;\t\t\t#avogadro number\n",
    "n_1 = 12.;\t\t\t#numbers of bond per atom\n",
    "n_2 = 3.;\t\t\t#bonds broken at the surface\n",
    "\n",
    "# Calculation and Results\n",
    "E = A*n_1/(2*N);\t\t\t#Energy of total bonds\n",
    "E_b = E*(n_2/n_1);\t\t\t#Energy of broken bonds on surface\n",
    "n_a = 1.77*10**19;\t\t\t#no. of atoms on {111} planes in copper(in m**-2)\n",
    "E_c = n_a*E_b;\t\t\t#Surface energy (enthalpy) of copper\n",
    "print 'Surface energy (enthalpy) of copper in = %.2f J/m**2'%E_c\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.24 Page No : 110"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "equilibrium concentration of vacancies in aluminium at 300 K = 1.44e-12\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "H_f = 68.*1000;\t\t\t#enthalpy of formation of vacancies(in J/mol)\n",
    "T_1 = 0;\t\t\t#temp (in K)\n",
    "T_2 = 300.;\t\t\t#temp (in K)\n",
    "R = 8.314;\t\t\t#consmath.tant\n",
    "\n",
    "# Calculation\n",
    "\n",
    "n = math.exp(-H_f/(R*T_2));\t\t\t#equilibrium concentration of vacancies in aluminium at 300 K\n",
    "\n",
    "# Results\n",
    "print 'equilibrium concentration of vacancies in aluminium at 300 K = %.2e'%n\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.25 Page No : 113"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the interplanar spacing between atomic plane in = 2.22 A\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "Wavelength = 1.54*10**(-10);\t\t\t#in meter\n",
    "Angle = 20.3;\t\t\t#in degree\n",
    "n = 1;\t\t\t#First order\n",
    "\n",
    "# Calculation\n",
    "d = Wavelength*n/(2*math.sin(math.radians(Angle)));\t\t\t#the interplanar spacing(in Meter)\n",
    "\n",
    "# Results\n",
    "print 'the interplanar spacing between atomic plane in = %.2f A'%(d/(10**-10))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.26 Page No : 113"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Size of unit cell in 3.51 Angstrom\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "wavelength = 0.58;\t\t\t#in Angstrom\n",
    "angle = 9.5;\t\t\t#in degree\n",
    "n = 1;\t\t\t#First order\n",
    "\n",
    "# Calculation\n",
    "#d_200 = wavelength*n/(2*math.sin(math.radians(angle)));\t\t\t#interplanar spacing(in Angstrom)\n",
    "d_200 = n/math.sqrt(2**2+0**2+0**2)\n",
    "#Miller indices of plane\n",
    "h = 2;\n",
    "k = 0;\n",
    "l = 0;\n",
    "a = 0.58/(math.sin(math.radians(angle))*2*d_200);\t\t\t#Size of unit cell(in Angstrom)\n",
    "# Results\n",
    "print 'Size of unit cell in %.2f Angstrom'%a\n",
    "\n",
    "# book answer is wrong."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.27 Page No : 114"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bragg angle(in degree) = 7.527\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "#Miller indices of plane\n",
    "h = 1.;\n",
    "k = 1.;\n",
    "l = 1.;\n",
    "wavelength = 0.54;\t\t\t#in angstrom\n",
    "a = 3.57;\t\t\t#size of a cube\n",
    "n = 1;\n",
    "\n",
    "# Calculation\n",
    "d_111 = a/(h**2+k**2+l**2)**(1./2);\t\t\t#interplanar spacing(in Angstrom)\n",
    "sinangle = (n*wavelength)/(2*d_111)\n",
    "angle = math.degrees(math.asin(sinangle))\n",
    "\n",
    "# Results\n",
    "print 'Bragg angle(in degree) = %.3f'%angle\n",
    "\n",
    "# rounding off error"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.28 Page No : 114"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bragg reflection index for BCC crystal = 1.53\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "d = 1.181;\t\t\t  #A\n",
    "wavelength = 1.540;\t  #in angstrom\n",
    "angle = 90;\t\t\t  #in degrees\n",
    "\n",
    "# Calculation\n",
    "n = 2*d*math.sin(math.radians(angle))/(wavelength);\t\t\t#the bragg reflection index\n",
    "\n",
    "# Results\n",
    "print 'Bragg reflection index for BCC crystal = %.2f'%n\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.29 Page No : 114"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3rd order reflection angle = 31.40\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "n_1 = 1;\t\t\t#1st order reflection index\n",
    "angle_1 = 10;\t\t\t#1st order reflection angle\n",
    "n_3 = 3;\t\t\t#3rd order reflection index\n",
    "\n",
    "# Calculation\n",
    "#math.math.sin(math.radians(angle_1)/math.math.sin(math.radians(angle_3) = n_1/n_3\n",
    "sinangle_3 = n_3 * math.sin(math.radians(angle_1)/n_1);\t\t\t#\n",
    "angle_3 = math.degrees(math.asin(sinangle_3))\n",
    "\n",
    "# Results\n",
    "print '3rd order reflection angle = %.2f'%angle_3\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.30 Page No : 115"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "interplanar spacing of reflection plane 2.22 A\n",
      "miller indices of the reflection plane 2.0\n",
      "((110),(101),(011))\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "angle = 20.3;\t\t\t#in degree\n",
    "wavelength = 1.54;\t\t\t#in angstrom\n",
    "n = 1;\n",
    "a = 3.16;\t\t\t#lattice parameter in angstrom\n",
    "\n",
    "# Calculation\n",
    "d = n*wavelength/(2*math.sin(math.radians(angle)));\t\t\t#interplanar spacing\n",
    "M_indices = a**2/(d**2);\n",
    "\n",
    "# Results\n",
    "print 'interplanar spacing of reflection plane %.2f A'%d\n",
    "print 'miller indices of the reflection plane',floor(M_indices)\n",
    "print \"((110),(101),(011))\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.31 Page No : 115"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "interatomic spacing(in angstrom) = 3.46\n"
     ]
    }
   ],
   "source": [
    "\t\t\t\n",
    "\n",
    "import math \n",
    "\n",
    "# Variables\n",
    "#Miller indices of plane\n",
    "n = 1;\n",
    "h = 1;\n",
    "k = 1;\n",
    "l = 1;\n",
    "angle = 30;\t\t\t#in degree\n",
    "wavelength = 2;\t\t\t#in angstrom\n",
    "\n",
    "# Calculation\n",
    "d = n*wavelength/(2*math.sin(math.radians(angle)));\t\t\t#interplanar spacing\n",
    "a = d*(h**2+k**2+l**2)**(1./2);\t\t\t#interatomic spacing\n",
    "\n",
    "# Results\n",
    "print 'interatomic spacing(in angstrom) = %.2f'%a\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
