API Reference
This page contains the auto-generated documentation for the mantis-delta source code.
mantis.CRNetwork
Unified interface for Chemical Reaction Network Theory (CRNT) analysis.
Construct with CRNetwork.from_string(reaction_strings, rates=...).
Structural properties (deficiency, conservation laws, weak reversibility) are
computed lazily and cached; they do not require rate constants. Symbolic and
numerical methods require rate constants to be supplied.
Parameters
reactions : list[Reaction]
Directed Reaction objects. Each reversible string A <-> B produces two.
rates : dict[str, float], optional
Rate constants keyed by reaction strings, e.g. {"A -> B": 1.0}.
Keys are automatically normalized to canonical form (species sorted
alphabetically); use rate_keys() to inspect the expected form.
Source code in mantis/network.py
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
chemostatted
property
Chemostatted species and their fixed concentrations.
bifurcation(parameter, range, n_points=100, initial_conditions=None, plot=False, t_end=10000.0)
Scan one rate constant over a log-spaced range and collect steady states.
Parameters
parameter : str
Rate key to vary, e.g. "miR21 + H1 -> miR21_H1".
range : tuple[float, float]
(min, max) values for the parameter (log scale).
n_points : int
Number of points in the scan.
initial_conditions : dict[str, float], optional
Initial concentrations for each scan point (defaults to all-zero).
plot : bool
If True, display a bifurcation diagram for the first species.
t_end : float
ODE integration horizon in seconds (default 1e4). Increase for
systems with slow reactions whose timescale τ = 1/(k·[X]) >> 1e4 s.
Returns
BifurcationResult
Source code in mantis/network.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
crnt_summary()
Return a human-readable CRNT analysis summary.
Source code in mantis/network.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
from_string(reaction_strings, rates=None, chemostatted=None)
classmethod
Construct from human-readable reaction strings.
Parameters
reaction_strings : list[str]
Each string is one reaction, e.g. "A + 2B <-> C" or "ES -> E + P".
rates : dict[str, float], optional
Maps reaction strings to rate constants. Order of species within each
side does not matter; keys are normalized before lookup.
chemostatted : dict[str, float], optional
Species held at fixed concentrations by an external reservoir.
They are excluded from the ODE system and stoichiometry matrix rows,
but their concentrations are folded into flux expressions.
Source code in mantis/network.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
jacobian()
Return the symbolic Jacobian matrix (n_species × n_species), cached after first call.
Source code in mantis/network.py
198 199 200 201 202 203 204 205 | |
odes(numeric_rates=True)
Return mass-action ODEs as SymPy expressions keyed by species name.
Parameters
numeric_rates : bool
If True (default) and rates were supplied, substitute numerical values
so that the returned expressions contain floats rather than k_i symbols.
Source code in mantis/network.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
rate_keys()
Return canonical rate key strings for all reactions (for debugging).
Source code in mantis/network.py
148 149 150 | |
simulate(initial_conditions, t_span, t_eval=None, rtol=1e-08, atol=1e-12)
Integrate the ODE system forward in time and return the full trajectory.
Parameters
initial_conditions : dict[str, float] Initial concentrations; missing species default to 0. t_span : (t0, tf) Start and end times in seconds. t_eval : array-like, optional Times at which to store the solution. Defaults to 200 log-spaced points across t_span. rtol, atol : float Solver tolerances (passed to scipy Radau).
Returns
SimulationResult
.times, .concentrations (dict species → 1-D array),
.success. Use .final() for the last time-point dict
or .at(t) for a specific time.
Source code in mantis/network.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
steady_states(initial_conditions, n_attempts=50, seed=None, t_end=10000.0)
Find steady states from the given initial conditions.
Uses ODE integration (Radau) as the primary strategy, which exactly preserves conservation laws, then falls back to multi-start least_squares for additional steady states. Duplicate solutions (relative L2 distance < 10%) and non-physical solutions (any concentration < −tol) are discarded. Results are sorted by residual ascending and filtered by relative residual against the best solution found to remove spurious stuck-at-IC artifacts.
Parameters
initial_conditions : dict[str, float] Initial concentrations; missing species default to 0. n_attempts : int Total number of solver attempts (including the integration from IC). seed : int, optional RNG seed for reproducibility. t_end : float ODE integration horizon in seconds (default 1e4). Increase for systems with slow reactions whose timescale τ = 1/(k·[X]) >> 1e4 s.
Returns
list[SteadyState]
Each entry has .concentrations, .eigenvalues, .is_stable,
.is_oscillatory, and .residual.
Source code in mantis/network.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
stochastic_simulate(initial_conditions, t_span, volume_L, *, initial_as='concentration', max_events=1000000, seed=None)
Single-trajectory Gillespie SSA realization.
Use when molecule counts are low (∼ ≤ 10³) and the deterministic ODE gives the wrong answer — e.g., a CHA cascade at single-cell concentrations or stochastic switching in a bistable circuit.
Parameters
initial_conditions : species → initial count or concentration. t_span : (t0, tf) in seconds. volume_L : reaction volume in liters (e.g. 1e-4 = 100 µL). initial_as : 'concentration' (default) or 'count'. max_events : safety cap on reaction firings. seed : RNG seed for reproducibility.
Returns
StochasticResult with .times, .counts, .concentrations,
.at(t), .final().
Source code in mantis/network.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
tau_leap_simulate(initial_conditions, t_span, volume_L, *, initial_as='concentration', tau=None, epsilon=0.03, n_record=200, seed=None)
τ-leap stochastic simulation (approximate Gillespie).
Same interface as :meth:stochastic_simulate but fires reactions in
Poisson-distributed bursts over each leap rather than one at a time.
Roughly N× faster than direct SSA when populations are large (N is
the mean number of firings per leap), at the cost of asymptotic
accuracy as populations shrink.
Parameters
tau : optional fixed leap size (s); if None, adaptive τ per Cao 2006. epsilon : adaptive-τ tolerance (max fractional propensity change per leap). Smaller = more accurate, slower. n_record : number of evenly-spaced time points to record.
See :func:mantis.analysis.tau_leap_simulate for full details.
Source code in mantis/network.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
mantis.analysis
Numerical ODE simulation, steady-state finding, stability analysis, and bifurcation scanning.
SimulationResult
dataclass
Source code in mantis/analysis.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
at(t)
Return interpolated concentrations at time t.
Source code in mantis/analysis.py
40 41 42 43 44 | |
final()
Return concentrations at the last time point.
Source code in mantis/analysis.py
46 47 48 | |
StochasticResult
dataclass
Trajectory from a single Gillespie SSA realization.
Attributes
times : 1-D ndarray of reaction times (length n_events + 1) counts : dict species → 1-D ndarray of integer molecule counts concentrations : dict species → 1-D ndarray of concentrations (M) (counts / (volume * Avogadro)) n_events : number of reaction firings recorded success : True if integration finished before exhausting events volume_L : reaction volume in liters
Source code in mantis/analysis.py
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 | |
at(t)
Step-function lookup of concentrations at time t.
Source code in mantis/analysis.py
76 77 78 79 80 | |
build_ode_function(reactions, species, rate_values, chemostatted=None)
Return a callable f(t, y) → dydt using pure numpy. Pre-computes N matrix and ordered rate array for speed.
Chemostatted species are excluded from reactants_info (their contribution has already been folded into rate_values via fold_chemostatted_into_rates).
Source code in mantis/analysis.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |
classify_steady_state(eigenvalues, tol_zero=0.0001)
Returns (is_stable, is_oscillatory).
is_stable — True iff all significant eigenvalues have Re < 0.
is_oscillatory — True iff any significant eigenvalue has a non-trivial
imaginary part (|Im| > 1e-10 * |λ|). This covers both
stable spirals (Re<0) and unstable foci/spirals (Re>0),
i.e. any fixed point near a Hopf bifurcation.
Filters near-zero eigenvalues (from conservation law dimensions) before classifying.
Source code in mantis/analysis.py
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 | |
find_steady_states(reactions, species, rate_values, initial_conditions, n_attempts=50, tol=1e-08, seed=None, chemostatted_values=None, t_end=10000.0)
Steady-state finder using three strategies: 1. Direct least_squares from user IC (finds both stable and unstable fixed points). 2. ODE integration from user IC to t_end (conserves CLs; reaches stable attractors). 3. Multi-start with scale-aware random ICs → ODE then least_squares fallback.
Chemostatted species are folded into effective rate constants so the ODE system only tracks dynamic species.
Parameters
t_end : float Integration horizon for ODE-based strategies (seconds). The default (1e4 s) is intentionally short so that oscillatory / limit-cycle systems do not hang; the algebraic least_squares fallback handles those cases. For systems with very slow reactions (e.g. leakage pathways with τ >> 1e4 s) increase this value so that ODE integration reaches the true attractor. A safe upper bound is 10–100× the slowest relevant timescale (τ = 1 / (k_slow × [reactant])).
Returns a list of SteadyState objects, sorted by true ODE residual (lowest first), filtered to remove duplicate states and high-residual algebraic artifacts.
Source code in mantis/analysis.py
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 | |
gillespie_simulate(reactions, species, rate_values, initial_conditions, t_span, volume_L, *, initial_as='concentration', max_events=1000000, seed=None, chemostatted_values=None)
Single-trajectory Gillespie direct-method SSA.
Parameters
reactions, species, rate_values
Same shape as :func:simulate_ode — deterministic mass-action rates.
initial_conditions
Either molecule counts (set initial_as='count') or molar
concentrations (default).
t_span : (t0, tf)
Simulation interval.
volume_L : float
Reaction volume in liters. Required because stochastic propensities
depend on absolute molecule counts. For 100 µL physiological volume,
pass 1e-4.
initial_as : 'concentration' or 'count'
max_events : safety cap on reaction firings.
seed : optional RNG seed for reproducibility.
chemostatted_values : species kept at constant concentration; folded into
the propensities of reactions that consume them.
Returns
StochasticResult Full trajectory of times, counts and concentrations.
Source code in mantis/analysis.py
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
scan_bifurcation(reactions, species, base_rate_values, parameter, param_range, n_points, initial_conditions, n_attempts=20, chemostatted_values=None, t_end=10000.0)
Vary one rate constant over a log-spaced range and collect steady states.
Parameters
t_end : float
ODE integration horizon passed to find_steady_states at each point.
See that function's t_end documentation for guidance on choosing a
value appropriate for the slowest reaction timescale in your network.
Source code in mantis/analysis.py
922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 | |
simulate_ode(reactions, species, rate_values, initial_conditions, t_span, t_eval=None, chemostatted_values=None, rtol=1e-08, atol=1e-12)
Integrate the ODE system forward in time and return the full trajectory.
Parameters
t_span : (t0, tf)
Start and end times in seconds.
t_eval : array-like, optional
Times at which to store the solution. Defaults to 200 log-spaced
points across t_span (or linear if t_span[0] == 0 and t_span[1] <= 0).
chemostatted_values : dict, optional
Fixed concentrations folded into rate constants (same semantics as
find_steady_states).
Returns
SimulationResult
.times (1-D array), .concentrations (dict species → 1-D array),
.success (bool). Use .final() to get the last time-point dict
or .at(t) for a specific time.
Source code in mantis/analysis.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | |
tau_leap_simulate(reactions, species, rate_values, initial_conditions, t_span, volume_L, *, initial_as='concentration', tau=None, epsilon=0.03, n_record=200, seed=None, chemostatted_values=None)
Approximate Gillespie via τ-leap (Gillespie 2001; Cao, Gillespie, Petzold 2006).
Instead of one reaction per step, fire all reactions in parallel over a timestep τ, sampling each firing count from Poisson(a_j · τ). Much faster than direct SSA when populations are large and propensities change slowly, at the cost of accuracy: τ-leap is exact only in the limit of frequent reactions per leap (large molecule counts).
Parameters
reactions, species, rate_values, initial_conditions, t_span, volume_L,
initial_as, seed, chemostatted_values
Same as :func:gillespie_simulate.
tau : optional fixed leap size (seconds). If None, an adaptive τ is
chosen each step bounded by epsilon (Cao 2006 algorithm).
epsilon : adaptive-τ tolerance. Controls the maximum allowed fractional
change in any propensity per leap; smaller = more accurate but slower.
Ignored when tau is given.
n_record : approximate number of evenly-spaced time points to record in
the returned trajectory (the simulator's internal step is independent
of this — recording is via linear interpolation of step boundaries).
Returns
StochasticResult
Same shape as :func:gillespie_simulate.
Notes
To preserve non-negativity in stiff systems, this implementation falls back to a single direct-SSA step when the chosen τ would drive any species count below zero (a simple "leap rejection" — not the binomial Tian/Burrage refinement, but adequate for most kinetic-design contexts).
Source code in mantis/analysis.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |