sys-bio / tellurium

Python Environment for Modeling and Simulating Biological Systems
http://tellurium.analogmachine.org/
Apache License 2.0
109 stars 36 forks source link

"Unexpected '\'' " error from an antimony model #554

Closed freiburgermsu closed 2 years ago

freiburgermsu commented 2 years ago

Hello,

I constructed the following model in antimony

self.model = (f'''
  model pdipy_oxidation
    # kinetic expressions
    J1: -> fa; {k_2x}*fa
    J2: ps -> e_ps; {photosensitizer}
    J3: e_ps + mo => so + ps;  {so_conversion}*{k_so}*e_ps*mo
    J4: ps + so => b_ps ; {k_b_ps}*ps*so
    J5: so => mo; {k_rlx_so}*so
    J6: so + fa => o_fa + mo; {k_fa}*so*fa
    J7: {biofilm}

    # define concentrations
    ps = {ps}
    e_ps = 0
    b_ps = 0
    mo = {mo}
    so = 0
    o_fa = 0
    fa = {fa}
    o_eps = 0
    {eps}

    # calculate the oxidation proportion
    oxidation := o_fa / (o_fa + fa);

  end
''')    

for this code, however, I receive this error Exception: Antimony: Error in model string, line 4: syntax error, unexpected '\'', expecting ',' or '}' when I attempt to execute the model. The error seems to suggest that the fourth line contains an unexpected quotation mark, yet quotation marks are not contained anywhere in the model string. I employed the syntax workaround from this page, yet the error persists.

What is the cause of the error, and how can it be resolved?

I appreciate your support :) Andrew

matthiaskoenig commented 2 years ago

You have to apply your replacements to the {xxx} parts of the model with fstrings or format before trying to load it. antimony cannot interpret this model because it gets confused with what {eps} and other things mean. Most likely the { brackets break the model loading.

freiburgermsu commented 2 years ago

The model is currently composed as an f-string: f ''' \n ... ''''. Are you suggesting that I change to '''\n ...'''.format(...) to populate the values? The model works when this line J1: -> fa; {k_2x}*fa and the J# format are removed

ps -> e_ps; {photosensitizer}
e_ps + mo => so + ps;  {so_conversion}*{k_so}*e_ps*mo
ps + so => b_ps ; {k_b_ps}*ps*so
so => mo; {k_rlx_so}*so
so + fa => o_fa + mo; {k_fa}*so*fa
{biofilm}

then the model breaks when the J# format and this line J1: -> fa; {k_2x}*fa are included.

matthiaskoenig commented 2 years ago

You should show the string with the replacements which will allow to figure out the issue. With the {} it is unclear what you substituted in. I.e. can you provide the output of

model_str = f'''
  model pdipy_oxidation
    # kinetic expressions
    J1: -> fa; {k_2x}*fa
    J2: ps -> e_ps; {photosensitizer}
    J3: e_ps + mo => so + ps;  {so_conversion}*{k_so}*e_ps*mo
    J4: ps + so => b_ps ; {k_b_ps}*ps*so
    J5: so => mo; {k_rlx_so}*so
    J6: so + fa => o_fa + mo; {k_fa}*so*fa
    J7: {biofilm}

    # define concentrations
    ps = {ps}
    e_ps = 0
    b_ps = 0
    mo = {mo}
    so = 0
    o_fa = 0
    fa = {fa}
    o_eps = 0
    {eps}

    # calculate the oxidation proportion
    oxidation := o_fa / (o_fa + fa);

  end
'''
print(model_str)

So it is clear what the actual model looks like you try to sent to antimony.

freiburgermsu commented 2 years ago

@matthiaskoenig Thank you for the suggestion of printing the model! I was accidentally passing a dictionary instead of a float for one of the values. The model now executes.

Thank you :) Andrew

luciansmith commented 2 years ago

Glad you figured it out! Feel free to bug us about anything, even if it turns out to be something like this ;-)

freiburgermsu commented 2 years ago

Thank you @luciansmith! :)