Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Closes #14
  • Loading branch information
dweindl committed Sep 11, 2024
1 parent 9057a42 commit f5da3ad
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sbmlmath/csymbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

__all__ = ["CSymbol", "TimeSymbol"]

#: The `Avogadro constant <https://en.wikipedia.org/wiki/Avogadro_constant>`_
# as defined in SBML L3V2 section 3.4.6.
SBML_L3V2_AVOGADRO_VALUE = 6.02214179e23


class CSymbol(sp.Dummy):
"""
Expand All @@ -20,7 +24,8 @@ class CSymbol(sp.Dummy):
>>> CSymbol("avogadro", definition_url="http://www.sbml.org/sbml/symbols/avogadro")
<avogadro(http://www.sbml.org/sbml/symbols/avogadro)>
>>> float(CSymbol("avogadro", definition_url="http://www.sbml.org/sbml/symbols/avogadro"))
6.02214179e+23
See also https://www.w3.org/TR/MathML2/chapter4.html#contm.csymbol.
"""
Expand Down Expand Up @@ -69,6 +74,11 @@ def __hash__(self):
# expressions
return hash(self.definition_url)

def __float__(self):
if self.definition_url == "http://www.sbml.org/sbml/symbols/avogadro":
return SBML_L3V2_AVOGADRO_VALUE
return super().__float__()


class TimeSymbol(CSymbol):
"""The current internal simulation time.
Expand Down

0 comments on commit f5da3ad

Please sign in to comment.