{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#3: Crystal Planes and Point Defects"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 3.1, Page number 45"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "miller indices are ( 3 6 1 )\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=1;\n",
    "b=1/2;\n",
    "c=3;      #intercepts\n",
    "\n",
    "#Calculation\n",
    "h=int(c/a);\n",
    "k=int(c/b);\n",
    "l=int(c/c);     #miller indices\n",
    "\n",
    "#Result\n",
    "print \"miller indices are (\",h,k,l,\")\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 3.5, Page number 48"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "miller indices are ( 3 2 6 )\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "a=1;\n",
    "b=2;\n",
    "c=3;      #intercepts\n",
    "\n",
    "#Calculation\n",
    "h=int(c/a);\n",
    "k=int(b);\n",
    "l=int(c*b);     #miller indices\n",
    "\n",
    "#Result\n",
    "print \"miller indices are (\",h,k,l,\")\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 3.7, Page number 48"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "miller indices are a/3 b/4 inf\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "from sympy import Symbol\n",
    "\n",
    "#Variable declaration\n",
    "a=Symbol('a');\n",
    "b=Symbol('b');\n",
    "X=3;\n",
    "Y=4;\n",
    "Z=0;       #intercepts\n",
    "\n",
    "#Calculation\n",
    "x=a/X;\n",
    "y=b/Y;\n",
    "z=float('inf');      #miller indices\n",
    "\n",
    "#Result\n",
    "print \"miller indices are\",x,y,z"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 3.8, Page number 49"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "spacing between planes is 2.521 nm\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.25;\n",
    "b=0.25;\n",
    "c=0.18;\n",
    "h=1;\n",
    "k=1;\n",
    "l=1;\n",
    "\n",
    "#Calculation\n",
    "d_hkl=1/math.sqrt((a**2/h**2)+(b**2/k**2)+(c**2/l**2));     #spacing between planes(nm)\n",
    "\n",
    "#Result\n",
    "print \"spacing between planes is\",round(d_hkl,3),\"nm\"\n",
    "print \"answer in the book is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 3.9, Page number 49"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of atoms is 17.169 *10**18 atoms/mm**2\n",
      "answer in the book is wrong\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;    #miller indices of (100)\n",
    "h2=1;\n",
    "k2=1;\n",
    "l2=0;    #miller indices of (110)\n",
    "a=0.287;    #lattice constant(nm)\n",
    "\n",
    "#Calculation\n",
    "d100=a/math.sqrt(h1**2+k1**2+l1**2);    #spacing(nm)\n",
    "d110=a/math.sqrt(h2**2+k2**2+l2**2);    #spacing(nm)\n",
    "rho=2/(math.sqrt(2)*(d100*10**-9)**2);    #number of atoms(per mm**2)\n",
    "\n",
    "#Result\n",
    "print \"number of atoms is\",round(rho*10**-18,3),\"*10**18 atoms/mm**2\"\n",
    "print \"answer in the book is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 3.10, Page number 49"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "interplanar spacing for (111) is 2.087 angstrom\n",
      "interplanar spacing for (321) is 0.966 angstrom\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "r=0.1278*10**-9;    #atomic radius(m)\n",
    "h1=1;\n",
    "k1=1;\n",
    "l1=1;\n",
    "h2=3;\n",
    "k2=2;\n",
    "l2=1;\n",
    "\n",
    "#Calculation\n",
    "a=2*math.sqrt(2)*r;\n",
    "d111=a*10**10/math.sqrt(h1**2+k1**2+l1**2);    #interplanar spacing for (111)\n",
    "d321=a*10**10/math.sqrt(h2**2+k2**2+l2**2);    #interplanar spacing for (321)\n",
    "\n",
    "#Result\n",
    "print \"interplanar spacing for (111) is\",round(d111,3),\"angstrom\"\n",
    "print \"interplanar spacing for (321) is\",round(d321,3),\"angstrom\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 3.11, Page number 50"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "percent volume change is 0.5 %\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "r1=1.258*10**-10;     #radius(m)\n",
    "r2=1.292*10**-10;     #radius(m)\n",
    "\n",
    "#Calculation\n",
    "a_bcc=4*r1/math.sqrt(3);\n",
    "v=a_bcc**3;\n",
    "V1=v/2;\n",
    "a_fcc=2*math.sqrt(2)*r2;\n",
    "V2=a_fcc**3/4;\n",
    "V=(V1-V2)*100/V1;           #percent volume change is\",V,\"%\"\n",
    "\n",
    "#Result\n",
    "print \"percent volume change is\",round(V,1),\"%\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 3.12, Page number 50"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "volume of cell is 9.356 *10**-29 m**3\n",
      "density of Zn is 6963.5 kg/m**3\n",
      "answer in the book is wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "C=0.494*10**-9;      #height(m)\n",
    "a=0.27*10**-9;      #distance(m)\n",
    "M=65.37;      #atomic weight\n",
    "N=6.02*10**26;    #avagadro number\n",
    "\n",
    "#Calculation\n",
    "V=3*math.sqrt(3)*a**2*C/2;      #volume of cell(m**3)\n",
    "m=6*M/N;\n",
    "rho=m/V;      #density of Zn(kg/m**3)\n",
    "\n",
    "#Result\n",
    "print \"volume of cell is\",round(V*10**29,3),\"*10**-29 m**3\"\n",
    "print \"density of Zn is\",round(rho,1),\"kg/m**3\"\n",
    "print \"answer in the book is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 3.13, Page number 51"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fraction of vacancy sites is 8.466 *10**-7\n",
      "answer in the book varies due to rounding off errors\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "T1=773;    #temperature(K)\n",
    "T2=1273;   #temperature(K)\n",
    "n=1*10**-10;    #fraction of vacancy sites\n",
    "\n",
    "#Calculation\n",
    "logx=round(T1*math.log(n)/T2,3);\n",
    "x=math.exp(logx);           #fraction of vacancy sites\n",
    "\n",
    "#Result\n",
    "print \"fraction of vacancy sites is\",round(x*10**7,3),\"*10**-7\"\n",
    "print \"answer in the book varies due to rounding off errors\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 3.14, Page number 51"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ratio of number of vacancies is 3.98 *10**-8\n",
      "answer in the book varies due to rounding off errors\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "Ev=68*10**3;    #enthalpy(j/mol)\n",
    "R=8.314;\n",
    "T1=300;    #temperature(K)\n",
    "T2=800;   #temperature(K)\n",
    "\n",
    "#Calculation\n",
    "x1=-Ev/(R*T1);\n",
    "x2=-Ev/(R*T2);\n",
    "n=math.exp(x1)/math.exp(x2);      #ratio of number of vacancies\n",
    "\n",
    "#Result\n",
    "print \"ratio of number of vacancies is\",round(n*10**8,2),\"*10**-8\"\n",
    "print \"answer in the book varies due to rounding off errors\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example number 3.15, Page number 52"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "value of concentration is 1.2 eV\n",
      "average seperation is 0.46 *10**-6 m\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "KbT=0.025;\n",
    "nbyN=1/10**10;    #concentration\n",
    "N=10**29;\n",
    "\n",
    "#Calculation\n",
    "x=2*KbT;\n",
    "Ev=x*math.log(1/nbyN);     #value of concentration(eV)\n",
    "n=1/((N*nbyN)**(1/3));     #average seperation(m)\n",
    "\n",
    "#Result\n",
    "print \"value of concentration is\",round(Ev,1),\"eV\"\n",
    "print \"average seperation is\",round(n*10**6,2),\"*10**-6 m\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 3.16, Page number 52"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "energy required is 1.97 eV\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "N=2.303*16.65;\n",
    "T=298;    #temperature(K)\n",
    "Kb=8.625*10**-5;\n",
    "\n",
    "#Calculation\n",
    "E=2*N*Kb*T;      #energy required(eV)\n",
    "\n",
    "#Result\n",
    "print \"energy required is\",round(E,2),\"eV\""
   ]
  }
 ],
 "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
}
