/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000016.xml diagram  at 2008.03.20 15:03:54
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000016 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        _default_CYTOPLASM_Pt_ = x[1] + x[2] + x[3] + x[4];
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_rM = _default*rM_Vs*Math.pow(rM_KI, rM_n)/(Math.pow(rM_KI, rM_n) + Math.pow((x[4]/_default_CYTOPLASM_compartment_0000004_), rM_n));
        rate_rP01 = _default_CYTOPLASM_*rP01_V1*(x[1]/_default_CYTOPLASM_)/(rP01_K1 + x[1]/_default_CYTOPLASM_);
        rate_rP10 = _default_CYTOPLASM_*rP10_V2*(x[2]/_default_CYTOPLASM_)/(rP10_K2 + x[2]/_default_CYTOPLASM_);
        rate_rP12 = _default_CYTOPLASM_*rP12_V3*(x[2]/_default_CYTOPLASM_)/(rP12_K3 + x[2]/_default_CYTOPLASM_);
        rate_rP21 = _default_CYTOPLASM_*rP21_V4*(x[3]/_default_CYTOPLASM_)/(rP21_K4 + x[3]/_default_CYTOPLASM_);
        rate_rP2n = rP2n_k1*(x[3]/_default_CYTOPLASM_)*_default_CYTOPLASM_;
        rate_rPn2 = rPn2_k2*(x[4]/_default_CYTOPLASM_compartment_0000004_)*_default_CYTOPLASM_compartment_0000004_;
        rate_rTL = rTL_ks*(x[0]/_default_CYTOPLASM_)*_default;
        rate_rVd = _default_CYTOPLASM_*rVd_Vd*(x[3]/_default_CYTOPLASM_)/(rVd_Kd + x[3]/_default_CYTOPLASM_);
        rate_rmRNAd = rmRNAd_Vm*(x[0]/_default_CYTOPLASM_)*_default_CYTOPLASM_/(rmRNAd_Km + x[0]/_default_CYTOPLASM_);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        _default_CYTOPLASM_ = 1.0E-15; // initial value of $"default.CYTOPLASM"
        _default_CYTOPLASM_Pt_ = 1.0E-15; // initial value of $"default.CYTOPLASM.Pt"
        _default_CYTOPLASM_compartment_0000004_ = 1.0E-15; // initial value of $"default.CYTOPLASM.compartment_0000004"
        _default = 1.0E-15; // initial value of $default
        rM_KI = 1.0; // initial value of rM_KI
        rM_Vs = 0.76; // initial value of rM_Vs
        rM_n = 4.0; // initial value of rM_n
        rP01_K1 = 2.0; // initial value of rP01_K1
        rP01_V1 = 3.2; // initial value of rP01_V1
        rP10_K2 = 2.0; // initial value of rP10_K2
        rP10_V2 = 1.58; // initial value of rP10_V2
        rP12_K3 = 2.0; // initial value of rP12_K3
        rP12_V3 = 5.0; // initial value of rP12_V3
        rP21_K4 = 2.0; // initial value of rP21_K4
        rP21_V4 = 2.5; // initial value of rP21_V4
        rP2n_k1 = 1.9; // initial value of rP2n_k1
        rPn2_k2 = 1.3; // initial value of rPn2_k2
        rTL_ks = 0.38; // initial value of rTL_ks
        rVd_Kd = 0.2; // initial value of rVd_Kd
        rVd_Vd = 0.95; // initial value of rVd_Vd
        rmRNAd_Km = 0.5; // initial value of rmRNAd_Km
        rmRNAd_Vm = 0.65; // initial value of rmRNAd_Vm
    }

    /*
     * Model variables initial values
     */
    protected double _default_CYTOPLASM_;
    protected double _default_CYTOPLASM_Pt_;
    protected double _default_CYTOPLASM_compartment_0000004_;
    protected double _default_EmptySet_;
    protected double rate_rM;
    protected double rate_rP01;
    protected double rate_rP10;
    protected double rate_rP12;
    protected double rate_rP21;
    protected double rate_rP2n;
    protected double rate_rPn2;
    protected double rate_rTL;
    protected double rate_rVd;
    protected double rate_rmRNAd;
    protected double _default;
    protected double rM_KI;
    protected double rM_Vs;
    protected double rM_n;
    protected double rP01_K1;
    protected double rP01_V1;
    protected double rP10_K2;
    protected double rP10_V2;
    protected double rP12_K3;
    protected double rP12_V3;
    protected double rP21_K4;
    protected double rP21_V4;
    protected double rP2n_k1;
    protected double rPn2_k2;
    protected double rTL_ks;
    protected double rVd_Kd;
    protected double rVd_Vd;
    protected double rmRNAd_Km;
    protected double rmRNAd_Vm;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[6];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = x[2];
        y[3] = x[3];
        y[4] = _default_CYTOPLASM_Pt_;
        y[5] = x[4];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[5];
        this.time = 0.0;
        x[0] = 1.0000000000000001E-16; // - $"default.CYTOPLASM.M"
        x[1] = 2.5E-16; // - $"default.CYTOPLASM.P0"
        x[2] = 2.5E-16; // - $"default.CYTOPLASM.P1"
        x[3] = 2.5E-16; // - $"default.CYTOPLASM.P2"
        x[4] = 2.5E-16; // - $"default.CYTOPLASM.compartment_0000004.Pn"

        __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 'BIOMD0000000016.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_rM-rate_rmRNAd;
        result[1] = -rate_rP01+rate_rP10+rate_rTL;
        result[2] = +rate_rP01-rate_rP10-rate_rP12+rate_rP21;
        result[3] = +rate_rP12-rate_rP21-rate_rP2n+rate_rPn2-rate_rVd;
        result[4] = +rate_rP2n-rate_rPn2;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[5];
        __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 ...