private SimulationQuantitySelection outputSelectionFrom(string outputFullPath, PKSimProject project) { var outputPath = new ObjectPath(outputFullPath.ToPathArray()); if (outputPath.Count == 0) { return(null); } var simulationName = outputPath[0]; var simulation = project.All <Model.Simulation>().FindByName(simulationName); if (simulation == null) { _logger.AddWarning(PKSimConstants.Error.CouldNotFindSimulation(simulationName)); return(null); } outputPath.RemoveAt(0); var output = simulation.Model.Root.EntityAt <IQuantity>(outputPath.ToArray()); if (output == null) { _logger.AddWarning(PKSimConstants.Error.CouldNotFindOutputInSimulation(outputPath, simulationName)); return(null); } return(new SimulationQuantitySelection(simulation, new QuantitySelection(outputPath, output.QuantityType))); }
public async Task <SimulationExport[]> ExportSimulationsIn(PKSimProject project, ExportRunOptions exportRunOptions) { var nameOfSimulationsToExport = (exportRunOptions.Simulations ?? Enumerable.Empty <string>()).ToList(); if (!nameOfSimulationsToExport.Any()) { nameOfSimulationsToExport.AddRange(project.All <Simulation>().AllNames()); } var simulationExports = new List <SimulationExport>(); //sequential for now foreach (var simulationName in nameOfSimulationsToExport) { var simulation = project.BuildingBlockByName <Simulation>(simulationName); if (simulation == null) { _logger.AddWarning($"Simulation '{simulationName}' was not found in project '{project.Name}'", project.Name); continue; } simulationExports.Add((await ExportSimulation(simulation, exportRunOptions, project))); } return(simulationExports.ToArray()); }
public override async Task <ModelCurve> MapToModel(SnapshotCurve snapshot, SimulationAnalysisContext simulationAnalysisContext) { var curve = new ModelCurve { Name = snapshot.Name }; var curveOptions = await _curveOptionsMapper.MapToModel(snapshot.CurveOptions); curve.CurveOptions.UpdateFrom(curveOptions); var yData = findCurveWithPath(snapshot.Y, simulationAnalysisContext.DataRepositories); if (yData == null) { _logger.AddWarning(PKSimConstants.Error.CouldNotFindQuantityWithPath(snapshot.Y)); return(null); } curve.SetyData(yData, _dimensionFactory); ModelDataColumn xData = yData.BaseGrid; if (!string.Equals(snapshot.X, xData?.Name)) { xData = findCurveWithPath(snapshot.X, simulationAnalysisContext.DataRepositories); } if (xData == null) { _logger.AddWarning(PKSimConstants.Error.CouldNotFindQuantityWithPath(snapshot.X)); return(null); } curve.SetxData(xData, _dimensionFactory); return(curve); }
private void createSummaryFilesIn(DirectoryInfo outputDirectory, SimulationExportMode exportMode) { if (!exportMode.HasFlag(SimulationExportMode.Csv)) { return; } var dataTable = new DataTable(outputDirectory.Name); dataTable.Columns.Add("Sim_id", typeof(string)); foreach (var simulationName in _allSimulationNames) { var row = dataTable.NewRow(); row[0] = simulationName; dataTable.Rows.Add(row); } var fileName = Path.Combine(outputDirectory.FullName, $"{outputDirectory.Name}.csv"); if (FileHelper.FileExists(fileName)) { var tmp = FileHelper.FileNameFromFileFullPath(FileHelper.GenerateTemporaryFileName()); tmp = Path.Combine(outputDirectory.FullName, $"{tmp}.csv"); _logger.AddWarning($"File '{fileName}' already exists and will be saved under '{tmp}'"); fileName = tmp; } _logger.AddDebug($"Exporting simulation file names to '{fileName}'"); dataTable.ExportToCSV(fileName); }
public override async Task <MoleculeExpressionContainer> MapToModel(ExpressionContainer snapshot, ExpressionContainerMapperContext context) { if (snapshot == null) { return(null); } var molecule = context.Molecule; var individual = context.SimulationSubject; var expressionContainer = molecule.ExpressionContainer(snapshot.Name); if (expressionContainer == null) { _logger.AddWarning(PKSimConstants.Error.RelativeExpressionContainerNotFound(snapshot.Name)); return(null); } var expressionParameter = expressionContainer.RelativeExpressionParameter; await _parameterMapper.MapToModel(snapshot, expressionParameter); if (!(molecule is IndividualTransporter transporter)) { return(expressionContainer); } var species = individual.Species.Name; var transporterExpressionContainer = expressionContainer.DowncastTo <TransporterExpressionContainer>(); var membraneLocation = ModelValueFor(snapshot.MembraneLocation, MembraneLocation.Basolateral); _transportContainerUpdater.UpdateTransporterFromTemplate(transporterExpressionContainer, species, membraneLocation, transporter.TransportType); return(expressionContainer); }
public override Task <ModelOutputSelections> MapToModel(SnapshotOutputSelections snapshot, Model.Simulation simulation) { var outputSelections = new ModelOutputSelections(); if (snapshot == null) { return(Task.FromResult(outputSelections)); } var allQuantities = _entitiesInContainerRetriever.QuantitiesFrom(simulation); snapshot.Each(path => { var quantity = allQuantities[path]; if (quantity == null) { _logger.AddWarning(PKSimConstants.Error.CouldNotFindQuantityWithPath(path)); } else { outputSelections.AddOutput(new QuantitySelection(path, quantity.QuantityType)); } }); return(Task.FromResult(outputSelections)); }
private async Task <CompoundProcessesSelection> modelProcessSelectionFrom(CompoundProcessSelection[] snapshotProcesses, Model.Compound compound, ISimulationSubject simulationSubject) { var compoundProcessesSelection = new CompoundProcessesSelection(); if (snapshotProcesses == null) { return(compoundProcessesSelection); } foreach (var snapshotProcess in snapshotProcesses) { var process = compound.ProcessByName(snapshotProcess.Name) ?? notSelectedProcessFrom(snapshotProcess, simulationSubject); if (process == null) { //No process found and a name was specified. This is a snapshot that is corrupted if (!string.IsNullOrEmpty(snapshotProcess.Name)) { _logger.AddWarning(PKSimConstants.Error.ProcessNotFoundInCompound(snapshotProcess.Name, compound.Name)); } continue; } await addProcessToProcessSelection(compoundProcessesSelection, snapshotProcess, process); } return(compoundProcessesSelection); }
public static void AddException(this ILogger logger, Exception exception, string categoryName = null) { if (exception.IsInfoException()) { logger.AddWarning(exception.ExceptionMessage(), categoryName); } else { logger.AddError(exception.ExceptionMessageWithStackTrace(), categoryName); } }
private void addSimulation(string simulationName, ModelParameterIdentification parameterIdentification, PKSimProject project) { var simulation = project.All <Model.Simulation>().FindByName(simulationName); if (simulation == null) { _logger.AddWarning(PKSimConstants.Error.CouldNotFindSimulation(simulationName)); return; } parameterIdentification.AddSimulation(simulation); }
private async Task exportSimulations(PKSimProject project, ExportRunOptions exportRunOptions) { var nameOfSimulationsToExport = (exportRunOptions.Simulations ?? Enumerable.Empty <string>()).ToList(); if (!nameOfSimulationsToExport.Any()) { nameOfSimulationsToExport.AddRange(project.All <Simulation>().AllNames()); } //sequential for now foreach (var simulationName in nameOfSimulationsToExport) { var simulation = project.BuildingBlockByName <Simulation>(simulationName); if (simulation == null) { _logger.AddWarning($"Simulation '{simulationName}' was not found in project '{project.Name}'"); continue; } await exportSimulation(simulation, exportRunOptions); } }
private async Task <InteractionSelection> interactionSelectionFrom(CompoundProcessSelection snapshotInteraction, PKSimProject project) { var process = findProcess(project, snapshotInteraction); if (process == null) { _logger.AddWarning(PKSimConstants.Error.ProcessNotFoundInCompound(snapshotInteraction.Name, snapshotInteraction.CompoundName)); return(null); } var processSelection = await _processMappingMapper.MapToModel(snapshotInteraction, process); return(processSelection.DowncastTo <InteractionSelection>()); }
public override Task <IQualificationStep> MapToModel(SnapshotQualificationStep snapshot, PKSimProject project) { var qualificationStep = createQualificationStepFrom(snapshot.Type); if (qualificationStep == null) { _logger.AddWarning(PKSimConstants.Error.CouldNotFindQualificationStep(snapshot.Type)); return(Task.FromResult <IQualificationStep>(null)); } mapQualificationStepPropertiesToModel(qualificationStep, snapshot, project); return(Task.FromResult(qualificationStep)); }
public override async Task <IParameter> MapToModel(SnapshotParameter snapshot, IParameter parameter) { _valueOriginMapper.UpdateValueOrigin(parameter.ValueOrigin, snapshot.ValueOrigin); //only update formula if required if (snapshot.TableFormula != null) { parameter.Formula = await _tableFormulaMapper.MapToModel(snapshot.TableFormula); } if (snapshot.Value == null) { return(parameter); } var displayUnit = ModelValueFor(snapshot.Unit); if (!parameter.Dimension.HasUnit(displayUnit)) { _logger.AddWarning(PKSimConstants.Warning.UnitNotFoundInDimensionForParameter(displayUnit, parameter.Dimension.Name, parameter.Name)); } parameter.DisplayUnit = parameter.Dimension.UnitOrDefault(displayUnit); //This needs to come AFTER formula update so that the base value is accurate var baseValue = parameter.Value; var snapshotValueInBaseUnit = parameter.ConvertToBaseUnit(snapshot.Value); if (!ValueComparer.AreValuesEqual(baseValue, snapshotValueInBaseUnit)) { parameter.Value = snapshotValueInBaseUnit; parameter.IsDefault = false; } return(parameter); }
private Model.CompoundProcess findProcess(PKSimProject project, CompoundProcessSelection snapshotInteraction, ISimulationSubject simulationSubject) { var compoundProcess = project.BuildingBlockByName <Model.Compound>(snapshotInteraction.CompoundName) ?.ProcessByName(snapshotInteraction.Name); if (compoundProcess != null) { return(compoundProcess); } //No process found and a name was specified. This is a snapshot that is corrupted if (!string.IsNullOrEmpty(snapshotInteraction.Name)) { _logger.AddWarning(PKSimConstants.Error.ProcessNotFoundInCompound(snapshotInteraction.Name, snapshotInteraction.CompoundName)); return(null); } //This might be a process that was deselected explicitly by the user var molecule = simulationSubject.MoleculeByName(snapshotInteraction.MoleculeName); return(molecule == null ? null : new NoInteractionProcess { MoleculeName = molecule.Name }); }
public override async Task <ModelAdvancedParameter> MapToModel(SnapshotAdvancedParameter snapshot, PathCache <IParameter> allParameters) { var parameter = allParameters[snapshot.Name]; if (parameter == null) { _logger.AddWarning(PKSimConstants.Error.SnapshotParameterNotFound(snapshot.Name)); return(null); } var advancedParameter = _advancedParameterFactory.Create(parameter, DistributionTypes.ById(snapshot.DistributionType)); advancedParameter.Seed = snapshot.Seed; await UpdateParametersFromSnapshot(snapshot, advancedParameter.DistributedParameter); return(advancedParameter); }
public static void AddException(this ILogger logger, Exception exception, string categoryName = null) { //Info message only => Should be shown as warning in log if (exception.IsInfoException()) { logger.AddWarning(exception.ExceptionMessage(addContactSupportInfo: false), categoryName); } // Not an info message but an exception thrown by the suite. Error without stack trace else if (exception.IsOSPSuiteException()) { logger.AddError((exception.ExceptionMessage(addContactSupportInfo: false)), categoryName); } // this is bad => Stack trace else { logger.AddError(exception.ExceptionMessageWithStackTrace(false), categoryName); } }
private void useCalculationMethodIn(ModelCalculationMethodCache calculationMethodCache, string calculationMethodName, bool oneCalculationMethodPerCategory) { var calculationMethod = _calculationMethodRepository.FindByName(calculationMethodName); if (calculationMethod == null) { _logger.AddWarning(PKSimConstants.Error.CalculationMethodNotFound(calculationMethodName)); return; } if (oneCalculationMethodPerCategory) { var existingCalculationMethod = calculationMethodCache.CalculationMethodFor(calculationMethod.Category); if (existingCalculationMethod != null) { calculationMethodCache.RemoveCalculationMethod(existingCalculationMethod); } } calculationMethodCache.AddCalculationMethod(calculationMethod); }
private ParameterSelection parameterSelectionFrom(string parameterFullPath, PKSimProject project) { var parameterPath = new ObjectPath(parameterFullPath.ToPathArray()); if (parameterPath.Count == 0) { return(null); } var simulationName = parameterPath[0]; var simulation = project.All <Model.Simulation>().FindByName(simulationName); if (simulation == null) { _logger.AddWarning(PKSimConstants.Error.CouldNotFindSimulation(simulationName)); return(null); } parameterPath.RemoveAt(0); return(new ParameterSelection(simulation, parameterPath)); }
private async Task <CompoundProcessesSelection> modelProcessSelectionFrom(CompoundProcessSelection[] snapshotProcesses, Model.Compound compound) { var compoundProcessesSelection = new CompoundProcessesSelection(); if (snapshotProcesses == null) { return(compoundProcessesSelection); } foreach (var snapshotProcess in snapshotProcesses) { var process = compound.ProcessByName(snapshotProcess.Name); if (process == null) { _logger.AddWarning(PKSimConstants.Error.ProcessNotFoundInCompound(snapshotProcess.Name, compound.Name)); } else { await addProcessToProcessSelection(compoundProcessesSelection, snapshotProcess, process); } } return(compoundProcessesSelection); }