def test_model_add__multiple_components__in_order(self): import gillespy2 s1 = gillespy2.Species(name="s1", initial_value=29) k1 = gillespy2.Parameter(name="k1", expression=29) r1 = gillespy2.Reaction(name="r1", reactants={"s1": 1}, rate="k1") rr1 = gillespy2.RateRule(name="rr1", variable="k1", formula="29") ar1 = gillespy2.AssignmentRule(name="ar1", variable="s1", formula="29") ea = gillespy2.EventAssignment(name="ea", variable="k1", expression="29") et = gillespy2.EventTrigger(expression="t > 29") e1 = gillespy2.Event(name="e1", trigger=et, assignments=[ea]) divide = gillespy2.FunctionDefinition(name="divide", function="x / y", args=["x", "y"]) tspan = gillespy2.TimeSpan(range(100)) model = gillespy2.Model(name="Test Model") model.add([s1, k1, r1, rr1, ar1, e1, divide, tspan]) self.assertIn("ar1", model.listOfAssignmentRules) self.assertIn("e1", model.listOfEvents) self.assertIn("divide", model.listOfFunctionDefinitions) self.assertIn("k1", model.listOfParameters) self.assertIn("rr1", model.listOfRateRules) self.assertIn("r1", model.listOfReactions) self.assertIn("s1", model.listOfSpecies) self.assertEqual(tspan, model.tspan)
def setUpClass(cls): cls.solvers = [ SSACSolver, ODESolver, NumPySSASolver, TauLeapingSolver, TauHybridSolver, ODECSolver, TauLeapingCSolver, TauHybridCSolver, ] cls.sbml_features = { "AssignmentRule": lambda model, variable: model.add_assignment_rule(gillespy2.AssignmentRule(variable=variable, formula="1/(t+1)")), "RateRule": lambda model, variable: model.add_rate_rule(gillespy2.RateRule(variable=variable, formula="2*t")), "Event": lambda model, variable: model.add_event(gillespy2.Event( trigger=gillespy2.EventTrigger(expression="t>1"), assignments=[gillespy2.EventAssignment(variable=variable, expression="100")] )), "FunctionDefinition": lambda model, variable: model.add_function_definition( gillespy2.FunctionDefinition(name="fn", function="variable", args=["variable"])), } # List of supported SBML features for each solver. # When a feature is implemented for a particular solver, add the feature to its list. cls.solver_supported_sbml_features = { NumPySSASolver: [], TauLeapingSolver: [], ODESolver: [], TauHybridSolver: [ "AssignmentRule", "RateRule", "Event", "FunctionDefinition", ], SSACSolver: [], ODECSolver: [], TauLeapingCSolver: [], TauHybridCSolver: [ "RateRule", "Event", ], } cls.model = create_decay() cls.results = {} cls.labeled_results = {} cls.labeled_results_more_trajectories = {}
def __get_function_definitions(sbml_model, gillespy_model): # TODO: # DOES NOT CURRENTLY SUPPORT ALL MATHML # ALSO DOES NOT SUPPORT NON-MATHML for i in range(sbml_model.getNumFunctionDefinitions()): function = sbml_model.getFunctionDefinition(i) function_name = function.getId() function_tree = function.getMath() num_nodes = function_tree.getNumChildren() function_args = [function_tree.getChild(i).getName() for i in range(num_nodes-1)] function_string = __get_math(function_tree.getChild(num_nodes-1)) gillespy_function = gillespy2.FunctionDefinition(name=function_name, function=function_string, args=function_args) gillespy_model.add_function_definition(gillespy_function) init_state[gillespy_function.name] = gillespy_function.function
def test_add_function_definition(self): model = Example() funcdef = gillespy2.FunctionDefinition(name='fun', function='Sp+1') model.add_function_definition(funcdef) results = model.run() self.assertEqual(results[0].solver_name,'TauHybridSolver')