Пример #1
0
        private void addSimulationToView(ISimulation simulation)
        {
            _lazyLoadTask.Load(simulation);
            var simulationNode = _treeNodeFactory.CreateFor(simulation);

            _view.AddNode(simulationNode);
        }
Пример #2
0
        public ICommand UpdateMoleculeName(ExpressionProfile expressionProfile, string newMoleculeName)
        {
            var command = new PKSimMacroCommand();

            var oldMoleculeName = expressionProfile.MoleculeName;

            //we are not renaming anything
            if (string.Equals(newMoleculeName, oldMoleculeName))
            {
                return(command);
            }

            var(_, individual) = expressionProfile;
            var mainCommand = renameMoleculeReferences(individual, oldMoleculeName, newMoleculeName);

            command.Add(mainCommand);
            command.UpdatePropertiesFrom(mainCommand);
            allSimulationSubjectsUsing(expressionProfile).Each(x =>
            {
                _lazyLoadTask.Load(x);
                command.Add(renameMoleculeReferences(x, oldMoleculeName, newMoleculeName));
            });


            return(command);
        }
Пример #3
0
        public override void Compare(IComparison <Simulation> comparison)
        {
            _lazyLoadTask.Load(comparison.Object1);
            _lazyLoadTask.Load(comparison.Object2);

            _comparer.Compare(comparison.ChildComparison(x => x.Model));
            _comparer.Compare(comparison.ChildComparison(x => x.UsedBuildingBlocks));
        }
        public void EditSimulation(Simulation simulation, CreationMode creationMode)
        {
            _simulationSubjectDTO = new SimulationSubjectDTO
            {
                BuildingBlock = _buildingBlockInSimulationManager.TemplateBuildingBlocksUsedBy <ISimulationSubject>(simulation).SingleOrDefault(),
                AllowAging    = simulation.AllowAging
            };

            _view.BindTo(_simulationSubjectDTO);

            _lazyLoadTask.Load(SelectedSubject);
            OnStatusChanged();
        }
Пример #5
0
        public void StartForSubject <T>(T subject)
        {
            if (subject == null)
            {
                return;
            }
            var lazyLoadable = subject as ILazyLoadable;

            if (lazyLoadable != null && !lazyLoadable.IsLoaded)
            {
                _heavyWorkManager.Start(() => _lazyLoadTask.Load(lazyLoadable));
            }

            var presenter = _openSingleStartPresenterInvoker.OpenPresenterFor(subject);

            try
            {
                presenter.Edit(subject);
            }
            catch (Exception)
            {
                //exception while loading the subject. We need to close the presenter to avoid memory leaks
                _applicationController.Close(subject);
                throw;
            }
        }
Пример #6
0
        public bool Edit(PopulationSimulationComparison simulationComparison)
        {
            updateSelectionFromComparison(simulationComparison);

            _view.BindTo(_selectionDTO);
            ViewChanged();
            _view.Display();

            if (_view.Canceled)
            {
                return(false);
            }

            simulationComparison.RemoveAllSimulations();
            selectedSimulations.Each(s =>
            {
                _lazyLoadTask.Load(s);
                simulationComparison.AddSimulation(s);
            });

            //add reference settings
            simulationComparison.ReferenceSimulation   = referenceSimulation;
            simulationComparison.ReferenceGroupingItem = referenceGroupingItem;

            return(true);
        }
 public void PrepareForCreating(Individual basedIndividual)
 {
     _lazyLoadTask.Load(basedIndividual);
     _importPopulationSettingsDTO.Individual = basedIndividual;
     this.DoWithinLatch(updateView);
     ViewChanged();
 }
Пример #8
0
        private async Task exportSimulation(Simulation simulation, ExportRunOptions exportRunOptions)
        {
            var outputFolder = Path.Combine(exportRunOptions.OutputFolder, simulation.Name);

            DirectoryHelper.CreateDirectory(outputFolder);

            var simulationRunOptions = new SimulationRunOptions();

            _lazyLoadTask.Load(simulation);
            _lazyLoadTask.LoadResults(simulation);

            if (!simulation.OutputSelections.HasSelection)
            {
                _logger.AddWarning($"Simulation '{simulation.Name}' does not have any selected output and will not be exported");
                return;
            }

            if (exportRunOptions.RunSimulation)
            {
                await _simulationExporter.RunAndExport(simulation, outputFolder, simulationRunOptions, exportRunOptions.ExportMode);
            }

            else if (simulation.HasResults)
            {
                await _simulationExporter.Export(simulation, outputFolder, exportRunOptions.ExportMode);
            }

            else
            {
                _logger.AddWarning($"Simulation '{simulation.Name}' does not have any results and will not be exported");
            }
        }
