# Path: phievo/AnalysisTools/main_functions.py
# def read_network(filename,verbose=False):
# def smoothing(array,param):
# def load_generation_data(generations,restart_file):
# def download_zip(dir_name,url):
#     def dlProgress(count, blockSize, totalSize):
# def download_tools(run_evolution="run_evolution.py",AnalyseRun="AnalyseRun.ipynb",ProjectCreator="ProjectCreator.ipynb"):
# def download_example(example_name,directory=None):
# 
# Path: phievo/AnalysisTools/palette.py
# def update_default_colormap(colormap):
# def HSL_to_RGB(h,s,l):
#     def Hue_2_RGB( v1, v2, vH ):
# def floatrange(start,stop,steps):
# def color_generate(n,colormap=None):
# def make_colormap(seq):
# def generate_gradient(values,seq):
# 
# Path: phievo/Networks/mutation.py
# T=1.0 #typical time scale
# C=1.0 #typical concentration
# L=1.0 #typical size for diffusion
#                 E_I=log(interval[1]/min_param) #range of possible energies
# def ligand_fct(random_generator):
# def build_lists(mutation_dict):
# def sample_dictionary_ranges(key,random_generator):
# def random_parameters(Types,random_generator):
# def rand_modify(self,random_generator):
#     def __init__(self,generator = random.Random()):
#     def compute_Cseed(self):
#     def random_Species(self, Type='Species'):
#     def random_Interaction(self,Interaction_Type):
#     def remove_Interaction(self,Type):
#     def random_remove_output(self):
#     def random_add_output(self):
#     def random_change_output(self):
#     def random_duplicate(self):
#     def mutate_Node(self,Type):
#     def build_mutations(self):
#         def update_dict(self,dictionary,key,name):
#     def compute_next_mutation(self):
#     def mutate_and_integrate(self,prmt,nnetwork,tgeneration,mutation=True):
# class Mutable_Network(classes_eds2.Network):
# 
# Path: phievo/Networks/classes_eds2.py
# class Node(object):
# class Species(Node):
# class TModule(Node):
# class Interaction(Node):
# class Network(object):
#     def __init__(self):
#     def __str__(self):
#     def print_node(self):
#     def isinstance(self,name):
#     def list_types(self):
#     def int_id(self):
#     def outputs_to_delete(self,net):
#     def isremovable(self,net,list_nodes_loop,verbose=False):
#     def string_param(self):
#     def __init__(self,listtypes=[]):
#     def __str__(self):
#         def cutter(arg):
#     def isinstance(self,name):
#     def list_types(self):
#     def def_label(self):
#     def clean_type(self,Type):
#     def change_type(self,Type,parameters):
#     def add_type(self,Type):
#     def __init__(self,rate=0,basal=0):
#     def __str__(self):
#     def string_param(self):
#     def __str__(self):
#     def check_grammar(self,input_list,output_list):
# def compare_node(x):
# def check_consistency(lTypes,lNodes):
#     def __init__(self):
#     def __str__(self):
#     def __repr__(self):
#     def add_Node(self, node):
#     def new_Species(self,types):
#     def number_nodes(self,Type):
#     def catal_data(self,interaction):
#     def check_existing_binary(self,list,Type):
#     def check_existing_link(self,list,Type):
#     def verify_IO_numbers(self):
#         def label_them(liszt):
#     def duplicate_downstream_interactions(self,species,D_species,module,D_module):
#     def duplicate_species_and_interactions(self,species):
#     def __build_dict_types__(self):
#     def __write_id__(self):
#     def __hash_net_topology__(self):
#     def write_id(self):
#     def check_Node(self,node,list_nodes_loop):
#     def remove_Node(self,Node):
#     def clean_Nodes(self,verbose=False):
#     def delete_clean(self,id,target = 'interaction',verbose=False):
#     def get_node(self,id,target = 'interaction'):
#     def draw(self,file=None,edgeLegend=False,extended=False,display=True,return_graph=False):
#     def store_to_pickle(self,filename):
#         S=Species(types)
# 
# Path: phievo/initialization_code.py
# def init_evolution(inits, deriv2):
# def check_model_dir(model):
# def init_networks(inits):
# def get_network_from_test(test_py, classes_eds2):
# def initialize_test(init_py):
# def parameters2file(inits, file_name):
# def make_workplace_dir(parent_dir):
# def display_error(msg = 'ERROR',filename = 'error.txt'):


import pickle
import shelve
import glob,os,sys
import re
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.patches as mpatches
import numpy as np
import importlib.util
import phievo
from phievo.AnalysisTools import main_functions as MF
from phievo.AnalysisTools  import palette
from  matplotlib.lines import Line2D
from phievo.Networks import mutation,classes_eds2
from phievo import  initialization_code
        from phievo.AnalysisTools import plotly_graph
        from phievo.AnalysisTools import plotly_graph
        from phievo.AnalysisTools import plotly_graph
        from phievo.AnalysisTools import plotly_graph
        from phievo.AnalysisTools import plotly_graph

class Simulation:
    """
    The simulation class is a container in which the informations about a simulation are unpacked. This is used for easy access to a simulation results.
    """
    def  __init__(self, path,mode="default"):
        """
        Creates a Simulation object. When th mode is not default (ex:test), the seeds are not loaded.
        usefull for prerun test.
        Args:
            path: directory of the project
            mode: Allows different mode to load the project.
        """
        self.root = path
        if self.root[-1] != os.sep:
            self.root += os.sep
        ## Upload Run parameters
        model_files = os.listdir(self.root)

