/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000057.xml diagram  at 2008.03.20 15:04:42
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000057 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        open_probability = Math.pow((0.1*x[1] + 0.9*x[0]), 4);
        Phi4 = (k4*L5 + l6)*c/(L5 + c);
        Phi_minus4 = L1*(kminus4 + lminus6)/(L1 + c);
        Phi5 = (k1*L1 + l2)*c/(L1 + c);
        Phi1 = (k1*L1 + l2)*c/(L1 + c*(1 + L1/L3));
        Phi2 = (k2*L3 + l4*c)/(L3 + c*(1 + L3/L1));
        Phi_minus2 = (kminus2 + lminus4*c)/(1 + c/L5);
        Phi3 = k3*L5/(L5 + c);
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_v1 = compartment*(Phi2*v1_IP3*x[2] - Phi_minus2*x[1]);
        rate_v2 = compartment*(Phi1*x[2] - (v2_kminus1 + v2_lminus2)*x[4]);
        rate_v3 = compartment*(Phi3*x[1] - v3_kminus3*x[3]);
        rate_v4 = compartment*(Phi4*x[1] - Phi_minus4*x[0]);
        rate_v5 = compartment*(Phi5*x[0] - (v5_kminus1 + v5_lminus2)*x[5]);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        compartment = 1.0; // initial value of $compartment
        L1 = 0.12; // initial value of L1
        L3 = 0.025; // initial value of L3
        L5 = 54.7; // initial value of L5
        c = 10.0; // initial value of c
        k1 = 0.64; // initial value of k1
        k2 = 37.4; // initial value of k2
        k3 = 0.11; // initial value of k3
        k4 = 4.0; // initial value of k4
        kminus2 = 1.4; // initial value of kminus2
        kminus4 = 0.54; // initial value of kminus4
        l2 = 1.7; // initial value of l2
        l4 = 1.7; // initial value of l4
        l6 = 4707.0; // initial value of l6
        lminus4 = 2.5; // initial value of lminus4
        lminus6 = 11.4; // initial value of lminus6
        v1_IP3 = 10.0; // initial value of v1_IP3
        v2_kminus1 = 0.04; // initial value of v2_kminus1
        v2_lminus2 = 0.8; // initial value of v2_lminus2
        v3_kminus3 = 29.8; // initial value of v3_kminus3
        v5_kminus1 = 0.04; // initial value of v5_kminus1
        v5_lminus2 = 0.8; // initial value of v5_lminus2
    }

    /*
     * Model variables initial values
     */
    protected double rate_v1;
    protected double rate_v2;
    protected double rate_v3;
    protected double rate_v4;
    protected double rate_v5;
    protected double compartment;
    protected double L1;
    protected double L3;
    protected double L5;
    protected double Phi1;
    protected double Phi2;
    protected double Phi3;
    protected double Phi4;
    protected double Phi5;
    protected double Phi_minus2;
    protected double Phi_minus4;
    protected double c;
    protected double k1;
    protected double k2;
    protected double k3;
    protected double k4;
    protected double kminus2;
    protected double kminus4;
    protected double l2;
    protected double l4;
    protected double l6;
    protected double lminus4;
    protected double lminus6;
    protected double open_probability;
    protected double v1_IP3;
    protected double v2_kminus1;
    protected double v2_lminus2;
    protected double v3_kminus3;
    protected double v5_kminus1;
    protected double v5_lminus2;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[14];
        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] = Phi1;
        y[7] = Phi2;
        y[8] = Phi3;
        y[9] = Phi4;
        y[10] = Phi5;
        y[11] = Phi_minus2;
        y[12] = Phi_minus4;
        y[13] = open_probability;
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[6];
        this.time = 0.0;
        x[0] = 0.0; // - $"compartment.A"
        x[1] = 0.0; // - $"compartment.O"
        x[2] = 1.0; // - $"compartment.R"
        x[3] = 0.0; // - $"compartment.S"
        x[4] = 0.0; // - $compartment.I1
        x[5] = 0.0; // - $compartment.I2

        __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 'BIOMD0000000057.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_v4-rate_v5;
        result[1] = +rate_v1-rate_v3-rate_v4;
        result[2] = -rate_v1-rate_v2;
        result[3] = +rate_v3;
        result[4] = +rate_v2;
        result[5] = +rate_v5;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[6];
        __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 ...