{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#2: Crystallography and Crystal Structures"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 2.3, Page number 2.9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of atoms in (100) is a**(-2) atoms/mm**2\n",
      "number of atoms in (110) is 0.707106781186547/a**2 atoms/mm**2\n",
      "number of atoms in (111) is 0.577350269189626/a**2 atoms/mm**2\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "from sympy import Symbol\n",
    "import numpy as np\n",
    "\n",
    "#Variable declaration\n",
    "a=Symbol('a');      #lattice constant(mm)\n",
    "x1=4;\n",
    "x2=math.sqrt(2);\n",
    "b=a*math.sqrt(2);\n",
    "theta=30;   #angle(degrees)\n",
    "\n",
    "#Calculation\n",
    "theta=theta*math.pi/180;    #angle(radian)\n",
    "na1=x1*1/(x1*a**2);     #number of atoms in (100)(per mm**2)\n",
    "na2=1/(x2*a**2);      #number of atoms in (110)(per mm**2)\n",
    "A3=(1/2)*b*b*math.cos(theta);  \n",
    "t=60/360*3;\n",
    "na3=t/A3;     #number of atoms in (111)(per mm**2)\n",
    "\n",
    "#Result\n",
    "print \"number of atoms in (100) is\",na1,\"atoms/mm**2\"\n",
    "print \"number of atoms in (110) is\",na2,\"atoms/mm**2\"\n",
    "print \"number of atoms in (111) is\",na3,\"atoms/mm**2\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 2.4, Page number 2.11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "interplanar spacing for (110) is 0.2556 nm\n",
      "interplanar spacing for (212) is 0.1205 nm\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "r=0.1278;     #atomic radius(m)\n",
    "h1=1;\n",
    "k1=1;\n",
    "l1=0;\n",
    "h2=2;\n",
    "k2=1;\n",
    "l2=2;\n",
    "\n",
    "#Calculation\n",
    "a=round(4*r/math.sqrt(2),4);\n",
    "d110=a/math.sqrt(h1**2+k1**2+l1**2);    #interplanar spacing for (110)(nm)\n",
    "d212=a/math.sqrt(h2**2+k2**2+l2**2);    #interplanar spacing for (212)(nm)\n",
    "\n",
    "#Result\n",
    "print \"interplanar spacing for (110) is\",round(d110,4),\"nm\"\n",
    "print \"interplanar spacing for (212) is\",d212,\"nm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 2.5, Page number 2.11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "seperation between successive lattice planes is 1 : 0.71 : 0.58\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",
    "\n",
    "#Calculation\n",
    "d100=1/math.sqrt(h1**2+k1**2+l1**2);    #interplanar spacing for (110)\n",
    "d110=1/math.sqrt(h2**2+k2**2+l2**2);    #interplanar spacing for (110)\n",
    "d111=1/math.sqrt(h3**2+k3**2+l3**2);    #interplanar spacing for (111)\n",
    "\n",
    "#Result\n",
    "print \"seperation between successive lattice planes is\",int(d100),\":\",round(d110,2),\":\",round(d111,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 2.6, Page number 2.12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "miller indices of plane is ( 3.0 6.0 1.0 )\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;\n",
    "\n",
    "#Calculation\n",
    "A=1/a;\n",
    "B=1/b;\n",
    "C=1/c;\n",
    "h=A*c;\n",
    "k=B*c;\n",
    "l=C*c;      #miller indices of plane\n",
    "\n",
    "#Result\n",
    "print \"miller indices of plane is (\",h,k,l,\")\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 2.7, Page number 2.22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "radius of interstitial sphere is 0.155 r\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "r=1;    #assume\n",
    "\n",
    "#Calculation\n",
    "a=4/math.sqrt(3);\n",
    "R=(a-(2*r))/2;      #radius of interstitial sphere(r)\n",
    "\n",
    "#Result\n",
    "print \"radius of interstitial sphere is\",round(R,3),\"r\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 2.8, Page number 2.23"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "decrease of volume is 0.5 %\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "r1=1.258;     #atomic radius(angstrom)\n",
    "r2=1.292;     #atomic radius(angstrom)\n",
    "\n",
    "#Calculation\n",
    "a1=4*r1/math.sqrt(3);       #spacing(angstrom)\n",
    "n1=((1/8)*8)+1;      #number of atoms per unit cell\n",
    "v1=a1**3/n1;           #volume occupied by 1 atom(m**3)\n",
    "n2=(1/2*6)+(1/8*8);    #number of atoms per unit cell\n",
    "a2=2*math.sqrt(2)*r2;   #spacing(angstrom)\n",
    "v2=a2**3/n2;           #volume occupied by 1 atom(m**3)\n",
    "dc=(v1-v2)*100/v1;     #change in volume(%)\n",
    "\n",
    "#Result\n",
    "print \"decrease of volume is\",round(dc,1),\"%\"                                    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 2.9, Page number 2.24"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "volume of unit cell is 9.356 *10**-29 m**3\n",
      "density of zinc is 6960 kg/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",
    "a=0.27*10**-9;     #spacing(m)\n",
    "c=0.494*10**-9;\n",
    "n=6;    #number of atoms\n",
    "M=65.37;    #atomic weight\n",
    "N=6.023*10**26;    #avagadro number\n",
    "\n",
    "#Calculation\n",
    "V=3*math.sqrt(3)*a**2*c/2;     #volume of unit cell(m**3)\n",
    "rho=n*M/(N*V);     #density of zinc(kg/m**3)\n",
    "\n",
    "#Result\n",
    "print \"volume of unit cell is\",round(V*10**29,3),\"*10**-29 m**3\"\n",
    "print \"density of zinc is\",int(rho),\"kg/m**3\"\n",
    "print \"answer varies due to rounding off errors\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 2.10, Page number 2.24"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "radius of interstitial sphere is 0.414 r\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "r=1;    #assume\n",
    "\n",
    "#Calculation\n",
    "a=4*r/math.sqrt(2);\n",
    "R=(a/2)-r;      #radius of interstitial sphere(r)\n",
    "\n",
    "#Result\n",
    "print \"radius of interstitial sphere is\",round(R,3),\"r\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 2.11, Page number 2.25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of atoms per m**3 is 1.77 *10**29\n",
      "density of diamond is 3535.7 kg/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",
    "a=0.356*10**-9;       #cube edge(m)\n",
    "m=12.01;    #atomic weight of carbon\n",
    "N=6.023*10**26;    #avagadro number\n",
    "\n",
    "#Calculation\n",
    "n=8/a**3;     #number of atoms per m**3\n",
    "M=m/N;\n",
    "d=M*n;       #density of diamond(kg/m**3)\n",
    "\n",
    "#Result\n",
    "print \"number of atoms per m**3 is\",round(n/10**29,2),\"*10**29\"\n",
    "print \"density of diamond is\",round(d,1),\"kg/m**3\"\n",
    "print \"answer varies due to rounding off errors\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 2.12, Page number 2.26"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "distance between 2 adjacent atoms is 2.81 angstrom\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "mw=23+35.5;     #molecular weight of NaCl(gm/mol)\n",
    "N=6.023*10**23;    #avagadro number(per mol)\n",
    "d=2.18;       #mass of unit volume\n",
    "\n",
    "#Calculation\n",
    "M=mw/N;     #mass of NaCl molecule(gm)\n",
    "n=2*d/M;      #number of atoms per unit volume(atoms/cm**3)\n",
    "a=(1/n)**(1/3);     #distance between 2 adjacent atoms(cm)\n",
    "\n",
    "#Result\n",
    "print \"distance between 2 adjacent atoms is\",round(a*10**8,2),\"angstrom\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 2.13, Page number 2.26"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "density of copper crystal is 8.929 gm/cm**3\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "M=63.5;    #atomic weight\n",
    "N=6.023*10**23;    #avagadro number\n",
    "r=1.278*10**-8;    #radius(m)\n",
    "n=4;\n",
    "\n",
    "#Calculation\n",
    "m=M/N;     #mass of copper atom(gm)\n",
    "a=4*r/math.sqrt(2);\n",
    "Mu=n*m;     #mass of unit cell\n",
    "d=Mu/a**3;    #density of copper crystal(gm/cm**3)\n",
    "\n",
    "#Result\n",
    "print \"density of copper crystal is\",round(d,3),\"gm/cm**3\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 2.14, Page number 2.27"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "free volume per unit cell is 7.6795 *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",
    "r=0.1249*10**-9;     #radius(m)\n",
    "pf=0.68;      #packing factor\n",
    "\n",
    "#Calculation\n",
    "a=4*r/math.sqrt(3);    #lattice constant(m)\n",
    "v=a**3;     #volume of unit cell(m**3)\n",
    "Fv=(1-pf)*v;     #free volume per unit cell(m**3)\n",
    "\n",
    "#Result\n",
    "print \"free volume per unit cell is\",round(Fv*10**30,4),\"*10**-30 m**3\"\n",
    "print \"answer varies due to rounding off errors\""
   ]
  }
 ],
 "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
}