Skip to content

Commit 7f51aba

Browse files
committed
Add missing Acet_sim.m file.
1 parent 5e52ed8 commit 7f51aba

File tree

1 file changed

+151
-0
lines changed
  • module1_pk/2C_model_v3_acetaminophen_func

1 file changed

+151
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
function [out1,out2] = Acet_sim(q0,CA0,kA,V1x,V2x,OralOrIV,OnOrOff,SaveFigs,SimName);
2+
% Simulate one 'run' (simulation) of the Acetaminophen model.
3+
%
4+
% This function takes in key parameters, defines others, and calls the
5+
% solver for the simulation.
6+
%
7+
% The function returns two outputs (the AUC for compartment 1 and 2);
8+
% and receives five parameters, two flags, and a name string as inputs.
9+
%
10+
% The line above can be modified as needed to build a function that
11+
% returns/takes in more, fewer, or different outputs or parameters.
12+
% As a general rule, pass the parameters/outputs you think you will need,
13+
% rather than passing everything.
14+
%
15+
%% THIS FUNCTION RETURNS:
16+
% out1 = AUC in central compartment
17+
% out2 = AUC in peripheral compartment
18+
%
19+
%% ARGUMENTS
20+
% q0 = infusion rate
21+
% CA0 = initial concentration in gut compartment (or equivalent for IV)
22+
% kA = absorption rate constant
23+
% V1x = Volume of central compartment
24+
% V2x = Volume of peripheral compartment
25+
% OralOrIV = flag (0 for Oral delivery; 1 for IV delivery)
26+
% OnOrOff = figure visibility (0 for invisible; 1 for visible)
27+
% SaveFigs = exporting figures to files (0 for no; 1 for yes)
28+
% SimName = short text string to identify this simulation; used in naming
29+
% output figure files
30+
31+
%% PARAMETER VALUES
32+
% note some of these values are passed in from the driver
33+
% it's not necessary to change the names (e.g. q = q0), you could
34+
% just use the names above. We change the names only to emphasize
35+
% where they come from, and to leave it flexible and easy to change which
36+
% parameters get passed.
37+
38+
p.q = q0; % ug/hr
39+
p.V1 = V1x; % mL
40+
p.V2 = V2x; % mL
41+
p.kc1 = .472; % hr-1
42+
p.kc2 = 0; % hr-1
43+
p.k12 = .319; % hr-1
44+
p.k21 = .499; % hr-1
45+
p.ka = kA; % hr-1
46+
47+
D0 = CA0*p.V1; % ug/ml * ml = ug
48+
49+
% Initial conditions
50+
if OralOrIV == 1 % oral
51+
y0 = [0 0 0 D0]'; % y1,y2 in ug/ml; y3,y4 in ug
52+
elseif OralOrIV == 2 % IV
53+
y0 = [D0/p.V1 0 0 0]'; % y1,y2 in ug/ml; y3,y4 in ug
54+
end
55+
56+
SimLength = 10; % hours
57+
ReportingTimeStep = 1.0/60; % ask solver to return result every minute
58+
59+
%% CALL SOLVER
60+
61+
options = odeset('MaxStep',5e-2, 'AbsTol', 1e-5,'RelTol', 1e-5,'InitialStep', 1e-2);
62+
[T1,Y1] = ode45(@Acet_eqns,[0:ReportingTimeStep:SimLength],y0,options,p);
63+
64+
%% USE RESULTS TO CALCULATE MASS BALANCE and AUC
65+
66+
% equations 1 and 2 produce concentrations, so multiply by the approporiate
67+
% volumes to get amounts
68+
CurrentDrug(:,1) = Y1(:,1)*p.V1;
69+
CurrentDrug(:,2) = Y1(:,2)*p.V2;
70+
InitialDrug = y0(1)*p.V1 + y0(2)*p.V2 ;
71+
72+
% equations 3 and 4 are already in amount units, not concentration units;
73+
% so they don't need to be multiplied by volume
74+
CurrentDrug(:,3) = Y1(:,3);
75+
CurrentDrug(:,4) = Y1(:,4);
76+
77+
if OralOrIV == 1 % oral
78+
DrugIn = p.q*T1 + D0 ; % cumulative drug into system (continuous infusion + bolus)
79+
elseif OralOrIV == 2 % IV
80+
DrugIn = p.q*T1 ; % D0 already accounted for in initial drug
81+
end
82+
DrugOut = CurrentDrug(:,3) ; % cumulative drug eliminated from system
83+
BalanceD = DrugIn - DrugOut - CurrentDrug(:,1) - CurrentDrug(:,2) - CurrentDrug(:,4) + InitialDrug ; %(zero = balance)
84+
85+
% calculate AUC by integrating the concentration curve (trapezoidal rule)
86+
AUC1 = 0;
87+
AUC2 = 0;
88+
for i=1:(length(Y1)-1)
89+
AUC1 = AUC1 + 0.5*(Y1(i,1)+Y1(i+1,1))*(T1(i+1)-T1(i));
90+
AUC2 = AUC2 + 0.5*(Y1(i,2)+Y1(i+1,2))*(T1(i+1)-T1(i));
91+
end
92+
93+
%% VISUALIZATION
94+
95+
if SaveFigs == 1 || OnOrOff == 1 % if both zero, don't bother making the figures at all!
96+
97+
if OnOrOff == 1
98+
fig1 = figure;
99+
else
100+
fig1 = figure('visible','off');
101+
end
102+
103+
% figure;
104+
105+
ax1=subplot(2,2,1);
106+
plot(ax1,T1,Y1(:,1),'k',T1,Y1(:,2),'r',T1,Y1(:,4)/p.V1,'b','linewidth',3)
107+
title(ax1,'Drug Concentration')
108+
ylabel(ax1,'[D] (ug/ml)')
109+
xlabel(ax1,'time (hrs)')
110+
lgd = legend('central', 'peripheral', 'gut');
111+
lgd.Location = 'best';
112+
lgd.Title.String = ['Compartment'];
113+
114+
ax2=subplot(2,2,2);
115+
plot(ax2,T1,CurrentDrug(:,1),'k',T1,CurrentDrug(:,2),'r',T1,CurrentDrug(:,4),'b','linewidth',3)
116+
title(ax2,'Total Drug Amount')
117+
ylabel(ax2,'Total Drug (ug)')
118+
xlabel(ax2,'time (hrs)')
119+
lgd = legend('central', 'peripheral', 'gut');
120+
lgd.Location = 'best';
121+
lgd.Title.String = ['Compartment'];
122+
123+
ax3=subplot(2,2,3);
124+
plot(ax3,T1,DrugIn,'g',T1,DrugOut,'c','linewidth',3)
125+
title(ax3,'Cumulative Input/Output')
126+
ylabel(ax3,['Cumulative Drug in/out' newline 'of system (ug)'])
127+
xlabel(ax3,'time (hrs)')
128+
lgd = legend('input', 'output');
129+
lgd.Location = 'best';
130+
lgd.Title.String = ['Drug'];
131+
132+
ax4=subplot(2,2,4);
133+
plot(ax4,T1,BalanceD,'m','linewidth',3)
134+
title(ax4,'Molecular Balance') %(zero = balance)
135+
ylabel(ax4,'Balance of Drug (ug)')
136+
xlabel(ax4,'time (hrs)')
137+
138+
%% EXPORT VISUALIZATION
139+
if SaveFigs == 1
140+
set(fig1,'Position',[0 0 600 450]);
141+
exportgraphics(fig1, strcat('Fig1_',SimName,'.png'),'Resolution',300);
142+
end
143+
144+
end
145+
146+
%% RETURN OUTPUTS
147+
148+
out1 = AUC1;
149+
out2 = AUC2;
150+
151+
end

0 commit comments

Comments
 (0)