/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000107.xml diagram  at 2008.03.20 15:08:43
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000107 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        _cytoplasm_cdc2_ = total_cdc2 - (x[4] + x[6] + x[7] + x[5]);
        k25 = V25_prime*(total_cdc25 - x[2]) + V25_double_prime*x[2];
        kwee = Vwee_prime*x[8] + Vwee_double_prime*(total_wee1 - x[8]);
        k2 = V2_prime*(total_UbE - x[1]) + V2_double_prime*x[1];
        _cytoplasm_cdc25_ = total_cdc25 - x[2];
        _cytoplasm_wee1_ = total_wee1 - x[8];
        cytoplasm_IE = total_IE - x[0];
        _cytoplasm_UbE_ = total_UbE - x[1];
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_R1 = k1AA;
        rate_R10 = k2*x[6];
        rate_R11 = kinh*x[7];
        rate_R12 = kwee*x[5];
        rate_R13 = k25*x[7];
        rate_R14 = k2*x[7];
        rate_R15 = k2*x[5];
        rate_R17 = ka*x[5]*(total_cdc25 - x[2])/(K_a + total_cdc25 - x[2]);
        rate_R18 = kbPPase*x[2]/(K_b + x[2]);
        rate_R19 = ke*x[5]*(total_wee1 - x[8])/(K_e + total_wee1 - x[8]);
        rate_R2 = k2*x[3];
        rate_R20 = kfPPase*x[8]/(K_f + x[8]);
        rate_R21 = kg*x[5]*(total_IE - x[0])/(K_g + total_IE - x[0]);
        rate_R22 = khPPAse*x[0]/(K_h + x[0]);
        rate_R23 = kc*x[0]*(total_UbE - x[1])/(K_c + total_UbE - x[1]);
        rate_R24 = kd_anti_IE*x[1]/(K_d + x[1]);
        rate_R3 = k3*x[3]*_cytoplasm_cdc2_;
        rate_R4 = kinh*x[5];
        rate_R5 = kwee*x[4];
        rate_R6 = kcak*x[4];
        rate_R7 = k2*x[4];
        rate_R8 = k25*x[6];
        rate_R9 = kcak*x[6];
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        K_a = 0.1; // initial value of K_a
        K_b = 0.1; // initial value of K_b
        K_c = 0.01; // initial value of K_c
        K_d = 0.01; // initial value of K_d
        K_e = 0.3; // initial value of K_e
        K_f = 0.3; // initial value of K_f
        K_g = 0.01; // initial value of K_g
        K_h = 0.01; // initial value of K_h
        V25_double_prime = 2.0; // initial value of V25_double_prime
        V25_prime = 0.1; // initial value of V25_prime
        Vwee_double_prime = 1.0; // initial value of Vwee_double_prime
        Vwee_prime = 0.1; // initial value of Vwee_prime
        k3 = 0.01; // initial value of k3
        ka = 0.01; // initial value of ka
        kbPPase = 0.125; // initial value of kbPPase
        kc = 0.1; // initial value of kc
        kcak = 0.25; // initial value of kcak
        kd_anti_IE = 0.095; // initial value of kd_anti_IE
        ke = 0.0133; // initial value of ke
        kfPPase = 0.1; // initial value of kfPPase
        kg = 0.0065; // initial value of kg
        khPPAse = 0.087; // initial value of khPPAse
        kinh = 0.025; // initial value of kinh
        total_IE = 1.0; // initial value of total_IE
        total_UbE = 1.0; // initial value of total_UbE
        total_cdc2 = 100.0; // initial value of total_cdc2
        total_cdc25 = 1.0; // initial value of total_cdc25
        total_wee1 = 1.0; // initial value of total_wee1
    }

    /*
     * Model variables initial values
     */
    protected double _cytoplasm_UbE_;
    protected double _cytoplasm_cdc2_;
    protected double _cytoplasm_cdc25_;
    protected double _cytoplasm_wee1_;
    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_R15;
    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_R3;
    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 cytoplasm_IE;
    protected double K_a;
    protected double K_b;
    protected double K_c;
    protected double K_d;
    protected double K_e;
    protected double K_f;
    protected double K_g;
    protected double K_h;
    protected double V25_double_prime;
    protected double V25_prime;
    protected double V2_double_prime;
    protected double V2_prime;
    protected double Vwee_double_prime;
    protected double Vwee_prime;
    protected double k1AA;
    protected double k2;
    protected double k25;
    protected double k3;
    protected double ka;
    protected double kbPPase;
    protected double kc;
    protected double kcak;
    protected double kd_anti_IE;
    protected double ke;
    protected double kfPPase;
    protected double kg;
    protected double khPPAse;
    protected double kinh;
    protected double kwee;
    protected double total_IE;
    protected double total_UbE;
    protected double total_cdc2;
    protected double total_cdc25;
    protected double total_wee1;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[17];
        y[0] = x[0];
        y[1] = _cytoplasm_UbE_;
        y[2] = x[1];
        y[3] = _cytoplasm_cdc2_;
        y[4] = _cytoplasm_cdc25_;
        y[5] = x[2];
        y[6] = x[3];
        y[7] = x[4];
        y[8] = x[5];
        y[9] = x[6];
        y[10] = x[7];
        y[11] = _cytoplasm_wee1_;
        y[12] = x[8];
        y[13] = cytoplasm_IE;
        y[14] = k2;
        y[15] = k25;
        y[16] = kwee;
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[9];
        this.time = 0.0;
        x[0] = 0.0; // - $"cytoplasm.IE_p"
        x[1] = 0.0; // - $"cytoplasm.UbE_star"
        x[2] = 0.0; // - $"cytoplasm.cdc25_p"
        x[3] = 100.0; // - $"cytoplasm.cyclin"
        x[4] = 0.0; // - $"cytoplasm.dimer"
        x[5] = 0.0; // - $"cytoplasm.dimer_p"
        x[6] = 0.0; // - $"cytoplasm.p_dimer"
        x[7] = 0.0; // - $"cytoplasm.p_dimer_p"
        x[8] = 0.0; // - $"cytoplasm.wee1_p"

        __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 'BIOMD0000000107.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_R21-rate_R22;
        result[1] = +rate_R23-rate_R24;
        result[2] = +rate_R17-rate_R18;
        result[3] = +rate_R1-rate_R2-rate_R3;
        result[4] = +rate_R3+rate_R4-rate_R5-rate_R6-rate_R7+rate_R8;
        result[5] = -rate_R12+rate_R13-rate_R15-rate_R4+rate_R6;
        result[6] = -rate_R10+rate_R11+rate_R5-rate_R8-rate_R9;
        result[7] = -rate_R11+rate_R12-rate_R13-rate_R14+rate_R9;
        result[8] = +rate_R19-rate_R20;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[9];
        __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 ...