library(ggplot2) library(dplyr) library(tidyr) library(deSolve) # Chemical concentrations across a 2 step reaction enzyme <- function(t, n, parameters){ with(as.list(c(t, n, parameters)),{ dE = -k1*E*S + k1r*ES + k2*ES - k2r*E*P1 - k3*E*P1 +k3r*EP +k4*EP -k4r*E*P2 dES = k1*E*S - k1r*ES - k2*ES +k2r*E*P1 dEP = k3*E*P1 -k3r*EP - k4*EP +k4r*E*P2 dS = -k1*E*S +k1r*ES dP1 = k2*ES -k2r*E*P1 - k3*E*P1 +k3r*EP dP2 = k4*EP - k4r*E*P2 dStot = dS + dES dP1tot = dP1 + dEP return(list(c(dE,dS, dES, dEP, dP1, dP2, dStot, dP1tot))) }) } parameters = c(k1 = 1208, #/sec k2 = 0.0087, #/sec k3 = 1208, #/sec - This changes across simulations k4 = 0.087, #/sec k1r = 0.01208, k2r = 0, k3r = 0.001208, k4r = 0) start_density = c(E = 0.000000, S = 0.0000757, ES = 0.0000043, EP = 0.0000007, P1 = 0.0000103, P2 = 0.000009, Stot=0.00008, P1tot=0.000011) time_to_sim = seq(from = 0 , to = 3600, by = 0.1) out1 = ode(y = start_density, times = time_to_sim, func = enzyme, parms = parameters) out1dataframe <-data.frame(out1) ggplot(out1dataframe, aes(x=time)) + geom_line(aes(y=Stot, color="Stot")) + geom_line(aes(y=P1tot, color="P1tot")) + geom_line(aes(y=P2, color="P2")) + ggtitle("Condition 1") Sim <-out1dataframe[seq(1,nrow(out1dataframe),600),] write.csv(Sim,"data.csv")