{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 4 Imperfections in Atomic and Ionic Arrangements"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4_1 pgno:115"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Temperature at which this number of vacancies forms in copper in Degree celsius: 102.0\n"
     ]
    }
   ],
   "source": [
    "from math import log,exp\n",
    "# Initialisation of Variables\n",
    "Lp=0.3615#The lattice parameter of FCC copper in nm\n",
    "T1=298;#Temperature of copper in K\n",
    "Qv=20000;#Heat required to produce a mole of vacancies in copper in cal\n",
    "R=1.987;#The gas constant in cal/mol-K\n",
    "#CALCULATIONS\n",
    "n=4/(Lp*10**-8)**3;#The number of copper atoms or lattice points per cm**3  in atoms/cm**3\n",
    "nv1=n*exp(-Qv/(T1*R));#concentration of vacancies in copper at 25 degree celsius  in vacancies /cm**3\n",
    "nv2=nv1*1000;#concentration of vacancies in copper atoms at T2 temperature\n",
    "T2=-Qv/(R*log(nv2/n));#temperature at which this number of vacancies forms in copper in K\n",
    "print \"Temperature at which this number of vacancies forms in copper in Degree celsius:\",round(T2-273)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4_2 pgno:116"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The expected theoretical density of iron BCC  7.88142586455\n",
      "Number of iron atoms that would be present in each unit cell for the required density: 1.99710055902\n",
      "The number of vacancies per cm**3 : 5.18240407897e+19\n"
     ]
    }
   ],
   "source": [
    "# Initialisation of Variables\n",
    "n1=2;#No. of Atoms in BCC iron Crystal\n",
    "m=55.847;#Atomic mass of BCC iron crystal\n",
    "a0=2.866*10**-8;#The lattice parameter of BCC iron in cm\n",
    "Na=6.02*10**23;#Avogadro's number in atoms/mol\n",
    "rho1=7.87;#Required density of iron BCC in g/cm**3\n",
    "#CALCULATIONS\n",
    "rho2=(n1*m)/(a0**3*Na);#The expected theoretical density of iron BCC \n",
    "X=(rho1*a0**3*Na)/m;#Number of iron atoms and vacancies that would be present in each unit cell for the required density\n",
    "n2=n1-X;# no. of vacacies per unit cell\n",
    "V=0.00122/a0**3;#The number of vacancies per cm**3 \n",
    "print \"The expected theoretical density of iron BCC \",rho2\n",
    "print \"Number of iron atoms that would be present in each unit cell for the required density:\",X\n",
    "print \"The number of vacancies per cm**3 :\",V\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4_3 pgno:117"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Radius of iron atom in nm 0.1241\n",
      "Interstitial Radius  of iron atom in nm: 0.03611\n",
      "the radius of the iron atom in nm: 0.12625\n",
      "the radius of the interstitial site in nm: 0.0523\n",
      "The atomic percentage  of carbon contained  in  BCC  iron in percent: 86.0\n",
      "The atomic percentage  of carbon contained  in  FCC  iron in percent: 50.0\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt\n",
    "# Initialisation of Variables\n",
    "a01=0.2866;#The Lattice parameter of BCC in nm\n",
    "a02=0.3571;#The Lattice parameter of FCC in nm\n",
    "r=0.071;#Radius of carbon atom in nm\n",
    "ni1=12.;#No. of interstitial sites per unit   cell for BCC\n",
    "ni2=4.;#No. of interstitial sites per unit   cell for FCC\n",
    "#CALCULATIONS\n",
    "Rb=(sqrt(3)*a01)/4.;#Radius of iron atom in nm\n",
    "Ri1=sqrt(0.3125*a01**2)-Rb;# Interstitial Radius  of iron atom in nm\n",
    "Rf=(sqrt(2)*a02)/4.;#the radius of the iron atom in nm\n",
    "Ri2=(a02-(2*Rf))/2.;#the radius of the interstitial site in nm\n",
    "C1=(ni1/(ni1+2))*100;#The atomic percentage  of carbon contained in the BCC iron in percent\n",
    "C2=(ni2/(ni2+4))*100;#The atomic percentage  of carbon contained in the FCC iron in percent\n",
    "print \"Radius of iron atom in nm\",round(Rb,5)\n",
    "print \"Interstitial Radius  of iron atom in nm:\",round(Ri1,5)\n",
    "print \"the radius of the iron atom in nm:\",round(Rf,5)\n",
    "print \"the radius of the interstitial site in nm:\",round(Ri2,5)\n",
    "print \"The atomic percentage  of carbon contained  in  BCC  iron in percent:\",round(C1)\n",
    "print \"The atomic percentage  of carbon contained  in  FCC  iron in percent:\",C2\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4_6 pgno:127"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The length of Burgers vector  in nm: 0.28\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt\n",
    "# Initialisation of Variable\n",
    "a0=0.396;#Lattice parameter  of magnesium     oxide\n",
    "h=1;#Because b is a [110] direction\n",
    "k=1;#Because b is a [110] direction\n",
    "l=0;#Because b is a [110] direction\n",
    "#CALCULATIONS\n",
    "b=a0/sqrt(2);#The length of Burgers vector  in nm\n",
    "print \"The length of Burgers vector  in nm:\",round(b,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4_7 pgno:128"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Face Diagonal of copperin nm: 0.51125\n",
      "The length of the Burgers vector in nm: 0.25563\n"
     ]
    }
   ],
   "source": [
    "\n",
    "from math import sqrt\n",
    "# Initialisation of Variables\n",
    "a01=0.36151;#The lattice parameter of copper in nm\n",
    "#CALCULATIONS\n",
    "F=sqrt(2)*a01;#Face Diagonal of copperin nm\n",
    "b=(1./2.)*(F);#The length of the Burgers vector, or the repeat distance in nm\n",
    "print \"Face Diagonal of copperin nm:\",round(F,5)\n",
    "print \"The length of the Burgers vector in nm:\",round(b,5)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4_8 pgno:129"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Planar density of (110)BCC in atoms/cm**2: 1.72172040168e+15\n",
      "The interplanar spacings for (110)BCC in cm: 2.02656803488e-17 3\n",
      "The interplanar spacings for (112)BCC in cm: 1.17003960047e-17 2\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt\n",
    "# Initialisation of Variables\n",
    "n=2;#No. of Atoms present per cell in BCC\n",
    "a0=2.866*10**-8;#The lattice parameter of BCC iron in cm\n",
    "rho1=0.994*10**15;#Planar density of (112)BCC in atoms/cm**2\n",
    "#CALCULATIONS\n",
    "a=sqrt(2)*a0**2;#Area of BCC iron in cm**2\n",
    "rho2=n/a;#Planar density of (110)BCC in atoms/cm**2\n",
    "d1=a0*10**-9/(sqrt(1**2+1**2+0));#The interplanar spacings for (110)BCC in cm\n",
    "d2=a0*10**-9/(sqrt(1**2+1**2+2**2));#The interplanar spacings for (112)BCC in cm\n",
    "print \"Planar density of (110)BCC in atoms/cm**2:\",round(rho2,2)\n",
    "print \"The interplanar spacings for (110)BCC in cm:\",d1,3\n",
    "print \"The interplanar spacings for (112)BCC in cm:\",d2,2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4_13 pgno:139"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the ASTM grain size number: 7.64\n"
     ]
    }
   ],
   "source": [
    "from math import log10\n",
    "# Initialisation of Variables\n",
    "g=16# No. of grains per square inch in a photomicrograph\n",
    "M=250;#Magnification in a photomicrograph\n",
    "N=(M/g)*100;#The number of grains per square   inch\n",
    "n=(log10(100)/log10(2))+1;#the ASTM grain size number\n",
    "print \"the ASTM grain size number:\",round(n,2)\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.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
