/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000067.xml diagram  at 2008.03.20 15:04:54
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000067 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_R_Acs = compartment*(alpha2*Math.pow((x[1]/Kg2), n)/(1 + Math.pow((x[1]/Kg2), n)) + alpha0);
        rate_R_LacI = compartment*(alpha1*Math.pow((x[1]/Kg1), n)/(1 + Math.pow((x[1]/Kg1), n)) + alpha0);
        rate_R_Pta = alpha3/(1 + Math.pow((x[4]/Kg3), n)) + alpha0;
        rate_R_dAcs = compartment*kd*x[2];
        rate_R_dLacI = compartment*kd*x[4];
        rate_R_dPta = compartment*kd*x[6];
        rate_V_Ace = compartment*C*(x[5]*H - Keq*x[3]);
        rate_V_Ack = compartment*(kAck_f*x[1] - kAck_r*x[5]);
        rate_V_Acs = compartment*k2*x[2]*x[5]/(KM2 + x[5]);
        rate_V_Pta = compartment*k1*x[6]*x[0]/(KM1 + x[0]);
        rate_V_TCA = compartment*kTCA*x[0];
        rate_V_gly = compartment*S0;
        rate_V_out = compartment*k3*(x[3] - _compartment_HOAc_E_);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        compartment = 1.0; // initial value of $compartment
        C = 100.0; // initial value of C
        H = 1.0E-7; // initial value of H
        KM1 = 0.06; // initial value of KM1
        KM2 = 0.1; // initial value of KM2
        Keq = 5.0E-4; // initial value of Keq
        Kg1 = 10.0; // initial value of Kg1
        Kg2 = 10.0; // initial value of Kg2
        Kg3 = 0.0010; // initial value of Kg3
        S0 = 0.5; // initial value of S0
        alpha1 = 0.1; // initial value of alpha1
        alpha2 = 2.0; // initial value of alpha2
        alpha3 = 2.0; // initial value of alpha3
        k1 = 80.0; // initial value of k1
        k2 = 0.8; // initial value of k2
        k3 = 0.01; // initial value of k3
        kAck_f = 1.0; // initial value of kAck_f
        kAck_r = 1.0; // initial value of kAck_r
        kTCA = 10.0; // initial value of kTCA
        kd = 0.06; // initial value of kd
        n = 2.0; // initial value of n
    }

    /*
     * Model variables initial values
     */
    protected double _compartment_HOAc_E_;
    protected double rate_R_Acs;
    protected double rate_R_LacI;
    protected double rate_R_Pta;
    protected double rate_R_dAcs;
    protected double rate_R_dLacI;
    protected double rate_R_dPta;
    protected double rate_V_Ace;
    protected double rate_V_Ack;
    protected double rate_V_Acs;
    protected double rate_V_Pta;
    protected double rate_V_TCA;
    protected double rate_V_gly;
    protected double rate_V_out;
    protected double compartment;
    protected double C;
    protected double H;
    protected double KM1;
    protected double KM2;
    protected double Keq;
    protected double Kg1;
    protected double Kg2;
    protected double Kg3;
    protected double S0;
    protected double alpha0;
    protected double alpha1;
    protected double alpha2;
    protected double alpha3;
    protected double k1;
    protected double k2;
    protected double k3;
    protected double kAck_f;
    protected double kAck_r;
    protected double kTCA;
    protected double kd;
    protected double n;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[7];
        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];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[7];
        this.time = 0.0;
        x[0] = 0.0; // - $"compartment.AcCoA"
        x[1] = 0.0; // - $"compartment.AcP"
        x[2] = 0.0; // - $"compartment.Acs"
        x[3] = 0.0; // - $"compartment.HOAc"
        x[4] = 0.0; // - $"compartment.LacI"
        x[5] = 0.0; // - $"compartment.OAc"
        x[6] = 0.0; // - $"compartment.Pta"

        __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 'BIOMD0000000067.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_V_Acs-rate_V_Pta-rate_V_TCA+rate_V_gly;
        result[1] = -rate_V_Ack+rate_V_Pta;
        result[2] = +rate_R_Acs-rate_R_dAcs;
        result[3] = +rate_V_Ace-rate_V_out;
        result[4] = +rate_R_LacI-rate_R_dLacI;
        result[5] = -rate_V_Ace+rate_V_Ack-rate_V_Acs;
        result[6] = +rate_R_Pta-rate_R_dPta;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[7];
        __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 ...