예제 #1
0
        public IReadOnlyList <IBuildingBlockSnapshot> BuildingBlocksByType(PKSimBuildingBlockType buildingBlockType)
        {
            switch (buildingBlockType)
            {
            case PKSimBuildingBlockType.ExpressionProfile:
                return(ExpressionProfiles);

            case PKSimBuildingBlockType.Compound:
                return(Compounds);

            case PKSimBuildingBlockType.Formulation:
                return(Formulations);

            case PKSimBuildingBlockType.Protocol:
                return(Protocols);

            case PKSimBuildingBlockType.Individual:
                return(Individuals);

            case PKSimBuildingBlockType.Population:
                return(Populations);

            case PKSimBuildingBlockType.Event:
                return(Events);

            case PKSimBuildingBlockType.Simulation:
                return(Simulations);

            case PKSimBuildingBlockType.ObserverSet:
                return(ObserverSets);

            default:
                return(null);
            }
        }
예제 #2
0
 public IReadOnlyList <TBuildingBlock> LoadFromSnapshot <TBuildingBlock>(PKSimBuildingBlockType buildingBlockType) where TBuildingBlock : class, IPKSimBuildingBlock
 {
     using (var presenter = _applicationController.Start <ILoadFromSnapshotPresenter <TBuildingBlock> >())
     {
         var buildingBlocks = presenter.LoadModelFromSnapshot();
         return(addBuildingBlocksToProject(buildingBlocks).ToList());
     }
 }
예제 #3
0
        public async Task <T> LoadModelFromProjectFileAsync <T>(string fileName, PKSimBuildingBlockType buildingBlockType, string buildingBlockName)
        {
            var projectSnapshot = await LoadSnapshotFromFileAsync <Project>(fileName);

            var snapshot = projectSnapshot.BuildingBlockByTypeAndName(buildingBlockType, buildingBlockName);

            return(await loadModelFromSnapshot <T>(snapshot));
        }
예제 #4
0
        private IParameter create(PKSimBuildingBlockType buildingBlockType)
        {
            var parameter = A.Fake <IParameter>();

            parameter.CanBeVaried             = false;
            parameter.CanBeVariedInPopulation = false;
            A.CallTo(() => parameter.BuildingBlockType).Returns(buildingBlockType);
            return(parameter);
        }
예제 #5
0
        private TemplateType typeFrom(PKSimBuildingBlockType buildingBlockType)
        {
            if (buildingBlockType == PKSimBuildingBlockType.SimulationSubject)
            {
                return(TemplateType.Individual | TemplateType.Population);
            }

            return(EnumHelper.ParseValue <TemplateType>(buildingBlockType.ToString()));
        }
예제 #6
0
        public IReadOnlyList <TBuildingBlock> LoadFromTemplate <TBuildingBlock>(PKSimBuildingBlockType buildingBlockType) where TBuildingBlock : class, IPKSimBuildingBlock
        {
            using (var presenter = _applicationController.Start <ITemplatePresenter>())
            {
                var buildingBlocks = presenter.LoadFromTemplate <TBuildingBlock>(typeFrom(buildingBlockType));

                return(addBuildingBlocksToProject(buildingBlocks).ToList());
            }
        }
예제 #7
0
 private static bool canFilterUnchangedParameters(PKSimBuildingBlockType buildingBlockType)
 {
     //Exclude Protocol for now because of the 1to n relationship between building block parameters and simulation parameters
     return(buildingBlockType.IsOneOf(
                PKSimBuildingBlockType.Compound,
                PKSimBuildingBlockType.Formulation,
                PKSimBuildingBlockType.Individual,
                PKSimBuildingBlockType.Event,
                PKSimBuildingBlockType.Population));
 }
예제 #8
0
 public ParameterInfo()
 {
     //Min value and Max value should be initialized to null to avoid serialization issues
     CanBeVaried       = true;
     MinValue          = null;
     MinIsAllowed      = false;
     MaxValue          = null;
     MaxIsAllowed      = false;
     Visible           = true;
     GroupName         = Constants.Groups.UNDEFINED;
     Sequence          = 1;
     ReferenceId       = 0;
     BuildingBlockType = PKSimBuildingBlockType.Simulation;
 }
예제 #9
0
        protected override IReadOnlyList <Compound> LoadFromTemplate(PKSimBuildingBlockType buildingBlockType)
        {
            var loadedCompounds = base.LoadFromTemplate(buildingBlockType);

            if (loadedCompounds.Count <= 1)
            {
                return(loadedCompounds);
            }

            //one compound and one or more metabolites
            warnUserIfMetabolitesDoNotMatch(loadedCompounds);

            return(loadedCompounds);
        }
