Skip to content

Commit

Permalink
No more psv (#2567)
Browse files Browse the repository at this point in the history
* Fixes #2439 Misleading info in global POP PK Analysis if no parameter… (#2459)

* Fixes #2439 Misleading info in global POP PK Analysis if no parameters can be calculated

* PR feedback

* Fixes #2469 show hidden entities (#2488)

* Fixes buil failing (#2489)

* Fixes #2495 failing tests (#2499)

* Fixes #2485 observed added mobi (#2500)

* Fixes #2484 bug when exporting pop simulation (#2503)

* Fixes #2275 #2279 #2277 by updating OSPSuite.Core (#2506)

* Fixes #2405 mapping lost after configure (#2507)

* Fixes #2255 resetting concentration issue (#2512)

* Fixes #2255 resetting concentration issue

* Small update to stay symetrical

* Update MoleculeExpressionTask.cs

* Modify the comment to reflect population

Co-authored-by: Robert McIntosh <261477+rwmcintosh@users.noreply.github.com>

* update core (#2514)

* Prepare for v11_1 (#2515)

* Fixes #2516 Cannot run population simulations imported from pkml (#2517)

* Fixes #2516 Cannot run population simulations imported from pkml

* PR feedback

* Fixes #2518 11.1 Cannot show PK-Analysis in a population simulations … (#2520)

* Fixes #2518 11.1 Cannot show PK-Analysis in a population simulations imported from pkml

* PR feedback

* PR feedback

* Updated OSPSuite.Core and OSPSuite.BuildingBlockTemplates (#2524)

* Updated OSPSuite.Core and OSPSuite.BuildingBlockTemplates

* Updated OSPSuite.Core again

Co-authored-by: Yuri05 <Yuri05@github.com>

* Update documentation v11.1

* Fixes #2553 pksim changes molecule name (#2561)

* Fixes #2536 loading project from snapshot observed data (#2560)

* Fixes #2536 loading project from snapshot observed data

* Fixes #2536 loading project from snapshot observed data

* Fixes #2536 loading project from snapshot observed data

* Fixes #2558 project created with v10< do not export properly (#2559)

* Fixes #2563 notification weird column no image data (#2564)

* Try update core

* Update to latest core

* More work to make sure we can still load indiviudals

* Remove creation of PSV for simulation

* Fixes test project"

* Fixes test project"

* No more psv

---------

Co-authored-by: Robert McIntosh <261477+rwmcintosh@users.noreply.github.com>
Co-authored-by: Juri Solodenko <Yuri05@users.noreply.github.com>
Co-authored-by: Yuri05 <Yuri05@github.com>
  • Loading branch information
4 people committed Apr 3, 2023
1 parent 9dc551e commit eccb8b4
Show file tree
Hide file tree
Showing 58 changed files with 181 additions and 244 deletions.
Empty file added fileName
Empty file.
4 changes: 2 additions & 2 deletions src/PKSim.Assets.Images/PKSim.Assets.Images.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Assets" Version="12.0.127" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.127" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.135" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.135" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.Assets/PKSim.Assets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Assets" Version="12.0.127" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.127" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.135" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.135" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.BatchTool/PKSim.BatchTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Core" Version="12.0.127" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.127" />
<PackageReference Include="OSPSuite.Core" Version="12.0.135" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.135" />
<PackageReference Include="OSPSuite.DevExpress" Version="21.2.3" />
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.54" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.53" GeneratePathProperty="true" />
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.CLI.Core/PKSim.CLI.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Assets" Version="12.0.127" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.135" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.Core" Version="12.0.127" />
<PackageReference Include="OSPSuite.Core" Version="12.0.135" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/PKSim.CLI/PKSim.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
<PackageReference Include="OSPSuite.Core" Version="12.0.127" />
<PackageReference Include="OSPSuite.Presentation" Version="12.0.127" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.127" />
<PackageReference Include="OSPSuite.Core" Version="12.0.135" />
<PackageReference Include="OSPSuite.Presentation" Version="12.0.135" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.135" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.54" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.53" GeneratePathProperty="true" />
Expand Down
20 changes: 11 additions & 9 deletions src/PKSim.Core/Model/Extensions/EntityExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System.Linq;
using OSPSuite.Utility.Extensions;
using OSPSuite.Core.Domain;
using OSPSuite.Utility.Extensions;

namespace PKSim.Core.Model.Extensions
{
public static class EntityExtensions
{
public static bool IsInNeighborhood(this IEntity entity)
{
if (entity == null) return false;
if (entity.IsAnImplementationOf<INeighborhood>()) return true;
if (entity == null)
return false;

if (entity.IsAnImplementationOf<Neighborhood>())
return true;

return IsInNeighborhood(entity.ParentContainer);
}

Expand All @@ -27,7 +30,6 @@ public static bool IsInMucosa(this IEntity entity)
IsInMucosa(neighborhood.SecondNeighbor);
}


public static bool IsInLumen(this IEntity entity)
{
if (entity.HasAncestorNamed(CoreConstants.Organ.LUMEN))
Expand All @@ -45,7 +47,7 @@ public static bool IsInLumen(this IEntity entity)
public static bool IsInLiverZone(this IEntity entity)
{
var parentContainer = entity.ParentContainer;
if (parentContainer == null)
if (parentContainer == null)
return false;

return parentContainer.IsLiverZone() || IsInLiverZone(parentContainer);
Expand All @@ -56,11 +58,11 @@ public static bool IsInLumenOrMucosa(this IEntity entity)
return entity.IsInLumen() || entity.IsInMucosa();
}

public static INeighborhood NeighborhoodAncestor(this IEntity entity)
public static Neighborhood NeighborhoodAncestor(this IEntity entity)
{
if (entity == null) return null;
if (entity.IsAnImplementationOf<INeighborhood>())
return entity.DowncastTo<INeighborhood>();
if (entity.IsAnImplementationOf<Neighborhood>())
return entity.DowncastTo<Neighborhood>();

return NeighborhoodAncestor(entity.ParentContainer);
}
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.Core/Model/PKSimBuildingBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public override void AcceptVisitor(IVisitor visitor)

public virtual IEnumerable<T> GetChildren<T>() where T : class, IEntity => Root.GetChildren<T>();

public virtual IReadOnlyList<IContainer> GetNeighborsFrom(IReadOnlyList<INeighborhood> neighborhoods) => Root.GetNeighborsFrom(neighborhoods);
public virtual IReadOnlyList<IContainer> GetNeighborsFrom(IReadOnlyList<Neighborhood> neighborhoods) => Root.GetNeighborsFrom(neighborhoods);

public virtual IReadOnlyList<INeighborhood> GetNeighborhoods(IReadOnlyList<INeighborhood> neighborhoods) => Root.GetNeighborhoods(neighborhoods);
public virtual IReadOnlyList<Neighborhood> GetNeighborhoods(IReadOnlyList<Neighborhood> neighborhoods) => Root.GetNeighborhoods(neighborhoods);

public virtual IReadOnlyList<TContainer> GetAllContainersAndSelf<TContainer>() where TContainer : class, IContainer =>
Root.GetAllContainersAndSelf<TContainer>();
Expand Down
7 changes: 1 addition & 6 deletions src/PKSim.Core/Model/PKSimNeighborhood.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

namespace PKSim.Core.Model
{
public interface IPKSimNeighborhood : INeighborhood
{
bool Visible { get; set; }
}

public class PKSimNeighborhood : Neighborhood, IPKSimNeighborhood
public class PKSimNeighborhood : Neighborhood
{
public bool Visible { get; set; }
}
Expand Down
2 changes: 1 addition & 1 deletion src/PKSim.Core/Model/PKSimSpatialStructureFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void addNeighborhoods(ISpatialStructure spatialStructure, Organism organ
_neighborhoodFinalizer.SetNeighborsIn(organism, neighborhoodList);
}

private void addNeighborhood(INeighborhoodBuilder neighborhood, ISpatialStructure spatialStructure, OriginData originData, ModelProperties modelProperties, IFormulaCache formulaCache)
private void addNeighborhood(NeighborhoodBuilder neighborhood, ISpatialStructure spatialStructure, OriginData originData, ModelProperties modelProperties, IFormulaCache formulaCache)
{
spatialStructure.AddNeighborhood(neighborhood);
_parameterContainerTask.AddModelParametersTo(neighborhood, originData, modelProperties, formulaCache);
Expand Down
8 changes: 4 additions & 4 deletions src/PKSim.Core/PKSim.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.Core" Version="12.0.127" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.127" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.127" />
<PackageReference Include="OSPSuite.Infrastructure.Import" Version="12.0.127" />
<PackageReference Include="OSPSuite.Core" Version="12.0.135" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.135" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.135" />
<PackageReference Include="OSPSuite.Infrastructure.Import" Version="12.0.135" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,18 @@ private void addNewParametersToParameterStartValues(IBuildConfiguration buildCon
addParameterToParameterStartValues(psv, minToYearFactorParameter);
}

private void addParameterToParameterStartValues(IParameterStartValuesBuildingBlock parameterStartValuesBuildingBlock, IParameter parameter)
private ParameterStartValue createParameterStartValue(IParameter parameter)
{
var path = _objectPathFactory.CreateAbsoluteObjectPath(parameter);
var psv = _parameterStartValuesCreator.CreateParameterStartValue(path, parameter);
return psv;
}

private ParameterStartValue addParameterToParameterStartValues(ParameterStartValuesBuildingBlock parameterStartValuesBuildingBlock, IParameter parameter)
{
var psv = createParameterStartValue(parameter);
parameterStartValuesBuildingBlock[psv.Path] = psv;
return psv;
}

private void createSpatialStructureTableParameters(IBuildConfiguration buildConfiguration)
Expand Down Expand Up @@ -197,8 +204,8 @@ private void createOntogenyTableParameters(IBuildConfiguration buildConfiguratio
{
var ontogenyFactorPath = _entityPathResolver.ObjectPathFor(molecule.OntogenyFactorParameter);
var ontogenyFactorGIPath = _entityPathResolver.ObjectPathFor(molecule.OntogenyFactorGIParameter);
createParameterValueVersionOntogenyTableParameter(molecule.OntogenyFactorParameter, buildConfiguration, ontogenyFactorPath, molecule);
createParameterValueVersionOntogenyTableParameter(molecule.OntogenyFactorGIParameter, buildConfiguration, ontogenyFactorGIPath, molecule);
createParameterValueVersionOntogenyTableParameter(molecule.OntogenyFactorParameter, buildConfiguration, molecule);
createParameterValueVersionOntogenyTableParameter(molecule.OntogenyFactorGIParameter, buildConfiguration, molecule);

createPopulationOntogenyTableParameter(molecule.OntogenyFactorParameter, ontogenyFactorPath, molecule, simulationPopulation);
createPopulationOntogenyTableParameter(molecule.OntogenyFactorGIParameter, ontogenyFactorGIPath, molecule, simulationPopulation);
Expand Down Expand Up @@ -226,17 +233,17 @@ private void createPlasmaProteinOntogenyTable(IBuildConfiguration buildConfigura
private void createParameterValueVersionOntogenyTableParameter(
IParameter ontogenyFactorParameter,
IBuildConfiguration buildConfiguration,
ObjectPath ontogenyFactorPath,
IndividualMolecule molecule)
{
var psv = buildConfiguration.ParameterStartValues;
var parameterStartValue = psv[ontogenyFactorPath];
var parameterStartValue = createParameterStartValue(ontogenyFactorParameter);

parameterStartValue.Formula = createOntogenyTableFormulaFrom(ontogenyFactorParameter, molecule.Ontogeny, _baseOriginData);
if (parameterStartValue.Formula == null)
return;

parameterStartValue.StartValue = null;
psv[parameterStartValue.Path] = parameterStartValue;
psv.FormulaCache.Add(parameterStartValue.Formula);
}

Expand Down Expand Up @@ -617,7 +624,7 @@ private void updateConstantParameterToFormula(IParameter parameter, IFormula for
removeParameterStartValueFor(parameter, buildConfiguration.ParameterStartValues);
}

private void removeParameterStartValueFor(IParameter parameter, IParameterStartValuesBuildingBlock parameterStartValuesBuildingBlock)
private void removeParameterStartValueFor(IParameter parameter, ParameterStartValuesBuildingBlock parameterStartValuesBuildingBlock)
{
parameterStartValuesBuildingBlock.Remove(_entityPathResolver.ObjectPathFor(parameter));
}
Expand Down
3 changes: 1 addition & 2 deletions src/PKSim.Core/Services/IModelNeighborhoodQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public interface IModelNeighborhoodQuery
/// </summary>
/// <param name="individualNeighborhoods">List of neighborhood already defined in the individual</param>
/// <param name="modelProperties">Model Properties defining the criteria with which the neighborhoods should be retrieved</param>
IEnumerable<INeighborhoodBuilder> NeighborhoodsFor(IContainer individualNeighborhoods,
ModelProperties modelProperties);
IEnumerable<NeighborhoodBuilder> NeighborhoodsFor(IContainer individualNeighborhoods, ModelProperties modelProperties);
}
}
2 changes: 1 addition & 1 deletion src/PKSim.Core/Services/INeighborhoodFinalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace PKSim.Core.Services
public interface INeighborhoodFinalizer
{
void SetNeighborsIn(Individual individual);
void SetNeighborsIn(Organism organism, IEnumerable<INeighborhoodBuilder> neighborhoods);
void SetNeighborsIn(Organism organism, IReadOnlyList<NeighborhoodBuilder> neighborhoods);
}
}
6 changes: 3 additions & 3 deletions src/PKSim.Core/Services/PKSimMoleculeStartValuesCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace PKSim.Core.Services
{
public interface IPKSimMoleculeStartValuesCreator
{
IMoleculeStartValuesBuildingBlock CreateFor(IBuildConfiguration buildConfiguration, Simulation simulation);
MoleculeStartValuesBuildingBlock CreateFor(IBuildConfiguration buildConfiguration, Simulation simulation);
}

public class PKSimMoleculeStartValuesCreator : IPKSimMoleculeStartValuesCreator
Expand All @@ -36,7 +36,7 @@ public PKSimMoleculeStartValuesCreator(
_entityPathResolver = entityPathResolver;
}

public IMoleculeStartValuesBuildingBlock CreateFor(IBuildConfiguration buildConfiguration, Simulation simulation)
public MoleculeStartValuesBuildingBlock CreateFor(IBuildConfiguration buildConfiguration, Simulation simulation)
{
//default molecule start values matrix
var compounds = simulation.Compounds;
Expand Down Expand Up @@ -75,7 +75,7 @@ private IEnumerable<ObjectPath> moleculesInvolvedInExpression(Individual individ
}
}

private void setStartFormulasForStaticMolecules(IMoleculeStartValuesBuildingBlock defaultStartValues, Simulation simulation, IEnumerable<Compound> compounds)
private void setStartFormulasForStaticMolecules(MoleculeStartValuesBuildingBlock defaultStartValues, Simulation simulation, IEnumerable<Compound> compounds)
{
var modelName = simulation.ModelConfiguration.ModelName;
//get the names of molecules that are static (e.g. not enzymes, metabolites, etc.)
Expand Down
81 changes: 12 additions & 69 deletions src/PKSim.Core/Services/PKSimParameterStartValuesCreator.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,39 @@
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Builder;
using OSPSuite.Core.Domain.Formulas;
using OSPSuite.Core.Domain.Services;
using OSPSuite.Utility.Extensions;
using PKSim.Core.Model;
using static PKSim.Core.CoreConstants.CalculationMethod;
using IFormulaFactory = PKSim.Core.Model.IFormulaFactory;

namespace PKSim.Core.Services
{
public interface IPKSimParameterStartValuesCreator
{
IParameterStartValuesBuildingBlock CreateFor(IBuildConfiguration buildConfiguration, Simulation simulation);
ParameterStartValuesBuildingBlock CreateFor(IBuildConfiguration buildConfiguration, Simulation simulation);
}

public class PKSimParameterStartValuesCreator : IPKSimParameterStartValuesCreator
{
private readonly IParameterStartValuesCreator _parameterStartValuesCreator;
private readonly IFormulaFactory _formulaFactory;
private readonly IObjectBaseFactory _objectBaseFactory;
private readonly IEntityPathResolver _entityPathResolver;
private IParameterStartValuesBuildingBlock _defaultStartValues;
private ParameterStartValuesBuildingBlock _defaultStartValues;

public PKSimParameterStartValuesCreator(IParameterStartValuesCreator parameterStartValuesCreator,
IFormulaFactory formulaFactory,
public PKSimParameterStartValuesCreator(
IParameterStartValuesCreator parameterStartValuesCreator,
IObjectBaseFactory objectBaseFactory,
IEntityPathResolver entityPathResolver)
{
_parameterStartValuesCreator = parameterStartValuesCreator;
_formulaFactory = formulaFactory;
_objectBaseFactory = objectBaseFactory;
_entityPathResolver = entityPathResolver;
}

public IParameterStartValuesBuildingBlock CreateFor(IBuildConfiguration buildConfiguration, Simulation simulation)
public ParameterStartValuesBuildingBlock CreateFor(IBuildConfiguration buildConfiguration, Simulation simulation)
{
try
{
//default default parameter start values matrix
var spatialStructure = buildConfiguration.SpatialStructure;
var molecules = buildConfiguration.Molecules;
_defaultStartValues = _parameterStartValuesCreator.CreateFrom(spatialStructure, molecules);
var individual = simulation.Individual;

//set the relative expression values for each molecule defined in individual
individual.AllMolecules().Each(molecule => updateMoleculeParametersValues(molecule, individual, simulation));

updateSimulationParameters(simulation);

return _defaultStartValues.WithName(simulation.Name);
}
finally
{
_defaultStartValues = null;
}
//default default parameter start values matrix
_defaultStartValues = _objectBaseFactory.Create<ParameterStartValuesBuildingBlock>();
updateSimulationParameters(simulation);
return _defaultStartValues.WithName(simulation.Name);
}

private void updateSimulationParameters(Simulation simulation)
Expand All @@ -75,40 +58,6 @@ private bool isChangedSimulationParameter(IParameter parameter)
&& parameter.ValueDiffersFromDefault();
}

private void updateMoleculeParametersValues(IndividualMolecule molecule, Individual individual, Simulation simulation)
{
var allMoleculeParameters = individual.AllMoleculeParametersFor(molecule);
var modelConfiguration = simulation.ModelConfiguration;
allMoleculeParameters.Each(p => setParameter(p, modelConfiguration.ModelName == CoreConstants.Model.FOUR_COMP));
}

private void setParameter(IParameter parameter, bool isSmallMolecule)
{
//We do not generate start values for endosome parameters when dealing with a small molecule model
if (parameter.HasAncestorNamed(CoreConstants.Compartment.ENDOSOME) && isSmallMolecule)
return;

//We do not generate value for this parameter by default. Exit
var parameterStartValue = getStartValueFor(parameter);
if (parameterStartValue == null)
return;

if (parameter.Formula.IsExplicit())
{
var formula = _formulaFactory.RateFor(EXPRESSION_PARAMETERS, parameter.Formula.Name, _defaultStartValues.FormulaCache);
parameterStartValue.Formula = formula;
//There is a formula, make sure we use it. We set this flag to false to ensure that the formula will not be replaced with a constant formula
parameterStartValue.OverrideFormulaWithValue = false;
}

if (parameter.IsConstantParameter())
{
parameterStartValue.StartValue = parameter.Value;
//we reset the formula to null to ensure that the start value will be used when constructing the simulation
parameterStartValue.Formula = null;
}
}

private ParameterStartValue trySetValue(IParameter parameter)
{
var parameterStartValue = getOrCreateStartValueFor(parameter);
Expand All @@ -128,11 +77,5 @@ private ParameterStartValue getOrCreateStartValueFor(IParameter parameter)

return parameterStartValue;
}

private ParameterStartValue getStartValueFor(IParameter parameter)
{
var parameterPath = _entityPathResolver.ObjectPathFor(parameter);
return _defaultStartValues[parameterPath];
}
}
}
Loading

0 comments on commit eccb8b4

Please sign in to comment.