# Path: phievo/AnalysisTools/main_functions.py
# def read_network(filename,verbose=False):
# def smoothing(array,param):
# def load_generation_data(generations,restart_file):
# def download_zip(dir_name,url):
#     def dlProgress(count, blockSize, totalSize):
# def download_tools(run_evolution="run_evolution.py",AnalyseRun="AnalyseRun.ipynb",ProjectCreator="ProjectCreator.ipynb"):
# def download_example(example_name,directory=None):
# 
# Path: phievo/AnalysisTools/palette.py
# def update_default_colormap(colormap):
# def HSL_to_RGB(h,s,l):
#     def Hue_2_RGB( v1, v2, vH ):
# def floatrange(start,stop,steps):
# def color_generate(n,colormap=None):
# def make_colormap(seq):
# def generate_gradient(values,seq):
# 
# Path: phievo/Networks/mutation.py
# T=1.0 #typical time scale
# C=1.0 #typical concentration
# L=1.0 #typical size for diffusion
#                 E_I=log(interval[1]/min_param) #range of possible energies
# def ligand_fct(random_generator):
# def build_lists(mutation_dict):
# def sample_dictionary_ranges(key,random_generator):
# def random_parameters(Types,random_generator):
# def rand_modify(self,random_generator):
#     def __init__(self,generator = random.Random()):
#     def compute_Cseed(self):
#     def random_Species(self, Type='Species'):
#     def random_Interaction(self,Interaction_Type):
#     def remove_Interaction(self,Type):
#     def random_remove_output(self):
#     def random_add_output(self):
#     def random_change_output(self):
#     def random_duplicate(self):
#     def mutate_Node(self,Type):
#     def build_mutations(self):
#         def update_dict(self,dictionary,key,name):
#     def compute_next_mutation(self):
#     def mutate_and_integrate(self,prmt,nnetwork,tgeneration,mutation=True):
# class Mutable_Network(classes_eds2.Network):
# 
# Path: phievo/Networks/classes_eds2.py
# class Node(object):
# class Species(Node):
# class TModule(Node):
# class Interaction(Node):
# class Network(object):
#     def __init__(self):
#     def __str__(self):
#     def print_node(self):
#     def isinstance(self,name):
#     def list_types(self):
#     def int_id(self):
#     def outputs_to_delete(self,net):
#     def isremovable(self,net,list_nodes_loop,verbose=False):
#     def string_param(self):
#     def __init__(self,listtypes=[]):
#     def __str__(self):
#         def cutter(arg):
#     def isinstance(self,name):
#     def list_types(self):
#     def def_label(self):
#     def clean_type(self,Type):
#     def change_type(self,Type,parameters):
#     def add_type(self,Type):
#     def __init__(self,rate=0,basal=0):
#     def __str__(self):
#     def string_param(self):
#     def __str__(self):
#     def check_grammar(self,input_list,output_list):
# def compare_node(x):
# def check_consistency(lTypes,lNodes):
#     def __init__(self):
#     def __str__(self):
#     def __repr__(self):
#     def add_Node(self, node):
#     def new_Species(self,types):
#     def number_nodes(self,Type):
#     def catal_data(self,interaction):
#     def check_existing_binary(self,list,Type):
#     def check_existing_link(self,list,Type):
#     def verify_IO_numbers(self):
#         def label_them(liszt):
#     def duplicate_downstream_interactions(self,species,D_species,module,D_module):
#     def duplicate_species_and_interactions(self,species):
#     def __build_dict_types__(self):
#     def __write_id__(self):
#     def __hash_net_topology__(self):
#     def write_id(self):
#     def check_Node(self,node,list_nodes_loop):
#     def remove_Node(self,Node):
#     def clean_Nodes(self,verbose=False):
#     def delete_clean(self,id,target = 'interaction',verbose=False):
#     def get_node(self,id,target = 'interaction'):
#     def draw(self,file=None,edgeLegend=False,extended=False,display=True,return_graph=False):
#     def store_to_pickle(self,filename):
#         S=Species(types)
# 
# Path: phievo/initialization_code.py
# def init_evolution(inits, deriv2):
# def check_model_dir(model):
# def init_networks(inits):
# def get_network_from_test(test_py, classes_eds2):
# def initialize_test(init_py):
# def parameters2file(inits, file_name):
# def make_workplace_dir(parent_dir):
# def display_error(msg = 'ERROR',filename = 'error.txt'):


# Path: phievo/AnalysisTools/Simulation.py
import pickle
import shelve
import glob,os,sys
import re
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.patches as mpatches
import numpy as np
import importlib.util
import phievo
from phievo.AnalysisTools import main_functions as MF
from phievo.AnalysisTools  import palette
from  matplotlib.lines import Line2D
from phievo.Networks import mutation,classes_eds2
from phievo import  initialization_code
        from phievo.AnalysisTools import plotly_graph
        from phievo.AnalysisTools import plotly_graph
        from phievo.AnalysisTools import plotly_graph
        from phievo.AnalysisTools import plotly_graph
        from phievo.AnalysisTools import plotly_graph


class Simulation:
    """
    The simulation class is a container in which the informations about a simulation are unpacked. This is used for easy access to a simulation results.
    """
    def  __init__(self, path,mode="default"):
        """
        Creates a Simulation object. When th mode is not default (ex:test), the seeds are not loaded.
        usefull for prerun test.
        Args:
            path: directory of the project
            mode: Allows different mode to load the project.
        """
        self.root = path
        if self.root[-1] != os.sep:
            self.root += os.sep
        ## Upload Run parameters
        model_files = os.listdir(self.root)

        (model_dir , self.inits , init_file) =tuple(initialization_code.check_model_dir(self.root))