{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Chapter 1:Crystal Structure,Bonding and Defects in solids"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 1.1,Page No:1.8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Lattice Constant a = 4.00 Å\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#variable declaration\n",
    "\n",
    "p       = 6250;             # Density of crystal in kg/m**3\n",
    "N       = 6.023*10**26;      #Avagadros number in atoms/kilomole\n",
    "M       = 60.2;             #molecular weight per mole\n",
    "n       = 4;                #No. of atoms per unit cell for FCC\n",
    "\n",
    "#Calculations\n",
    "\n",
    "a       = ((n*M)/float(N*p))**(1/float(3));         #Lattice Constant Å\n",
    "\n",
    "#result\n",
    "\n",
    "print'Lattice Constant a = %3.2f'%(a*10**10),'Å';"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1.2,Page No:1.8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "d100 = 6.30 Å\n",
      "d110 = 4.45 Å\n",
      "d111 = 3.64 Å\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#variable declaration\n",
    "h1       = 1;            #miller indice\n",
    "k1       = 1;            # miller indice\n",
    "l1       = 1;            # miller indice\n",
    "h0       = 0;            # miller indice\n",
    "k0       = 0;            # miller indice\n",
    "l0       = 0;            # miller indice\n",
    "p       = 1980;             # Density of KCl in kg/m**3\n",
    "N       = 6.023*10**26;      # Avagadros number in atoms/kilomole\n",
    "M       = 74.5;             # molecular weight of KCl\n",
    "n       = 4;                # No. of atoms per unit cell for FCC\n",
    "\n",
    "# calculations\n",
    "a       = ((n*M)/float(N*p))**(1/float(3));\n",
    "\n",
    "#dhkl    = a/math.sqrt((h**2)+(k**2)+(l**2));               #interplanar distance\n",
    "d100     = a/math.sqrt((h1**2)+(k0**2)+(l0**2));           # interplanar distance\n",
    "d110     = a/math.sqrt((h1**2)+(k1**2)+(l0**2));           # interplanar distance\n",
    "d111     = a/math.sqrt((h1**2)+(k1**2)+(l1**2));          # interplanar distance\n",
    "\n",
    "# Output\n",
    "print'd100 = %3.2f'%(d100*10**10),'Å';\n",
    "print'd110 = %3.2f'%(d110*10**10),'Å';\n",
    "print'd111 = %3.2f'%(d111*10**10),'Å';\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1.3,Page No:1.9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "miller indices = 1  4 2\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "import fractions\n",
    "\n",
    "#variable declaration\n",
    "h          = 4;               #miller indices\n",
    "k          = 1;               #miller indices\n",
    "l          = 2;               #miller indices\n",
    " \n",
    "#calculation\n",
    "d     = fractions.gcd(h,k);\n",
    "lcm   = (h*k)/float(d);\n",
    "e     = fractions.gcd(lcm,l);\n",
    "lc    = (lcm*l)/float(e);                 #finding lcm\n",
    "h1    =1/float(h);       \n",
    "k1    =1/float(k);\n",
    "l1    =1/float(l);\n",
    "a     = h1*lc;               #miller indices\n",
    "b     = k1*lc;               #miller indices\n",
    "c     = l1*lc;               #miller indices\n",
    "\n",
    "#result\n",
    "print'miller indices = %d '%a,'%d'%b,'%d'%c;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1.4,Page No:1.10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "miller indices = 4 3 6\n"
     ]
    }
   ],
   "source": [
    "import fractions\n",
    "\n",
    "#variable declaration\n",
    "#intercepts given are 3a,4b,2c\n",
    "#from the law of rational indices\n",
    "#3a:4b:2c=a/h:b/k:c/l\n",
    "\n",
    "#Variable Declaration\n",
    "h1          = 3;               #miller indices\n",
    "k1          = 4;               #miller indices\n",
    "l1          = 2;               #miller indices\n",
    " \n",
    "#calculation\n",
    "d  = fractions.gcd(h1,k1);\n",
    "lcm  = (h1*k1)/float(d);\n",
    "e   = fractions.gcd(lcm,l1);\n",
    "lc   = (lcm*l1)/float(e);        #finding lcm\n",
    "\n",
    "h = lc*1/float(h1);               #miller indices \n",
    "k = lc*1/float(k1);               #miller indices\n",
    "l= lc*1/float(l1);               #miller indices\n",
    "\n",
    "#result\n",
    "print'miller indices = %d'%h,'%d'%k,'%d'%l;\n",
    " \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1.5,Page No:1.10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "miller indices =   6   3  -4\n"
     ]
    }
   ],
   "source": [
    "import fractions\n",
    "\n",
    "#variable declaration\n",
    "#intercepts given are a,2b,-3c/2\n",
    "#from the law of rational indices\n",
    "#a:2b:-3c/2=a/h:b/k:c/l\n",
    "\n",
    "\n",
    "#variable declaration\n",
    "h1  = 1;                         #miller indices\n",
    "k1  = 2;                         #miller indices\n",
    "l1  = 3;                         #miller indices \n",
    "\n",
    "#calculation\n",
    "d    = fractions.gcd(h1,k1);\n",
    "lcm  = (h1*k1)/float(d);\n",
    "e    = fractions.gcd(lcm,l1);\n",
    "lc   = (lcm*l1)/float(e);\n",
    "h2   = 1;\n",
    "k2   = 1/float(k1);\n",
    "l2   = -2/float(l1)\n",
    "h    =  h2*lc;                   #miller indices \n",
    "k    = (k2)*(lc);                #miller indices \n",
    "l    = (l2)*(lc);                #miller indices \n",
    "\n",
    "#result\n",
    "print'miller indices = %3.0f'%h,'%3.0f'%k,'%3.0f'%l;\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1.6,Page No:1.11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "miller indices = 1 1 2\n",
      "Note:printing mistake of miller indices in textbook \n",
      "\n",
      "\n",
      "miller indices = 1 2 0\n",
      "\n",
      "miller indices = 1 2 1\n",
      "Note:calculation mistake in textbook\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import fractions\n",
    "\n",
    "#variable declaration\n",
    "#intercepts given are 3a,3b,2c\n",
    "#from the law of rational indices\n",
    "#3a:3b:2c=a/h:b/k:c/l\n",
    "#variable declaration\n",
    "a    = 4;\n",
    "b    = 4;\n",
    "c    = 2;\n",
    "a1   = 2;\n",
    "b1   = 1;\n",
    "c1   = 1;\n",
    "a3   = 1;\n",
    "b3   = 1;\n",
    "c3   = 1;\n",
    "h12 = 1/float(2);                 #miller indices\n",
    "k12 = 1;                          #miller indices\n",
    "#l12 = 1/math.inf;                #miller indices\n",
    "l12  =0;\n",
    "h13 = 1;                 #miller indices\n",
    "k13 = 2;                 #miller indices\n",
    "l13 = 1;                 #miller indices\n",
    "\n",
    "\n",
    "#calculation\n",
    "d    = fractions.gcd(a,b);\n",
    "lcm  = (a*b)/float(d);\n",
    "e    = fractions.gcd(lcm,c);\n",
    "lc   = (lcm*c)/float(e);         #finding lcm \n",
    "h1   = 1/float(4);               #miller indices\n",
    "k1   = 1/float(4);               #miller indices\n",
    "l1   = 1/float(2);               #miller indices\n",
    "h    = h1*(lc);                               #miller indices\n",
    "k    = (k1)*(lc);                             #miller indices\n",
    "l    = (l1)*(lc);                             #miller indices\n",
    "\n",
    "d    = fractions.gcd(a1,b1);\n",
    "lcm  = (a1*b1)/float(d);\n",
    "e    = fractions.gcd(lcm,c1);\n",
    "lc1   = (lcm*c1)/float(e);\n",
    "# 1/%inf = 0  ; (1/2 1/1 0/1) hence lcm is taken for [2 1 1]\n",
    "h3  = h12*(lc1);                             #miller indices\n",
    "k3  = (k12)*(lc1);                             #miller indices\n",
    "l3  = (l12)*(lc1);                             #miller indices\n",
    "\n",
    "\n",
    "d    = fractions.gcd(a3,b3);\n",
    "lcm  = (a3*b3)/float(d);\n",
    "e    = fractions.gcd(lcm,c3);\n",
    "lc2   = (lcm*c3)/float(e);\n",
    "h4   = h13*(lc2);                             #miller indices\n",
    "k4   = k13*(lc2);                             #miller indices\n",
    "l4   = l13*(lc2);                             #miller indices\n",
    "\n",
    "\n",
    "\n",
    "#result\n",
    "print'miller indices = %d'%h,'%d'%k,'%d'%l;\n",
    "print'Note:printing mistake of miller indices in textbook \\n';\n",
    "print'\\nmiller indices = %d'%h3,'%d'%k3,'%d'%l3;\n",
    "print'\\nmiller indices = %d'%h4,'%d'%k4,'%d'%lc2;\n",
    "print'Note:calculation mistake in textbook\\n';\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example 1.7,Page No:1.16"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "d100 = 1.00 a\n",
      "d111 = 0.58 a\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#variable declaration\n",
    "h   = 1;                  #miller indices\n",
    "k   = 0;                 #miller indices\n",
    "l   = 0;                 #miller indices\n",
    "h1   = 1;                 #miller indices\n",
    "k1   = 1;                 #miller indices\n",
    "l1   = 1;                 #miller indices\n",
    "\n",
    "#calculations\n",
    "d100   = 1/float(math.sqrt((h**2)+(k**2)+(l**2)));\n",
    "d111   = 1/float(math.sqrt((h1**2)+(k1**2)+(l1**2)));\n",
    "\n",
    "#result\n",
    "print'd100 = %3.2f a'%d100;\n",
    "print'd111 = %3.2f a'%d111;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1.8,Page No:1.16"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "miller indices = 2 1 0\n",
      "interplanar distance is =4.47 Å\n"
     ]
    }
   ],
   "source": [
    "import fractions\n",
    "\n",
    "#variable declaration\n",
    "#intercepts given are a,2b,-3c/2\n",
    "#from the law of rational indices\n",
    "#a:2b:-3c/2=a/h:b/k:c/l\n",
    "\n",
    "\n",
    "#variable declaration\n",
    "h1   = 1;\n",
    "k1   = 2;\n",
    "l1   = 1;\n",
    "a    = 10*10**-9; \n",
    "\n",
    "#calculation\n",
    "h12  = 1;                         #miller indices\n",
    "k12  = 1/float(k1);                #miller indices\n",
    "l12  = 0;                         #miller indices\n",
    "\n",
    "#1/%inf = 0  ; (1/2 1/1 0/1) hence lcm is taken for [2 1 1]\n",
    "d    = fractions.gcd(h1,k1);\n",
    "lcm  = (h1*k1)/float(d);\n",
    "e    = fractions.gcd(lcm,l1);\n",
    "lc   = (lcm*l1)/float(e);\n",
    "h    = h12*(lcm);                         #miller indices\n",
    "k    = (k12)*(lcm);                         #miller indices\n",
    "l    = (l12)*(lcm);                         #miller indices\n",
    "d    = a/float(((h**2)+(k**2)+(l**2))**(1/float(2)));\n",
    "\n",
    "\n",
    "#result\n",
    "print'miller indices = %d'%h,'%d'%k,'%d'%l;\n",
    "print'interplanar distance is =%3.2f'%(d*10**9),'Å';"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example 1.9,Page No:1.17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "inter planar spacing =1.32e-10 m/n\n",
      "Note : calculation mistake in textbook in  calculating in dhkl,r value istaken as 0.125*10**-9  instead of 0.175*10**-9  \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#variable Declaration\n",
    "\n",
    "r       = 0.175*10**-9;              #radius in m\n",
    "h       = 2;                        #miller indices\n",
    "k       = 3;                        #miller indices\n",
    "l       = 1;                        #miller indices\n",
    "\n",
    "#calculation\n",
    "a      = (4*r)/math.sqrt(2);\n",
    "dhkl   = a/float(math.sqrt((h**2)+(k**2)+(l**2)));\n",
    " \n",
    "#result\n",
    "print'inter planar spacing =%3.2e'%dhkl,'m/n';\n",
    "print'Note : calculation mistake in textbook in  calculating in dhkl,r value istaken as 0.125*10**-9  instead of 0.175*10**-9  ';"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example 1.10,Page No:1.17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "distance between two atoms =1.732 Å\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "a       = 4;               #lattice constant in Å\n",
    "\n",
    "#calculation\n",
    "d       = (math.sqrt(3)*a)/float(4);    #distance between two atoms in Å\n",
    "  \n",
    "#result\n",
    "print'distance between two atoms =%3.3f'%d,'Å';"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "##Example 1.11,Page No:1.20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wavelength=0.431 Å\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#variable declaration\n",
    "d      = 1.41;          #lattice constant in Å\n",
    "theta  = 8.8;          # angle in degrees\n",
    "n      = 1;\n",
    "\n",
    "#calculation\n",
    "\n",
    "lamda  = (2*d*(math.sin(theta*math.pi/float(180))))/float(n);     #wavelength in Å\n",
    "\n",
    "\n",
    "#result\n",
    "print'wavelength=%3.3f'%lamda,'Å';"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example 1.12,Page No:1.21"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wavelength =0.7822 Å\n",
      "glancing angle =18.2 °\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "d         = 2.5;            #spacing in angstroms\n",
    "theta     = 9;              #glancing angle in degrees\n",
    "n1        = 1;\n",
    "n2        = 2;\n",
    "\n",
    "\n",
    "#calculation\n",
    "lamda      = (2*math.sin(theta*(math.pi/180))*d);     #wavelength Å\n",
    "theta      = math.asin((2*lamda)/float(2*d));         #glancing angle in °\n",
    "\n",
    "#result\n",
    "print'wavelength =%3.4f'%lamda,'Å';\n",
    "print'glancing angle =%3.1f'%(theta*(180/math.pi)),'°';\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example 1.13,Page No:1.21"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "lattice constant=1.15 Å\n",
      "note:printing mistake in textbook in calculation part,n value is printed as 2\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#variable declaration\n",
    "lamda      = 2;                     #wavelength in angstroms\n",
    "theta1     = 60;                    #angle in degrees\n",
    "n          = 1;\n",
    " \n",
    "#formula\n",
    "#2*d*math.sin(theta)=n*lamda\n",
    "#calculation\n",
    "d  = (n*lamda)/(2*math.sin(theta1*math.pi/float(180)));      #lattice constant in Å\n",
    "\n",
    "#result\n",
    "print'lattice constant=%3.2f'%d,'Å';\n",
    "print'note:printing mistake in textbook in calculation part,n value is printed as 2';"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example 1.14,Page No:1.21"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "angle=37.32 °\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#variable declaration\n",
    "lamda      = 1.4*10**-10;              #wavelength in angstroms\n",
    "a          = 2*10**-10;                #lattice parameter in angstroms\n",
    "h          = 1;                #miller indices\n",
    "k          = 1;                #miller indices\n",
    "l          = 1;                #miller indices\n",
    "n         = 1;\n",
    "#formula\n",
    "#2*d*math.sin(theta)=n*lamda\n",
    "\n",
    "#calculation\n",
    "\n",
    "dhkl       = a/float(math.sqrt((h**2)+(k**2)+(l**2)));         #inter planar spacing\n",
    "theta      = math.asin((n*lamda)/float(2*dhkl));               #angle  in °\n",
    "\n",
    "#result\n",
    "print'angle=%3.2f'%(theta*(180/float(math.pi))),'°';"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example 1.15,Page No:1.22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wavelength of neutron =7.33e+02 m/n\n",
      " Note:calculation mistake in text book in calculating wavelength \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#variabledeclaration\n",
    "d         = 3.84 *10**-10;       #spacing between planes in m\n",
    "theta     = 45;                  #glancing angle in  degrees\n",
    "m         = 1.67*10**-27;        #mass ef electron\n",
    "h         = 6.62*10**-34;        #planck's constant\n",
    "n         = 1;                  #braggg reflextion \n",
    "v         = 5.41*10**-10;\n",
    " \n",
    "#calculation\n",
    "#lamda = 2*d*(1/math.sqrt(2));\n",
    "lamda = (n*h)/float(m*v);               #wavelength of neutron\n",
    "\n",
    "#result\n",
    "print'wavelength of neutron =%3.2e'%lamda,'m/n';\n",
    "print' Note:calculation mistake in text book in calculating wavelength ';"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example 1.16,Page No:1.22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "lattice parameter =  2 Å\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "#variable declaration\n",
    "m      = 9.1*10**-31;       # mass of electron in kilograms\n",
    "e      = 1.6*10**-19;       #charge of  electron in coulombs\n",
    "n      = 1;                 #bragg's reflection\n",
    "h1     = 6.62*10**-34;      #planck's constant J.s\n",
    "n     = 1;                  #bragg reflecton \n",
    "V      = 200;               #voltage in V\n",
    "theta  = 22;                #observed reflection\n",
    " \n",
    "#calculation\n",
    "\n",
    "lamda      = h1/math.sqrt(2*m*e*V);\n",
    "dhkl       = (n*lamda)/float(2*math.sin(theta*math.pi/180));\n",
    "a         = dhkl*math.sqrt(3);                               #lattice parameter in Å\n",
    "  \n",
    "#result\n",
    " \n",
    "print'lattice parameter =%3.0f'%(a*10**10),'Å';"
   ]
  }
 ],
 "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.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}