/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000147.xml diagram  at 2008.03.20 15:09:36
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000147 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        Total_IkBalpha = x[4] + x[16] + x[1] + x[2] + x[3] + x[14];
        Total_IkBbeta = x[8] + x[19] + x[5] + x[6] + x[7] + x[17];
        Total_IkBeps = x[12] + x[22] + x[9] + x[10] + x[11] + x[20];
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_IKK_deg = cytoplasm*IKK_deg_IKK_deg*x[0];
        rate_deg_a = cytoplasm*deg_a_deg1_c*x[4];
        rate_deg_a_n = nucleus*deg_a_n_deg1_n*x[16];
        rate_deg_ai = cytoplasm*deg_ai_r1*x[1];
        rate_deg_ain = cytoplasm*deg_ain_r4*x[2];
        rate_deg_an = cytoplasm*deg_an_deg4_c*x[3];
        rate_deg_an_n = nucleus*deg_an_n_deg4_n*x[14];
        rate_deg_b = cytoplasm*deg_b_deg2_c*x[8];
        rate_deg_b_n = nucleus*deg_b_n_deg2_n*x[19];
        rate_deg_bi = cytoplasm*deg_bi_r2*x[5];
        rate_deg_bin = cytoplasm*deg_bin_r5*x[6];
        rate_deg_bn = cytoplasm*deg_bn_deg5_c*x[7];
        rate_deg_bn_n = nucleus*deg_bn_n_deg5_n*x[17];
        rate_deg_e = cytoplasm*deg_e_deg3_c*x[12];
        rate_deg_e_n = nucleus*deg_e_n_deg3_n*x[22];
        rate_deg_ei = cytoplasm*deg_ei_r3*x[9];
        rate_deg_ein = cytoplasm*deg_ein_r6*x[10];
        rate_deg_en = cytoplasm*deg_en_deg6_c*x[11];
        rate_deg_en_n = nucleus*deg_en_n_deg6_n*x[20];
        rate_int_2ain = cytoplasm*(int_2ain_a4_3*x[1]*x[13] - int_2ain_d4_3*x[2]);
        rate_int_2ani = cytoplasm*(int_2ani_a7*x[3]*x[0] - int_2ani_d1_2*x[2]);
        rate_int_2bin = cytoplasm*(int_2bin_a5_3*x[5]*x[13] - int_2bin_d5_3*x[6]);
        rate_int_2bni = cytoplasm*(int_2bni_a8*x[7]*x[0] - int_2bni_d2_2*x[6]);
        rate_int_2ein = cytoplasm*(int_2ein_a6_3*x[9]*x[13] - int_2ein_d6_3*x[10]);
        rate_int_2eni = cytoplasm*(int_2eni_a9*x[11]*x[0] - int_2eni_d3_2*x[10]);
        rate_int_ai = cytoplasm*(int_ai_a1*x[4]*x[0] - int_ai_d1_1*x[1]);
        rate_int_an = cytoplasm*(int_an_a4_1*x[4]*x[13] - int_an_d4_1*x[3]);
        rate_int_an_n = nucleus*(int_an_n_a4_2*x[16]*x[23] - int_an_n_d4_2*x[14]);
        rate_int_bi = cytoplasm*(int_bi_a2*x[8]*x[0] - int_bi_d2_1*x[5]);
        rate_int_bn = cytoplasm*(int_bn_a5_1*x[8]*x[13] - int_bn_d5_1*x[7]);
        rate_int_bn_n = nucleus*(int_bn_n_a5_2*x[19]*x[23] - int_bn_n_d5_2*x[17]);
        rate_int_ei = cytoplasm*(int_ei_a3*x[12]*x[0] - int_ei_d3_1*x[9]);
        rate_int_en = cytoplasm*(int_en_a6_1*x[12]*x[13] - int_en_d6_1*x[11]);
        rate_int_en_n = nucleus*(int_en_n_a6_2*x[22]*x[23] - int_en_n_d6_2*x[20]);
        rate_itxn_a = nucleus*itxn_a_tr2a_i*Math.pow(x[23], 2);
        rate_loc_a = cytoplasm*loc_a_tp1a*x[4] - nucleus*loc_a_tp2a*x[16];
        rate_loc_an = nucleus*loc_an_k2_a*x[14];
        rate_loc_b = cytoplasm*loc_b_tp1b*x[8] - nucleus*loc_b_tp2b*x[19];
        rate_loc_bn = nucleus*loc_bn_k2_b*x[17];
        rate_loc_e = cytoplasm*loc_e_tp1e*x[12] - nucleus*loc_e_tp2e*x[22];
    }
    public void __internalRateVarInitFunc_1(double time, double[] x)
    {
        rate_loc_en = nucleus*loc_en_k2_e*x[20];
        rate_loc_n = cytoplasm*loc_n_k1_2*x[13] - nucleus*loc_n_k1_1*x[23];
        rate_mdeg_a = nucleus*mdeg_a_tr3a*x[15];
        rate_mdeg_b = nucleus*mdeg_b_tr3b*x[18];
        rate_mdeg_e = nucleus*mdeg_e_tr3e*x[21];
        rate_tsl_a = nucleus*tsl_a_tr1a*x[15];
        rate_tsl_b = nucleus*tsl_b_tr1b*x[18];
        rate_tsl_e = nucleus*tsl_e_tr1e*x[21];
        rate_txn_a = nucleus*txn_a_tr2a;
        rate_txn_b = nucleus*txn_b_tr2b;
        rate_txn_e = nucleus*txn_e_tr2e;
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        cytoplasm = 1.0; // initial value of $cytoplasm
        nucleus = 1.0; // initial value of $nucleus
        deg_a_deg1_c = 0.12; // initial value of deg_a_deg1_c
        deg_a_n_deg1_n = 0.12; // initial value of deg_a_n_deg1_n
        deg_ai_r1 = 0.072; // initial value of deg_ai_r1
        deg_ain_r4 = 0.36; // initial value of deg_ain_r4
        deg_an_deg4_c = 6.0E-5; // initial value of deg_an_deg4_c
        deg_an_n_deg4_n = 6.0E-5; // initial value of deg_an_n_deg4_n
        deg_b_deg2_c = 0.18; // initial value of deg_b_deg2_c
        deg_b_n_deg2_n = 0.18; // initial value of deg_b_n_deg2_n
        deg_bi_r2 = 0.024; // initial value of deg_bi_r2
        deg_bin_r5 = 0.12; // initial value of deg_bin_r5
        deg_bn_deg5_c = 6.0E-5; // initial value of deg_bn_deg5_c
        deg_bn_n_deg5_n = 6.0E-5; // initial value of deg_bn_n_deg5_n
        deg_e_deg3_c = 0.18; // initial value of deg_e_deg3_c
        deg_e_n_deg3_n = 0.18; // initial value of deg_e_n_deg3_n
        deg_ei_r3 = 0.036; // initial value of deg_ei_r3
        deg_ein_r6 = 0.18; // initial value of deg_ein_r6
        deg_en_deg6_c = 6.0E-5; // initial value of deg_en_deg6_c
        deg_en_n_deg6_n = 6.0E-5; // initial value of deg_en_n_deg6_n
        int_2ain_a4_3 = 30.0; // initial value of int_2ain_a4_3
        int_2ain_d4_3 = 6.0E-5; // initial value of int_2ain_d4_3
        int_2ani_a7 = 11.1; // initial value of int_2ani_a7
        int_2ani_d1_2 = 0.075; // initial value of int_2ani_d1_2
        int_2bin_a5_3 = 30.0; // initial value of int_2bin_a5_3
        int_2bin_d5_3 = 6.0E-5; // initial value of int_2bin_d5_3
        int_2bni_a8 = 2.88; // initial value of int_2bni_a8
        int_2bni_d2_2 = 0.105; // initial value of int_2bni_d2_2
        int_2ein_a6_3 = 30.0; // initial value of int_2ein_a6_3
        int_2ein_d6_3 = 6.0E-5; // initial value of int_2ein_d6_3
        int_2eni_a9 = 4.2; // initial value of int_2eni_a9
        int_2eni_d3_2 = 0.105; // initial value of int_2eni_d3_2
        int_ai_a1 = 1.35; // initial value of int_ai_a1
        int_ai_d1_1 = 0.075; // initial value of int_ai_d1_1
        int_an_a4_1 = 30.0; // initial value of int_an_a4_1
        int_an_d4_1 = 6.0E-5; // initial value of int_an_d4_1
        int_an_n_a4_2 = 30.0; // initial value of int_an_n_a4_2
        int_an_n_d4_2 = 6.0E-5; // initial value of int_an_n_d4_2
        int_bi_a2 = 0.36; // initial value of int_bi_a2
        int_bi_d2_1 = 0.105; // initial value of int_bi_d2_1
        int_bn_a5_1 = 30.0; // initial value of int_bn_a5_1
        int_bn_d5_1 = 6.0E-5; // initial value of int_bn_d5_1
        int_bn_n_a5_2 = 30.0; // initial value of int_bn_n_a5_2
        int_bn_n_d5_2 = 6.0E-5; // initial value of int_bn_n_d5_2
        int_ei_a3 = 0.54; // initial value of int_ei_a3
        int_ei_d3_1 = 0.105; // initial value of int_ei_d3_1
        int_en_a6_1 = 30.0; // initial value of int_en_a6_1
        int_en_d6_1 = 6.0E-5; // initial value of int_en_d6_1
        int_en_n_a6_2 = 30.0; // initial value of int_en_n_a6_2
        int_en_n_d6_2 = 6.0E-5; // initial value of int_en_n_d6_2
        itxn_a_tr2a_i = 1.98; // initial value of itxn_a_tr2a_i
        loc_a_tp1a = 0.018; // initial value of loc_a_tp1a
        loc_a_tp2a = 0.012; // initial value of loc_a_tp2a
        loc_an_k2_a = 0.828; // initial value of loc_an_k2_a
        loc_b_tp1b = 0.018; // initial value of loc_b_tp1b
        loc_b_tp2b = 0.012; // initial value of loc_b_tp2b
        loc_bn_k2_b = 0.414; // initial value of loc_bn_k2_b
        loc_e_tp1e = 0.018; // initial value of loc_e_tp1e
        loc_e_tp2e = 0.012; // initial value of loc_e_tp2e
        loc_en_k2_e = 0.414; // initial value of loc_en_k2_e
        loc_n_k1_1 = 0.0048; // initial value of loc_n_k1_1
        loc_n_k1_2 = 5.4; // initial value of loc_n_k1_2
        mdeg_a_tr3a = 0.0168; // initial value of mdeg_a_tr3a
        mdeg_b_tr3b = 0.0168; // initial value of mdeg_b_tr3b
        mdeg_e_tr3e = 0.0168; // initial value of mdeg_e_tr3e
        tsl_a_tr1a = 0.2448; // initial value of tsl_a_tr1a
        tsl_b_tr1b = 0.2448; // initial value of tsl_b_tr1b
        tsl_e_tr1e = 0.2448; // initial value of tsl_e_tr1e
        txn_a_tr2a = 1.848E-4; // initial value of txn_a_tr2a
        txn_b_tr2b = 4.272E-5; // initial value of txn_b_tr2b
        txn_e_tr2e = 3.048E-5; // initial value of txn_e_tr2e
    }

    /*
     * Model variables initial values
     */
    protected double rate_IKK_deg;
    protected double rate_deg_a;
    protected double rate_deg_a_n;
    protected double rate_deg_ai;
    protected double rate_deg_ain;
    protected double rate_deg_an;
    protected double rate_deg_an_n;
    protected double rate_deg_b;
    protected double rate_deg_b_n;
    protected double rate_deg_bi;
    protected double rate_deg_bin;
    protected double rate_deg_bn;
    protected double rate_deg_bn_n;
    protected double rate_deg_e;
    protected double rate_deg_e_n;
    protected double rate_deg_ei;
    protected double rate_deg_ein;
    protected double rate_deg_en;
    protected double rate_deg_en_n;
    protected double rate_int_2ain;
    protected double rate_int_2ani;
    protected double rate_int_2bin;
    protected double rate_int_2bni;
    protected double rate_int_2ein;
    protected double rate_int_2eni;
    protected double rate_int_ai;
    protected double rate_int_an;
    protected double rate_int_an_n;
    protected double rate_int_bi;
    protected double rate_int_bn;
    protected double rate_int_bn_n;
    protected double rate_int_ei;
    protected double rate_int_en;
    protected double rate_int_en_n;
    protected double rate_itxn_a;
    protected double rate_loc_a;
    protected double rate_loc_an;
    protected double rate_loc_b;
    protected double rate_loc_bn;
    protected double rate_loc_e;
    protected double rate_loc_en;
    protected double rate_loc_n;
    protected double rate_mdeg_a;
    protected double rate_mdeg_b;
    protected double rate_mdeg_e;
    protected double rate_tsl_a;
    protected double rate_tsl_b;
    protected double rate_tsl_e;
    protected double rate_txn_a;
    protected double rate_txn_b;
    protected double rate_txn_e;
    protected double cytoplasm;
    protected double nucleus;
    protected double IKK_deg_IKK_deg;
    protected double Total_IkBalpha;
    protected double Total_IkBbeta;
    protected double Total_IkBeps;
    protected double deg_a_deg1_c;
    protected double deg_a_n_deg1_n;
    protected double deg_ai_r1;
    protected double deg_ain_r4;
    protected double deg_an_deg4_c;
    protected double deg_an_n_deg4_n;
    protected double deg_b_deg2_c;
    protected double deg_b_n_deg2_n;
    protected double deg_bi_r2;
    protected double deg_bin_r5;
    protected double deg_bn_deg5_c;
    protected double deg_bn_n_deg5_n;
    protected double deg_e_deg3_c;
    protected double deg_e_n_deg3_n;
    protected double deg_ei_r3;
    protected double deg_ein_r6;
    protected double deg_en_deg6_c;
    protected double deg_en_n_deg6_n;
    protected double int_2ain_a4_3;
    protected double int_2ain_d4_3;
    protected double int_2ani_a7;
    protected double int_2ani_d1_2;
    protected double int_2bin_a5_3;
    protected double int_2bin_d5_3;
    protected double int_2bni_a8;
    protected double int_2bni_d2_2;
    protected double int_2ein_a6_3;
    protected double int_2ein_d6_3;
    protected double int_2eni_a9;
    protected double int_2eni_d3_2;
    protected double int_ai_a1;
    protected double int_ai_d1_1;
    protected double int_an_a4_1;
    protected double int_an_d4_1;
    protected double int_an_n_a4_2;
    protected double int_an_n_d4_2;
    protected double int_bi_a2;
    protected double int_bi_d2_1;
    protected double int_bn_a5_1;
    protected double int_bn_d5_1;
    protected double int_bn_n_a5_2;
    protected double int_bn_n_d5_2;
    protected double int_ei_a3;
    protected double int_ei_d3_1;
    protected double int_en_a6_1;
    protected double int_en_d6_1;
    protected double int_en_n_a6_2;
    protected double int_en_n_d6_2;
    protected double itxn_a_tr2a_i;
    protected double loc_a_tp1a;
    protected double loc_a_tp2a;
    protected double loc_an_k2_a;
    protected double loc_b_tp1b;
    protected double loc_b_tp2b;
    protected double loc_bn_k2_b;
    protected double loc_e_tp1e;
    protected double loc_e_tp2e;
    protected double loc_en_k2_e;
    protected double loc_n_k1_1;
    protected double loc_n_k1_2;
    protected double mdeg_a_tr3a;
    protected double mdeg_b_tr3b;
    protected double mdeg_e_tr3e;
    protected double tsl_a_tr1a;
    protected double tsl_b_tr1b;
    protected double tsl_e_tr1e;
    protected double txn_a_tr2a;
    protected double txn_b_tr2b;
    protected double txn_e_tr2e;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[27];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = x[2];
        y[3] = x[3];
        y[4] = x[4];
        y[5] = x[5];
        y[6] = x[6];
        y[7] = x[7];
        y[8] = x[8];
        y[9] = x[9];
        y[10] = x[10];
        y[11] = x[11];
        y[12] = x[12];
        y[13] = x[13];
        y[14] = x[14];
        y[15] = x[15];
        y[16] = x[16];
        y[17] = x[17];
        y[18] = x[18];
        y[19] = x[19];
        y[20] = x[20];
        y[21] = x[21];
        y[22] = x[22];
        y[23] = x[23];
        y[24] = Total_IkBalpha;
        y[25] = Total_IkBbeta;
        y[26] = Total_IkBeps;
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[24];
        this.time = 0.0;
        x[0] = 0.0010; // - $"cytoplasm.IKK"
        x[1] = 0.0; // - $"cytoplasm.IkBaIKK"
        x[2] = 0.0; // - $"cytoplasm.IkBaIKKNFkB"
        x[3] = 0.06; // - $"cytoplasm.IkBaNFkB_cytoplasm"
        x[4] = 0.0; // - $"cytoplasm.IkBa_cytoplasm"
        x[5] = 0.0; // - $"cytoplasm.IkBbIKK"
        x[6] = 0.0; // - $"cytoplasm.IkBbIKKNFkB"
        x[7] = 0.03; // - $"cytoplasm.IkBbNFkB_cytoplasm"
        x[8] = 0.0; // - $"cytoplasm.IkBb_cytoplasm"
        x[9] = 0.0; // - $"cytoplasm.IkBeIKK"
        x[10] = 0.0; // - $"cytoplasm.IkBeIKKNFkB"
        x[11] = 0.01; // - $"cytoplasm.IkBeNFkB_cytoplasm"
        x[12] = 0.0; // - $"cytoplasm.IkBe_cytoplasm"
        x[13] = 0.0; // - $"cytoplasm.NFkB_cytoplasm"
        x[14] = 0.0; // - $"nucleus.IkBaNFkB_nucleus"
        x[15] = 0.0; // - $"nucleus.IkBa_mRNA"
        x[16] = 0.0; // - $"nucleus.IkBa_nucleus"
        x[17] = 0.0; // - $"nucleus.IkBbNFkB_nucleus"
        x[18] = 0.0; // - $"nucleus.IkBb_mRNA"
        x[19] = 0.0; // - $"nucleus.IkBb_nucleus"
        x[20] = 0.0; // - $"nucleus.IkBeNFkB_nucleus"
        x[21] = 0.0; // - $"nucleus.IkBe_mRNA"
        x[22] = 0.0; // - $"nucleus.IkBe_nucleus"
        x[23] = 0.0; // - $"nucleus.NFkB_nucleus"

        __internalVarInitFunc_0(time, x);
        __internalRateVarInitFunc_0(time, x);
        __internalRateVarInitFunc_1(time, x);

        return x;
    }

