protected override void Because()
        {
            var compoundName = _simulation.CompoundNames.First();
            var parameter    = _simulation.Model.Root.EntityAt <IParameter>(compoundName, CoreConstantsForSpecs.Parameters.BLOOD_PLASMA_CONCENTRATION_RATIO);

            parameter.Value = 10;
            _parameterPath  = _entityPathResolver.ObjectPathFor(parameter);
            _psv            = _buildConfigurationTask.CreateFor(_simulation, shouldValidate: true, createAgingDataInSimulation: false).ParameterStartValues;
        }
예제 #2
0
        private IParameterStartValue getOrCreateStartValueFor(IParameter parameter)
        {
            var parameterPath       = _entityPathResolver.ObjectPathFor(parameter);
            var parameterStartValue = _defaultStartValues[parameterPath];

            if (parameterStartValue != null)
            {
                return(parameterStartValue);
            }

            parameterStartValue = _parameterStartValuesCreator.CreateParameterStartValue(parameterPath, parameter);
            _defaultStartValues.Add(parameterStartValue);

            return(parameterStartValue);
        }
예제 #3
0
        private TMoleculeExpressionContainer addContainerExpression(TMolecule protein, IContainer container, string name, string groupingName)
        {
            var expressionContainer = addContainerExpression(protein, name, groupingName);

            expressionContainer.OrganPath = _entityPathResolver.ObjectPathFor(container);
            return(expressionContainer);
        }
예제 #4
0
        private void updateAllParametersFor(Simulation simulation, Individual individual, IList <IContainer> allOrganismContainers, IndividualMolecule molecule, PathCache <IMoleculeAmount> moleculeAmountPath)
        {
            var globalMoleculeContainer = simulation.Model.Root
                                          .GetSingleChildByName <IContainer>(molecule.Name);

            globalMoleculeContainer.Parameter(CoreConstants.Parameter.ONTOGENY_FACTOR_GI).Visible = false;
            globalMoleculeContainer.Parameter(CoreConstants.Parameter.ONTOGENY_FACTOR).Visible    = false;

            hideGlobalParametersForUndefinedMolecule(globalMoleculeContainer);

            foreach (var expressionContainer in molecule.AllExpressionsContainers())
            {
                var relExpNorm = expressionContainer.RelativeExpressionNormParameter;
                var relExp     = expressionContainer.RelativeExpressionParameter;

                if (expressionContainer.IsSurrogate())
                {
                    string relExpName;
                    if (expressionContainer.IsBloodCell())
                    {
                        relExpName = CoreConstants.Parameter.RelExpBloodCell;
                    }
                    else if (expressionContainer.IsPlasma())
                    {
                        relExpName = CoreConstants.Parameter.RelExpPlasma;
                    }
                    else if (expressionContainer.IsVascularEndothelium())
                    {
                        relExpName = CoreConstants.Parameter.RelExpVascEndo;
                    }
                    else
                    {
                        continue;
                    }

                    string relExpNormName = CoreConstants.Parameter.NormParameterFor(relExpName);
                    updateFromIndividualParameter(globalMoleculeContainer.Parameter(relExpName), relExp, individual, molecule);
                    updateFromIndividualParameter(globalMoleculeContainer.Parameter(relExpNormName), relExpNorm, individual, molecule);
                }
                else
                {
                    //not a global parameter simply update the norm  parameters
                    var allContainers = _expressionContainersRetriever.AllContainersFor(individual.Organism, allOrganismContainers, molecule, expressionContainer);
                    foreach (var container in allContainers)
                    {
                        var amount = moleculeAmountPath[_entityPathResolver.ObjectPathFor(container).AndAdd(molecule.Name).ToString()];
                        if (amount == null)
                        {
                            continue;
                        }

                        updateFromIndividualParameter(amount.Parameter(CoreConstants.Parameter.RelExpNorm), relExpNorm, individual, molecule);
                        updateFromIndividualParameter(amount.Parameter(CoreConstants.Parameter.RelExp), relExp, individual, molecule);
                    }
                }
            }
        }
        private bool isParameterStartValue(IQuantity changedQuantity, IMoBiBuildConfiguration buildConfiguration)
        {
            if (!changedQuantity.IsAnImplementationOf <IParameter>())
            {
                return(false);
            }

            var parameterStartValues = buildConfiguration.ParameterStartValues;
            var path = _entityPathResolver.ObjectPathFor(changedQuantity);

            return(parameterStartValues.Any(psv => Equals(psv.Path, path)));
        }
        private IFormulaUsablePath objectPathFor(IFormulaUsable referencedObject, IFormulaUsablePath originalObjectPath)
        {
            if (referencedObject == null)
            {
                return(originalObjectPath);
            }

            var consolidatedPath = _entityPathResolver.ObjectPathFor(referencedObject);

            return(_objectPathFactory.CreateFormulaUsablePathFrom(consolidatedPath)
                   .WithAlias(originalObjectPath.Alias)
                   .WithDimension(originalObjectPath.Dimension));
        }
