Skip to content

Commit

Permalink
Add tests for EPS driver
Browse files Browse the repository at this point in the history
  • Loading branch information
langmm committed Dec 14, 2024
1 parent 96f625f commit 7fac79d
Show file tree
Hide file tree
Showing 14 changed files with 610 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
* text=auto

*.fig binary
*.mat binary
*.mdl binary diff merge=mlAutoMerge
*.mdlp binary
*.mex* binary
*.mlapp binary
*.mldatx binary
*.mlproj binary
*.mlx binary
*.p binary
*.sfx binary
*.sldd binary
*.slreqx binary merge=mlAutoMerge
*.slmx binary merge=mlAutoMerge
*.sltx binary
*.slxc binary
*.slx binary merge=mlAutoMerge
*.slxp binary

## Other common binary file types
*.docx binary
*.exe binary
*.jpg binary
*.pdf binary
*.png binary
*.xlsx binary
23 changes: 23 additions & 0 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run tests
'on':
push:
branches-ignore:
- gh-pages
tags:
- '*'
schedule:
- cron: 0 10 * * 1
jobs:
build_cxx:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
submodules: true
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v2
- name: Run tests
uses: matlab-actions/run-tests@v2
with:
select-by-folder: tests
48 changes: 48 additions & 0 deletions InitRatios.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function InitRatios(ParaNum, Ratio)
if ParaNum <= 0
return;
end

global PSRatio;
PSRatio=ones(103,1);
if ParaNum <= 103
PSRatio(ParaNum)=Ratio;
end

global SUCRatio;
SUCRatio=ones(66,1);
if ParaNum > 103&&ParaNum<=169
SUCRatio(ParaNum-103)=Ratio;
end

global PRRatio;
PRRatio=ones(48,1);
if ParaNum > 169&&ParaNum<=217
PRRatio(ParaNum-169)=Ratio;
end

global RacRatio;
RacRatio=ones(16,1);
if ParaNum > 217&&ParaNum<=233
RacRatio(ParaNum-217)=Ratio;
end

global FIRatio;
FIRatio=ones(23,1);
if ParaNum > 233&&ParaNum<=256
FIRatio(ParaNum-233)=Ratio;
end

global BFRatio;
BFRatio=ones(49,1);
if ParaNum > 256&&ParaNum<=305
BFRatio(ParaNum-256)=Ratio;
end

global XanRatio;
XanRatio=ones(4,1);
if ParaNum > 305&&ParaNum<=309
XanRatio(ParaNum-305)=Ratio;
end

end
200 changes: 200 additions & 0 deletions ePhotosynthesis.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
function values = ePhotosynthesis(driver, EnvFile, GRNFile, EnzymeFile, ATPCostFile, ...
OutputFile, OutputParamBase, WeatherTemp, ...
PARi, CO2i, O2i, ...
ProteinTotalRatio, GRNCin, GRNTin, ...
RUBISCOMETHODin, RUBISCOTOTALin, ...
PAR_in_Wpm2)
arguments
driver (1,1) string
EnvFile (1,1) string = ""
GRNFile (1,1) string = ""
EnzymeFile (1,1) string = ""
ATPCostFile (1,1) string = ""
OutputFile (1,1) string = "output.data"
OutputParamBase (1,1) string = ""
WeatherTemp (1,1) double = 25
PARi (1,1) double = 470
CO2i (1,1) double = 400
O2i (1,1) double = 0.21 % i.e. 21%
ProteinTotalRatio (1,1) double = 0.973
GRNCin (1,1) double = 0
GRNTin (1,1) double = 0
RUBISCOMETHODin (1,1) double = 2
RUBISCOTOTALin (1,1) double = 3
PAR_in_Wpm2 (1, 1) double = 0
end
driver = str2double(driver);

global GRNC;
global GRNT;
global pcfactor;
global cATPsyn;
global CPSi;
global cNADPHsyn;
global cpsii;
global VfactorC;
global CO2_Env;
global CO2_cond;
global O2_cond;
global Temp_cond;
global TestLi;
global TestCa;
global TestATPCost;
global TestSucPath;
global LI;
global Tp;
global RUBISCOMETHOD;
global RUBISCOTOTAL;
global GLight;
global VolRatioStCyto;
global dontCondition;
global dontGraph;
global dontClear;
% dontCondition = 1;
dontGraph = 1;
% dontClear = 1;

SucPath = 0;
ATPCost = 0.0;
GRNC = GRNCin;
GRNT = GRNTin;
RUBISCOMETHOD = RUBISCOMETHODin;
RUBISCOTOTAL = RUBISCOTOTALin;
pcfactor = 1.0 / 0.973;

if (strlength(EnvFile) > 0)
fprintf("EVN FILE PROVIDED: %s\n", EnvFile);
Env_data = ReadParam(EnvFile);
if isKey(Env_data, "WeatherTemp")
WeatherTemp = Env_data("WeatherTemp");
end
if isKey(Env_data, "PAR")
PARi = Env_data("PAR");
end
% TODO: Propery unit parsing?
if isKey(Env_data, "PAR_in_Wpm2")
PAR_in_Wpm2 = Env_data("PAR_in_Wpm2");
end
if isKey(Env_data, "CO2")
CO2i = Env_data("CO2");
end
if isKey(Env_data, "ProteinTotalRatio")
ProteinTotalRatio = Env_data("ProteinTotalRatio");
end
if isKey(Env_data, "GRNC")
GRNC = Env_data("GRNC");
end
if isKey(Env_data, "GRNT")
GRNT = Env_data("GRNT");
end
if isKey(Env_data, "SucPath")
SucPath = Env_data("SucPath");
end
end
if (strlength(ATPCostFile) > 0)
fprintf("ATPCOST FILE PROVIDED: %s\n", ATPCostFile);
ATPCost_data = ReadParam(ATPCostFile);
if isKey(ATPCost_data, "ATPCost")
ATPCost = ATPCost_data("ATPCost");
end
end

