/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000009.xml diagram  at 2008.03.20 15:03:20
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000009 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_r10a = compartment*(r10a_a10*(x[10]/compartment)*(x[7]/compartment) - r10a_d10*(x[8]/compartment));
        rate_r10b = compartment*r10b_k10*(x[8]/compartment);
        rate_r1a = compartment*(r1a_a1*(x[19]/compartment)*(x[3]/compartment) - r1a_d1*(x[0]/compartment));
        rate_r1b = compartment*r1b_k2*(x[0]/compartment);
        rate_r2a = compartment*(r2a_a2*(x[20]/compartment)*(x[16]/compartment) - r2a_d2*(x[1]/compartment));
        rate_r2b = compartment*r2b_k2*(x[1]/compartment);
        rate_r3a = compartment*(r3a_a3*(x[21]/compartment)*(x[16]/compartment) - r3a_d3*(x[17]/compartment));
        rate_r3b = compartment*r3b_k3*(x[17]/compartment);
        rate_r4a = compartment*(r4a_a4*(x[15]/compartment)*(x[4]/compartment) - r4a_d4*(x[6]/compartment));
        rate_r4b = compartment*r4b_k4*(x[6]/compartment);
        rate_r5a = compartment*(r5a_a5*(x[15]/compartment)*(x[16]/compartment) - r5a_d5*(x[18]/compartment));
        rate_r5b = compartment*r5b_k5*(x[18]/compartment);
        rate_r6a = compartment*(r6a_a6*(x[11]/compartment)*(x[4]/compartment) - r6a_d6*(x[5]/compartment));
        rate_r6b = compartment*r6b_k6*(x[5]/compartment);
        rate_r7a = compartment*(r7a_a7*(x[2]/compartment)*(x[11]/compartment) - r7a_d7*(x[12]/compartment));
        rate_r7b = compartment*r7b_k7*(x[12]/compartment);
        rate_r8a = compartment*(r8a_a8*(x[14]/compartment)*(x[7]/compartment) - r8a_d8*(x[9]/compartment));
        rate_r8b = compartment*r8b_k8*(x[9]/compartment);
        rate_r9a = compartment*(r9a_a9*(x[14]/compartment)*(x[11]/compartment) - r9a_d9*(x[13]/compartment));
        rate_r9b = compartment*r9b_k9*(x[13]/compartment);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        compartment = 4.0E-12; // initial value of $compartment
        r10a_a10 = 1000.0; // initial value of r10a_a10
        r10a_d10 = 150.0; // initial value of r10a_d10
        r10b_k10 = 150.0; // initial value of r10b_k10
        r1a_a1 = 1000.0; // initial value of r1a_a1
        r1a_d1 = 150.0; // initial value of r1a_d1
        r1b_k2 = 150.0; // initial value of r1b_k2
        r2a_a2 = 1000.0; // initial value of r2a_a2
        r2a_d2 = 150.0; // initial value of r2a_d2
        r2b_k2 = 150.0; // initial value of r2b_k2
        r3a_a3 = 1000.0; // initial value of r3a_a3
        r3a_d3 = 150.0; // initial value of r3a_d3
        r3b_k3 = 150.0; // initial value of r3b_k3
        r4a_a4 = 1000.0; // initial value of r4a_a4
        r4a_d4 = 150.0; // initial value of r4a_d4
        r4b_k4 = 150.0; // initial value of r4b_k4
        r5a_a5 = 1000.0; // initial value of r5a_a5
        r5a_d5 = 150.0; // initial value of r5a_d5
        r5b_k5 = 150.0; // initial value of r5b_k5
        r6a_a6 = 1000.0; // initial value of r6a_a6
        r6a_d6 = 150.0; // initial value of r6a_d6
        r6b_k6 = 150.0; // initial value of r6b_k6
        r7a_a7 = 1000.0; // initial value of r7a_a7
        r7a_d7 = 150.0; // initial value of r7a_d7
        r7b_k7 = 150.0; // initial value of r7b_k7
        r8a_a8 = 1000.0; // initial value of r8a_a8
        r8a_d8 = 150.0; // initial value of r8a_d8
        r8b_k8 = 150.0; // initial value of r8b_k8
        r9a_a9 = 1000.0; // initial value of r9a_a9
        r9a_d9 = 150.0; // initial value of r9a_d9
        r9b_k9 = 150.0; // initial value of r9b_k9
    }

    /*
     * Model variables initial values
     */
    protected double rate_r10a;
    protected double rate_r10b;
    protected double rate_r1a;
    protected double rate_r1b;
    protected double rate_r2a;
    protected double rate_r2b;
    protected double rate_r3a;
    protected double rate_r3b;
    protected double rate_r4a;
    protected double rate_r4b;
    protected double rate_r5a;
    protected double rate_r5b;
    protected double rate_r6a;
    protected double rate_r6b;
    protected double rate_r7a;
    protected double rate_r7b;
    protected double rate_r8a;
    protected double rate_r8b;
    protected double rate_r9a;
    protected double rate_r9b;
    protected double compartment;
    protected double r10a_a10;
    protected double r10a_d10;
    protected double r10b_k10;
    protected double r1a_a1;
    protected double r1a_d1;
    protected double r1b_k2;
    protected double r2a_a2;
    protected double r2a_d2;
    protected double r2b_k2;
    protected double r3a_a3;
    protected double r3a_d3;
    protected double r3b_k3;
    protected double r4a_a4;
    protected double r4a_d4;
    protected double r4b_k4;
    protected double r5a_a5;
    protected double r5a_d5;
    protected double r5b_k5;
    protected double r6a_a6;
    protected double r6a_d6;
    protected double r6b_k6;
    protected double r7a_a7;
    protected double r7a_d7;
    protected double r7b_k7;
    protected double r8a_a8;
    protected double r8a_d8;
    protected double r8b_k8;
    protected double r9a_a9;
    protected double r9a_d9;
    protected double r9b_k9;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[22];
        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];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[22];
        this.time = 0.0;
        x[0] = 0.0; // - $"compartment.E1_KKK"
        x[1] = 0.0; // - $"compartment.E2_P_KKK"
        x[2] = 4.8E-12; // - $"compartment.K"
        x[3] = 1.2E-14; // - $"compartment.KKK"
        x[4] = 1.1999999999999998E-15; // - $"compartment.KKPase"
        x[5] = 0.0; // - $"compartment.KKPase_PP_KK"
        x[6] = 0.0; // - $"compartment.KKPase_P_KK"
        x[7] = 4.8E-13; // - $"compartment.KPase"
        x[8] = 0.0; // - $"compartment.KPase_PP_K"
        x[9] = 0.0; // - $"compartment.KPase_P_K"
        x[10] = 0.0; // - $"compartment.PP_K"
        x[11] = 0.0; // - $"compartment.PP_KK"
        x[12] = 0.0; // - $"compartment.PP_KK_K"
        x[13] = 0.0; // - $"compartment.PP_KK_P_K"
        x[14] = 0.0; // - $"compartment.P_K"
        x[15] = 0.0; // - $"compartment.P_KK"
        x[16] = 0.0; // - $"compartment.P_KKK"
        x[17] = 0.0; // - $"compartment.P_KKK_KK"
        x[18] = 0.0; // - $"compartment.P_KKK_P_KK"
        x[19] = 1.2E-16; // - $compartment.E1
        x[20] = 1.1999999999999998E-15; // - $compartment.E2
        x[21] = 4.8E-12; // - $compartment.KK

        __internalRateVarInitFunc_0(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);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000009.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_r1a-rate_r1b;
        result[1] = +rate_r2a-rate_r2b;
        result[2] = -rate_r7a+rate_r8b;
        result[3] = -rate_r1a+rate_r2b;
        result[4] = -rate_r4a+rate_r4b-rate_r6a+rate_r6b;
        result[5] = +rate_r6a-rate_r6b;
        result[6] = +rate_r4a-rate_r4b;
        result[7] = -rate_r10a+rate_r10b-rate_r8a+rate_r8b;
        result[8] = +rate_r10a-rate_r10b;
        result[9] = +rate_r8a-rate_r8b;
        result[10] = -rate_r10a+rate_r9b;
        result[11] = +rate_r5b-rate_r6a-rate_r7a+rate_r7b-rate_r9a+rate_r9b;
        result[12] = +rate_r7a-rate_r7b;
        result[13] = +rate_r9a-rate_r9b;
        result[14] = +rate_r10b+rate_r7b-rate_r8a-rate_r9a;
        result[15] = +rate_r3b-rate_r4a-rate_r5a+rate_r6b;
        result[16] = +rate_r1b-rate_r2a-rate_r3a+rate_r3b-rate_r5a+rate_r5b;
        result[17] = +rate_r3a-rate_r3b;
        result[18] = +rate_r5a-rate_r5b;
        result[19] = -rate_r1a+rate_r1b;
        result[20] = -rate_r2a+rate_r2b;
        result[21] = -rate_r3a+rate_r4b;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[22];
        __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 ...