/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000073.xml diagram  at 2008.03.20 15:07:54
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000073 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_reaction_0 = cell*function_0(reaction_0_vsb, reaction_0_K, reaction_0_m, x[9]);
        rate_reaction_1 = cell*function_1(reaction_1_k, x[0]);
        rate_reaction_10 = cell*function_1(reaction_10_k, x[13]);
        rate_reaction_11 = cell*function_2(reaction_11_V, x[15], reaction_11_Km);
        rate_reaction_12 = cell*function_2(reaction_12_V, x[14], reaction_12_Km);
        rate_reaction_13 = cell*(reaction_13_k1*x[10]*x[14] - reaction_13_k2*x[2]);
        rate_reaction_14 = cell*function_2(reaction_14_V, x[2], reaction_14_Km);
        rate_reaction_15 = cell*function_2(reaction_15_V, x[3], reaction_15_Km);
        rate_reaction_16 = cell*(reaction_16_k1*x[2] - reaction_16_k2*x[4]);
        rate_reaction_17 = cell*reaction_17_k1*x[6];
        rate_reaction_18 = cell*reaction_18_k1*x[8];
        rate_reaction_19 = cell*reaction_19_k1*x[5];
        rate_reaction_2 = cell*reaction_2_k1*x[0];
        rate_reaction_20 = cell*function_3(reaction_20_Vs, x[9], reaction_20_n, reaction_20_K);
        rate_reaction_21 = cell*function_2(reaction_21_V, x[4], reaction_21_Km);
        rate_reaction_22 = cell*reaction_22_k1*x[13];
        rate_reaction_23 = cell*(reaction_23_k1*x[4]*x[9] - reaction_23_k2*x[7]);
        rate_reaction_24 = cell*function_2(reaction_24_V, x[0], reaction_24_Km);
        rate_reaction_25 = cell*function_2(reaction_25_V, x[11], reaction_25_Km);
        rate_reaction_26 = cell*function_2(reaction_26_V, x[13], reaction_26_Km);
        rate_reaction_27 = cell*reaction_27_k1*x[14];
        rate_reaction_28 = cell*reaction_28_k1*x[10];
        rate_reaction_29 = cell*reaction_29_k1*x[15];
        rate_reaction_3 = cell*function_2(reaction_3_V, x[1], reaction_3_Km);
        rate_reaction_30 = cell*reaction_30_k1*x[12];
        rate_reaction_31 = cell*reaction_31_k1*x[3];
        rate_reaction_32 = cell*reaction_32_k1*x[2];
        rate_reaction_33 = cell*function_2(reaction_33_V, x[6], reaction_33_Km);
        rate_reaction_34 = cell*reaction_34_k1*x[1];
        rate_reaction_35 = cell*function_2(reaction_35_V, x[8], reaction_35_Km);
        rate_reaction_36 = cell*function_2(reaction_36_V, x[9], reaction_36_Km);
        rate_reaction_37 = cell*function_2(reaction_37_V, x[5], reaction_37_Km);
        rate_reaction_38 = cell*reaction_38_k1*x[7];
        rate_reaction_39 = cell*function_2(reaction_39_V, x[7], reaction_39_Km);
        rate_reaction_4 = cell*(reaction_4_k1*x[1] - reaction_4_k2*x[9]);
        rate_reaction_40 = cell*reaction_40_k1*x[9];
        rate_reaction_41 = cell*function_2(reaction_41_V, x[8], reaction_41_Km);
        rate_reaction_42 = cell*function_2(reaction_42_V, x[5], reaction_42_Km);
        rate_reaction_43 = cell*function_2(reaction_43_V, x[12], reaction_43_Km);
        rate_reaction_44 = cell*function_2(reaction_44_V, x[15], reaction_44_Km);
    }
    public void __internalRateVarInitFunc_1(double time, double[] x)
    {
        rate_reaction_45 = cell*function_2(reaction_45_V, x[6], reaction_45_Km);
        rate_reaction_46 = cell*reaction_46_k1*x[4];
        rate_reaction_47 = cell*function_2(reaction_47_V, x[3], reaction_47_Km);
        rate_reaction_5 = cell*function_1(reaction_5_k, x[11]);
        rate_reaction_6 = cell*reaction_6_k1*x[11];
        rate_reaction_7 = cell*function_2(reaction_7_V, x[10], reaction_7_Km);
        rate_reaction_8 = cell*function_2(reaction_8_V, x[12], reaction_8_Km);
        rate_reaction_9 = cell*function_3(reaction_9_Vs, x[9], reaction_9_n, reaction_9_K);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        cell = 1.0; // initial value of $cell
        reaction_0_K = 2.2; // initial value of reaction_0_K
        reaction_0_m = 2.0; // initial value of reaction_0_m
        reaction_0_vsb = 1.0; // initial value of reaction_0_vsb
        reaction_10_k = 0.6; // initial value of reaction_10_k
        reaction_11_Km = 0.3; // initial value of reaction_11_Km
        reaction_11_V = 0.7; // initial value of reaction_11_V
        reaction_12_Km = 0.1; // initial value of reaction_12_Km
        reaction_12_V = 0.4; // initial value of reaction_12_V
        reaction_13_k1 = 0.4; // initial value of reaction_13_k1
        reaction_13_k2 = 0.2; // initial value of reaction_13_k2
        reaction_14_Km = 0.1; // initial value of reaction_14_Km
        reaction_14_V = 0.4; // initial value of reaction_14_V
        reaction_15_Km = 0.3; // initial value of reaction_15_Km
        reaction_15_V = 0.7; // initial value of reaction_15_V
        reaction_16_k1 = 0.4; // initial value of reaction_16_k1
        reaction_16_k2 = 0.2; // initial value of reaction_16_k2
        reaction_17_k1 = 0.01; // initial value of reaction_17_k1
        reaction_18_k1 = 0.01; // initial value of reaction_18_k1
        reaction_19_k1 = 0.01; // initial value of reaction_19_k1
        reaction_1_k = 0.12; // initial value of reaction_1_k
        reaction_20_K = 0.6; // initial value of reaction_20_K
        reaction_20_Vs = 1.1; // initial value of reaction_20_Vs
        reaction_20_n = 4.0; // initial value of reaction_20_n
        reaction_21_Km = 0.1; // initial value of reaction_21_Km
        reaction_21_V = 0.4; // initial value of reaction_21_V
        reaction_22_k1 = 0.01; // initial value of reaction_22_k1
        reaction_23_k1 = 0.5; // initial value of reaction_23_k1
        reaction_23_k2 = 0.1; // initial value of reaction_23_k2
        reaction_24_Km = 0.4; // initial value of reaction_24_Km
        reaction_24_V = 0.8; // initial value of reaction_24_V
        reaction_25_Km = 0.4; // initial value of reaction_25_Km
        reaction_25_V = 1.0; // initial value of reaction_25_V
        reaction_26_Km = 0.31; // initial value of reaction_26_Km
        reaction_26_V = 1.1; // initial value of reaction_26_V
        reaction_27_k1 = 0.01; // initial value of reaction_27_k1
        reaction_28_k1 = 0.12; // initial value of reaction_28_k1
        reaction_29_k1 = 0.01; // initial value of reaction_29_k1
        reaction_2_k1 = 0.01; // initial value of reaction_2_k1
        reaction_30_k1 = 0.01; // initial value of reaction_30_k1
        reaction_31_k1 = 0.01; // initial value of reaction_31_k1
        reaction_32_k1 = 0.01; // initial value of reaction_32_k1
        reaction_33_Km = 0.3; // initial value of reaction_33_Km
        reaction_33_V = 0.7; // initial value of reaction_33_V
        reaction_34_k1 = 0.01; // initial value of reaction_34_k1
        reaction_35_Km = 0.3; // initial value of reaction_35_Km
        reaction_35_V = 0.5; // initial value of reaction_35_V
        reaction_36_Km = 0.1; // initial value of reaction_36_Km
        reaction_36_V = 0.5; // initial value of reaction_36_V
        reaction_37_Km = 0.3; // initial value of reaction_37_Km
        reaction_37_V = 0.6; // initial value of reaction_37_V
        reaction_38_k1 = 0.01; // initial value of reaction_38_k1
        reaction_39_Km = 0.3; // initial value of reaction_39_Km
        reaction_39_V = 0.8; // initial value of reaction_39_V
        reaction_3_Km = 0.1; // initial value of reaction_3_Km
        reaction_3_V = 0.5; // initial value of reaction_3_V
        reaction_40_k1 = 0.01; // initial value of reaction_40_k1
        reaction_41_Km = 0.1; // initial value of reaction_41_Km
        reaction_41_V = 0.1; // initial value of reaction_41_V
        reaction_42_Km = 0.1; // initial value of reaction_42_Km
        reaction_42_V = 0.2; // initial value of reaction_42_V
        reaction_43_Km = 0.1; // initial value of reaction_43_Km
        reaction_43_V = 0.1; // initial value of reaction_43_V
        reaction_44_Km = 0.1; // initial value of reaction_44_Km
        reaction_44_V = 0.3; // initial value of reaction_44_V
        reaction_45_Km = 0.1; // initial value of reaction_45_Km
        reaction_45_V = 0.1; // initial value of reaction_45_V
        reaction_46_k1 = 0.01; // initial value of reaction_46_k1
        reaction_47_Km = 0.1; // initial value of reaction_47_Km
        reaction_47_V = 0.1; // initial value of reaction_47_V
        reaction_4_k1 = 0.4; // initial value of reaction_4_k1
        reaction_4_k2 = 0.2; // initial value of reaction_4_k2
        reaction_5_k = 1.6; // initial value of reaction_5_k
        reaction_6_k1 = 0.01; // initial value of reaction_6_k1
        reaction_7_Km = 0.1; // initial value of reaction_7_Km
        reaction_7_V = 0.6; // initial value of reaction_7_V
        reaction_8_Km = 0.3; // initial value of reaction_8_Km
        reaction_8_V = 0.7; // initial value of reaction_8_V
        reaction_9_K = 0.7; // initial value of reaction_9_K
        reaction_9_Vs = 1.5; // initial value of reaction_9_Vs
        reaction_9_n = 4.0; // initial value of reaction_9_n
    }

    /*
     * Model variables initial values
     */
    protected double rate_reaction_0;
    protected double rate_reaction_1;
    protected double rate_reaction_10;
    protected double rate_reaction_11;
    protected double rate_reaction_12;
    protected double rate_reaction_13;
    protected double rate_reaction_14;
    protected double rate_reaction_15;
    protected double rate_reaction_16;
    protected double rate_reaction_17;
    protected double rate_reaction_18;
    protected double rate_reaction_19;
    protected double rate_reaction_2;
    protected double rate_reaction_20;
    protected double rate_reaction_21;
    protected double rate_reaction_22;
    protected double rate_reaction_23;
    protected double rate_reaction_24;
    protected double rate_reaction_25;
    protected double rate_reaction_26;
    protected double rate_reaction_27;
    protected double rate_reaction_28;
    protected double rate_reaction_29;
    protected double rate_reaction_3;
    protected double rate_reaction_30;
    protected double rate_reaction_31;
    protected double rate_reaction_32;
    protected double rate_reaction_33;
    protected double rate_reaction_34;
    protected double rate_reaction_35;
    protected double rate_reaction_36;
    protected double rate_reaction_37;
    protected double rate_reaction_38;
    protected double rate_reaction_39;
    protected double rate_reaction_4;
    protected double rate_reaction_40;
    protected double rate_reaction_41;
    protected double rate_reaction_42;
    protected double rate_reaction_43;
    protected double rate_reaction_44;
    protected double rate_reaction_45;
    protected double rate_reaction_46;
    protected double rate_reaction_47;
    protected double rate_reaction_5;
    protected double rate_reaction_6;
    protected double rate_reaction_7;
    protected double rate_reaction_8;
    protected double rate_reaction_9;
    protected double cell;
    protected double reaction_0_K;
    protected double reaction_0_m;
    protected double reaction_0_vsb;
    protected double reaction_10_k;
    protected double reaction_11_Km;
    protected double reaction_11_V;
    protected double reaction_12_Km;
    protected double reaction_12_V;
    protected double reaction_13_k1;
    protected double reaction_13_k2;
    protected double reaction_14_Km;
    protected double reaction_14_V;
    protected double reaction_15_Km;
    protected double reaction_15_V;
    protected double reaction_16_k1;
    protected double reaction_16_k2;
    protected double reaction_17_k1;
    protected double reaction_18_k1;
    protected double reaction_19_k1;
    protected double reaction_1_k;
    protected double reaction_20_K;
    protected double reaction_20_Vs;
    protected double reaction_20_n;
    protected double reaction_21_Km;
    protected double reaction_21_V;
    protected double reaction_22_k1;
    protected double reaction_23_k1;
    protected double reaction_23_k2;
    protected double reaction_24_Km;
    protected double reaction_24_V;
    protected double reaction_25_Km;
    protected double reaction_25_V;
    protected double reaction_26_Km;
    protected double reaction_26_V;
    protected double reaction_27_k1;
    protected double reaction_28_k1;
    protected double reaction_29_k1;
    protected double reaction_2_k1;
    protected double reaction_30_k1;
    protected double reaction_31_k1;
    protected double reaction_32_k1;
    protected double reaction_33_Km;
    protected double reaction_33_V;
    protected double reaction_34_k1;
    protected double reaction_35_Km;
    protected double reaction_35_V;
    protected double reaction_36_Km;
    protected double reaction_36_V;
    protected double reaction_37_Km;
    protected double reaction_37_V;
    protected double reaction_38_k1;
    protected double reaction_39_Km;
    protected double reaction_39_V;
    protected double reaction_3_Km;
    protected double reaction_3_V;
    protected double reaction_40_k1;
    protected double reaction_41_Km;
    protected double reaction_41_V;
    protected double reaction_42_Km;
    protected double reaction_42_V;
    protected double reaction_43_Km;
    protected double reaction_43_V;
    protected double reaction_44_Km;
    protected double reaction_44_V;
    protected double reaction_45_Km;
    protected double reaction_45_V;
    protected double reaction_46_k1;
    protected double reaction_47_Km;
    protected double reaction_47_V;
    protected double reaction_4_k1;
    protected double reaction_4_k2;
    protected double reaction_5_k;
    protected double reaction_6_k1;
    protected double reaction_7_Km;
    protected double reaction_7_V;
    protected double reaction_8_Km;
    protected double reaction_8_V;
    protected double reaction_9_K;
    protected double reaction_9_Vs;
    protected double reaction_9_n;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[16];
        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];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[16];
        this.time = 0.0;
        x[0] = 9.0; // - $"cell.species_0"
        x[1] = 2.0; // - $"cell.species_1"
        x[2] = 0.0; // - $"cell.species_10"
        x[3] = 0.0; // - $"cell.species_11"
        x[4] = 1.0; // - $"cell.species_12"
        x[5] = 0.0; // - $"cell.species_13"
        x[6] = 0.0; // - $"cell.species_14"
        x[7] = 0.0; // - $"cell.species_15"
        x[8] = 0.0; // - $"cell.species_2"
        x[9] = 1.9; // - $"cell.species_3"
        x[10] = 0.0; // - $"cell.species_4"
        x[11] = 1.4; // - $"cell.species_5"
        x[12] = 0.0; // - $"cell.species_6"
        x[13] = 1.6; // - $"cell.species_7"
        x[14] = 0.0; // - $"cell.species_8"
        x[15] = 0.0; // - $"cell.species_9"

        __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)
    {

        __internalRateVarInitFunc_0(time, x);
        __internalRateVarInitFunc_1(time, x);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000073.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_reaction_0-rate_reaction_24-rate_reaction_2;
        result[1] = +rate_reaction_1-rate_reaction_34-rate_reaction_3+rate_reaction_41-rate_reaction_4;
        result[2] = +rate_reaction_13-rate_reaction_14-rate_reaction_16-rate_reaction_32+rate_reaction_47;
        result[3] = +rate_reaction_14-rate_reaction_15-rate_reaction_31-rate_reaction_47;
        result[4] = +rate_reaction_16-rate_reaction_21-rate_reaction_23+rate_reaction_45-rate_reaction_46;
        result[5] = -rate_reaction_19+rate_reaction_36-rate_reaction_37-rate_reaction_42;
        result[6] = -rate_reaction_17+rate_reaction_21-rate_reaction_33-rate_reaction_45;
        result[7] = +rate_reaction_23-rate_reaction_38-rate_reaction_39;
        result[8] = -rate_reaction_18-rate_reaction_35+rate_reaction_3-rate_reaction_41;
        result[9] = -rate_reaction_23-rate_reaction_36-rate_reaction_40+rate_reaction_42+rate_reaction_4;
        result[10] = -rate_reaction_13-rate_reaction_28+rate_reaction_43+rate_reaction_5-rate_reaction_7;
        result[11] = +rate_reaction_20-rate_reaction_25-rate_reaction_6;
        result[12] = -rate_reaction_30-rate_reaction_43+rate_reaction_7-rate_reaction_8;
        result[13] = -rate_reaction_22-rate_reaction_26+rate_reaction_9;
        result[14] = +rate_reaction_10-rate_reaction_12-rate_reaction_13-rate_reaction_27+rate_reaction_44;
        result[15] = -rate_reaction_11+rate_reaction_12-rate_reaction_29-rate_reaction_44;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[16];
        __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 );
    }

    protected double function_0(double vsb, double K, double m, double Bn)
    {
         return vsb*Math.pow(K, m)/(Math.pow(K, m) + Math.pow(Bn, m));
    }
    protected double function_1(double k, double mRNA)
    {
         return k*mRNA;
    }
    protected double function_2(double V, double substrate, double Km)
    {
         return V*substrate/(Km + substrate);
    }
    protected double function_3(double Vs, double B, double n, double K)
    {
         return Vs*Math.pow(B, n)/(Math.pow(K, n) + Math.pow(B, n));
    }
} // class ...