Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
CellMLToNektar.pycml.cellml_model Class Reference
Inheritance diagram for CellMLToNektar.pycml.cellml_model:
Inheritance graph
[legend]
Collaboration diagram for CellMLToNektar.pycml.cellml_model:
Collaboration graph
[legend]

Public Member Functions

def __init__
 
def __del__
 
def clean_up
 
def get_config
 
def get_option
 
def get_component_by_name
 
def get_variable_by_name
 
def get_variable_by_oxmeta_name
 
def get_variables_by_ontology_term
 
def get_variable_by_cmeta_id
 
def get_all_variables
 
def validation_error
 
def get_validation_errors
 
def validation_warning
 
def get_validation_warnings
 
def validate
 
def search_for_assignments
 
def build_name_dictionaries
 
def build_component_hierarchy
 
def topological_sort
 
def get_assignments
 
def clear_assignments
 
def do_binding_time_analysis
 
def get_standard_units
 
def get_all_units
 
def get_units_by_name
 
def add_units
 
def has_units
 
def add_units_conversions
 
def find_state_vars
 
def find_free_vars
 
def calculate_extended_dependencies
 
def is_self_excitatory
 
def xml
 
- Public Member Functions inherited from CellMLToNektar.pycml.element_base
def __init__
 
def __delattr__
 
def __setattr__
 
def rootNode
 
def cmeta_id
 
def xml_remove_child_at
 
def xml_doc
 
def xml_properties
 

Static Public Attributes

string math_xpath_1 = u'cml:component/m:math'
 
string math_xpath_2 = u'cml:component/cml:reaction/cml:variable_ref/cml:role/m:math'
 
string apply_xpath_1 = u'/m:apply[m:eq]'
 
string apply_xpath_2 = u'/m:semantics/m:apply[m:eq]'
 

Private Member Functions

def _add_variable
 
def _del_variable
 
def _add_component
 
def _del_component
 
def _report_exception
 
def _validate_component_hierarchies
 
def _check_variable_mappings
 
def _validate_connection
 
def _check_variable_units_exist
 
def _check_connection_units
 
def _check_maths_name_references
 
def _check_assigned_vars
 
def _check_cellml_subset
 
def _classify_variables
 
def _order_variables
 
def _add_sorted_assignment
 
def _remove_assignment
 
def _check_dimensional_consistency
 
def _check_unit_cycles
 
def _build_units_dictionary
 
def _add_units_obj
 
def _get_units_obj
 
def _is_new_units_obj
 

Private Attributes

 _cml_validation_errors
 
 _cml_validation_warnings
 
 _cml_variables
 
 _cml_components
 
 _cml_units
 
 _cml_standard_units
 
 _cml_units_map
 
 _cml_assignments
 
 _cml_sorting_variables_stack
 
 _cml_conversions_needed
 

Additional Inherited Members

- Public Attributes inherited from CellMLToNektar.pycml.element_base
 xml_attributes
 

Detailed Description

Specialised class for the model element of a CellML document.
Adds methods for collecting and reporting validation errors, etc.

Definition at line 377 of file pycml.py.

Constructor & Destructor Documentation

def CellMLToNektar.pycml.cellml_model.__init__ (   self)

Definition at line 383 of file pycml.py.

384  def __init__(self):
385  element_base.__init__(self)
388  self._cml_variables = {}
389  self._cml_components = {}
390  self._cml_units = {}
392  self._cml_units_map = {}
393  # Topologically sorted assignments list
394  self._cml_assignments = []
def CellMLToNektar.pycml.cellml_model.__del__ (   self)

Definition at line 395 of file pycml.py.

References CellMLToNektar.pycml.cellml_model.clean_up().

396  def __del__(self):
397  self.clean_up()

Member Function Documentation

def CellMLToNektar.pycml.cellml_model._add_component (   self,
  comp,
  special = False 
)
private
Add a new component to the model.

Definition at line 499 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_components.

500  def _add_component(self, comp, special=False):
501  """Add a new component to the model."""
502  if special:
503  comp.xml_parent = self
504  else:
505  self.xml_append(comp)
506  self._cml_components[comp.name] = comp
def CellMLToNektar.pycml.cellml_model._add_sorted_assignment (   self,
  a 
)
private
During the topological sort, add a finished assignment to the
list.  This list can then be executed in order to simulate the
model.

The element added can either be a MathML expression
representing an assignment, or a CellML variable element,
indicating an assignment due to a variable mapping.

Definition at line 1095 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model.topological_sort().

1096  def _add_sorted_assignment(self, a):
1097  """
1098  During the topological sort, add a finished assignment to the
1099  list. This list can then be executed in order to simulate the
1100  model.
1101 
1102  The element added can either be a MathML expression
1103  representing an assignment, or a CellML variable element,
1104  indicating an assignment due to a variable mapping.
1105  """
self._cml_assignments.append(a)
def CellMLToNektar.pycml.cellml_model._add_units_obj (   self,
  units 
)
private
Add a units object into the global hashmap.

Definition at line 1331 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_units_map.

Referenced by CellMLToNektar.pycml.cellml_model._build_units_dictionary(), and CellMLToNektar.pycml.cellml_model.add_units().

1332  def _add_units_obj(self, units):
1333  """Add a units object into the global hashmap."""
1334  if not units.uniquify_tuple in self._cml_units_map:
1335  self._cml_units_map[units.uniquify_tuple] = units
1336  return
def CellMLToNektar.pycml.cellml_model._add_variable (   self,
  var,
  varname,
  compname 
)
private
Add a new variable to the model.

Definition at line 490 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_variables.

491  def _add_variable(self, var, varname, compname):
492  """Add a new variable to the model."""
493  assert (compname, varname) not in self._cml_variables
494  self._cml_variables[(compname, varname)] = var
def CellMLToNektar.pycml.cellml_model._build_units_dictionary (   self)
private
Create a dictionary mapping units names to objects, for all units definitions in this element.

Definition at line 1210 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._add_units_obj(), CellMLToNektar.pycml.cellml_model._cml_standard_units, CellMLToNektar.pycml.cellml_model._cml_units, and CellMLToNektar.pycml.cellml_model.validation_error().

Referenced by CellMLToNektar.pycml.cellml_model.add_units(), CellMLToNektar.pycml.cellml_component.add_units(), CellMLToNektar.pycml.cellml_model.get_all_units(), CellMLToNektar.pycml.cellml_component.get_all_units(), CellMLToNektar.pycml.cellml_model.get_standard_units(), CellMLToNektar.pycml.cellml_model.get_units_by_name(), and CellMLToNektar.pycml.cellml_component.get_units_by_name().

1211  def _build_units_dictionary(self):
1212  """Create a dictionary mapping units names to objects, for all units definitions in this element."""
1213  # Standard units
1214  std_units = self._cml_standard_units
1215  def make(name, bases):
1216  return cellml_units.create_new(self, name, bases, standard=True)
1217  # SI base units & dimensionless
1218  base_units = [u'ampere', u'candela', u'dimensionless', u'kelvin',
1219  u'kilogram', u'metre', u'mole', u'second']
1220  base_units.append(u'#FUDGE#') # Used for PE of naughty models
1221  for units in base_units:
1222  std_units[units] = make(units, [])
1223  # Special cellml:boolean units
1224  boolean = make(u'cellml:boolean', [])
1225  std_units[u'cellml:boolean'] = boolean
1226  # Convenience derived units
1227  gram = make('gram', [{'units': 'kilogram', 'multiplier': '0.001'}])
1228  litre = make('litre', [{'multiplier': '1000', 'prefix': 'centi',
1229  'units': 'metre', 'exponent': '3'}])
1230  # SI derived units
1231  radian = make('radian', [{'units': 'metre'},
1232  {'units': 'metre', 'exponent': '-1'}])
1233  steradian = make('steradian', [{'units': 'metre', 'exponent': '2'},
1234  {'units': 'metre', 'exponent': '-2'}])
1235  hertz = make('hertz', [{'units': 'second', 'exponent': '-1'}])
1236  newton = make('newton', [{'units': 'metre'},
1237  {'units': 'kilogram'},
1238  {'units': 'second', 'exponent': '-2'}])
1239  pascal = make('pascal', [{'units': 'newton'},
1240  {'units': 'metre', 'exponent': '-2'}])
1241  joule = make('joule', [{'units': 'newton'},
1242  {'units': 'metre'}])
1243  watt = make('watt', [{'units': 'joule'},
1244  {'units': 'second', 'exponent': '-1'}])
1245  coulomb = make('coulomb', [{'units': 'second'},
1246  {'units': 'ampere'}])
1247  volt = make('volt', [{'units': 'watt'},
1248  {'units': 'ampere', 'exponent': '-1'}])
1249  farad = make('farad', [{'units': 'coulomb'},
1250  {'units': 'volt', 'exponent': '-1'}])
1251  ohm = make('ohm', [{'units': 'volt'},
1252  {'units': 'ampere', 'exponent': '-1'}])
1253  siemens = make('siemens', [{'units': 'ampere'},
1254  {'units': 'volt', 'exponent': '-1'}])
1255  weber = make('weber', [{'units': 'volt'},
1256  {'units': 'second'}])
1257  tesla = make('tesla', [{'units': 'weber'},
1258  {'units': 'metre', 'exponent': '-2'}])
1259  henry = make('henry', [{'units': 'weber'},
1260  {'units': 'ampere', 'exponent': '-1'}])
1261  celsius = make('celsius', [{'units': 'kelvin', 'offset': '-273.15'}])
1262  lumen = make('lumen', [{'units': 'candela'},
1263  {'units': 'steradian'}])
1264  lux = make('lux', [{'units': 'lumen'},
1265  {'units': 'metre', 'exponent': '-2'}])
1266  becquerel = make('becquerel', [{'units': 'second', 'exponent': '-1'}])
1267  gray = make('gray', [{'units': 'joule'},
1268  {'units': 'kilogram', 'exponent': '-1'}])
1269  sievert = make('sievert', [{'units': 'joule'},
1270  {'units': 'kilogram', 'exponent': '-1'}])
1271  katal = make('katal', [{'units': 'second', 'exponent': '-1'},
1272  {'units': 'mole'}])
1273  for units in [becquerel, celsius, coulomb, farad, gram, gray, henry,
1274  hertz, joule, katal, litre, lumen, lux, newton, ohm,
1275  pascal, radian, siemens, sievert, steradian, tesla,
1276  volt, watt, weber]:
1277  std_units[units.name] = units
1278  # American spellings
1279  std_units[u'meter'] = std_units[u'metre']
1280  std_units[u'liter'] = std_units[u'litre']
1281  # User-defined units
1282  model_units = self._cml_units
1283  model_units.update(std_units)
1284  if hasattr(self, u'units'):
1285  for units in self.units:
1286  if units.name in model_units:
1287  self.validation_error("Units names must be unique within the parent component or model,"
1288  " and must not redefine the standard units (5.4.1.2)."
1289  " The units definition named '%s' in the model is a duplicate." % units.name)
1290  model_units[units.name] = units
1291  # Update units hashmap
1292  for u in model_units.itervalues():
1293  self._add_units_obj(u)
def CellMLToNektar.pycml.cellml_model._check_assigned_vars (   self,
  assignments,
  xml_context = False 
)
private
Check Rule 4.4.4: mathematical expressions may only modify
variables belonging to the current component.

