sbmlteam / libsbml

LibSBML is a native library for reading, writing and manipulating files and data streams containing the Systems Biology Markup Language (SBML). It offers language bindings for C, C++, C#, Java, JavaScript, MATLAB, Perl, PHP, Python, R and Ruby.
https://sbml.org/software/libsbml
Other
38 stars 28 forks source link

Unit validation is giving incorrect warnings #344

Closed fbergmann closed 9 months ago

fbergmann commented 10 months ago

The attached model model gives a validation warning because of an issue with the time unit:

Warning Line 155 Column 20: (SBML Validation Rule #10541) The units of the 'math' formula in a definition are expected to be the equivalent of substance per time. Reference: L2V4 Section 4.13.5 Expected units are mole (exponent = 1, multiplier = 1, scale = -9), second (exponent = -1, multiplier = 1, scale = -3) but the units returned by the expression in the (from the with id 'R1') are second (exponent = -1, multiplier = 0.0001, scale = 0), mole (exponent = 1, multiplier = 1, scale = -9).

Somehow the multiplier is used instead of the scale.

skeating commented 10 months ago

actually the reason why it gives the error is that the units are wrong:

`

       <minus/>

            <apply>

              <times/>

              <ci> kf_R1 </ci>  <!--one_over_nM_ms-->

              <ci> gaba </ci>   <!--substance-->

              <ci> GABABR </ci> <!--substance-->

            </apply>

            <apply>

              <times/>

              <ci> kr_R1 </ci>      <!--one_over_nM_ms-->

              <ci> gabaGABABR </ci> <!--substance-->

            </apply>

          </apply>

`

is trying to subtract a unit that is time x substance from a unit that is time x substance x substance

fbergmann commented 10 months ago

@skeating for me kr_R1 has the unit one_over_ms, so it is different. Since we have

      <unitDefinition id="one_over_ms">
        <listOfUnits>
          <unit kind="dimensionless" exponent="1" scale="0" multiplier="1"/>
          <unit kind="second" exponent="-1" scale="-3" multiplier="1"/>
        </listOfUnits>
      </unitDefinition>
      <unitDefinition id="one_over_nM_ms">
        <listOfUnits>
          <unit kind="dimensionless" exponent="1" scale="0" multiplier="1"/>
          <unit kind="mole" exponent="-1" scale="-9" multiplier="1"/>
          <unit kind="litre" exponent="1" scale="1" multiplier="1"/>
          <unit kind="second" exponent="-1" scale="-3" multiplier="1"/>
        </listOfUnits>
      </unitDefinition>

regardless, does this explain the issue for you?

skeating commented 10 months ago

you still cannot subtract something with units AB from something with units ABB

fbergmann commented 10 months ago

Stefan found the issue. since volume and liter are defined with a scale=0, then the litre component in the one_over_nM_ms unit should also have a scale=0. If that is corrected, then the validator does not complain anymore either.

skeating commented 9 months ago

yes it was trying to subtract two different units!!