/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000089.xml diagram  at 2008.03.20 15:08:19
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000089 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 = compartment*function_1(m1, x[4], k1);
        rate_reaction_1 = compartment*Math.pow(g0, alpha)/(Math.pow(g0, alpha) + Math.pow(x[2], alpha))*(light*(q1*x[6] + n0) + n1*Math.pow(x[12], a)/(Math.pow(g1, a) + Math.pow(x[12], a)));
        rate_reaction_10 = compartment*function_1(m14, x[15], k12);
        rate_reaction_11 = compartment*p4*x[14];
        rate_reaction_12 = compartment*function_1(m13, x[13], k11);
        rate_reaction_13 = compartment*(r5*x[10] - r6*x[12]);
        rate_reaction_14 = compartment*function_1(m10, x[10], k8);
        rate_reaction_15 = compartment*p3*x[11];
        rate_reaction_16 = compartment*function_1(m11, x[12], k9);
        rate_reaction_17 = compartment*p6*x[1];
        rate_reaction_18 = compartment*(r9*x[0] - r10*x[2]);
        rate_reaction_19 = compartment*function_1(m17, x[0], k15);
        rate_reaction_2 = compartment*p1*x[4];
        rate_reaction_20 = compartment*function_1(m18, x[2], k16);
        rate_reaction_21 = (1 - light)*p5*compartment;
        rate_reaction_22 = q3*light*x[6]*compartment;
        rate_reaction_23 = compartment*m15*x[6]/(k13 + x[6]);
        rate_reaction_25 = light*q4*x[6]*compartment;
        rate_reaction_26 = compartment*n6*Math.pow(x[5], g)/(Math.pow(g7, g) + Math.pow(x[5], g));
        rate_reaction_27 = compartment*m16*x[1]/(k14 + x[1]);
        rate_reaction_28 = compartment*n3*Math.pow(x[9], d)/(Math.pow(g4, d) + Math.pow(x[9], d));
        rate_reaction_29 = compartment*m9*x[11]/(k7 + x[11]);
        rate_reaction_3 = compartment*(r1*x[3] - r2*x[5]);
        rate_reaction_30 = p2*compartment*x[8];
        rate_reaction_31 = compartment*(-r4*x[9] + r3*x[7]);
        rate_reaction_32 = compartment*(1 - light)*m5*x[7]/(k5 + x[7]);
        rate_reaction_33 = m6*compartment*x[7]/(k5 + x[7]);
        rate_reaction_34 = compartment*(1 - light)*m7*x[9]/(k6 + x[9]);
        rate_reaction_38 = m8*compartment*x[9]/(k6 + x[9]);
        rate_reaction_39 = compartment*(light*q2*x[6] + (light*n4 + n5)*Math.pow(g5, e)/(Math.pow(g5, e) + Math.pow(x[9], e)))*(Math.pow(g6, f)/(Math.pow(g6, f) + Math.pow(x[5], f)));
        rate_reaction_4 = compartment*function_1(m2, x[3], k2);
        rate_reaction_40 = compartment*m12*x[14]/(k10 + x[14]);
        rate_reaction_5 = compartment*function_1(m3, x[5], k3);
        rate_reaction_6 = compartment*n2*Math.pow(x[15], b)/(Math.pow(g2, b) + Math.pow(x[15], b))*(Math.pow(g3, c)/(Math.pow(g3, c) + Math.pow(x[5], c)));
        rate_reaction_7 = compartment*function_1(m4, x[8], k4);
        rate_reaction_9 = compartment*(r7*x[13] - r8*x[15]);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        compartment = 1.0; // initial value of $compartment
        a = 1.2479; // initial value of a
        alpha = 4.0; // initial value of alpha
        b = 1.0258; // initial value of b
        c = 1.0258; // initial value of c
        d = 1.4422; // initial value of d
        e = 3.6064; // initial value of e
        f = 1.0237; // initial value of f
        g = 1.0258; // initial value of g
        g0 = 1.0; // initial value of g0
        g1 = 3.1383; // initial value of g1
        g2 = 0.0368; // initial value of g2
        g3 = 0.2658; // initial value of g3
        g4 = 0.5388; // initial value of g4
        g5 = 1.178; // initial value of g5
        g6 = 0.0645; // initial value of g6
        g7 = 4.0E-4; // initial value of g7
        k1 = 2.392; // initial value of k1
        k10 = 1.7303; // initial value of k10
        k11 = 1.8258; // initial value of k11
        k12 = 1.8066; // initial value of k12
        k13 = 1.2; // initial value of k13
        k14 = 10.3617; // initial value of k14
        k15 = 0.0703; // initial value of k15
        k16 = 0.6104; // initial value of k16
        k2 = 1.5644; // initial value of k2
        k3 = 1.2765; // initial value of k3
        k4 = 2.5734; // initial value of k4
        k5 = 2.7454; // initial value of k5
        k6 = 0.4033; // initial value of k6
        k7 = 6.5585; // initial value of k7
        k8 = 0.6632; // initial value of k8
        k9 = 17.1111; // initial value of k9
        light = 1.0; // initial value of light
        m1 = 1.999; // initial value of m1
        m10 = 0.2179; // initial value of m10
        m11 = 3.3442; // initial value of m11
        m12 = 4.297; // initial value of m12
        m13 = 0.1347; // initial value of m13
        m14 = 0.6114; // initial value of m14
        m15 = 1.2; // initial value of m15
        m16 = 12.2398; // initial value of m16
        m17 = 4.4505; // initial value of m17
        m18 = 0.0156; // initial value of m18
        m2 = 20.44; // initial value of m2
        m3 = 3.6888; // initial value of m3
        m4 = 3.8231; // initial value of m4
        m5 = 0.0013; // initial value of m5
        m6 = 3.1741; // initial value of m6
        m7 = 0.0492; // initial value of m7
        m8 = 4.0424; // initial value of m8
        m9 = 10.1132; // initial value of m9
        n0 = 0.05; // initial value of n0
        n1 = 7.8142; // initial value of n1
        n2 = 3.0087; // initial value of n2
        n3 = 0.2431; // initial value of n3
        n4 = 0.0857; // initial value of n4
        n5 = 0.1649; // initial value of n5
        n6 = 8.0706; // initial value of n6
        p1 = 0.8295; // initial value of p1
        p2 = 4.324; // initial value of p2
        p3 = 2.147; // initial value of p3
        p4 = 0.2485; // initial value of p4
        p5 = 0.5; // initial value of p5
        p6 = 0.2907; // initial value of p6
        q1 = 4.1954; // initial value of q1
        q2 = 2.4017; // initial value of q2
        q3 = 1.0; // initial value of q3
        q4 = 2.4514; // initial value of q4
        r1 = 16.8363; // initial value of r1
        r10 = 0.2212; // initial value of r10
        r2 = 0.1687; // initial value of r2
        r3 = 0.3166; // initial value of r3
        r4 = 2.1509; // initial value of r4
        r5 = 1.0352; // initial value of r5
        r6 = 3.3017; // initial value of r6
        r7 = 2.2123; // initial value of r7
        r8 = 0.2002; // initial value of r8
        r9 = 0.2528; // initial value of r9
    }

    /*
     * 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_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_38;
    protected double rate_reaction_39;
    protected double rate_reaction_4;
    protected double rate_reaction_40;
    protected double rate_reaction_5;
    protected double rate_reaction_6;
    protected double rate_reaction_7;
    protected double rate_reaction_9;
    protected double compartment;
    protected double a;
    protected double alpha;
    protected double b;
    protected double c;
    protected double d;
    protected double e;
    protected double f;
    protected double g;
    protected double g0;
    protected double g1;
    protected double g2;
    protected double g3;
    protected double g4;
    protected double g5;
    protected double g6;
    protected double g7;
    protected double k1;
    protected double k10;
    protected double k11;
    protected double k12;
    protected double k13;
    protected double k14;
    protected double k15;
    protected double k16;
    protected double k2;
    protected double k3;
    protected double k4;
    protected double k5;
    protected double k6;
    protected double k7;
    protected double k8;
    protected double k9;
    protected double light;
    protected double m1;
    protected double m10;
    protected double m11;
    protected double m12;
    protected double m13;
    protected double m14;
    protected double m15;
    protected double m16;
    protected double m17;
    protected double m18;
    protected double m2;
    protected double m3;
    protected double m4;
    protected double m5;
    protected double m6;
    protected double m7;
    protected double m8;
    protected double m9;
    protected double n0;
    protected double n1;
    protected double n2;
    protected double n3;
    protected double n4;
    protected double n5;
    protected double n6;
    protected double p1;
    protected double p2;
    protected double p3;
    protected double p4;
    protected double p5;
    protected double p6;
    protected double q1;
    protected double q2;
    protected double q3;
    protected double q4;
    protected double r1;
    protected double r10;
    protected double r2;
    protected double r3;
    protected double r4;
    protected double r5;
    protected double r6;
    protected double r7;
    protected double r8;
    protected double r9;

    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] = 0.7027; // - $"compartment.cAc"
        x[1] = 14.6921; // - $"compartment.cAm"
        x[2] = 0.8648; // - $"compartment.cAn"
        x[3] = 0.0132; // - $"compartment.cLc"
        x[4] = 0.4625; // - $"compartment.cLm"
        x[5] = 0.0699; // - $"compartment.cLn"
        x[6] = 0.8476; // - $"compartment.cPn"
        x[7] = 10.2965; // - $"compartment.cTc"
        x[8] = 0.4303; // - $"compartment.cTm"
        x[9] = 0.5402; // - $"compartment.cTn"
        x[10] = 1.5413; // - $"compartment.cXc"
        x[11] = 0.0957; // - $"compartment.cXm"
        x[12] = 0.4585; // - $"compartment.cXn"
        x[13] = 0.0041; // - $"compartment.cYc"
        x[14] = 0.0303; // - $"compartment.cYm"
        x[15] = 0.0122; // - $"compartment.cYn"

        __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 'BIOMD0000000089.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_reaction_17-rate_reaction_18-rate_reaction_19;
        result[1] = +rate_reaction_25+rate_reaction_26-rate_reaction_27;
        result[2] = +rate_reaction_18-rate_reaction_20;
        result[3] = +rate_reaction_2-rate_reaction_3-rate_reaction_4;
        result[4] = -rate_reaction_0+rate_reaction_1;
        result[5] = +rate_reaction_3-rate_reaction_5;
        result[6] = +rate_reaction_21-rate_reaction_22-rate_reaction_23;
        result[7] = +rate_reaction_30-rate_reaction_31-rate_reaction_32-rate_reaction_33;
        result[8] = +rate_reaction_6-rate_reaction_7;
        result[9] = +rate_reaction_31-rate_reaction_34-rate_reaction_38;
        result[10] = -rate_reaction_13-rate_reaction_14+rate_reaction_15;
        result[11] = +rate_reaction_28-rate_reaction_29;
        result[12] = +rate_reaction_13-rate_reaction_16;
        result[13] = +rate_reaction_11-rate_reaction_12-rate_reaction_9;
        result[14] = +rate_reaction_39-rate_reaction_40;
        result[15] = -rate_reaction_10+rate_reaction_9;
    }
    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_1(double V, double substrate, double Km)
    {
         return V*substrate/(Km + substrate);
    }
} // class ...