예제 #7
0
        protected override void Context()
        {
            _affectedBuildingBlockRetriever = A.Fake <IAffectedBuildingBlockRetriever>();
            _entityPathResolver             = A.Fake <IEntityPathResolver>();
            _context = A.Fake <IMoBiContext>();
            sut      = new QuantitySynchronizer(_affectedBuildingBlockRetriever, _entityPathResolver, _context);

            _simulation        = A.Fake <IMoBiSimulation>();
            _buildingBlockInfo = A.Fake <IBuildingBlockInfo>();
            _objectPath        = new ObjectPath("P");
            A.CallTo(() => _entityPathResolver.ObjectPathFor(_parameter, false)).Returns(_objectPath);
            A.CallTo(() => _entityPathResolver.PathFor(_parameter)).Returns("P");
            A.CallTo(() => _affectedBuildingBlockRetriever.RetrieveFor(_quantity, _simulation)).Returns(_buildingBlockInfo);
        }
        private IParameterStartValue trySetValue(IParameter parameter)
        {
            var parameterPath = _entityPathResolver.ObjectPathFor(parameter);

            if (_defaultStartValues[parameterPath] != null)
            {
                return(trySetValue(parameterPath, parameter));
            }

            var parameterStartValue = _parameterStartValuesCreator.CreateParameterStartValue(parameterPath, parameter);

            _defaultStartValues.Add(parameterStartValue);
            return(parameterStartValue);
        }
예제 #9
0
        private void addParametersToDataTable(IParameter parameter, DataTable dt)
        {
            var path = _resolver.ObjectPathFor(parameter);

            path.RemoveAt(path.Count - 1);
            var row = dt.Rows.Add();

            row[_path]        = path;
            row[_name]        = parameter.Name;
            row[_value]       = parameter.ConvertToDisplayUnit(parameter.Value);
            row[_formula]     = (parameter.Formula.IsConstant() || parameter.Formula == null) ? (object)string.Empty : parameter.Formula;
            row[_rhsFormula]  = parameter.RHSFormula ?? (object)string.Empty;
            row[_unit]        = parameter.DisplayUnit;
            row[_description] = parameter.Description;
        }
예제 #10
0
        private IEnumerable <IObjectPath> moleculesInvolvedInExpression(Individual individual, IndividualMolecule molecule,
                                                                        IReadOnlyList <CompoundProperties> compoundPropertiesList)
        {
            foreach (var container in individual.AllPhysicalContainersWithMoleculeFor(molecule))
            {
                var containerPath = _entityPathResolver.ObjectPathFor(container);

                foreach (var compoundProperties in compoundPropertiesList)
                {
                    foreach (var moleculeName in compoundProperties.Processes.AllInducedMoleculeNames(molecule))
                    {
                        yield return(containerPath.Clone <IObjectPath>().AndAdd(moleculeName));
                    }
                }
            }
        }
예제 #11
0
        private void updateParameterDTOFromParameter(ParameterDTO parameterDTO, IParameter parameter)
        {
            var parameterPath      = _entityPathResolver.ObjectPathFor(parameter);
            var representationInfo = _representationInfoRepository.InfoFor(parameter);

            parameterDTO.DisplayName  = representationInfo.DisplayName;
            parameterDTO.Description  = representationInfo.Description;
            parameterDTO.AllUnits     = allUnitsFor(parameter);
            parameterDTO.FormulaType  = _formulaTypeMapper.MapFrom(parameter.Formula);
            parameterDTO.IsFavorite   = _favoriteRepository.Contains(parameterPath);
            parameterDTO.Sequence     = parameter.Sequence;
            parameterDTO.PathElements = _parameterDisplayPathMapper.MapFrom(parameter);

            //now create special list of values for parameter for our discrete parameters
            updateListOfValues(parameterDTO, parameter);
        }
        protected override void Context()
        {
            _parameterStartValueBuildingBlock = new ParameterStartValuesBuildingBlock().WithId("PSVBB");
            _objectPath = new ObjectPath("A", "B", "P");
            _parameter  = A.Fake <IParameter>().WithName("P").WithId("P");
            sut         = new AddParameterStartValueFromQuantityInSimulationCommand(_parameter, _parameterStartValueBuildingBlock);

            _context = A.Fake <IMoBiContext>();
            _parameterStartValuesCreator = A.Fake <IParameterStartValuesCreator>();
            _entityPathResolver          = A.Fake <IEntityPathResolver>();
            A.CallTo(() => _context.Resolve <IEntityPathResolver>()).Returns(_entityPathResolver);
            A.CallTo(() => _context.Resolve <IParameterStartValuesCreator>()).Returns(_parameterStartValuesCreator);
            A.CallTo(() => _context.Get <IParameter>(_parameter.Id)).Returns(_parameter);
            A.CallTo(() => _context.Get <IStartValuesBuildingBlock <IParameterStartValue> >(_parameterStartValueBuildingBlock.Id)).Returns(_parameterStartValueBuildingBlock);

            A.CallTo(() => _entityPathResolver.ObjectPathFor(_parameter, false)).Returns(_objectPath);
        }
