{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 7 - Principles of chemical equilibrium"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E1 - Pg 147"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the reaction gibbs energy\n",
      "#Initialization of variables\n",
      "import math\n",
      "G=-31. #kJ/mol\n",
      "T=37+273. #K\n",
      "Cadp=1/1000. #mmol/L\n",
      "Cp=8/1000. #mmol/L\n",
      "Catp=8/1000. #mmol/L\n",
      "R=8.314 #J/K mol\n",
      "#calculations\n",
      "Q=Cadp*Cp/Catp\n",
      "deltaG=G+R*T*math.log(Q) /1000.\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Reaction Gibbs energy =\",deltaG,\" kJ/mol\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Reaction Gibbs energy = -48.8  kJ/mol\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E2 - Pg 149"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the gibbs energy\n",
      "#Initialization of variables\n",
      "Hr=-285.83 #kJ/mol\n",
      "Sr=-163.34 #J/ K mol\n",
      "T=298.15 #K\n",
      "#calculations\n",
      "Gr=Hr-T*Sr/1000.\n",
      "#results\n",
      "print '%s %.2f %s' %('Gibbs energy =',Gr,'kJ/mol')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Gibbs energy = -237.13 kJ/mol\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E3 - Pg 153"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the change in gibbs energy\n",
      "#Initialization of variables\n",
      "import math\n",
      "aADP=1 #mol/L\n",
      "aP=1 #mol/L\n",
      "aATP=1 #mol/L\n",
      "aH2O=1 #mol/L\n",
      "aH=math.pow(10,-7) #mol/L\n",
      "G=10 #kJ/mol\n",
      "T=298. #K\n",
      "R=8.314 #J/K mol\n",
      "#calculations\n",
      "Q=aADP*aP*aH/(aATP*aH2O)\n",
      "Gr=G+R*T*math.log(Q)/1000.\n",
      "#results\n",
      "print '%s %.1f %s' %('Change in nGibbs energy =',Gr,'kJ/mol')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in nGibbs energy = -29.9 kJ/mol\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E4 - Pg 155"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the equivalent fration\n",
      "#Initialization of variables\n",
      "Gr=1.7*1000 #J/mol\n",
      "T=298. #K\n",
      "R=8.314 #J/K mol\n",
      "K=0.5\n",
      "#calculations\n",
      "GbyRT=Gr/(R*T)\n",
      "feq=K/(K+1)\n",
      "#results\n",
      "print '%s %.2f' %(\"Equivalent fraction = \",feq)\n",
      "print '%s' %(\"For the second part, Gr=1.7 + 2.48 ln(f/1-f)\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Equivalent fraction =  0.33\n",
        "For the second part, Gr=1.7 + 2.48 ln(f/1-f)\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example E5 - Pg 157"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the pressure of N2,H2,NH3 gases\n",
      "#Initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "species=(['N2', 'H2', 'NH3'])\n",
      "change=(['-x', '-3x', '2x'])\n",
      "E=(['1-x', '3-3x', '2x'])\n",
      "print '%s' %(\"Concentration table\")\n",
      "print '%s' %(\"species\")\n",
      "print '%s' %(\"change\")\n",
      "print(E)\n",
      "K=977.\n",
      "#Calculations\n",
      "g=math.sqrt(27*K/4.)\n",
      "vector=([g, -(2*g +1), g])\n",
      "sol=numpy.roots(vector)[1]\n",
      "\n",
      "PN2=1-sol\n",
      "PH2=3-3*sol\n",
      "PNH3=2*sol\n",
      "K=math.pow(PNH3,2)/(math.pow(PH2,3) *PN2)\n",
      "#results\n",
      "print '%s %.2f %s' %(\"Pressure of N2 gas = \",PN2,\"bar\")\n",
      "print '%s %.2f %s' %(\"\\n Pressure of H2 gas =\",PH2,\"bar\")\n",
      "print '%s %.2f %s' %(\"\\n Pressure of NH3 gas =\",PNH3,\"bar\")\n",
      "print '%s %.2e %s' %(\"\\n K final =\",K,\"> it is close to original value.\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Concentration table\n",
        "species\n",
        "change\n",
        "['1-x', '3-3x', '2x']\n",
        "Pressure of N2 gas =  0.10 bar\n",
        "\n",
        " Pressure of H2 gas = 0.31 bar\n",
        "\n",
        " Pressure of NH3 gas = 1.79 bar\n",
        "\n",
        " K final = 9.77e+02 > it is close to original value.\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example I2 - Pg 148"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the equilibrium constant\n",
      "#Initialization of variables\n",
      "import math\n",
      "Gr=-3.40 #kJ/mol\n",
      "R=8.314 #J/k mol\n",
      "T=298. #K\n",
      "#calculations\n",
      "lnK=Gr*1000./(R*T)\n",
      "K=math.exp(lnK)\n",
      "#results\n",
      "print '%s %.2f' %('Equilibrium constant K= ',K)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Equilibrium constant K=  0.25\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example I3 - Pg 149"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the decomposition temperature\n",
      "#Initialization of variables\n",
      "Hr=178. #kJ/mol\n",
      "Sr=161. #J/K mol\n",
      "#calculations\n",
      "T=Hr*1000 /Sr\n",
      "#results\n",
      "print '%s %.2e %s' %(\"Decompostion temperature =\",T,\"K\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Decompostion temperature = 1.11e+03 K\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example I4 - Pg 151"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculate the standard reaction gibbs energy\n",
      "#Initialization of variables\n",
      "GCO2=-394. #kJ/mol\n",
      "GCO=-137. #kJ/mol\n",
      "GO2=0\n",
      "#calculations\n",
      "deltaG=2*GCO2-2*GCO+GO2\n",
      "#results\n",
      "print '%s %d %s' %('Standard reaction gibbs energy =',deltaG,' kJ/mol')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Standard reaction gibbs energy = -514  kJ/mol\n"
       ]
      }
     ],
     "prompt_number": 9
    }
   ],
   "metadata": {}
  }
 ]
}