/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000112.xml diagram  at 2008.03.20 15:08:49
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000112 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        sum_R_smad_nuc = x[6] + x[4] + x[5];
        sum_smad4_nuc = x[7] + x[5];
        sum_R_smad_cyt = x[2] + x[0] + x[1];
        sum_smad4_cyt = x[9] + x[1];
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_reaction_0 = 100*Math.exp(-time/90);
        rate_reaction_1 = reaction_1_KCAT*x[8]*x[2]/(reaction_1_K1 + x[2]);
        rate_reaction_2 = reaction_2_k2a*x[0]*x[9] - reaction_2_k2d*x[1];
        rate_reaction_3 = reaction_3_k3*x[1];
        rate_reaction_4 = reaction_4_k4nc*x[7] - reaction_4_k4cn*x[9];
        rate_reaction_5 = reaction_5_k5nc*x[6] - reaction_5_k5cn*x[2];
        rate_reaction_6 = reaction_6_k6d*x[5] - reaction_6_k6a*x[7]*x[4];
        rate_reaction_7 = reaction_7_Vmax7*x[4]/(reaction_7_K7 + x[4]);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        reaction_1_K1 = 289000.0; // initial value of reaction_1_K1
        reaction_1_KCAT = 3.51; // initial value of reaction_1_KCAT
        reaction_2_k2a = 6.5E-5; // initial value of reaction_2_k2a
        reaction_2_k2d = 0.0399; // initial value of reaction_2_k2d
        reaction_3_k3 = 16.6; // initial value of reaction_3_k3
        reaction_4_k4cn = 0.00497; // initial value of reaction_4_k4cn
        reaction_4_k4nc = 0.783; // initial value of reaction_4_k4nc
        reaction_5_k5cn = 0.563; // initial value of reaction_5_k5cn
        reaction_5_k5nc = 5.63; // initial value of reaction_5_k5nc
        reaction_6_k6a = 1.44E-4; // initial value of reaction_6_k6a
        reaction_6_k6d = 0.0492; // initial value of reaction_6_k6d
        reaction_7_K7 = 8950.0; // initial value of reaction_7_K7
        reaction_7_Vmax7 = 17100.0; // initial value of reaction_7_Vmax7
    }

    /*
     * Model variables initial values
     */
    protected double rate_reaction_0;
    protected double rate_reaction_1;
    protected double rate_reaction_2;
    protected double rate_reaction_3;
    protected double rate_reaction_4;
    protected double rate_reaction_5;
    protected double rate_reaction_6;
    protected double rate_reaction_7;
    protected double reaction_1_K1;
    protected double reaction_1_KCAT;
    protected double reaction_2_k2a;
    protected double reaction_2_k2d;
    protected double reaction_3_k3;
    protected double reaction_4_k4cn;
    protected double reaction_4_k4nc;
    protected double reaction_5_k5cn;
    protected double reaction_5_k5nc;
    protected double reaction_6_k6a;
    protected double reaction_6_k6d;
    protected double reaction_7_K7;
    protected double reaction_7_Vmax7;
    protected double sum_R_smad_cyt;
    protected double sum_R_smad_nuc;
    protected double sum_smad4_cyt;
    protected double sum_smad4_nuc;
    protected double time;

    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] = x[6];
        y[7] = x[7];
        y[8] = x[8];
        y[9] = x[9];
        y[10] = sum_R_smad_cyt;
        y[11] = sum_R_smad_nuc;
        y[12] = sum_smad4_cyt;
        y[13] = sum_smad4_nuc;
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[10];
        this.time = 0.0;
        x[0] = 0.0; // - $"cytoplasm.R_smad_P_cyt"
        x[1] = 0.0; // - $"cytoplasm.R_smad_P_smad4_cyt"
        x[2] = 162000.0; // - $"cytoplasm.R_smad_cyt"
        x[3] = 0.0; // - $"cytoplasm.nucleus.Pi"
        x[4] = 0.0; // - $"cytoplasm.nucleus.R_smad_P_nuc"
        x[5] = 0.0; // - $"cytoplasm.nucleus.R_smad_P_smad4_nuc"
        x[6] = 18000.0; // - $"cytoplasm.nucleus.R_smad_nuc"
        x[7] = 30000.0; // - $"cytoplasm.nucleus.smad4_nuc"
        x[8] = 10000.0; // - $"cytoplasm.receptor"
        x[9] = 120000.0; // - $"cytoplasm.smad4_cyt"

        __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 'BIOMD0000000112.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_reaction_1-rate_reaction_2;
        result[1] = +rate_reaction_2-rate_reaction_3;
        result[2] = -rate_reaction_1+rate_reaction_5;
        result[3] = +rate_reaction_7;
        result[4] = +rate_reaction_6-rate_reaction_7;
        result[5] = +rate_reaction_3-rate_reaction_6;
        result[6] = -rate_reaction_5+rate_reaction_7;
        result[7] = -rate_reaction_4+rate_reaction_6;
        result[8] = -rate_reaction_0;
        result[9] = -rate_reaction_2+rate_reaction_4;
    }
    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 ...