Simulation_main.m %% PDE simulation bead case c0= 20; % initial nutrient concentration etaC = @(x) 0.05 * x./(1.2-x); % function to compute eta_i etaS2 = etaC(1); n1_v12_long = zeros(26,8); n2_v12_long = zeros(26,8); S1_v12_long = zeros(26,8); S2_v12_long = zeros(26,8); k = 1; x = 40; for l = 0.3:0.1:1 etaS1 = etaC(l); try [n1,n2,S1,S2] = simuV1_2(etaS1,etaS2,c0,x); f = numel(n1); n1_v12_long(1:f,k) = n1(:); n2_v12_long(1:f,k) = n2(:); S1_v12_long(1:f,k) = S1(:); S2_v12_long(1:f,k) = S2(:); catch ME warning(['Problem for l=',num2str(l),' in solving equations. Problem is:\n',ME.message]); end k=k+1; end %% ODE simulation secondary metabolites etaC = @(x,c) 1/c * x./(1.2-x); c0 = 20; l = 0.1:0.1:1; maxS2=[]; gr_odeAlph_M = zeros(numel(l),1); for k=1:numel(l) eta1 = etaC(l(k),20); eta2 = 0.5; alpha = 0.2; odeSim = @(t,y) odeOfSimu_Alpha(t,y,eta1,eta2,alpha); [t,y] = ode45(odeSim, [0 30], [1e-2;c0;0.0001]); figure(5) hold on plot(t,y(:,1)) figure(6) hold on plot(t,y(:,2)) plot(t,y(:,3)) maxS2 = [maxS2;max(y(:,3))]; x1 = eta1*y(:,2); x2 = eta2*y(:,3); gr_ode = (x1+x2)./(x1+x2+1); figure(7) hold on plot(y(:,1),1.2 * gr_ode) gr_odeAlph_M(k) = 1.2 * mean(gr_ode(y(:,1)>0.05 & y(:,1)<0.5)); end %% PDE simulation secondary metabolite case etaC = @(x,c) 1/c * x./(1.16-x); tf = [33,25,20,17,14,12,11,10,9]; % simulation lengths c0 = 20; nW_v5_12_AlphChi_sl = zeros(tf(1)+1,10,1); nY_v5_12_AlphChi_sl = zeros(tf(1)+1,10,1); S1_v5_12_AlphChi_sl = zeros(tf(1)+1,10,1); S2_v5_12_AlphChi_sl = zeros(tf(1)+1,10,1); etaS2 = 0.5; k = 1; for l = 0.2:0.1:1 try etaS1 = etaC(l,20); alpha = 0.5; chi = 35 * (2 - gr_odeAlph_M(k)/1.2); tic [u,model,res] = simuV5_12_AlphaChi(etaS1,etaS2,c0,tf,alpha,chi); toc nW_v5_12_AlphChi_sl( 1:(tf(k)+1) ,k) = squeeze(mean(u(:,1,:),1)); nY_v5_12_AlphChi_sl( 1:(tf(k)+1) ,k) = squeeze(mean(u(:,2,:),1)); S1_v5_12_AlphChi_sl( 1:(tf(k)+1) ,k) = squeeze(mean(u(:,3,:),1)); S2_v5_12_AlphChi_sl( 1:(tf(k)+1) ,k) = squeeze(mean(u(:,4,:),1)); savefig(figure(2),['Maps_v5_12_AlphChi_l-',num2str(l),'_e2-',num2str(etaS2),'.fig']); savefig(figure(3),['Ncells_v5_12_AlphChi_l-',num2str(l),'_e2-',num2str(etaS2),'.fig']); savefig(figure(4),['CC_v5_12_AlphChi_l-',num2str(l),'_e2-',num2str(etaS2),'.fig']); close(figure(1)) close(figure(2)) close(figure(3)) close(figure(4)) catch ME warning(['Problem for l=',num2str(l),' in solving equations. Problem is:\n',ME.message]); end k = k+1; end simuV5_12_AlphaChi.m function [u,model,res] = simuV5_12_AlphaChi(etaS1,etaS2,c0,tf,alpha,chi) % Units of length = 100 µm, Unit of time = 1 h, unit of cc = 1mM normSize = 50; %Dc = 9*36; % 900 µm2/s %Ds = 5*36; % 500 µm2/s %Chi = 40*36; % 4 10^3 µm2/s % KE = 1e-3; % in mM from R. Endres model % n0 = 2e-3; % initial OD % c0 should be about 20 mM according to mat and meth times = [0.001,1:tf]; % creating the pde system model = createpde(4); R1 = [2;4;0;0;normSize;normSize;0;normSize;normSize;0]; geometryFromEdges(model,decsg(R1)); generateMesh(model,'Hmax',1,'Hmin',0.01,'GeometricOrder','quadratic'); %'quadratic' figure(1) pdegplot(model,'EdgeLabels','on') hold on pdeplot(model) axis equal CA = specifyCoefficients(model,'m',0,'d',1,'c',@Dcoef,'a',@GrowthCoeff,'f',@fcoeff); setInitialConditions(model,@initCond); q2 = [1.8,0,0,0; 0,1.8,0,0; 0,0, 0 ,0; 0,0,0, 0 ]; applyBoundaryCondition(model,'neumann','Edge',2,'q',q2); % to ensure no flux under gravity applyBoundaryCondition(model,'neumann','Edge',4,'q',-q2); model.SolverOptions.RelativeTolerance=1e-3; model.SolverOptions.AbsoluteTolerance=1e-6; model.SolverOptions.MaxIterations = 30000; model.SolverOptions.ReportStatistics='on'; model.SolverOptions.MinStep=0; res=solvepde(model,times); u = res.NodalSolution; figure(2) subplot(2,2,1) pdeplot(model,'xydata',u(:,1,end)); %.*(u(:,1,end)>0&u(:,1,end)<0.2) title('WT') subplot(2,2,2) pdeplot(model,'xydata',u(:,2,end)); title('CheY') subplot(2,2,3) pdeplot(model,'xydata',u(:,3,end)); title('S1') subplot(2,2,4) pdeplot(model,'xydata',u(:,4,end)); title('S2') n1 = squeeze(mean(u(:,1,:),1)) ; n2 = squeeze(mean(u(:,2,:),1)) ; figure(3) semilogy(times,n1) hold on semilogy(times,n2) S1 = squeeze(mean(u(:,3,:),1)); S2 = squeeze(mean(u(:,4,:),1)); figure(4) plot(times,S1) hold on plot(times,S2) function D = Dcoef(region,state) Dc = 3*36*1; % swimers 300 µm2/s Ds = 5*36*1; % nutrient 500 µm2/s Chi = -chi*36*1; % negative for positive chemotaxis Kn = 1e-3; nr = length(region.x); u1 = state.u(1,:); u3 = state.u(3,:); u4 = state.u(4,:); un = ones(1,nr); D = zeros(64,nr); D( 1,:) = Dc*un; D( 4,:) = Dc*un; D(21,:) = Dc*un; D(24,:) = Dc*un; D(33,:) = u1.*Chi./(u3+Kn); %u1 is the chemotactic cells D(36,:) = u1.*Chi./(u3+Kn); D(49,:) = u1.*Chi./(u4+Kn); %u1 is the chemotactic cells D(52,:) = u1.*Chi./(u4+Kn); D(41,:) = Ds*un; D(44,:) = Ds*un; D(61,:) = Ds*un; D(64,:) = Ds*un; end % D=[Dc,0,0,0,u1Chi/u5; % 0,Dc,0,0,0; % 0,0,Dn,0,0; % 0,0,0,Dn,0; % 0,0,0,0,Ds]; function a = GrowthCoeff(region,state) beta = 13; % in mM/OD lc = 1.2*1; nr = numel(region.x); u3 = state.u(3,:); u4 = state.u(4,:); nS1 = etaS1 .* u3; nS2 = etaS2 .* u4; Ktot =(1 + nS1+nS2); nS1 = lc* nS1./Ktot; nS2 = lc* nS2./Ktot; l12= - (nS1 +nS2); bl1 = beta * nS1/alpha; bl2 = beta * nS2 - (1-alpha) * bl1; a=[ l12 ;zeros(1,nr); bl1 ; bl2; % column1 zeros(1,nr); l12 ; bl1 ; bl2; % column2 zeros(1,nr);zeros(1,nr);zeros(1,nr);zeros(1,nr); % column3 zeros(1,nr);zeros(1,nr);zeros(1,nr);zeros(1,nr) % column4 ]; end % a = [l12 (1), 0 , 0,0; % 0 (2), l12, 0,0; % bl1 (3), bl1, 0,0; % bl2 (4), bl2, 0,0 % ]; function f = fcoeff(region,state) nr = numel(region.x); vsed = 1.80; % 180 µm/h f = zeros(4,nr); f(1,:) = vsed*state.uy(1,:); f(2,:) = vsed*state.uy(2,:); % f(3,:) = vsed*state.uy(3,:); % no sedimentation of the nutrient % f(4,:) = vsed*state.uy(4,:); end function ci = initCond(locations) n0 = 2e-3; dn0 = 2*1e-4; nr = numel(locations.x); un = ones(1,nr); ci = [n0 + dn0*(rand(1,nr)-0.5); n0 + dn0*(rand(1,nr)-0.5); c0*un; 0.0001*un]; % very small s2 initial cc to avoid numerical error negative values end end simuV1_2.m function [n1,n2,S1,S2] = simuV1_2(etaS1,etaS2,c0,x) % Units of length = 100 µm, Unit of time = 1 h, unit of cc = 1mM normSize = 50; %Dc = 9*36; % 900 µm2/s %Ds = 5*36; % 500 µm2/s n0 = 2e-3; % initial OD //previous value 0.1 area fraction = 10^3 /100*100 % c0 should be about 20 mM according to mat and meth ci = [n0;n0;c0;0.001]; GR = 20*etaS1/(1+20*etaS1) * 1.2; tf = floor(7.5/GR); % simulation duration times = [0.001,1:tf]; % creating the pde system model = createpde(4); R1 = [2;4;0;0;normSize;normSize;0;normSize;normSize;0]; geometryFromEdges(model,decsg(R1)); generateMesh(model,'Hmax',0.5,'Hmin',0.01,'GeometricOrder','quadratic'); %'quadratic' figure(1) pdegplot(model,'EdgeLabels','on') hold on pdeplot(model) axis equal CA = specifyCoefficients(model,'m',0,'d',1,'c',@Dcoef,'a',@GrowthCoeff,'f',[0;0;0;0]); setInitialConditions(model,ci); % Influx of nutrient 2 applyBoundaryCondition(model,'neumann','Edge',1, 'g',[0;0;0;normSize*0.2],'q',0); % dc/dt = dN/dt/hL2 = hLg/hL2 = g/L => g = L*2mM/10h model.SolverOptions.RelativeTolerance=1e-3; model.SolverOptions.AbsoluteTolerance=1e-6; model.SolverOptions.MaxIterations = 30000; model.SolverOptions.ReportStatistics='on'; model.SolverOptions.MinStep=0; res=solvepde(model,times); u = res.NodalSolution; figure(2) subplot(2,2,1) pdeplot(model,'xydata',u(:,1,end)); subplot(2,2,2) pdeplot(model,'xydata',u(:,2,end)); subplot(2,2,3) pdeplot(model,'xydata',u(:,3,end)); subplot(2,2,4) pdeplot(model,'xydata',u(:,4,end)); n1 = squeeze(mean(u(:,1,:),1)); n2 = squeeze(mean(u(:,2,:),1)); figure(3) semilogy(times,n1) hold on semilogy(times,n2) S1 = squeeze(mean(u(:,3,:),1)); S2 = squeeze(mean(u(:,4,:),1)); figure(4) plot(times,S1) hold on plot(times,S2) function D = Dcoef(region,state) Dc = 3*36*1; % 900 µm2/s Ds = 5*36*1; % 500 µm2/s Chi = -x*36*1; % 4 10^3 µm2/s negative for positive chemotaxis Kn = 1e-3; nr = length(region.x); u2 = state.u(2,:); u3 = state.u(3,:); u4 = state.u(4,:); un = ones(1,nr); D = zeros(64,nr); D( 1,:) = Dc*un; D( 4,:) = Dc*un; D(21,:) = Dc*un; D(24,:) = Dc*un; D(37,:) = u2.*Chi./(u3+Kn); % u2 is the chemotactic cells D(40,:) = u2.*Chi./(u3+Kn); D(41,:) = Ds*un; D(44,:) = Ds*un; D(53,:) = u2.*Chi./(u4+Kn); D(56,:) = u2.*Chi./(u4+Kn); D(61,:) = Ds*un; D(64,:) = Ds*un; end % D=[Dc,0,0,0; % 0,Dc,u2Chi/u3,u2Chi/u4; % 0,0,Ds,0; % 0,0,0,Ds]; function a = GrowthCoeff(region,state) beta = 13; % in mM/OD lc = 1.2*1; nr = numel(region.x); u3 = state.u(3,:); u4 = state.u(4,:); nS1 = etaS1 .* u3; nS2 = etaS2 .* u4; Ktot =(1 + nS1+nS2); nS1 = nS1./Ktot; nS2 = nS2./Ktot; l12= -lc* (nS1+nS2); bl1 = beta * lc* (nS1); bl2 = beta * lc* (nS2); a=[ l12; zeros(1,nr); bl1; bl2; zeros(1,nr); l12; bl1; bl2; zeros(1,nr);zeros(1,nr);zeros(1,nr);zeros(1,nr); % column3 zeros(1,nr);zeros(1,nr);zeros(1,nr);zeros(1,nr) % column4 ]; end % a = [l12 (1), 0 , 0,0; % 0 (2), l12, 0,0; % bl1 (3), bl1, 0,0; % bl2 (4), bl2, 0,0 % ]; end odeOfSimu_Alpha.m function dy = odeOfSimu_Alpha(t,y,eta1,eta2,alpha) dy = zeros(3,1); beta = 13; x1 = eta1*y(2); x2 = eta2*y(3); r = 1+x1+x2; l1 = x1./r; l2 = x2./r; dy(1) = (l1+l2).*y(1); dy(2) = -beta.* l1./alpha .*y(1); dy(3) = -beta.* (l2-l1.*(1-alpha)/alpha) .*y(1); end