Пример #9
0
        public override IReadOnlyCollection <object> Report(Simulation simulation, OSPSuiteTracker buildTracker)
        {
            _lazyLoadTask.Load(simulation);
            var chapter = new Chapter(simulation.Name);
            var report  = new List <object> {
                chapter
            };

            buildTracker.AddReference(simulation, chapter);
            report.AddRange(this.ReportDescription(simulation, buildTracker));
            report.Add(new Section(PKSimConstants.UI.UsedBuildingBlocks));
            report.Add(simulation.UsedBuildingBlocks);

            report.Add(new Section(PKSimConstants.UI.SimulationProperties));
            report.Add(simulation.Properties);

            addHistograms(simulation, report);

            if (simulation.Analyses.Any())
            {
                report.Add(simulation.Analyses.ToList());
            }

            return(report);
        }
Пример #10
0
 protected override void PerformExecute()
 {
     _lazyLoadTask.Load(Subject);
     using (var presenter = _applicationController.Start <IParameterValuesDebugPresenter>())
     {
         presenter.ShowParametersFor(Subject);
     }
 }
Пример #11
0
 public void RunSimulation(Simulation simulation, bool defineSettings = false)
 {
     _defineSettings = defineSettings;
     _lazyLoadTask.Load(simulation);
     if (!_entityValidationTask.Validate(simulation))
     {
         return;
     }
     this.Visit(simulation);
 }
Пример #12
0
        public override void Build(TBuildingBlock buildingBlock, OSPSuiteTracker tracker)
        {
            _lazyLoadTask.Load(buildingBlock);
            var section = new Section(buildingBlock.Name);

            tracker.AddReference(buildingBlock, section);

            _builderRepository.Report(section, tracker);
            _builderRepository.Report(this.ReportDescription(buildingBlock, tracker), tracker);
            _builderRepository.Report(BuildingBlockReport(buildingBlock, tracker), tracker);
        }
Пример #13
0
        public void ExportForCluster(PopulationSimulation populationSimulation, string populationFolder, string fileDescription = null)
        {
            if (string.IsNullOrEmpty(populationFolder))
            {
                return;
            }

            _lazyLoadTask.Load(populationSimulation);

            if (settingsRequired(populationSimulation))
            {
                var outputSelections = _simulationSettingsRetriever.SettingsFor(populationSimulation);
                if (outputSelections == null)
                {
                    return;
                }

                populationSimulation.OutputSelections.UpdatePropertiesFrom(outputSelections, _cloner);
            }

            var existingFiles = Directory.GetFiles(populationFolder);

            if (existingFiles.Any())
            {
                if (_dialogCreator.MessageBoxYesNo(PKSimConstants.UI.DeleteFilesIn(populationFolder)).Equals(ViewResult.No))
                {
                    return;
                }

                existingFiles.Each(FileHelper.DeleteFile);
            }

            var fileName          = populationSimulation.Name;
            var modelFileFullPath = Path.Combine(populationFolder, $"{fileName}.pkml");
            var agingFileFullPath = Path.Combine(populationFolder, $"{fileName}{CoreConstants.Population.TABLE_PARAMETER_EXPORT}.csv");

            //Model
            _mobiExportTask.ExportSimulationToPkmlFile(populationSimulation, modelFileFullPath);

            var comments = _populationExportTask.CreateProjectMetaInfoFrom(fileDescription);

            //all values
            var dataTable = _populationExportTask.CreatePopulationDataFor(populationSimulation);

            dataTable.ExportToCSV(Path.Combine(populationFolder, $"{fileName}.csv"), comments: comments);

            //all aging data
            var agingData = populationSimulation.AgingData.ToDataTable();

            if (agingData.Rows.Count > 0)
            {
                agingData.ExportToCSV(agingFileFullPath, comments: comments);
            }
        }
