public void Compute(IMoBiSimulation simulation) { var buildConfiguration = _buildConfigurationFactory.CreateFromReferencesUsedIn(simulation.MoBiBuildConfiguration); buildConfiguration.ShowProgress = false; _logger.AddDebug("Creating new simulation from loaded building blocks"); var results = _modelConstructor.CreateModelFrom(buildConfiguration, "BatchRun"); if (results.IsInvalid) { _logger.AddWarning(results.ValidationResult.Messages.SelectMany(x => x.Details).ToString()); } var newSimulation = new MoBiSimulation { BuildConfiguration = buildConfiguration, Model = results.Model, Id = "Sim" }; _context.Register(newSimulation); _logger.AddDebug("Running simulation"); _simModelManager.RunSimulation(newSimulation); }
private TMolecule addMoleculeTo <TMolecule>(Model.Individual individual, Molecule molecule) where TMolecule : IndividualMolecule { var proteinFactory = _moleculeFactoryResolver.FactoryFor <TMolecule>(); var newMolecule = proteinFactory.CreateFor(individual); newMolecule.ReferenceConcentration.Value = molecule.ReferenceConcentration; newMolecule.HalfLifeLiver.Value = molecule.HalfLifeLiver; newMolecule.HalfLifeIntestine.Value = molecule.HalfLifeIntestine; newMolecule.Name = molecule.Name; individual.AddMolecule(newMolecule); foreach (var expression in molecule.Expressions) { var expressionParameter = newMolecule.GetRelativeExpressionNormParameterFor(expression.Key); if (expressionParameter == null) { _batchLogger.AddWarning($"Relative Expression container '{expression.Key}' not found for '{molecule.Name}'"); continue; } expressionParameter.Value = expression.Value; _batchLogger.AddDebug($"Relative Expression norm for container '{expression.Key}' set to {expression.Value}"); } return(newMolecule.DowncastTo <TMolecule>()); }
public Model.Formulation MapFrom(Formulation batchFormulation) { if (batchFormulation == null) { return(null); } var template = _formulationRepository.FormulationBy(batchFormulation.FormulationType); var formulation = _cloner.Clone(template); formulation.Name = batchFormulation.Name; foreach (var parameterValue in batchFormulation.Parameters) { var parameter = formulation.Parameter(parameterValue.Key); if (parameter == null) { _batchLogger.AddWarning($"Parameter '{parameterValue.Key}' not found in formulation '{formulation.Name}'"); continue; } parameter.Value = parameterValue.Value; _batchLogger.AddParameterValueToDebug(parameter); } return(formulation); }
private void createSummaryFilesIn(DirectoryInfo outputDirectory) { 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 ModelCompound MapFrom(BatchCompound batchCompound) { var compound = _compoundFactory.Create(); compound.Name = batchCompound.Name; setValue(compound, CoreConstants.Groups.COMPOUND_LIPOPHILICITY, CoreConstants.Parameter.LIPOPHILICITY, batchCompound.Lipophilicity); setValue(compound, CoreConstants.Groups.COMPOUND_FRACTION_UNBOUND, CoreConstants.Parameter.FractionUnbound, batchCompound.FractionUnbound); setValue(compound, Constants.Parameters.MOL_WEIGHT, batchCompound.MolWeight); setValue(compound, CoreConstants.Parameter.CL, batchCompound.Cl); setValue(compound, CoreConstants.Parameter.F, batchCompound.F); setValue(compound, CoreConstants.Parameter.BR, batchCompound.Br); setValue(compound, CoreConstants.Parameter.I, batchCompound.I); setValue(compound, CoreConstants.Parameter.IS_SMALL_MOLECULE, batchCompound.IsSmallMolecule ? 1 : 0); setValue(compound, CoreConstants.Groups.COMPOUND_SOLUBILITY, CoreConstants.Parameter.SolubilityAtRefpH, batchCompound.SolubilityAtRefpH); setValue(compound, CoreConstants.Groups.COMPOUND_SOLUBILITY, CoreConstants.Parameter.RefpH, batchCompound.RefpH); for (int i = 0; i < batchCompound.PkaTypes.Count; i++) { setPka(compound, batchCompound.PkaTypes[i], i); } foreach (var batchSystemicProcess in batchCompound.SystemicProcesses) { var systemicProcess = retrieveProcessFrom <Model.SystemicProcess>(batchSystemicProcess); if (systemicProcess == null) { continue; } systemicProcess.SystemicProcessType = SystemicProcessTypes.ById(batchSystemicProcess.SystemicProcessType); systemicProcess.RefreshName(); compound.AddProcess(systemicProcess); } foreach (var batchPartialProcess in batchCompound.PartialProcesses) { var partialProcess = retrieveProcessFrom <Model.PartialProcess>(batchPartialProcess); if (partialProcess == null) { continue; } partialProcess.MoleculeName = batchPartialProcess.MoleculeName; partialProcess.RefreshName(); compound.AddProcess(partialProcess); } //Update default with available CM in configuration foreach (var calculationMethodName in batchCompound.CalculationMethods) { var calculationMethod = _calculationMethodRepository.FindByName(calculationMethodName); if (calculationMethod == null) { _batchLogger.AddWarning($"Calculation method '{calculationMethodName}' not found"); continue; } var category = _calculationMethodCategoryRepository.FindByName(calculationMethod.Category); if (category == null) { _batchLogger.AddWarning($"Could not find compound category '{calculationMethod.Category}' for calculation method '{calculationMethodName}."); continue; } //this is a compound calculationmethod. Swap them out var existingCalculationMethod = compound.CalculationMethodFor(category); compound.RemoveCalculationMethod(existingCalculationMethod); compound.AddCalculationMethod(calculationMethod); _batchLogger.AddDebug($"Using calculation method '{calculationMethod.Name}' instead of '{existingCalculationMethod.Name}' for category '{calculationMethod.Category}'"); } return(compound); }
private bool warn(string warning) { _logger.AddWarning(warning); return(false); }