# Path: src/core/def_tools.py
# def cond2dir(dir_desk, fuel, oxid, phi, atm, T0, reactor, d):
# 
#     comp = add_bracket(fuel) + ' + ' + add_bracket(oxid)
#     phi_str = 'phi' + str(phi)#num2str(phi, d=3)
#     atm_str = str(atm)+'atm'#num2str(atm, d) + 'atm'
#     T0_str = str(T0)+'K'#num2str(T0, d) + 'K'
#     return os.path.join(dir_desk,'raw', comp, reactor, phi_str+'_'+atm_str+'_'+T0_str)
# 
# def keys_sorted(dictionary, n_top=None):
#     import heapq
#     if n_top is None:
#         n_top = len(dictionary.keys())
#     else:
#         n_top = int(n_top)
#     return heapq.nlargest(n_top, dictionary, key = lambda k:dictionary[k])
# 
# Path: src/ct/def_ct_tools.py
# def load_raw(path_raw):
#     raw_file = np.load(open(path_raw, 'rb'))
#     raw = dict()
#     for key in raw_file.keys():
#         if key in ['mole_fraction','net_reaction_rate']:
#             raw[key] = np.matrix(raw_file[key])
#         else:
#             raw[key] = raw_file[key]
#     return raw
# 
# Path: src/gui/def_run.py
# def load_dR(path_save, soln, overwrite=False):
# 
# 	if overwrite == False:
# 		if os.path.exists(path_save):
# 			npz_file = np.load(open(path_save, 'rb'))
# 			npz = dict()
# 			for key in npz_file.keys():
# 				npz[key] = npz_file[key]
# 			return npz['dnR']
# 
# 	R = []
# 	sp_list = soln.species_names
# 	R_cand = ['O','H','OH']
# 	for R_cand_i in R_cand:
# 		if R_cand_i in sp_list:
# 			R.append(R_cand_i)
# 		elif R_cand_i.lower() in sp_list:
# 			R.append(R_cand_i.lower())
# 
# 
# 	rxn = soln.reaction
# 	dnR = []
# 	for id_rxn in range(soln.n_reactions):
# 		reactants = rxn(id_rxn).reactants.keys()
# 		products = rxn(id_rxn).products.keys()
# 
# 		dnR_i = 0
# 		for R_i in R:
# 			if R_i in reactants:
# 				dnR_i -= rxn(id_rxn).reactants[R_i]
# 			if R_i in products:
# 				dnR_i += rxn(id_rxn).products[R_i]
# 
# 		dnR.append(dnR_i)
# 
# 	np.savez(path_save,dnR=dnR)
# 	return dnR


import sys
import os
import cantera as ct
import json
import time
import copy
import matplotlib.pyplot as plt
import sys
import os
import cantera as ct
import json
import time
import copy
import numpy as np
		import matplotlib.ticker as mtick
from networkx.readwrite import json_graph
from src.core.def_tools import cond2dir, keys_sorted
from src.core.def_GPSA import *
from src.ct.def_ct_tools import load_raw
from src.gui.def_run import load_dR
from PyQt4 import uic
from PyQt4.QtGui import * 
from PyQt4.QtCore import * 
from def_plt_tools import *
		if bool(xlim):
			minx = xlim[0]
			x_txt = xlim[0] + 0.05*(xlim[1] - xlim[0])
		else:
			minx = 0
			x_txt = 0


	n_rxn = int(opt['n_rxn'][0])
	dy = 0.8/(1+n_rxn)

	for i_edge in range(len(edges)):
		edge = edges[i_edge]
		A,B = edge.split('.')[1].strip().replace('-->',',').split(',')
		txt0 = rename_species(A, rename) + r' $\rightarrow$ ' + rename_species(B, rename)
		

		c_list = []
		txt_list = []


		c_list.append(data[edge]['net'][i_plot])
		txt_list.append(txt0)


		mm = data[edge]['member'][i_plot]
		mm_abs = dict()
		for id_rxn_s in mm.keys():
			mm_abs[id_rxn_s] = abs(mm[id_rxn_s])


