-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSimulation.cs
More file actions
174 lines (137 loc) · 6.28 KB
/
Simulation.cs
File metadata and controls
174 lines (137 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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;
public bool HasUpToDateResults { get; } = true;
public bool ComesFromPKSim { get; } = false;
public bool UsesObservedData(DataRepository observedData) => false;
public IEnumerable<CurveChart> Charts { get; } = new List<CurveChart>();
public SimulationEntitySources EntitySources { get; set; } = new SimulationEntitySources();
public OutputMappings OutputMappings { get; set; }
public DataRepository ResultsDataRepository { get; set; }
public void RemoveUsedObservedData(DataRepository dataRepository)
{
// nothing to do in R
}
public void RemoveOutputMappings(DataRepository dataRepository)
{
// nothing to do in R
}
public void RemoveAnalysis(ISimulationAnalysis simulationAnalysis)
{
// nothing to do in R
}
public IEnumerable<ISimulationAnalysis> Analyses { get; } = new List<ISimulationAnalysis>();
public void AddAnalysis(ISimulationAnalysis simulationAnalysis)
{
// nothing to do in R
}
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
{
get => CoreSimulation.Name;
set
{
CoreSimulation.Name = value;
new RenameModelCommand(CoreSimulation.Model, value).Execute(new ExecutionContext());
}
}
public string Id
{
get => CoreSimulation.Id;
set => CoreSimulation.Id = value;
}
public event PropertyChangedEventHandler PropertyChanged
{
add => CoreSimulation.PropertyChanged += value;
remove => CoreSimulation.PropertyChanged -= value;
}
public event Action<object> Changed
{
add => CoreSimulation.Changed += value;
remove => CoreSimulation.Changed -= value;
}
public void AcceptVisitor(IVisitor visitor) => CoreSimulation.AcceptVisitor(visitor);
public void UpdatePropertiesFrom(IUpdatable source, ICloneManager cloneManager)
{
CoreSimulation.UpdatePropertiesFrom(source, cloneManager);
}
public string Description
{
get => CoreSimulation.Description;
set => CoreSimulation.Description = value;
}
public string Icon
{
get => CoreSimulation.Icon;
set => CoreSimulation.Icon = value;
}
public CreationMetaData Creation
{
get => CoreSimulation.Creation;
set => CoreSimulation.Creation = value;
}
public IModel Model
{
get => CoreSimulation.Model;
set => CoreSimulation.Model = value;
}
public OutputSelections OutputSelections => CoreSimulation.OutputSelections;
public double? EndTime => CoreSimulation.EndTime;
public SimulationSettings Settings => CoreSimulation.Settings;
public SimulationConfiguration Configuration
{
get => CoreSimulation.Configuration;
set => CoreSimulation.Configuration = value;
}
public IReadOnlyList<ReactionBuildingBlock> Reactions => CoreSimulation.Reactions;
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 =>
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();
}
public IEnumerable<T> All<T>() where T : class, IEntity => CoreSimulation.All<T>();
public IParameter BodyWeight => CoreSimulation.BodyWeight;
public IParameter TotalDrugMassFor(string moleculeName) => CoreSimulation.TotalDrugMassFor(moleculeName);
public double? MolWeightFor(IQuantity quantity) => CoreSimulation.MolWeightFor(quantity);
public double? MolWeightFor(string quantityPath) => CoreSimulation.MolWeightFor(quantityPath);
public bool HasChanged { get; set; }
}
}