{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#7: Crystal Planes and X-ray Diffraction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.1, Page number 7.12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i)Number of atoms per unit area of (100)plane= 1/(4*R**2)\n",
      "ii)Number of atoms per unit area of (110)plane= 2.82842712474619*R**2\n",
      "iii)Number of atoms per unit area of (111)plane= 2.3094010767585*R**2\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "from sympy import Symbol\n",
    "#Variable declaration\n",
    "R=Symbol('R')\n",
    "a=2*R\n",
    "\n",
    "#Results\n",
    "print\"i)Number of atoms per unit area of (100)plane=\",1/a**2\n",
    "print\"ii)Number of atoms per unit area of (110)plane=\",1/math.sqrt(2)*a**2\n",
    "print\"iii)Number of atoms per unit area of (111)plane=\",1/math.sqrt(3)*a**2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.2, Page number 7.13"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i)Surface area of the face ABCD = 13.0 *10**-14 mm**2\n",
      "ii)Surface area of plane (110) = 1.09 *10**13 atoms/mm**2\n",
      "iii)Surface area of pane(111)= 1.772 *10**13 atoms/mm**2\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=3.61*10**-7\n",
    "BC=math.sqrt(2)/2\n",
    "AD=(math.sqrt(6))/2\n",
    "#Result\n",
    "print\"i)Surface area of the face ABCD =\",round(a**2*10**14),\"*10**-14 mm**2\"\n",
    "print\"ii)Surface area of plane (110) =\",round((2/(a*math.sqrt(2)*a)/10**13),2),\"*10**13 atoms/mm**2\"\n",
    "print\"iii)Surface area of pane(111)=\",round(2/(BC*AD*a**2)*10**-13,3),\"*10**13 atoms/mm**2\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.3, Page number 7.14"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "d1 = 1.0\n",
      "d2 = 0.707\n",
      "d3 = 0.577\n",
      "d1:d2:d3 = 1.0 : 0.707 : 0.577\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "h1=1\n",
    "k1=0\n",
    "l1=0\n",
    "h2=1\n",
    "k2=1\n",
    "l2=0\n",
    "h3=1\n",
    "k3=1\n",
    "l3=1\n",
    "a=1\n",
    "\n",
    "#Calculations\n",
    "d1=a/(math.sqrt(h1**2+k1**2+l1**2))\n",
    "d2=a/(math.sqrt(h2**2+k2**2+l2**2))\n",
    "d3=a/(math.sqrt(h3**2+k3**2+l3**2))\n",
    "\n",
    "#Result\n",
    "print\"d1 =\",d1 \n",
    "print\"d2 =\",round(d2,3)\n",
    "print\"d3 =\",round(d3,3)\n",
    "print\"d1:d2:d3 =\",d1,\":\",round(d2,3),\":\",round(d3,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.4, Page number 7.15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "d(220) = 159.1 pm\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "h=2\n",
    "k=2\n",
    "l=0\n",
    "a=450\n",
    "\n",
    "#Calculations\n",
    "d=a/(math.sqrt(h**2+k**2+l**2))\n",
    "\n",
    "#Result\n",
    "print\"d(220) =\",round(d,1),\"pm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.5, Page number 7.15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a = 3.615 Angstroms\n",
      "d = 2.087 Angstroms\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=3.615\n",
    "r=1.278\n",
    "h=1\n",
    "k=1\n",
    "l=1\n",
    "\n",
    "#Calculations\n",
    "a=(4*r)/math.sqrt(2)\n",
    "d=a/(math.sqrt(h**2+k**2+l**2))\n",
    "\n",
    "#Result\n",
    "print\"a =\",round(a,3),\"Angstroms\"\n",
    "print\"d =\",round(d,3),\"Angstroms\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.7, Page number 7.15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "d = 1.45 *10**-10 m\n",
      "a = 4.1 *10**-10 m\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "n=1\n",
    "lamda=1.54\n",
    "theta=32*math.pi/180\n",
    "h=2\n",
    "k=2\n",
    "l=0\n",
    "\n",
    "#Calculations\n",
    "d=(n*lamda*10**-10)/(2*math.sin(theta))   #derived from 2dsin(theta)=n*l\n",
    "a=d*(math.sqrt(h**2+k**2+l**2))\n",
    "\n",
    "#Results\n",
    "print\"d =\",round(d*10**10,2),\"*10**-10 m\"\n",
    "print\"a =\",round(a*10**10,1),\"*10**-10 m\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.8, Page number 7.16"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i.  d/n = 2.582 Angstroms\n",
      "ii. d/n = 1.824 Angstroms\n",
      "iii.d/n = 1.289 Angstroms\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "lamda=0.58\n",
    "theta1=6.45*math.pi/180\n",
    "theta2=9.15*math.pi/180\n",
    "theta3=13*math.pi/180\n",
    "\n",
    "#Calculations\n",
    "dbyn1=lamda/(2*(math.sin(theta1)))\n",
    "dbyn2=lamda/(2*math.sin(theta2))\n",
    "dbyn3=lamda/(2*math.sin(theta3))\n",
    "           \n",
    "#Results\n",
    "print\"i.  d/n =\",round(dbyn1,3),\"Angstroms\"\n",
    "print\"ii. d/n =\",round(dbyn2,3),\"Angstroms\"\n",
    "print\"iii.d/n =\",round(dbyn3,3),\"Angstroms\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.9, Page number 7.16"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n = 1.53\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "d=1.18\n",
    "theta=90*math.pi/180\n",
    "lamda=1.540\n",
    "\n",
    "#Calculations\n",
    "n=(2*d*math.sin(theta))/lamda\n",
    "\n",
    "#Result\n",
    "print\"n =\",round(n,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.10, Page number 7.17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a = 3.51 Angstorms\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "lamda=0.58\n",
    "theta=9.5*math.pi/180\n",
    "n=1\n",
    "d=0.5           #d200=a/math.sqrt(2**2+0**2+0**2)=0.5a\n",
    "#Calculations\n",
    "a=n*lamda/(2*d*math.sin(theta))     #2*d*sin(theta)=n*lamda \n",
    "\n",
    "#Result\n",
    "print\"a =\",round(a,2),\"Angstorms\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.11, Page number 7.17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sin(theta3) = 26 35.9387574495\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "lamda=0.842\n",
    "n1=1\n",
    "q=(8+(35/60))*(math.pi/180)\n",
    "n2=3\n",
    "d=1\n",
    "#Calculations\n",
    "#n*lamda=2*d*sin(theta)\n",
    "#n1*0.842=2*d*sin(q)\n",
    "#n3*0.842=2*d*sin(theta3)\n",
    "#Dividing both the eauations, we get\n",
    "#(n2*lamda)/(n1*lamda)=2*d*math.sin(theta3)/2*d*math.sin(q)\n",
    "theta3=math.asin((((n2*lamda)/(n1*lamda))*(2*d*math.sin(q)))/(2*d))\n",
    "d=theta3*180/math.pi;\n",
    "a_d=int(d);\n",
    "a_m=(d-int(d))*60\n",
    "\n",
    "#Result\n",
    "print\"sin(theta3) =\",a_d,a_m\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.12, Page number 7.18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "d = 2.22 Angstorms\n",
      "sqrt(h**2+k**2+l**2) = 1.424\n",
      "Therefore, h**2+k**2+l**2 =sqrt(2)\n",
      "h =1, k=1\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=3.16\n",
    "lamda=1.54\n",
    "n=1\n",
    "theta=20.3*math.pi/180\n",
    "\n",
    "#Calculations\n",
    "d=(n*lamda)/(2*math.sin(theta))\n",
    "x=a/d                             #let math.sqrt(h**2+k**2+l**2)=x\n",
    "\n",
    "#Result\n",
    "print\"d =\",round(d,2),\"Angstorms\"\n",
    "print\"sqrt(h**2+k**2+l**2) =\",round(x,3)\n",
    "print\"Therefore, h**2+k**2+l**2 =sqrt(2)\"\n",
    "print\"h =1, k=1\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.13, Page number 7.18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a = 4.09 Angstroms\n",
      "d = 2.36 Angstroms\n",
      "lamda = 1.552 Angstroms\n",
      "E = 8.0 *10**3 eV\n"
     ]
    }
   ],
   "source": [
    "## importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "n=4\n",
    "A=107.87\n",
    "rho=10500\n",
    "N=6.02*10**26\n",
    "h=1;\n",
    "k=1;\n",
    "l=1;\n",
    "H=6.625*10**-34\n",
    "e=1.6*10**-19\n",
    "theta=(19+(12/60))*math.pi/180\n",
    "C=3*10**8\n",
    "#Calculations\n",
    "a=((n*A)/(rho*N))**(1/3)*10**10\n",
    "d=a/math.sqrt(h**2+k**2+l**2)\n",
    "lamda=2*d*math.sin(theta)\n",
    "E=(H*C)/(lamda*10**-10*e)\n",
    "\n",
    "#Result\n",
    "print\"a =\",round(a,2),\"Angstroms\"\n",
    "print\"d =\",round(d,2),\"Angstroms\"\n",
    "print\"lamda =\",round(lamda,3),\"Angstroms\"\n",
    "print\"E =\",round(E/10**3),\"*10**3 eV\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 7.14, Page number 7.19"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "d = 2.64 Angstorms\n",
      "sin(theta)= 0.288\n",
      "X = 7.554 cm\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=4.57\n",
    "h=1\n",
    "k=1\n",
    "l=1\n",
    "lamda=1.52\n",
    "twotheta=33.5*math.pi/180\n",
    "r=5                  #radius\n",
    "#Calculations\n",
    "d=a/(h**2+k**2+l**2)**(1/2)\n",
    "sintheta=lamda/(2*d)\n",
    "X=r/math.tan(twotheta)\n",
    "\n",
    "#Result\n",
    "print\"d =\",round(d,2),\"Angstorms\"\n",
    "print\"sin(theta)=\",round(sintheta,3)\n",
    "print\"X =\",round(X,3),\"cm\""
   ]
  }
 ],
 "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
}