Definition at line 842 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._report_exception(), and CellMLToNektar.utilities.DEBUG().

Referenced by CellMLToNektar.pycml.cellml_model.validate().

843  def _check_assigned_vars(self, assignments, xml_context=False):
844  """Check Rule 4.4.4: mathematical expressions may only modify
845  variables belonging to the current component.
846  """
847  for expr in assignments:
848  try:
849  expr.check_assigned_var()
850  except MathsError, e:
851  self._report_exception(e, xml_context)
852  DEBUG('validator', 'Checked variable assignments')
def CellMLToNektar.pycml.cellml_model._check_cellml_subset (   self,
  math_elts,
  root = True 
)
private
Warn if MathML outside the CellML subset is used.

Definition at line 853 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._check_cellml_subset(), CellMLToNektar.utilities.DEBUG(), and CellMLToNektar.pycml.cellml_model.validation_warning().

Referenced by CellMLToNektar.pycml.cellml_model._check_cellml_subset(), and CellMLToNektar.pycml.cellml_model.validate().

854  def _check_cellml_subset(self, math_elts, root=True):
855  """Warn if MathML outside the CellML subset is used."""
856  for elt in math_elts:
857  if not elt.localName in CELLML_SUBSET_ELTS and \
858  elt.namespaceURI == NSS[u'm']:
859  self.validation_warning(u' '.join([
860  u'MathML element', elt.localName,
861  u'is not in the CellML subset.',
862  u'Some tools may not be able to process it.']))
863  self._check_cellml_subset(self.xml_element_children(elt), False)
864  if root:
865  DEBUG('validator', 'Checked for CellML subset')
def CellMLToNektar.pycml.cellml_model._check_connection_units (   self,
  check_for_units_conversions = False 
)
private
Check that the units of mapped variables are dimensionally consistent.

If check_for_units_conversions is True we also warn if they are not equivalent,
since much processing software may not be able to handle that case.

Definition at line 786 of file pycml.py.

References CellMLToNektar.pycml.cellml_model.get_component_by_name(), CellMLToNektar.pycml.cellml_model.get_variable_by_name(), CellMLToNektar.pycml.cellml_model.validation_error(), and CellMLToNektar.pycml.cellml_model.validation_warning().

Referenced by CellMLToNektar.pycml.cellml_model.validate().

787  def _check_connection_units(self, check_for_units_conversions=False):
788  """Check that the units of mapped variables are dimensionally consistent.
789 
790  If check_for_units_conversions is True we also warn if they are not equivalent,
791  since much processing software may not be able to handle that case.
792  """
793  for conn in getattr(self, u'connection', []):
794  comp1 = self.get_component_by_name(conn.map_components.component_1)
795  comp2 = self.get_component_by_name(conn.map_components.component_2)
796  for mapping in conn.map_variables:
797  var1 = self.get_variable_by_name(comp1.name, mapping.variable_1)
798  var2 = self.get_variable_by_name(comp2.name, mapping.variable_2)
799  # Check the units
800  u1 = var1.get_units()
801  u2 = var2.get_units()
802  if not u1 == u2:
803  if not u1.dimensionally_equivalent(u2):
804  self.validation_error(u' '.join([
805  var1.fullname(), 'and', var2.fullname(),
806  'are mapped, but have dimensionally inconsistent units.']))
807  elif check_for_units_conversions:
808  self.validation_warning(
809  u' '.join(['Warning: mapping between', var1.fullname(), 'and',
810  var2.fullname(), 'will require a units conversion.']),
811  level=logging.WARNING_TRANSLATE_ERROR)
def CellMLToNektar.pycml.cellml_model._check_dimensional_consistency (   self,
  assignment_exprs,
  xml_context = False,
  warn_on_units_errors = False,
  check_for_units_conversions = False 
)
private
Appendix C.3.6: Equation dimension checking.

Definition at line 1154 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model.do_binding_time_analysis(), and CellMLToNektar.pycml.cellml_model.validate().

1155  check_for_units_conversions=False):
1156  """Appendix C.3.6: Equation dimension checking."""
1157  self._cml_conversions_needed = False
1158  # Check dimensions
1159  for expr in assignment_exprs:
1160  try:
1161  expr.get_units()
1162  except UnitsError, e:
1163  if warn_on_units_errors:
1164  e.warn = True
1165  e.level = logging.WARNING
1166  self._report_exception(e, xml_context)
1167  # Check if units conversions will be needed
1168  if check_for_units_conversions and not self._cml_validation_errors:
1169  boolean = self.get_units_by_name('cellml:boolean')
1170  for expr in assignment_exprs:
1171  try:
1172  DEBUG('validator', "Checking units in", element_xpath(expr), expr.component.name)
1173  expr._set_in_units(boolean, no_act=True)
1174  except UnitsError:
1175  pass
1176  # Warn if conversions used
1177  if self._cml_conversions_needed:
1178  self.validation_warning('The mathematics in this model require units conversions.',
1179  level=logging.WARNING)
1180  DEBUG('validator', 'Checked units')
def CellMLToNektar.pycml.cellml_model._check_maths_name_references (   self,
  expr,
  xml_context = False 
)
private
Check rules 4.4.2.1 and 4.4.3.2: name references in mathematics.

Definition at line 812 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._check_maths_name_references(), and CellMLToNektar.pycml.cellml_model._report_exception().

Referenced by CellMLToNektar.pycml.cellml_model._check_maths_name_references(), and CellMLToNektar.pycml.cellml_model.validate().

813  def _check_maths_name_references(self, expr, xml_context=False):
814  """Check rules 4.4.2.1 and 4.4.3.2: name references in mathematics."""
815  if isinstance(expr, mathml_ci):
816  # Check variable exists
817  try:
818  _ = expr.variable
819  except KeyError:
820  self._report_exception(
821  MathsError(expr,
822  "The content of a MathML ci element must match the name of a variable "
823  "in the enclosing component, once whitespace normalisation has been "
824  "performed (4.4.2.1). Variable '%s' does not exist in component '%s'."
825  % (unicode(expr).strip(), expr.component.name)),
826  xml_context)
827  elif isinstance(expr, mathml_cn):
828  # Check units exist
829  try:
830  expr.get_units()
831  except KeyError:
832  self._report_exception(
833  MathsError(expr,
834  "Units on a cn element must be standard or defined in the current "
835  "component or model (4.4.3.2). Units '%s' are not defined in "
836  "component '%s'." % (expr.units, expr.component.name)),
837  xml_context)
838  else:
839  # Recurse
840  for child in expr.xml_element_children():
841  self._check_maths_name_references(child, xml_context)
def CellMLToNektar.pycml.cellml_model._check_unit_cycles (   self,
  unit 
)
private
Check for cyclic units definitions.

We do this by doing a depth-first search from unit.

Definition at line 1181 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._check_unit_cycles(), and CellMLToNektar.pycml.cellml_model.validation_error().

Referenced by CellMLToNektar.pycml.cellml_model._check_unit_cycles(), and CellMLToNektar.pycml.cellml_model.validate().

1182  def _check_unit_cycles(self, unit):
1183  """Check for cyclic units definitions.
1184 
1185  We do this by doing a depth-first search from unit.
1186  """
1187  if unit.get_colour() != DFS.White:
1188  # Allow self.validate to call us without colour check
1189  return
1190  unit.set_colour(DFS.Gray)
1191  # Get the object unit is defined in
1192  parent = unit.xml_parent or self
1193  for u in getattr(unit, u'unit', []):
1194  # Explore units that this unit is defined in terms of
1195  try:
1196  v = parent.get_units_by_name(u.units)
1197  except KeyError:
1198  self.validation_error("The value of the units attribute on a unit element must be taken"
1199  " from the dictionary of standard units or be the name of a"
1200  " user-defined unit in the current component or model (5.4.2.2)."
1201  " Units '%s' are not defined." % u.units)
1202  continue
1203  if v.get_colour() == DFS.White:
1204  self._check_unit_cycles(v)
1205  elif v.get_colour() == DFS.Gray:
1206  # We have a cycle
1207  self.validation_error("Units %s and %s are in a cyclic units definition"
1208  % (unit.name, v.name))
1209  unit.set_colour(DFS.Black)
def CellMLToNektar.pycml.cellml_model._check_variable_mappings (   self)
private
Check Rules 3.4.{5,6}: check variable mappings and interfaces are sane.

