/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000106.xml diagram  at 2008.03.20 15:08:42
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000106 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_R1 = cell*K15*_cell_x15_*lin*(1 + x[13]/KI19 + x[11]/KI20 + x[3]/KI21 + x[1]/KI22)/(lin + k15*(1 + x[10]/ks));
        rate_R10 = cell*K21*x[8]*x[10]/(x[10] + k21*(1 + x[14]/ki7 + x[12]/ki8 + x[16]/ki11 + x[1]/ki12 + x[0]/ks));
        rate_R11 = cell*K24*_cell_x24_*x[0]/(x[0] + k24*(1 + x[1]/ks));
        rate_R12 = cell*K21*x[8]*x[0]/(x[0] + k21*(1 + x[14]/ki7 + x[12]/ki8 + x[16]/ki11 + x[1]/ki12 + x[2]/ks));
        rate_R13 = cell*K22*x[9]*x[2]/(x[2] + k22*(1 + x[3]/ks));
        rate_R14 = cell*K23*_cell_x23_*x[3]/(x[3] + k23*(1 + x[14]/ki14 + x[1]/ki15 + x[4]/ks));
        rate_R16 = cell*a24*x[16]*x[16]/(x[16]*x[16] + KI24*KI24);
        rate_R17 = cell*ki17*x[11]*x[6];
        rate_R18 = kd9*x[18]*cell;
        rate_R19 = cell*ki5*x[15]*x[7];
        rate_R2 = cell*K16*x[5]*x[10]/(x[10] + k16*(1 + x[11]/ks));
        rate_R20 = ki4*x[11]*x[7]*cell;
        rate_R21 = cell*KI23*x[3]*x[8];
        rate_R22 = cell*K22*x[9]*x[2]/((x[2] + k22)*129);
        rate_R23 = cell*x[2]*kd12;
        rate_R24 = cell*kd13*x[3];
        rate_R25 = cell*kd8*x[17];
        rate_R26 = kd3*x[12]*cell;
        rate_R27 = kd2*cell*x[11];
        rate_R28 = cell*kd16*x[5];
        rate_R29 = kd11*x[1]*cell;
        rate_R3 = cell*K24*_cell_x24_*x[11]/(x[11] + k24*(1 + x[12]/ks));
        rate_R30 = cell*ki9*x[2]*x[8];
        rate_R31 = cell*ki10*x[0]*x[8];
        rate_R32 = cell*ki6*x[8]*x[11];
        rate_R34 = 0.1*x[10]*cell;
        rate_R4 = cell*K17*x[6]*x[10]/(x[10] + k17*(1 + x[13]/ki18 + x[12]/ki16 + x[13]/ks));
        rate_R5 = cell*K24*_cell_x24_*x[13]/(x[13] + k24*(1 + x[14]/ks));
        rate_R6 = cell*K18*_cell_x18_*x[10]/(x[10] + k18*(1 + x[16]/ki3 + x[15]/ks));
        rate_R7 = cell*K19*_cell_x19_*x[15]/(x[15] + k19*(1 + x[10]/ki1 + x[12]/ki2 + x[16]/ks));
        rate_R8 = cell*K20*x[7]*x[15]/(x[15] + k20*(1 + x[17]/ks));
        rate_R9 = kd8*x[17]*cell;
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        _cell_x15_ = 1.5; // initial value of $"cell.x15"
        _cell_x18_ = 0.2; // initial value of $"cell.x18"
        _cell_x19_ = 0.5; // initial value of $"cell.x19"
        _cell_x23_ = 0.07; // initial value of $"cell.x23"
        _cell_x24_ = 0.8; // initial value of $"cell.x24"
        cell = 1.0; // initial value of $cell
        K15 = 3600.0; // initial value of K15
        K16 = 1000.0; // initial value of K16
        K17 = 1000.0; // initial value of K17
        K18 = 1000.0; // initial value of K18
        K19 = 3000.0; // initial value of K19
        K20 = 1599.0; // initial value of K20
        K21 = 5000.0; // initial value of K21
        K22 = 125.0; // initial value of K22
        K23 = 150.0; // initial value of K23
        K24 = 500.0; // initial value of K24
        KI19 = 500.0; // initial value of KI19
        KI20 = 200.0; // initial value of KI20
        KI21 = 500.0; // initial value of KI21
        KI22 = 500.0; // initial value of KI22
        KI23 = 0.053; // initial value of KI23
        KI24 = 2.3E-5; // initial value of KI24
        a24 = 0.15; // initial value of a24
        k15 = 2600.0; // initial value of k15
        k16 = 70.0; // initial value of k16
        k17 = 50.0; // initial value of k17
        k18 = 50.0; // initial value of k18
        k19 = 160.0; // initial value of k19
        k20 = 4.0; // initial value of k20
        k21 = 5.0; // initial value of k21
        k22 = 20.0; // initial value of k22
        k23 = 3.9; // initial value of k23
        k24 = 70.0; // initial value of k24
        kd11 = 0.0010; // initial value of kd11
        kd12 = 0.07; // initial value of kd12
        kd13 = 0.01; // initial value of kd13
        kd16 = 0.01; // initial value of kd16
        kd2 = 0.05; // initial value of kd2
        kd3 = 0.01; // initial value of kd3
        kd8 = 0.1; // initial value of kd8
        kd9 = 0.0010; // initial value of kd9
        ki1 = 0.3; // initial value of ki1
        ki10 = 0.01; // initial value of ki10
        ki11 = 15.0; // initial value of ki11
        ki12 = 6.3; // initial value of ki12
        ki14 = 0.2; // initial value of ki14
        ki15 = 0.86; // initial value of ki15
        ki16 = 10.0; // initial value of ki16
        ki17 = 10.0; // initial value of ki17
        ki18 = 10.0; // initial value of ki18
        ki2 = 30.0; // initial value of ki2
        ki3 = 30.0; // initial value of ki3
        ki4 = 0.6; // initial value of ki4
        ki5 = 0.1; // initial value of ki5
        ki6 = 0.01; // initial value of ki6
        ki7 = 30.0; // initial value of ki7
        ki8 = 4.0; // initial value of ki8
        ki9 = 0.175; // initial value of ki9
        ks = 500.0; // initial value of ks
        lin = 12.0; // initial value of lin
    }

    /*
     * Model variables initial values
     */
    protected double _cell_x15_;
    protected double _cell_x18_;
    protected double _cell_x19_;
    protected double _cell_x23_;
    protected double _cell_x24_;
    protected double rate_R1;
    protected double rate_R10;
    protected double rate_R11;
    protected double rate_R12;
    protected double rate_R13;
    protected double rate_R14;
    protected double rate_R16;
    protected double rate_R17;
    protected double rate_R18;
    protected double rate_R19;
    protected double rate_R2;
    protected double rate_R20;
    protected double rate_R21;
    protected double rate_R22;
    protected double rate_R23;
    protected double rate_R24;
    protected double rate_R25;
    protected double rate_R26;
    protected double rate_R27;
    protected double rate_R28;
    protected double rate_R29;
    protected double rate_R3;
    protected double rate_R30;
    protected double rate_R31;
    protected double rate_R32;
    protected double rate_R34;
    protected double rate_R4;
    protected double rate_R5;
    protected double rate_R6;
    protected double rate_R7;
    protected double rate_R8;
    protected double rate_R9;
    protected double cell;
    protected double K15;
    protected double K16;
    protected double K17;
    protected double K18;
    protected double K19;
    protected double K20;
    protected double K21;
    protected double K22;
    protected double K23;
    protected double K24;
    protected double KI19;
    protected double KI20;
    protected double KI21;
    protected double KI22;
    protected double KI23;
    protected double KI24;
    protected double a24;
    protected double k15;
    protected double k16;
    protected double k17;
    protected double k18;
    protected double k19;
    protected double k20;
    protected double k21;
    protected double k22;
    protected double k23;
    protected double k24;
    protected double kd11;
    protected double kd12;
    protected double kd13;
    protected double kd16;
    protected double kd2;
    protected double kd3;
    protected double kd8;
    protected double kd9;
    protected double ki1;
    protected double ki10;
    protected double ki11;
    protected double ki12;
    protected double ki14;
    protected double ki15;
    protected double ki16;
    protected double ki17;
    protected double ki18;
    protected double ki2;
    protected double ki3;
    protected double ki4;
    protected double ki5;
    protected double ki6;
    protected double ki7;
    protected double ki8;
    protected double ki9;
    protected double ks;
    protected double lin;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        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] = x[17];
        y[18] = x[18];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[19];
        this.time = 0.0;
        x[0] = 0.0010; // - $"cell.x10"
        x[1] = 0.0010; // - $"cell.x11"
        x[2] = 0.0010; // - $"cell.x12"
        x[3] = 0.0010; // - $"cell.x13"
        x[4] = 0.0010; // - $"cell.x14"
        x[5] = 1.5; // - $"cell.x16"
        x[6] = 0.5; // - $"cell.x17"
        x[7] = 0.5; // - $"cell.x20"
        x[8] = 5.0; // - $"cell.x21"
        x[9] = 0.76; // - $"cell.x22"
        x[10] = 0.0010; // - $cell.x1
        x[11] = 0.0010; // - $cell.x2
        x[12] = 0.0010; // - $cell.x3
        x[13] = 0.0010; // - $cell.x4
        x[14] = 0.0010; // - $cell.x5
        x[15] = 0.0010; // - $cell.x6
        x[16] = 0.0010; // - $cell.x7
        x[17] = 0.0010; // - $cell.x8
        x[18] = 0.0010; // - $cell.x9

        __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 'BIOMD0000000106.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_R10-rate_R11-rate_R12;
        result[1] = +rate_R11-rate_R29;
        result[2] = +rate_R12-rate_R13-rate_R23;
        result[3] = +rate_R13-rate_R14-rate_R24;
        result[4] = +rate_R14;
        result[5] = +rate_R16-rate_R28;
        result[6] = -rate_R17;
        result[7] = -rate_R19-rate_R20;
        result[8] = +rate_R21-rate_R30-rate_R31-rate_R32;
        result[9] = -rate_R22;
        result[10] = -rate_R10+rate_R1-rate_R2-rate_R34-rate_R4-rate_R6;
        result[11] = -rate_R27+rate_R2-rate_R3;
        result[12] = -rate_R26+rate_R3;
        result[13] = +rate_R4-rate_R5;
        result[14] = +rate_R5;
        result[15] = +rate_R6-rate_R7-rate_R8;
        result[16] = +rate_R7;
        result[17] = -rate_R25+rate_R8;
        result[18] = -rate_R18+rate_R9;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[19];
        __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 ...