예제 #13
0
        public void SynchronizeValue(IModelCoreSimulation simulation, IParameter parameter)
        {
            if (parameter == null)
            {
                return;
            }
            var parameterStartValues = simulation.BuildConfiguration.ParameterStartValues;
            var objectPath           = _entityPathResolver.ObjectPathFor(parameter);
            var parameterStartValue  = parameterStartValues[objectPath];

            if (parameterStartValue == null)
            {
                return;
            }

            parameterStartValue.StartValue  = parameter.Value;
            parameterStartValue.Dimension   = parameter.Dimension;
            parameterStartValue.DisplayUnit = parameter.DisplayUnit;
        }
        private void resetQuantity(IQuantity quantityToReset, IQuantity quantityUsedToFindPath, IMoBiContext context)
        {
            if (quantityUsedToFindPath == null)
            {
                return;
            }

            var objectPath = _entityPathResolver.ObjectPathFor(quantityUsedToFindPath);
            var startValue = _startValuesBuildingBlock[objectPath];

            if (startValue == null)
            {
                return;
            }

            quantityToReset.Formula      = defaultFormulaBasedOn(startValue);
            quantityToReset.IsFixedValue = false;

            context.PublishEvent(new QuantityChangedEvent(quantityToReset));
        }
예제 #15
0
        public IParameterDTO MapFrom(IParameter parameter)
        {
            var dto = new ParameterDTO(parameter);

            MapProperties(parameter, dto);
            dto.Formula                 = _formulaToDTOFormulaBuilderMapper.MapFrom(parameter.Formula);
            dto.RHSFormula              = _formulaToDTOFormulaBuilderMapper.MapFrom(parameter.RHSFormula);
            dto.BuildMode               = parameter.BuildMode;
            dto.Dimension               = parameter.Dimension;
            dto.HasRHS                  = (parameter.RHSFormula != null);
            dto.DisplayUnit             = parameter.Dimension.BaseUnit;
            dto.Group                   = _groupRepository.GroupByName(parameter.GroupName);
            dto.IsAdvancedParameter     = !parameter.Visible;
            dto.CanBeVariedInPopulation = parameter.CanBeVariedInPopulation;
            dto.PathElements            = _pathToPathElementsMapper.MapFrom(parameter);
            var parameterPath = _entityPathResolver.ObjectPathFor(parameter);

            dto.IsFavorite = _favoriteRepository.Contains(parameterPath);

            return(dto);
        }
예제 #16
0
        public virtual QuantitySelectionDTO MapFrom(IQuantity quantity, int sequence)
        {
            if (quantity == null)
            {
                return(null);
            }

            var quantityPath = _entityPathResolver.ObjectPathFor(quantity);
            var pathElements = _pathToPathElementsMapper.MapFrom(quantity);

            return(new QuantitySelectionDTO
            {
                QuantityPath = quantityPath.PathAsString,
                QuantityName = quantity.Name,
                QuantityType = quantity.QuantityType,
                Dimension = quantity.Dimension,
                Quantity = quantity,
                Sequence = sequence,
                PathElements = pathElements
            });
        }
예제 #17
0
        private IMoBiCommand synchronizeStartValueCommand <TStartValue>(IQuantity quantity, IStartValuesBuildingBlock <TStartValue> startValuesBuildingBlock, bool allowCreation,
                                                                        Func <TStartValue, IMoBiCommand> synchronizeStartValueCommandFunc, Func <IMoBiCommand> createStartValueCommandFunc) where TStartValue : class, IStartValue
        {
            if (quantity == null)
            {
                return(new MoBiEmptyCommand());
            }

            var objectPath = _entityPathResolver.ObjectPathFor(quantity);
            var startValue = startValuesBuildingBlock[objectPath];

            if (startValue != null)
            {
                return(synchronizeStartValueCommandFunc(startValue));
            }

            if (allowCreation)
            {
                return(createStartValueCommandFunc());
            }

            return(new MoBiEmptyCommand());
        }
예제 #18
0
 public virtual PathElements MapFrom(IEntity entity)
 {
     return(entity == null
     ? new PathElements()
     : MapFrom(entity.RootContainer, _entityPathResolver.ObjectPathFor(entity, addSimulationName: true).ToList()));
 }
예제 #19
0
        private IMoleculeAmount amountFor(IContainer container, IndividualMolecule molecule, PathCache <IMoleculeAmount> moleculeAmountPath)
        {
            var amount = moleculeAmountPath[_entityPathResolver.ObjectPathFor(container).AndAdd(molecule.Name).ToString()];

            return(amount);
        }
예제 #20
0
 public override void Compare(IComparison <IEvent> comparison)
 {
     _entityDiffBuilder.Compare(comparison);
     CompareValues(x => x.OneTime, x => x.OneTime, comparison);
     _objectComparer.Compare(comparison.FormulaComparison());
     _enumerableComparer.CompareEnumerables(comparison, x => x.Assignments, item => _entityPathResolver.ObjectPathFor(item.ChangedEntity));
     _enumerableComparer.CompareEnumerables(comparison, x => x.GetChildren <IEntity>(i => !i.IsAnImplementationOf <IEventAssignment>()), item => item.Name);
 }