-
Notifications
You must be signed in to change notification settings - Fork 8
Fixes #2655 Usage of SimulationBuilder in R #2698
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,22 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel; | ||
| using System.Linq; | ||
| using OSPSuite.CLI.Core.MinimalImplementations; | ||
| using OSPSuite.Core.Chart; | ||
| using OSPSuite.Core.Commands; | ||
| using OSPSuite.Core.Domain; | ||
| using OSPSuite.Core.Domain.Builder; | ||
| using OSPSuite.Core.Domain.Data; | ||
| using OSPSuite.Core.Domain.Services; | ||
| using OSPSuite.Utility.Extensions; | ||
| using OSPSuite.Utility.Visitor; | ||
|
|
||
| namespace OSPSuite.R.Domain | ||
| { | ||
| public class Simulation : ISimulation | ||
| { | ||
| private readonly IReadOnlyList<MoleculeBuilder> _allBuildersInSimulation; | ||
| public IModelCoreSimulation CoreSimulation { get; } | ||
|
|
||
| public bool IsLoaded { get; set; } = true; | ||
|
|
@@ -50,6 +53,9 @@ public void AddAnalysis(ISimulationAnalysis simulationAnalysis) | |
| public Simulation(IModelCoreSimulation modelCoreSimulation) | ||
| { | ||
| CoreSimulation = modelCoreSimulation; | ||
|
|
||
| // Initialize the list of molecule builders for which there are initial conditions in the simulation | ||
| _allBuildersInSimulation = allBuildersFor(allMoleculeNamesInSimulation.ToList()).DistinctBy(x => x.Name).ToList(); | ||
| } | ||
|
|
||
| public string Name | ||
|
|
@@ -127,6 +133,33 @@ public SimulationConfiguration Configuration | |
|
|
||
| public IReadOnlyList<string> CompoundNames => CoreSimulation.CompoundNames; | ||
|
|
||
| public IReadOnlyList<string> AllPresentFloatingMoleculeNames => _allBuildersInSimulation.Where(m => m is { IsFloating: true }).AllNames().ToArray(); | ||
|
|
||
| public IReadOnlyList<string> AllPresentXenobioticFloatingMoleculeNames => _allBuildersInSimulation.Where(m => m is { IsFloatingXenobiotic: true }).AllNames().ToArray(); | ||
|
|
||
| public IReadOnlyList<string> AllPresentStationaryMoleculeNames => _allBuildersInSimulation.Where(m => m is { IsFloating: false, IsXenobiotic: true }).AllNames().ToArray(); | ||
|
|
||
| public IReadOnlyList<string> AllPresentEndogenousStationaryMoleculeNames => _allBuildersInSimulation.Where(m => m is { IsFloating: false, IsXenobiotic: false }).AllNames().ToArray(); | ||
|
|
||
| private IEnumerable<string> allMoleculeNamesInSimulation => | ||
| CoreSimulation.Configuration.ModuleConfigurations. | ||
| Where(x => x.SelectedInitialConditions != null). // Initial conditions are selected | ||
| SelectMany(x => x.SelectedInitialConditions). | ||
| Where(x => x.IsPresent). // this initial condition is present | ||
| Select(ic => ic.MoleculeName).Distinct(); | ||
|
|
||
| private IEnumerable<MoleculeBuilder> allMoleculeBuilders => | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. none of this code is required . The service returning a simulation builder should be used IMO in the simulation.R alongside the simulation and saved as reference to be used with each subsequent access |
||
| CoreSimulation.Configuration.ModuleConfigurations. | ||
| Where(x => x.Module.Molecules != null). // filter out modules without molecules building blocks | ||
| SelectMany(x => x.Module.Molecules); | ||
|
|
||
| private IReadOnlyList<MoleculeBuilder> allBuildersFor(IReadOnlyList<string> moleculeNames) | ||
| { | ||
| var cache = new CacheByName<MoleculeBuilder>(); | ||
| allMoleculeBuilders.Where(x => moleculeNames.Contains(x.Name)).Each(x => cache.Add(x)); | ||
| return cache.ToList(); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cache by name so that we only pay attention to the last merged version of a builder. |
||
| } | ||
|
|
||
| public IEnumerable<T> All<T>() where T : class, IEntity => CoreSimulation.All<T>(); | ||
|
|
||
| public IParameter BodyWeight => CoreSimulation.BodyWeight; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can build this list once at construction rather than build the list for each access.