示例#1
0
def Reaction_Creator(path_xml, path_sql, start=None, end=None):
    reader = xml2dict()
    reader.parse(path_xml)
    info = reader.get_info()
    species = info[0]
    reactions = [Reaction(**r) for r in info[1]]
    cq = CoeffQuery(path_sql)

    if end is None or start is None:
        rs = ReactionSystem(reactions, species, nasa_query=cq)

    else:
        rs = ReactionSystem(reactions[start:end], nasa_query=cq)

    return rs
示例#2
0
# Testing
from chemkin_CS207_G9.parser.xml2dict import xml2dict
from chemkin_CS207_G9.parser.database_query import CoeffQuery
from chemkin_CS207_G9.reaction.Reaction import Reaction
from chemkin_CS207_G9.reaction.ReactionSystem import ReactionSystem
import os
from chemkin_CS207_G9.plotting.RSGraph import RSGraph, BipartiteRSGraph, HierarchicalRSGraph
from graphviz import Digraph

# Paths
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
path_xml = os.path.join(BASE_DIR, 'rxns_reversible.xml') # path to the .xml file
path_sql = os.path.join(BASE_DIR, 'nasa_thermo.sqlite')  # path to the .sqlite file

# Loading Reactions and Species from xml file
reader = xml2dict()
reader.parse(path_xml)
info = reader.get_info()
species = info[0]
reactions = [Reaction(**r) for r in info[1]]
cq = CoeffQuery(path_sql)
rs1 = ReactionSystem(reactions[:3], nasa_query = cq)
rs2 = ReactionSystem(reactions, species_ls = species, nasa_query = cq)
rs3 = ReactionSystem(reactions[:4], nasa_query = cq)
temperature = 2500
concentrations = dict(H=2, O=1, OH=0.5, H2=1, H2O=1, O2=1)
rs1.set_temp(temperature)
rs1.set_concs(concentrations, initial=True)


def test_RSGraph():
def test_class1():
    r = xml2dict()
    print(os.listdir('.'))
    r.parse(os.path.join(BASE_DIR, 'rxns.xml'))
    assert (r.get_info()[1][1]['TYPE'] == 'Elementary')
def test_class7():
    r = xml2dict()
    r.parse(os.path.join(BASE_DIR, 'rxns2.xml'))
    assert (r.get_info()[1][2]['reversible'] == 'no')
def test_class6():
    r = xml2dict()
    r.parse(os.path.join(BASE_DIR, 'rxns2.xml'))
    assert (r.get_info()[1][2]['ID'] == 'reaction03')
def test_class5():
    r = xml2dict()
    r.parse(os.path.join(BASE_DIR, 'rxns2.xml'))
    assert (r.get_info()[1][1]['reactants'] == {'HO2': 1, 'OH': 1})
def test_class3():
    r = xml2dict()
    r.parse(os.path.join(BASE_DIR, 'rxns.xml'))
    assert (r.get_info()[1][1]['products'] == {'H': 1, 'OH': 1})
def test_class2():
    r = xml2dict()
    r.parse(os.path.join(BASE_DIR, 'rxns.xml'))
    assert (r.get_info()[0][1] == 'O')