Source code for gillespy2.core.assignmentrule
# GillesPy2 is a modeling toolkit for biochemical simulation.
# Copyright (C) 2019-2024 GillesPy2 developers.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import uuid
from gillespy2.core.sortableobject import SortableObject
from gillespy2.core.jsonify import Jsonify
[docs]class AssignmentRule(SortableObject, Jsonify):
"""
An AssignmentRule is used to express equations that set the values of
variables. This would correspond to a function in the form of x = f(V)
:param name: Name of the Rule
:type name: str
:param variable: Target Species/Parameter to be modified by rule
:type variable: str
:param formula: String representation of formula to be evaluated
:type formula: str
"""
def __init__(self, variable=None, formula=None, name=None):
if name in (None, ""):
self.name = f'ar{uuid.uuid4()}'.replace('-', '_')
else:
self.name = name
self.variable = variable
self.formula = formula
def __str__(self):
var_name = self.variable if isinstance(self.variable, str) else self.variable.name
return f"{self.name}: Var: {var_name}: {self.formula}"