/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000144.xml diagram  at 2008.03.20 15:09:25
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000144 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        CycBT = (1.0 - x[9]*E_1)*(x[0] + x[5]) + x[9]*E_1*(x[8] + x[14]);
        StgPT = (1.0 - x[9]*E_1)*x[1] + x[9]*E_1*x[10];
        _cytoplasm_Wee1Pc_ = (Wee1T - x[9]*E_1*(x[13] + x[12]))/(1 - x[9]*E_1) - x[4];
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_Nuclei_1 = 0.0;
        rate_R_1 = ksc*cytoplasm;
        rate_R_10 = nuclei*(kdmp*x[3]/(Jm + x[3]) + kdm*x[16]*x[3]);
        rate_R_12 = cytoplasm*ksstg*x[3];
        rate_R_13 = cytoplasm*((kastgp + kastg*x[0])*x[2]/(Jastg + x[2]));
        rate_R_14 = cytoplasm*(kistg*x[1]/(Jistg + x[1]));
        rate_R_15 = cytoplasm*kdstg*x[2];
        rate_R_16 = cytoplasm*kdstg*x[1];
        rate_R_19 = cytoplasm*(kt*x[0]*E_1*x[9]/(1 - x[9]*E_1));
        rate_R_2 = cytoplasm*(kstgp + kstg*x[1])*x[5];
        rate_R_20 = cytoplasm*(kt*x[5]*E_1*x[9]/(1 - x[9]*E_1));
        rate_R_21 = nuclei*koutw_1*x[12];
        rate_R_22 = cytoplasm*(kinw_1*_cytoplasm_Wee1Pc_*E_1*x[9]/(1 - x[9]*E_1));
        rate_R_23 = nuclei*koutw_1*x[13];
        rate_R_24 = cytoplasm*(kinw_1*x[4]*E_1*x[9]/(1 - x[9]*E_1));
        rate_R_25 = nuclei*kouts_1*x[10];
        rate_R_26 = cytoplasm*(kins_1*x[1]*E_1*x[9]/(1 - x[9]*E_1));
        rate_R_27 = nuclei*kouts_1*x[11];
        rate_R_28 = cytoplasm*(kins_1*x[2]*E_1*x[9]/(1 - x[9]*E_1));
        rate_R_29 = nuclei*(kstgp + kstg*x[10])*x[14];
        rate_R_3 = cytoplasm*(kweep + kwee*x[4])*x[0];
        rate_R_30 = nuclei*(kweep + kwee*x[13])*x[8];
        rate_R_33 = nuclei*(kdnp + kdn*x[6])*x[14];
        rate_R_34 = nuclei*(kdnp + kdn*x[6])*x[8];
        rate_R_37 = nuclei*(kiie*x[7]/(Jiie + x[7]));
        rate_R_38 = nuclei*(kaie*(1 - x[7])*x[8]/(Jaie + 1 - x[7]));
        rate_R_39 = nuclei*(kafzy*x[7]*(1 - x[6])/(Jafzy + 1 - x[6]));
        rate_R_40 = nuclei*(kifzy*x[6]/(Jifzy + x[6]));
        rate_R_41 = nuclei*((kiweep + kiwee*x[8])*x[13]/(Jiwee + x[13]));
        rate_R_42 = nuclei*(kawee*x[12]/(Jawee + x[12]));
        rate_R_43 = nuclei*((kastgp + kastg*x[8])*x[11]/(Jastg + x[11]));
        rate_R_44 = nuclei*(kistg*x[10]/(Jistg + x[10]));
        rate_R_45 = nuclei*kdstg*x[11];
        rate_R_46 = nuclei*kdstg*x[10];
        rate_R_6 = cytoplasm*kdc*x[5];
        rate_R_7 = cytoplasm*kdc*x[0];
        rate_R_8 = cytoplasm*((kiweep + kiwee*x[0])*x[4]/(Jiwee + x[4]));
        rate_R_9 = cytoplasm*(kawee*_cytoplasm_Wee1Pc_/(Jawee + _cytoplasm_Wee1Pc_));
        rate__16 = cytoplasm*kt*x[0];
        rate__18 = cytoplasm*kt*x[5];
    }
    public void __internalRateVarInitFunc_1(double time, double[] x)
    {
        rate__182_1 = nuclei*(koutw_1*x[12]*x[9]*E_1/(1 - x[9]*E_1));
        rate__20 = cytoplasm*kinw_1*_cytoplasm_Wee1Pc_;
        rate__22 = nuclei*(koutw_1*x[13]*x[9]*E_1/(1 - x[9]*E_1));
        rate__24 = cytoplasm*kinw_1*x[4];
        rate__26 = nuclei*(kouts_1*x[10]*E_1*x[9]/(1 - x[9]*E_1));
        rate__28 = cytoplasm*kins_1*x[1];
        rate__30 = nuclei*(kouts_1*x[11]*E_1*x[9]/(1 - x[9]*E_1));
        rate__32 = cytoplasm*kins_1*x[2];
        rate__50 = nuclei*ksxm_1*x[9];
        rate__51 = cytoplasm*ksxp_1*x[15];
        rate_exportofMPFfromnucleus_1 = nuclei*kout_1*x[8];
        rate_exportofpreMPFnfromnucleus_1 = nuclei*kout_1*x[14];
        rate_importofMPFintocytoplasm_1 = nuclei*(kout_1*x[8]*E_1*x[9]/(1 - x[9]*E_1));
        rate_importofpreMPFintocytoplaslm_1 = nuclei*(kout_1*x[14]*x[9]*E_1/(1 - x[9]*E_1));
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        _cytoplasm_Wee1Pc_ = 0.8; // initial value of $"cytoplasm.Wee1Pc"
        cytoplasm = 1.0; // initial value of $cytoplasm
        nuclei = 1.0; // initial value of $nuclei
        E_1 = 7.0E-5; // initial value of E_1
        Jafzy = 0.01; // initial value of Jafzy
        Jaie = 0.01; // initial value of Jaie
        Jastg = 0.05; // initial value of Jastg
        Jawee = 0.05; // initial value of Jawee
        Jifzy = 0.01; // initial value of Jifzy
        Jiie = 0.01; // initial value of Jiie
        Jistg = 0.05; // initial value of Jistg
        Jiwee = 0.05; // initial value of Jiwee
        Jm = 0.05; // initial value of Jm
        Wee1T = 0.8; // initial value of Wee1T
        factor_1 = 1.95; // initial value of factor_1
        kafzy = 1.0; // initial value of kafzy
        kaie = 1.0; // initial value of kaie
        kastg = 1.0; // initial value of kastg
        kawee = 0.3; // initial value of kawee
        kdc = 0.01; // initial value of kdc
        kdm = 0.2; // initial value of kdm
        kdmp = 0.0020; // initial value of kdmp
        kdn = 1.5; // initial value of kdn
        kdnp = 0.01; // initial value of kdnp
        kez_1 = 0.5; // initial value of kez_1
        kifzy = 0.2; // initial value of kifzy
        kiie = 0.4; // initial value of kiie
        kins_1 = 0.08; // initial value of kins_1
        kinw_1 = 0.04; // initial value of kinw_1
        kistg = 0.3; // initial value of kistg
        kiwee = 1.0; // initial value of kiwee
        kiweep = 0.01; // initial value of kiweep
        kouts_1 = 0.02; // initial value of kouts_1
        koutw_1 = 0.01; // initial value of koutw_1
        ksc = 0.01; // initial value of ksc
        kstg = 2.0; // initial value of kstg
        kstgp = 0.2; // initial value of kstgp
        ksxm_1 = 5.0E-4; // initial value of ksxm_1
        ksxp_1 = 0.0010; // initial value of ksxp_1
        kt = 0.15; // initial value of kt
        kwee = 1.0; // initial value of kwee
        kweep = 0.0050; // initial value of kweep
    }

    /*
     * Model variables initial values
     */
    protected double _cytoplasm_Wee1Pc_;
    protected double rate_Nuclei_1;
    protected double rate_R_1;
    protected double rate_R_10;
    protected double rate_R_12;
    protected double rate_R_13;
    protected double rate_R_14;
    protected double rate_R_15;
    protected double rate_R_16;
    protected double rate_R_19;
    protected double rate_R_2;
    protected double rate_R_20;
    protected double rate_R_21;
    protected double rate_R_22;
    protected double rate_R_23;
    protected double rate_R_24;
    protected double rate_R_25;
    protected double rate_R_26;
    protected double rate_R_27;
    protected double rate_R_28;
    protected double rate_R_29;
    protected double rate_R_3;
    protected double rate_R_30;
    protected double rate_R_33;
    protected double rate_R_34;
    protected double rate_R_37;
    protected double rate_R_38;
    protected double rate_R_39;
    protected double rate_R_40;
    protected double rate_R_41;
    protected double rate_R_42;
    protected double rate_R_43;
    protected double rate_R_44;
    protected double rate_R_45;
    protected double rate_R_46;
    protected double rate_R_6;
    protected double rate_R_7;
    protected double rate_R_8;
    protected double rate_R_9;
    protected double rate__16;
    protected double rate__18;
    protected double rate__182_1;
    protected double rate__20;
    protected double rate__22;
    protected double rate__24;
    protected double rate__26;
    protected double rate__28;
    protected double rate__30;
    protected double rate__32;
    protected double rate__50;
    protected double rate__51;
    protected double rate_exportofMPFfromnucleus_1;
    protected double rate_exportofpreMPFnfromnucleus_1;
    protected double rate_importofMPFintocytoplasm_1;
    protected double rate_importofpreMPFintocytoplaslm_1;
    protected double cytoplasm;
    protected double nuclei;
    protected double CycBT;
    protected double E_1;
    protected double Jafzy;
    protected double Jaie;
    protected double Jastg;
    protected double Jawee;
    protected double Jifzy;
    protected double Jiie;
    protected double Jistg;
    protected double Jiwee;
    protected double Jm;
    protected double StgPT;
    protected double Wee1T;
    protected double factor_1;
    protected double kafzy;
    protected double kaie;
    protected double kastg;
    protected double kastgp;
    protected double kawee;
    protected double kdc;
    protected double kdm;
    protected double kdmp;
    protected double kdn;
    protected double kdnp;
    protected double kdstg;
    protected double kez_1;
    protected double kifzy;
    protected double kiie;
    protected double kins_1;
    protected double kinw_1;
    protected double kistg;
    protected double kiwee;
    protected double kiweep;
    protected double kout_1;
    protected double kouts_1;
    protected double koutw_1;
    protected double ksc;
    protected double ksstg;
    protected double kstg;
    protected double kstgp;
    protected double ksxm_1;
    protected double ksxp_1;
    protected double kt;
    protected double kwee;
    protected double kweep;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[20];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = x[2];
        y[3] = x[3];
        y[4] = _cytoplasm_Wee1Pc_;
        y[5] = x[4];
        y[6] = x[5];
        y[7] = x[6];
        y[8] = x[7];
        y[9] = x[8];
        y[10] = x[9];
        y[11] = x[10];
        y[12] = x[11];
        y[13] = x[12];
        y[14] = x[13];
        y[15] = x[14];
        y[16] = x[15];
        y[17] = x[16];
        y[18] = CycBT;
        y[19] = StgPT;
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[17];
        this.time = 0.0;
        x[0] = 1.0; // - $"cytoplasm.MPFc"
        x[1] = 0.8; // - $"cytoplasm.StgPc"
        x[2] = 0.0; // - $"cytoplasm.Stgc"
        x[3] = 1.0; // - $"cytoplasm.Stgm"
        x[4] = 0.0; // - $"cytoplasm.Wee1c"
        x[5] = 0.0; // - $"cytoplasm.preMPFc"
        x[6] = 0.0; // - $"nuclei.FZYa"
        x[7] = 0.0; // - $"nuclei.IEa_1"
        x[8] = 0.0; // - $"nuclei.MPFn"
        x[9] = 1.0; // - $"nuclei.N"
        x[10] = 0.0; // - $"nuclei.StgPn"
        x[11] = 0.0; // - $"nuclei.Stgn"
        x[12] = 0.0; // - $"nuclei.Wee1Pn"
        x[13] = 0.0; // - $"nuclei.Wee1n"
        x[14] = 0.0; // - $"nuclei.preMPFn"
        x[15] = 0.0; // - $cytoplasm.Xm
        x[16] = 0.0; // - $cytoplasm.Xp

        __internalVarInitFunc_0(time, x);
        __internalRateVarInitFunc_0(time, x);
        __internalRateVarInitFunc_1(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);
        __internalRateVarInitFunc_1(time, x);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000144.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_R_19+rate_R_1+rate_R_2-rate_R_3-rate_R_7+rate_importofMPFintocytoplasm_1;
        result[1] = +rate_R_13-rate_R_14-rate_R_16-rate_R_26+rate__26;
        result[2] = +rate_R_12-rate_R_13+rate_R_14-rate_R_15-rate_R_28+rate__30;
        result[3] = -rate_R_10;
        result[4] = -rate_R_24-rate_R_8+rate_R_9+rate__22;
        result[5] = -rate_R_20-rate_R_2+rate_R_3-rate_R_6+rate_importofpreMPFintocytoplaslm_1;
        result[6] = +rate_R_39-rate_R_40;
        result[7] = -rate_R_37+rate_R_38;
        result[8] = +rate_R_29-rate_R_30-rate_R_34+rate__16-rate_exportofMPFfromnucleus_1;
        result[9] = +rate_Nuclei_1;
        result[10] = -rate_R_25+rate_R_43-rate_R_44-rate_R_46+rate__28;
        result[11] = -rate_R_27-rate_R_43+rate_R_44-rate_R_45+rate__32;
        result[12] = -rate_R_21+rate_R_41-rate_R_42+rate__20;
        result[13] = -rate_R_23-rate_R_41+rate_R_42+rate__24;
        result[14] = -rate_R_29+rate_R_30-rate_R_33+rate__18-rate_exportofpreMPFnfromnucleus_1;
        result[15] = +rate__50;
        result[16] = +rate__51;
    }
    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 );
    }

    public double[] checkEvent(double time, double[] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);
        __internalRateVarInitFunc_0(time, x);
        __internalRateVarInitFunc_1(time, x);

        double [] flags = new double[1];
        flags[0] = (x[6] >= kez_1) ? +1 : -1; //event_1
        return flags;
    }

    public void processEvent(int __internalVar12060041656250, double time, double[] x)
    {
        this.time = time;
        if ( __internalVar12060041656250 == 0) //event_1
        {
            x[9] = factor_1*x[9];
            x[8] = x[8]/1.95;
            x[14] = x[14]/1.95;
            x[13] = x[13]/1.95;
            x[12] = x[12]/1.95;
            x[4] = x[4]*((1.0 - x[9]*E_1)/(1.0 - 1.95*x[9]*E_1));
            _cytoplasm_Wee1Pc_ = _cytoplasm_Wee1Pc_*((1.0 - x[9]*E_1)/(1.0 - 1.95*x[9]*E_1));
            x[11] = x[11]/1.95;
            x[1] = x[1]*((1 - x[9]*E_1)/(1 - 1.95*x[9]*E_1));
            x[2] = x[2]*((1 - x[9]*E_1)/(1 - 1.95*x[9]*E_1));
            x[10] = x[10]/1.95;
            x[0] = x[0]*((1 - x[9]*E_1)/(1 - 1.95*x[9]*E_1));
        }
    }

} // class ...