Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

601 fixing nightly build #606

Merged
merged 17 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/MoBi.Engine/ISBMLInitializableImporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace MoBi.Engine
{
public interface ISBMLInitializableImporter
{
void Initialize();
}
}
7 changes: 6 additions & 1 deletion src/MoBi.Engine/Sbml/FunctionDefinitionImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IFunctionDefinitionImporter : ISBMLImporter
List<FunctionDefinition> FunctionDefinitions { get; }
}

public class FunctionDefinitionImporter : SBMLImporter, IFunctionDefinitionImporter
public class FunctionDefinitionImporter : SBMLImporter, ISBMLInitializableImporter, IFunctionDefinitionImporter
{
private readonly List<FunctionDefinition> _functionDefinitions;
public List<FunctionDefinition> FunctionDefinitions { get => _functionDefinitions; }
Expand All @@ -32,5 +32,10 @@ protected override void Import(Model model)
public override void AddToProject()
{
}

public void Initialize()
{
_functionDefinitions.Clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this class FunctionDefinitionImporter singleton? Why isn't it done in constructor?
We have a IStartable interface also... maybe that should be enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a singleton yes. Then if you load a file and load a second file, it will remember all the units and functions defined so you need to clearly trigger "this is a new file" and reset to a clean state. This is why for example tests were failing.

}
}
}
1 change: 1 addition & 0 deletions src/MoBi.Engine/Sbml/SBMLTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public IMoBiCommand ImportModelFromSbml(string filename, IMoBiProject project)
project.Name = getProjectName(model);

reportConstraints(project, model);
_importerRepository.AllFor(model).OfType<ISBMLInitializableImporter>().Each(impoter => impoter.Initialize());

foreach (var importer in _importerRepository.AllFor(model))
{
Expand Down
9 changes: 8 additions & 1 deletion src/MoBi.Engine/Sbml/UnitDefinitionImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IUnitDefinitionImporter : ISBMLImporter
double[] ToMobiBaseUnit(string unit, IEnumerable<double> value);
}

public class UnitDefinitionImporter : SBMLImporter, IUnitDefinitionImporter
public class UnitDefinitionImporter : SBMLImporter, ISBMLInitializableImporter, IUnitDefinitionImporter
{
private readonly IMoBiDimensionFactory _moBiDimensionFactory;
private readonly IDictionary<int, Unit> _baseUnitsDictionary;
Expand Down Expand Up @@ -98,6 +98,7 @@ public IDimension ConvertUnit(UnitDefinition unitDefinition)
if (dimension != Constants.Dimension.NO_DIMENSION)
{
_sbmlInformation.MobiDimension[sbmlUnit] = dimension;
_unitConvertionDictionary.Add(sbmlUnit, new UnitConvertionInfo() { Dimension = dimension, Unit = dimension.DefaultUnit, Rate = 1 });
return dimension;
}

Expand All @@ -114,6 +115,7 @@ public IDimension ConvertUnit(UnitDefinition unitDefinition)
return unitDimension;
}
}
_unitConvertionDictionary.Add(sbmlUnit, new UnitConvertionInfo() { Dimension = dimension, Unit = dimension.DefaultUnit, Rate = 1 });
return dimension;
}

Expand All @@ -136,6 +138,11 @@ public double[] ToMobiBaseUnit(string unit, IEnumerable<double> value)
var convertionData = _unitConvertionDictionary[unit];
return convertionData.Dimension.UnitValuesToBaseUnitValues(convertionData.Unit, value.Select(v => v * convertionData.Rate));
}

public void Initialize()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know about IStartable... already committed.

{
_unitConvertionDictionary.Clear();
}
}

}
2 changes: 1 addition & 1 deletion tests/MoBi.Tests/Core/SBML/Testfiles/UnitTestFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<compartment metaid="default" id="default" size="1" units="volume"/>
</listOfCompartments>
<listOfSpecies>
<species metaid="s1" id="s1" name="s1" compartment="default" initialAmount="5" substanceUnits="mole" hasOnlySubstanceUnits="true" charge="0">
<species metaid="s1" id="s1" name="s1" compartment="default" initialAmount="5" substanceUnits="substance" hasOnlySubstanceUnits="true" charge="0">
<annotation>
<celldesigner:extension>
<celldesigner:positionToCompartment>inside</celldesigner:positionToCompartment>
Expand Down
2 changes: 1 addition & 1 deletion tests/MoBi.Tests/Core/SBML/UnitImporterSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace MoBi.Core.SBML
{
public abstract class UnitImporterSpecs : ContextForSBMLIntegration<UnitDefinitionImporter>
public abstract class UnitImporterSpecs : ContextForSBMLIntegration<IUnitDefinitionImporter>
{
private Model _sbmlModel;

Expand Down
3 changes: 3 additions & 0 deletions tests/MoBi.Tests/MoBi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
<None Update="Core\SBML\Testfiles\Barros2021_RAJI.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Core\SBML\Testfiles\UnitTestFile.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>


Expand Down