From 1608e63287375d7b9b2baa525fe104643bd6d802 Mon Sep 17 00:00:00 2001 From: Michael Sevestre Date: Wed, 15 Feb 2023 08:47:07 -0500 Subject: [PATCH] Fixes #693 plug the function into model construction --- .../Domain/ObjectPathKeywords.cs | 4 +- .../Domain/Services/ModelConstructor.cs | 3 + .../ModelHelperForSpecs.cs | 119 ++++++++++-------- 3 files changed, 74 insertions(+), 52 deletions(-) diff --git a/src/OSPSuite.Core/Domain/ObjectPathKeywords.cs b/src/OSPSuite.Core/Domain/ObjectPathKeywords.cs index ad4f19ef2..931d157bb 100644 --- a/src/OSPSuite.Core/Domain/ObjectPathKeywords.cs +++ b/src/OSPSuite.Core/Domain/ObjectPathKeywords.cs @@ -8,7 +8,7 @@ namespace OSPSuite.Core.Domain public static class ObjectPathKeywords { //list of all keywords defined - private static readonly IList _allKeywords = new List(); + private static readonly List _allKeywords = new List(); /// /// String representing a reference to local Molecule @@ -73,6 +73,6 @@ private static string addKeyword(string keyword) return keyword; } - public static IEnumerable All => _allKeywords; + public static IReadOnlyList All => _allKeywords; } } \ No newline at end of file diff --git a/src/OSPSuite.Core/Domain/Services/ModelConstructor.cs b/src/OSPSuite.Core/Domain/Services/ModelConstructor.cs index b94819afd..5ea008c4e 100644 --- a/src/OSPSuite.Core/Domain/Services/ModelConstructor.cs +++ b/src/OSPSuite.Core/Domain/Services/ModelConstructor.cs @@ -90,6 +90,9 @@ public CreationResult CreateModelFrom(IBuildConfiguration buildConfiguration, st //replace all keywords define in the model structure once all build processes have been executed _keywordReplacerTask.ReplaceIn(model.Root); + //This needs to be done before we validate the model to ensure that all references can be found + _formulaTask.ExpandNeighborhoodReferencesIn(model); + creationResult.Add(validateModel(model, buildConfiguration)); if (creationResult.State == ValidationState.Invalid) diff --git a/tests/OSPSuite.HelpersForTests/ModelHelperForSpecs.cs b/tests/OSPSuite.HelpersForTests/ModelHelperForSpecs.cs index 56eec80a2..ab10cb273 100644 --- a/tests/OSPSuite.HelpersForTests/ModelHelperForSpecs.cs +++ b/tests/OSPSuite.HelpersForTests/ModelHelperForSpecs.cs @@ -1,13 +1,15 @@ using System; using System.Collections.Generic; using System.Linq; -using OSPSuite.Utility.Extensions; using OSPSuite.Core.Domain; using OSPSuite.Core.Domain.Builder; using OSPSuite.Core.Domain.Descriptors; using OSPSuite.Core.Domain.Formulas; using OSPSuite.Core.Domain.Services; using OSPSuite.Core.Domain.UnitSystem; +using OSPSuite.Utility.Extensions; +using static OSPSuite.Core.Domain.ObjectPath; +using static OSPSuite.Core.Domain.ObjectPathKeywords; namespace OSPSuite.Helpers { @@ -103,9 +105,9 @@ private IEnumerable allCalculationMethods() private IEventGroupBuildingBlock getEventGroups() { - var eventGroupBuiderCollection = _objectBaseFactory.Create(); - eventGroupBuiderCollection.Add(createBolusApplication(eventGroupBuiderCollection.FormulaCache)); - return eventGroupBuiderCollection; + var eventGroupBuilderCollection = _objectBaseFactory.Create(); + eventGroupBuilderCollection.Add(createBolusApplication(eventGroupBuilderCollection.FormulaCache)); + return eventGroupBuilderCollection; } private IEventGroupBuilder createBolusApplication(IFormulaCache cache) @@ -158,8 +160,8 @@ private void setParameterStartValues(IParameterStartValuesBuildingBlock paramete var moleculeAPath = _objectPathFactory.CreateObjectPathFrom(ConstantsForSpecs.Organism, ConstantsForSpecs.Lung, ConstantsForSpecs.Plasma, "D"); moleculeAPath.Add("RelExpNorm"); var formula = _objectBaseFactory.Create().WithFormulaString("RelExp + RelExpGlobal").WithName("RelExpNormD"); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.MOLECULE, "RelExpGlobal")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, "RelExp").WithAlias("RelExp")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(MOLECULE, "RelExpGlobal")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(PARENT_CONTAINER, "RelExp").WithAlias("RelExp")); parameterStartValues.AddFormula(formula); parameterStartValues[moleculeAPath].Formula = formula; @@ -435,7 +437,7 @@ private IMoleculeBuilder createMoleculeD(IFormulaCache formulaCache) var relExpGlobal = newConstantParameter("RelExpGlobal", 0).WithMode(ParameterBuildMode.Global); IFormula moleculeReferenceFormula = _objectBaseFactory.Create().WithFormulaString("RelExpGlobal"); formulaCache.Add(moleculeReferenceFormula); - moleculeReferenceFormula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.MOLECULE, "RelExpGlobal").WithAlias("RelExpGlobal")); + moleculeReferenceFormula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(MOLECULE, "RelExpGlobal").WithAlias("RelExpGlobal")); var relExpLocalFromGlobal = _objectBaseFactory.Create() .WithName("RelExpLocal") @@ -455,7 +457,7 @@ private IMoleculeBuilder createMoleculeE(IFormulaCache formulaCache) moleculeE.IsFloating = false; moleculeE.AddParameter(newConstantParameter("RelExp", 0).WithMode(ParameterBuildMode.Local)); - + //create a couple of NaN Parameters. Only a few should be created in the simulation moleculeE.AddParameter(newConstantParameter("NaNParam", double.NaN).WithMode(ParameterBuildMode.Local)); moleculeE.AddParameter(newConstantParameter("OtherNaNParam", double.NaN).WithMode(ParameterBuildMode.Local)); @@ -515,7 +517,7 @@ private IFormula B_StartF(IFormulaCache formulaCache) formula = _objectBaseFactory.Create().WithFormulaString("A/2").WithName("B_StartF") .WithDimension(amountDimension); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, "A").WithAlias("A")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(PARENT_CONTAINER, "A").WithAlias("A")); //Add reference to global parameters in reaction formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom("R1", "k2").WithAlias("k2")); @@ -534,7 +536,7 @@ private IFormula enzymeStartFormula(IFormulaCache formulaCache) .WithName("EnzymeStartFormula") .WithFormulaString("RelExp * ProteinContent"); formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom("RelExp")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.MOLECULE, "ProteinContent")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(MOLECULE, "ProteinContent")); formulaCache.Add(formula); return formula; } @@ -549,9 +551,9 @@ private IFormula R1Formula(IFormulaCache formulaCache) formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom("k1").WithAlias("k1")); formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom("R1", "k2")); formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ConstantsForSpecs.Organism, "fu").WithAlias("fu")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, "A").WithAlias("A")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, "B").WithAlias("B")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, "C").WithAlias("C")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(PARENT_CONTAINER, "A").WithAlias("A")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(PARENT_CONTAINER, "B").WithAlias("B")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(PARENT_CONTAINER, "C").WithAlias("C")); formulaCache.Add(formula); @@ -579,10 +581,10 @@ private IFormula MM1FormulaFrom(IFormulaCache formulaCache) formula = _objectBaseFactory.Create().WithFormulaString("VmaxAbs*RelExp*C/(Km+C)").WithName("MM1"); formula.AddObjectPath( - _objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.NEIGHBORHOOD, ObjectPathKeywords.MOLECULE, ObjectPathKeywords.REALIZATION, "VmaxAbs").WithAlias("VmaxAbs")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.NEIGHBORHOOD, ObjectPathKeywords.MOLECULE, ObjectPathKeywords.REALIZATION, "Km").WithAlias("Km")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.SOURCE, ObjectPathKeywords.MOLECULE, "C").WithAlias("C")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.SOURCE, ObjectPathKeywords.TRANSPORTER, "RelExp").WithAlias("RelExp")); + _objectPathFactory.CreateFormulaUsablePathFrom(NEIGHBORHOOD, MOLECULE, REALIZATION, "VmaxAbs").WithAlias("VmaxAbs")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(NEIGHBORHOOD, MOLECULE, REALIZATION, "Km").WithAlias("Km")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(SOURCE, MOLECULE, "C").WithAlias("C")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(SOURCE, TRANSPORTER, "RelExp").WithAlias("RelExp")); formulaCache.Add(formula); @@ -597,8 +599,8 @@ private IFormula MM2FormulaFrom(IFormulaCache formulaCache) formula = _objectBaseFactory.Create().WithFormulaString("VMaxAbs*C/(1+C)").WithName("MM2"); formula.AddObjectPath( - _objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.NEIGHBORHOOD, ObjectPathKeywords.MOLECULE, ObjectPathKeywords.REALIZATION, "VmaxAbs").WithAlias("VMaxAbs")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.SOURCE, ObjectPathKeywords.MOLECULE, "C").WithAlias("C")); + _objectPathFactory.CreateFormulaUsablePathFrom(NEIGHBORHOOD, MOLECULE, REALIZATION, "VmaxAbs").WithAlias("VMaxAbs")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(SOURCE, MOLECULE, "C").WithAlias("C")); formulaCache.Add(formula); @@ -612,8 +614,8 @@ private IFormula ConcentrationFormulaFrom(IFormulaCache formulaCache) return formula; formula = _objectBaseFactory.Create().WithFormulaString("M/V").WithName("ConcFormula"); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER).WithAlias("M")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, ObjectPath.PARENT_CONTAINER, ConstantsForSpecs.Volume).WithAlias("V")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(PARENT_CONTAINER).WithAlias("M")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(PARENT_CONTAINER, PARENT_CONTAINER, ConstantsForSpecs.Volume).WithAlias("V")); formulaCache.Add(formula); @@ -820,6 +822,22 @@ private ISpatialStructure getSpatialStructure() art.Add(newConstantParameter(ConstantsForSpecs.Q, 2)); organism.Add(art); + var parameterReferencingNeighborhood = newConstantParameter("RefParam", 10); + parameterReferencingNeighborhood.Formula = new ExplicitFormula("K *10").WithName("FormulaReferencingNBH"); + //referencing parameter K between art_pls and bone_pls + + var objectPath = _objectPathFactory.CreateFormulaUsablePathFrom( + PARENT_CONTAINER, + NBH, + PARENT_CONTAINER, PARENT_CONTAINER, PARENT_CONTAINER, ConstantsForSpecs.Bone, ConstantsForSpecs.Plasma, + NBH, "K"); + + objectPath.Alias = "K"; + parameterReferencingNeighborhood.Formula.AddObjectPath(objectPath); + artPlasma.Add(parameterReferencingNeighborhood); + spatialStructure.AddFormula(parameterReferencingNeighborhood.Formula); + + //LUNG var lung = CreateContainerWithName(ConstantsForSpecs.Lung) .WithMode(ContainerMode.Logical); @@ -850,6 +868,7 @@ private ISpatialStructure getSpatialStructure() bonePlasma.AddTag(new Tag(bone.Name)); bone.Add(bonePlasma); + var boneCell = CreateContainerWithName(ConstantsForSpecs.Cell).WithMode(ContainerMode.Physical); boneCell.Add(newConstantParameter(ConstantsForSpecs.Volume, 1)); boneCell.Add(newConstantParameter(ConstantsForSpecs.pH, 7)); @@ -883,6 +902,8 @@ private ISpatialStructure getSpatialStructure() spatialStructure.AddTopContainer(organism); var neighborhood1 = _neighborhoodFactory.CreateBetween(artPlasma, bonePlasma).WithName("art_pls_to_bon_pls"); + //this is a constant parmaeter that will be referenced from arterial plasma compartment + neighborhood1.AddParameter(newConstantParameter("K", 10)); spatialStructure.AddNeighborhood(neighborhood1); var neighborhood2 = _neighborhoodFactory.CreateBetween(lngPlasma, artPlasma).WithName("lng_pls_to_art_pls"); spatialStructure.AddNeighborhood(neighborhood2); @@ -927,8 +948,8 @@ private IFormula Fabs(IFormulaCache formulaCache) { var formula = _objectBaseFactory.Create() .WithFormulaString("SumProcessRateLung + SumProcessRateBone").WithName("FabsFormula"); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(Constants.NEIGHBORHOODS, "lng_pls_to_lng_cell", ObjectPathKeywords.MOLECULE, ConstantsForSpecs.SumProcessRate).WithAlias("SumProcessRateLung")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(Constants.NEIGHBORHOODS, "bon_pls_to_bon_cell", ObjectPathKeywords.MOLECULE, ConstantsForSpecs.SumProcessRate).WithAlias("SumProcessRateBone")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(Constants.NEIGHBORHOODS, "lng_pls_to_lng_cell", MOLECULE, ConstantsForSpecs.SumProcessRate).WithAlias("SumProcessRateLung")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(Constants.NEIGHBORHOODS, "bon_pls_to_bon_cell", MOLECULE, ConstantsForSpecs.SumProcessRate).WithAlias("SumProcessRateBone")); formulaCache.Add(formula); return formula; } @@ -960,7 +981,7 @@ private IFormula SumFormula(IFormulaCache formulaCache) var dynamicFormula = _objectBaseFactory.Create().WithName("SumFormula"); - dynamicFormula.Criteria = Create.Criteria(x => x.With(Constants.Parameters.PROCESS_RATE).And.With(ObjectPathKeywords.NEIGHBORHOOD).And.With(ObjectPathKeywords.MOLECULE)); + dynamicFormula.Criteria = Create.Criteria(x => x.With(Constants.Parameters.PROCESS_RATE).And.With(NEIGHBORHOOD).And.With(MOLECULE)); formulaCache.Add(dynamicFormula); return dynamicFormula; } @@ -980,8 +1001,8 @@ private IFormula Convection(IFormulaCache formulaCache) return formula; formula = _objectBaseFactory.Create().WithFormulaString("Q*C").WithName("Convection"); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.SOURCE, ObjectPath.PARENT_CONTAINER, "Q").WithAlias("Q")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.SOURCE, ObjectPathKeywords.MOLECULE, "C").WithAlias("C")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(SOURCE, PARENT_CONTAINER, "Q").WithAlias("Q")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(SOURCE, MOLECULE, "C").WithAlias("C")); formulaCache.Add(formula); @@ -996,12 +1017,12 @@ private IFormula Diffusion(IFormulaCache formulaCache) formula = _objectBaseFactory.Create().WithFormulaString("fu*P*SA*(C1-C2/K)*logMA").WithName("Diffusion"); formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ConstantsForSpecs.Organism, "fu").WithAlias("fu")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.SOURCE, ObjectPathKeywords.MOLECULE, "C").WithAlias("C1")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.TARGET, ObjectPathKeywords.MOLECULE, "C").WithAlias("C2")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.NEIGHBORHOOD, ObjectPathKeywords.MOLECULE, "K").WithAlias("K")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.MOLECULE, "logMA").WithAlias("logMA")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.SOURCE, ObjectPath.PARENT_CONTAINER, "P").WithAlias("P")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.NEIGHBORHOOD, "SA").WithAlias("SA")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(SOURCE, MOLECULE, "C").WithAlias("C1")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(TARGET, MOLECULE, "C").WithAlias("C2")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(NEIGHBORHOOD, MOLECULE, "K").WithAlias("K")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(MOLECULE, "logMA").WithAlias("logMA")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(SOURCE, PARENT_CONTAINER, "P").WithAlias("P")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(NEIGHBORHOOD, "SA").WithAlias("SA")); formulaCache.Add(formula); @@ -1011,7 +1032,7 @@ private IFormula Diffusion(IFormulaCache formulaCache) private IFormula GlobalMoleculeDepParamFormula_1(IFormulaCache formulaCache) { var formula = _objectBaseFactory.Create().WithFormulaString("MW").WithName("GlobalMoleculeDepParamFormula_1"); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.MOLECULE, "MW").WithAlias("MW")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(MOLECULE, "MW").WithAlias("MW")); formulaCache.Add(formula); @@ -1032,10 +1053,10 @@ private IFormula BlackBoxPartitionCoeffFormula(IFormulaCache formulaCache) private IFormula PartitionCoeff_1() { var formula = _objectBaseFactory.Create().WithFormulaString("pH1/pH2*logMA*HelpMe").WithName("PartitionCoeff_1"); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.MOLECULE, "logMA").WithAlias("logMA")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.FIRST_NEIGHBOR, "pH").WithAlias("pH1")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.FIRST_NEIGHBOR, ObjectPathKeywords.MOLECULE, "HelpMe").WithAlias("HelpMe")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.SECOND_NEIGHBOR, "pH").WithAlias("pH2")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(MOLECULE, "logMA").WithAlias("logMA")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(FIRST_NEIGHBOR, "pH").WithAlias("pH1")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(FIRST_NEIGHBOR, MOLECULE, "HelpMe").WithAlias("HelpMe")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(SECOND_NEIGHBOR, "pH").WithAlias("pH2")); return formula; } @@ -1043,9 +1064,9 @@ private IFormula PartitionCoeff_1() private IFormula PartitionCoeff_2() { var formula = _objectBaseFactory.Create().WithFormulaString("pH1/pH2*logMA").WithName("PartitionCoeff_2"); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.MOLECULE, "logMA").WithAlias("logMA")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.FIRST_NEIGHBOR, "pH").WithAlias("pH1")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPathKeywords.SECOND_NEIGHBOR, "pH").WithAlias("pH2")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(MOLECULE, "logMA").WithAlias("logMA")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(FIRST_NEIGHBOR, "pH").WithAlias("pH1")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(SECOND_NEIGHBOR, "pH").WithAlias("pH2")); return formula; } @@ -1057,7 +1078,7 @@ private IFormula AmountObs(IFormulaCache formulaCache) return formula; formula = _objectBaseFactory.Create().WithFormulaString("M/2").WithName("AmountObs"); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER).WithAlias("M")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(PARENT_CONTAINER).WithAlias("M")); formula.Dimension = _dimensionFactory.Dimension(Constants.Dimension.MOLAR_AMOUNT); formulaCache.Add(formula); return formula; @@ -1070,7 +1091,7 @@ private IFormula FractionObs(IFormulaCache formulaCache) return formula; formula = _objectBaseFactory.Create().WithFormulaString("M/4").WithName("FractionObs"); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER).WithAlias("M")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(PARENT_CONTAINER).WithAlias("M")); formula.Dimension = _dimensionFactory.Dimension(Constants.Dimension.FRACTION); formulaCache.Add(formula); return formula; @@ -1083,15 +1104,14 @@ private IFormula ContainerObs(IFormulaCache formulaCache) return formula; formula = _objectBaseFactory.Create().WithFormulaString("M1+M2").WithName("ContainerObs"); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ConstantsForSpecs.Organism, ConstantsForSpecs.Lung, ConstantsForSpecs.Cell, ObjectPathKeywords.MOLECULE).WithAlias("M1")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ConstantsForSpecs.Organism, ConstantsForSpecs.Bone, ConstantsForSpecs.Cell, ObjectPathKeywords.MOLECULE).WithAlias("M2")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ConstantsForSpecs.Organism, ConstantsForSpecs.Lung, ConstantsForSpecs.Cell, MOLECULE).WithAlias("M1")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ConstantsForSpecs.Organism, ConstantsForSpecs.Bone, ConstantsForSpecs.Cell, MOLECULE).WithAlias("M2")); formula.Dimension = _dimensionFactory.Dimension(Constants.Dimension.MOLAR_AMOUNT); formulaCache.Add(formula); return formula; } - private IFormula InContainerObs(IFormulaCache formulaCache) { var formula = formulaCache.FirstOrDefault(x => string.Equals(x.Name, "InContainerObs")); @@ -1099,8 +1119,8 @@ private IFormula InContainerObs(IFormulaCache formulaCache) return formula; formula = _objectBaseFactory.Create().WithFormulaString("M1+M2").WithName("InContainerObs"); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ConstantsForSpecs.Organism, ConstantsForSpecs.Lung, ConstantsForSpecs.Cell, ObjectPathKeywords.MOLECULE).WithAlias("M1")); - formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ConstantsForSpecs.Organism, ConstantsForSpecs.Bone, ConstantsForSpecs.Cell, ObjectPathKeywords.MOLECULE).WithAlias("M2")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ConstantsForSpecs.Organism, ConstantsForSpecs.Lung, ConstantsForSpecs.Cell, MOLECULE).WithAlias("M1")); + formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ConstantsForSpecs.Organism, ConstantsForSpecs.Bone, ConstantsForSpecs.Cell, MOLECULE).WithAlias("M2")); formula.Dimension = _dimensionFactory.Dimension(Constants.Dimension.MOLAR_AMOUNT); formulaCache.Add(formula); @@ -1189,7 +1209,7 @@ public T CreateObjectBaseFrom(T sourceObject) return default(T); } - private T newBuildingBlockWithId(T sourceObject, string id) where T: BuildingBlock + private T newBuildingBlockWithId(T sourceObject, string id) where T : BuildingBlock { BuildingBlock bb = default(T); if (sourceObject.IsAnImplementationOf()) @@ -1215,14 +1235,13 @@ private T newBuildingBlockWithId(T sourceObject, string id) where T: Building if (sourceObject.IsAnImplementationOf()) bb = new ParameterStartValuesBuildingBlock(); - + if (bb != null) return bb.WithId(id).DowncastTo(); return null; } - public T Create(string id) where T : class, IObjectBase { throw new NotSupportedException();