Пример #14
0
        public DataTable CreatePopulationDataFor(Population population, bool includeUnitsInHeader = false)
        {
            _lazyLoadTask.Load(population);
            var dataTable = new DataTable(population.Name);

            dataTable.BeginLoadData();

            //Create one column for the parameter path
            addCovariates(population, dataTable);

            //add advanced parameters
            var allAdvancedParameters = population.AllAdvancedParameters(_entityPathResolver).ToList();
            var parametersToExport    = population.AllVectorialParameters(_entityPathResolver);

            //do not take the one that should never be exported
            parametersToExport = parametersToExport.Where(p => parameterShouldBeExported(p, allAdvancedParameters));

            parametersToExport.Each(p => addParameterToTable(population, dataTable, p, includeUnitsInHeader));
            dataTable.EndLoadData();
            return(dataTable);
        }
Пример #15
0
        private IPKSimBuildingBlock subjectFor(WorkspaceLayoutItem layoutItem)
        {
            if (!_withIdRepository.ContainsObjectWithId(layoutItem.SubjectId))
            {
                return(null);
            }

            var subject = _withIdRepository.Get <IPKSimBuildingBlock>(layoutItem.SubjectId);

            _lazyLoadTask.Load(subject);
            return(subject);
        }
Пример #16
0
        public async Task <SimulationExport> ExportSimulation(Simulation simulation, ExportRunOptions exportRunOptions, PKSimProject project)
        {
            var projectName      = project.Name;
            var simulationName   = simulation.Name;
            var simulationFolder = Path.Combine(exportRunOptions.OutputFolder, FileHelper.RemoveIllegalCharactersFrom(simulationName));

            DirectoryHelper.CreateDirectory(simulationFolder);

            var simulationExport = new SimulationExport
            {
                Project          = projectName,
                SimulationFolder = simulationFolder,
                Simulation       = simulationName
            };

            var simulationRunOptions = new SimulationRunOptions();

            _lazyLoadTask.Load(simulation);
            _lazyLoadTask.LoadResults(simulation);

            var simulationExportOptions = new SimulationExportOptions
            {
                OutputFolder = simulationFolder,
                ExportMode   = exportRunOptions.ExportMode,
                ProjectName  = projectName,
            };

            if (!simulation.OutputSelections.HasSelection)
            {
                _logger.AddWarning($"Simulation '{simulationName}' does not have any selected output and will not be exported", projectName);
                return(simulationExport);
            }

            if (exportRunOptions.RunSimulation)
            {
                await _simulationExporter.RunAndExport(simulation, simulationRunOptions, simulationExportOptions);
            }

            else if (simulation.HasResults)
            {
                await _simulationExporter.Export(simulation, simulationExportOptions);
            }

            else
            {
                _logger.AddWarning($"Simulation '{simulationName}' does not have any results and will not be exported", projectName);
                return(simulationExport);
            }

            _logger.AddDebug($"Simulation '{simulationName}' exported to '{simulationFolder}'", projectName);
            return(simulationExport);
        }
        public PKCalculationOptions CreateForObservedData(IReadOnlyList <Simulation> simulations, string moleculeName)
        {
            var allDosesForMolecules = simulations.Select(s =>
            {
                _lazyLoadTask.Load(s);
                return(s.TotalDrugMassPerBodyWeightFor(moleculeName));
            }).Distinct().ToList();

            return(new PKCalculationOptions
            {
                Dose = allDosesForMolecules.Count == 1 ? allDosesForMolecules[0] : null
            });
        }
Пример #18
0
        private Task exportParameterIdentificationContent(ParameterIdentification parameterIdentification, string exportDirectory)
        {
            return(Task.Run(() =>
            {
                if (string.IsNullOrEmpty(exportDirectory))
                {
                    return;
                }

                _lazyLoadTask.Load(parameterIdentification);

                parameterIdentification.AllSimulations.Each(simulation => exportToDirectory(simulation, exportDirectory));
                exportToDirectory(parameterIdentification, exportDirectory);
            }));
        }
Пример #19
0
        private void addSimulationToChart(IndividualSimulation simulation)
        {
            _lazyLoadTask.Load(simulation);
            if (!simulation.HasResults)
            {
                throw new PKSimException(PKSimConstants.Error.SimulationHasNoResultsAndCannotBeUsedInSummaryChart(simulation.Name));
            }

            Chart.AddSimulation(simulation);
            UpdateAnalysisBasedOn(simulation, simulation.DataRepository);

            _chartTemplatingTask.UpdateDefaultSettings(ChartEditorPresenter, simulation.DataRepository.ToList(), new[] { simulation }, addCurveIfNoSourceDefined: false);
            InitializeFromTemplateIfRequired();

            showChartView();
        }
        public async Task RunSimulation(Simulation simulation, bool selectOutput)
        {
            _lazyLoadTask.Load(simulation);

            if (outputSelectionRequired(simulation, selectOutput))
            {
                var outputSelections = _simulationSettingsRetriever.SettingsFor(simulation);
                if (outputSelections == null)
                {
                    return;
                }

                simulation.OutputSelections.UpdatePropertiesFrom(outputSelections, _cloner);
            }

            await _simulationRunner.RunSimulation(simulation, _simulationRunOptions);

            addAnalysableToSimulationIfRequired(simulation);
        }
Пример #21
0
        protected virtual PopulationSimulationPKAnalyses CalculateFor(ISimulation simulation, int numberOfIndividuals, SimulationResults runResults, Action <int> performIndividualScalingAction)
        {
            _lazyLoadTask.Load(simulation);

            var popAnalyses = new PopulationSimulationPKAnalyses();

            foreach (var selectedQuantityForMolecule in simulation.OutputSelections.GroupBy(moleculeNameFrom))
            {
                var moleculeName             = selectedQuantityForMolecule.Key;
                var pkCalculationOptions     = _pkCalculationOptionsFactory.CreateFor(simulation, moleculeName);
                var allApplicationParameters = _pkCalculationOptionsFactory.AllApplicationParametersOrderedByStartTimeFor(simulation, moleculeName);

                foreach (var selectedQuantity in selectedQuantityForMolecule)
                {
                    addPKParametersForOutput(simulation, numberOfIndividuals, runResults, performIndividualScalingAction, selectedQuantity, popAnalyses, moleculeName, pkCalculationOptions, allApplicationParameters);
                }
            }

            return(popAnalyses);
        }
Пример #22
0
        public Task RunSimulation(Simulation simulation, SimulationRunOptions simulationRunOptions = null)
        {
            _simulationRunOptions = simulationRunOptions ?? new SimulationRunOptions();
            _lazyLoadTask.Load(simulation);

            if (_simulationRunOptions.Validate && !_entityValidationTask.Validate(simulation))
            {
                return(_simulationDidNotRun);
            }

            switch (simulation)
            {
            case IndividualSimulation individualSimulation:
                return(runSimulation(individualSimulation, _simulationPersistableUpdater.UpdatePersistableFromSettings));

            case PopulationSimulation populationSimulation:
                return(runSimulation(populationSimulation, _simulationPersistableUpdater.UpdatePersistableFromSettings));
            }
            return(_simulationDidNotRun);
        }
Пример #23
0
        public async Task ExportParameterIdentification(ParameterIdentification parameterIdentification, string exportDirectory)
        {
            _lazyLoadTask.Load(parameterIdentification);
            var simulations      = parameterIdentification.AllSimulations.Cast <Simulation>().ToList();
            var observedDataList = parameterIdentification.AllObservedData.ToList();

            var observedDataFolder = Path.Combine(exportDirectory, "Data");

            DirectoryHelper.CreateDirectory(observedDataFolder);

            var simulationFolder = Path.Combine(exportDirectory, "Simulations");

            DirectoryHelper.CreateDirectory(simulationFolder);

            var tasks = simulations.Select(x => exportSimulation(x, simulationFolder)).ToList();

            tasks.Add(exportParameterIdentification(parameterIdentification, exportDirectory));
            tasks.AddRange(observedDataList.Select(x => exportUsedObservedData(x, observedDataFolder)));

            await Task.WhenAll(tasks);
        }
