% Author: Elsa W. Birch, ewbirch@stanford.edu, Covert Lab - Stanford Bioengineering
% Date: 4/24/2011
% Version: associated with production of the figures for Birch et al. 2012 
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
%
% Summary: Evaluation of host growth rate dependant model parameters
% 
%
% Inputs: 
%
% Outputs: 
%
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
%
% Notes: 
%
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function [organismInitialized] = T7_37Growth_EB_VirusInitializer(organism)
    
model = organism.modelInfected.viralVarargin;

% could do some mu access here
% Growth rate
model.hostGrowth = organism.simulation.growth(1); % /h    ref endy thesis code
if isfield(organism.modelInfected, 'growthFactorResetValue') % this is a catch having to do with the limiting factor calculations
    model.hostGrowth = model.hostGrowth * organism.modelInfected.growthFactorResetValue;
%     model.hostGrowth
end

if model.hostGrowth < 0.6
    model.hostGrowth = 0.6;
end

% Calculated parameters
% Growth rate dependant simulation parameters 
% [Table I in Endy1997(Biotech&Bioeng)]
model.n_polymeraseEcoli = -103.59+model.hostGrowth*(548.977+model.hostGrowth*(-155.18+192.216*model.hostGrowth));
model.spacingRNAploymerase = 233/model.hostGrowth^2 + 73; % bp
% model.spacingRibosome = 82.5/model.hostGrowth + 145; % nt/ribosome
model.spacingRibosome = (((-31.7460*model.hostGrowth+215.5556)*model.hostGrowth-519.4921)*model.hostGrowth+492.7778)*model.hostGrowth-72.0952; % nt/ribosome
% % model.spacingRibosome = model.spacingRibosome / 3; % aa/ribosome
c = 42.4 + 132.7*exp(-2.812 * model.hostGrowth); % min
d = 22.3 + 15.4 * exp(-1.16 * model.hostGrowth); % min
model.NhostGenomePerCell = 60 / model.hostGrowth / (c * log(2) ) * ( 2 ^ (( c + d ) * model.hostGrowth / 60 ) - 2 ^ ( model.hostGrowth / 60 ) );
model.k_translation = 102.9 - 55.5 * (model.hostGrowth) ^ (-0.3906); % nt/sec/ribo
model.vol_Ecoli = 2 ^ ( model.hostGrowth + 2 ) * 1e-16; % liters
model.k_transcriptionEcoli = 108.7 - 63.6 * model.hostGrowth ^ (-0.1797); % nt/sec/RNAP
model.n_polymeraseEcoli = 192.2 * (model.hostGrowth ) ^ 3 - 155.5 * ( model.hostGrowth ) ^ 2 + 549 * ( model.hostGrowth ) - 103.6;
model.n_ribosome = 0.8 * (13.1*model.hostGrowth^2 - 6.89*model.hostGrowth + 6.46) * 1e3;

% rate of genome degradation calculation        
model.k_degradationEcoliDNA = model.NhostGenomePerCell * model.lengthHostGenome * model.fractHostGenomeDegrade * 2 ...
                                / model.tTotalHostGenomeDegrade;

% reassign to simulation structure
organism.modelInfected.viralVarargin = model;   
                                
% set nonzero initial concentration 
organism.simulation.viralConcentrations((4*model.n_gene +10),1) = model.NhostGenomePerCell;


organismInitialized = organism;