{
 "metadata": {
  "name": "",
  "signature": "sha256:dc7951185c6d2c2020409b6a4f6420009478010f311e90b1a30732a0039ca5cf"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      " 2: Crystal Structures and X-ray Diffraction"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.1, Page number 2.16"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "r = 1;      #assume value of r as 1\n",
      "   \n",
      "#Calculation\n",
      "#since 4*r = math.sqrt(3)*a\n",
      "a = 4*r/math.sqrt(3);     \n",
      "R = (a-(2*r))/2;     #since 2*r+2*R = a\n",
      "R = math.ceil(R*10**3)/10**3;   #rounding off to 3 decimals\n",
      "\n",
      "#Result\n",
      "print \"radius of interstitial sphere is\",R,\"r\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "radius of interstitial sphere is 0.155 r\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.2, Page number 2.17"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "r_BCC = 1.258;     #atomic radius(Angstrom)\n",
      "r_FCC = 1.292;     #atomic radius(Angstrom)\n",
      "\n",
      "#Calculation\n",
      "a_BCC = (4*r_BCC)/math.sqrt(3);     #In BCC(Angstrom)\n",
      "a_BCCm = a_BCC*10**-10;      #converting a from Angstrom to m\n",
      "V_BCC = a_BCCm**3;     #volume of unit cell(m^3)\n",
      "n_BCC = ((1/8)*8)+1;      #number of atoms per unit cell\n",
      "V1_BCC = V_BCC/n_BCC;     #volume occupied by 1 atom(m^3)\n",
      "a_FCC = 2*math.sqrt(2)*r_FCC;     #In FCC(Angstrom)\n",
      "a_FCCm = a_FCC*10**-10;      #converting a from Angstrom to m\n",
      "V_FCC = a_FCCm**3;     #volume of unit cell(m^3)\n",
      "n_FCC = ((1/2)*6) + ((1/8)*8);      #number of atoms per unit cell\n",
      "V1_FCC = V_FCC/n_FCC;     #volume occupied by 1 atom(m^3)\n",
      "delta_V = (V1_BCC - V1_FCC)*100/V1_BCC;       #change in volume in %\n",
      "delta_V = math.ceil(delta_V*10)/10;   #rounding off to 1 decimal\n",
      "\n",
      "#Result\n",
      "print \"decrease of volume during conversion from BCC to FCC is\",delta_V,\"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "decrease of volume during conversion from BCC to FCC is 0.5 %\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.3, Page number 2.17"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "a = 0.27;      #nearest neighbour distance(nm)\n",
      "c = 0.494;     #height of unit cell(nm)\n",
      "N = 6.023*10**26;    #avagadro number(k/mol)\n",
      "M = 65.37;     #atomic weight(kg)\n",
      "\n",
      "#Calculation\n",
      "a_m = a*10**-9;    #nearest neighbour distance(m)\n",
      "c_m = c*10**-9;     #height of unit cell(m)\n",
      "V = 3*math.sqrt(3)*(a_m**2)*c_m/2;      #volume of unit cell(m^3)\n",
      "#if rho is density then mass = V*rho\n",
      "#V*rho = 6*M/N\n",
      "rho = (6*M)/(N*V);      #density(kg/m^3)\n",
      "\n",
      "#Result\n",
      "print \"Volume of the unit cell is\",round(V/1e-29,2),\"*10^-29 m^3\"\n",
      "print \"density of Zinc is\",round(rho),\"kg/m^3\"\n",
      "print \"answer for density given in the book differs due to rounding off errors\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Volume of the unit cell is 9.36 *10^-29 m^3\n",
        "density of Zinc is 6960.0 kg/m^3\n",
        "answer for density given in the book differs due to rounding off errors\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.4, Page number 2.18"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "r = 1;      #assume value of r as 1\n",
      "\n",
      "#Calculation\n",
      "a = 4*r/math.sqrt(2);      #for FCC structure\n",
      "R = (a/2)-r;     #since 2*r+2*R = a\n",
      "R = math.ceil(R*10**4)/10**4;   #rounding off to 4 decimals\n",
      "\n",
      "#Result\n",
      "print \"maximum radius of the sphere that can fit into the void is\",R,\"r\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "maximum radius of the sphere that can fit into the void is 0.4143 r\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.5, Page number 2.19"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "a = 0.356;      #cube edge of diamond(nm)\n",
      "aw = 12.01;      #atomic weight of carbon(kg)\n",
      "N = 6.023*10**26;     #avagadro's number\n",
      "\n",
      "#Calculation\n",
      "a_m = a*10**-9;      #cube edge of diamond(m)\n",
      "n = 8/(a_m**3);      #number of atoms(per m^3)\n",
      "n = n/10**29;\n",
      "n = math.ceil(n*10**3)/10**3;   #rounding off to 3 decimals\n",
      "n = n*10**29;\n",
      "M = aw/N;      #mass of 1 carbon atom(kg)\n",
      "rho =  M*n;\n",
      "\n",
      "#Result\n",
      "print \"number of atoms per m^3 is\",n\n",
      "print \"density of diamond is\",int(rho),\"kg/m^3\"\n",
      "print \"answer for density given in the book differs due to rounding off errors\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "number of atoms per m^3 is 1.774e+29\n",
        "density of diamond is 3537 kg/m^3\n",
        "answer for density given in the book differs due to rounding off errors\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.6, Page number 2.19"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "MW = 23+35.5;      #molecular weight of NaCl(gm)\n",
      "N = 6.023*10**23;     #avagadro number(mol-1)\n",
      "rho = 2.18;     #density of NaCl(gm/cm^3)\n",
      "V = 1;     #volume of unit cube(cm^3)\n",
      "\n",
      "#Calculation\n",
      "M = MW/N;       #mass of NaCl molecule(gm)\n",
      "n = rho/M;      #number of molecules per unit volume\n",
      "n = 2*n;        #since NaCl is diatomic(atoms/cm^3)\n",
      "#length of edge of unit cube is n*a\n",
      "#volume V = n^3*a^3 = 1 cm^3 \n",
      "a = (V/n)**(1/3);      #distance between two adjacent atoms(cm)\n",
      "a = a*10**8;       #distance between two adjacent atoms(A)\n",
      "a = math.ceil(a*10**3)/10**3;   #rounding off to 3 decimals\n",
      "\n",
      "#Result\n",
      "print \"distance between two adjacent atoms is\",a,\"Angstrom\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "distance between two adjacent atoms is 2.814 Angstrom\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.7, Page number 2.20"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "AW = 63.5;    #atomic weight of Cu(gm/mol)\n",
      "N = 6.023*10**23;     #avagadro's number(mol-1)\n",
      "r = 1.278;     #atomic radius(A)\n",
      "n = 4;     #number of atoms in unit cell\n",
      "\n",
      "#Calculation\n",
      "r = r*10**-8;      #atomic radius(cm)\n",
      "M = AW/N;      #mass of each Copper atom(gm)\n",
      "a = 4*r/math.sqrt(2);      #lattice constant(cm)\n",
      "m = n*M;    #mass of unit cell(gm)\n",
      "rho = m/a**3;     #density of copper crystal(gm/cm^3)\n",
      "rho = math.ceil(rho*10**3)/10**3;   #rounding off to 3 decimals\n",
      "\n",
      "#Result\n",
      "print \"density of Copper crystal is\",rho,\"gm/cm^3\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "density of Copper crystal is 8.929 gm/cm^3\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.8, Page number 2.21"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "r = 0.1249;     #atomic radius(nm)\n",
      "PF = 0.68;      #packing factor for BCC\n",
      "\n",
      "#Calculation\n",
      "a = 4*r/math.sqrt(3);      #lattice constant(nm)\n",
      "a_m = a*10**-9;        #lattice constant(m)\n",
      "V = a_m**3;       #volume of unit cell(m^3)\n",
      "FV = 1-PF;      #free volume\n",
      "FV1 = FV*V;      #free volume per unit cell(m^3)\n",
      "\n",
      "#Result\n",
      "print \"free volume per unit cell is\",round(FV1/1e-30,4),\"*10^-30 m^3\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "free volume per unit cell is 7.6795 *10^-30 m^3\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.11, Page number 2.27"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "#in (100) plane the total number of atoms are n\n",
      "n = (1/4)*4;\n",
      "\n",
      "#Calculation\n",
      "#in (111) plane, area = (1/2)*base*height = (1/2)*a*sqrt(2)*a*sqrt(2)*cosd(30)\n",
      "x = math.cos(30);\n",
      "#area = (1/2)*a*sqrt(2)*a*sqrt(2)*x = 0.866*a^2 = 0.58/a^2\n",
      "n1 = (1/360)*60*3;\n",
      "\n",
      "#Result\n",
      "print \"number of atoms in (100) plane are\",n;\n",
      "#A = a^2. number of atoms per mm^2 is n/a^2\n",
      "print \"number of atoms per mm^2 is 1/a^2\";\n",
      "print \"number of atoms in (110) plane is 1\";\n",
      "#in (110) plane, area is sqrt(2)*a*a = sqrt(2)*a^2\n",
      "print \"unit area contains 1/(sqrt(2)*a^2) = 0.707/a^2 atoms/mm^2\";\n",
      "print \"total number of atoms in (111) plane is\",n1\n",
      "#number of atoms per unit area is 0.5/(0.866*a^2)\n",
      "print \"number of atoms per unit area is 0.58/a^2 atoms/mm^2\";"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "number of atoms in (100) plane are 1.0\n",
        "number of atoms per mm^2 is 1/a^2\n",
        "number of atoms in (110) plane is 1\n",
        "unit area contains 1/(sqrt(2)*a^2) = 0.707/a^2 atoms/mm^2\n",
        "total number of atoms in (111) plane is 0.5\n",
        "number of atoms per unit area is 0.58/a^2 atoms/mm^2\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.12, Page number 2.28"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "h1 = 1;\n",
      "k1 = 1;\n",
      "l1 = 0;     #for (110) plane\n",
      "h2 = 2;\n",
      "k2 = 1;\n",
      "l2 = 2;     #for (212) plane\n",
      "r = 0.1278;      #atomic radius(nm)\n",
      "\n",
      "#Calculation\n",
      "r = r*10**-9;     #atomic radius(m) \n",
      "x1 = math.sqrt(h1**2+k1**2+l1**2);\n",
      "a = 4*r/x1;     #nearest neighbouring distance(m)\n",
      "a = a*10**9;     #nearest neighbouring distance(nm)\n",
      "d_110 = a/x1;    #interplanar spacing for (110),(nm)\n",
      "x2 = math.sqrt(h2**2+k2**2+l2**2);\n",
      "d_212 = a/x2;    #interplanar spacing for (212),(nm)\n",
      "d_212 = math.ceil(d_212*10**4)/10**4;   #rounding off to 4 decimals\n",
      "\n",
      "#Result\n",
      "print \"interplanar spacing for (110) is\",d_110,\"nm\"\n",
      "print \"interplanar spacing for (212) is\",d_212,\"nm\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "interplanar spacing for (110) is 0.2556 nm\n",
        "interplanar spacing for (212) is 0.1205 nm\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.13, Page number 2.29"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "h1 = 1;\n",
      "k1 = 0;\n",
      "l1 = 0;    #for (100) plane\n",
      "h2 = 1;\n",
      "k2 = 1;\n",
      "l2 = 0;    #for (110) plane \n",
      "h3 = 1;\n",
      "k3 = 1;\n",
      "l3 = 1;    #for (111) plane\n",
      "\n",
      "#Calculation\n",
      "x1 = math.sqrt(1/(h1**2+k1**2+l1**2));      #for (100) plane\n",
      "x2 = math.sqrt(1/(h2**2+k2**2+l2**2));      #for (110) plane \n",
      "x3 = math.sqrt(1/(h3**2+k3**2+l3**2));      #for (111) plane\n",
      "x2 = math.ceil(x2*10**2)/10**2;   #rounding off to 2 decimals\n",
      "x3 = math.ceil(x3*10**2)/10**2;   #rounding off to 2 decimals\n",
      "\n",
      "#Result\n",
      "print \"ratio of the seperation between successive lattice planes is %d:%.2f:%.2f\"%(x1,x2,x3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "ratio of the seperation between successive lattice planes is 1:0.71:0.58\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.14, Page number 2.30"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Calculation\n",
      "#plane intercepts at a,b/2,3*c\n",
      "#therefore intercepts are (1 1/2 3)\n",
      "x = 1;\n",
      "y = 1/2;\n",
      "z = 3;\n",
      "def lcm(x, y):\n",
      "   if y > z:\n",
      "       greater = y\n",
      "   else:\n",
      "       greater = z\n",
      "\n",
      "   while(True):\n",
      "       if((greater % y == 0) and (greater % z == 0)):\n",
      "           lcm = greater\n",
      "           break\n",
      "       greater += 1\n",
      "\n",
      "   return lcm\n",
      "\n",
      "lcm = lcm(y,z);                \n",
      "x_dash = (1/x)*lcm;      #miller index of x plane\n",
      "y_dash = (1/y)*lcm;      #miller index of y plane  \n",
      "z_dash = (1/z)*lcm;      #miller index of z plane\n",
      "\n",
      "#Result\n",
      "print \"miller indices of the plane are (\",x_dash,y_dash,z_dash,\")\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "miller indices of the plane are ( 3.0 6.0 1.0 )\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.15, Page number 2.37"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "d = 0.282;     #lattice spacing(nm)\n",
      "n = 1;     #first order\n",
      "theta = (8+(35/60))*(math.pi/180);      #glancing angle(radian)\n",
      "theeta = 90;     #maximum value possible(degrees)\n",
      "\n",
      "#Calculation\n",
      "theeta = theeta*math.pi/180;       #maximum value possible(radian)   \n",
      "d = d*10**-9;      #lattice spacing(m)\n",
      "lamda = 2*d*math.sin(theta)/n;     #wavelength of X-rays(m)\n",
      "lamda_nm = lamda*10**9;     #wavelength of X-rays(nm)\n",
      "lamda_nm = math.ceil(lamda_nm*10**4)/10**4;   #rounding off to 4 decimals\n",
      "n1 = 2*d*math.sin(theeta)/lamda;       #maximum order of diffraction possible\n",
      "\n",
      "#Result\n",
      "print \"wavelength of X-rays is\",lamda_nm,\"nm\"\n",
      "print \"maximum order of diffraction possible is\",int(n1)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "wavelength of X-rays is 0.0842 nm\n",
        "maximum order of diffraction possible is 6\n"
       ]
      }
     ],
     "prompt_number": 35
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.16, Page number 2.37"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "lamda = 1.5;      #wavelength(A.U)\n",
      "d = 1.6;      #interplanar spacing(A.U)\n",
      "theta = 90;     #maximum glancing angle possible(degrees)\n",
      "\n",
      "#Calculation\n",
      "theta = theta*math.pi/180;       #maximum glancing angle possible(radian)\n",
      "n = 2*d*math.sin(theta)/lamda;      #maximum possible diffraction order\n",
      "\n",
      "#Result\n",
      "print \"maximum possible diffraction order is\",int(n)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "maximum possible diffraction order is 2\n"
       ]
      }
     ],
     "prompt_number": 38
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.17, Page number 2.38"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "h = 1;\n",
      "k = 1;\n",
      "l = 1;      #for (111) plane\n",
      "theta = 30;    #glancing angle(degrees)\n",
      "n = 1;     #first order\n",
      "lamda = 1.5418;     #wavelength of X-rays(A)\n",
      "\n",
      "#Calculation\n",
      "theta = theta*math.pi/180;      #glancing angle(radian)\n",
      "x = math.sqrt(h**2+k**2+l**2);\n",
      "lamda = lamda*10**-10;     #wavelength of X-rays(m)\n",
      "d = lamda/(2*math.sin(theta));\n",
      "a = d*x;      #interatomic spacing(m)\n",
      "a = a*10**10;      #interatomic spacing(A)\n",
      "a = math.ceil(a*10**4)/10**4;   #rounding off to 4 decimals\n",
      "\n",
      "#Result\n",
      "print \"the interatomic spacing is\",a,\"Angstrom\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the interatomic spacing is 2.6705 Angstrom\n"
       ]
      }
     ],
     "prompt_number": 42
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.18, Page number 2.38"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "d100 = 0.28;     #lattice constant(nm)\n",
      "h = 1;\n",
      "k = 1;\n",
      "l = 0;      #for (110) plane\n",
      "n = 2;      #second order\n",
      "lamda = 0.071;     #wavelength of X-rays(nm)\n",
      "\n",
      "#Calculation\n",
      "lamda_m = lamda*10**-9;     #wavelength of X-rays(m)\n",
      "d110 = d100/math.sqrt(h**2+k**2+l**2);     #interatomic spacing(nm)\n",
      "d110 = d110*10**-9;      #interatomic spacing(m)\n",
      "theta = math.asin(n*lamda_m/(2*d110));       #glancing angle(radian)\n",
      "theta = theta*180/math.pi;        #glancing angle(degrees)\n",
      "\n",
      "#Result\n",
      "print \"the glancing angle is\",int(theta),\"degrees\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the glancing angle is 21 degrees\n"
       ]
      }
     ],
     "prompt_number": 46
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.19, Page number 2.39"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "a = 0.38;      #lattice constant(nm)\n",
      "h = 1;\n",
      "k = 1;\n",
      "l = 0;      #for (110) plane\n",
      "\n",
      "#Calculation\n",
      "d = a/math.sqrt(h**2+k**2+l**2);\n",
      "d = math.ceil(d*10**2)/10**2;   #rounding off to 2 decimals\n",
      "\n",
      "#Result\n",
      "print \"the distance between (110) planes is\",d,\"nm\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the distance between (110) planes is 0.27 nm\n"
       ]
      }
     ],
     "prompt_number": 48
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.20, Page number 2.39"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "#area of (110) plane is a*sqrt(2)*a = sqrt(2)*a^2\n",
      "theta = 30;      #glancing angle(degrees)\n",
      "\n",
      "#Calculation\n",
      "theta = theta*math.pi/180;      #glancing angle(radian)\n",
      "n = (1/4)*4;     #number of atoms\n",
      "x = math.cos(theta);\n",
      "#area of (111) plane is (a/sqrt(2))*x*a*sqrt(2)\n",
      "#hence area is (sqrt(3)/2)*a^2\n",
      "n1 = 3*(1/6);     #number of atoms\n",
      "\n",
      "#Result\n",
      "print \"area of (110) plane contains\",n,\"atom\"\n",
      "print \"density of lattice points is 1/(sqrt(2)*a^2)\"\n",
      "print \"area of (111) plane contains\",n1,\"atom\"\n",
      "#density of lattice points is (1/2)/(sqrt(3)*a^2/2)\n",
      "print \"density of lattice points is 1/(sqrt(3)*a^2)\"\n",
      "#density of lattice points (111) plane : (110) plane is 1/(sqrt(3)*a^2) : 1/(sqrt(2)*a^2) = sqrt(2):sqrt(3)\n",
      "print \"density of lattice points (111) plane : (110) plane is sqrt(2):sqrt(3)\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "area of (110) plane contains 1.0 atom\n",
        "density of lattice points is 1/(sqrt(2)*a^2)\n",
        "area of (111) plane contains 0.5 atom\n",
        "density of lattice points is 1/(sqrt(3)*a^2)\n",
        "density of lattice points (111) plane : (110) plane is sqrt(2):sqrt(3)\n"
       ]
      }
     ],
     "prompt_number": 49
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.21, Page number 2.40"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "n = 2;     #second order\n",
      "h = 1;\n",
      "k = 1;\n",
      "l = 0;   #plane (110)\n",
      "lamda = 0.065;     #wavelength of X-rays(nm)\n",
      "a = 0.26;      #axial length(nm)\n",
      "\n",
      "#Calculation\n",
      "lamda_m = lamda*10**-9;    #wavelength of X-rays(m)\n",
      "a_m = a*10**-9;    #axial length(m)\n",
      "x = math.sqrt(h**2+k**2+l**2);\n",
      "theta = math.asin(n*lamda_m*x/(2*a_m));       #glancing angle(radian)\n",
      "theta = theta*180/math.pi;          #glancing angle(degrees)\n",
      "deg = int(theta);       #glancing angle(degrees)\n",
      "t = 60*(theta-deg);\n",
      "mint = int(t);         #glancing angle(minutes)\n",
      "\n",
      "#Result\n",
      "print \"the glancing angle is\",deg,\"degrees\",mint,\"minutes\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the glancing angle is 20 degrees 42 minutes\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.22, Page number 2.41"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "n = 1;    #first order\n",
      "h = 1;\n",
      "k = 1;\n",
      "l = 1;     #for (111) plane\n",
      "lamda = 1.54;      #wavelength(A.U)\n",
      "theta = 19.2;      #Bragg's angle(degrees)\n",
      "\n",
      "#Calculation\n",
      "lamda_m = lamda*10**-10;      #wavelength(m)\n",
      "theta = theta*math.pi/180;        #Bragg's angle(radian)\n",
      "d = n*lamda_m/(2*math.sin(theta));     #interplanar spacing(m)\n",
      "a = d*math.sqrt(h**2+k**2+l**2);      #cube edge(m)\n",
      "a_AU = a*10**10;      #cube edge(A.U)\n",
      "a_AU = math.ceil(a_AU*10**4)/10**4;   #rounding off to 4 decimals\n",
      "\n",
      "#Result\n",
      "print \"the cube edge is\",a_AU,\"A.U\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the cube edge is 4.0554 A.U\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 2.23, Page number 2.41"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "n = 1;    #first order\n",
      "h = 1;\n",
      "k = 1;\n",
      "l = 1;     #for (111) plane\n",
      "lamda = 1.54;    #wavelength(A.U)\n",
      "theta = 19.2;      #Bragg's angle(degrees)\n",
      "\n",
      "#Calculation\n",
      "lamda_m = lamda*10**-10;      #wavelength(m)\n",
      "theta = theta*math.pi/180;        #Bragg's angle(radian)\n",
      "d = n*lamda_m/(2*math.sin(theta));     #interplanar spacing(m)\n",
      "a = d*math.sqrt(h**2+k**2+l**2);       #cube edge(m)\n",
      "\n",
      "#Result\n",
      "print \"the cube edge is\",round(a/1e-10,3),\"*10^-10 m\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the cube edge is 4.055 *10^-10 m\n"
       ]
      }
     ],
     "prompt_number": 9
    }
   ],
   "metadata": {}
  }
 ]
}