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); }
public IMoBiCommand CreateBuildConfigurationBaseOn(IMoBiSimulation simulation, IBuildingBlock templateBuildingBlock) { //we create a build configuration where all current building block are referencing template building blocks BuildConfiguration = _buildConfigurationFactory.CreateFromReferencesUsedIn(simulation.MoBiBuildConfiguration, templateBuildingBlock); var tmpSimulation = new MoBiSimulation() { DiagramManager = _diagramManagerFactory.Create <ISimulationDiagramManager>(), BuildConfiguration = BuildConfiguration, Creation = simulation.Creation, Name = simulation.Name, }; edit(tmpSimulation); _view.Caption = AppConstants.Captions.ConfigureSimulation(simulation.Name); _view.Display(); if (_view.Canceled) { return(new MoBiEmptyCommand()); } //Set the selected MSV AND PSV as per user inputs UpdateStartValueInfo <IMoleculeStartValuesBuildingBlock, IMoleculeStartValue>(BuildConfiguration.MoleculeStartValuesInfo, SelectedMoleculeStartValues); UpdateStartValueInfo <IParameterStartValuesBuildingBlock, IParameterStartValue>(BuildConfiguration.ParameterStartValuesInfo, SelectedParameterStartValues); return(_commands); }
public void should_be_able_to_read_all_files_and_run_the_most() { var directories = new DirectoryInfo(_directory).EnumerateDirectories(); var messages = new List <string>(); foreach (var directory in directories) { _sbmlTask = IoC.Resolve <ISbmlTask>().DowncastTo <SbmlTask>(); var caseName = directory.Name; Debug.Print(caseName); var fileName = Path.Combine(directory.FullName, $"{caseName}-sbml-l3v1.xml"); var context = IoC.Resolve <IMoBiContext>(); context.NewProject(); var project = context.CurrentProject; IMoBiCommand command; try { command = _sbmlTask.ImportModelFromSbml(fileName, project); } catch (Exception e) { messages.Add($"Import: {caseName} {e.Message}:"); continue; } if (command.IsEmpty()) { messages.Add($"Import: {caseName}"); continue; } addjEmptyBBIfneeded(project); addSettings(project, Path.Combine(directory.FullName, $"{caseName}-settings.txt")); var buildConfigurtion = genreateBuildConfiguration(project); var result = _modelConstructor.CreateModelFrom(buildConfigurtion, caseName); if (result.IsInvalid) { messages.Add(caseName); continue; } var simulation = new MoBiSimulation { BuildConfiguration = buildConfigurtion, Model = result.Model }; var simModelManager = new SimModelManager(_simModelExporter, new SimModelSimulationFactory(), new DataFactory(IoC.Resolve <IMoBiDimensionFactory>(), new SBMLTestDataNamingService(), IoC.Resolve <IObjectPathFactory>(), IoC.Resolve <IDisplayUnitRetriever>(), IoC.Resolve <IDataRepositoryTask>())); var runResults = simModelManager.RunSimulation(simulation); if (!runResults.Success) { messages.Add(caseName); continue; } var dt = _dateRepositoryTask.ToDataTable(runResults.Results); dt.First().ExportToCSV(Path.Combine(directory.FullName, $"{caseName}-result_mobi.csv")); _sbmlTask = null; } messages.Count.ShouldBeEqualTo(0, messages.ToString("\n")); }
protected override void Context() { base.Context(); var m1 = new Model().WithName("S1"); var m2 = new Model().WithName("S1"); var bc1 = A.Fake <IMoBiBuildConfiguration>(); var bc2 = A.Fake <IMoBiBuildConfiguration>(); var reactionInfo1 = new ReactionBuildingBlockInfo { BuildingBlock = A.Fake <IMoBiReactionBuildingBlock>().WithName("R1"), TemplateBuildingBlock = A.Fake <IMoBiReactionBuildingBlock>().WithName("R1") }; bc1.ReactionsInfo = reactionInfo1; var reactionInfo2 = new ReactionBuildingBlockInfo { BuildingBlock = A.Fake <IMoBiReactionBuildingBlock>().WithName("R2"), TemplateBuildingBlock = A.Fake <IMoBiReactionBuildingBlock>().WithName("R2") }; bc2.ReactionsInfo = reactionInfo2; var sim1 = new MoBiSimulation { BuildConfiguration = bc1, Model = m1 }.WithName("S1"); var sim2 = new MoBiSimulation { BuildConfiguration = bc2, Model = m2 }.WithName("S1"); _object1 = sim1; _object2 = sim2; }
protected override void Context() { base.Context(); _cloneManager = A.Fake <ICloneManager>(); _simulationDiagramManager = A.Fake <ISimulationDiagramManager>(); _moBiSimulation = new MoBiSimulation { DiagramManager = _simulationDiagramManager }; }
protected override void Context() { base.Context(); _observedData = new DataRepository("OBS1"); _simulationResults = new DataRepository("RES"); _simmulation = new MoBiSimulation().WithId("ID"); _simmulation.Results = _simulationResults; _project.AddSimulation(_simmulation); _project.AddObservedData(_observedData); }
public IMoBiSimulation CreateFrom(IMoBiBuildConfiguration buildConfiguration, IModel model) { var moBiSimulation = new MoBiSimulation() { DiagramManager = _diagramManagerFactory.Create <ISimulationDiagramManager>(), BuildConfiguration = buildConfiguration, Model = model, Creation = _creationMetaDataFactory.Create(), HasChanged = true, Id = _idGenerator.NewId(), }; _simulationParameterOriginIdUpdater.UpdateSimulationId(moBiSimulation); return(moBiSimulation); }
protected override void Context() { base.Context(); _currentResult = new DataRepository("id1"); _historicResult = new DataRepository("id2"); _repositories = new List <DataRepository> { _currentResult, _historicResult }; _moBiSimulation = new MoBiSimulation { Results = _currentResult }; _moBiSimulation.HistoricResults.Add(_historicResult); _project.AddSimulation(_moBiSimulation); A.CallTo(_dialogCreator).WithReturnType <ViewResult>().Returns(ViewResult.Yes); }
protected override void Context() { base.Context(); var m1 = new Model().WithName("S1"); var m2 = new Model().WithName("S1"); var bc1 = A.Fake <IMoBiBuildConfiguration>(); var bc2 = A.Fake <IMoBiBuildConfiguration>(); var sim1 = new MoBiSimulation { BuildConfiguration = bc1, Model = m1 }.WithName("S1"); var sim2 = new MoBiSimulation { BuildConfiguration = bc2, Model = m2 }.WithName("S1"); _object1 = sim1; _object2 = sim2; }
protected override void Context() { base.Context(); _simulation = new MoBiSimulation(); _simModelManager = A.Fake <ISimModelManager>(); _outputSelections = new OutputSelections(); _drug = new MoleculeBuilder().WithName("DRUG"); _drug.AddParameter(new Parameter().WithName(AppConstants.Parameters.MOLECULAR_WEIGHT).WithFormula(new ConstantFormula(400))); _outputSelections.AddOutput(new QuantitySelection("A", QuantityType.Drug)); _simulation.BuildConfiguration = new MoBiBuildConfiguration { SimulationSettings = new SimulationSettings { OutputSelections = _outputSelections }, Molecules = new MoleculeBuildingBlock { _drug } }; A.CallTo(() => _simModelManagerFactory.Create()).Returns(_simModelManager); _oldResults = new DataRepository("OLD"); _simulation.Results = _oldResults; _newResults = new DataRepository("NEW"); _simulationResults = new SimulationRunResults(success: true, warnings: Enumerable.Empty <SolverWarning>(), results: _newResults); A.CallTo(() => _simModelManager.RunSimulation(_simulation)).Returns(_simulationResults); var baseGrid = new BaseGrid("Time", DomainHelperForSpecs.TimeDimension); _concentrationColumn = new DataColumn("Drug", DomainHelperForSpecs.ConcentrationDimension, baseGrid); _fractionColumn = new DataColumn("Fraction", DomainHelperForSpecs.FractionDimension, baseGrid); _newResults.Add(_concentrationColumn); _newResults.Add(_fractionColumn); A.CallTo(() => _keyPathMapper.MoleculeNameFrom(_concentrationColumn)).Returns(_drug.Name); }
protected override void Because() { var testSimulation = new MoBiSimulation().WithName("Sim"); _forbiddenNames = sut.For(testSimulation); }
public void Visit(MoBiSimulation simulation) { enableActiveSimulationItems = true; }