TestCa = CO2i;
TestLi = PARi;
if (PAR_in_Wpm2)
TestLi = TestLi * 1E6/(2.35E5); % Convert W m^{-2} to u moles m^{-2} s^{-1}
end
TestATPCost = ATPCost;
TestSucPath = SucPath;

if dontCondition
CO2_Env = 0.7 * TestCa; % intercellular CO2
CO2_cond = CO2_Env/(3 * 10^4);
% TestLi = TestLi / 30;
O2_cond = O2i * 1.26;
Tp = WeatherTemp;
pcfactor = 1/ProteinTotalRatio;
Temp_cond = Tp;
GLight = TestLi*0.85*0.85; % light umol m-2 s-1
VolRatioStCyto = 1;
end

if (strlength(GRNFile) > 0)
fprintf("GRN FILE PROVIDED: %s\n", GRNFile);
GRN_data = pcfactor * ReadGRN(GRNFile);
VfactorC = GRN_data(1:33);
if GRNC == 1
cATPsyn = GRN_data(34);
CPSi = GRN_data(35);
cNADPHsyn = GRN_data(37);
cpsii = GRN_data(36);
else
cATPsyn = 1;
CPSi = 1;
cNADPHsyn = 1;
cpsii = 1;
end
else
GRN_data = ones(36, 1);
end
if (strlength(EnzymeFile) > 0)
fprintf("ENZYME FILE PROVIDED: %s\n", EnzymeFile);
Enzyme_data = ReadEnzymes(EnzymeFile);
global EnzymeAct;
EnzymeAct = Enzyme_data(1:27) / 30; % unit change
global Jmax;
Jmax = EnzymeAct(27);
global BFVmax;
BFVmax = Enzyme_data(28:45);
global FIVmax;
FIVmax = Enzyme_data(46:66);
else
Enzyme_data = ones(66, 1);
end

if (strlength(OutputParamBase) > 0)
global export_mod_file_base;
global export_mod_enabled;
export_mod_enabled = 1;
export_mod_file_base = OutputParamBase;
end

if (driver == 1)
error("trDynaPS driver is disabled on this branch");
% ResultRate = trDynaPS_Drive(TestCa, TestLi, TestATPCost, TestSucPath, 1, 1);
% Arate = TargetFunVal;
% names = ["Light intensity", "Vc", "Vo", "VPGA", "VT3P", ...
% "Vstarch", "Vt_glycerate", "Vt_glycolate", "CO2AR"];
% nres = size(ResultRate, 1);
% values = zeros(nres+2, 1);
% values(1, 1) = TestLi;
% for i=1:nres
% values(i+1, 1) = ResultRate(i);
% end
% values(nres+2, 1) = Arate;
elseif (driver == 2)
error("DynaPS driver is disabled on this branch");
% ResultRate = DynaPS_Drive(1, 1);
% Arate = TargetFunVal;
% names = ["Light intensity", "PSIIabs", "PSIabs", "Vc", "Vo", ...
% "VPGA", "Vstarch", "Vsucrose", "CO2AR"];
% nres = size(ResultRate, 1);
% values = zeros(nres+2, 1);
% values(1, 1) = TestLi;
% for i=1:nres
% values(i+1, 1) = ResultRate(i);
% end
% values(nres+2, 1) = Arate;
elseif (driver == 3)
error("CM driver is disabled on this branch");
% CM_Drive;
% Arate = TargetFunVal;
% names = ["Light intensity", "CO2AR"];
% values = [TestLi; Arate];
elseif (driver == 4)
Arate = EPS_Drive(TestLi, TestCa, WeatherTemp);
names = [];
values = [Arate];
end
WriteTable(OutputFile, names, values);
end
1 change: 1 addition & 0 deletions tests/data/InputATPCost.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ATPCost 0
66 changes: 66 additions & 0 deletions tests/data/InputEnzyme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
V1 120
V2 1241.24
V3 166.35
V5 50.2
V6 29.91
V7 128.58
V8 50.2
V9 13.35
V10 128.57
V13 446.19
V23 8.01
V16 150
V112 1572.6
V113 171.47
V121 43.68
V122 99.19
V123 300.29
V124 82.37
V131 74.84
V51 3.22
V52 1.92
V55 3.46
V56 1.67
V57 16.65
V58 0.5
V59 3.03
Jmax 180
K1 1000000
K2 500
K3 50000000
K4 50000000
K5 50000000
K6 50000000
K7 10000
K8 1000
K9 8300000
K10 800000000
Vmax11 6
Kau 10000000000
Kua 10000000000
Kf 6300000
Kd 200000000
K15 10000000000
K16 100000
V2M 27.8
kA_d 200000000
kA_f 1260000
kA_U 10000000000
kU_A 10000000000
kU_d 200000000
kU_f 1260000
k1 2.5E+11
k_r1 300000000
kz 5000000
k12 30000
k23 10000
k30 3000
k01 500
k2 2000000000
kAB1 2500
kBA1 200
kAB2 3300
kBA2 250
k3 800
k_r3 80
k_pq_oxy 500
7 changes: 7 additions & 0 deletions tests/data/InputEvn.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CO2 400.0
PAR 470.0 # umol s**-1 m**-2
PAR_in_Wpm2 0
SucPath 0
WeatherTemperature 25.0
ProteinTotalRatio 0.973
GRNC 1.0
Loading

0 comments on commit 7fac79d

Please sign in to comment.