/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000091.xml diagram  at 2008.03.20 15:08:21
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000091 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_ATPconsumption = k19*x[1];
        rate_ATPformation = k18*x[0];
        rate_HSETriHBinding = k14*x[5]*x[13];
        rate_HSETriHRelease = k15*x[6];
        rate_Hsp90Degradation = k17*x[8]*x[1];
        rate_Hsp90HSF1Binding = k8*x[8]*x[7];
        rate_Hsp90HSF1Release = k9*x[4];
        rate_Hsp90MisPBinding = k3*x[10]*x[8];
        rate_Hsp90Transcription = k16*x[6];
        rate_countTime = 1;
        rate_deDimerisation = k13*x[3];
        rate_deTrimerisation = k12*x[13];
        rate_dimerisation = (x[7] - 1)*k10*x[7]/2;
        rate_misfolding = k2*x[11]*x[12];
        rate_proteinAggregation1 = (x[10] - 1)*k7*x[10]/2;
        rate_proteinAggregation2 = k7*x[10]*x[2];
        rate_proteinDegradation = k6*x[10]*x[1];
        rate_proteinSynthesis = k1;
        rate_radicalFormation = k20;
        rate_radicalScavenging = k21*x[12];
        rate_refolding = k5*x[9]*x[1];
        rate_trimerisation = k11*x[7]*x[3];
        rate_unsuccessulRefolding = k4*x[9];
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        k1 = 10.0; // initial value of k1
        k10 = 0.01; // initial value of k10
        k11 = 100.0; // initial value of k11
        k12 = 0.5; // initial value of k12
        k13 = 0.5; // initial value of k13
        k14 = 0.05; // initial value of k14
        k15 = 0.08; // initial value of k15
        k16 = 1000.0; // initial value of k16
        k17 = 8.02E-9; // initial value of k17
        k18 = 12.0; // initial value of k18
        k19 = 0.02; // initial value of k19
        k2 = 2.0E-5; // initial value of k2
        k20 = 0.1; // initial value of k20
        k21 = 0.0010; // initial value of k21
        k3 = 50.0; // initial value of k3
        k4 = 1.0E-5; // initial value of k4
        k5 = 4.0E-6; // initial value of k5
        k6 = 6.0E-7; // initial value of k6
        k7 = 1.0E-7; // initial value of k7
        k8 = 500.0; // initial value of k8
        k9 = 1.0; // initial value of k9
    }

    /*
     * Model variables initial values
     */
    protected double _compartment_source_;
    protected double rate_ATPconsumption;
    protected double rate_ATPformation;
    protected double rate_HSETriHBinding;
    protected double rate_HSETriHRelease;
    protected double rate_Hsp90Degradation;
    protected double rate_Hsp90HSF1Binding;
    protected double rate_Hsp90HSF1Release;
    protected double rate_Hsp90MisPBinding;
    protected double rate_Hsp90Transcription;
    protected double rate_countTime;
    protected double rate_deDimerisation;
    protected double rate_deTrimerisation;
    protected double rate_dimerisation;
    protected double rate_misfolding;
    protected double rate_proteinAggregation1;
    protected double rate_proteinAggregation2;
    protected double rate_proteinDegradation;
    protected double rate_proteinSynthesis;
    protected double rate_radicalFormation;
    protected double rate_radicalScavenging;
    protected double rate_refolding;
    protected double rate_trimerisation;
    protected double rate_unsuccessulRefolding;
    protected double k1;
    protected double k10;
    protected double k11;
    protected double k12;
    protected double k13;
    protected double k14;
    protected double k15;
    protected double k16;
    protected double k17;
    protected double k18;
    protected double k19;
    protected double k2;
    protected double k20;
    protected double k21;
    protected double k3;
    protected double k4;
    protected double k5;
    protected double k6;
    protected double k7;
    protected double k8;
    protected double k9;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[15];
        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];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[15];
        this.time = 0.0;
        x[0] = 1000.0; // - $"compartment.ADP"
        x[1] = 10000.0; // - $"compartment.ATP"
        x[2] = 0.0; // - $"compartment.AggP"
        x[3] = 0.0; // - $"compartment.DiH"
        x[4] = 5900.0; // - $"compartment.HCom"
        x[5] = 1.0; // - $"compartment.HSE"
        x[6] = 0.0; // - $"compartment.HSETriH"
        x[7] = 100.0; // - $"compartment.HSF1"
        x[8] = 300000.0; // - $"compartment.Hsp90"
        x[9] = 0.0; // - $"compartment.MCom"
        x[10] = 0.0; // - $"compartment.MisP"
        x[11] = 6000000.0; // - $"compartment.NatP"
        x[12] = 100.0; // - $"compartment.ROS"
        x[13] = 0.0; // - $"compartment.TriH"
        x[14] = 0.0; // - $"compartment.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)
    {

        __internalRateVarInitFunc_0(time, x);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000091.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_ATPconsumption-rate_ATPformation+rate_Hsp90Degradation+rate_proteinDegradation+rate_refolding;
        result[1] = -rate_ATPconsumption+rate_ATPformation-rate_Hsp90Degradation-rate_proteinDegradation-rate_refolding;
        result[2] = +rate_proteinAggregation1+rate_proteinAggregation2*2-rate_proteinAggregation2;
        result[3] = -rate_deDimerisation+rate_deTrimerisation+rate_dimerisation-rate_trimerisation;
        result[4] = +rate_Hsp90HSF1Binding-rate_Hsp90HSF1Release;
        result[5] = -rate_HSETriHBinding+rate_HSETriHRelease;
        result[6] = +rate_HSETriHBinding-rate_HSETriHRelease+rate_Hsp90Transcription-rate_Hsp90Transcription;
        result[7] = -rate_Hsp90HSF1Binding+rate_Hsp90HSF1Release+rate_deDimerisation*2+rate_deTrimerisation-rate_dimerisation*2-rate_trimerisation;
        result[8] = -rate_Hsp90Degradation-rate_Hsp90HSF1Binding+rate_Hsp90HSF1Release-rate_Hsp90MisPBinding+rate_Hsp90Transcription+rate_refolding+rate_unsuccessulRefolding;
        result[9] = +rate_Hsp90MisPBinding-rate_refolding-rate_unsuccessulRefolding;
        result[10] = -rate_Hsp90MisPBinding+rate_misfolding-rate_proteinAggregation1*2-rate_proteinAggregation2-rate_proteinDegradation+rate_unsuccessulRefolding;
        result[11] = -rate_misfolding+rate_proteinSynthesis+rate_refolding;
        result[12] = +rate_misfolding-rate_misfolding+rate_radicalFormation-rate_radicalScavenging;
        result[13] = -rate_HSETriHBinding+rate_HSETriHRelease-rate_deTrimerisation+rate_trimerisation;
        result[14] = +rate_countTime;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[15];
        __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 ...