|
1 | 1 | (* Mathematica Test File *)
|
2 | 2 |
|
3 |
| -testRxns = str2mass/@{"rxn1: a + b <-> c + d", "rxn2: a + b <-> c", "rxn3: a <-> b + c", "rxn4: a <-> 0", "rxn5: 0 <-> a"}; |
| 3 | +testRxns=str2mass/@{"rxn1: a + b <-> c + d","rxn2: a + b <-> c","rxn3: a <-> b + c","rxn4: a <-> 0","rxn5: 0 <-> a", |
| 4 | +"cmprt_rxn1: a_c + b_c <-> c_c + d_c","cmprt_rxn2: a_c + b_c <-> c_c","cmprt_rxn3: a_c <-> b_c + c_c","cmprt_rxn4: a_c <-> 0","cmprt_rxn5: 0 <-> a_c", |
| 5 | +"trans1: a_c <=> a_e","trans2: a_c + b_d <=> a_e + 3.3 e_c","trans3: 0 <=> a_e + 3.3 e_c","cmprt_rxn_weird: a_c + b_c <-> c_c + 3.3 d_c"}; |
4 | 6 |
|
5 |
| -cmpds=Union[Flatten[getCompounds/@testRxns]]; |
| 7 | +model=constructModel[testRxns,UnitChecking->True]; |
6 | 8 |
|
7 |
| -conc=MapIndexed[#->{1,Milli,Micro,Pico,Femto}[[First@#2]]Mole Liter^-1&,cmpds]; |
| 9 | +cmpds=Union[Flatten[getSpecies/@testRxns]]; |
8 | 10 |
|
9 |
| -param = Join[Keq[getID[#]]->1&/@testRxns,rateconst[getID[#]]->1&/@testRxns, rateconst[getID[#],False]->1&/@testRxns] |
| 11 | +metricPrefixes=Join[Sequence@@Table[{1,Milli,Micro,Pico,Femto,Giga,Tera,Yotta},{3}]] |
| 12 | +conc=MapIndexed[#->metricPrefixes[[First@#2]]Mole Liter^-1&,cmpds]; |
10 | 13 |
|
11 |
| -rates = makeRates[testRxns]; |
| 14 | +param=Join[Keq[getID[#]]->1&/@testRxns,rateconst[getID[#]]->1&/@testRxns,rateconst[getID[#],False]->1&/@testRxns] |
| 15 | + |
| 16 | +rates=stripTime@model["Rates"]; |
12 | 17 |
|
13 |
| -Print[adjustUnits[conc]]; |
14 | 18 |
|
15 | 19 | Test[
|
16 | 20 | adjustUnits[conc]
|
17 | 21 | ,
|
18 |
| - {metabolite["a", _] -> (1000*Milli*Mole)/Liter, metabolite["b", _] -> (Milli*Mole)/Liter, metabolite["c", _] -> (Milli*Mole)/(1000*Liter), metabolite["d", _] -> (Milli*Mole)/(1000000000*Liter)} |
| 22 | + {metabolite["a", "c"] -> Unit[1000, "Millimole"/"Liter"], metabolite["a", "e"] -> Unit[1, "Millimole"/"Liter"], metabolite["a", None] -> Unit[1/1000, "Millimole"/"Liter"], metabolite["b", "c"] -> Unit[1/1000000000, "Millimole"/"Liter"], metabolite["b", "d"] -> Unit[1/1000000000000, "Millimole"/"Liter"], metabolite["b", None] -> Unit[1000000000000, "Millimole"/"Liter"], metabolite["c", "c"] -> Unit[1000000000000000, "Millimole"/"Liter"], metabolite["c", None] -> Unit[1000000000000000000000000000, "Millimole"/"Liter"], metabolite["d", "c"] -> Unit[1000, "Millimole"/"Liter"], metabolite["d", None] -> Unit[1, "Millimole"/"Liter"], metabolite["e", "c"] -> Unit[1/1000, "Millimole"/"Liter"]} |
19 | 23 | ,
|
20 | 24 | TestID->"UnitCheckingRelatedTests-20120822-X4U4H1"
|
21 | 25 | ]
|
22 | 26 |
|
23 | 27 | Test[
|
24 | 28 | adjustUnits[{m["atp","c"] -> Pico Mole (Centi Meter)^-1}]
|
25 | 29 | ,
|
26 |
| - {metabolite["atp", "c"] -> (Milli*Mole)/(10000000*Meter)} |
| 30 | + {metabolite["atp", "c"] -> Unit[1/10000000, "Millimole"/"Meter"]} |
27 | 31 | ,
|
28 | 32 | TestID->"UnitCheckingRelatedTests-20120927-G1X3U0"
|
29 | 33 | ]
|
30 | 34 |
|
31 | 35 | Test[
|
32 | 36 | adjustUnits[{m["atp","c"] -> Pico Mole (Centi Meter)^-2}]
|
33 | 37 | ,
|
34 |
| - {metabolite["atp", "c"] -> (Milli*Mole)/(100000*Meter^2)} |
| 38 | + {metabolite["atp", "c"] -> Unit[1/100000, "Millimole"/"Meter"^2]} |
35 | 39 | ,
|
36 | 40 | TestID->"UnitCheckingRelatedTests-20120927-E8P5U8"
|
37 | 41 | ]
|
38 | 42 |
|
39 | 43 | Test[
|
40 | 44 | adjustUnits[{m["atp","c"] -> Pico Mole Feet^-3}]
|
41 | 45 | ,
|
42 |
| - {metabolite["atp", "c"] -> (Milli*Mole)/(28316846592*Liter)} |
| 46 | + {metabolite["atp", "c"] -> Unit[1/28316846592, "Millimole"/"Liter"]} |
43 | 47 | ,
|
44 | 48 | TestID->"UnitCheckingRelatedTests-20120927-E8P5U8"
|
45 | 49 | ]
|
46 | 50 |
|
47 |
| -(*Test[ |
48 |
| - adjustUnits[param, testRxns] |
49 |
| - , |
50 |
| - {Keq["rxn1"] -> 1, Keq["rxn2"] -> (1000*Liter)/Mole, Keq["rxn3"] -> Mole/(1000*Liter), Keq["rxn4"] -> 1, Keq["rxn5"] -> 1, rateconst["rxn1"] -> 1, rateconst["rxn2"] -> 1, rateconst["rxn3"] -> 1, rateconst["rxn4"] -> 1, rateconst["rxn5"] -> 1, rateconst["rxn1", False] -> (1000*Liter)/(Hour*Mole), rateconst["rxn2", False] -> Hour^(-1), rateconst["rxn3", False] -> (1000*Liter)/(Hour*Mole), rateconst["rxn4", False] -> Hour^(-1), rateconst["rxn5", False] -> Hour^(-1)} |
| 51 | +Test[ |
| 52 | + Quiet[adjustUnits[param, testRxns],{adjustUnits::noUnitsProvidedKeq,adjustUnits::noUnitsProvidedRateConst}] |
51 | 53 | ,
|
52 |
| - {adjustUnits::noUnits} |
| 54 | + {Keq["rxn1"] -> 1, Keq["rxn2"] -> Unit[1, "Liter"/"Millimole"], Keq["rxn3"] -> Unit[1, "Millimole"/"Liter"], Keq["rxn4"] -> 1, Keq["rxn5"] -> 1, Keq["cmprt_rxn1"] -> 1, Keq["cmprt_rxn2"] -> Unit[1, "Liter"/"Millimole"], Keq["cmprt_rxn3"] -> Unit[1, "Millimole"/"Liter"], Keq["cmprt_rxn4"] -> 1, Keq["cmprt_rxn5"] -> 1, Keq["trans1"] -> 1, Keq["trans2"] -> Unit[1., "Millimole"^2.3/"Liter"^2.3], Keq["trans3"] -> 1, Keq["cmprt_rxn_weird"] -> Unit[1., "Millimole"^2.3/"Liter"^2.3], rateconst["rxn1", True] -> Unit[1, "Liter"^2/("Hour"*"Millimole")], rateconst["rxn2", True] -> Unit[1, "Liter"^2/("Hour"*"Millimole")], rateconst["rxn3", True] -> Unit[1, "Liter"/"Hour"], rateconst["rxn4", True] -> Unit[1, "Liter"/"Hour"], rateconst["rxn5", True] -> Unit[1, "Liter"/"Hour"], rateconst["cmprt_rxn1", True] -> Unit[1, "Liter"/("Hour"*"Millimole")], rateconst["cmprt_rxn2", True] -> Unit[1, "Liter"/("Hour"*"Millimole")], rateconst["cmprt_rxn3", True] -> Unit[1, "Hour"^(-1)], rateconst["cmprt_rxn4", True] -> Unit[1, "Hour"^(-1)], rateconst["cmprt_rxn5", True] -> Unit[1, "Hour"^(-1)], rateconst["trans1", True] -> Unit[1, "Liter"/"Hour"], rateconst["trans2", True] -> Unit[1, "Liter"^2/("Hour"*"Millimole")], rateconst["trans3", True] -> Unit[1., "Liter"^4.3/("Hour"*"Millimole"^3.3)], rateconst["cmprt_rxn_weird", True] -> Unit[1, "Liter"/("Hour"*"Millimole")], rateconst["rxn1", False] -> Unit[1, "Liter"^2/("Hour"*"Millimole")], rateconst["rxn2", False] -> Unit[1, "Liter"/"Hour"], rateconst["rxn3", False] -> Unit[1, "Liter"^2/("Hour"*"Millimole")], rateconst["rxn4", False] -> Unit[1, "Liter"/"Hour"], rateconst["rxn5", False] -> Unit[1, "Liter"/"Hour"], rateconst["cmprt_rxn1", False] -> Unit[1, "Liter"/("Hour"*"Millimole")], rateconst["cmprt_rxn2", False] -> Unit[1, "Hour"^(-1)], rateconst["cmprt_rxn3", False] -> Unit[1, "Liter"/("Hour"*"Millimole")], rateconst["cmprt_rxn4", False] -> Unit[1, "Hour"^(-1)], rateconst["cmprt_rxn5", False] -> Unit[1, "Hour"^(-1)], rateconst["trans1", False] -> Unit[1, "Liter"/"Hour"], rateconst["trans2", False] -> Unit[1., "Liter"^4.3/("Hour"*"Millimole"^3.3)], rateconst["trans3", False] -> Unit[1., "Liter"^4.3/("Hour"*"Millimole"^3.3)], rateconst["cmprt_rxn_weird", False] -> Unit[1., "Liter"^3.3/("Hour"*"Millimole"^3.3)]} |
53 | 55 | ,
|
54 | 56 | TestID->"UnitCheckingRelatedTests-20120822-I8U2C3"
|
55 |
| -]*) |
56 |
| - |
57 |
| -(*Test[ |
58 |
| - {1 + 1} |
59 |
| - , |
60 |
| - {1 + 1} |
61 |
| - , |
62 |
| - TestID->"UnitCheckingRelatedTests-20120823-E7J5T9" |
63 | 57 | ]
|
64 | 58 |
|
65 | 59 |
|
66 |
| -SetOptions[adjustParameters, "DefaultAmountUnit" -> Mole] |
67 |
| -
|
68 | 60 | Test[
|
69 |
| - adjustUnits[param, testRxns] |
| 61 | + SetOptions[adjustUnits, "DefaultAmountUnit" -> Mole, "DefaultVolumeUnit" -> Meter^3, "DefaultTimeUnit"->Second]; |
| 62 | + Quiet[adjustUnits[param, testRxns],{adjustUnits::noUnitsProvidedKeq,adjustUnits::noUnitsProvidedRateConst}] |
70 | 63 | ,
|
71 |
| - {Keq["rxn1"] -> 1, Keq["rxn2"] -> (1000*Liter)/Mole, Keq["rxn3"] -> Mole/(1000*Liter), Keq["rxn4"] -> 1, Keq["rxn5"] -> 1, rateconst["rxn1"] -> 1, rateconst["rxn2"] -> 1, rateconst["rxn3"] -> 1, rateconst["rxn4"] -> 1, rateconst["rxn5"] -> 1, rateconst["rxn1", False] -> (1000*Liter)/(Hour*Mole), rateconst["rxn2", False] -> Hour^(-1), rateconst["rxn3", False] -> (1000*Liter)/(Hour*Mole), rateconst["rxn4", False] -> Hour^(-1), rateconst["rxn5", False] -> Hour^(-1)} |
| 64 | + {Keq["rxn1"] -> 1, Keq["rxn2"] -> Unit[1, "Meter"^3/"Mole"], Keq["rxn3"] -> Unit[1, "Mole"/"Meter"^3], Keq["rxn4"] -> 1, Keq["rxn5"] -> 1, Keq["cmprt_rxn1"] -> 1, Keq["cmprt_rxn2"] -> Unit[1, "Meter"^3/"Mole"], Keq["cmprt_rxn3"] -> Unit[1, "Mole"/"Meter"^3], Keq["cmprt_rxn4"] -> 1, Keq["cmprt_rxn5"] -> 1, Keq["trans1"] -> 1, Keq["trans2"] -> Unit[1., "Mole"^2.3/"Meter"^6.8999999999999995], Keq["trans3"] -> 1, Keq["cmprt_rxn_weird"] -> Unit[1., "Mole"^2.3/"Meter"^6.8999999999999995], rateconst["rxn1", True] -> Unit[1, "Meter"^6/("Mole"*"Second")], rateconst["rxn2", True] -> Unit[1, "Meter"^6/("Mole"*"Second")], rateconst["rxn3", True] -> Unit[1, "Meter"^3/"Second"], rateconst["rxn4", True] -> Unit[1, "Meter"^3/"Second"], rateconst["rxn5", True] -> Unit[1, "Meter"^3/"Second"], rateconst["cmprt_rxn1", True] -> Unit[1, "Meter"^3/("Mole"*"Second")], rateconst["cmprt_rxn2", True] -> Unit[1, "Meter"^3/("Mole"*"Second")], rateconst["cmprt_rxn3", True] -> Unit[1, "Second"^(-1)], rateconst["cmprt_rxn4", True] -> Unit[1, "Second"^(-1)], rateconst["cmprt_rxn5", True] -> Unit[1, "Second"^(-1)], rateconst["trans1", True] -> Unit[1, "Meter"^3/"Second"], rateconst["trans2", True] -> Unit[1, "Meter"^6/("Mole"*"Second")], rateconst["trans3", True] -> Unit[1., "Meter"^12.899999999999999/("Mole"^3.3*"Second")], rateconst["cmprt_rxn_weird", True] -> Unit[1, "Meter"^3/("Mole"*"Second")], rateconst["rxn1", False] -> Unit[1, "Meter"^6/("Mole"*"Second")], rateconst["rxn2", False] -> Unit[1, "Meter"^3/"Second"], rateconst["rxn3", False] -> Unit[1, "Meter"^6/("Mole"*"Second")], rateconst["rxn4", False] -> Unit[1, "Meter"^3/"Second"], rateconst["rxn5", False] -> Unit[1, "Meter"^3/"Second"], rateconst["cmprt_rxn1", False] -> Unit[1, "Meter"^3/("Mole"*"Second")], rateconst["cmprt_rxn2", False] -> Unit[1, "Second"^(-1)], rateconst["cmprt_rxn3", False] -> Unit[1, "Meter"^3/("Mole"*"Second")], rateconst["cmprt_rxn4", False] -> Unit[1, "Second"^(-1)], rateconst["cmprt_rxn5", False] -> Unit[1, "Second"^(-1)], rateconst["trans1", False] -> Unit[1, "Meter"^3/"Second"], rateconst["trans2", False] -> Unit[1., "Meter"^12.899999999999999/("Mole"^3.3*"Second")], rateconst["trans3", False] -> Unit[1., "Meter"^12.899999999999999/("Mole"^3.3*"Second")], rateconst["cmprt_rxn_weird", False] -> Unit[1., "Meter"^9.899999999999999/("Mole"^3.3*"Second")]} |
72 | 65 | ,
|
73 | 66 | TestID->"UnitCheckingRelatedTests-20120822-U7R3N3"
|
74 |
| -]*) |
| 67 | +] |
| 68 | + |
75 | 69 |
|
| 70 | +(*The following combinatorial code tests that rate and equilibrium constants always have the correct units regardless of the spatial dimension or compartimentalization of the model...*) |
| 71 | +combinatorialRxns = |
| 72 | + str2mass /@ {"1: a <=> p", "2: a + b <=> p", "3: a <=> p + q", |
| 73 | + "4: a[c] <=> p[c]", "5: a[c] + b[c] <=> p[c]", |
| 74 | + "6: a[c] <=> p[c] + q[c]", "7: a[c] <=> p[e]", |
| 75 | + "8: a[e] + b[c] <=> p[d]", "9: a[c] <=> p[e] + q[e]", "9: a[c] <=> p[e] + q[e] + z[g]", "10: a <=> p[e] + q + z[g]"}; |
| 76 | +Do[ |
| 77 | + SetOptions[adjustUnits, "DefaultAmountUnit" -> Millimole, "DefaultVolumeUnit" -> volumeUnit, "DefaultTimeUnit" -> Hour]; |
| 78 | + adjustedParam = Quiet[adjustUnits[{k[getID[rxn]] -> 1, Keq[getID[rxn]] -> 2, k[getID[rxn], False] -> .1}, {rxn}], {adjustUnits::noUnitsProvidedKeq,adjustUnits::noUnitsProvidedRateConst}]; |
| 79 | + units = Quiet[adjustUnits[adjustedParam, {rxn}],{adjustUnits::noUnitsProvidedKeq,adjustUnits::noUnitsProvidedRateConst}]; |
| 80 | + rate = stripTime[Toolbox`Private`reaction2rate[rxn]]; |
| 81 | + kkRate = keq2k[rate]; |
| 82 | + numRate = rate /. m_metabolite :> RandomReal[] Millimole volumeUnit^-1 /. units /. parameter["Volume", "c"] -> 1.5 volumeUnit; |
| 83 | + numRate2 = kkRate /. m_metabolite :> RandomReal[] Millimole volumeUnit^-1 /. units /. parameter["Volume", "c"] -> 1.5 volumeUnit; |
| 84 | + With[{testID=StringJoin["UnitCheckingRelatedTests-",volumeUnit /. {Meter->"m",Meter^2->"m^2",Meter^3->"m^3",Liter->"l"} ,"-",ToString[rxn]]}, |
| 85 | + Test[ |
| 86 | + MatchQ[numRate, Unit[_?NumberQ, "Millimole"*("Hour")^-1]]&&MatchQ[numRate2, Unit[_?NumberQ, "Millimole"*("Hour")^-1]] |
| 87 | + , |
| 88 | + True |
| 89 | + , |
| 90 | + TestID->testID |
| 91 | +] |
| 92 | +]; |
| 93 | + ,{rxn, combinatorialRxns}, {volumeUnit, {Meter, Meter^2, Meter^3,Liter}} |
| 94 | + ] |
0 commit comments