Definition at line 663 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._validate_connection(), CellMLToNektar.pycml.cellml_model.build_name_dictionaries(), CellMLToNektar.utilities.DEBUG(), and CellMLToNektar.pycml.cellml_model.validation_error().

Referenced by CellMLToNektar.pycml.cellml_model.validate().

664  def _check_variable_mappings(self):
665  """Check Rules 3.4.{5,6}: check variable mappings and interfaces are sane."""
666  # First check connection elements and build mappings dict
668  connected_components = set()
669  for connection in getattr(self, u'connection', []):
670  comps = frozenset([connection.map_components.component_1, connection.map_components.component_2])
671  if comps in connected_components:
672  self.validation_error("Each map_components element must map a unique pair of components "
673  "(3.4.5.4). The pair ('%s', '%s') is repeated." % tuple(comps))
674  connected_components.add(comps)
675  self._validate_connection(connection)
676  # Now check for variables that should receive a value but don't
677  for comp in getattr(self, u'component', []):
678  for var in getattr(comp, u'variable', []):
679  for iface in [u'private_interface', u'public_interface']:
680  if getattr(var, iface, u'none') == u'in':
681  try:
682  var.get_source_variable()
683  except TypeError:
684  # No source variable found
685  self.validation_error("Variable '%s' has a %s attribute with value 'in', "
686  "but no component exports a value to that variable."
687  % (var.fullname(), iface))
688  DEBUG('validator', 'Checked variable mappings')
def CellMLToNektar.pycml.cellml_model._check_variable_units_exist (   self)
private
Check rule 3.4.3.3: that the units declared for variables exist.

Definition at line 774 of file pycml.py.

References CellMLToNektar.pycml.cellml_model.get_all_variables(), and CellMLToNektar.pycml.cellml_model.validation_error().

Referenced by CellMLToNektar.pycml.cellml_model.validate().

775  def _check_variable_units_exist(self):
776  """Check rule 3.4.3.3: that the units declared for variables exist."""
777  for var in self.get_all_variables():
778  try:
779  var.get_units()
780  except KeyError:
781  self.validation_error("The value of the units attribute on a variable must be either "
782  "one of the standard units or the name of a unit defined in the "
783  "current component or model (3.4.3.3). The units '%s' on the "
784  "variable '%s' in component '%s' do not exist."
785  % (var.units, var.name, var.component.name))
def CellMLToNektar.pycml.cellml_model._classify_variables (   self,
  assignment_exprs,
  xml_context = False 
)
private
Determine the type of each variable.

Note that mapped vars must have already been classified by
self._check_variable_mappings, and the RELAX NG schema ensures
that a variable cannot be both Mapped and MaybeConstant.

Builds the equation dependency graph in the process.

Definition at line 866 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._report_exception(), CellMLToNektar.utilities.DEBUG(), and CellMLToNektar.pycml.cellml_model.get_all_variables().

Referenced by CellMLToNektar.pycml.cellml_model.validate().

867  def _classify_variables(self, assignment_exprs, xml_context=False):
868  """Determine the type of each variable.
869 
870  Note that mapped vars must have already been classified by
871  self._check_variable_mappings, and the RELAX NG schema ensures
872  that a variable cannot be both Mapped and MaybeConstant.
873 
874  Builds the equation dependency graph in the process.
875  """
876  # Classify those vars that might be constants,
877  # i.e. have an initial value assigned.
878  for var in self.get_all_variables():
879  if hasattr(var, u'initial_value'):
880  var._set_type(VarTypes.MaybeConstant)
881  # Now classify by checking usage in mathematics, building
882  # an equation dependency graph in the process.
883  for expr in assignment_exprs:
884  try:
885  expr.classify_variables(root=True)
886  except MathsError, e:
887  self._report_exception(e, xml_context)
888  # Unused vars still classified as MaybeConstant are constants
889  for var in self.get_all_variables():
890  if var.get_type() == VarTypes.MaybeConstant:
891  var._set_type(VarTypes.Constant)
892  DEBUG('validator', 'Classified variables')
def CellMLToNektar.pycml.cellml_model._del_component (   self,
  comp 
)
private
Remove the given component from the model.

Definition at line 507 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_components.

508  def _del_component(self, comp):
509  """Remove the given component from the model."""
510  self.xml_remove_child(comp)
511  del self._cml_components[comp.name]
def CellMLToNektar.pycml.cellml_model._del_variable (   self,
  varname,
  compname 
)
private
Remove a variable from the model.

Definition at line 495 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_variables.

496  def _del_variable(self, varname, compname):
497  """Remove a variable from the model."""
498  del self._cml_variables[(compname, varname)]
def CellMLToNektar.pycml.cellml_model._get_units_obj (   self,
  units 
)
private
Unique-ify this units object.

If an object with the same definition already exists, return that.
Otherwise return the given units object.

'Same definition' is based on the cellml_units.uniquify_tuple
property, which in turn is based partly on the generated name
which would be given to these units, since that really *must*
be unique in generated models.

Definition at line 1337 of file pycml.py.

1338  def _get_units_obj(self, units):
1339  """Unique-ify this units object.
1340 
1341  If an object with the same definition already exists, return that.
1342  Otherwise return the given units object.
1343 
1344  'Same definition' is based on the cellml_units.uniquify_tuple
1345  property, which in turn is based partly on the generated name
1346  which would be given to these units, since that really *must*
1347  be unique in generated models.
1348  """
1349  return self._cml_units_map.get(units.uniquify_tuple, units)
def CellMLToNektar.pycml.cellml_model._is_new_units_obj (   self,
  units 
)
private
Have these units been generated already?

i.e. is a units object with this definition in our map?

Definition at line 1350 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_units_map.

1351  def _is_new_units_obj(self, units):
1352  """Have these units been generated already?
1353 
1354  i.e. is a units object with this definition in our map?
1355  """
1356  return units.uniquify_tuple not in self._cml_units_map
def CellMLToNektar.pycml.cellml_model._order_variables (   self,
  assignment_exprs,
  xml_context = False 
)
private
Topologically sort the equation dependency graph.

