/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000015.xml diagram  at 2008.03.20 15:03:53
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000015 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_ada = ada_aada*Math.pow(x[0], ada_fada4);
        rate_ade = ade_aade*Math.pow(x[1], ade_fade6);
        rate_adna = adna_aadna*Math.pow(x[11], adna_fdnap9)*Math.pow(x[12], adna_fdnap10);
        rate_adrnr = adrnr_aadrnr*Math.pow(x[0], adrnr_fadrnr4)*Math.pow(x[11], adrnr_fadrnr9)*Math.pow(x[12], adrnr_fadrnr10);
        rate_ampd = ampd_aampd*Math.pow(x[0], ampd_fampd4)*Math.pow(x[3], ampd_fampd8)*Math.pow(cell_Pi, ampd_fampd18);
        rate_aprt = aprt_aaprt*Math.pow(x[6], aprt_faprt1)*Math.pow(x[0], aprt_faprt4)*Math.pow(x[1], aprt_faprt6);
        rate_arna = arna_aarna*Math.pow(x[0], arna_frnap4)*Math.pow(x[3], arna_frnap8);
        rate_asli = asli_aasli*Math.pow(x[9], asli_fasli3)*Math.pow(x[0], asli_fasli4);
        rate_asuc = asuc_aasuc*Math.pow(x[5], asuc_fasuc2)*Math.pow(x[0], asuc_fasuc4)*Math.pow(x[3], asuc_fasuc8)*Math.pow(cell_Pi, asuc_fasuc18);
        rate_dada = dada_adada*Math.pow(x[11], dada_fdada9);
        rate_den = den_aden*Math.pow(x[6], den_fden1)*Math.pow(x[5], den_fden2)*Math.pow(x[0], den_fden4)*Math.pow(x[3], den_fden8)*Math.pow(cell_Pi, den_fden18);
        rate_dgnuc = dgnuc_adgnuc*Math.pow(x[12], dgnuc_fdgnuc10);
        rate_dnaa = dnaa_adnaa*Math.pow(x[2], dnaa_fdnan12);
        rate_dnag = dnag_adnag*Math.pow(x[2], dnag_fdnan12);
        rate_gdna = gdna_agdna*Math.pow(x[11], gdna_fdnap9)*Math.pow(x[12], gdna_fdnap10);
        rate_gdrnr = gdrnr_agdrnr*Math.pow(x[3], gdrnr_fgdrnr8)*Math.pow(x[11], gdrnr_fgdrnr9)*Math.pow(x[12], gdrnr_fgdrnr10);
        rate_gmpr = gmpr_agmpr*Math.pow(x[5], gmpr_fgmpr2)*Math.pow(x[0], gmpr_fgmpr4)*Math.pow(x[10], gmpr_fgmpr7)*Math.pow(x[3], gmpr_fgmpr8);
        rate_gmps = gmps_agmps*Math.pow(x[0], gmps_fgmps4)*Math.pow(x[10], gmps_fgmps7);
        rate_gnuc = gnuc_agnuc*Math.pow(x[3], gnuc_fgnuc8)*Math.pow(cell_Pi, gnuc_fgnuc18);
        rate_gprt = gprt_agprt*Math.pow(x[6], gprt_fgprt1)*Math.pow(x[3], gprt_fgprt8)*Math.pow(x[4], gprt_fgprt15);
        rate_grna = grna_agrna*Math.pow(x[0], grna_frnap4)*Math.pow(x[3], grna_frnap8);
        rate_gua = gua_agua*Math.pow(x[4], gua_fgua15);
        rate_hprt = hprt_ahprt*Math.pow(x[6], hprt_fhprt1)*Math.pow(x[5], hprt_fhprt2)*Math.pow(x[13], hprt_fhprt13);
        rate_hx = hx_ahx*Math.pow(x[13], hx_fhx13);
        rate_hxd = hxd_ahxd*Math.pow(x[13], hxd_fhxd13);
        rate_impd = impd_aimpd*Math.pow(x[5], impd_fimpd2)*Math.pow(x[10], impd_fimpd7)*Math.pow(x[3], impd_fimpd8);
        rate_inuc = inuc_ainuc*Math.pow(x[5], inuc_finuc2)*Math.pow(cell_Pi, inuc_finuc18);
        rate_mat = mat_amat*Math.pow(x[0], mat_fmat4)*Math.pow(x[8], mat_fmat5);
        rate_polyam = polyam_apolyam*Math.pow(x[8], polyam_fpolyam5);
        rate_prpps = prpps_aprpps*Math.pow(x[6], prpps_fprpps1)*Math.pow(x[0], prpps_fprpps4)*Math.pow(x[3], prpps_fprpps8)*Math.pow(_cell_R5P_, prpps_fprpps17)*Math.pow(cell_Pi, prpps_fprpps18);
        rate_pyr = pyr_apyr*Math.pow(x[6], pyr_fpyr1);
        rate_rnaa = rnaa_arnaa*Math.pow(x[7], rnaa_frnan11);
        rate_rnag = rnag_arnag*Math.pow(x[7], rnag_frnan11);
        rate_trans = trans_atrans*Math.pow(x[8], trans_ftrans5);
        rate_ua = ua_aua*Math.pow(x[14], ua_fua16);
        rate_x = x_ax*Math.pow(x[15], x_fx14);
        rate_xd = xd_axd*Math.pow(x[15], xd_fxd14);
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        _cell_R5P_ = 18.0; // initial value of $"cell.R5P"
        cell_Pi = 1400.0; // initial value of $cell.Pi
        ada_aada = 0.001062; // initial value of ada_aada
        ada_fada4 = 0.97; // initial value of ada_fada4
        ade_aade = 0.01; // initial value of ade_aade
        ade_fade6 = 0.55; // initial value of ade_fade6
        adna_aadna = 3.2789; // initial value of adna_aadna
        adna_fdnap10 = 0.33; // initial value of adna_fdnap10
        adna_fdnap9 = 0.42; // initial value of adna_fdnap9
        adrnr_aadrnr = 0.0602; // initial value of adrnr_aadrnr
        adrnr_fadrnr10 = 0.87; // initial value of adrnr_fadrnr10
        adrnr_fadrnr4 = 0.1; // initial value of adrnr_fadrnr4
        adrnr_fadrnr9 = -0.3; // initial value of adrnr_fadrnr9
        ampd_aampd = 0.02688; // initial value of ampd_aampd
        ampd_fampd18 = -0.1; // initial value of ampd_fampd18
        ampd_fampd4 = 0.8; // initial value of ampd_fampd4
        ampd_fampd8 = -0.03; // initial value of ampd_fampd8
        aprt_aaprt = 233.8; // initial value of aprt_aaprt
        aprt_faprt1 = 0.5; // initial value of aprt_faprt1
        aprt_faprt4 = -0.8; // initial value of aprt_faprt4
        aprt_faprt6 = 0.75; // initial value of aprt_faprt6
        arna_aarna = 614.5; // initial value of arna_aarna
        arna_frnap4 = 0.05; // initial value of arna_frnap4
        arna_frnap8 = 0.13; // initial value of arna_frnap8
        asli_aasli = 66544.0; // initial value of asli_aasli
        asli_fasli3 = 0.99; // initial value of asli_fasli3
        asli_fasli4 = -0.95; // initial value of asli_fasli4
        asuc_aasuc = 3.5932; // initial value of asuc_aasuc
        asuc_fasuc18 = -0.05; // initial value of asuc_fasuc18
        asuc_fasuc2 = 0.4; // initial value of asuc_fasuc2
        asuc_fasuc4 = -0.24; // initial value of asuc_fasuc4
        asuc_fasuc8 = 0.2; // initial value of asuc_fasuc8
        dada_adada = 0.03333; // initial value of dada_adada
        dada_fdada9 = 1.0; // initial value of dada_fdada9
        den_aden = 5.2728; // initial value of den_aden
        den_fden1 = 2.0; // initial value of den_fden1
        den_fden18 = -0.08; // initial value of den_fden18
        den_fden2 = -0.06; // initial value of den_fden2
        den_fden4 = -0.25; // initial value of den_fden4
        den_fden8 = -0.2; // initial value of den_fden8
        dgnuc_adgnuc = 0.03333; // initial value of dgnuc_adgnuc
        dgnuc_fdgnuc10 = 1.0; // initial value of dgnuc_fdgnuc10
        dnaa_adnaa = 0.001938; // initial value of dnaa_adnaa
        dnaa_fdnan12 = 1.0; // initial value of dnaa_fdnan12
        dnag_adnag = 0.001318; // initial value of dnag_adnag
        dnag_fdnan12 = 1.0; // initial value of dnag_fdnan12
        gdna_agdna = 2.2296; // initial value of gdna_agdna
        gdna_fdnap10 = 0.33; // initial value of gdna_fdnap10
        gdna_fdnap9 = 0.42; // initial value of gdna_fdnap9
        gdrnr_agdrnr = 0.1199; // initial value of gdrnr_agdrnr
        gdrnr_fgdrnr10 = -0.39; // initial value of gdrnr_fgdrnr10
        gdrnr_fgdrnr8 = 0.4; // initial value of gdrnr_fgdrnr8
        gdrnr_fgdrnr9 = -1.2; // initial value of gdrnr_fgdrnr9
        gmpr_agmpr = 0.3005; // initial value of gmpr_agmpr
        gmpr_fgmpr2 = -0.15; // initial value of gmpr_fgmpr2
        gmpr_fgmpr4 = -0.07; // initial value of gmpr_fgmpr4
        gmpr_fgmpr7 = -0.76; // initial value of gmpr_fgmpr7
        gmpr_fgmpr8 = 0.7; // initial value of gmpr_fgmpr8
        gmps_agmps = 0.3738; // initial value of gmps_agmps
        gmps_fgmps4 = 0.12; // initial value of gmps_fgmps4
        gmps_fgmps7 = 0.16; // initial value of gmps_fgmps7
        gnuc_agnuc = 0.2511; // initial value of gnuc_agnuc
        gnuc_fgnuc18 = -0.34; // initial value of gnuc_fgnuc18
        gnuc_fgnuc8 = 0.9; // initial value of gnuc_fgnuc8
        gprt_agprt = 361.69; // initial value of gprt_agprt
        gprt_fgprt1 = 1.2; // initial value of gprt_fgprt1
        gprt_fgprt15 = 0.42; // initial value of gprt_fgprt15
        gprt_fgprt8 = -1.2; // initial value of gprt_fgprt8
        grna_agrna = 409.6; // initial value of grna_agrna
        grna_frnap4 = 0.05; // initial value of grna_frnap4
        grna_frnap8 = 0.13; // initial value of grna_frnap8
        gua_agua = 0.4919; // initial value of gua_agua
        gua_fgua15 = 0.5; // initial value of gua_fgua15
        hprt_ahprt = 12.569; // initial value of hprt_ahprt
        hprt_fhprt1 = 1.1; // initial value of hprt_fhprt1
        hprt_fhprt13 = 0.48; // initial value of hprt_fhprt13
        hprt_fhprt2 = -0.89; // initial value of hprt_fhprt2
        hx_ahx = 0.003793; // initial value of hx_ahx
        hx_fhx13 = 1.12; // initial value of hx_fhx13
        hxd_ahxd = 0.2754; // initial value of hxd_ahxd
        hxd_fhxd13 = 0.65; // initial value of hxd_fhxd13
        impd_aimpd = 1.2823; // initial value of impd_aimpd
        impd_fimpd2 = 0.15; // initial value of impd_fimpd2
        impd_fimpd7 = -0.09; // initial value of impd_fimpd7
        impd_fimpd8 = -0.03; // initial value of impd_fimpd8
        inuc_ainuc = 0.9135; // initial value of inuc_ainuc
        inuc_finuc18 = -0.36; // initial value of inuc_finuc18
        inuc_finuc2 = 0.8; // initial value of inuc_finuc2
        mat_amat = 7.2067; // initial value of mat_amat
        mat_fmat4 = 0.2; // initial value of mat_fmat4
        mat_fmat5 = -0.6; // initial value of mat_fmat5
        polyam_apolyam = 0.29; // initial value of polyam_apolyam
        polyam_fpolyam5 = 0.9; // initial value of polyam_fpolyam5
        prpps_aprpps = 0.9; // initial value of prpps_aprpps
        prpps_fprpps1 = -0.03; // initial value of prpps_fprpps1
        prpps_fprpps17 = 0.65; // initial value of prpps_fprpps17
        prpps_fprpps18 = 0.7; // initial value of prpps_fprpps18
        prpps_fprpps4 = -0.45; // initial value of prpps_fprpps4
        prpps_fprpps8 = -0.04; // initial value of prpps_fprpps8
        pyr_apyr = 1.2951; // initial value of pyr_apyr
        pyr_fpyr1 = 1.27; // initial value of pyr_fpyr1
        rnaa_arnaa = 0.06923; // initial value of rnaa_arnaa
        rnaa_frnan11 = 1.0; // initial value of rnaa_frnan11
        rnag_arnag = 0.04615; // initial value of rnag_arnag
        rnag_frnan11 = 1.0; // initial value of rnag_frnan11
        trans_atrans = 8.8539; // initial value of trans_atrans
        trans_ftrans5 = 0.33; // initial value of trans_ftrans5
        ua_aua = 8.744E-5; // initial value of ua_aua
        ua_fua16 = 2.21; // initial value of ua_fua16
        x_ax = 0.0012; // initial value of x_ax
        x_fx14 = 2.0; // initial value of x_fx14
        xd_axd = 0.949; // initial value of xd_axd
        xd_fxd14 = 0.55; // initial value of xd_fxd14
    }

    /*
     * Model variables initial values
     */
    protected double _cell_R5P_;
    protected double rate_ada;
    protected double rate_ade;
    protected double rate_adna;
    protected double rate_adrnr;
    protected double rate_ampd;
    protected double rate_aprt;
    protected double rate_arna;
    protected double rate_asli;
    protected double rate_asuc;
    protected double rate_dada;
    protected double rate_den;
    protected double rate_dgnuc;
    protected double rate_dnaa;
    protected double rate_dnag;
    protected double rate_gdna;
    protected double rate_gdrnr;
    protected double rate_gmpr;
    protected double rate_gmps;
    protected double rate_gnuc;
    protected double rate_gprt;
    protected double rate_grna;
    protected double rate_gua;
    protected double rate_hprt;
    protected double rate_hx;
    protected double rate_hxd;
    protected double rate_impd;
    protected double rate_inuc;
    protected double rate_mat;
    protected double rate_polyam;
    protected double rate_prpps;
    protected double rate_pyr;
    protected double rate_rnaa;
    protected double rate_rnag;
    protected double rate_trans;
    protected double rate_ua;
    protected double rate_x;
    protected double rate_xd;
    protected double cell_Pi;
    protected double ada_aada;
    protected double ada_fada4;
    protected double ade_aade;
    protected double ade_fade6;
    protected double adna_aadna;
    protected double adna_fdnap10;
    protected double adna_fdnap9;
    protected double adrnr_aadrnr;
    protected double adrnr_fadrnr10;
    protected double adrnr_fadrnr4;
    protected double adrnr_fadrnr9;
    protected double ampd_aampd;
    protected double ampd_fampd18;
    protected double ampd_fampd4;
    protected double ampd_fampd8;
    protected double aprt_aaprt;
    protected double aprt_faprt1;
    protected double aprt_faprt4;
    protected double aprt_faprt6;
    protected double arna_aarna;
    protected double arna_frnap4;
    protected double arna_frnap8;
    protected double asli_aasli;
    protected double asli_fasli3;
    protected double asli_fasli4;
    protected double asuc_aasuc;
    protected double asuc_fasuc18;
    protected double asuc_fasuc2;
    protected double asuc_fasuc4;
    protected double asuc_fasuc8;
    protected double dada_adada;
    protected double dada_fdada9;
    protected double den_aden;
    protected double den_fden1;
    protected double den_fden18;
    protected double den_fden2;
    protected double den_fden4;
    protected double den_fden8;
    protected double dgnuc_adgnuc;
    protected double dgnuc_fdgnuc10;
    protected double dnaa_adnaa;
    protected double dnaa_fdnan12;
    protected double dnag_adnag;
    protected double dnag_fdnan12;
    protected double gdna_agdna;
    protected double gdna_fdnap10;
    protected double gdna_fdnap9;
    protected double gdrnr_agdrnr;
    protected double gdrnr_fgdrnr10;
    protected double gdrnr_fgdrnr8;
    protected double gdrnr_fgdrnr9;
    protected double gmpr_agmpr;
    protected double gmpr_fgmpr2;
    protected double gmpr_fgmpr4;
    protected double gmpr_fgmpr7;
    protected double gmpr_fgmpr8;
    protected double gmps_agmps;
    protected double gmps_fgmps4;
    protected double gmps_fgmps7;
    protected double gnuc_agnuc;
    protected double gnuc_fgnuc18;
    protected double gnuc_fgnuc8;
    protected double gprt_agprt;
    protected double gprt_fgprt1;
    protected double gprt_fgprt15;
    protected double gprt_fgprt8;
    protected double grna_agrna;
    protected double grna_frnap4;
    protected double grna_frnap8;
    protected double gua_agua;
    protected double gua_fgua15;
    protected double hprt_ahprt;
    protected double hprt_fhprt1;
    protected double hprt_fhprt13;
    protected double hprt_fhprt2;
    protected double hx_ahx;
    protected double hx_fhx13;
    protected double hxd_ahxd;
    protected double hxd_fhxd13;
    protected double impd_aimpd;
    protected double impd_fimpd2;
    protected double impd_fimpd7;
    protected double impd_fimpd8;
    protected double inuc_ainuc;
    protected double inuc_finuc18;
    protected double inuc_finuc2;
    protected double mat_amat;
    protected double mat_fmat4;
    protected double mat_fmat5;
    protected double polyam_apolyam;
    protected double polyam_fpolyam5;
    protected double prpps_aprpps;
    protected double prpps_fprpps1;
    protected double prpps_fprpps17;
    protected double prpps_fprpps18;
    protected double prpps_fprpps4;
    protected double prpps_fprpps8;
    protected double pyr_apyr;
    protected double pyr_fpyr1;
    protected double rnaa_arnaa;
    protected double rnaa_frnan11;
    protected double rnag_arnag;
    protected double rnag_frnan11;
    protected double trans_atrans;
    protected double trans_ftrans5;
    protected double ua_aua;
    protected double ua_fua16;
    protected double x_ax;
    protected double x_fx14;
    protected double xd_axd;
    protected double xd_fxd14;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[16];
        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];
        y[11] = x[11];
        y[12] = x[12];
        y[13] = x[13];
        y[14] = x[14];
        y[15] = x[15];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[16];
        this.time = 0.0;
        x[0] = 2475.35; // - $"cell.ATP"
        x[1] = 0.98473; // - $"cell.Ade"
        x[2] = 5179.34; // - $"cell.DNA"
        x[3] = 410.223; // - $"cell.GTP"
        x[4] = 5.50638; // - $"cell.Gua"
        x[5] = 98.2634; // - $"cell.IMP"
        x[6] = 5.01742; // - $"cell.PRPP"
        x[7] = 28680.5; // - $"cell.RNA"
        x[8] = 3.99187; // - $"cell.SAM"
        x[9] = 0.198189; // - $"cell.SAMP"
        x[10] = 24.793; // - $"cell.XMP"
        x[11] = 6.01413; // - $"cell.dATP"
        x[12] = 3.02581; // - $"cell.dGTP"
        x[13] = 9.51785; // - $cell.HX
        x[14] = 100.293; // - $cell.UA
        x[15] = 5.05941; // - $cell.Xa

        __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 'BIOMD0000000015.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_ada-rate_adrnr-rate_ampd+rate_aprt-rate_arna+rate_asli-rate_mat+rate_rnaa+rate_trans;
        result[1] = -rate_ade-rate_aprt+rate_polyam;
        result[2] = +rate_adna-rate_dnaa-rate_dnag+rate_gdna;
        result[3] = -rate_gdrnr-rate_gmpr+rate_gmps-rate_gnuc+rate_gprt-rate_grna+rate_rnag;
        result[4] = +rate_dgnuc+rate_gnuc-rate_gprt-rate_gua;
        result[5] = +rate_ampd-rate_asuc+rate_den+rate_gmpr+rate_hprt-rate_impd-rate_inuc;
        result[6] = -rate_aprt-rate_den-rate_gprt-rate_hprt+rate_prpps-rate_pyr;
        result[7] = +rate_arna+rate_grna-rate_rnaa-rate_rnag;
        result[8] = +rate_mat-rate_polyam-rate_trans;
        result[9] = -rate_asli+rate_asuc;
        result[10] = -rate_gmps+rate_impd;
        result[11] = -rate_adna+rate_adrnr-rate_dada+rate_dnaa;
        result[12] = -rate_dgnuc+rate_dnag-rate_gdna+rate_gdrnr;
        result[13] = +rate_ada+rate_dada-rate_hprt-rate_hx-rate_hxd+rate_inuc;
        result[14] = -rate_ua+rate_xd;
        result[15] = +rate_gua+rate_hxd-rate_x-rate_xd;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[16];
        __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 ...