Пример #24
0
        private void addSimulationToChart(IndividualSimulation simulation)
        {
            _lazyLoadTask.Load(simulation);
            if (!simulation.HasResults)
            {
                throw new PKSimException(PKSimConstants.Error.SimulationHasNoResultsAndCannotBeUsedInSummaryChart(simulation.Name));
            }

            Chart.AddSimulation(simulation);
            SetDataSource(simulation, simulation.DataRepository);

            if (!Chart.Curves.Any())
            {
                InitializeFromTemplate();
            }
            else
            {
                _chartTemplatingTask.UpdateDefaultSettings(_chartEditorPresenter, simulation.DataRepository.ToList(), new[] { simulation });
            }

            showChartView();
        }
Пример #25
0
        public static void AddReferencedObject <TObectWithReference, TReference>(this XElement referenceElementList, TObectWithReference objectWithReference, Func <TObectWithReference, Action <TReference> > addAction,
                                                                                 IWithIdRepository withIdRepository, ILazyLoadTask lazyLoadTask, string referenceElementName) where TReference : class, IWithId
        {
            foreach (var referenceElement in referenceElementList.Descendants(referenceElementName))
            {
                var id = referenceElement.GetAttribute(Constants.Serialization.Attribute.ID);

                //reference might have been deleted...in that case, simply ignore the simulation
                if (!withIdRepository.ContainsObjectWithId(id))
                {
                    continue;
                }

                var reference    = withIdRepository.Get <TReference>(id);
                var lazyLoadable = reference as ILazyLoadable;
                if (lazyLoadable != null)
                {
                    lazyLoadTask?.Load(lazyLoadable);
                }

                addAction(objectWithReference)(reference);
            }
        }
        public void ExctractIndividuals(Population population, IEnumerable <int> individualIds)
        {
            _lazyLoadTask.Load(population);
            _populationName             = population.Name;
            _view.Caption               = PKSimConstants.UI.ExtractIndividualFromPopulation(_populationName);
            _view.PopulationDescription = PKSimConstants.UI.ExtractIndividualPopulationDescription(_populationName, population.NumberOfItems);

            _extractIndividualDTO = new ExtractIndividualsDTO(population.NumberOfItems)
            {
                NamingPattern = IndividualExtractionOptions.DEFAULT_NAMING_PATTERN,
                IndividualIds = individualIds
            };

            _view.BindTo(_extractIndividualDTO);
            _view.Display();

            if (_view.Canceled)
            {
                return;
            }

            _individualExtractor.ExtractIndividualsFrom(population, extractionOptions);
        }
Пример #27
0
        public override IReadOnlyCollection <object> Report(TSimulationComparison simulationComparison, OSPSuiteTracker buildTracker)
        {
            _lazyLoadTask.Load(simulationComparison);
            var chapter = new Chapter(simulationComparison.Name);
            var report  = new List <object> {
                chapter
            };

            buildTracker.AddReference(simulationComparison, chapter);

            var populationComparison = simulationComparison as PopulationSimulationComparison;

            if (populationComparison != null)
            {
                report.Add(getTableFor(populationComparison));

                if (populationComparison.ReferenceGroupingItem != null)
                {
                    report.Add(new Text("The reference simulation is named: {0}", populationComparison.ReferenceGroupingItem.Label));
                }

                report.Add(new SelectedDistribution(populationComparison, 1));

                if (populationComparison.Analyses.Any())
                {
                    report.Add(populationComparison.Analyses.ToList());
                }
            }
            var comparison = simulationComparison as IndividualSimulationComparison;

            if (comparison != null)
            {
                report.Add(comparison);
            }

            return(report);
        }
Пример #28
0
 private void load(ILazyLoadable lazyLoadable) => _lazyLoadTask.Load(lazyLoadable);
Пример #29
0
 public void PrepareForCreating(Individual basedIndividual)
 {
     _lazyLoadTask.Load(basedIndividual);
     _populationSettingsDTO = _populationSettingsMapper.MapFrom(basedIndividual);
     this.DoWithinLatch(updateView);
 }
Пример #30
0
 protected void Load <TBuildingBlock>(TBuildingBlock bb) where TBuildingBlock : class, IPKSimBuildingBlock
 {
     _lazyLoadTask.Load(bb);
 }