예제 #10
0
        private string getContainerPathToRename(PKSimBuildingBlockType buildingBlockType)
        {
            switch (buildingBlockType)
            {
            case PKSimBuildingBlockType.Formulation:
            case PKSimBuildingBlockType.Protocol:
                return(Constants.APPLICATIONS);

            case PKSimBuildingBlockType.Event:
                return(Constants.EVENTS);

            default:
                throw new ArgumentOutOfRangeException("buildingBlockType");
            }
        }
예제 #11
0
        public IReadOnlyList <TBuildingBlock> LoadFromTemplate <TBuildingBlock>(PKSimBuildingBlockType buildingBlockType) where TBuildingBlock : class, IPKSimBuildingBlock
        {
            var loadedBuildingBlocks = new List <TBuildingBlock>();

            using (var presenter = _applicationController.Start <ITemplatePresenter>())
            {
                var buildingBlocks = presenter.LoadFromTemplate <TBuildingBlock>(typeFrom(buildingBlockType));

                buildingBlocks.Each(bb =>
                {
                    var command = AddToProject(bb, editBuildingBlock: false);
                    if (!command.IsEmpty())
                    {
                        loadedBuildingBlocks.Add(bb);
                    }
                });

                return(loadedBuildingBlocks);
            }
        }
예제 #12
0
 public IParameter CreateFor(string parameterName, double defaultValue, PKSimBuildingBlockType buildingBlockType)
 {
     return(CreateFor(parameterName, defaultValue, Constants.Dimension.DIMENSIONLESS, buildingBlockType));
 }
예제 #13
0
 public IParameter CreateFor(string parameterName, PKSimBuildingBlockType buildingBlockType)
 {
     return(CreateFor(parameterName, double.NaN, buildingBlockType));
 }
예제 #14
0
 public UsedBuildingBlock(string templateId, PKSimBuildingBlockType buildingBlockType)
 {
     TemplateId        = templateId;
     BuildingBlockType = buildingBlockType;
 }
 public static bool IsOneOf(this PKSimBuildingBlockType buildingBlockType, params PKSimBuildingBlockType[] typesToCompare)
 {
     return(typesToCompare.Any(b => buildingBlockType.Is(b)));
 }
예제 #16
0
        public void UpdateUsedBuildingBlockInSimulationFromTemplate(Simulation simulation, IPKSimBuildingBlock templateBuildingBlock, PKSimBuildingBlockType buildingBlockType)
        {
            if (!templateBuildingBlockCanBeUpdatedAsSingle(buildingBlockType))
            {
                throw new ArgumentException($"Should not call this function with a building block of type '{buildingBlockType}'");
            }

            var previousUsedBuildingBlock = simulation.UsedBuildingBlockInSimulation(buildingBlockType);
            var newUsedBuildingBlock      = _buildingBlockMapper.MapFrom(templateBuildingBlock, previousUsedBuildingBlock);

            simulation.RemoveUsedBuildingBlock(previousUsedBuildingBlock);
            simulation.AddUsedBuildingBlock(newUsedBuildingBlock);
        }
예제 #17
0
 protected PKSimBuildingBlock(PKSimBuildingBlockType buildingBlockType) : this()
 {
     _buildingBlockType = buildingBlockType;
     Icon = buildingBlockType.ToString();
 }
        /// <summary>
        ///    Update parameter values from the used building block into the simulationm
        /// </summary>
        /// <param name="usedBuildingBlockParameters">All used building blocks parameters</param>
        /// <param name="simulation">simulation for which parameters should be updated</param>
        /// <param name="buildingBlockType">Type of parameters to update</param>
        private IEnumerable <ICommand> updateParameterValues(IEnumerable <IParameter> usedBuildingBlockParameters, Simulation simulation, PKSimBuildingBlockType buildingBlockType)
        {
            var simulationParameterCache = new Cache <string, List <IParameter> >(onMissingKey: x => new List <IParameter>());

            foreach (var parameter in simulation.ParametersOfType(buildingBlockType))
            {
                var originParameterId = parameter.Origin.ParameterId;
                if (!simulationParameterCache.Contains(originParameterId))
                {
                    simulationParameterCache[originParameterId] = new List <IParameter>();
                }

                simulationParameterCache[originParameterId].Add(parameter);
            }

            return(from parameter in usedBuildingBlockParameters.OrderBy(x => x.IsDistributed())
                   let simParams = simulationParameterCache[parameter.Id]
                                   from simParam in simParams
                                   select _parameterSetUpdater.UpdateValue(parameter, simParam));
        }
 private void addUsedBuildingBlock(Simulation simulation, ITreeNode simulationNode, PKSimBuildingBlockType buildingBlockType)
 {
     foreach (var usedBuildingBlock in simulation.UsedBuildingBlocksInSimulation(buildingBlockType))
     {
         _treeNodeFactory.CreateFor(simulation, usedBuildingBlock)
         .WithIcon(_buildingBlockIconRetriever.IconFor(usedBuildingBlock))
         .WithText(usedBuildingBlock.Name)
         .Under(simulationNode);
     }
 }
