%template file for running BioNetGen simulations from Matlab

%In order to use the runbng function, you need to add to Matlab path 
%the directories containing the BioNetGen installation.  Make sure you save
%the path before exiting Matlab so that you don't need to add the
%directories again in the future.

%Note, the first time you run the runbng function, a window will pop up and
%ask you to give the location of the file BNG2.pl

%Change the current directory to your RuleBender project directory

%define the same basic constants as in RuleBender
vol=1;%1.1e-15;		%cell volume in  liters
avn=1;%6.022e23*1e-9; %avogadros number
RNAn=100; %average polymerase per minute per cell
PROn=1000; %average ribosomes per minute per cell

kPd = .0116;
kRd = .4159;
kRp = RNAn*kRd;
kPp = PROn*kPd/RNAn;



filename = 'ex1-GeneExpression.bngl';

changePar(filename,{'RNAn','kRp','kPp'},[RNAn,kRp,kPp]);

runbng('',filename); 
A = importdata([filename(1:end-4),'gdat'],' ',1); %import the data
time = A.data(:,1); %rename the time vector
R = A.data(:,2);
P = A.data(:,3);

i50 = find(R>R(end)/2,1,'first');


figure(1)

h = plot(time/60,R*vol*avn);
line([0 time(end)/60],[R(i50) R(i50)]*vol*avn,'color','k','linestyle','--')
line([time(i50) time(i50)]/60,[0 max(R)],'color','k','linestyle','--')
line([],[])
xlabel('time [hr]','fontsize',16);
ylabel('R [#]','fontsize',16);
set(h,'linewidth',3)
set(gca,'fontsize',16)
axis([0 time(end)/60 0 max(R)])




