Exemple #1
0
    'product_concentration', 'substrate_concentration'
]

# Filter the data frame for specific condition

this_volume_fraction = 0.0
this_mu = 31.9
this_sigma = 0.825

this_df = df[(df['sigma_mass'] == this_sigma) & (df['mu_mass'] == this_mu) &
             (df['volume_fraction'] == this_volume_fraction)]

# Extract the GEEK parameters from Linear regression
k1_fwd_params = geek_regression(this_df,
                                concentrations,
                                reference_concentrations,
                                'k1_fwd_relative',
                                verbose=False)

k1_bwd_params = geek_regression(this_df,
                                concentrations,
                                reference_concentrations,
                                'k1_bwd_relative',
                                verbose=False)
k2_fwd_params = geek_regression(this_df,
                                concentrations,
                                reference_concentrations,
                                'k1_fwd_relative',
                                verbose=False)

k2_bwd_params = geek_regression(this_df,
def geek_simulations_crwderfree(parameters, sim_type, phi= 0.0, seed=1):
    from geek.analysis import geek_regression

    if sim_type == 'diff':
        df = read_csv('../data/validation_diffusion_lim_crowderfree.csv')
    elif sim_type == 'react':
        df = read_csv('../data/validation_reaction_lim_crowderfree.csv')
    else:
        raise ValueError('{} is not a valid input'.format(sim_type))
    # Reference concentrations
    reference_concentrations = [50e-6,]*3
    concentrations = ['A_concentration',
                      'B_concentration',
                      'C_concentration',]


    this_df = df[(df['volume_fraction'] == phi)]

    # Extract the GEEK parameters from Linear regression
    k1_fwd_params = geek_regression(this_df,
                                      concentrations,
                                      reference_concentrations,
                                      'k1_fwd_relative',
                                      verbose=True)

    k1_bwd_params = geek_regression(this_df,
                                      concentrations,
                                      reference_concentrations,
                                      'k1_bwd_relative',
                                      verbose=True)

    random.seed(seed)
    #Map to parameter dict
    param_dict = {
        'k_1f0': parameters['k_fwd'],
        'k_1b0': parameters['k_fwd']*parameters['K_eq'],
        'beta_1f': k1_fwd_params['beta_lb'] + (k1_fwd_params['beta_ub'] - k1_fwd_params['beta_lb']) * random.random(),
        'alpha_A_1f': k1_fwd_params['alpha_A_concentration_lb'] + (
                k1_fwd_params['alpha_A_concentration_ub'] - k1_fwd_params[
                'alpha_A_concentration_lb']) * random.random(),
        'alpha_B_1f': k1_fwd_params['alpha_B_concentration_lb'] + (
                k1_fwd_params['alpha_B_concentration_ub'] - k1_fwd_params[
            'alpha_B_concentration_lb']) * random.random(),
        'alpha_C_1f': k1_fwd_params['alpha_C_concentration_lb'] + (
                k1_fwd_params['alpha_C_concentration_ub'] - k1_fwd_params[
            'alpha_C_concentration_lb']) * random.random(),
        'beta_1b': k1_bwd_params['beta_lb'] + (k1_bwd_params['beta_ub'] - k1_bwd_params['beta_lb']) * random.random(),
        'alpha_A_1b': k1_bwd_params['alpha_A_concentration_lb'] + (
                k1_bwd_params['alpha_A_concentration_ub'] - k1_bwd_params[
            'alpha_A_concentration_lb']) * random.random(),
        'alpha_B_1b': k1_bwd_params['alpha_B_concentration_lb'] + (
                k1_bwd_params['alpha_B_concentration_ub'] - k1_bwd_params[
            'alpha_B_concentration_lb']) * random.random(),
        'alpha_C_1b': k1_bwd_params['alpha_C_concentration_lb'] + (
                k1_bwd_params['alpha_C_concentration_ub'] - k1_bwd_params[
            'alpha_C_concentration_lb']) * random.random(),
        'A0': reference_concentrations[0],
        'B0': reference_concentrations[1],
        'C0': reference_concentrations[2],
    }

    """
    Declare ODE-Problem
    """
    from sympy import symbols
    from sympy import exp as sym_exp

    # Variables
    A, B, C = symbols(['A', 'B', 'C'])
    variables = [A, B, C,]
    # Parameters
    k_1f0, k_1b0, = symbols(['k_1f0', 'k_1b0',] )
    # Define symbols for the GEEK parameters
    beta_1f, beta_1b,  = symbols(['beta_1f', 'beta_1b',] )
    alpha_A_1f, alpha_A_1b, = symbols(['alpha_A_1f', 'alpha_A_1b',])
    alpha_B_1f, alpha_B_1b, = symbols(['alpha_B_1f', 'alpha_B_1b',])
    alpha_C_1f, alpha_C_1b, = symbols(['alpha_C_1f', 'alpha_C_1b',])
    A0,B0,C0 = symbols(['A0', 'B0', 'C0'])

    ode_params = [k_1f0, k_1b0,
                  beta_1f, beta_1b ,
                  alpha_A_1b, alpha_A_1f ,
                  alpha_B_1b, alpha_B_1f,
                  alpha_C_1f, alpha_C_1b,
                  A0, B0, C0]
    # Reactions

    geek_reactions = {
        'r_1f': k_1f0 * A * B * sym_exp(beta_1f) * (A / A0) ** alpha_A_1f * (B / B0) ** alpha_B_1f * (
                    C / C0) ** alpha_C_1f,
        'r_1b': k_1b0 * C * sym_exp(beta_1b) * (A / A0) ** alpha_A_1b * (B / B0) ** alpha_B_1b * (
                    C / C0) ** alpha_C_1b
    }

    #Expressions

    expressions = {
        A: geek_reactions['r_1b'] - geek_reactions['r_1f'],
        B: geek_reactions['r_1b'] - geek_reactions['r_1f'],
        C: geek_reactions['r_1f'] - geek_reactions['r_1b'],
    }

    from geek.analysis.ode_function import OdeFun
    fun = OdeFun(variables,ode_params,expressions)

    from scipy.integrate import ode
    r = ode(fun).set_integrator('vode', method='bdf')

    eps = 1e-3

    A0 = round(parameters['A_0']*AVOGADRO_NUMBER*parameters['volume'])/AVOGADRO_NUMBER/parameters['volume']
    B0 = round(parameters['B_0']*AVOGADRO_NUMBER*parameters['volume'])/AVOGADRO_NUMBER/parameters['volume']
    C0 = round(parameters['C_0']*AVOGADRO_NUMBER*parameters['volume'])/AVOGADRO_NUMBER/parameters['volume']

    print(A0,B0,C0)

    y0 = [A0 * (1. - eps),
          B0 * (1. - eps),
          A0 * eps]
    t0 = 0.0

    r.set_initial_value(y0, t0).set_f_params(param_dict)
    data = []

    scale = parameters['volume']*AVOGADRO_NUMBER
    while r.successful() and r.t < parameters['t_max']:
        data.append( np.append(r.t + parameters['t_max']/1000.0,
                     r.integrate(r.t + parameters['t_max']/1000.0) * scale))
    data = np.array(data)

    df = DataFrame(data=data, columns = ['time', 'A', 'B', 'C'])
    return df