This orders all the assignment expressions in the model, to
allow procedural code generation.  It also checks that equations
are not cyclic (we don't support DAEs).

Definition at line 893 of file pycml.py.

References CellMLToNektar.pycml.cellml_model.clear_assignments().

Referenced by CellMLToNektar.pycml.cellml_model.validate().

894  def _order_variables(self, assignment_exprs, xml_context=False):
895  """Topologically sort the equation dependency graph.
896 
897  This orders all the assignment expressions in the model, to
898  allow procedural code generation. It also checks that equations
899  are not cyclic (we don't support DAEs).
900  """
901  self.clear_assignments() # Ensure we start from a clean slate
902  try:
904  for var in self.get_all_variables():
905  if var.get_colour() == DFS.White:
906  self.topological_sort(var)
907  for expr in assignment_exprs:
908  if expr.get_colour() == DFS.White:
909  self.topological_sort(expr)
910  except MathsError, e:
911  self._report_exception(e, xml_context)
912  DEBUG('validator', 'Topologically sorted variables')
def CellMLToNektar.pycml.cellml_model._remove_assignment (   self,
  a 
)
private
Remove the given assignment from our list.

This method is used by the partial evaluator.

Definition at line 1106 of file pycml.py.

1107  def _remove_assignment(self, a):
1108  """Remove the given assignment from our list.
1109 
1110  This method is used by the partial evaluator."""
self._cml_assignments.remove(a)
def CellMLToNektar.pycml.cellml_model._report_exception (   self,
  e,
  show_xml_context 
)
private
Report an exception e as a validation error or warning.

If show_xml_context is True, display the XML of the context
of the exception as well.

Definition at line 533 of file pycml.py.

References CellMLToNektar.pycml.cellml_model.validate(), CellMLToNektar.pycml.cellml_model.validation_error(), and CellMLToNektar.pycml.cellml_model.validation_warning().

Referenced by CellMLToNektar.pycml.cellml_model._check_assigned_vars(), CellMLToNektar.pycml.cellml_model._check_maths_name_references(), and CellMLToNektar.pycml.cellml_model._classify_variables().

534  def _report_exception(self, e, show_xml_context):
535  """Report an exception e as a validation error or warning.
536 
537  If show_xml_context is True, display the XML of the context
538  of the exception as well.
539  """
540  e.show_xml_context = show_xml_context
541  if e.warn:
542  self.validation_warning(unicode(e), level=e.level)
543  else:
544  self.validation_error(unicode(e), level=e.level)
def CellMLToNektar.pycml.cellml_model._validate_component_hierarchies (   self)
private
Check Rule 6.4.3.2 (4): hierarchies must not be circular.

Builds all the hierarchies, and checks for cycles.
In the process, we also check the other rules in 6.4.3, and 6.4.2.5.

Definition at line 632 of file pycml.py.

References CellMLToNektar.pycml.cellml_model.build_component_hierarchy(), CellMLToNektar.utilities.DEBUG(), and CellMLToNektar.pycml.cellml_model.validation_error().

Referenced by CellMLToNektar.pycml.cellml_model.validate().

634  """Check Rule 6.4.3.2 (4): hierarchies must not be circular.
635 
636  Builds all the hierarchies, and checks for cycles.
637  In the process, we also check the other rules in 6.4.3, and 6.4.2.5.
638  """
639  # First, we find the hierarchies that are defined.
640  hiers = set()
641  rels = []
642  for group in getattr(self, u'group', []):
643  local_hiers = set()
644  for rel in getattr(group, u'relationship_ref', []):
645  rels.append(rel)
646  reln = rel.relationship
647  ns = rel.xml_attributes[u'relationship'][1]
648  name = getattr(rel, u'name', None)
649  hier = (reln, ns, name)
650  if hier in local_hiers:
651  self.validation_error("A group element must not contain two or more relationship_ref"
652  " elements that define a relationship attribute in a common"
653  " namespace with the same value and that have the same name"
654  " attribute value (which may be non-existent) (6.4.2.5)."
655  " Relationship '%s' name '%s' in namespace '%s' is repeated."
656  % (reln, name or '', ns))
657  local_hiers.add(hier)
658  hiers.add(hier)
659  # Now build & check each hierarchy
660  for hier in hiers:
661  self.build_component_hierarchy(hier[0], hier[1], hier[2], rels=rels)
662  DEBUG('validator', 'Checked component hierachies')
def CellMLToNektar.pycml.cellml_model._validate_connection (   self,
  conn 
)
private
Validate the given connection element.

Check that the given connection object defines valid mappings
between variables, according to rules 3.4.5 and 3.4.6.

Definition at line 689 of file pycml.py.

References CellMLToNektar.pycml.cellml_model.get_component_by_name(), CellMLToNektar.pycml.cellml_model.get_variable_by_name(), and CellMLToNektar.pycml.cellml_model.validation_error().

Referenced by CellMLToNektar.pycml.cellml_model._check_variable_mappings().

690  def _validate_connection(self, conn):
691  """Validate the given connection element.
692 
693  Check that the given connection object defines valid mappings
694  between variables, according to rules 3.4.5 and 3.4.6.
695  """
696  # Check we are allowed to connect these components
697  try:
698  comp1 = self.get_component_by_name(conn.map_components.component_1)
699  except KeyError:
700  self.validation_error("Connections must be between components defined in the current model "
701  "(3.4.5.2). There is no component '%s'." % conn.map_components.component_1)
702  return
703  try:
704  comp2 = self.get_component_by_name(conn.map_components.component_2)
705  except KeyError:
706  self.validation_error("Connections must be between components defined in the current model "
707  "(3.4.5.3). There is no component '%s'." % conn.map_components.component_2)
708  return
709  if comp1 is comp2:
710  self.validation_error("A connection must link two different components (3.4.5.4). "
711  "The component '%s' is being connected to itself." % comp1.name)
712  return
713  # Get the parent of each component in the encapsulation hierarchy
714  par1, par2 = comp1.parent(), comp2.parent()
715  # The two components must either be siblings (maybe top-level) or parent & child.
716  if not (par1 == comp2 or par2 == comp1 or par1 == par2):
717  self.validation_error(u' '.join([
718  'Connections are only permissible between sibling',
719  'components, or where one is the parent of the other.\n',
720  comp1.name,'and',comp2.name,'are unrelated.']))
721  return
722  # Now check each variable mapping
723  for mapping in conn.map_variables:
724  try:
725  var1 = self.get_variable_by_name(comp1.name, mapping.variable_1)
726  except KeyError:
727  self.validation_error("A variable mapping must be between existing variables (3.4.6.2). "
728  "Variable '%s' doesn't exist in component '%s'."
729  % (mapping.variable_1, comp1.name))
730  continue
731  try:
732  var2 = self.get_variable_by_name(comp2.name, mapping.variable_2)
733  except KeyError:
734  self.validation_error("A variable mapping must be between existing variables (3.4.6.2). "
735  "Variable '%s' doesn't exist in component '%s'."
736  % (mapping.variable_2, comp2.name))
737  continue
738  errm, e = ['Interface mismatch mapping',var1.fullname(),'and',var2.fullname(),':\n'], None
739  if par1 == par2:
740  # Siblings, so should have differing public interfaces
741  if not hasattr(var1, 'public_interface'):
742  e = 'missing public_interface attribute on ' + \
743  var1.fullname() + '.'
744  elif not hasattr(var2, 'public_interface'):
745  e = 'missing public_interface attribute on ' + \
746  var2.fullname() + '.'
747  elif var1.public_interface == var2.public_interface:
748  e = 'public_interface attributes are identical.'
749  else:
750  if var1.public_interface == 'in':
751  var1._set_source_variable(var2)
752  else:
753  var2._set_source_variable(var1)
754  else:
755  if par2 == comp1:
756  # Component 1 is the parent of component 2
757  var1, var2 = var2, var1
758  # Now var2 is in the parent component, and var1 in the child
759  if not hasattr(var1, 'public_interface'):
760  e = var1.fullname()+' missing public_interface.'
761  elif not hasattr(var2, 'private_interface'):
762  e = var2.fullname()+' missing private_interface.'
763  elif var1.public_interface == var2.private_interface:
764  e = 'relevant interfaces have identical values.'
765  else:
766  if var1.public_interface == 'in':
767  var1._set_source_variable(var2)
768  else:
769  var2._set_source_variable(var1)
770  # If there was an error, log it
771  if e:
772  errm.append(e)
773  self.validation_error(u' '.join(errm))
def CellMLToNektar.pycml.cellml_model.add_units (   self,
  name,
  units 
)
Add an entry in our units dictionary for units named `name' with element object `units'.

Definition at line 1318 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._add_units_obj(), CellMLToNektar.pycml.cellml_model._build_units_dictionary(), and CellMLToNektar.pycml.cellml_model._cml_units.

1319  def add_units(self, name, units):
1320  """Add an entry in our units dictionary for units named `name' with element object `units'."""
1321  if not self._cml_units:
1323  assert name not in self._cml_units
1324  self._cml_units[name] = units
1325  self._add_units_obj(units)
1326  return
def CellMLToNektar.pycml.cellml_model.add_units_conversions (   self)
Add explicit units conversion mathematics where necessary.

Definition at line 1357 of file pycml.py.

References CellMLToNektar.pycml.import_processors().

1358  def add_units_conversions(self):
1359  """Add explicit units conversion mathematics where necessary."""
1361  processors.UnitsConverter(self).add_all_conversions()
def import_processors
Definition: pycml.py:84
def CellMLToNektar.pycml.cellml_model.build_component_hierarchy (   self,
  relationship,
  namespace = None,
  name = None,
  rels = None 
)
Create all the parent-child links for the given component hierarchy.

relationship gives the type of the hierarchy. If it is not one of the
CellML types (i.e. encapsulation or containment) then the namespace URI
must be specified.  Multiple non-encapsulation hierarchies of the same
type can be specified by giving the name argument.

Definition at line 958 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_validation_errors, CellMLToNektar.pycml.cellml_model.build_name_dictionaries(), CellMLToNektar.pycml.cellml_model.get_component_by_name(), and CellMLToNektar.pycml.cellml_model.validation_error().

Referenced by CellMLToNektar.pycml.cellml_model._validate_component_hierarchies().

959  def build_component_hierarchy(self, relationship, namespace=None, name=None, rels=None):
960  """
961  Create all the parent-child links for the given component hierarchy.
962 
963  relationship gives the type of the hierarchy. If it is not one of the
964  CellML types (i.e. encapsulation or containment) then the namespace URI
965  must be specified. Multiple non-encapsulation hierarchies of the same
966  type can be specified by giving the name argument.
967  """
968  key = (relationship, namespace, name)
969  # Set all components to have no parent or children, under this hierarchy
970  for comp in getattr(self, u'component', []):
971  comp._clear_hierarchy(key)
973  # Find nodes defining this hierarchy
974  if rels is None:
975  rels = self.xml_xpath(u'cml:group/cml:relationship_ref')
976  groups = []
977  for rel in rels:
978  # NB: The first test below relies on there only being one
979  # attr with localname of 'relationship' on each rel.
980  # So let's check this...
981  if hasattr(rel, u'relationship_'):
982  self.validation_error(u' '.join([
983  'relationship_ref element has multiple relationship',
984  'attributes in different namespaces:\n'] +
985  map(lambda qn,ns: '('+qn+','+ns+')',
986  rel.xml_attributes.values())))
987  return
988  if rel.relationship == relationship and \
989  rel.xml_attributes[u'relationship'][1] == namespace and \
990  getattr(rel, u'name', None) == name:
991  # It's in the hierarchy
992  groups.append(rel.xml_parent)
993  # Now build all the parent links for this hierarchy
994  def set_parent(p, crefs):
995  for cref in crefs:
996  # Find component cref refers to
997  try:
998  c = self.get_component_by_name(cref.component)
999  except KeyError:
1000  self.validation_error("A component_ref element must reference a component in the current"
1001  " model (6.4.3.3). Component '%s' does not exist." % cref.component)
1002  return
1003  # Set c's parent to p
1004  c._set_parent_component(key, p)
1005  if hasattr(cref, 'component_ref'):
1006  # If we already have children under this hierarchy it's a validation error
1007  if c._has_child_components(key):
1008  self.validation_error("In a given hierarchy, only one component_ref element "
1009  "referencing a given component may contain children (6.4.3.2)."
1010  " Component '%s' has children in multiple locations." % c.name)
1011  # Set parent of c's children to c
1012  set_parent(c, cref.component_ref)
1013  elif p is None and namespace is None:
1014  self.validation_error("Containment and encapsulation relationships must be hierarchical"
1015  " (6.4.3.2). Potentially top-level component '%s' has not been"
1016  " given children." % cref.component)
1017  for group in groups:
1018  set_parent(None, group.component_ref)
1019  if self._cml_validation_errors:
1020  return
1021  # Check for a cycle in the hierarchy (rule 6.4.3.2 (4)).
1022  # Note that since we have already ensured that no component is a parent in more than one location,
1023  # nor is any component a child more than once, so the only possibility for a cycle is if one of
1024  # the components referenced as a child of a group element is also referenced as a (leaf) descendent
1025  # of one of its children. We check for this by following parent links backwards.
1026  def has_cycle(root_comp, cur_comp):
1027  if cur_comp is None:
1028  return False
1029  elif cur_comp is root_comp:
1030  return True
1031  else:
1032  return has_cycle(root_comp, cur_comp.parent(reln_key=key))
1033  for group in groups:
1034  for cref in group.component_ref:
1035  # Find component cref refers to
1036  c = self.get_component_by_name(cref.component)
1037  if has_cycle(c, c.parent(reln_key = key)):
1038  n, ns = name or "", namespace or ""
1039  self.validation_error("The '%s' relationship hierarchy with name '%s' and namespace"
1040  " '%s' has a cycle" % (relationship, n, ns))
1041  return
def CellMLToNektar.pycml.cellml_model.build_name_dictionaries (   self,
  rebuild = False 
)
Create dictionaries mapping names of variables and components to
the objects representing them.
Dictionary keys for variables will be
  (component_name, variable_name).

If rebuild is True, clear the dictionaries first.

Definition at line 932 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_components, CellMLToNektar.pycml.cellml_model._cml_variables, and CellMLToNektar.pycml.cellml_model.validation_error().

Referenced by CellMLToNektar.pycml.cellml_model._check_variable_mappings(), and CellMLToNektar.pycml.cellml_model.build_component_hierarchy().

933  def build_name_dictionaries(self, rebuild=False):
934  """
935  Create dictionaries mapping names of variables and components to
936  the objects representing them.
937  Dictionary keys for variables will be
938  (component_name, variable_name).
939 
940  If rebuild is True, clear the dictionaries first.
941  """
942  if rebuild:
943  self._cml_variables = {}
944  self._cml_components = {}
945  if not self._cml_components:
946  for comp in getattr(self, u'component', []):
947  if comp.name in self._cml_components:
948  self.validation_error("Component names must be unique within a model (3.4.2.2)."
949  " The name '%s' is repeated." % comp.name)
950  self._cml_components[comp.name] = comp
951  for var in getattr(comp, u'variable', []):
952  key = (comp.name, var.name)
953  if key in self._cml_variables:
954  self.validation_error("Variable names must be unique within a component (3.4.3.2)."
955  " The name '%s' is repeated in component '%s'."
956  % (var.name, comp.name))
957  self._cml_variables[key] = var
def CellMLToNektar.pycml.cellml_model.calculate_extended_dependencies (   self,
  nodes,
  prune = [],
  prune_deps = [],
  state_vars_depend_on_odes = False,
  state_vars_examined = set() 
)
Calculate the extended dependencies of the given nodes.

Recurse into the dependency graph, in order to construct a
set, for each node in nodes, of all the nodes on which it
depends, either directly or indirectly.

Each node IS included in its own dependency set.

If prune is specified, it should be a set of nodes for which
we won't include their dependencies or the nodes themselves.
This is useful e.g. for pruning variables required for calculating
a stimulus if the stimulus is being provided by another method.
prune_deps is similar: dependencies of these nodes will be excluded,
but the nodes themselves will be included if asked for.

If state_vars_depend_on_odes is True, then considers state variables
to depend on the ODE defining them.

Requires the dependency graph to be acyclic.

Return the union of all the dependency sets.

Definition at line 1381 of file pycml.py.

References CellMLToNektar.pycml.cellml_model.calculate_extended_dependencies().

Referenced by CellMLToNektar.pycml.cellml_model.calculate_extended_dependencies(), CellMLToNektar.pycml.cellml_model.find_free_vars(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations_grl(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl_compute_partial(), and CellMLToNektar.translators.CellMLTranslator.output_table_index_generation().

1382  state_vars_examined=set()):
1383  """Calculate the extended dependencies of the given nodes.
1384 
1385  Recurse into the dependency graph, in order to construct a
1386  set, for each node in nodes, of all the nodes on which it
1387  depends, either directly or indirectly.
1388 
1389  Each node IS included in its own dependency set.
1390 
1391  If prune is specified, it should be a set of nodes for which
1392  we won't include their dependencies or the nodes themselves.
1393  This is useful e.g. for pruning variables required for calculating
1394  a stimulus if the stimulus is being provided by another method.
1395  prune_deps is similar: dependencies of these nodes will be excluded,
1396  but the nodes themselves will be included if asked for.
1397 
1398  If state_vars_depend_on_odes is True, then considers state variables
1399  to depend on the ODE defining them.
1400 
1401  Requires the dependency graph to be acyclic.
1402 
1403  Return the union of all the dependency sets.
1404  """
1405  deps = set()
1406  for node in nodes:
1407  if node in prune or (isinstance(node, mathml_apply) and
1408  isinstance(node.operator(), mathml_eq) and
1409  isinstance(node.eq.lhs, mathml_ci) and
1410  node.eq.lhs.variable in prune):
1411  continue
1412  if type(node) == tuple:
1413  # This is an ODE dependency, so get the defining expression instead.
1414  ode = True
1415  orig_node = node
1416  node = node[0].get_ode_dependency(node[1])
1417  if orig_node in prune_deps:
1418  # Include the defining expression, but skip its dependencies
1419  deps.add(node)
1420  continue
1421  free_var = node.eq.lhs.diff.independent_variable
1422  else:
1423  ode = False
1424  deps.add(node)
1425  if node in prune_deps:
1426  # Skip dependencies of this node
1427  continue
1428  nodedeps = set(node.get_dependencies())
1429  if ode and not node._cml_ode_has_free_var_on_rhs:
1430  # ODEs depend on their independent variable. However,
1431  # when writing out code we don't want to pull the free
1432  # variable in just for this, as the compiler then
1433  # gives us unused variable warnings.
1434  nodedeps.remove(free_var)
1435  if (state_vars_depend_on_odes and isinstance(node, cellml_variable)
1436  and node.get_type() == VarTypes.State
1437  and node not in state_vars_examined):
1438  nodedeps.update(node.get_all_expr_dependencies())
1439  state_vars_examined.add(node)
1440  deps.update(self.calculate_extended_dependencies(nodedeps,
1441  prune=prune,
1442  prune_deps=prune_deps,
1443  state_vars_depend_on_odes=state_vars_depend_on_odes,
1444  state_vars_examined=state_vars_examined))
1445  return deps
def CellMLToNektar.pycml.cellml_model.clean_up (   self)
Try to get the RDF library to clean up nicely.

Definition at line 398 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model.__del__().

399  def clean_up(self):
400  """Try to get the RDF library to clean up nicely."""
401  cellml_metadata.remove_model(self)
def CellMLToNektar.pycml.cellml_model.clear_assignments (   self)
Clear the assignments list.

Definition at line 1120 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_assignments.

Referenced by CellMLToNektar.pycml.cellml_model._order_variables().

1121  def clear_assignments(self):
1122  """Clear the assignments list."""
1123  self._cml_assignments = []
def CellMLToNektar.pycml.cellml_model.do_binding_time_analysis (   self)
Perform a binding time analysis on the model's mathematics.

This requires variables to have been classified and a
topological sort of the mathematics to have been performed.

Variables and top-level expressions are processed in the order
given by the topological sort, hence only a single pass is
necessary.

Variables are classified based on their type:
  State, Free -> dynamic
  Constant -> static
  Mapped -> binding time of source variable
  Computed -> binding time of defining expression

Expressions are dealt with by recursively annotating
subexpressions.  See code in the MathML classes for details.

Definition at line 1124 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._check_dimensional_consistency(), and CellMLToNektar.pycml.cellml_model.get_assignments().

1125  def do_binding_time_analysis(self):
1126  """Perform a binding time analysis on the model's mathematics.
1127 
1128  This requires variables to have been classified and a
1129  topological sort of the mathematics to have been performed.
1130 
1131  Variables and top-level expressions are processed in the order
1132  given by the topological sort, hence only a single pass is
1133  necessary.
1134 
1135  Variables are classified based on their type:
1136  State, Free -> dynamic
1137  Constant -> static
1138  Mapped -> binding time of source variable
1139  Computed -> binding time of defining expression
1140 
1141  Expressions are dealt with by recursively annotating
1142  subexpressions. See code in the MathML classes for details.
1143  """
1144  for item in self.get_assignments():
1145  if isinstance(item, cellml_variable):
1146  # Set binding time based on type
1147  item._get_binding_time()
1148  else:
1149  # Compute binding time recursively
1150  item._get_binding_time()
def CellMLToNektar.pycml.cellml_model.find_free_vars (   self)
Return a list of the free variable elements in this model.

Definition at line 1370 of file pycml.py.

References CellMLToNektar.pycml.cellml_model.calculate_extended_dependencies(), and CellMLToNektar.pycml.cellml_model.get_all_variables().

1371  def find_free_vars(self):
1372  """Return a list of the free variable elements in this model."""
1373  free_vars = []
1374  for var in self.get_all_variables():
1375  if var.get_type() == VarTypes.Free:
1376  free_vars.append(var)
1377  return free_vars
def CellMLToNektar.pycml.cellml_model.find_state_vars (   self)
Return a list of the state variable elements in this model.

Definition at line 1362 of file pycml.py.

References CellMLToNektar.pycml.cellml_model.get_all_variables().

1363  def find_state_vars(self):
1364  """Return a list of the state variable elements in this model."""
1365  state_vars = []
1366  for var in self.get_all_variables():
1367  if var.get_type() == VarTypes.State:
1368  state_vars.append(var)
1369  return state_vars
def CellMLToNektar.pycml.cellml_model.get_all_units (   self)
Get a list of all units objects, including the standard units.

Definition at line 1300 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._build_units_dictionary(), and CellMLToNektar.pycml.cellml_model._cml_units.

Referenced by CellMLToNektar.pycml.cellml_model.validate().

1301  def get_all_units(self):
1302  """Get a list of all units objects, including the standard units."""
1303  if not self._cml_units:
1305  units = self._cml_units.values()
1306  for comp in getattr(self, u'component', []):
1307  units.extend(comp.get_all_units())
1308  return units
def CellMLToNektar.pycml.cellml_model.get_all_variables (   self)
Return an iterator over the variables in the model.

Definition at line 484 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model._check_variable_units_exist(), CellMLToNektar.pycml.cellml_model._classify_variables(), CellMLToNektar.pycml.cellml_model.find_free_vars(), and CellMLToNektar.pycml.cellml_model.find_state_vars().

485  def get_all_variables(self):
486  """Return an iterator over the variables in the model."""
487  for comp in getattr(self, u'component', []):
488  for var in getattr(comp, u'variable', []):
489  yield var
def CellMLToNektar.pycml.cellml_model.get_assignments (   self)
Return a sorted list of all the assignments in the model.

Assignments can either be instances of cellml_variable, in
which case they represent a variable mapping, or instances of
mathml_apply, representing top-level assignment expressions.

Definition at line 1111 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_assignments.

Referenced by CellMLToNektar.pycml.cellml_model.do_binding_time_analysis().

1112  def get_assignments(self):
1113  """
1114  Return a sorted list of all the assignments in the model.
1115 
1116  Assignments can either be instances of cellml_variable, in
1117  which case they represent a variable mapping, or instances of
1118  mathml_apply, representing top-level assignment expressions.
1119  """
return self._cml_assignments
def CellMLToNektar.pycml.cellml_model.get_component_by_name (   self,
  compname 
)
Return the component object that has name `compname'.

Definition at line 414 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_components.

Referenced by CellMLToNektar.pycml.cellml_model._check_connection_units(), CellMLToNektar.pycml.cellml_model._validate_connection(), and CellMLToNektar.pycml.cellml_model.build_component_hierarchy().

415  def get_component_by_name(self, compname):
416  """Return the component object that has name `compname'."""
417  return self._cml_components[compname]
def CellMLToNektar.pycml.cellml_model.get_config (   self,
  config_attr = None 
)
Get the configuration store if it exists, or an attribute thereof.

Definition at line 402 of file pycml.py.

403  def get_config(self, config_attr=None):
404  """Get the configuration store if it exists, or an attribute thereof."""
405  config = getattr(self.xml_parent, '_cml_config', None)
406  if config_attr:
407  config = getattr(config, config_attr, None)
408  return config
def CellMLToNektar.pycml.cellml_model.get_option (   self,
  option_name 
)
Get the value of a command-line option.

Definition at line 409 of file pycml.py.

410  def get_option(self, option_name):
411  """Get the value of a command-line option."""
412  config = getattr(self.xml_parent, '_cml_config', None)
413  return config and getattr(config.options, option_name)
def CellMLToNektar.pycml.cellml_model.get_standard_units (   self)
Get a dictionary mapping the names of the standard CellML units to their definitions.

Definition at line 1294 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._build_units_dictionary(), and CellMLToNektar.pycml.cellml_model._cml_standard_units.

1295  def get_standard_units(self):
1296  """Get a dictionary mapping the names of the standard CellML units to their definitions."""
1297  if not self._cml_standard_units:
1299  return self._cml_standard_units
def CellMLToNektar.pycml.cellml_model.get_units_by_name (   self,
  uname 
)
Return an object representing the element that defines the units named `uname'.

Definition at line 1309 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._build_units_dictionary(), and CellMLToNektar.pycml.cellml_model._cml_units.

1310  def get_units_by_name(self, uname):
1311  """Return an object representing the element that defines the units named `uname'."""
1312  if not self._cml_units:
1314  try:
1315  return self._cml_units[uname]
1316  except KeyError:
1317  raise KeyError("Units '%s' are not defined in the current component or model." % uname)
def CellMLToNektar.pycml.cellml_model.get_validation_errors (   self)
Return the list of all errors found (so far) while validating this model.

Definition at line 519 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_validation_errors.

520  def get_validation_errors(self):
521  """Return the list of all errors found (so far) while validating this model."""
return self._cml_validation_errors
def CellMLToNektar.pycml.cellml_model.get_validation_warnings (   self)
Return the list of all warnings found (so far) while validating this model.

Definition at line 529 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_validation_warnings.

530  def get_validation_warnings(self):
531  """Return the list of all warnings found (so far) while validating this model.
532  """
return self._cml_validation_warnings
def CellMLToNektar.pycml.cellml_model.get_variable_by_cmeta_id (   self,
  cmeta_id 
)
Get the unique variable in this model with the given cmeta:id attribute value.

Definition at line 474 of file pycml.py.

475  def get_variable_by_cmeta_id(self, cmeta_id):
476  """
477  Get the unique variable in this model with the given cmeta:id attribute value.
478  """
479  vars = self.xml_xpath(u'cml:component/cml:variable[@cmeta:id="%s"]' % cmeta_id)
480  if len(vars) != 1:
481  raise ValueError('"%s" does not ID a unique variable (matches: %s)'
482  % (cmeta_id, str(vars)))
483  return vars[0]
def CellMLToNektar.pycml.cellml_model.get_variable_by_name (   self,
  compname,
  varname 
)
Return the variable object with name `varname' in component
`compname'.

Definition at line 418 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_variables.

Referenced by CellMLToNektar.pycml.cellml_model._check_connection_units(), and CellMLToNektar.pycml.cellml_model._validate_connection().

419  def get_variable_by_name(self, compname, varname):
420  """
421  Return the variable object with name `varname' in component
422  `compname'.
423  """
424  try:
425  var = self._cml_variables[(compname, varname)]
426  except KeyError, e:
427  if compname == u'':
428  if self.component.ignore_component_name:
429  compname = self.component.name
430  else:
431  try:
432  compname, varname = cellml_variable.split_name(varname)
433  except ValueError:
434  raise e
435  var = self._cml_variables[(compname, varname)]
436  else:
437  raise e
438  return var
def CellMLToNektar.pycml.cellml_model.get_variable_by_oxmeta_name (   self,
  name,
  throw = True 
)
Get the unique variable in this model with the given Oxford metadata
name annotation.

If throw is True, will raise ValueError if there is no such variable,
or more than 1 match.  If throw is False, returns None in these cases.

Definition at line 439 of file pycml.py.

440  def get_variable_by_oxmeta_name(self, name, throw=True):
441  """
442  Get the unique variable in this model with the given Oxford metadata
443  name annotation.
444 
445  If throw is True, will raise ValueError if there is no such variable,
446  or more than 1 match. If throw is False, returns None in these cases.
447  """
448  vars = cellml_metadata.find_variables(self,
449  ('bqbiol:is', NSS['bqbiol']),
450  ('oxmeta:'+str(name), NSS['oxmeta']))
451  if len(vars) == 1:
452  var = vars[0]
453  elif throw:
454  raise ValueError('"%s" does not name a unique variable (matches: %s)'
455  % (name, str(vars)))
456  else:
457  var = None
458  return var
def CellMLToNektar.pycml.cellml_model.get_variables_by_ontology_term (   self,
  term 
)
Return a list of variables annotated with the given ontology term.

The annotations have the same form as for oxmeta name annotations (see
get_variable_by_oxmeta_name).  However, here we are not restricted to
namespace, and no check is done on the number of results returned.

The given term must be a (prefixed_name, nsuri) tuple.

Definition at line 459 of file pycml.py.

460  def get_variables_by_ontology_term(self, term):
461  """Return a list of variables annotated with the given ontology term.
462 
463  The annotations have the same form as for oxmeta name annotations (see
464  get_variable_by_oxmeta_name). However, here we are not restricted to
465  namespace, and no check is done on the number of results returned.
466 
467  The given term must be a (prefixed_name, nsuri) tuple.
468  """
469  assert isinstance(term, tuple)
470  assert len(term) == 2
471  named_vars = cellml_metadata.find_variables(self, ('bqbiol:is', NSS['bqbiol']), term)
472  category_vars = cellml_metadata.find_variables(self, ('bqbiol:isVersionOf', NSS['bqbiol']), term)
473  return named_vars + category_vars
def CellMLToNektar.pycml.cellml_model.has_units (   self,
  units 
)
Test whether a given units definition appears in the model.

Definition at line 1327 of file pycml.py.

1328  def has_units(self, units):
1329  """Test whether a given units definition appears in the model."""
1330  return units in self._cml_units.itervalues()
def CellMLToNektar.pycml.cellml_model.is_self_excitatory (   self)
Determine whether this model is self-excitatory,
i.e. does not require an external stimulus.

Definition at line 1446 of file pycml.py.

References CellMLToNektar.pycml.element_base.cmeta_id().

1447  def is_self_excitatory(self):
1448  """Determine whether this model is self-excitatory,
1449  i.e. does not require an external stimulus.
1450  """
1451  meta_id = self.cmeta_id
1452  if not meta_id:
1453  return False
1454  property = cellml_metadata.create_rdf_node(('pycml:is-self-excitatory', NSS['pycml']))
1455  source = cellml_metadata.create_rdf_node(fragment_id=meta_id)
1456  return cellml_metadata.get_target(self, source, property) == 'yes'
def CellMLToNektar.pycml.cellml_model.search_for_assignments (   self,
  comp = None 
)
Search for assignment expressions in the model's mathematics.

If comp is supplied, will only return assignments in that component.

Definition at line 918 of file pycml.py.

References CellMLToNektar.pycml.cellml_model.apply_xpath_1, CellMLToNektar.pycml.cellml_model.apply_xpath_2, CellMLToNektar.pycml.cellml_model.math_xpath_1, and CellMLToNektar.pycml.cellml_model.math_xpath_2.

Referenced by CellMLToNektar.pycml.cellml_model.validate().

919  def search_for_assignments(self, comp=None):
920  """Search for assignment expressions in the model's mathematics.
921 
922  If comp is supplied, will only return assignments in that component.
923  """
924  assignments_xpath = u' | '.join([self.math_xpath_1 + self.apply_xpath_1,
925  self.math_xpath_1 + self.apply_xpath_2,
926  self.math_xpath_2 + self.apply_xpath_1,
927  self.math_xpath_2 + self.apply_xpath_2])
928  if comp:
929  assignments_xpath = assignments_xpath.replace(u'component',
930  u'component[@name="%s"]' % comp.name)
931  return self.xml_xpath(assignments_xpath)
def CellMLToNektar.pycml.cellml_model.topological_sort (   self,
  node 
)
Do a topological sort of all assignment expressions and variables
in the model.

node should be an expression or variable object that inherits from
Colourable and has methods get_dependencies, get_component

Definition at line 1042 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._add_sorted_assignment(), CellMLToNektar.pycml.cellml_model._cml_sorting_variables_stack, CellMLToNektar.pycml.cellml_model.topological_sort(), and CellMLToNektar.pycml.cellml_model.validation_error().

Referenced by CellMLToNektar.pycml.cellml_model.topological_sort().

1043  def topological_sort(self, node):
1044  """
1045  Do a topological sort of all assignment expressions and variables
1046  in the model.
1047 
1048  node should be an expression or variable object that inherits from
1049  Colourable and has methods get_dependencies, get_component
1050  """
1051  node.set_colour(DFS.Gray)
1052  # Keep track of gray variables, for reporting cycles
1053  if isinstance(node, cellml_variable):
1054  self._cml_sorting_variables_stack.append(node.fullname())
1055  elif node.is_ode():
1056  # This is an expression defining an ODE; the name on the
1057  # stack will look something like d(V)/d(t)
1058  n1, n2 = map(lambda v: v.fullname(), node.assigned_variable())
1059  self._cml_sorting_variables_stack.append(u'd'+n1+u'/d'+n2)
1060  # Visit children in the dependency graph
1061  for dep in node.get_dependencies():
1062  if type(dep) == types.TupleType:
1063  # This is an ODE dependency, so get the defining expression
1064  dep = dep[0].get_ode_dependency(dep[1], node)
1065  if dep.get_colour() == DFS.White:
1066  self.topological_sort(dep)
1067  elif dep.get_colour() == DFS.Gray:
1068  # We have a cyclic dependency
1069  if isinstance(dep, cellml_variable):
1070  i = self._cml_sorting_variables_stack.index(dep.fullname())
1071  elif node.is_ode():
1072  n1, n2 = map(lambda v: v.fullname(),
1073  dep.assigned_variable())
1074  i = self._cml_sorting_variables_stack.index(
1075  u'd'+n1+u'/d'+n2)
1076  else:
1077  # Since any variable always depends on a mathematical
1078  # expression defining it, the only case where the
1079  # expression is gray before the corresponding variable
1080  # (apart from an ODE, dealt with above) is if a tree
1081  # started at an expression. Hence the whole stack
1082  # is in the cycle.
1083  i = 0
1084  varnames = self._cml_sorting_variables_stack[i:]
1085  self.validation_error(u' '.join([
1086  u'There is a cyclic dependency involving the following',
1087  u'variables:', u','.join(varnames)]))
1088  # Finish this node, and add it to the appropriate sorted list
1089  node.set_colour(DFS.Black)
1090  self._add_sorted_assignment(node)
1091  # Pop the gray variables stack
1092  if (isinstance(node, cellml_variable) or node.is_ode()):
1093  self._cml_sorting_variables_stack.pop()
1094  return
def CellMLToNektar.pycml.cellml_model.validate (   self,
  xml_context = False,
  invalid_if_warnings = False,
  warn_on_units_errors = False,
  check_for_units_conversions = False,
  assume_valid = False,
  ignored_kwargs 
)
Validate this model.

Assumes that RELAX NG validation has been done.  Checks rules
3.4.2.2, 3.4.3.2, 3.4.3.3, 3.4.5.2, 3.4.5.3, 3.4.5.4, 3.4.6.2, 3.4.6.3, 3.4.6.4,
4.4.2.1, 4.4.3.2, 4.4.4, 5.4.1.2, 5.4.2.2, 6.4.2.5, 6.4.3.2, and 6.4.3.3
in the CellML 1.0 spec, and performs units checking.

Note that if some checks fail, most of the remaining checks
will not be performed.  Hence when testing a model validate
repeatedly until it passes.

If xml_context is True, then the failing MathML tree will be
displayed with every units error.

If check_for_units_conversions is True, then generate a warning if
units conversions will be needed.

If assume_valid is True then fewer checks will be done - only
what is required to set up the data structures needed for model
transformation.

Returns True iff the model validates.
When invalid_if_warnings is True the model will fail to validate
if there are any warnings, as well as if there are any errors.

Definition at line 549 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._check_assigned_vars(), CellMLToNektar.pycml.cellml_model._check_cellml_subset(), CellMLToNektar.pycml.cellml_model._check_connection_units(), CellMLToNektar.pycml.cellml_model._check_dimensional_consistency(), CellMLToNektar.pycml.cellml_model._check_maths_name_references(), CellMLToNektar.pycml.cellml_model._check_unit_cycles(), CellMLToNektar.pycml.cellml_model._check_variable_mappings(), CellMLToNektar.pycml.cellml_model._check_variable_units_exist(), CellMLToNektar.pycml.cellml_model._classify_variables(), CellMLToNektar.pycml.cellml_model._cml_validation_errors, CellMLToNektar.pycml.cellml_model._cml_validation_warnings, CellMLToNektar.pycml.cellml_model._order_variables(), CellMLToNektar.pycml.cellml_model._validate_component_hierarchies(), CellMLToNektar.utilities.DEBUG(), CellMLToNektar.pycml.cellml_model.get_all_units(), CellMLToNektar.pycml.cellml_model.math_xpath_1, CellMLToNektar.pycml.cellml_model.math_xpath_2, CellMLToNektar.pycml.cellml_model.search_for_assignments(), and CellMLToNektar.pycml.cellml_model.validation_warning().

Referenced by CellMLToNektar.pycml.cellml_model._report_exception().

550  assume_valid=False, **ignored_kwargs):
551  """Validate this model.
552 
553  Assumes that RELAX NG validation has been done. Checks rules
554  3.4.2.2, 3.4.3.2, 3.4.3.3, 3.4.5.2, 3.4.5.3, 3.4.5.4, 3.4.6.2, 3.4.6.3, 3.4.6.4,
555  4.4.2.1, 4.4.3.2, 4.4.4, 5.4.1.2, 5.4.2.2, 6.4.2.5, 6.4.3.2, and 6.4.3.3
556  in the CellML 1.0 spec, and performs units checking.
557 
558  Note that if some checks fail, most of the remaining checks
559  will not be performed. Hence when testing a model validate
560  repeatedly until it passes.
561 
562  If xml_context is True, then the failing MathML tree will be
563  displayed with every units error.
564 
565  If check_for_units_conversions is True, then generate a warning if
566  units conversions will be needed.
567 
568  If assume_valid is True then fewer checks will be done - only
569  what is required to set up the data structures needed for model
570  transformation.
571 
572  Returns True iff the model validates.
573  When invalid_if_warnings is True the model will fail to validate
574  if there are any warnings, as well as if there are any errors.
575  """
577 
578  # Rule 5.4.2.2: units definitions may not be circular.
579  # Also checks 5.4.1.2: no duplicate units names.
580  if not assume_valid:
581  for unit in self.get_all_units():
582  self._check_unit_cycles(unit)
583  DEBUG('validator', 'Checked for units cycles')
584  # Check rule 3.4.3.3 too.
586 
587  if not self._cml_validation_errors:
588  self._check_variable_mappings() # This sets up source variable links
589  if not self._cml_validation_errors and not assume_valid:
590  self._check_connection_units(check_for_units_conversions)
591 
592  # Rules 4.4.2.1 and 4.4.3.2: check name references in mathematics
593  if not self._cml_validation_errors:
594  assignment_exprs = self.search_for_assignments()
595  if not assume_valid:
596  for expr in assignment_exprs:
597  self._check_maths_name_references(expr, xml_context)
598 
599  # Rule 4.4.4: mathematical expressions may only modify
600  # variables belonging to the current component.
601  if not self._cml_validation_errors and not assume_valid:
602  self._check_assigned_vars(assignment_exprs, xml_context)
603 
604  # Warn if mathematics outside the CellML subset is used.
605  if not self._cml_validation_errors and not assume_valid:
606  math_elts = self.xml_xpath(self.math_xpath_1 + u' | ' + self.math_xpath_2)
607  self._check_cellml_subset(math_elts)
608 
609  # Classify variables and check for circular equations.
610  # Does a topological sort of all equations in the process.
611  # TODO: Handle reactions properly.
612  if not self._cml_validation_errors:
613  self._classify_variables(assignment_exprs, xml_context)
614  self._order_variables(assignment_exprs, xml_context)
615 
616  # Appendix C.3.6: Equation dimension checking.
617  if not self._cml_validation_errors and (not assume_valid or check_for_units_conversions):
618  self._check_dimensional_consistency(assignment_exprs,
619  xml_context,
620  warn_on_units_errors,
621  check_for_units_conversions)
622 
623  # Warn if unknown namespaces are used, just in case.
624  unknown_nss = set(self.rootNode.xml_namespaces.keys()).difference(set(NSS.values()))
625  if unknown_nss:
626  self.validation_warning(u'Unrecognised namespaces used:\n ' +
627  u'\n '.join(list(unknown_nss)))
628 
629  # Return validation result
630  return not self._cml_validation_errors and \
631  (not invalid_if_warnings or not self._cml_validation_warnings)
def CellMLToNektar.pycml.cellml_model.validation_error (   self,
  errmsg,
  level = logging.ERROR 
)
Log a validation error message.

Message should be a unicode string.

Definition at line 512 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model._build_units_dictionary(), CellMLToNektar.pycml.cellml_component._build_units_dictionary(), CellMLToNektar.pycml.cellml_model._check_connection_units(), CellMLToNektar.pycml.cellml_model._check_unit_cycles(), CellMLToNektar.pycml.cellml_model._check_variable_mappings(), CellMLToNektar.pycml.cellml_model._check_variable_units_exist(), CellMLToNektar.pycml.cellml_model._report_exception(), CellMLToNektar.pycml.cellml_model._validate_component_hierarchies(), CellMLToNektar.pycml.cellml_model._validate_connection(), CellMLToNektar.pycml.cellml_model.build_component_hierarchy(), CellMLToNektar.pycml.cellml_model.build_name_dictionaries(), and CellMLToNektar.pycml.cellml_model.topological_sort().

513  def validation_error(self, errmsg, level=logging.ERROR):
514  """Log a validation error message.
515 
516  Message should be a unicode string.
517  """
518  self._cml_validation_errors.append(errmsg)
logging.getLogger('validator').log(level, errmsg.encode('UTF-8'))
def CellMLToNektar.pycml.cellml_model.validation_warning (   self,
  errmsg,
  level = logging.WARNING 
)
Log a validation warning message.

Message should be a unicode string.

Definition at line 522 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model._check_cellml_subset(), CellMLToNektar.pycml.cellml_model._check_connection_units(), CellMLToNektar.pycml.cellml_model._report_exception(), and CellMLToNektar.pycml.cellml_model.validate().

523  def validation_warning(self, errmsg, level=logging.WARNING):
524  """Log a validation warning message.
525 
526  Message should be a unicode string.
527  """
528  self._cml_validation_warnings.append(errmsg)
logging.getLogger('validator').log(level, errmsg.encode('UTF-8'))
def CellMLToNektar.pycml.cellml_model.xml (   self,
  stream = None,
  writer = None,
  wargs 
)
Serialize back to XML.
If stream is given, output to stream.
If writer is given, use it directly.
If neither a stream nor a writer is given, return the output text
as a Python string (not Unicode) encoded as UTF-8.

This overrides Amara's method, in order to force declaration of
various namespaces with prefixes on this element, and to ensure
the RDF annotations are up-to-date.

See base class docs for possible keyword arguments.

Definition at line 1457 of file pycml.py.

References CellMLToNektar.pycml.element_base.xml_attributes.

1458  def xml(self, stream=None, writer=None, **wargs):
1459  """Serialize back to XML.
1460  If stream is given, output to stream.
1461  If writer is given, use it directly.
1462  If neither a stream nor a writer is given, return the output text
1463  as a Python string (not Unicode) encoded as UTF-8.
1464 
1465  This overrides Amara's method, in order to force declaration of
1466  various namespaces with prefixes on this element, and to ensure
1467  the RDF annotations are up-to-date.
1468 
1469  See base class docs for possible keyword arguments.
1470  """
1471  extra_namespaces = {u'cellml': NSS[u'cml'],
1472  u'pe': NSS[u'pe'],
1473  u'lut': NSS[u'lut']}
1474 
1475  # Update RDF block if necessary
1476  cellml_metadata.update_serialized_rdf(self)
1477 
1478  temp_stream = None
1479  close_document = 0
1480  if not writer:
1481  #Change the default to *not* generating an XML decl
1482  if not wargs.get('omitXmlDeclaration'):
1483  wargs['omitXmlDeclaration'] = u'yes'
1484  if stream:
1485  writer = amara.bindery.create_writer(stream, wargs)
1486  else:
1487  temp_stream = StringIO()
1488  writer = amara.bindery.create_writer(temp_stream, wargs)
1489 
1490  writer.startDocument()
1491  close_document = 1
1492  writer.startElement(self.nodeName, self.namespaceURI,
1493  extraNss=extra_namespaces)
1494  if hasattr(self, 'xml_attributes'):
1495  for apyname in self.xml_attributes:
1496  aqname, ans = self.xml_attributes[apyname]
1497  val = self.__dict__[apyname]
1498  writer.attribute(aqname, val, ans)
1499  for child in self.xml_children:
1500  if isinstance(child, unicode):
1501  writer.text(child)
1502  else:
1503  child.xml(writer=writer)
1504  writer.endElement(self.nodeName, self.namespaceURI)
1505  if close_document:
1506  writer.endDocument()
1507  return temp_stream and temp_stream.getvalue()
1508 

Member Data Documentation

CellMLToNektar.pycml.cellml_model._cml_assignments
private

Definition at line 393 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model.clear_assignments(), and CellMLToNektar.pycml.cellml_model.get_assignments().

CellMLToNektar.pycml.cellml_model._cml_components
private

Definition at line 388 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model._add_component(), CellMLToNektar.pycml.cellml_model._del_component(), CellMLToNektar.pycml.cellml_model.build_name_dictionaries(), and CellMLToNektar.pycml.cellml_model.get_component_by_name().

CellMLToNektar.pycml.cellml_model._cml_conversions_needed
private

Definition at line 1156 of file pycml.py.

CellMLToNektar.pycml.cellml_model._cml_sorting_variables_stack
private

Definition at line 902 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model.topological_sort().

CellMLToNektar.pycml.cellml_model._cml_standard_units
private

Definition at line 390 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model._build_units_dictionary(), and CellMLToNektar.pycml.cellml_model.get_standard_units().

CellMLToNektar.pycml.cellml_model._cml_units
private

Definition at line 389 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model._build_units_dictionary(), CellMLToNektar.pycml.cellml_component._build_units_dictionary(), CellMLToNektar.pycml.mathml_apply._set_in_units(), CellMLToNektar.pycml.mathml_piecewise._set_in_units(), CellMLToNektar.pycml.cellml_model.add_units(), CellMLToNektar.pycml.cellml_component.add_units(), CellMLToNektar.pycml.cellml_model.get_all_units(), CellMLToNektar.pycml.cellml_component.get_all_units(), CellMLToNektar.pycml.mathml_ci.get_units(), CellMLToNektar.pycml.mathml_apply.get_units(), CellMLToNektar.pycml.mathml_piecewise.get_units(), CellMLToNektar.pycml.cellml_model.get_units_by_name(), and CellMLToNektar.pycml.cellml_component.get_units_by_name().

CellMLToNektar.pycml.cellml_model._cml_units_map
private

Definition at line 391 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model._add_units_obj(), and CellMLToNektar.pycml.cellml_model._is_new_units_obj().

CellMLToNektar.pycml.cellml_model._cml_validation_errors
private

Definition at line 385 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model.build_component_hierarchy(), CellMLToNektar.pycml.cellml_model.get_validation_errors(), and CellMLToNektar.pycml.cellml_model.validate().

CellMLToNektar.pycml.cellml_model._cml_validation_warnings
private

Definition at line 386 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model.get_validation_warnings(), and CellMLToNektar.pycml.cellml_model.validate().

CellMLToNektar.pycml.cellml_model._cml_variables
private

Definition at line 387 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model._add_variable(), CellMLToNektar.pycml.cellml_model._del_variable(), CellMLToNektar.pycml.cellml_model.build_name_dictionaries(), and CellMLToNektar.pycml.cellml_model.get_variable_by_name().

string CellMLToNektar.pycml.cellml_model.apply_xpath_1 = u'/m:apply[m:eq]'
static

Definition at line 915 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model.search_for_assignments().

string CellMLToNektar.pycml.cellml_model.apply_xpath_2 = u'/m:semantics/m:apply[m:eq]'
static

Definition at line 916 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model.search_for_assignments().

string CellMLToNektar.pycml.cellml_model.math_xpath_1 = u'cml:component/m:math'
static

Definition at line 913 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model.search_for_assignments(), and CellMLToNektar.pycml.cellml_model.validate().

string CellMLToNektar.pycml.cellml_model.math_xpath_2 = u'cml:component/cml:reaction/cml:variable_ref/cml:role/m:math'
static

Definition at line 914 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model.search_for_assignments(), and CellMLToNektar.pycml.cellml_model.validate().