<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Simulating Batch Reactor
Here a batch reactor simulation is demoed with pure gas phase mechanism. The gas phase mechanims is called GRI-Mech v3.0 from University of Berkeley. GRI-Mech 3.0 is an optimized mechanism designed to model natural gas combustion, including NO formation and reburn chemistry. The mechanims consists of 53 species and 325 reactions. For more details, refer to http
Step1:  1. Adiabatic batch reactor
Under adiabatic conditions, no heat is supplied/taken from the reactor. The temperature within the reactor is allowed to change. We try to understand the detonation process via the mole fractions of the reactants, products, and intermediates.
Diagnostic data Files
First lets look at the diagnostic files with .out extension.  These files have .out extension. 
species.out
Step2:  Data Files
The files are given as _ss.csv and _tr.csv or _ss.dat and _tr.dat depending on the output format selected. _tr indicates transient output, and _ss indicates steady state.
gas_mass_, gas_mole_
Step3:  Reactor State Comparison
How do the reactor temperature and pressure evolve for the two different operating conditions?
<ASSISTANT_TASK:>
Python Code:
import matplotlib as mpl
mpl.rcParams['figure.dpi'] = 500
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline 
%config InlineBackend.figure_format = 'retina'
Explanation: Simulating Batch Reactor
Here a batch reactor simulation is demoed with pure gas phase mechanism. The gas phase mechanims is called GRI-Mech v3.0 from University of Berkeley. GRI-Mech 3.0 is an optimized mechanism designed to model natural gas combustion, including NO formation and reburn chemistry. The mechanims consists of 53 species and 325 reactions. For more details, refer to http://combustion.berkeley.edu/gri-mech/version30/text30.html.
For this demo, we are interested in Hydrogen detonation in a batch reactor under different operating conditions. The conventional overall reaction is written as 2H<sub>2</sub> + O<sub>2</sub> = 2H<sub>2</sub>O.   
Note: The actual simulations are executed from command line. In the jupyter notebook, analysis of the resulting data is carried out.
End of explanation
ls adiab/*.out
def read_file(fname):
    with open(fname) as fp:
        lines = fp.readlines()
        for line in lines:
            print(line)
read_file("adiab/kf.out")
Explanation: 1. Adiabatic batch reactor
Under adiabatic conditions, no heat is supplied/taken from the reactor. The temperature within the reactor is allowed to change. We try to understand the detonation process via the mole fractions of the reactants, products, and intermediates.
Diagnostic data Files
First lets look at the diagnostic files with .out extension.  These files have .out extension. 
species.out: Lists the species participating in the mechanism, phase and the composition
Hform.out, Sform.out: Formation enthalpy and entropy of species
reactions.out: List of reactions
Hrxn.out, Srxn.out, Grxn.out: Enthalpy, entropy, and Gibbs energies of reactions
kc.out, kf.out, kr.out: Equilibrium constant, forward and reverse rate constants.
End of explanation
ls adiab/*.csv
df = pd.read_csv(os.path.join('adiab', 'gas_mole_tr.csv'))
df.columns = df.columns.str.strip()
df["t_ms"] = df["t(s)"]*1e3
plt.clf()
ax1 = plt.subplot(1, 1, 1)
ax1.plot('t_ms',  'H', data=df, marker='^', markersize=0.5, label="H mole frac")
ax1.plot('t_ms',  'OH', data=df, marker='v', markersize=0.5, label="OH mole frac")
ax1.plot('t_ms',  'H2O', data=df, marker='*', markersize=0.5, label="H2O mole frac")
ax1.plot('t_ms',  'H2', data=df, marker='o', markersize=0.5, label="H2 mole frac")
ax1.plot('t_ms',  'O2', data=df, marker='<', markersize=0.5, label="O2 mole frac")
ax1.set_xlabel('Time (ms)')
ax1.ticklabel_format(axis='y', style='sci', scilimits=(0,0))
ax1.set_ylabel('Mass Fraction')
#ax1.set_xlim([0,1])
ax1.legend(loc="upper left", bbox_to_anchor=(1,1))
plt.tight_layout()
plt.savefig('GRI30_Hdetonation_adiab_mole.png', dpi=500)
plt.clf()
ax1 = plt.subplot(1, 1, 1)
ax1.plot('t_ms',  'H', data=df, marker='^', markersize=0.5, label="H mole frac")
ax1.plot('t_ms',  'OH', data=df, marker='v', markersize=0.5, label="OH mole frac")
ax1.plot('t_ms',  'H2O', data=df, marker='*', markersize=0.5, label="H2O mole frac")
ax1.plot('t_ms',  'H2', data=df, marker='o', markersize=0.5, label="H2 mole frac")
ax1.plot('t_ms',  'O2', data=df, marker='<', markersize=0.5, label="O2 mole frac")
ax1.set_xlabel('Time (ms)')
ax1.ticklabel_format(axis='y', style='sci', scilimits=(0,0))
ax1.set_ylabel('Mass Fraction')
#ax1.set_xlim([0,1])
ax1.legend(loc="upper left", bbox_to_anchor=(1,1))
ax1.set_xlim(0.25,0.4)
plt.tight_layout()
plt.savefig('GRI30_Hdetonation_adiab_mole_zoomed.png', dpi=500)
df_isothermal = pd.read_csv(os.path.join('isother', 'gas_mole_tr.csv'))
df_isothermal.columns = df_isothermal.columns.str.strip()
df_isothermal["t_ms"] = df_isothermal["t(s)"]*1e3
plt.clf()
ax = plt.subplot(1, 1, 1)
ax.plot('t_ms',  'H', data=df, marker='^', markersize=0.5, label="H mole frac")
ax.plot('t_ms',  'OH', data=df, marker='v', markersize=0.5, label="OH mole frac")
ax.plot('t_ms',  'H2O', data=df, marker='*', markersize=0.5, label="H2O mole frac")
ax.plot('t_ms',  'H2', data=df, marker='o', markersize=0.5, label="H2 mole frac")
ax.plot('t_ms',  'O2', data=df, marker='<', markersize=0.5, label="O2 mole frac")
ax.set_xlabel('Time (ms)')
ax.ticklabel_format(axis='y', style='sci', scilimits=(0,0))
ax.set_ylabel('Mass Fraction')
ax.set_xlim(0.25,0.4)
#ax1.set_xlim([0,1])
ax.legend(loc="upper left", bbox_to_anchor=(1,1))
plt.tight_layout()
plt.savefig('GRI30_H-detonation_isother_mole.png', dpi=500)
Explanation: Data Files
The files are given as _ss.csv and _tr.csv or _ss.dat and _tr.dat depending on the output format selected. _tr indicates transient output, and _ss indicates steady state.
gas_mass_, gas_mole_: Lists the mass fraction and mole fractions of gas phase species respectively
gas_msdot_: Production rate of the gas space species from the surface.
surf_cov_: Coverages of the surface species
rctr_state: State of the reactor (Temperature, Pressure, Density, Internal Energy)
End of explanation
adiab_state_df = pd.read_csv(os.path.join('adiab','rctr_state_tr.csv'))
isotherm_state_df = pd.read_csv(os.path.join('isother','rctr_state_tr.csv'))
adiab_state_df.columns = adiab_state_df.columns.str.strip()
isotherm_state_df.columns = isotherm_state_df.columns.str.strip()
isotherm_state_df["t_ms"] = isotherm_state_df["t(s)"]*1e3
adiab_state_df["t_ms"] = adiab_state_df["t(s)"]*1e3
plt.clf()
ax_comp = plt.subplot(1, 1, 1)
ax_comp.plot('t_ms',  'Temperature(K)', data=isotherm_state_df, marker='^', markersize=0.5, label="Isothermal T")
ax_comp.plot('t_ms',  'Temperature(K)', data=adiab_state_df, marker='v', markersize=0.5, label="Adiabatic T")
ax_comp.set_xlabel('Time (ms)')
ax_comp.ticklabel_format(axis='y', style='sci', scilimits=(0,0))
ax_comp.set_ylabel('Temp (K)')
ax_comp.set_ylim([500,3000])
ax_comp.legend(loc="upper left", bbox_to_anchor=(1,1))
plt.tight_layout()
plt.savefig('GRI30_H-detonation_T-comp.png', dpi=500)
plt.clf()
ax_comp = plt.subplot(1, 1, 1)
ax_comp.plot('t_ms',  'Pressure(Pa)', data=isotherm_state_df, marker='^', markersize=0.5, label="Isothermal T")
ax_comp.plot('t_ms',  'Pressure(Pa)', data=adiab_state_df, marker='v', markersize=0.5, label="Adiabatic T")
ax_comp.set_xlabel('Time (ms)')
ax_comp.ticklabel_format(axis='y', style='sci', scilimits=(0,0))
ax_comp.set_ylabel('Press (Pa)')
#ax_comp.set_ylim([500,3000])
ax_comp.legend(loc="upper left", bbox_to_anchor=(1,1))
plt.tight_layout()
plt.savefig('GRI30_H-detonation_P-comp.png', dpi=500)
Explanation: Reactor State Comparison
How do the reactor temperature and pressure evolve for the two different operating conditions?
End of explanation
<END_TASK>