Menu

#480 Comp flattening drops conversion_factors for assignment rules of the form "p1 = p2"

libSBML-5.18.0
open
None
2020-09-30
2020-06-29
No

Hi all,
some major bug in the flattening of comp models. If there are assignment rules of the form

p1 = p2

in a submodel, i.e. the ASTNodeTree is a simple node. And p2 is replaced with a conversion_factor the conversion factor is just dropped.
Minimal example showing the bug is attached. Workaround for now is to just create a more complex astnodetree which works

p1 = 1 dimensionless p2

In the example (SBML attached):
model1

compartments = [
    Compartment('Vbr', value=1000, unit="ml", constant=False, name='brain tissue', port=True),
]
rules = [
    AssignmentRule('Vtest1', 'Vbr', unit="ml"),
    AssignmentRule('Vtest2', '1 dimensionless * Vbr', unit="ml"),
]

model2

compartments = [
    Compartment('Vbrain', value=1, unit="l", constant=False, name='brain tissue', port=True),
]
parameters = [
    Parameter('conversion_l_per_ml', 0.001, 'l_per_ml', constant=True, name='volume conversion factor'),
]
externalModelDefinitions = [
    mcomp.ExternalModelDefinition(
        sid="model1", source=f"model1.xml", modelRef="model1"),
]
submodels = [
    mcomp.Submodel(sid="model1", modelRef="model1"),
]
replacedElements = [
    mcomp.ReplacedElement(sid=f"Vbrain_RE", metaId=f"Vbrain_RE", elementRef=f"Vbrain",
                          submodelRef="model1", portRef=f"Vbr{PORT_SUFFIX}", conversionFactor="conversion_l_per_ml"),
]

Flattened models is

    <listOfRules>
      <assignmentRule variable="model1__Vtest1">
        <math xmlns="http://www.w3.org/1998/Math/MathML">
          <ci> Vbrain </ci>
        </math>
      </assignmentRule>
      <assignmentRule variable="model1__Vtest2">
        <math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:sbml="http://www.sbml.org/sbml/level3/version1/core">
          <apply>
            <times/>
            <cn sbml:units="dimensionless" type="integer"> 1 </cn>
            <apply>
              <divide/>
              <ci> Vbrain </ci>
              <ci> conversion_l_per_ml </ci>
            </apply>
          </apply>
        </math>
      </assignmentRule>
    </listOfRules>

Assignment rule model1__Vtest1 misses the conversion factor, whereas it is correctly applied for model1__Vtest2.

Same happens probably for all math which is replaced and is a single ASTNodeTree. Also unit conversion is not complaining despite the model being not unit correct without the conversion factor.

Best Matthias

1 Attachments

Discussion

  • Matthias König

    Matthias König - 2020-09-27

    Hi all,
    could someone look at this bug.

    Should be very easy to fix (just a special case of handling the conversion factors).
    There should be a test case for this in the SBML test suite. This is a major bug giving incorrect numerical results for all models which have such a construct, i.e. direct assignment rule with conversion factor.
    @Lucian Have you seen this issue?

    Best Matthias

     
  • Lucian Smith

    Lucian Smith - 2020-09-28
    • assigned_to: Lucian Smith
    • Priority: -->
     
  • Lucian Smith

    Lucian Smith - 2020-09-30

    I found the problem and have submitted a fix. The situation you describe was indeed anticipated in the code, but it clearly was never tested: it checked whether the root ASTNode had the id of the element to be converted... but ASTNodes use 'name' instead. Sorry about that!

    https://github.com/sbmlteam/libsbml/pull/47

     

Log in to post a comment.