# Path: src/core/def_tools.py
# def cond2dir(dir_desk, fuel, oxid, phi, atm, T0, reactor, d):
# 
#     comp = add_bracket(fuel) + ' + ' + add_bracket(oxid)
#     phi_str = 'phi' + str(phi)#num2str(phi, d=3)
#     atm_str = str(atm)+'atm'#num2str(atm, d) + 'atm'
#     T0_str = str(T0)+'K'#num2str(T0, d) + 'K'
#     return os.path.join(dir_desk,'raw', comp, reactor, phi_str+'_'+atm_str+'_'+T0_str)
# 
# def keys_sorted(dictionary, n_top=None):
#     import heapq
#     if n_top is None:
#         n_top = len(dictionary.keys())
#     else:
#         n_top = int(n_top)
#     return heapq.nlargest(n_top, dictionary, key = lambda k:dictionary[k])
# 
# Path: src/ct/def_ct_tools.py
# def load_raw(path_raw):
#     raw_file = np.load(open(path_raw, 'rb'))
#     raw = dict()
#     for key in raw_file.keys():
#         if key in ['mole_fraction','net_reaction_rate']:
#             raw[key] = np.matrix(raw_file[key])
#         else:
#             raw[key] = raw_file[key]
#     return raw
# 
# Path: src/gui/def_run.py
# def load_dR(path_save, soln, overwrite=False):
# 
# 	if overwrite == False:
# 		if os.path.exists(path_save):
# 			npz_file = np.load(open(path_save, 'rb'))
# 			npz = dict()
# 			for key in npz_file.keys():
# 				npz[key] = npz_file[key]
# 			return npz['dnR']
# 
# 	R = []
# 	sp_list = soln.species_names
# 	R_cand = ['O','H','OH']
# 	for R_cand_i in R_cand:
# 		if R_cand_i in sp_list:
# 			R.append(R_cand_i)
# 		elif R_cand_i.lower() in sp_list:
# 			R.append(R_cand_i.lower())
# 
# 
# 	rxn = soln.reaction
# 	dnR = []
# 	for id_rxn in range(soln.n_reactions):
# 		reactants = rxn(id_rxn).reactants.keys()
# 		products = rxn(id_rxn).products.keys()
# 
# 		dnR_i = 0
# 		for R_i in R:
# 			if R_i in reactants:
# 				dnR_i -= rxn(id_rxn).reactants[R_i]
# 			if R_i in products:
# 				dnR_i += rxn(id_rxn).products[R_i]
# 
# 		dnR.append(dnR_i)
# 
# 	np.savez(path_save,dnR=dnR)
# 	return dnR


# Path: src/post/def_painter.py
import sys
import os
import cantera as ct
import json
import time
import copy
import matplotlib.pyplot as plt
import sys
import os
import cantera as ct
import json
import time
import copy
import numpy as np
		import matplotlib.ticker as mtick
from networkx.readwrite import json_graph
from src.core.def_tools import cond2dir, keys_sorted
from src.core.def_GPSA import *
from src.ct.def_ct_tools import load_raw
from src.gui.def_run import load_dR
from PyQt4 import uic
from PyQt4.QtGui import * 
from PyQt4.QtCore import * 
from def_plt_tools import *

		if bool(xlim):
			minx = xlim[0]
			x_txt = xlim[0] + 0.05*(xlim[1] - xlim[0])
		else:
			minx = 0
			x_txt = 0


	n_rxn = int(opt['n_rxn'][0])
	dy = 0.8/(1+n_rxn)

	for i_edge in range(len(edges)):
		edge = edges[i_edge]
		A,B = edge.split('.')[1].strip().replace('-->',',').split(',')
		txt0 = rename_species(A, rename) + r' $\rightarrow$ ' + rename_species(B, rename)
		

		c_list = []
		txt_list = []


		c_list.append(data[edge]['net'][i_plot])
		txt_list.append(txt0)


		mm = data[edge]['member'][i_plot]
		mm_abs = dict()
		for id_rxn_s in mm.keys():
			mm_abs[id_rxn_s] = abs(mm[id_rxn_s])


		top_rxns = keys_sorted(mm_abs)