Exemplo n.º 1
0
        private void createNonApplicationEvents()
        {
            // group events by the event-building block they are using
            var eventBuildingBlockInfos = (from eventMapping in _simulation.EventProperties.EventMappings
                                           let usedBuildingBlock = _simulation.UsedBuildingBlockByTemplateId(eventMapping.TemplateEventId)
                                                                   let eventBuildingBlock = usedBuildingBlock.BuildingBlock.DowncastTo <PKSimEvent>()
                                                                                            select new { eventBuildingBlock.Id, eventBuildingBlock.TemplateName, eventBuildingBlock.Name })
                                          .Distinct();

            // create event groups for each used event-building block
            foreach (var eventBuildingBlockInfo in eventBuildingBlockInfos)
            {
                // get event group template
                var templateEventGroup = _eventGroupRepository.FindByName(eventBuildingBlockInfo.TemplateName);

                // create new event group
                var eventGroup = _cloneManagerForBuildingBlock.Clone(templateEventGroup);
                eventGroup.Name = eventBuildingBlockInfo.Name;
                eventGroup.RemoveChild(eventGroup.MainSubContainer());

                // get building block and eventgroup-template to be used
                var eventBuildingBlock = _simulation.UsedBuildingBlockById(eventBuildingBlockInfo.Id);
                var eventTemplate      = eventBuildingBlock.BuildingBlock.DowncastTo <PKSimEvent>();

                // set event group parameter
                _parameterSetUpdater.UpdateValuesByName(eventTemplate, eventGroup);

                // create subcontainers (event groups) for all events of the same type
                int eventIndex = 0; //used for naming of event subcontainers only

                foreach (var eventMapping in _simulation.EventProperties.EventMappings.OrderBy(em => em.StartTime.Value))
                {
                    if (!eventMapping.TemplateEventId.Equals(eventBuildingBlock.TemplateId))
                    {
                        continue; //event from different template
                    }
                    // clone main event subcontainer and set its start time
                    var mainSubContainer = _cloneManagerForBuildingBlock.Clone(templateEventGroup.MainSubContainer());

                    eventIndex           += 1;
                    mainSubContainer.Name = $"{eventBuildingBlockInfo.Name}_{eventIndex}";

                    _parameterSetUpdater.UpdateValue(eventMapping.StartTime, mainSubContainer.StartTime());

                    eventGroup.Add(mainSubContainer);
                }

                // update building block ids
                _parameterIdUpdater.UpdateBuildingBlockId(eventGroup, eventTemplate);

                _eventGroupBuildingBlock.Add(eventGroup);
            }
        }
Exemplo n.º 2
0
        private void updateParameterFromIndividual(ISpatialStructure spatialStructure, Individual individual)
        {
            //Update parameter values for parameter that have been changed in individual
            var allIndividualParameter    = new PathCache <IParameter>(_entityPathResolver).For(individual.GetAllChildren <IParameter>());
            var allContainerParameters    = new PathCache <IParameter>(_entityPathResolver).For(spatialStructure.TopContainers.SelectMany(x => x.GetAllChildren <IParameter>()));
            var allNeighborhoodParameters = new PathCache <IParameter>(_entityPathResolver).For(spatialStructure.Neighborhoods.SelectMany(x => x.GetAllChildren <IParameter>()));

            _parameterSetUpdater.UpdateValues(allIndividualParameter, allContainerParameters);
            _parameterSetUpdater.UpdateValues(allIndividualParameter, allNeighborhoodParameters);
            _parameterIdUpdater.UpdateBuildingBlockId(allContainerParameters, individual);
            _parameterIdUpdater.UpdateBuildingBlockId(allNeighborhoodParameters, individual);
        }
Exemplo n.º 3
0
        private void addMolecule(IndividualMolecule individualMolecule)
        {
            var molecule = _moleculeBuilderFactory.Create(individualMolecule.MoleculeType, _moleculeBuildingBlock.FormulaCache)
                           .WithName(individualMolecule.Name)
                           .WithIcon(individualMolecule.Icon);

            addMoleculeToBuildingBlock(molecule, null);

            //Update protein builder parameters with the parameter ids
            _parameterSetUpdater.UpdateValuesByName(individualMolecule, molecule.Parameters);

            //Update the building block ids
            _parameterIdUpdater.UpdateBuildingBlockId(molecule.Parameters, _individual);
        }
Exemplo n.º 4
0
        private void updateParameterOrginInSimulation(Simulation simulation)
        {
            var allParameters = simulation.Model.Root.GetAllChildren <IParameter>()
                                .Where(x => !string.IsNullOrEmpty(x.Origin.BuilingBlockId)).ToList();

            var allParametersGroupByBuildingBlockId = allParameters.GroupBy(x => x.Origin.BuilingBlockId);

            foreach (var parametersByBuildingBlockId in allParametersGroupByBuildingBlockId)
            {
                var usedBuildingBlock = _usedBuildingBlockCache[parametersByBuildingBlockId.Key];
                if (usedBuildingBlock != null)
                {
                    _parameterIdUpdater.UpdateBuildingBlockId(parametersByBuildingBlockId, usedBuildingBlock.BuildingBlock);
                }
                else
                {
                    _parameterIdUpdater.ResetParameterOrigin(parametersByBuildingBlockId);
                }
            }

            allParameters.Where(p => !string.IsNullOrEmpty(p.Origin.ParameterId))
            .Each(updateParameterOrigin);

            _parameterIdUpdater.UpdateSimulationId(simulation);
        }
Exemplo n.º 5
0
        public IMoleculeBuilder Create(Compound compound, CompoundProperties compoundProperties, InteractionProperties interactionProperties, IFormulaCache formulaCache)
        {
            var drug = Create(QuantityType.Drug, formulaCache).WithName(compound.Name);

            //first update all parameters defined in the molecule that are also in the compound and that DO NOT belong in one alternative
            _parameterSetUpdater.UpdateValuesByName(allSimpleParametersFrom(compound), drug.AllParameters());

            //once simple parameters have been set, set the alternative parameters
            updateAlternativeParameters(compound, compoundProperties, drug, formulaCache);

            //add interaction parameters
            addInteractionParameters(compound, drug, interactionProperties);

            _parameterIdUpdater.UpdateBuildingBlockId(drug.GetAllChildren <IParameter>(), compound);
            return(drug);
        }