/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000069.xml diagram  at 2008.03.20 15:04:56
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000069 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        src_activity = rho_srco*x[9] + rho_srca*x[6] + src_background + rho_srcc*x[7];
        ptp_activity = PTP_background + Kser*x[5];
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_CSK_translocation = (x[2]*kCSKon*x[0] - kCSKoff*x[3])*_default;
        rate_Cbp_phosphorylation = kCbp*src_activity*x[1]*_default;
        rate_PTP_phosphorylation = _default*((kPTP*src_activity + p3)*x[4] - p2*x[5]);
        rate_v1 = (k2*ptp_activity*x[8] - k1*x[3]*x[9])*_default;
        rate_v2 = (k3*src_activity*x[9] - p1*x[6])*_default;
        rate_v3 = (k1*x[3]*x[6] - k2*ptp_activity*x[7])*_default;
        rate_v4 = _default*k4*p1*x[7];
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        _default = 1.0; // initial value of $default
        Kser = 1.0; // initial value of Kser
        k1 = 1.0; // initial value of k1
        k2 = 0.8; // initial value of k2
        k3 = 1.0; // initial value of k3
        k4 = 10.0; // initial value of k4
        kCSKoff = 0.01; // initial value of kCSKoff
        kCSKon = 0.1; // initial value of kCSKon
        kCbp = 1.0; // initial value of kCbp
        kPTP = 1.0; // initial value of kPTP
        p1 = 0.05; // initial value of p1
        p2 = 0.15; // initial value of p2
        p3 = 0.035; // initial value of p3
        rho_srca = 1.0; // initial value of rho_srca
        rho_srcc = 1.0; // initial value of rho_srcc
        src_background = 1.0E-4; // initial value of src_background
    }

    /*
     * Model variables initial values
     */
    protected double rate_CSK_translocation;
    protected double rate_Cbp_phosphorylation;
    protected double rate_PTP_phosphorylation;
    protected double rate_v1;
    protected double rate_v2;
    protected double rate_v3;
    protected double rate_v4;
    protected double _default;
    protected double Kser;
    protected double PTP_background;
    protected double k1;
    protected double k2;
    protected double k3;
    protected double k4;
    protected double kCSKoff;
    protected double kCSKon;
    protected double kCbp;
    protected double kPTP;
    protected double p1;
    protected double p2;
    protected double p3;
    protected double ptp_activity;
    protected double rho_srca;
    protected double rho_srcc;
    protected double rho_srco;
    protected double src_activity;
    protected double src_background;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[12];
        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] = ptp_activity;
        y[11] = src_activity;
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[10];
        this.time = 0.0;
        x[0] = 1.0; // - $"default.CSK_cytoplasm"
        x[1] = 1.0; // - $"default.Cbp"
        x[2] = 0.0; // - $"default.Cbp_P"
        x[3] = 0.0; // - $"default.Cbp_P_CSK"
        x[4] = 1.0; // - $"default.PTP"
        x[5] = 0.0; // - $"default.PTP_pY789"
        x[6] = 0.0; // - $"default.srca"
        x[7] = 0.0; // - $"default.srcc"
        x[8] = 1.0; // - $"default.srci"
        x[9] = 0.0; // - $"default.srco"

        __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 'BIOMD0000000069.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_CSK_translocation;
        result[1] = -rate_Cbp_phosphorylation;
        result[2] = -rate_CSK_translocation+rate_Cbp_phosphorylation;
        result[3] = +rate_CSK_translocation;
        result[4] = -rate_PTP_phosphorylation;
        result[5] = +rate_PTP_phosphorylation;
        result[6] = +rate_v2-rate_v3;
        result[7] = +rate_v3-rate_v4;
        result[8] = -rate_v1+rate_v4;
        result[9] = +rate_v1-rate_v2;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[10];
        __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 ...