/*
 * code for algebraic rules calculations
 */

/*
 * end of code for algebraic rules calculations
 */

    protected void calculateRates(double time, double[] x)
    {

        __internalVarInitFunc_0(time, x);
        __internalRateVarInitFunc_0(time, x);
        __internalRateVarInitFunc_1(time, x);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000147.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_IKK_deg+rate_deg_ai+rate_deg_ain+rate_deg_bi+rate_deg_bin+rate_deg_ei+rate_deg_ein-rate_int_2ani-rate_int_2bni-rate_int_2eni-rate_int_ai-rate_int_bi-rate_int_ei;
        result[1] = -rate_deg_ai-rate_int_2ain+rate_int_ai;
        result[2] = -rate_deg_ain+rate_int_2ain+rate_int_2ani;
        result[3] = -rate_deg_an-rate_int_2ani+rate_int_an+rate_loc_an;
        result[4] = -rate_deg_a-rate_int_ai-rate_int_an-rate_loc_a+rate_tsl_a;
        result[5] = -rate_deg_bi-rate_int_2bin+rate_int_bi;
        result[6] = -rate_deg_bin+rate_int_2bin+rate_int_2bni;
        result[7] = -rate_deg_bn-rate_int_2bni+rate_int_bn+rate_loc_bn;
        result[8] = -rate_deg_b-rate_int_bi-rate_int_bn-rate_loc_b+rate_tsl_b;
        result[9] = -rate_deg_ei-rate_int_2ein+rate_int_ei;
        result[10] = -rate_deg_ein+rate_int_2ein+rate_int_2eni;
        result[11] = -rate_deg_en-rate_int_2eni+rate_int_en+rate_loc_en;
        result[12] = -rate_deg_e-rate_int_ei-rate_int_en-rate_loc_e+rate_tsl_e;
        result[13] = +rate_deg_ain+rate_deg_an+rate_deg_bin+rate_deg_bn+rate_deg_ein+rate_deg_en-rate_int_2ain-rate_int_2bin-rate_int_2ein-rate_int_an-rate_int_bn-rate_int_en-rate_loc_n;
        result[14] = -rate_deg_an_n+rate_int_an_n-rate_loc_an;
        result[15] = +rate_itxn_a-rate_mdeg_a+rate_tsl_a-rate_tsl_a+rate_txn_a;
        result[16] = -rate_deg_a_n-rate_int_an_n+rate_loc_a;
        result[17] = -rate_deg_bn_n+rate_int_bn_n-rate_loc_bn;
        result[18] = -rate_mdeg_b+rate_tsl_b-rate_tsl_b+rate_txn_b;
        result[19] = -rate_deg_b_n-rate_int_bn_n+rate_loc_b;
        result[20] = -rate_deg_en_n+rate_int_en_n-rate_loc_en;
        result[21] = -rate_mdeg_e+rate_tsl_e-rate_tsl_e+rate_txn_e;
        result[22] = -rate_deg_e_n-rate_int_en_n+rate_loc_e;
        result[23] = +rate_deg_an_n+rate_deg_bn_n+rate_deg_en_n-rate_int_an_n-rate_int_bn_n-rate_int_en_n+rate_loc_n;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[24];
        __internalDyDt_0(time, x, result);
        return result;
    }
    public double[] dy_dt(double time, double[] x)
    {
        this.time = time;
        calculateRates( time,x );

        return calculateResult( time,x );
    }

} // class ...