public Simulation CreateSimulation(SimulationConstruction simulationConstruction, Action <Simulation> preModelCreationAction = null)
        {
            var sim = CreateModelLessSimulationWith(simulationConstruction);

            preModelCreationAction?.Invoke(sim);

            AddModelToSimulation(sim);
            return(sim);
        }
        public Simulation CreateModelLessSimulationWith(SimulationConstruction simulationConstruction)
        {
            var sim = _simulationFactory.CreateFrom(simulationConstruction.SimulationSubject, simulationConstruction.TemplateCompounds, simulationConstruction.ModelProperties);

            sim.Name = simulationConstruction.SimulationName;

            for (int index = 0; index < simulationConstruction.TemplateCompounds.Count; index++)
            {
                var compoundProperties = sim.CompoundPropertiesList[index];
                var compound           = compoundProperties.Compound;

                //for now: only simple protocol
                var simpleProtocol = simulationConstruction.TemplateProtocols[index] as SimpleProtocol;
                if (simpleProtocol != null && simpleProtocol.ApplicationType.NeedsFormulation && simulationConstruction.TemplateFormulation != null)
                {
                    simpleProtocol.FormulationKey = simulationConstruction.TemplateFormulation.Name;
                    compoundProperties.ProtocolProperties.AddFormulationMapping(new FormulationMapping {
                        FormulationKey = simulationConstruction.TemplateFormulation.Name, TemplateFormulationId = simulationConstruction.TemplateFormulation.Id
                    });
                }

                var processes = compoundProperties.Processes;

                //add all systemic processes
                addSystemicProcesses(compound, processes.MetabolizationSelection, SystemicProcessTypes.Hepatic);
                addSystemicProcesses(compound, processes.TransportAndExcretionSelection, SystemicProcessTypes.GFR);
                addSystemicProcesses(compound, processes.TransportAndExcretionSelection, SystemicProcessTypes.Renal);
                addSystemicProcesses(compound, processes.TransportAndExcretionSelection, SystemicProcessTypes.Biliary);

                //add all partial processes
                var individual = simulationConstruction.SimulationSubject as Individual ?? simulationConstruction.SimulationSubject.DowncastTo <Population>().FirstIndividual;

                addPartialProcesses <EnzymaticProcess, IndividualEnzyme, EnzymaticProcessSelection>(compound, individual, processes.MetabolizationSelection);
                addPartialProcesses <TransportPartialProcess, IndividualTransporter, ProcessSelection>(compound, individual, processes.TransportAndExcretionSelection);
                addPartialProcesses <SpecificBindingPartialProcess, IndividualMolecule, ProcessSelection>(compound, individual, processes.SpecificBindingSelection);

                _buildingBlockUpdater.UpdateMultipleUsedBuildingBlockInSimulationFromTemplate(sim, simulationConstruction.TemplateProtocols.Where(p => p != null), PKSimBuildingBlockType.Protocol);

                var templateProtocol = simulationConstruction.TemplateProtocols[index];
                if (templateProtocol != null)
                {
                    compoundProperties.ProtocolProperties.Protocol = sim.AllBuildingBlocks <Protocol>().FindByName(templateProtocol.Name);
                }

                if (simulationConstruction.TemplateFormulation != null)
                {
                    _buildingBlockUpdater.UpdateMultipleUsedBuildingBlockInSimulationFromTemplate(sim, new[] { simulationConstruction.TemplateFormulation }, PKSimBuildingBlockType.Formulation);
                }
            }

            simulationConstruction.Interactions.Each(sim.InteractionProperties.AddInteraction);
            sim.AllowAging = simulationConstruction.AllowAging;
            return(sim);
        }
Exemple #3
0
        public static Simulation CreateModelLessSimulationWith(ISimulationSubject simulationSubject, IReadOnlyList <Compound> compounds, IReadOnlyList <Protocol> protocols
                                                               , ModelProperties modelProperties, bool allowAging = false)
        {
            var simConstructor         = IoC.Resolve <ISimulationConstructor>();
            var simulationConstruction = new SimulationConstruction
            {
                SimulationSubject = simulationSubject,
                TemplateCompounds = compounds,
                TemplateProtocols = protocols,
                ModelProperties   = modelProperties,
                SimulationName    = "simulation",
                AllowAging        = allowAging,
            };

            return(simConstructor.CreateModelLessSimulationWith(simulationConstruction));
        }