예제 #20
0
 private bool templateBuildingBlockCanBeUpdatedAsSingle(PKSimBuildingBlockType buildingBlockType)
 {
     return(buildingBlockType.IsOneOf(PKSimBuildingBlockType.Individual, PKSimBuildingBlockType.Population));
 }
예제 #21
0
 public static bool IsOfType(this IParameter parameter, PKSimBuildingBlockType buildingBlockType)
 {
     return(parameter.BuildingBlockType.Is(buildingBlockType));
 }
예제 #22
0
 /// <summary>
 ///    return all parameters defined with the given building block type
 /// </summary>
 public virtual IEnumerable <IParameter> ParametersOfType(PKSimBuildingBlockType buildingBlockType)
 {
     //Do not need neighborhood parameters, since neighborhood is defined a a child of root
     return(All <IParameter>().Where(p => p.IsOfType(buildingBlockType)));
 }
예제 #23
0
 /// <summary>
 ///    Returns the building block used in the simulation with the given building block type
 /// </summary>
 public virtual UsedBuildingBlock UsedBuildingBlockInSimulation(PKSimBuildingBlockType buildingBlockType)
 {
     return(UsedBuildingBlocksInSimulation(buildingBlockType).SingleOrDefault());
 }
예제 #24
0
        public void UpdateMultipleUsedBuildingBlockInSimulationFromTemplate(Simulation simulation, IEnumerable <IPKSimBuildingBlock> templateBuildingBlocks, PKSimBuildingBlockType buildingBlockType)
        {
            var allTemplates = templateBuildingBlocks.ToList();

            if (!allTemplates.Any())
            {
                simulation.RemoveAllBuildingBlockOfType(buildingBlockType);
            }

            if (!templateBuildingBlockCanBeUpdatedAsMultiple(buildingBlockType))
            {
                throw new ArgumentException($"Should not call this function with a building block of type '{buildingBlockType}'");
            }

            //templateBuildingBlocks contains all the building block that have been selected
            //remove the one that are not used anymore . Used to list to remove while looping
            foreach (var usedBuildingBlock in simulation.UsedBuildingBlocksInSimulation(buildingBlockType).ToList())
            {
                //template is used, continue
                if (allTemplates.ExistsById(usedBuildingBlock.TemplateId))
                {
                    continue;
                }

                //user defined building block reused?
                if (allTemplates.ExistsById(usedBuildingBlock.Id))
                {
                    continue;
                }

                simulation.RemoveUsedBuildingBlock(usedBuildingBlock);
            }

            allTemplates.Each(bb => addUsedBuildingBlockToSimulation(simulation, bb));
        }
예제 #25
0
        public IParameter CreateFor(string parameterName, double defaultValue, string dimensionName, PKSimBuildingBlockType buildingBlockType)
        {
            var parameterValueDefinition = new ParameterValueMetaData
            {
                ParameterName     = parameterName,
                DefaultValue      = defaultValue,
                Dimension         = dimensionName,
                BuildingBlockType = buildingBlockType,
            };

            return(CreateFor(parameterValueDefinition));
        }
예제 #26
0
 public IBuildingBlockSnapshot BuildingBlockByTypeAndName(PKSimBuildingBlockType buildingBlockType, string name) =>
 BuildingBlocksByType(buildingBlockType)?.FindByName(name);
예제 #27
0
        public virtual string BuildingBlockName(PKSimBuildingBlockType buildingBlockType)
        {
            var usedBuildingBlock = UsedBuildingBlockInSimulation(buildingBlockType);

            return(usedBuildingBlock == null ? string.Empty : usedBuildingBlock.Name);
        }
예제 #28
0
 private bool templateBuildingBlockCanBeUpdatedAsMultiple(PKSimBuildingBlockType buildingBlockType)
 {
     return(!templateBuildingBlockCanBeUpdatedAsSingle(buildingBlockType));
 }
예제 #29
0
        /// <summary>
        ///    Remove the building blocks as used in the simulation by type
        /// </summary>
        public virtual void RemoveAllBuildingBlockOfType(PKSimBuildingBlockType buildingBlockType)
        {
            var allBuildingBlocksOfType = _usedBuildingBlocks.Where(x => x.BuildingBlockType.Is(buildingBlockType)).ToList();

            allBuildingBlocksOfType.Each(RemoveUsedBuildingBlock);
        }
예제 #30
0
 /// <summary>
 ///    Returns all the buildng block with the given type used in the simulation
 /// </summary>
 public virtual IEnumerable <UsedBuildingBlock> UsedBuildingBlocksInSimulation(PKSimBuildingBlockType buildingBlockType)
 {
     return(from usedBuildingBlock in UsedBuildingBlocks
            where usedBuildingBlock.BuildingBlockType.Is(buildingBlockType)
            select usedBuildingBlock);
 }