def _parse_rules(self, model, comp, node): """ Parses the rules (equations) in this model """ parent = node formulas = {} # Create variables with assignment rules (all except derivatives) node = dom_child(parent, 'assignmentRule') while node: var = self._convert_name(str(node.getAttribute('variable')).strip()) if var in comp: self.log('Parsing assignment rule for <' + str(var) + '>.') var = comp[var] var.set_rhs(parse_mathml_rhs( dom_child(node, 'math'), comp, self)) else: raise SBMLError('Assignment found for unknown parameter: "' + var + '".') node = dom_next(node, 'assignmentRule') # Create variables with rate rules (states) node = dom_child(parent, 'rateRule') while node: var = self._convert_name(str(node.getAttribute('variable')).strip()) if var in comp: self.log('Parsing rate rule for <' + var + '>.') var = comp[var] ini = var.rhs() ini = ini.eval() if ini else 0 var.promote(ini) var.set_rhs(parse_mathml_rhs( dom_child(node, 'math'), comp, self)) else: raise SBMLError('Derivative found for unknown parameter: <' + var + '>.') node = dom_next(node, 'rateRule')
def _parse_initial_assignments(self, model, comp, refs, node): """ Parses any initial values specified outside of the rules section. """ node = dom_child(node, 'initialAssignment') while node: var = str(node.getAttribute('symbol')).strip() var = self._convert_name(var) if var in comp: self.logger().log('Parsing initial assignment for "' + var + '".') var = comp[var] expr = parse_mathml_rhs(dom_child(node, 'math'), refs, self.logger()) if var.is_state(): # Initial value var.set_state_value(expr) else: # Change of value var.set_rhs(expr) else: # pragma: no cover raise SBMLError( # pragma: no cover 'Initial assignment found for unknown parameter <' + var + '>.') node = dom_next(node, 'initialAssignment')
def mathml(node, rfs): return parse_mathml_rhs(node, var_table=rfs, logger=self, number_post_processor=npp, derivative_post_processor=dpp)