Exemplo n.º 1
0
        public Simulation CreateSimulation(SimulationConstruction simulationConstruction, Action <Simulation> preModelCreationAction = null)
        {
            var simulation = _simulationConstructor.CreateSimulation(simulationConstruction, preModelCreationAction);

            AddSimulationClassificationFor(simulation);
            return(simulation);
        }
Exemplo n.º 2
0
        private async Task <IBuildConfiguration> configurationFrom(SimulationConstruction simulationConstruction)
        {
            var simulation = await _snapshotObjectCreator.SimulationFor(simulationConstruction);

            return(_buildConfigurationTask.CreateFor(simulation, shouldValidate: false, createAgingDataInSimulation: false));
        }
Exemplo n.º 3
0
        private async Task exportToFolder(string exportFolder)
        {
            var project    = new Project();
            var individual = await _snapshotObjectCreator.DefaultIndividual();

            project.Individuals = new[] { individual };

            var compound = await _snapshotObjectCreator.StandardCompound(lipophilicity : 3, fractionUnbound : 0.1, molWeight : 400, name : "Standard Molecule");

            compound.Name     = "Standard Molecule";
            project.Compounds = new[] { compound };

            var intrevanousBolusMgPerKg = await _snapshotObjectCreator.SimpleProtocol(dose : 1, doseUnit : "mg/kg", applicationType : ApplicationTypes.IntravenousBolus);

            var intrevanousBolusMg = await _snapshotObjectCreator.SimpleProtocol(dose : 1, doseUnit : "mg", applicationType : ApplicationTypes.IntravenousBolus);

            project.Protocols = new[] { intrevanousBolusMgPerKg, intrevanousBolusMg };

            var snapshotConfiguration = new SimulationConstruction
            {
                Individual = individual,
                Compounds  = new[] { compound },
                Protocols  = new [] { intrevanousBolusMgPerKg },
                ModelName  = CoreConstants.Model.FourComp,
            };

            var fourCompIvBolusMgPerKg = await configurationFrom(snapshotConfiguration);

            snapshotConfiguration.ModelName = CoreConstants.Model.TwoPores;
            var twoPore = await configurationFrom(snapshotConfiguration);

            snapshotConfiguration.Protocols = new[] { intrevanousBolusMg };
            snapshotConfiguration.ModelName = CoreConstants.Model.FourComp;
            var fourCompIvBolusMg = await configurationFrom(snapshotConfiguration);


            twoPore.SpatialStructure.Name  = "Human 2 Pores";
            twoPore.PassiveTransports.Name = "2 Pores Passive Transports";

            fourCompIvBolusMgPerKg.SpatialStructure.Name  = "Human Standard";
            fourCompIvBolusMgPerKg.PassiveTransports.Name = "Standard Passive Transports";
            fourCompIvBolusMgPerKg.EventGroups.Name       = "IV Bolus";
            fourCompIvBolusMgPerKg.Molecules.Name         = "Standard Molecule";
            fourCompIvBolusMgPerKg.Observers.Name         = "Standard Observer";


            fourCompIvBolusMg.EventGroups.Name = "IV Bolus (mg)";

            var defaultCompound = fourCompIvBolusMgPerKg.Molecules.First();

            defaultCompound.Name = string.Empty;
            defaultCompound.Parameter(CoreConstants.Parameters.LIPOPHILICITY).Value    = double.NaN;
            defaultCompound.Parameter(CoreConstants.Parameters.MOLECULAR_WEIGHT).Value = double.NaN;
            defaultCompound.Parameter(CoreConstants.Parameters.FRACTION_UNBOUND_PLASMA_REFERENCE_VALUE).Value = double.NaN;
            defaultCompound.Parameter(CoreConstants.Parameters.SOLUBILITY_AT_REFERENCE_PH).Value = double.NaN;

            _moBiExportTask.UpdateObserverForAllFlag(fourCompIvBolusMgPerKg.Observers);

            var buildingBlocks = new IBuildingBlock[]
            {
                twoPore.SpatialStructure,
                twoPore.PassiveTransports,
                fourCompIvBolusMgPerKg.SpatialStructure,
                fourCompIvBolusMgPerKg.PassiveTransports,
                fourCompIvBolusMgPerKg.EventGroups,
                fourCompIvBolusMgPerKg.Molecules,
                fourCompIvBolusMgPerKg.Observers,
                fourCompIvBolusMg.EventGroups
            };

            buildingBlocks.Each(bb => saveToPKML(bb, exportFolder));
        }
Exemplo n.º 4
0
        public SimulationForBatch MapFrom(Simulation batchSimulation)
        {
            var individual = _individualMapper.MapFrom(batchSimulation.Individual);
            var compounds  = batchSimulation.Compounds.Select(_compoundMapper.MapFrom).ToList();
            var protocols  = batchSimulation.ApplicationProtocols.Select(_protocolMapper.MapFrom).ToList();

            var protocolForCompound = new Cache <Model.Compound, Protocol>();

            foreach (var applicationProtocol in batchSimulation.ApplicationProtocols)
            {
                var protocol = _protocolMapper.MapFrom(applicationProtocol);
                var compound = compounds.FindByName(applicationProtocol.CompoundName);
                if (compound != null)
                {
                    protocolForCompound.Add(compound, protocol);
                }
            }

            //if protocol for compound is not empty, that means that name were specified explictely in json file and we should use that
            var protocolToUse = protocolForCompound.Any() ? protocolForCompound.ToList() : protocols;

            //a requirement is that compounds and protocols have the same length. Fill missing entries with null
            while (protocolToUse.Count < compounds.Count)
            {
                protocolToUse.Add(null);
            }

            var modelProperties = _modelPropertiesMapper.MapFrom(batchSimulation.Configuration, individual);
            var formulation     = _formulationMapper.MapFrom(batchSimulation.Formulation);

            var simulationConstruction = new SimulationConstruction
            {
                SimulationSubject   = individual,
                TemplateCompounds   = compounds,
                TemplateProtocols   = protocols,
                TemplateFormulation = formulation,
                ModelProperties     = modelProperties,
                SimulationName      = Simulation.Name,
                AllowAging          = batchSimulation.Configuration.AllowAging,
                Interactions        = batchSimulation.Interactions
            };

            var simulation = _simulationConstructor
                             .CreateSimulation(simulationConstruction)
                             .DowncastTo <IndividualSimulation>();


            var config   = batchSimulation.Configuration;
            var interval = simulation.OutputSchema.Intervals.First();

            //remove old ones
            foreach (var otherInterval in simulation.OutputSchema.Intervals.Skip(1).ToList())
            {
                simulation.OutputSchema.RemoveInterval(otherInterval);
            }

            interval.StartTime.Value  = config.StartTime;
            interval.EndTime.Value    = config.EndTime;
            interval.Resolution.Value = config.Resolution;
            simulation.Solver.AbsTol  = config.AbsTol;
            simulation.Solver.RelTol  = config.RelTol;

            _logger.AddDebug($"Start Time = {config.StartTime}");
            _logger.AddDebug($"End Time = {config.EndTime}");
            _logger.AddDebug($"Resolution = {config.Resolution}");
            _logger.AddDebug($"AbsTol = {config.AbsTol}");
            _logger.AddDebug($"RelTol = {config.RelTol}");
            _logger.AddDebug($"UseJacobian = {config.UseJacobian}");

            var simForBatch = new SimulationForBatch
            {
                Simulation    = simulation,
                Configuration = config
            };

            simForBatch.ParameterVariationSets.AddRange(batchSimulation.ParameterVariationSets);

            return(simForBatch);
        }