/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000029.xml diagram  at 2008.03.20 15:04:06
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000029 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_v1 = cell*(kcat1*_cell_MEK_*x[0]/Km1/(1.0 + x[0]*((Km1 + Km3)/(Km1*Km3)) + x[2]/Km2 + x[1]/Km4));
        rate_v2 = cell*(kcat2*_cell_MEK_*x[2]/Km2/(1.0 + x[0]*((Km1 + Km3)/(Km1*Km3)) + x[2]/Km2 + x[1]/Km4));
        rate_v3 = cell*(kcat3*_cell_MEK_*x[0]/Km3/(1.0 + x[0]*((Km1 + Km3)/(Km1*Km3)) + x[2]/Km2 + x[1]/Km4));
        rate_v4 = cell*(kcat4*_cell_MEK_*x[1]/Km4/(1.0 + x[0]*((Km1 + Km3)/(Km1*Km3)) + x[2]/Km2 + x[1]/Km4));
        rate_v5 = cell*(kcat5*_cell_MKP3_*x[3]/Km5/(1.0 + x[3]/Km5 + x[1]/Km6 + x[2]/Km7 + x[0]/Km8));
        rate_v6 = cell*(kcat6*_cell_MKP3_*x[1]/Km6/(1.0 + x[3]/Km5 + x[1]/Km6 + x[2]/Km7 + x[0]/Km8));
        rate_v7 = cell*(kcat7*_cell_MKP3_*x[2]/Km7/(1.0 + x[3]/Km5 + x[1]/Km6 + x[2]/Km7 + x[0]/Km8));
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        _cell_MEK_ = 180.0; // initial value of $"cell.MEK"
        _cell_MKP3_ = 100.0; // initial value of $"cell.MKP3"
        cell = 1.0; // initial value of $cell
        Km1 = 410.0; // initial value of Km1
        Km2 = 40.0; // initial value of Km2
        Km3 = 20.0; // initial value of Km3
        Km4 = 300.0; // initial value of Km4
        Km5 = 22.0; // initial value of Km5
        Km6 = 18.0; // initial value of Km6
        Km7 = 34.0; // initial value of Km7
        Km8 = 40.0; // initial value of Km8
        kcat1 = 1.08; // initial value of kcat1
        kcat2 = 0.0070; // initial value of kcat2
        kcat3 = 0.0080; // initial value of kcat3
        kcat4 = 0.45; // initial value of kcat4
        kcat5 = 0.084; // initial value of kcat5
        kcat6 = 0.06; // initial value of kcat6
        kcat7 = 0.108; // initial value of kcat7
    }

    /*
     * Model variables initial values
     */
    protected double _cell_MEK_;
    protected double _cell_MKP3_;
    protected double rate_v1;
    protected double rate_v2;
    protected double rate_v3;
    protected double rate_v4;
    protected double rate_v5;
    protected double rate_v6;
    protected double rate_v7;
    protected double cell;
    protected double Km1;
    protected double Km2;
    protected double Km3;
    protected double Km4;
    protected double Km5;
    protected double Km6;
    protected double Km7;
    protected double Km8;
    protected double kcat1;
    protected double kcat2;
    protected double kcat3;
    protected double kcat4;
    protected double kcat5;
    protected double kcat6;
    protected double kcat7;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[4];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = x[2];
        y[3] = x[3];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[4];
        this.time = 0.0;
        x[0] = 800.0; // - $"cell.M"
        x[1] = 0.0; // - $"cell.MpT"
        x[2] = 0.0; // - $"cell.MpY"
        x[3] = 0.0; // - $"cell.Mpp"

        __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 'BIOMD0000000029.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_v1-rate_v3+rate_v6+rate_v7;
        result[1] = +rate_v3-rate_v4+rate_v5-rate_v6;
        result[2] = +rate_v1-rate_v2-rate_v7;
        result[3] = +rate_v2+rate_v4-rate_v5;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[4];
        __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 ...