/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000060.xml diagram  at 2008.03.20 15:04:45
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000060 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        Open_probability = x[2] + x[3];
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_Closed_State_2 = Closed_State_2_kc_plus*x[2] - Closed_State_2_kc_minus*x[1];
        rate_Closed_state_1 = Closed_state_1_ka_minus*x[2] - Closed_state_1_ka_plus*Math.pow(Closed_state_1_Ca, Closed_state_1_n)*x[0];
        rate_Open_state_2 = Open_state_2_kb_plus*Math.pow(Open_state_2_Ca, Open_state_2_m)*x[2] - Open_state_2_kb_minus*x[3];
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        Closed_State_2_kc_minus = 0.1; // initial value of Closed_State_2_kc_minus
        Closed_State_2_kc_plus = 1.75; // initial value of Closed_State_2_kc_plus
        Closed_state_1_Ca = 0.9; // initial value of Closed_state_1_Ca
        Closed_state_1_ka_minus = 28.8; // initial value of Closed_state_1_ka_minus
        Closed_state_1_ka_plus = 1500.0; // initial value of Closed_state_1_ka_plus
        Closed_state_1_n = 4.0; // initial value of Closed_state_1_n
        Open_state_2_Ca = 0.9; // initial value of Open_state_2_Ca
        Open_state_2_kb_minus = 385.9; // initial value of Open_state_2_kb_minus
        Open_state_2_kb_plus = 1500.0; // initial value of Open_state_2_kb_plus
        Open_state_2_m = 3.0; // initial value of Open_state_2_m
    }

    /*
     * Model variables initial values
     */
    protected double rate_Closed_State_2;
    protected double rate_Closed_state_1;
    protected double rate_Open_state_2;
    protected double Closed_State_2_kc_minus;
    protected double Closed_State_2_kc_plus;
    protected double Closed_state_1_Ca;
    protected double Closed_state_1_ka_minus;
    protected double Closed_state_1_ka_plus;
    protected double Closed_state_1_n;
    protected double Open_probability;
    protected double Open_state_2_Ca;
    protected double Open_state_2_kb_minus;
    protected double Open_state_2_kb_plus;
    protected double Open_state_2_m;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[5];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = x[2];
        y[3] = x[3];
        y[4] = Open_probability;
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[4];
        this.time = 0.0;
        x[0] = 0.963; // - $"compartment.Pc1"
        x[1] = 0.037; // - $"compartment.Pc2"
        x[2] = 0.0; // - $"compartment.Po1"
        x[3] = 0.0; // - $"compartment.Po2"

        __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 'BIOMD0000000060.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_Closed_state_1;
        result[1] = +rate_Closed_State_2;
        result[2] = -rate_Closed_State_2-rate_Closed_state_1-rate_Open_state_2;
        result[3] = +rate_Open_state_2;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[4];
        __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 ...