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 452 453 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 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 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 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 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 883 | |
chemostatted
property
Chemostatted species and their fixed concentrations.
all_steady_states(initial_conditions, backend='auto', scale=None)
Exhaustively enumerate all positive steady states (with completeness).
Unlike :meth:steady_states (ODE integration + multi-start least-squares,
which can silently miss unstable fixed points), this solves the mass-action
steady-state polynomial system for every complex root and returns the real
non-negative ones — so it certifies the full steady-state set rather than
sampling it. The classic payoff: on the Schlögl model it returns all three
equilibria, including the unstable middle branch that integration never
reaches.
Parameters
initial_conditions : dict[str, float]
Used only to fix the conservation-law totals (the stoichiometric
compatibility class) for closed networks.
backend : {'auto', 'sympy', 'phcpy'}
'sympy' is the pure-Python Gröbner-basis enumerator (default via
'auto'). 'phcpy' uses optional polynomial homotopy continuation
(PHCpack) for larger / stiffer systems — pip install mantis-delta[homotopy].
scale : float, optional
Characteristic concentration used to non-dimensionalise the variables.
Inferred from the conservation totals / initial conditions when omitted;
override only if the solver struggles on a badly-scaled network.
Returns
list[SteadyState]
One entry per distinct positive steady state, sorted by residual, each
with .eigenvalues, .is_stable, .is_oscillatory.
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 | |
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
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 | |
certify_global_stability(initial_conditions, n_samples=200, seed=0)
Certify global asymptotic stability via the Horn–Jackson Lyapunov function.
For complex-balanced networks the pseudo-Helmholtz function
V(c) = Σ_i [c_i(ln(c_i/c_i*) − 1) + c_i*] is a strict Lyapunov function,
so the positive equilibrium c* is globally asymptotically stable within
its stoichiometric compatibility class — a strictly stronger statement than
the local eigenvalue test.
Parameters
initial_conditions : dict[str, float]
Fixes the compatibility class (conservation totals) and the equilibrium.
n_samples : int
Number of random points in the class at which dV/dt ≤ 0 is verified.
seed : int
RNG seed for the sampling.
Returns
StabilityCertificate
With .globally_stable, .equilibrium, .lyapunov_function (V),
and .lyapunov_derivative (dV/dt). str() gives a readable summary.
Source code in mantis/network.py
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 | |
complex_balanced_equilibrium(initial_conditions)
Return the Birch point — the unique positive complex-balanced equilibrium
in the stoichiometric compatibility class fixed by initial_conditions.
Defined only for complex-balanced networks (every weakly reversible
deficiency-zero network qualifies, for all rates). This equilibrium sets the
means of the exact stochastic stationary distribution (see
:meth:stationary_distribution). Raises ValueError otherwise.
Source code in mantis/network.py
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | |
continuation(parameter, range, initial_conditions, ds=0.05, max_steps=2000, initial_state=None)
Trace a steady-state branch by pseudo-arclength continuation.
Unlike :meth:bifurcation (an independent log-scan that loses the branch
at folds and never reports them), this parameterises the branch by
arclength along the solution curve, so saddle-node folds are traversed
smoothly and detected. The classic payoff: on the Schlögl model it traces
the full S-curve and pins both folds that bound the bistable region.
Parameters
parameter : str
Rate key to continue, e.g. "A + 2X -> 3X".
range : tuple[float, float]
(λ_min, λ_max) box the branch is traced within; to capture an
S-curve the box must bracket both folds.
initial_conditions : dict[str, float]
Fixes the conservation totals (the compatibility class) and seeds the
branch (a steady state is solved at λ_min unless initial_state
is given).
ds : float
Arclength step (adapted automatically on Newton failure / success).
max_steps : int
Cap on continuation steps (guards against closed isolas).
initial_state : dict[str, float], optional
Explicit starting steady state — use to select which branch to follow.
Returns
ContinuationResult
With .parameter_values (arclength order — non-monotonic across
folds), .branch, .stable, .bifurcations (.folds() /
.hopfs()), and .species_branch(species). str() summarises.
Source code in mantis/network.py
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 | |
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 | |
detect_acr(initial_conditions=None)
Detect Absolute Concentration Robustness (Shinar–Feinberg, Science 2010).
A deficiency-one network with two non-terminal complexes differing in a single species S has ACR in S: its steady-state concentration is independent of the initial totals — the robustness property at the heart of biosensor design.
Parameters
initial_conditions : dict[str, float], optional When supplied (with rate constants set), the robust steady-state value of each ACR species is computed at a positive steady state.
Returns
ACRResult
With .has_acr, .species, .acr_values, and a readable summary
via str().
Source code in mantis/network.py
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 | |
from_sbml(source)
classmethod
Construct a network from an SBML model.
Requires the optional python-libsbml package
(pip install mantis-delta[sbml]).
Parameters
source : str
Either a path to an .xml SBML file or a raw SBML/XML string.
Mass-action kinetic laws are parsed to recover rate constants where
possible; SBML boundary/constant species become chemostatted species.
Returns
CRNetwork
Source code in mantis/network.py
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | |
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 | |
fsp(initial_conditions, volume_L, t=None, *, initial_as='concentration', max_states=100000)
Solve the chemical master equation by Finite State Projection (Munsky–Khammash 2006).
Truncates the count-state space to the reachable set, builds the CME generator, and solves it directly — accurate where the SSA is noisy (low molecule numbers), with a rigorous truncation-error bound.
Parameters
initial_conditions : dict[str, float]
Starting state; interpreted per initial_as.
volume_L : float
Reaction volume in litres.
t : float, optional
If given, returns the transient distribution p(t); if None, returns
the stationary distribution (valid for closed, fully enumerated networks).
initial_as : 'concentration' or 'count'
max_states : int
Cap on the number of enumerated states.
Returns
FSPResult
With .probabilities, .states, .marginal(species),
.expected_counts(), and .truncation_error.
Source code in mantis/network.py
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |
is_complex_balanced(initial_conditions=None)
Whether the network is complex-balanced.
Every weakly reversible deficiency-zero network is complex-balanced for
all rate constants (Horn–Jackson). For weakly reversible higher-deficiency
networks the property is rate-dependent and is verified numerically at the
positive equilibrium — pass initial_conditions to enable that check.
Source code in mantis/network.py
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | |
is_injective()
Test mass-action injectivity (Craciun–Feinberg, SIAM J. Appl. Math. 2005/06).
An injective network has at most one positive steady state in each stoichiometric compatibility class — ruling out multistationarity. Unlike the Deficiency One Theorem this works for higher-deficiency networks too. The test is the sign-definiteness of the steady-state Jacobian determinant over all positive concentrations and rate constants (a sufficient condition).
Returns
InjectivityResult
With .injective (True ⇒ certified injective; False ⇒ inconclusive),
.determinant, and a readable summary via str().
Source code in mantis/network.py
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 | |
is_multistationary(initial_conditions, backend='auto')
Exactly decide multistationarity in one compatibility class by enumeration.
Whereas :meth:multistationarity_region gives the rate-free structural
verdict (and the symbolic region), this is the concrete numeric answer for
the supplied rate constants and totals: it enumerates all positive steady
states (:meth:all_steady_states) in the class fixed by initial_conditions
and returns True iff there are at least two. Definitive for any network —
no parametrisation or sign condition required.
Parameters
initial_conditions : dict[str, float]
Fixes the stoichiometric compatibility class (the conservation totals).
backend : {'auto', 'sympy', 'phcpy'}
Steady-state enumeration backend (see :meth:all_steady_states).
Returns
bool
True ⇔ ≥ 2 positive steady states in this class.
Source code in mantis/network.py
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 | |
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 | |
multistationarity_region()
Compute the multistationarity parameter region (Conradi–Feliu–Mincheva–Wiuf, PLoS Comput. Biol. 2017).
Where :meth:is_injective answers whether multistationarity is possible,
this maps where in parameter space it occurs. It forms the critical
function φ = (−1)^s·det J (s = rank(N)) and reads it as a polynomial
in the steady-state concentrations: if every coefficient is positive for all
positive rates the network is monostationary for all parameters; otherwise
each coefficient that can go negative is a face of the multistationarity
region. When rate constants are set, also reports whether those rates lie
inside the region.
Returns
MultistationarityResult
With .monostationary, .multistationary_possible,
.critical_function, .region_conditions,
.multistationary_at_rates, and a readable summary via str().
Source code in mantis/network.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 | |
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
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 452 453 454 455 456 457 458 459 460 461 | |
stationary_distribution(initial_conditions, volume_L, *, initial_as='concentration', max_states=200000)
Exact stochastic stationary distribution (Anderson–Craciun–Kurtz 2010).
For a complex-balanced network the chemical master equation has a closed-form
product-of-Poissons stationary distribution with means λ_i = N_A·V·c_i*
(c* the complex-balanced equilibrium) — written down from structure
alone, with no simulation. With conservation laws it is that product
conditioned on the conserved totals (e.g. a Binomial for a single moiety).
Parameters
initial_conditions : dict[str, float]
Fixes the compatibility class; interpreted per initial_as.
volume_L : float
Reaction volume in litres (sets the absolute molecule counts).
initial_as : 'concentration' or 'count'
max_states : int
Cap on enumerated states for the conditioned (closed-network) case.
Returns
StationaryDistribution
With .poisson_means(), .probability(state), .expected_counts(),
.marginal(species) and .sample(...).
Raises
ValueError If the network is not complex-balanced (the closed form does not apply).
Source code in mantis/network.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
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
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 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
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
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 | |
to_sbml(path=None)
Export this network to SBML (Level 3 Version 2).
Requires the optional python-libsbml package
(pip install mantis-delta[sbml]).
Parameters
path : str, optional If given, the SBML document is written to this file path. The XML string is returned in all cases.
Returns
str The SBML document as an XML string.
Source code in mantis/network.py
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 | |
mantis.analysis
Numerical ODE simulation, steady-state finding, stability analysis, and bifurcation scanning.
SimulationResult
dataclass
Source code in mantis/analysis.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
at(t)
Return interpolated concentrations at time t.
Source code in mantis/analysis.py
39 40 41 42 43 | |
final()
Return concentrations at the last time point.
Source code in mantis/analysis.py
45 46 47 | |
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
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 | |
at(t)
Step-function lookup of concentrations at time t.
Source code in mantis/analysis.py
75 76 77 78 79 | |
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
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 | |
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
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 | |
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
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 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 698 699 700 701 702 703 | |
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
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 | |
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
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 | |
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
445 446 447 448 449 450 451 452 453 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 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
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
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 | |
Exhaustive steady states
mantis.steady_states
Exhaustive steady-state enumeration for mass-action networks.
The hybrid solver in :mod:mantis.analysis (ODE integration + multi-start
least_squares) can silently miss steady states — in particular unstable
fixed points that forward integration flows away from. At mass-action
equilibrium the positive steady states are the positive real roots of a
polynomial system, so they can instead be found exhaustively with completeness
guarantees:
- Default pure-Python backend (
backend="sympy"). The reaction-rate polynomials are reduced against the conservation laws, a lexicographic Gröbner basis triangularises the system, every complex root is recovered by back-substitution (numpy.roots) and refined by a Newton polish, and the real non-negative roots are returned. For a zero-dimensional ideal this finds all solutions (their count is bounded by the Bézout number), so it certifies the full steady-state set rather than sampling it. - Optional homotopy backend (
backend="phcpy"). Delegates to PHCpack via :mod:phcpy(Verschelde) — numerical polynomial homotopy continuation that scales to larger / stiffer systems. Requirespip install mantis-delta[homotopy].
The classic demonstration is the Schlögl model: this enumerator returns all three positive steady states (including the unstable middle branch that integration never reaches), whereas the multi-start solver typically returns only the two stable ones.
all_steady_states(reactions, species, rate_values, initial_conditions, chemostatted_values=None, backend='auto', scale=None, residual_tol=1e-08, imag_tol=1e-06)
Exhaustively enumerate the positive steady states of a mass-action network.
Returns a list of :class:~mantis.analysis.SteadyState objects (with
eigenvalues and stability classification), sorted by residual. See the module
docstring for the algorithm and the meaning of backend.
Source code in mantis/steady_states.py
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 | |
Global stability (Horn–Jackson Lyapunov)
mantis.stability
Global asymptotic stability certification via the Horn–Jackson Lyapunov function.
The structural theorems already in mantis certify local stability through the sign of the Jacobian eigenvalues. For complex-balanced networks a much stronger, global statement is available (Horn & Jackson 1972; Feinberg's Deficiency Zero Theorem): the pseudo-Helmholtz function
V(c) = Σ_i [ c_i (ln(c_i / c_i*) − 1) + c_i* ]
is a strict Lyapunov function on every positive stoichiometric compatibility
class, where c* is the (unique) positive complex-balanced equilibrium of that
class. Indeed ∂V/∂c_i = ln(c_i/c_i*), so
dV/dt = Σ_i ln(c_i/c_i*) · ċ_i ≤ 0,
with equality only at c = c*. Hence c* is globally asymptotically
stable within the relative interior of its compatibility class — strictly
stronger than the eigenvalue check.
Every weakly reversible deficiency-zero network is complex-balanced for all rate constants (Horn–Jackson), so the certificate is purely structural there; for higher-deficiency weakly-reversible networks complex balance is rate-dependent and is verified numerically at the equilibrium.
StabilityCertificate
dataclass
Outcome of a global-stability analysis.
Attributes
is_complex_balanced : bool
Whether the network is complex-balanced (structurally for δ=0 weakly
reversible, else numerically at the equilibrium).
globally_stable : bool
True when a Horn–Jackson Lyapunov certificate establishes global
asymptotic stability within the compatibility class.
equilibrium : dict[str, float] | None
The positive complex-balanced equilibrium c* (per the supplied class).
lyapunov_function : sympy.Expr | None
The symbolic pseudo-Helmholtz function V(c).
lyapunov_derivative : sympy.Expr | None
The symbolic dV/dt = Σ ln(c_i/c_i*)·f_i(c).
n_samples_checked : int
Number of random points in the compatibility class at which dV/dt ≤ 0
was numerically verified.
max_dVdt : float
Largest dV/dt observed over the samples (should be ≤ 0).
rationale : str
Human-readable explanation of the verdict.
Source code in mantis/stability.py
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 | |
certify_global_stability(reactions, species, rate_values, deficiency, is_weakly_reversible, odes, initial_conditions, chemostatted_values=None, n_samples=200, seed=0, tol=1e-09)
Attempt a Horn–Jackson global-stability certificate for one compatibility class.
odes is the species → SymPy RHS mapping (numeric rates substituted).
Returns a :class:StabilityCertificate.
Source code in mantis/stability.py
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 | |
complex_balanced_equilibrium(reactions, species, rate_values, deficiency, is_weakly_reversible, initial_conditions, chemostatted_values=None)
Return the Birch point: the unique positive complex-balanced equilibrium.
For a complex-balanced network the Birch theorem guarantees exactly one positive
equilibrium in each stoichiometric compatibility class (fixed here by the initial
conditions). Raises ValueError if the network is not complex-balanced or no
positive equilibrium is found.
Source code in mantis/stability.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
is_complex_balanced(reactions, species, rate_values, deficiency, is_weakly_reversible, initial_conditions=None, chemostatted_values=None, tol=1e-06)
Decide whether the network is complex-balanced.
Complex balance ⇒ weak reversibility (necessary). Every weakly reversible deficiency-zero network is complex-balanced for all rates (Horn–Jackson). For weakly reversible higher-deficiency networks the property is rate-dependent and is checked numerically at the positive equilibrium (requires ICs).
Source code in mantis/stability.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
Absolute Concentration Robustness
mantis.acr
Absolute Concentration Robustness (ACR) detection — Shinar & Feinberg, Science 2010.
A mass-action system has absolute concentration robustness in a species S when the steady-state concentration of S is identical in every positive steady state, regardless of the initial totals (the stoichiometric compatibility class). This is exactly the robustness property a biosensor or homeostatic module is designed to have, which makes it directly relevant to diagnostic-circuit design.
Shinar & Feinberg give a purely structural sufficient condition:
If a mass-action system has deficiency one, admits a positive steady state, and
possesses two **non-terminal** complexes that differ only in species *S*, then the
system has ACR in *S*.
"Non-terminal" complexes are those that do not lie in a terminal strong linkage class (a strongly connected component of the reaction graph with no reactions leading out of it). Two complexes "differ only in S" when their species vectors differ in exactly one coordinate.
This module implements that test on top of the complex graph mantis already builds.
ACRResult
dataclass
Outcome of an ACR analysis.
Attributes
has_acr : bool
Whether the Shinar–Feinberg sufficient condition detected ACR.
species : list[str]
Species for which ACR is certified (empty when has_acr is False).
deficiency : int
Network deficiency (the test applies only when this is 1).
applies : bool
Whether the deficiency-one precondition is met.
acr_values : dict[str, float]
Steady-state value of each ACR species, when a positive steady state was
computed (the value is independent of the initial totals).
nonterminal_complex_pairs : list[tuple[str, str, str]]
Witnessing (complex_a, complex_b, species) triples.
summary_lines : list[str]
Source code in mantis/acr.py
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 | |
detect_acr(reactions, species, graph, deficiency, rate_values=None, initial_conditions=None, chemostatted_values=None)
Detect ACR via the Shinar–Feinberg deficiency-one sufficient condition.
graph is the (reduced) complex digraph; deficiency the network deficiency.
When rate_values and initial_conditions are supplied and a positive steady
state exists, the robust steady-state value of each ACR species is also reported.
Source code in mantis/acr.py
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 | |
terminal_strong_linkage_classes(graph)
Return the terminal strong linkage classes of a complex graph.
A strong linkage class (SCC) is terminal when no edge leaves it for another SCC — i.e. it is a sink in the condensation.
Source code in mantis/acr.py
83 84 85 86 87 88 89 90 91 92 93 94 95 | |
Injectivity
mantis.injectivity
Injectivity test — Craciun & Feinberg (SIAM J. Appl. Math. 2005, 2006).
A mass-action network is injective when its species-formation-rate map is injective on each stoichiometric compatibility class; an injective network has at most one positive steady state per class, so it cannot be multistationary. Crucially this rules out multistationarity for higher-deficiency networks too, where the Deficiency One Theorem is silent.
Craciun & Feinberg reduce injectivity to a sign condition on a determinant. Form the square "steady-state map"
F(c) = ( rank(N) independent components of N·v(c) , the conservation totals ),
whose Jacobian J(c) is an n×n matrix whose entries are polynomials in the
(positive) concentrations c and the (positive) rate constants k. If
det J(c) is sign-definite — every monomial coefficient shares one sign, so
the determinant never vanishes for any positive c and k — then F is
injective and the network admits at most one positive steady state per class.
The test is sufficient: a sign-definite determinant certifies injectivity, while a sign-indefinite one is inconclusive (the network may still be injective for specific rates, or may genuinely be multistationary, as for the Schlögl model).
InjectivityResult
dataclass
Outcome of the Craciun–Feinberg injectivity test.
Attributes
injective : bool True ⇒ the network is certified injective (at most one positive steady state per compatibility class). False ⇒ inconclusive (not sign-definite). is_sign_definite : bool Whether the steady-state Jacobian determinant is sign-definite. determinant : sympy.Expr The symbolic determinant (in concentrations and rate constants). reason : str summary_lines : list[str]
Source code in mantis/injectivity.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
test_injectivity(reactions, species, chemostatted_values=None)
Run the determinant sign-definiteness injectivity test (symbolic, rate-free).
Source code in mantis/injectivity.py
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 | |
Pseudo-arclength continuation (fold / Hopf)
mantis.continuation
Pseudo-arclength continuation of steady-state branches (fold / Hopf detection).
The :meth:~mantis.network.CRNetwork.bifurcation log-scan recomputes steady
states independently at each parameter value. Near a saddle-node (fold) the
branch turns back on itself, so two states share one parameter value and one
disappears as the parameter is swept past the fold — a naive scan loses the
branch, mis-pairs points across the fold, and never reports the fold itself.
Pseudo-arclength continuation (Keller 1977; Allgower–Georg 2003) fixes this
by parameterising the branch not by the bifurcation parameter λ but by
arclength s along the solution curve (c(s), λ(s)). Folds — where
dλ/ds = 0 — are then ordinary points of the curve and are traversed
smoothly. The method is the standard predictor–corrector:
- Predictor — step
dsalong the unit tangent of the branch. -
Corrector — Newton on the augmented square system
G(c, λ) = 0 (n steady-state equations) ⟨t_c, c − c_prev⟩ + t_λ (λ − λ_prev) − ds = 0 (arclength constraint)
The arclength row keeps the Jacobian non-singular through the fold, where
the steady-state Jacobian G_c alone is singular.
G is the conservation-constrained steady-state map: rank(N) independent
rows of the mass-action ODE field stacked on the n − rank(N) conservation
laws (totals fixed by the initial conditions), so the branch stays inside one
stoichiometric compatibility class.
Bifurcation detection along the branch:
- Fold (saddle-node) —
det G_cchanges sign (the steady-state Jacobian is singular exactly at a fold), the canonical fold test function. - Hopf — the number of eigenvalues with positive real part changes without
a fold (so a complex-conjugate pair, not a real eigenvalue, has crossed the
imaginary axis). Reported as a candidate; a Hopf marks the birth of a limit
cycle. Eigenvalues are those of the Jacobian restricted to the stoichiometric
subspace (the
n − rank(N)exact zeros from conservation are dropped).
The classic demonstration is the Schlögl model: continuation traces the full S-shaped branch and pins both fold points bounding the bistable region, neither of which the log-scan reports.
BifurcationPoint
dataclass
A detected bifurcation on a continuation branch.
Attributes
kind : str
"fold" (saddle-node) or "hopf" (candidate Hopf).
parameter : float
Bifurcation-parameter value at the point (linearly localised between the
two bracketing continuation steps).
state : dict[str, float]
Species concentrations at the bifurcation.
eigenvalue : complex
The critical eigenvalue nearest the imaginary axis at the crossing.
Source code in mantis/continuation.py
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 | |
ContinuationResult
dataclass
A steady-state branch traced by pseudo-arclength continuation.
The branch is ordered by arclength, so parameter_values is generally
non-monotonic (it reverses at each fold) — that is the whole point.
Attributes
parameter_name : str Rate key that was continued. parameter_values : np.ndarray Bifurcation-parameter value at each branch point (arclength order). branch : list[dict[str, float]] Species concentrations at each branch point. stable : np.ndarray Boolean stability of each branch point (all reduced eigenvalues Re < 0). eigenvalues : list[np.ndarray] Reduced-Jacobian eigenvalues at each branch point. bifurcations : list[BifurcationPoint]
Source code in mantis/continuation.py
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 | |
species_branch(species)
The concentration of one species along the branch (arclength order).
Source code in mantis/continuation.py
113 114 115 | |
pseudo_arclength_continuation(reactions, species, base_rates, parameter, param_range, initial_conditions, chemostatted_values=None, ds=0.05, max_steps=2000, newton_tol=1e-10, initial_state=None)
Trace a steady-state branch by pseudo-arclength continuation.
Parameters
parameter : str
Rate key to continue (e.g. "A + 2X -> 3X").
param_range : (float, float)
(λ_min, λ_max) box the branch is traced within; continuation stops
when it leaves the box. To capture an S-curve the box must bracket both
folds.
initial_conditions : dict[str, float]
Fixes the conservation totals (the compatibility class) and, unless
initial_state is given, seeds the branch (a steady state is solved at
λ_min to start from).
ds : float
Arclength step (in the non-dimensional (c/scale, λ/λ_min) metric);
adapted down on Newton failure and back up on easy steps.
max_steps : int
Cap on continuation steps (guards against closed isolas / cycling).
initial_state : dict[str, float], optional
Explicit starting steady state on the desired branch; overrides the
automatic seed (use to select which branch to follow).
Returns
ContinuationResult
Source code in mantis/continuation.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 | |
Multistationarity parameter regions (Conradi–Feliu–Mincheva–Wiuf)
mantis.multistationarity
Parameter regions for multistationarity — Conradi, Feliu, Mincheva & Wiuf (PLoS Comput. Biol. 2017).
Injectivity (:mod:mantis.injectivity) answers a yes/no question — can this
network ever have more than one positive steady state in a compatibility class?
Conradi et al. (2017) go further and ask where in parameter space it does:
they give the determinant criterion that carves the rate-/total-concentration
space into a monostationary region and a multistationary region.
The object of study is the critical function
φ(c, k) = (−1)^s · det J(c, k),
where J is the Jacobian of the canonical steady-state map (s = rank(N)
independent mass-action ODE rows stacked on the n − s conservation laws) and
s is the dimension of the stoichiometric subspace. Reading φ as a
polynomial in the steady-state concentrations c with coefficients that are
polynomials in the rate constants k:
- If every coefficient is positive for all positive
kthenφ > 0on the whole positive orthant, the steady-state map is injective, and the network is monostationary for all rates and totals (Craciun–Feinberg). - If some coefficient can be negative,
φattains negative values and the network is multistationary for parameters in that region. Each such coefficient inequalitya_α(k) < 0is a face of the multistationarity region — the explicit "where" that the 2017 paper contributes.
For a network whose positive steady states admit a monomial parametrisation (weakly reversible / toric steady states, the paper's setting) a negative coefficient is both necessary and sufficient for multistationarity; in general it is the necessary condition (a sign-change witness). This module returns the critical function, the per-coefficient sign certificate, and — when numeric rates are supplied — whether those specific rates land in the multistationary region.
MultistationarityResult
dataclass
Outcome of the Conradi–Feliu–Mincheva–Wiuf critical-function analysis.
Attributes
monostationary : bool
True ⇒ certified at most one positive steady state per compatibility
class for all positive rate constants (the critical function is
sign-definite positive).
multistationary_possible : bool
True ⇒ some coefficient of the critical function can be negative, so
multistationarity occurs for parameters in region_conditions.
critical_function : sympy.Expr
φ = (−1)^s · det J in concentrations and rate constants.
coefficient_terms : list[tuple]
(monomial, coefficient_expr, sign) for each concentration-monomial of
φ; sign ∈ {"+", "−", "±"} is the coefficient's sign
over positive rate constants.
region_conditions : list[sympy.Expr]
Coefficient expressions whose negativity delimits the multistationarity
region (expr < 0 ⇒ multistationarity). Empty when monostationary.
multistationary_at_rates : bool | None
If numeric rates were supplied: whether they actually yield ≥ 2 positive
steady states. When the steady-state set reduces to a univariate
polynomial this is exact (a positive-root count); otherwise it falls
back to the necessary sign condition (a critical coefficient is negative).
None if no rates were supplied.
region_boundary : sympy.Expr | None
The exact multistationarity-region boundary when the steady states
reduce to a univariate polynomial p(x): the discriminant
disc_x(p). Crossing region_boundary = 0 changes the number of
(positive) steady states, so it is the genuine fold locus in parameter
space — unlike region_conditions, which is only the necessary sign
condition. None when the reduction is unavailable.
steady_state_polynomial : sympy.Expr | None
The reduced univariate steady-state polynomial p(x) (in one species,
with rate / total parameters), when available.
summary_lines : list[str]
Source code in mantis/multistationarity.py
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 | |
multistationarity_region(reactions, species, rate_values=None, chemostatted_values=None)
Compute the multistationarity parameter region via the CFMW critical function.
Source code in mantis/multistationarity.py
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 | |
Stochastic stationary distribution (Anderson–Craciun–Kurtz)
mantis.stochastic_stationary
Exact stochastic stationary distributions — Anderson, Craciun & Kurtz (Bull. Math. Biol. 2010).
For a complex-balanced mass-action network the stochastic (chemical master equation) model has an exact stationary distribution in closed form — a product of independent Poissons whose means are the deterministic complex-balanced equilibrium scaled to molecule counts:
π(x) = M · Π_i λ_i^{x_i} / x_i!, λ_i = (N_A · V) · c_i*,
supported on the reachable state space (the stoichiometric compatibility class).
With no conservation laws the state space is all of ℤ≥0ⁿ and π factorises into
independent Poisson(λ_i); with conservation laws π is that product conditioned
on the conserved totals (for a single moiety this is exactly a Binomial /
multinomial). This lets you write the stationary distribution down from network
structure alone — no simulation — for any weakly reversible deficiency-zero
network, the regime where SSA is noisiest.
StationaryDistribution
dataclass
Exact product-form stationary distribution of a complex-balanced network.
Attributes
species : list[str]
means : np.ndarray
The Poisson means λ_i (in molecule counts) = N_A · V · c_i*.
volume_L : float
is_conditioned : bool
Whether conservation laws restrict the support to a compatibility class.
is_exact : bool
True when the distribution is represented exactly (independent Poissons, or a
fully enumerated finite class); False when the class could not be enumerated
and the independent-Poisson factorisation is used as an approximation.
Source code in mantis/stochastic_stationary.py
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 | |
expected_counts()
Stationary mean molecule counts (conditional means when conditioned).
Source code in mantis/stochastic_stationary.py
135 136 137 138 139 140 141 142 | |
marginal(species)
Return (values, probabilities) for the marginal of one species.
Source code in mantis/stochastic_stationary.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
poisson_means()
Poisson means λ_i keyed by species (molecule counts).
Source code in mantis/stochastic_stationary.py
109 110 111 | |
probability(counts)
Normalised stationary probability of an integer state counts.
Source code in mantis/stochastic_stationary.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
sample(size=1, seed=None)
Draw samples from the stationary distribution.
Source code in mantis/stochastic_stationary.py
161 162 163 164 165 166 167 168 169 170 171 172 | |
stationary_distribution(reactions, species, rate_values, deficiency, is_weakly_reversible, initial_conditions, volume_L, initial_as='concentration', chemostatted_values=None, max_states=200000)
Build the exact ACK product-form stationary distribution.
Raises ValueError if the network is not complex-balanced (the closed-form
result does not apply).
Source code in mantis/stochastic_stationary.py
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 | |
Finite State Projection
mantis.fsp
Finite State Projection — Munsky & Khammash (J. Chem. Phys. 2006).
The chemical master equation (CME) is an (often infinite) linear ODE for the probability of every molecular-count state. FSP truncates the state space to a finite, reachable subset, assembles the corresponding generator matrix, and solves the truncated CME directly — giving accurate distributions exactly where the SSA is noisiest (the low-copy-number biosensor regime), together with a rigorous bound on the truncation error (the probability that has leaked out of the projection).
This module enumerates the reachable states (BFS under the reaction stoichiometry,
respecting conservation laws, capped at max_states), builds the sparse generator
Q, and provides:
- transient distributions
p(t) = expm(Q·t)·p₀with the leaked-mass error bound; - stationary distributions (null space of
Q) for closed, fully enumerated networks — which, for complex-balanced networks, reproduces the exact Anderson–Craciun–Kurtz product form (a strong cross-check).
FSPResult
dataclass
A finite-state-projection distribution over molecular-count states.
Attributes
species : list[str]
states : np.ndarray
(M, n) integer array of enumerated states.
probabilities : np.ndarray
Length-M probability vector aligned with states.
truncation_error : float
Probability that left the projection (0 for a closed, fully enumerated
network; an upper bound on the distribution error otherwise).
time : float | None
Evaluation time for a transient solve, or None for the stationary one.
truncated : bool
True if state enumeration hit max_states before closing.
Source code in mantis/fsp.py
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 | |
expected_counts()
Mean molecule counts under the (renormalised) projected distribution.
Source code in mantis/fsp.py
75 76 77 78 79 | |
marginal(species)
Return (values, probabilities) for one species' marginal.
Source code in mantis/fsp.py
65 66 67 68 69 70 71 72 73 | |
probability(counts)
Probability of an exact integer state (0 if outside the projection).
Source code in mantis/fsp.py
56 57 58 59 60 61 62 63 | |
fsp_solve(reactions, species, rate_values, initial_conditions, volume_L, t=None, initial_as='concentration', chemostatted_values=None, max_states=100000)
Solve the CME by finite state projection.
With t given, returns the transient distribution p(t); with t=None,
returns the stationary distribution (null space of Q) — valid when the
enumerated state space is closed.
Source code in mantis/fsp.py
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 | |
SBML interoperability
mantis.sbml
SBML (Systems Biology Markup Language) import/export for CRNetwork.
This is an optional interoperability layer. It requires python-libsbml;
if that package is not installed, importing the helpers raises a clear
:class:ImportError with an install hint, but the rest of mantis keeps
working without it.
The mapping between mantis and SBML is mass-action-centric:
- Each directed :class:
~mantis.parsing.Reactionbecomes one irreversible SBML reaction. A reversibleA <-> Bround-trips as two irreversible reactions (matching mantis' internal representation). - Each reaction carries a mass-action kinetic law
k_i * Π reactant^coeffwith the rate constant stored as a global parameterk_i. - Chemostatted species are exported as SBML boundary species
(
boundaryCondition=True) holding their fixed concentration; on import, boundary / constant species are recovered as chemostatted.
network_from_sbml(source)
Construct a :class:CRNetwork from an SBML file path or XML string.
source is treated as a file path if it points to an existing file,
otherwise as a raw SBML/XML document string.
Source code in mantis/sbml.py
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 | |
network_to_sbml(net, *, level=3, version=2)
Serialize a :class:CRNetwork to an SBML document string (Level 3 v2).
Source code in mantis/sbml.py
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 | |
write_sbml(net, path)
Write a :class:CRNetwork to an SBML file at path.
Source code in mantis/sbml.py
136 137 138 139 140 | |