/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000037.xml diagram  at 2008.03.20 15:04:16
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000037 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_Glucose_sensor_inactivation = Glucose_sensor_inactivation_kG*x[9]*_compartment_Gluc_*compartment;
        rate_Photoreceptor_activation = compartment*x[0]*Photoreceptor_activation_IfrSfrPfr;
        rate_Photoreceptor_decay = compartment*Photoreceptor_decay_kd*x[6];
        rate_Photoreceptor_inactivation = Photoreceptor_inactivation_IrSrPr*x[6]*compartment;
        rate_S_degradation = x[1]*compartment;
        rate_S_formation = compartment*(S_formation_alpha1/(1 + Math.pow(x[2], 3)));
        rate_S_generation = x[3]*S_generation_ky*x[9]*compartment;
        rate_Transducer_activation = x[8]*Transducer_activation_kia*x[6]*compartment;
        rate_Transducer_inactivation = Transducer_inactivation_kai*x[7]*compartment;
        rate_V_degradation = compartment*x[2];
        rate_V_formation = compartment*(V_formation_alpha2/(1 + Math.pow(x[1], 3)));
        rate_preS_formation = x[4]*preS_formation_kx*x[7]*compartment;
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        compartment = 1.0; // initial value of $compartment
        Glucose_sensor_inactivation_kG = 0.1; // initial value of Glucose_sensor_inactivation_kG
        Photoreceptor_activation_IfrSfrPfr = 0.1; // initial value of Photoreceptor_activation_IfrSfrPfr
        Photoreceptor_decay_kd = 0.1; // initial value of Photoreceptor_decay_kd
        S_formation_alpha1 = 30.0; // initial value of S_formation_alpha1
        S_generation_ky = 1.0; // initial value of S_generation_ky
        Transducer_activation_kia = 0.1; // initial value of Transducer_activation_kia
        Transducer_inactivation_kai = 0.8; // initial value of Transducer_inactivation_kai
        V_formation_alpha2 = 50.0; // initial value of V_formation_alpha2
        preS_formation_kx = 0.2; // initial value of preS_formation_kx
    }

    /*
     * Model variables initial values
     */
    protected double _compartment_Gluc_;
    protected double rate_Glucose_sensor_inactivation;
    protected double rate_Photoreceptor_activation;
    protected double rate_Photoreceptor_decay;
    protected double rate_Photoreceptor_inactivation;
    protected double rate_S_degradation;
    protected double rate_S_formation;
    protected double rate_S_generation;
    protected double rate_Transducer_activation;
    protected double rate_Transducer_inactivation;
    protected double rate_V_degradation;
    protected double rate_V_formation;
    protected double rate_preS_formation;
    protected double compartment;
    protected double Glucose_sensor_inactivation_kG;
    protected double Photoreceptor_activation_IfrSfrPfr;
    protected double Photoreceptor_decay_kd;
    protected double Photoreceptor_inactivation_IrSrPr;
    protected double S_formation_alpha1;
    protected double S_generation_ky;
    protected double Transducer_activation_kia;
    protected double Transducer_inactivation_kai;
    protected double V_formation_alpha2;
    protected double preS_formation_kx;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[11];
        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] = x[10];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[11];
        this.time = 0.0;
        x[0] = 10.0; // - $"compartment.Pfr"
        x[1] = 0.0; // - $"compartment.S"
        x[2] = 30.0; // - $"compartment.V"
        x[3] = 0.0; // - $"compartment.preS"
        x[4] = 200.0; // - $"compartment.prepreS"
        x[5] = 0.0; // - $compartment.Pi
        x[6] = 0.0; // - $compartment.Pr
        x[7] = 0.0; // - $compartment.Xa
        x[8] = 6.0; // - $compartment.Xi
        x[9] = 0.9; // - $compartment.Ya
        x[10] = 0.0; // - $compartment.Yi

        __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)
    {

        __internalRateVarInitFunc_0(time, x);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000037.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_Photoreceptor_activation+rate_Photoreceptor_inactivation;
        result[1] = -rate_S_degradation+rate_S_formation+rate_S_generation;
        result[2] = -rate_V_degradation+rate_V_formation;
        result[3] = -rate_S_generation+rate_preS_formation;
        result[4] = -rate_preS_formation;
        result[5] = +rate_Photoreceptor_decay;
        result[6] = +rate_Photoreceptor_activation-rate_Photoreceptor_decay-rate_Photoreceptor_inactivation;
        result[7] = +rate_Transducer_activation-rate_Transducer_inactivation;
        result[8] = -rate_Transducer_activation+rate_Transducer_inactivation;
        result[9] = -rate_Glucose_sensor_inactivation;
        result[10] = +rate_Glucose_sensor_inactivation;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[11];
        __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 ...