{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#4: Dislocations and Crystal Structure Determination"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 4.1, Page number 66"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wavelength is 0.842 angstrom\n",
      "answer varies due to rounding off errors\n",
      "maximum order of diffraction is 7.0\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "d=0.282*10**-9;    #lattice spacing(m)\n",
    "theta=8+(35/60);   #glancing angle(degree)\n",
    "n=1;   #order\n",
    "Theta=90;    #angle(degree)\n",
    "\n",
    "#Calculation\n",
    "theta=theta*math.pi/180;    #angle(radian)\n",
    "Theta=Theta*math.pi/180;    #angle(radian)\n",
    "lamda=2*d*math.sin(theta)/n;    #wavelength(m)\n",
    "nmax=2*d*math.sin(Theta)/lamda;    #maximum order of diffraction\n",
    "\n",
    "#Result\n",
    "print \"wavelength is\",round(lamda*10**10,3),\"angstrom\"\n",
    "print \"answer varies due to rounding off errors\"\n",
    "print \"maximum order of diffraction is\",round(nmax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 4.2, Page number 66"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "glancing angle is 22.942 degrees\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "d=3.04*10**-10;    #lattice spacing(m)\n",
    "n=3;   #order\n",
    "lamda=0.79*10**-10;    #wavelength(m)\n",
    "\n",
    "#Calculation\n",
    "theta=math.asin(n*lamda/(2*d));     #glancing angle(radian)\n",
    "theta=theta*180/math.pi;          #glancing angle(degrees)\n",
    "\n",
    "#Result\n",
    "print \"glancing angle is\",round(theta,3),\"degrees\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 4.3, Page number 66"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "glancing angle is 21.01 degrees\n",
      "answer in the book is wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=0.28*10**-9;    #lattice spacing(m)\n",
    "n=2;   #order\n",
    "lamda=0.071*10**-9;    #wavelength(m)\n",
    "h=1;\n",
    "k=1;\n",
    "l=0;\n",
    "\n",
    "#Calculation\n",
    "d110=a/math.sqrt(h**2+k**2+l**2);     #spacing(m)\n",
    "theta=math.asin(n*lamda/(2*d110));    #glancing angle(radian)\n",
    "theta=theta*180/math.pi;          #glancing angle(degrees)\n",
    "\n",
    "#Result\n",
    "print \"glancing angle is\",round(theta,2),\"degrees\"\n",
    "print \"answer in the book is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 4.4, Page number 67"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "space of plane is 2.3336 angstrom\n",
      "volume of unit cell is 12.708 *10**-30 m**3\n",
      "answer varies due to rounding off errors\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "n=1;   #order\n",
    "lamda=3*10**-10;    #wavelength(m)\n",
    "h=1;\n",
    "k=0;\n",
    "l=0;\n",
    "theta=40;    #angle(degree)\n",
    "\n",
    "#Calculation\n",
    "theta=theta*math.pi/180;    #angle(radian)\n",
    "d=n*lamda/(2*math.sin(theta));     #space of plane(m)\n",
    "a=d*math.sqrt(h**2+k**2+l**2);     \n",
    "V=a**3;      #volume of unit cell(m**3)\n",
    "\n",
    "#Result\n",
    "print \"space of plane is\",round(d*10**10,4),\"angstrom\"\n",
    "print \"volume of unit cell is\",round(V*10**30,3),\"*10**-30 m**3\"\n",
    "print \"answer varies due to rounding off errors\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 4.5, Page number 67"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "spacing is 4.23 angstrom\n",
      "answer in the book is wrong. hence the miller indices given in the book are also wrong and cannot be calculated\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=3;    #lattice spacing(m)\n",
    "n=1;   #order\n",
    "lamda=0.82*10**-9;    #wavelength(m)\n",
    "theta=75.86;    #angle(degree)\n",
    "\n",
    "#Calculation\n",
    "theta=theta*math.pi/180;    #angle(radian)\n",
    "d=n*10**10*lamda/(2*math.sin(theta));    #spacing(angstrom)\n",
    "\n",
    "#Result\n",
    "print \"spacing is\",round(d,2),\"angstrom\"\n",
    "print \"answer in the book is wrong. hence the miller indices given in the book are also wrong and cannot be calculated\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 4.6, Page number 68"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "interplanar spacing is 2.502 angstrom\n",
      "answer in the book is wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "e=1.6*10**-19;    #charge(c)\n",
    "m=9.1*10**-31;    #mass(kg)\n",
    "h=6.625*10**-34;   #plank constant\n",
    "n=1;   #order\n",
    "theta=9+(12/60)+(25/(60*60));    #angle(degree)\n",
    "V=235.2;    #kinetic energy of electron(eV)\n",
    "\n",
    "#Calculation\n",
    "theta=theta*math.pi/180;    #angle(radian)\n",
    "lamda=h*10**10/math.sqrt(2*m*e*V);   \n",
    "d=n*lamda/(2*math.sin(theta));       #interplanar spacing(angstrom)\n",
    "\n",
    "#Result\n",
    "print \"interplanar spacing is\",round(d,3),\"angstrom\"\n",
    "print \"answer in the book is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 4.7, Page number 68"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wavelength of X-ray beam is 3 angstrom\n",
      "energy of Xray beam is 4.14 *10**5 eV\n",
      "answer in the book is wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "n=1;   #order\n",
    "h=1;\n",
    "k=1;\n",
    "l=1;\n",
    "e=1.6*10**-19;    #charge(c)\n",
    "theta=27.5;    #angle(degree)\n",
    "H=6.625*10**-34;    #plancks constant\n",
    "c=3*10**10;    #velocity of light(m)\n",
    "a=5.63*10**-10;     #lattice constant(m)\n",
    "\n",
    "#Calculation\n",
    "theta=theta*math.pi/180;    #angle(radian)\n",
    "d=a/math.sqrt(h**2+k**2+l**2);\n",
    "lamda=2*d*math.sin(theta)/n;      #wavelength of Xray beam(m)\n",
    "E=H*c/(e*lamda);           #energy of Xray beam(eV)         \n",
    "\n",
    "#Result\n",
    "print \"wavelength of X-ray beam is\",int(lamda*10**10),\"angstrom\"\n",
    "print \"energy of Xray beam is\",round(E/10**5,2),\"*10**5 eV\"\n",
    "print \"answer in the book is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 4.8, Page number 69"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "spacing of crystal is 0.253 angstrom\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "e=1.6*10**-19;    #charge(c)\n",
    "theta=56;    #angle(degree)\n",
    "V=854;    #voltage(V)\n",
    "n=1;      #order of diffraction\n",
    "m=9.1*10**-31;    #mass(kg)\n",
    "h=6.625*10**-34;   #plank constant\n",
    "\n",
    "#Calculation\n",
    "theta=theta*math.pi/180;    #angle(radian)\n",
    "lamda=h/math.sqrt(2*m*e*V);    #wavelength(m)\n",
    "d=n*lamda/(2*math.sin(theta));     #spacing of crystal(m)\n",
    "\n",
    "#Result\n",
    "print \"spacing of crystal is\",round(d*10**10,3),\"angstrom\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 4.9, Page number 69"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "lattice parameter is 3.794 angstrom\n",
      "answer in the book is wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "n=1;   #order\n",
    "h=2;\n",
    "k=0;\n",
    "l=2;\n",
    "theta=34;    #angle(degree)\n",
    "lamda=1.5;   #wavelength(angstrom)\n",
    "\n",
    "#Calculation\n",
    "theta=theta*math.pi/180;    #angle(radian)\n",
    "d=n*lamda/(2*math.sin(theta));     #spacing of crystal(angstrom)\n",
    "a=d*math.sqrt(h**2+k**2+l**2);     #lattice parameter(angstrom)\n",
    "\n",
    "#Result\n",
    "print \"lattice parameter is\",round(a,3),\"angstrom\"\n",
    "print \"answer in the book is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 4.10, Page number 70"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bragg's angle is 2.4389 degrees\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "n=1;   #order\n",
    "h=1;\n",
    "k=1;\n",
    "l=1;\n",
    "e=1.6*10**-19;    #charge(c)\n",
    "V=5000;    #voltage(V)\n",
    "m=9.1*10**-31;    #mass(kg)\n",
    "H=6.625*10**-34;   #plank constant\n",
    "d=0.204*10**-9;    #interplanar spacing(m)\n",
    "\n",
    "#Calculation\n",
    "lamda=H/math.sqrt(2*m*e*V);    #wavelength(m)\n",
    "theta=math.asin(n*lamda/(2*d));    #bragg's angle(radian)\n",
    "theta=theta*180/math.pi;    #bragg's angle(degree)\n",
    "\n",
    "#Result\n",
    "print \"bragg's angle is\",round(theta,4),\"degrees\""
   ]
  }
 ],
 "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.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
