{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 4: Crystal Physics "
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.1, Page 113"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import sqrt\n",
      "\n",
      "#Variable Declaration\n",
      "r=1.278*1e-8 ;#atomic radius in cm\n",
      "M=63.5; #atomic weight\n",
      "N=6.023*1e23; #avogadro number\n",
      "n=4#for fcc n=4\n",
      "\n",
      "#Calculations\n",
      "a=4*r/(sqrt(2));\n",
      "density=n*M/(N*a**3);#Density of copper\n",
      "\n",
      "#Result\n",
      "print 'Density of copper =',round(density,1),'g/cc'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Density of copper = 8.9 g/cc\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.2, Page 113"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable Declaration\n",
      "M=58.45;#atomic mass\n",
      "N=6.02*1e23;#avogadro number\n",
      "density=2.17*1e3 ; #in kg/m^3\n",
      "n=4 #Nacl is FCC\n",
      "\n",
      "#Calculation\n",
      "a=(n*M/(N*density))**(1./3);#lattice constant\n",
      "\n",
      "#Result\n",
      "print 'lattice constant = ',round(a/1e-10,2),'A'\n",
      "#incorrect answer in the textbook\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "lattice constant =  56.35 A\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.3, Page 126"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable Declaration\n",
      "#let three intercepts are I1,I2,I3\n",
      "I1=3;\n",
      "I2=-2;\n",
      "I3=3./2;\n",
      "#let their reciprocals are I1_1,I2_1,I3_1\n",
      "I1_1=1./I1;\n",
      "I2_1=1./I2;\n",
      "I3_1=1./I3;\n",
      "\n",
      "#Calculations\n",
      "#LCM of I1_1,I2_1,I3_1 are 6 . \n",
      "#By multiply LCM with I1_1,I2_1,I3_1 we will get miller indices\n",
      "LCM=6;\n",
      "M_1=LCM*I1_1;\n",
      "M_2=LCM*I2_1 ;\n",
      "M_3=LCM*I3_1;\n",
      "\n",
      "#Results\n",
      "print 'Miller indices of plane are [',M_1,\n",
      "print(M_2),\n",
      "print(M_3),']'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Miller indices of plane are [ 2.0 -3.0 4.0 ]\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.4, Page 126"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import sqrt\n",
      "\n",
      "#Variable Declaration\n",
      "r=1.246 #in A\n",
      "\n",
      "#Calculations & Results\n",
      "a=4*r/sqrt(2)\n",
      "d_200=a/sqrt(2**2+0**2+0**2)\n",
      "print 'd200 = ',round(d_200,2),'A'\n",
      "d_220=a/sqrt(2**2+2**2+0**2)\n",
      "print 'd220 = ',d_220,'A'\n",
      "d_111=a/sqrt(1**2+1**2+1**2)\n",
      "print 'd111 = ',round(d_111,2),'A'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "d200 =  1.76 A\n",
        "d220 =  1.246 A\n",
        "d111 =  2.03 A\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.5, Page 127"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import acos,degrees\n",
      "\n",
      "#Variable Declaration\n",
      "h=1\n",
      "k=1\n",
      "l=1\n",
      "h1=1\n",
      "k1=1\n",
      "l1=1\n",
      "\n",
      "#Calculations\n",
      "a=((h*h1)-(k*k1)+(l*l1))/(sqrt((h*h)+(k*k)+(l*l))*sqrt((h1*h1)+(k1*k1)+(l1*l1)));\n",
      "#cosine angle=a so angle=cosine inverse of a\n",
      "theta=degrees(acos(a));#angle between two planes\n",
      "\n",
      "#Result\n",
      "print 'angle between two planes =',round(theta,2),'degrees'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "angle between two planes = 70.53 degrees\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.6, Page 127"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable Declaration\n",
      "a=2.9*1e-8; #in cm\n",
      "M=55.85;#atomic mass\n",
      "density=7.87 #in g/cc\n",
      "N=6.023*1e23;\n",
      "\n",
      "#Calculations\n",
      "n=(a**3*N*density)/M;#Number of atoms per unit cell\n",
      "\n",
      "#Result\n",
      "print 'Number of atoms per unit cell =',round(n,3)\n",
      "#Incorrect answer in the textbook\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Number of atoms per unit cell = 2.07\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.7, Page 127"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import sqrt\n",
      "\n",
      "#Variable Declaration\n",
      "M=55.85;#atomic mass\n",
      "d=7.86 #density of iron in g/cc\n",
      "N=6.023*1e23\n",
      "n=2#BCC structure\n",
      "\n",
      "#Calculations\n",
      "a=((n*M)/(N*d))**(1./3);\n",
      "r=(sqrt(3)*a)/4;#radius of iron atom \n",
      "\n",
      "#Result\n",
      "print 'radius of iron atom =',round(r/1e-10,3),'A'\n",
      "#Incorrect answer in the textbook"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "radius of iron atom = 124.196 A\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.8, Page 128"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import sqrt\n",
      "\n",
      "#Variable Declaration\n",
      "M=207.21;#atomic mass\n",
      "d=11.34*1e3 #in kg/m^3\n",
      "N=6.023*1e26 #in kg/m^3\n",
      "n=4;#for FCC\n",
      "\n",
      "#Calculations\n",
      "a=((n*M)/(N*d))**(1./3);#lattice constant\n",
      "r=(sqrt(2)*a)/4;#Atomic radius\n",
      "\n",
      "#Result\n",
      "print 'lattice constant =',round(a/1e-10,2),'A'\n",
      "print 'Atomic radius =',round(r/1e-10,2),'A'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "lattice constant = 4.95 A\n",
        "Atomic radius = 1.75 A\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.9, Page 128"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import sqrt,sin,degrees,radians,pi\n",
      "\n",
      "#Variable Declaration\n",
      "n=1;\n",
      "theta=30;#angle in degree\n",
      "lamda=1.75; #in A\n",
      "h=1;\n",
      "k=1;\n",
      "l=1;\n",
      "\n",
      "#Calculations\n",
      "#d111=a/sqrt((h*h)+(k*k)+(l*l))\n",
      "#2dsin(thita)=n*lamda\n",
      "d=n*lamda/(2*sin(theta*pi/180))\n",
      "a=sqrt(3)*d;#lattice constant \n",
      "\n",
      "#Result\n",
      "print \"lattice constant =\",round(a,3),'A'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "lattice constant = 3.031 A\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.10, Page 129"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable Declaration\n",
      "#let three intercepts are I1,I2,I3\n",
      "I1=0.96;\n",
      "I2=0.64;\n",
      "I3=0.48;\n",
      "\n",
      "#Calculations\n",
      "#as they are ratios we will multiply by some some constants so that  it will become integers\n",
      "I1=6;\n",
      "I2=4;\n",
      "I3=3 ;\n",
      "#let their reciprocals are I1_1,I2_1,I3_1\n",
      "I1_1=1./I1;\n",
      "I2_1=1./I2;\n",
      "I3_1=1./I3;\n",
      "#LCM of I1_1,I2_1,I3_1 are 12. \n",
      "#By multiply LCM with I1_!,I2_1,I3_1 we will get miller indices\n",
      "LCM=12;\n",
      "M_1=LCM*I1_1;\n",
      "M_2=LCM*I2_1 ;\n",
      "M_3=LCM*I3_1;\n",
      "\n",
      "#Results\n",
      "print 'Miller indices of plane are [',M_1,\n",
      "print(M_2),\n",
      "print(M_3),']'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Miller indices of plane are [ 2.0 3.0 4.0 ]\n"
       ]
      }
     ],
     "prompt_number": 12
    }
   ],
   "metadata": {}
  }
 ]
}