# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # 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`

import xml.etree.ElementTree as ET
tree=ET.parse("rxns.xml")
elementroot=tree.getroot()


elements=elementroot.find('phase').find("speciesArray").text.strip(" ").split(" ")
print(elements)


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)))




StarcoderdataJupyterScriptsDedupFiltered