/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000085.xml diagram  at 2008.03.20 15:08:06
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000085 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        parameter_0 = (x[12] + x[2] + x[7] + x[3])/1.0E-8;
        parameter_1 = (25*x[7] + 25*x[3] + 0.013*x[2] + 0.013*x[12])/1.0E-8;
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_reaction_1 = compartment_0*(reaction_1_k1*x[1]*x[10] - reaction_1_k2*x[12]);
        rate_reaction_10 = compartment_0*(reaction_10_k1*x[2] - reaction_10_k2*x[5]*x[14]);
        rate_reaction_11 = compartment_0*(reaction_11_k1*x[5] - reaction_11_k2*x[16]*x[15]);
        rate_reaction_13 = compartment_0*(reaction_13_k1*x[3] - reaction_13_k2*x[4]*x[14]);
        rate_reaction_14 = compartment_0*(reaction_14_k1*x[4] - reaction_14_k2*x[9]*x[15]);
        rate_reaction_16 = compartment_0*(reaction_16_k1*x[9]*x[11] - reaction_16_k2*x[6]);
        rate_reaction_17 = compartment_0*(reaction_17_k1*x[6]*x[10] - reaction_17_k2*x[7]);
        rate_reaction_19 = compartment_0*(reaction_19_k1*x[2]*x[0] - reaction_19_k2*x[7]);
        rate_reaction_20 = compartment_0*(reaction_20_k1*x[7] - reaction_20_k2*x[8]*x[14]);
        rate_reaction_23 = compartment_0*(reaction_23_k1*x[8] - reaction_23_k2*x[6]*x[15]);
        rate_reaction_3 = compartment_0*(reaction_3_k1*x[12] - reaction_3_k2*x[13]*x[14]);
        rate_reaction_4 = compartment_0*(reaction_4_k1*x[13] - reaction_4_k2*x[1]*x[15]);
        rate_reaction_5 = compartment_0*(reaction_5_k1*x[16]*x[10] - reaction_5_k2*x[2]);
        rate_reaction_6 = compartment_0*(reaction_6_k1*x[12]*x[11] - reaction_6_k2*x[2]);
        rate_reaction_7 = compartment_0*(reaction_7_k1*x[12]*x[0] - reaction_7_k2*x[3]);
        rate_reaction_8 = compartment_0*(reaction_8_k1*x[13]*x[0] - reaction_8_k2*x[4]);
        rate_reaction_9 = compartment_0*(reaction_9_k1*x[13]*x[11] - reaction_9_k2*x[5]);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        compartment_0 = 1.0; // initial value of $compartment_0
        reaction_10_k1 = 0.013; // initial value of reaction_10_k1
        reaction_10_k2 = 2.22E-9; // initial value of reaction_10_k2
        reaction_11_k1 = 2.0; // initial value of reaction_11_k1
        reaction_11_k2 = 1470000.0; // initial value of reaction_11_k2
        reaction_13_k1 = 25.0; // initial value of reaction_13_k1
        reaction_13_k2 = 0.244; // initial value of reaction_13_k2
        reaction_14_k1 = 1.0E-4; // initial value of reaction_14_k1
        reaction_14_k2 = 3.83; // initial value of reaction_14_k2
        reaction_16_k1 = 3.96E9; // initial value of reaction_16_k1
        reaction_16_k2 = 5.43E-5; // initial value of reaction_16_k2
        reaction_17_k1 = 1620000.0; // initial value of reaction_17_k1
        reaction_17_k2 = 0.00875; // initial value of reaction_17_k2
        reaction_19_k1 = 6300000.0; // initial value of reaction_19_k1
        reaction_19_k2 = 0.478; // initial value of reaction_19_k2
        reaction_1_k1 = 529000.0; // initial value of reaction_1_k1
        reaction_1_k2 = 8.38E-6; // initial value of reaction_1_k2
        reaction_20_k1 = 25.0; // initial value of reaction_20_k1
        reaction_20_k2 = 0.00297; // initial value of reaction_20_k2
        reaction_23_k1 = 2.75; // initial value of reaction_23_k1
        reaction_23_k2 = 2940.0; // initial value of reaction_23_k2
        reaction_3_k1 = 0.013; // initial value of reaction_3_k1
        reaction_3_k2 = 9.03E-7; // initial value of reaction_3_k2
        reaction_4_k1 = 1.0E-4; // initial value of reaction_4_k1
        reaction_4_k2 = 62.3; // initial value of reaction_4_k2
        reaction_5_k1 = 853000.0; // initial value of reaction_5_k1
        reaction_5_k2 = 0.00468; // initial value of reaction_5_k2
        reaction_6_k1 = 1.32E8; // initial value of reaction_6_k1
        reaction_6_k2 = 1.28; // initial value of reaction_6_k2
        reaction_7_k1 = 386000.0; // initial value of reaction_7_k1
        reaction_7_k2 = 0.0408; // initial value of reaction_7_k2
        reaction_8_k1 = 64100.0; // initial value of reaction_8_k1
        reaction_8_k2 = 0.95; // initial value of reaction_8_k2
        reaction_9_k1 = 9.47E7; // initial value of reaction_9_k1
        reaction_9_k2 = 0.00227; // initial value of reaction_9_k2
    }

    /*
     * Model variables initial values
     */
    protected double rate_reaction_1;
    protected double rate_reaction_10;
    protected double rate_reaction_11;
    protected double rate_reaction_13;
    protected double rate_reaction_14;
    protected double rate_reaction_16;
    protected double rate_reaction_17;
    protected double rate_reaction_19;
    protected double rate_reaction_20;
    protected double rate_reaction_23;
    protected double rate_reaction_3;
    protected double rate_reaction_4;
    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 compartment_0;
    protected double parameter_0;
    protected double parameter_1;
    protected double reaction_10_k1;
    protected double reaction_10_k2;
    protected double reaction_11_k1;
    protected double reaction_11_k2;
    protected double reaction_13_k1;
    protected double reaction_13_k2;
    protected double reaction_14_k1;
    protected double reaction_14_k2;
    protected double reaction_16_k1;
    protected double reaction_16_k2;
    protected double reaction_17_k1;
    protected double reaction_17_k2;
    protected double reaction_19_k1;
    protected double reaction_19_k2;
    protected double reaction_1_k1;
    protected double reaction_1_k2;
    protected double reaction_20_k1;
    protected double reaction_20_k2;
    protected double reaction_23_k1;
    protected double reaction_23_k2;
    protected double reaction_3_k1;
    protected double reaction_3_k2;
    protected double reaction_4_k1;
    protected double reaction_4_k2;
    protected double reaction_5_k1;
    protected double reaction_5_k2;
    protected double reaction_6_k1;
    protected double reaction_6_k2;
    protected double reaction_7_k1;
    protected double reaction_7_k2;
    protected double reaction_8_k1;
    protected double reaction_8_k2;
    protected double reaction_9_k1;
    protected double reaction_9_k2;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[19];
        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] = parameter_0;
        y[18] = parameter_1;
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[17];
        this.time = 0.0;
        x[0] = 0.0; // - $"compartment_0.species_0"
        x[1] = 1.0E-8; // - $"compartment_0.species_1"
        x[2] = 0.0; // - $"compartment_0.species_10"
        x[3] = 0.0; // - $"compartment_0.species_11"
        x[4] = 0.0; // - $"compartment_0.species_12"
        x[5] = 0.0; // - $"compartment_0.species_13"
        x[6] = 0.0; // - $"compartment_0.species_14"
        x[7] = 0.0; // - $"compartment_0.species_15"
        x[8] = 0.0; // - $"compartment_0.species_16"
        x[9] = 0.0; // - $"compartment_0.species_2"
        x[10] = 4.68E-4; // - $"compartment_0.species_3"
        x[11] = 1.0E-5; // - $"compartment_0.species_4"
        x[12] = 0.0; // - $"compartment_0.species_5"
        x[13] = 0.0; // - $"compartment_0.species_6"
        x[14] = 0.0044; // - $"compartment_0.species_7"
        x[15] = 1.49E-4; // - $"compartment_0.species_8"
        x[16] = 0.0; // - $"compartment_0.species_9"

        __internalVarInitFunc_0(time, x);
        __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)
    {

        __internalVarInitFunc_0(time, x);
        __internalRateVarInitFunc_0(time, x);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000085.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_reaction_19-rate_reaction_7-rate_reaction_8;
        result[1] = -rate_reaction_1+rate_reaction_4;
        result[2] = -rate_reaction_10-rate_reaction_19+rate_reaction_5+rate_reaction_6;
        result[3] = -rate_reaction_13+rate_reaction_7;
        result[4] = +rate_reaction_13-rate_reaction_14+rate_reaction_8;
        result[5] = +rate_reaction_10-rate_reaction_11+rate_reaction_9;
        result[6] = +rate_reaction_16-rate_reaction_17+rate_reaction_23;
        result[7] = +rate_reaction_17+rate_reaction_19-rate_reaction_20;
        result[8] = +rate_reaction_20-rate_reaction_23;
        result[9] = +rate_reaction_14-rate_reaction_16;
        result[10] = -rate_reaction_17-rate_reaction_1-rate_reaction_5;
        result[11] = -rate_reaction_16-rate_reaction_6-rate_reaction_9;
        result[12] = +rate_reaction_1-rate_reaction_3-rate_reaction_6-rate_reaction_7;
        result[13] = +rate_reaction_3-rate_reaction_4-rate_reaction_8-rate_reaction_9;
        result[14] = +rate_reaction_10+rate_reaction_13+rate_reaction_20+rate_reaction_3;
        result[15] = +rate_reaction_11+rate_reaction_14+rate_reaction_23+rate_reaction_4;
        result[16] = +rate_reaction_11-rate_reaction_5;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[17];
        __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 ...