{
 "metadata": {
  "name": "",
  "signature": "sha256:ac0a66c98f2095bc3ebf2778dcd991b562e3ba004b2f051bfaa777d8205d2aed"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 7: The Hydrogen Atom"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.2, Page 248"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import scipy\n",
      "import math\n",
      "from scipy.integrate import quad\n",
      "\n",
      "#Variable declaration\n",
      "a0 = 1;    # For simplicity assume Bohr radius to be unity, m\n",
      "\n",
      "#Calculations&Results\n",
      "x = lambda r:r**4*math.exp(-r/a0)\n",
      "int1,err = scipy.integrate.quad(x,0,15)\n",
      "y = lambda t:math.sin(t)**3\n",
      "int2,err = scipy.integrate.quad(y,0,math.pi)\n",
      "z = lambda p:p**0\n",
      "int3,err = scipy.integrate.quad(z,0,2*math.pi)\n",
      "NE = 1./(64*math.pi*a0**5)*int1*int2*int3;\n",
      "print \"NE = %.f\"%NE\n",
      "if round(NE) == 1:\n",
      "    print \"The hydrogen wave function is normalized\"\n",
      "else:\n",
      "    print \"The hydrogen wave function is not normalized\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "NE = 1\n",
        "The hydrogen wave function is normalized\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.4, Page 252"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "n = 3;    # Principal quantum number\n",
      "\n",
      "#Calculations&Results\n",
      "Total = 0;\n",
      "print (\"\\nn    l    m_l               2(l + 1)\");\n",
      "print (\"\\n------------------------------------\");\n",
      "for l in range(0,n):\n",
      "    print (\"\\n%d\"% n),\n",
      "    print (\"    %d    \"% l),\n",
      "    if l > 0:\n",
      "        count = 0;\n",
      "        for m_l in range(-l,l+1):\n",
      "            print (\"%2d \"% m_l),\n",
      "            count = count + 1;\n",
      "\n",
      "        if  l == 1:\n",
      "            print(\"      \"),\n",
      "        else:\n",
      "            print(\"\"),\n",
      "\n",
      "    else :\n",
      "        m_l = 0;\n",
      "        count = 0;\n",
      "        print(\"%2d             \"% m_l),\n",
      "        count = count + 1;\n",
      "\n",
      "    print(\"      %d\"% count),\n",
      "    Total = Total + count;\n",
      "\n",
      "print(\"\\n                                 Total = %d\"% Total);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "n    l    m_l               2(l + 1)\n",
        "\n",
        "------------------------------------\n",
        "\n",
        "3     0      0                    1 \n",
        "3     1     -1   0   1               3 \n",
        "3     2     -2  -1   0   1   2         5 \n",
        "                                 Total = 9\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.7, Page 256"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "e = 1.602e-019;    # Charge on an electron, C\n",
      "h = 6.62e-034;    # Planck's constant, Js\n",
      "h_bar = h/(2*math.pi);    # Reduced Planck's constant, Js\n",
      "m = 9.11e-031;    # Electron mass, kg\n",
      "B = 2.00;    # External magnetic field, T\n",
      "m_l1 = 0;    # Lower orbital magnetic quantum number\n",
      "m_l2 = 1;    # Upper orbital magnetic quantum number\n",
      "\n",
      "#Calculations\n",
      "delta_m_l = m_l2 - m_l1;    # Change in m_l\n",
      "mu_B = e*h_bar/(2*m);    # Bohr's magneton, J/T\n",
      "delta_E = mu_B*B*delta_m_l/e;    # Energy difference between components of p states of atomic hydrogen placed in the external field, eV\n",
      "\n",
      "#Results\n",
      "print \"The value of Bohr magneton = %4.2e J/T\"%mu_B\n",
      "print \"The energy difference between components of p states of atomic hydrogen placed in the external field = %4.2e eV\"%delta_E"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of Bohr magneton = 9.26e-24 J/T\n",
        "The energy difference between components of p states of atomic hydrogen placed in the external field = 1.16e-04 eV\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.8, Page 257"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "m = 1.67e-027;    # Mass of the proton, kg\n",
      "k = 1.38e-023;    # Boltzmann constant, J/K\n",
      "T = 663;    # Temperature of the discharge tube, K\n",
      "\n",
      "#Calculations\n",
      "v_x = math.sqrt(3*k*T/m);    # Average speed of the hydrogen atom\n",
      "mu_z = 9.27e-024;    # Bohr's magneton, J/T\n",
      "B_grad = 1240;    # Magnetic field gradient, T/m\n",
      "delta_x = 0.03;    # Length of the homogeneous magnetic field, m\n",
      "d = 1/(2*m)*(mu_z*B_grad)*(delta_x/v_x)**2;    # Separation of the atomic beam, m\n",
      "\n",
      "#Result\n",
      "print \"The separation of the atomic beam = %4.2f mm\"%(d/1e-003)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The separation of the atomic beam = 0.19 mm\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.9, Page 259"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "n = 4;    # Principal quantum number\n",
      "l = 2;    # For 4d-state\n",
      "\n",
      "#Calculations&Results\n",
      "print \"\\nn    l         m_l             m_s\"\n",
      "print \"\\n------------------------------------------\"\n",
      "count = 0;\n",
      "for m_l in range(-l,3):\n",
      "    if (m_l == 0):\n",
      "        print \"%d\\t\"%n,\n",
      "        print \" %d\"%l,\n",
      "        print \"     %d       \"%m_l,\n",
      "        print \"     +1./2, -1./2\"\n",
      "    else:    \n",
      "        print \"               %2d\"%m_l,\n",
      "        print \"            +1./2, -1./2\"\n",
      "    count = count + 2;\n",
      "     \n",
      "print \"Total No. of different states for 4d level of atomic hydrogen = %d\"%count\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "n    l         m_l             m_s\n",
        "\n",
        "------------------------------------------\n",
        "               -2             +1./2, -1./2\n",
        "               -1             +1./2, -1./2\n",
        "4\t 2      0             +1./2, -1./2\n",
        "                1             +1./2, -1./2\n",
        "                2             +1./2, -1./2\n",
        "Total No. of different states for 4d level of atomic hydrogen = 10\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.10, Page 263"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "def check_allowance(dn, dl, dml, dms):\n",
      "    if (dl == -1 or dl == 1 or dml == -1 or dml == 0 or dml == 1 or dms == -1 or dms == 0 or dms == 1) and dl != 0:\n",
      "        return 1;\n",
      "    else:\n",
      "        return 0;\n",
      "\n",
      "\n",
      "state = [[2, 0, 0, 1./2],[ 3, 1, 1, 1./2],[ 2, 0, 0, 1./2],[ 3, 0, 0, 1./2],[ 4, 2, -1, -1./2],[ 2, 1, 0, 1./2]];\n",
      "for i in range(0,5,2):\n",
      "    flag = 0; \n",
      "    d_n = state[i][0] - state[i+1][0];\n",
      "    d_l = state[i][1] - state[i+1][1];\n",
      "    d_m_l = state[i][2] - state[i+1][2];\n",
      "    d_m_s = state[i][3] - state[i+1][3];\n",
      "    flag = check_allowance(d_n, d_l, d_m_l, d_m_s);\n",
      "    if flag == 1:\n",
      "        print(\"\\n\\nThe transition (%d,%d,%d,1/%d) --> (%d,%d,%d,1/%d) is allowed\"%( state[i][0], state[i][1], state[i][2], state[i][3]*4, state[i+1][0], state[i+1][1], state[i+1][2], state[i+1][3]*4))\n",
      "        delta_E = -13.6*(1./state[i+1][0]**2-1./state[i][0]**2);\n",
      "        print(\"The energy of this transition is %4.2f eV\"% delta_E);\n",
      "    else:\n",
      "        print(\"\\n\\nThe transition (%d,%d,%d, %d)--> (%d,%d,%d,%d) is not allowed\"%(state[i][0], state[i][1], state[i][2], state[i][3], state[i+1][0], state[i+1][1], state[i+1][2], state[i+1][3]))\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "The transition (2,0,0,1/2) --> (3,1,1,1/2) is allowed\n",
        "The energy of this transition is 1.89 eV\n",
        "\n",
        "\n",
        "The transition (2,0,0, 0)--> (3,0,0,0) is not allowed\n",
        "\n",
        "\n",
        "The transition (4,2,-1,1/-2) --> (2,1,0,1/2) is allowed\n",
        "The energy of this transition is -2.55 eV\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.13, Page 266"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import scipy\n",
      "from scipy.integrate import quad\n",
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "a0 = 1;    # For simplicity assume bohr radius to be unity\n",
      "\n",
      "#Calculations\n",
      "p = lambda r: 4/a0**3*math.exp(-2*r/a0)*r**2\n",
      "P,err = scipy.integrate.quad(p, a0, 10);\n",
      "\n",
      "#Result\n",
      "print \"The probability of the electron in the 1s state of the hydrogen atom = %4.2f\"%P"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The probability of the electron in the 1s state of the hydrogen atom = 0.68\n"
       ]
      }
     ],
     "prompt_number": 10
    }
   ],
   "metadata": {}
  }
 ]
}