mxlpy 0.21.0__py3-none-any.whl → 0.23.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mxlpy/__init__.py +15 -2
- mxlpy/carousel.py +6 -4
- mxlpy/compare.py +4 -8
- mxlpy/experimental/diff.py +1 -1
- mxlpy/fit.py +195 -99
- mxlpy/identify.py +14 -9
- mxlpy/integrators/__init__.py +4 -0
- mxlpy/integrators/int_assimulo.py +3 -3
- mxlpy/integrators/int_diffrax.py +119 -0
- mxlpy/integrators/int_scipy.py +15 -6
- mxlpy/label_map.py +6 -7
- mxlpy/linear_label_map.py +3 -1
- mxlpy/mc.py +25 -22
- mxlpy/mca.py +10 -6
- mxlpy/meta/__init__.py +5 -3
- mxlpy/meta/codegen_latex.py +44 -30
- mxlpy/meta/codegen_model.py +175 -0
- mxlpy/meta/codegen_mxlpy.py +254 -0
- mxlpy/meta/source_tools.py +506 -221
- mxlpy/meta/sympy_tools.py +117 -0
- mxlpy/model.py +758 -257
- mxlpy/plot.py +16 -14
- mxlpy/report.py +153 -90
- mxlpy/sbml/_export.py +22 -11
- mxlpy/sbml/_import.py +68 -547
- mxlpy/scan.py +39 -243
- mxlpy/simulator.py +109 -283
- mxlpy/symbolic/symbolic_model.py +29 -17
- mxlpy/types.py +694 -97
- mxlpy/units.py +133 -0
- {mxlpy-0.21.0.dist-info → mxlpy-0.23.0.dist-info}/METADATA +4 -1
- mxlpy-0.23.0.dist-info/RECORD +57 -0
- mxlpy/meta/codegen_modebase.py +0 -112
- mxlpy/meta/codegen_py.py +0 -115
- mxlpy/sbml/_mathml.py +0 -692
- mxlpy/sbml/_unit_conversion.py +0 -74
- mxlpy-0.21.0.dist-info/RECORD +0 -56
- {mxlpy-0.21.0.dist-info → mxlpy-0.23.0.dist-info}/WHEEL +0 -0
- {mxlpy-0.21.0.dist-info → mxlpy-0.23.0.dist-info}/licenses/LICENSE +0 -0
mxlpy/sbml/_mathml.py
DELETED
@@ -1,692 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
from typing import TYPE_CHECKING, Any
|
4
|
-
|
5
|
-
from ._name_conversion import _name_to_py
|
6
|
-
from ._unit_conversion import get_ast_types
|
7
|
-
|
8
|
-
if TYPE_CHECKING:
|
9
|
-
from libsbml import ASTNode
|
10
|
-
|
11
|
-
__all__ = [
|
12
|
-
"AST_TYPES",
|
13
|
-
"handle_ast_constant_e",
|
14
|
-
"handle_ast_constant_false",
|
15
|
-
"handle_ast_constant_pi",
|
16
|
-
"handle_ast_constant_true",
|
17
|
-
"handle_ast_divide",
|
18
|
-
"handle_ast_divide_int",
|
19
|
-
"handle_ast_function",
|
20
|
-
"handle_ast_function_abs",
|
21
|
-
"handle_ast_function_ceiling",
|
22
|
-
"handle_ast_function_delay",
|
23
|
-
"handle_ast_function_exp",
|
24
|
-
"handle_ast_function_factorial",
|
25
|
-
"handle_ast_function_floor",
|
26
|
-
"handle_ast_function_ln",
|
27
|
-
"handle_ast_function_log",
|
28
|
-
"handle_ast_function_max",
|
29
|
-
"handle_ast_function_min",
|
30
|
-
"handle_ast_function_piecewise",
|
31
|
-
"handle_ast_function_power",
|
32
|
-
"handle_ast_function_rate_of",
|
33
|
-
"handle_ast_function_rem",
|
34
|
-
"handle_ast_function_root",
|
35
|
-
"handle_ast_integer",
|
36
|
-
"handle_ast_lambda",
|
37
|
-
"handle_ast_logical_and",
|
38
|
-
"handle_ast_logical_implies",
|
39
|
-
"handle_ast_logical_not",
|
40
|
-
"handle_ast_logical_or",
|
41
|
-
"handle_ast_logical_xor",
|
42
|
-
"handle_ast_minus",
|
43
|
-
"handle_ast_name",
|
44
|
-
"handle_ast_name_avogadro",
|
45
|
-
"handle_ast_name_time",
|
46
|
-
"handle_ast_originates_in_package",
|
47
|
-
"handle_ast_plus",
|
48
|
-
"handle_ast_rational",
|
49
|
-
"handle_ast_real",
|
50
|
-
"handle_ast_relational_eq",
|
51
|
-
"handle_ast_relational_geq",
|
52
|
-
"handle_ast_relational_gt",
|
53
|
-
"handle_ast_relational_leq",
|
54
|
-
"handle_ast_relational_lt",
|
55
|
-
"handle_ast_relational_neq",
|
56
|
-
"handle_ast_times",
|
57
|
-
"handle_ast_trigonometric_arc_cos",
|
58
|
-
"handle_ast_trigonometric_arc_cosh",
|
59
|
-
"handle_ast_trigonometric_arc_cot",
|
60
|
-
"handle_ast_trigonometric_arc_coth",
|
61
|
-
"handle_ast_trigonometric_arc_csc",
|
62
|
-
"handle_ast_trigonometric_arc_csch",
|
63
|
-
"handle_ast_trigonometric_arc_sec",
|
64
|
-
"handle_ast_trigonometric_arc_sech",
|
65
|
-
"handle_ast_trigonometric_arc_sin",
|
66
|
-
"handle_ast_trigonometric_arc_sinh",
|
67
|
-
"handle_ast_trigonometric_arc_tan",
|
68
|
-
"handle_ast_trigonometric_arc_tanh",
|
69
|
-
"handle_ast_trigonometric_cos",
|
70
|
-
"handle_ast_trigonometric_cosh",
|
71
|
-
"handle_ast_trigonometric_cot",
|
72
|
-
"handle_ast_trigonometric_coth",
|
73
|
-
"handle_ast_trigonometric_csc",
|
74
|
-
"handle_ast_trigonometric_csch",
|
75
|
-
"handle_ast_trigonometric_sec",
|
76
|
-
"handle_ast_trigonometric_sech",
|
77
|
-
"handle_ast_trigonometric_sin",
|
78
|
-
"handle_ast_trigonometric_sinh",
|
79
|
-
"handle_ast_trigonometric_tan",
|
80
|
-
"handle_ast_trigonometric_tanh",
|
81
|
-
"parse_sbml_math",
|
82
|
-
]
|
83
|
-
|
84
|
-
|
85
|
-
AST_TYPES = get_ast_types()
|
86
|
-
|
87
|
-
|
88
|
-
def handle_ast_constant_e(
|
89
|
-
node: ASTNode, # noqa: ARG001
|
90
|
-
func_arguments: list[str], # noqa: ARG001
|
91
|
-
) -> str:
|
92
|
-
return "math.e"
|
93
|
-
|
94
|
-
|
95
|
-
def handle_ast_constant_false(
|
96
|
-
node: ASTNode, # noqa: ARG001
|
97
|
-
func_arguments: list[str], # noqa: ARG001
|
98
|
-
) -> str:
|
99
|
-
return "False"
|
100
|
-
|
101
|
-
|
102
|
-
def handle_ast_constant_true(
|
103
|
-
node: ASTNode, # noqa: ARG001
|
104
|
-
func_arguments: list[str], # noqa: ARG001
|
105
|
-
) -> str:
|
106
|
-
return "True"
|
107
|
-
|
108
|
-
|
109
|
-
def handle_ast_constant_pi(
|
110
|
-
node: ASTNode, # noqa: ARG001
|
111
|
-
func_arguments: list[str], # noqa: ARG001
|
112
|
-
) -> str:
|
113
|
-
return "math.pi"
|
114
|
-
|
115
|
-
|
116
|
-
def handle_ast_divide(node: ASTNode, func_arguments: list[str]) -> str:
|
117
|
-
children = [
|
118
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
119
|
-
for i in range(node.getNumChildren())
|
120
|
-
]
|
121
|
-
bracketed_children = []
|
122
|
-
for child in children:
|
123
|
-
if len(child.split("+")) > 1:
|
124
|
-
bracketed_children.append(f"({child})")
|
125
|
-
else:
|
126
|
-
bracketed_children.append(child)
|
127
|
-
return " / ".join(bracketed_children)
|
128
|
-
|
129
|
-
|
130
|
-
def handle_ast_divide_int(node: ASTNode, func_arguments: list[str]) -> str:
|
131
|
-
children = [
|
132
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
133
|
-
for i in range(node.getNumChildren())
|
134
|
-
]
|
135
|
-
bracketed_children = []
|
136
|
-
for child in children:
|
137
|
-
if len(child.split("+")) > 1:
|
138
|
-
bracketed_children.append(f"({child})")
|
139
|
-
else:
|
140
|
-
bracketed_children.append(child)
|
141
|
-
return " // ".join(bracketed_children)
|
142
|
-
|
143
|
-
|
144
|
-
def handle_ast_function(node: ASTNode, func_arguments: list[str]) -> str:
|
145
|
-
children = [
|
146
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
147
|
-
for i in range(node.getNumChildren())
|
148
|
-
]
|
149
|
-
node_name = node.getName()
|
150
|
-
arguments = ", ".join(children)
|
151
|
-
return f"{node_name}({arguments})"
|
152
|
-
|
153
|
-
|
154
|
-
def handle_ast_function_abs(node: ASTNode, func_arguments: list[str]) -> str:
|
155
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
156
|
-
return f"np.abs({child})"
|
157
|
-
|
158
|
-
|
159
|
-
def handle_ast_function_ceiling(node: ASTNode, func_arguments: list[str]) -> str:
|
160
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
161
|
-
return f"np.ceil({child})"
|
162
|
-
|
163
|
-
|
164
|
-
def handle_ast_function_delay(node: ASTNode, func_arguments: list[str]) -> str:
|
165
|
-
raise NotImplementedError
|
166
|
-
|
167
|
-
|
168
|
-
def handle_ast_function_exp(node: ASTNode, func_arguments: list[str]) -> str:
|
169
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
170
|
-
return f"np.exp({child})"
|
171
|
-
|
172
|
-
|
173
|
-
def handle_ast_function_factorial(node: ASTNode, func_arguments: list[str]) -> str:
|
174
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
175
|
-
return f"scipy.special.factorial({child})"
|
176
|
-
|
177
|
-
|
178
|
-
def handle_ast_function_floor(node: ASTNode, func_arguments: list[str]) -> str:
|
179
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
180
|
-
return f"np.floor({child})"
|
181
|
-
|
182
|
-
|
183
|
-
def handle_ast_function_ln(node: ASTNode, func_arguments: list[str]) -> str:
|
184
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
185
|
-
return f"np.log({child})"
|
186
|
-
|
187
|
-
|
188
|
-
def handle_ast_function_log(node: ASTNode, func_arguments: list[str]) -> str:
|
189
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
190
|
-
return f"np.log10({child})"
|
191
|
-
|
192
|
-
|
193
|
-
def handle_ast_function_max(node: ASTNode, func_arguments: list[str]) -> str:
|
194
|
-
children = [
|
195
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
196
|
-
for i in range(node.getNumChildren())
|
197
|
-
]
|
198
|
-
args = ", ".join(children)
|
199
|
-
return f"np.max([{args}])"
|
200
|
-
|
201
|
-
|
202
|
-
def handle_ast_function_min(node: ASTNode, func_arguments: list[str]) -> str:
|
203
|
-
children = [
|
204
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
205
|
-
for i in range(node.getNumChildren())
|
206
|
-
]
|
207
|
-
args = ", ".join(children)
|
208
|
-
return f"np.min({args})"
|
209
|
-
|
210
|
-
|
211
|
-
def handle_ast_function_piecewise(node: ASTNode, func_arguments: list[str]) -> str:
|
212
|
-
children = [
|
213
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
214
|
-
for i in range(node.getNumChildren())
|
215
|
-
]
|
216
|
-
if len(children) == 3: # noqa: PLR2004
|
217
|
-
condition = children[1]
|
218
|
-
x = children[0]
|
219
|
-
y = children[2]
|
220
|
-
return f"np.where({condition}, {x}, {y})"
|
221
|
-
return f"({children[0]} if {children[1]} else 0.0)"
|
222
|
-
|
223
|
-
|
224
|
-
def handle_ast_function_power(node: ASTNode, func_arguments: list[str]) -> str:
|
225
|
-
children = [
|
226
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
227
|
-
for i in range(node.getNumChildren())
|
228
|
-
]
|
229
|
-
left_subchildren = node.getChild(0).getChild(0) is not None
|
230
|
-
right_subchildren = node.getChild(1).getChild(0) is not None
|
231
|
-
if left_subchildren and right_subchildren:
|
232
|
-
return f"({children[0]}) ** ({children[1]})"
|
233
|
-
if left_subchildren:
|
234
|
-
return f"({children[0]}) ** {children[1]}"
|
235
|
-
return f"{children[0]} ** ({children[1]})"
|
236
|
-
|
237
|
-
|
238
|
-
def handle_ast_function_rate_of(node: ASTNode, func_arguments: list[str]) -> str:
|
239
|
-
raise NotImplementedError
|
240
|
-
|
241
|
-
|
242
|
-
def handle_ast_function_root(node: ASTNode, func_arguments: list[str]) -> str:
|
243
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
244
|
-
return f"np.sqrt({child})"
|
245
|
-
|
246
|
-
|
247
|
-
def handle_ast_function_rem(node: ASTNode, func_arguments: list[str]) -> str:
|
248
|
-
children = [
|
249
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
250
|
-
for i in range(node.getNumChildren())
|
251
|
-
]
|
252
|
-
args = ", ".join(children)
|
253
|
-
return f"np.remainder({args})"
|
254
|
-
|
255
|
-
|
256
|
-
def handle_ast_integer(
|
257
|
-
node: ASTNode,
|
258
|
-
func_arguments: list[str], # noqa: ARG001
|
259
|
-
) -> str:
|
260
|
-
return str(int(node.getValue()))
|
261
|
-
|
262
|
-
|
263
|
-
def handle_ast_lambda(node: ASTNode, func_arguments: list[str]) -> str:
|
264
|
-
num_b_vars = node.getNumBvars()
|
265
|
-
num_children = node.getNumChildren()
|
266
|
-
children = [
|
267
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
268
|
-
for i in range(num_b_vars, num_children)
|
269
|
-
]
|
270
|
-
return ", ".join(children)
|
271
|
-
|
272
|
-
|
273
|
-
def handle_ast_logical_and(node: ASTNode, func_arguments: list[str]) -> str:
|
274
|
-
children = [
|
275
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
276
|
-
for i in range(node.getNumChildren())
|
277
|
-
]
|
278
|
-
if len(children) == 0:
|
279
|
-
return "and"
|
280
|
-
if len(children) == 1:
|
281
|
-
return "and"
|
282
|
-
args = " and ".join(children)
|
283
|
-
return f"({args})"
|
284
|
-
|
285
|
-
|
286
|
-
def handle_ast_logical_implies(
|
287
|
-
node: ASTNode,
|
288
|
-
func_arguments: list[str],
|
289
|
-
) -> str:
|
290
|
-
raise NotImplementedError
|
291
|
-
|
292
|
-
|
293
|
-
def handle_ast_logical_not(node: ASTNode, func_arguments: list[str]) -> str:
|
294
|
-
children = [
|
295
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
296
|
-
for i in range(node.getNumChildren())
|
297
|
-
]
|
298
|
-
if len(children) == 0:
|
299
|
-
return "not"
|
300
|
-
if len(children) == 1:
|
301
|
-
return f"not({children[0]})"
|
302
|
-
args = " not ".join(children)
|
303
|
-
return f"({args})"
|
304
|
-
|
305
|
-
|
306
|
-
def handle_ast_logical_or(node: ASTNode, func_arguments: list[str]) -> str:
|
307
|
-
children = [
|
308
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
309
|
-
for i in range(node.getNumChildren())
|
310
|
-
]
|
311
|
-
if len(children) == 0:
|
312
|
-
return "or"
|
313
|
-
if len(children) == 1:
|
314
|
-
return "or"
|
315
|
-
args = " or ".join(children)
|
316
|
-
return f"({args})"
|
317
|
-
|
318
|
-
|
319
|
-
def handle_ast_logical_xor(node: ASTNode, func_arguments: list[str]) -> str:
|
320
|
-
children = [
|
321
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
322
|
-
for i in range(node.getNumChildren())
|
323
|
-
]
|
324
|
-
if len(children) == 0:
|
325
|
-
return "^"
|
326
|
-
if len(children) == 1:
|
327
|
-
return "^"
|
328
|
-
children = [f"({i})" for i in children]
|
329
|
-
args = " ^ ".join(children)
|
330
|
-
return f"({args})"
|
331
|
-
|
332
|
-
|
333
|
-
def handle_ast_minus(node: ASTNode, func_arguments: list[str]) -> str:
|
334
|
-
children = [
|
335
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
336
|
-
for i in range(node.getNumChildren())
|
337
|
-
]
|
338
|
-
if node.getNumChildren() == 1:
|
339
|
-
child = node.getChild(0)
|
340
|
-
child_str = children[0]
|
341
|
-
if child.getChild(0) is not None:
|
342
|
-
return f"-({child_str})"
|
343
|
-
return f"-{child_str}"
|
344
|
-
return " - ".join(children)
|
345
|
-
|
346
|
-
|
347
|
-
def handle_ast_name(node: ASTNode, func_arguments: list[str]) -> str:
|
348
|
-
name: str = _name_to_py(node.getName())
|
349
|
-
func_arguments.append(name)
|
350
|
-
return name
|
351
|
-
|
352
|
-
|
353
|
-
def handle_ast_name_avogadro(
|
354
|
-
node: ASTNode, # noqa: ARG001
|
355
|
-
func_arguments: list[str], # noqa: ARG001
|
356
|
-
) -> str:
|
357
|
-
return "6.02214179e+23"
|
358
|
-
|
359
|
-
|
360
|
-
def handle_ast_name_time(
|
361
|
-
node: ASTNode, # noqa: ARG001
|
362
|
-
func_arguments: list[str],
|
363
|
-
) -> str:
|
364
|
-
func_arguments.append("time")
|
365
|
-
return "time"
|
366
|
-
|
367
|
-
|
368
|
-
def handle_ast_originates_in_package(node: ASTNode, func_arguments: list[str]) -> str:
|
369
|
-
raise NotImplementedError
|
370
|
-
|
371
|
-
|
372
|
-
def handle_ast_plus(node: ASTNode, func_arguments: list[str]) -> str:
|
373
|
-
children = [
|
374
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
375
|
-
for i in range(node.getNumChildren())
|
376
|
-
]
|
377
|
-
return " + ".join(children)
|
378
|
-
|
379
|
-
|
380
|
-
def handle_ast_rational(
|
381
|
-
node: ASTNode,
|
382
|
-
func_arguments: list[str], # noqa: ARG001
|
383
|
-
) -> str:
|
384
|
-
return str(node.getValue())
|
385
|
-
|
386
|
-
|
387
|
-
def handle_ast_real(
|
388
|
-
node: ASTNode,
|
389
|
-
func_arguments: list[str], # noqa: ARG001
|
390
|
-
) -> str:
|
391
|
-
value = str(node.getValue())
|
392
|
-
if value == "inf":
|
393
|
-
return "np.inf"
|
394
|
-
if value == "nan":
|
395
|
-
return "np.nan"
|
396
|
-
return value
|
397
|
-
|
398
|
-
|
399
|
-
def handle_ast_relational_eq(node: ASTNode, func_arguments: list[str]) -> str:
|
400
|
-
children = [
|
401
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
402
|
-
for i in range(node.getNumChildren())
|
403
|
-
]
|
404
|
-
if len(children) > 2: # noqa: PLR2004
|
405
|
-
raise NotImplementedError
|
406
|
-
return f"{children[0]} == {children[1]}"
|
407
|
-
|
408
|
-
|
409
|
-
def handle_ast_relational_geq(node: ASTNode, func_arguments: list[str]) -> str:
|
410
|
-
children = [
|
411
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
412
|
-
for i in range(node.getNumChildren())
|
413
|
-
]
|
414
|
-
if len(children) > 2: # noqa: PLR2004
|
415
|
-
raise NotImplementedError
|
416
|
-
return f"{children[0]} >= {children[1]}"
|
417
|
-
|
418
|
-
|
419
|
-
def handle_ast_relational_gt(node: ASTNode, func_arguments: list[str]) -> str:
|
420
|
-
children = [
|
421
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
422
|
-
for i in range(node.getNumChildren())
|
423
|
-
]
|
424
|
-
if len(children) > 2: # noqa: PLR2004
|
425
|
-
raise NotImplementedError
|
426
|
-
return f"{children[0]} > {children[1]}"
|
427
|
-
|
428
|
-
|
429
|
-
def handle_ast_relational_leq(node: ASTNode, func_arguments: list[str]) -> str:
|
430
|
-
children = [
|
431
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
432
|
-
for i in range(node.getNumChildren())
|
433
|
-
]
|
434
|
-
if len(children) > 2: # noqa: PLR2004
|
435
|
-
raise NotImplementedError
|
436
|
-
return f"{children[0]} <= {children[1]}"
|
437
|
-
|
438
|
-
|
439
|
-
def handle_ast_relational_lt(node: ASTNode, func_arguments: list[str]) -> str:
|
440
|
-
children = [
|
441
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
442
|
-
for i in range(node.getNumChildren())
|
443
|
-
]
|
444
|
-
if len(children) > 2: # noqa: PLR2004
|
445
|
-
raise NotImplementedError
|
446
|
-
return f"{children[0]} < {children[1]}"
|
447
|
-
|
448
|
-
|
449
|
-
def handle_ast_relational_neq(node: ASTNode, func_arguments: list[str]) -> str:
|
450
|
-
children = [
|
451
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
452
|
-
for i in range(node.getNumChildren())
|
453
|
-
]
|
454
|
-
if len(children) > 2: # noqa: PLR2004
|
455
|
-
raise NotImplementedError
|
456
|
-
return f"{children[0]} != {children[1]}"
|
457
|
-
|
458
|
-
|
459
|
-
def handle_ast_times(node: ASTNode, func_arguments: list[str]) -> str:
|
460
|
-
children = [
|
461
|
-
_handle_ast_node(node=node.getChild(i), func_arguments=func_arguments)
|
462
|
-
for i in range(node.getNumChildren())
|
463
|
-
]
|
464
|
-
bracketed_children = []
|
465
|
-
for child in children:
|
466
|
-
if len(child.split("+")) > 1:
|
467
|
-
bracketed_children.append(f"({child})")
|
468
|
-
else:
|
469
|
-
bracketed_children.append(child)
|
470
|
-
return " * ".join(bracketed_children)
|
471
|
-
|
472
|
-
|
473
|
-
###############################################################################
|
474
|
-
# Base
|
475
|
-
###############################################################################
|
476
|
-
|
477
|
-
|
478
|
-
def handle_ast_trigonometric_sin(node: ASTNode, func_arguments: list[str]) -> str:
|
479
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
480
|
-
return f"np.sin({child})"
|
481
|
-
|
482
|
-
|
483
|
-
def handle_ast_trigonometric_cos(node: ASTNode, func_arguments: list[str]) -> str:
|
484
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
485
|
-
return f"np.cos({child})"
|
486
|
-
|
487
|
-
|
488
|
-
def handle_ast_trigonometric_tan(node: ASTNode, func_arguments: list[str]) -> str:
|
489
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
490
|
-
return f"np.tan({child})"
|
491
|
-
|
492
|
-
|
493
|
-
def handle_ast_trigonometric_sec(node: ASTNode, func_arguments: list[str]) -> str:
|
494
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
495
|
-
return f"1 / np.cos({child})"
|
496
|
-
|
497
|
-
|
498
|
-
def handle_ast_trigonometric_csc(node: ASTNode, func_arguments: list[str]) -> str:
|
499
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
500
|
-
return f"1 / np.sin({child})"
|
501
|
-
|
502
|
-
|
503
|
-
def handle_ast_trigonometric_cot(node: ASTNode, func_arguments: list[str]) -> str:
|
504
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
505
|
-
return f"1 / np.tan({child})"
|
506
|
-
|
507
|
-
|
508
|
-
###############################################################################
|
509
|
-
# Inverse
|
510
|
-
###############################################################################
|
511
|
-
|
512
|
-
|
513
|
-
def handle_ast_trigonometric_arc_sin(node: ASTNode, func_arguments: list[str]) -> str:
|
514
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
515
|
-
return f"np.arcsin({child})"
|
516
|
-
|
517
|
-
|
518
|
-
def handle_ast_trigonometric_arc_cos(node: ASTNode, func_arguments: list[str]) -> str:
|
519
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
520
|
-
return f"np.arccos({child})"
|
521
|
-
|
522
|
-
|
523
|
-
def handle_ast_trigonometric_arc_tan(node: ASTNode, func_arguments: list[str]) -> str:
|
524
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
525
|
-
return f"np.arctan({child})"
|
526
|
-
|
527
|
-
|
528
|
-
def handle_ast_trigonometric_arc_cot(node: ASTNode, func_arguments: list[str]) -> str:
|
529
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
530
|
-
return f"np.arctan(1 / ({child}))"
|
531
|
-
|
532
|
-
|
533
|
-
def handle_ast_trigonometric_arc_sec(node: ASTNode, func_arguments: list[str]) -> str:
|
534
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
535
|
-
return f"np.arccos(1 / ({child}))"
|
536
|
-
|
537
|
-
|
538
|
-
def handle_ast_trigonometric_arc_csc(node: ASTNode, func_arguments: list[str]) -> str:
|
539
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
540
|
-
return f"np.arcsin(1 / ({child}))"
|
541
|
-
|
542
|
-
|
543
|
-
###############################################################################
|
544
|
-
# Hyperbolic
|
545
|
-
###############################################################################
|
546
|
-
|
547
|
-
|
548
|
-
def handle_ast_trigonometric_sinh(node: ASTNode, func_arguments: list[str]) -> str:
|
549
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
550
|
-
return f"np.sinh({child})"
|
551
|
-
|
552
|
-
|
553
|
-
def handle_ast_trigonometric_cosh(node: ASTNode, func_arguments: list[str]) -> str:
|
554
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
555
|
-
return f"np.cosh({child})"
|
556
|
-
|
557
|
-
|
558
|
-
def handle_ast_trigonometric_tanh(node: ASTNode, func_arguments: list[str]) -> str:
|
559
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
560
|
-
return f"np.tanh({child})"
|
561
|
-
|
562
|
-
|
563
|
-
def handle_ast_trigonometric_sech(node: ASTNode, func_arguments: list[str]) -> str:
|
564
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
565
|
-
return f"1 / np.cosh({child})"
|
566
|
-
|
567
|
-
|
568
|
-
def handle_ast_trigonometric_csch(node: ASTNode, func_arguments: list[str]) -> str:
|
569
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
570
|
-
return f"1 / np.sinh({child})"
|
571
|
-
|
572
|
-
|
573
|
-
def handle_ast_trigonometric_coth(node: ASTNode, func_arguments: list[str]) -> str:
|
574
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
575
|
-
return f"1 / np.tanh({child})"
|
576
|
-
|
577
|
-
|
578
|
-
###############################################################################
|
579
|
-
# Hyperbolic - inverse
|
580
|
-
###############################################################################
|
581
|
-
|
582
|
-
|
583
|
-
def handle_ast_trigonometric_arc_sinh(node: ASTNode, func_arguments: list[str]) -> str:
|
584
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
585
|
-
return f"np.arcsinh({child})"
|
586
|
-
|
587
|
-
|
588
|
-
def handle_ast_trigonometric_arc_cosh(node: ASTNode, func_arguments: list[str]) -> str:
|
589
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
590
|
-
return f"np.arccosh({child})"
|
591
|
-
|
592
|
-
|
593
|
-
def handle_ast_trigonometric_arc_tanh(node: ASTNode, func_arguments: list[str]) -> str:
|
594
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
595
|
-
return f"np.arctanh({child})"
|
596
|
-
|
597
|
-
|
598
|
-
def handle_ast_trigonometric_arc_csch(node: ASTNode, func_arguments: list[str]) -> str:
|
599
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
600
|
-
return f"np.arcsinh(1 / {child})"
|
601
|
-
|
602
|
-
|
603
|
-
def handle_ast_trigonometric_arc_sech(node: ASTNode, func_arguments: list[str]) -> str:
|
604
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
605
|
-
return f"np.arccosh(1 / {child})"
|
606
|
-
|
607
|
-
|
608
|
-
def handle_ast_trigonometric_arc_coth(node: ASTNode, func_arguments: list[str]) -> str:
|
609
|
-
child = _handle_ast_node(node=node.getChild(0), func_arguments=func_arguments)
|
610
|
-
return f"np.arctanh(1 / {child})"
|
611
|
-
|
612
|
-
|
613
|
-
def _handle_ast_node(node: ASTNode, func_arguments: list[str]) -> str:
|
614
|
-
commands = {
|
615
|
-
"AST_CONSTANT_E": handle_ast_constant_e,
|
616
|
-
"AST_CONSTANT_FALSE": handle_ast_constant_false,
|
617
|
-
"AST_CONSTANT_PI": handle_ast_constant_pi,
|
618
|
-
"AST_CONSTANT_TRUE": handle_ast_constant_true,
|
619
|
-
"AST_DIVIDE": handle_ast_divide,
|
620
|
-
"AST_FUNCTION": handle_ast_function,
|
621
|
-
"AST_FUNCTION_ABS": handle_ast_function_abs,
|
622
|
-
"AST_FUNCTION_ARCCOS": handle_ast_trigonometric_arc_cos,
|
623
|
-
"AST_FUNCTION_ARCCOSH": handle_ast_trigonometric_arc_cosh,
|
624
|
-
"AST_FUNCTION_ARCCOT": handle_ast_trigonometric_arc_cot,
|
625
|
-
"AST_FUNCTION_ARCCOTH": handle_ast_trigonometric_arc_coth,
|
626
|
-
"AST_FUNCTION_ARCCSC": handle_ast_trigonometric_arc_csc,
|
627
|
-
"AST_FUNCTION_ARCCSCH": handle_ast_trigonometric_arc_csch,
|
628
|
-
"AST_FUNCTION_ARCSEC": handle_ast_trigonometric_arc_sec,
|
629
|
-
"AST_FUNCTION_ARCSECH": handle_ast_trigonometric_arc_sech,
|
630
|
-
"AST_FUNCTION_ARCSIN": handle_ast_trigonometric_arc_sin,
|
631
|
-
"AST_FUNCTION_ARCSINH": handle_ast_trigonometric_arc_sinh,
|
632
|
-
"AST_FUNCTION_ARCTAN": handle_ast_trigonometric_arc_tan,
|
633
|
-
"AST_FUNCTION_ARCTANH": handle_ast_trigonometric_arc_tanh,
|
634
|
-
"AST_FUNCTION_CEILING": handle_ast_function_ceiling,
|
635
|
-
"AST_FUNCTION_COS": handle_ast_trigonometric_cos,
|
636
|
-
"AST_FUNCTION_COSH": handle_ast_trigonometric_cosh,
|
637
|
-
"AST_FUNCTION_COT": handle_ast_trigonometric_cot,
|
638
|
-
"AST_FUNCTION_COTH": handle_ast_trigonometric_coth,
|
639
|
-
"AST_FUNCTION_CSC": handle_ast_trigonometric_csc,
|
640
|
-
"AST_FUNCTION_CSCH": handle_ast_trigonometric_csch,
|
641
|
-
"AST_FUNCTION_DELAY": handle_ast_function_delay,
|
642
|
-
"AST_FUNCTION_EXP": handle_ast_function_exp,
|
643
|
-
"AST_FUNCTION_FACTORIAL": handle_ast_function_factorial,
|
644
|
-
"AST_FUNCTION_FLOOR": handle_ast_function_floor,
|
645
|
-
"AST_FUNCTION_LN": handle_ast_function_ln,
|
646
|
-
"AST_FUNCTION_LOG": handle_ast_function_log,
|
647
|
-
"AST_FUNCTION_MAX": handle_ast_function_max,
|
648
|
-
"AST_FUNCTION_MIN": handle_ast_function_min,
|
649
|
-
"AST_FUNCTION_PIECEWISE": handle_ast_function_piecewise,
|
650
|
-
"AST_FUNCTION_POWER": handle_ast_function_power,
|
651
|
-
"AST_FUNCTION_QUOTIENT": handle_ast_divide_int,
|
652
|
-
"AST_FUNCTION_RATE_OF": handle_ast_function_rate_of,
|
653
|
-
"AST_FUNCTION_ROOT": handle_ast_function_root,
|
654
|
-
"AST_FUNCTION_REM": handle_ast_function_rem,
|
655
|
-
"AST_FUNCTION_SEC": handle_ast_trigonometric_sec,
|
656
|
-
"AST_FUNCTION_SECH": handle_ast_trigonometric_sech,
|
657
|
-
"AST_FUNCTION_SIN": handle_ast_trigonometric_sin,
|
658
|
-
"AST_FUNCTION_SINH": handle_ast_trigonometric_sinh,
|
659
|
-
"AST_FUNCTION_TAN": handle_ast_trigonometric_tan,
|
660
|
-
"AST_FUNCTION_TANH": handle_ast_trigonometric_tanh,
|
661
|
-
"AST_INTEGER": handle_ast_integer,
|
662
|
-
"AST_LAMBDA": handle_ast_lambda,
|
663
|
-
"AST_LOGICAL_AND": handle_ast_logical_and,
|
664
|
-
"AST_LOGICAL_IMPLIES": handle_ast_logical_implies,
|
665
|
-
"AST_LOGICAL_NOT": handle_ast_logical_not,
|
666
|
-
"AST_LOGICAL_OR": handle_ast_logical_or,
|
667
|
-
"AST_LOGICAL_XOR": handle_ast_logical_xor,
|
668
|
-
"AST_MINUS": handle_ast_minus,
|
669
|
-
"AST_NAME": handle_ast_name,
|
670
|
-
"AST_NAME_AVOGADRO": handle_ast_name_avogadro,
|
671
|
-
"AST_NAME_TIME": handle_ast_name_time,
|
672
|
-
"AST_ORIGINATES_IN_PACKAGE": handle_ast_originates_in_package,
|
673
|
-
"AST_PLUS": handle_ast_plus,
|
674
|
-
"AST_POWER": handle_ast_function_power,
|
675
|
-
"AST_RATIONAL": handle_ast_rational,
|
676
|
-
"AST_REAL": handle_ast_real,
|
677
|
-
"AST_REAL_E": handle_ast_real,
|
678
|
-
"AST_RELATIONAL_EQ": handle_ast_relational_eq,
|
679
|
-
"AST_RELATIONAL_GEQ": handle_ast_relational_geq,
|
680
|
-
"AST_RELATIONAL_GT": handle_ast_relational_gt,
|
681
|
-
"AST_RELATIONAL_LEQ": handle_ast_relational_leq,
|
682
|
-
"AST_RELATIONAL_LT": handle_ast_relational_lt,
|
683
|
-
"AST_RELATIONAL_NEQ": handle_ast_relational_neq,
|
684
|
-
"AST_TIMES": handle_ast_times,
|
685
|
-
}
|
686
|
-
return commands[AST_TYPES[node.getType()]](node=node, func_arguments=func_arguments)
|
687
|
-
|
688
|
-
|
689
|
-
def parse_sbml_math(node: ASTNode) -> tuple[str, list[str]]:
|
690
|
-
func_arguments: list[Any] = []
|
691
|
-
body = _handle_ast_node(node=node, func_arguments=func_arguments)
|
692
|
-
return body, sorted(set(func_arguments))
|