Exercise 1

Read and parse the chemical reactions .xml input file rxns.xml.

  1. Collect the species into a species list. My output is ['H', 'O', 'OH', 'H2', 'O2'].

    Some notes and hints:

    • Hint: For this .xml format you should have a loop over the phase element.
    • Hint: You can use the find() method to get the species array.
  2. Calculate and print out the Arrhenius reaction rate coefficients using $R = 8.314$ and $T = 1500$.

    Some notes and hints:

    • Hint: For this .xml format you should have loops over the reactionData element, the reaction element, the rateCoeff element, and the Arrhenius element using the findall() method discussed in lecture.
    • Hint: You can use the find() method to get the reaction rate coefficients.
    • My solution is:

      k for reaction01 = 6.8678391864294477e+05 k for reaction02 = 2.3105559199959813e+06


In [6]:
import xml.etree.ElementTree as ET
tree=ET.parse("rxns.xml")
elementroot=tree.getroot()

In [18]:
elements=elementroot.find('phase').find("speciesArray").text.strip(" ").split(" ")
print(elements)


['H', 'O', 'OH', 'H2', 'O2']

In [25]:
reactionroot=elementroot.find("reactionData")
for reaction in reactionroot:
    coefficients=reaction.find("rateCoeff").find("Arrhenius")
    a=float(coefficients.find("A").text)
    b=float(coefficients.find("b").text)
    e=float(coefficients.find("E").text)
    print("k=",a*T**b*math.exp(-e/(R*T)))


k= 686783.9186429448
k= 2310555.9199959813

In [ ]: