forked from blakeaw/GAlibrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pysb.py
151 lines (107 loc) · 3.85 KB
/
test_pysb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from pysb import Model, Parameter, Monomer, Rule, Observable, Initial
from scipy.stats import norm
import numpy as np
from galibrate.pysb import GaoIt, GAlibrateIt
SHARED = dict()
def test_gaoit_init():
SHARED["gao_it"] = GaoIt()
def test_gaoit_addbycall():
# We'll build a simple dimeration model
# with this call:
# Dimerization model:
# A + A <> AA
Model()
#######
V = 100.0
#######
SHARED["gao_it"](Parameter("kf", 0.001))
SHARED["gao_it"](Parameter("kr", 1.0), loc=np.log10(1.0) - 1.0, width=2.0)
Monomer("A", ["d"])
# Rules
Rule("ReversibleBinding", A(d=None) + A(d=None) | A(d=1) % A(d=1), kf, kr)
# Observables
Observable("A_free", A(d=None))
Observable("A_dimer", A(d=1) % A(d=1))
# Inital Conditions
Parameter("A_0", 20.0 * V)
Initial(A(d=None), A_0)
assert len(SHARED["gao_it"].parms) == 2
def test_gaoit_isub():
SHARED["gao_it"] -= model.parameters["kf"]
assert len(SHARED["gao_it"].parms) == 1
SHARED["gao_it"] -= "kr"
assert len(SHARED["gao_it"].parms) == 0
def test_gaoit_func_add_all_kinetic_params():
SHARED["gao_it"].add_all_kinetic_params(model)
assert len(SHARED["gao_it"].parms) == 2
def test_gaoit_getitem():
loc = np.log10(model.parameters["kf"].value) - 2.0
width = 4.0
loc_width = SHARED["gao_it"]["kf"]
assert np.allclose((loc, width), loc_width)
def test_gaoit_iadd():
gao_it = GaoIt()
gao_it += model.parameters["kf"]
assert len(gao_it.parms) == 1
assert "kf" in list(gao_it.parms.keys())
def test_gaoit_contains():
assert "kf" in SHARED["gao_it"]
assert "kr" in SHARED["gao_it"]
def test_gaoit_setitem():
loc = np.log10(model.parameters["kf"].value) - 1.0
width = 2.0
loc_width_old = SHARED["gao_it"]["kf"]
SHARED["gao_it"]["kf"] = (loc, width)
loc_width_new = SHARED["gao_it"]["kf"]
assert np.allclose(loc_width_new, [loc, width])
assert not np.allclose(loc_width_old, loc_width_new)
def test_gaoit_names():
assert SHARED["gao_it"].names() == ["kf", "kr"]
def test_gaoit_keys():
assert list(SHARED["gao_it"].keys()) == ["kf", "kr"]
def test_gaoit_mask():
assert SHARED["gao_it"].mask(model.parameters) == [True, True, False]
def test_gaoit_locs():
assert len(SHARED["gao_it"].locs()) == 2
def test_gaoit_widths():
assert len(SHARED["gao_it"].widths()) == 2
def test_gaoit_sampled_parameters():
assert len(SHARED["gao_it"].sampled_parameters()) == 2
def test_gaoit_add_all_nonkinetic_params():
gao_it = GaoIt()
gao_it.add_all_nonkinetic_params(model)
assert gao_it.mask(model.parameters) == [False, False, True]
def test_gaoit_add_by_name_with_string_input():
gao_it = GaoIt()
# Test adding by name with single string
gao_it.add_by_name(model, "kf")
assert gao_it.mask(model.parameters) == [True, False, False]
def test_gaoit_add_by_name_with_list_input():
gao_it = GaoIt()
# Test adding by name with list of strings
gao_it.add_by_name(model, ["kf", "kr"])
assert gao_it.mask(model.parameters) == [True, True, False]
def test_gaoit_add_by_name_with_tuple_input():
gao_it = GaoIt()
# Test adding by name with tuple of strings
gao_it.add_by_name(model, ("kr", "A_0"))
assert gao_it.mask(model.parameters) == [False, True, True]
if __name__ == "__main__":
test_gaoit_init()
test_gaoit_addbycall()
test_gaoit_isub()
test_gaoit_func_add_all_kinetic_params()
test_gaoit_getitem()
test_gaoit_iadd()
test_gaoit_contains()
test_gaoit_setitem()
test_gaoit_names()
test_gaoit_keys()
test_gaoit_mask()
test_gaoit_locs()
test_gaoit_widths()
test_gaoit_sampled_parameters()
test_gaoit_add_all_nonkinetic_params()
test_gaoit_add_by_name_with_string_input()
test_gaoit_add_by_name_with_list_input()
test_gaoit_add_by_name_with_tuple_input()