#Calculate the reaction gibbs energy
#Initialization of variables
import math
G=-31. #kJ/mol
T=37+273. #K
Cadp=1/1000. #mmol/L
Cp=8/1000. #mmol/L
Catp=8/1000. #mmol/L
R=8.314 #J/K mol
#calculations
Q=Cadp*Cp/Catp
deltaG=G+R*T*math.log(Q) /1000.
#results
print '%s %.1f %s' %("Reaction Gibbs energy =",deltaG," kJ/mol")
#Calculate the gibbs energy
#Initialization of variables
Hr=-285.83 #kJ/mol
Sr=-163.34 #J/ K mol
T=298.15 #K
#calculations
Gr=Hr-T*Sr/1000.
#results
print '%s %.2f %s' %('Gibbs energy =',Gr,'kJ/mol')
#calculate the change in gibbs energy
#Initialization of variables
import math
aADP=1 #mol/L
aP=1 #mol/L
aATP=1 #mol/L
aH2O=1 #mol/L
aH=math.pow(10,-7) #mol/L
G=10 #kJ/mol
T=298. #K
R=8.314 #J/K mol
#calculations
Q=aADP*aP*aH/(aATP*aH2O)
Gr=G+R*T*math.log(Q)/1000.
#results
print '%s %.1f %s' %('Change in nGibbs energy =',Gr,'kJ/mol')
#Calculate the equivalent fration
#Initialization of variables
Gr=1.7*1000 #J/mol
T=298. #K
R=8.314 #J/K mol
K=0.5
#calculations
GbyRT=Gr/(R*T)
feq=K/(K+1)
#results
print '%s %.2f' %("Equivalent fraction = ",feq)
print '%s' %("For the second part, Gr=1.7 + 2.48 ln(f/1-f)")
#Calculate the pressure of N2,H2,NH3 gases
#Initialization of variables
import math
import numpy
species=(['N2', 'H2', 'NH3'])
change=(['-x', '-3x', '2x'])
E=(['1-x', '3-3x', '2x'])
print '%s' %("Concentration table")
print '%s' %("species")
print '%s' %("change")
print(E)
K=977.
#Calculations
g=math.sqrt(27*K/4.)
vector=([g, -(2*g +1), g])
sol=numpy.roots(vector)[1]
PN2=1-sol
PH2=3-3*sol
PNH3=2*sol
K=math.pow(PNH3,2)/(math.pow(PH2,3) *PN2)
#results
print '%s %.2f %s' %("Pressure of N2 gas = ",PN2,"bar")
print '%s %.2f %s' %("\n Pressure of H2 gas =",PH2,"bar")
print '%s %.2f %s' %("\n Pressure of NH3 gas =",PNH3,"bar")
print '%s %.2e %s' %("\n K final =",K,"> it is close to original value.")
#Calculate the equilibrium constant
#Initialization of variables
import math
Gr=-3.40 #kJ/mol
R=8.314 #J/k mol
T=298. #K
#calculations
lnK=Gr*1000./(R*T)
K=math.exp(lnK)
#results
print '%s %.2f' %('Equilibrium constant K= ',K)
#Calculate the decomposition temperature
#Initialization of variables
Hr=178. #kJ/mol
Sr=161. #J/K mol
#calculations
T=Hr*1000 /Sr
#results
print '%s %.2e %s' %("Decompostion temperature =",T,"K")
#Calculate the standard reaction gibbs energy
#Initialization of variables
GCO2=-394. #kJ/mol
GCO=-137. #kJ/mol
GO2=0
#calculations
deltaG=2*GCO2-2*GCO+GO2
#results
print '%s %d %s' %('Standard reaction gibbs energy =',deltaG,' kJ/mol')