/// <summary>
        ///     Parses an Integer.
        /// </summary>
        private string parseInteger(ASTNode rootNode)
        {
            double value = rootNode.getInteger();

            if (rootNode.isSetUnits() && _unitDefinitionImporter != null)
            {
                value = _unitDefinitionImporter.ToMobiBaseUnit(rootNode.getUnits(), value).value;
            }
            if (value.ToString(CultureInfo.InvariantCulture).Contains("-"))
            {
                return(SBMLConstants.LBRACE + rootNode.getInteger().ToString(CultureInfo.InvariantCulture) +
                       SBMLConstants.RBRACE);
            }
            return(value.ToString(CultureInfo.InvariantCulture));
        }
Exemple #2
0
        /// <summary>
        ///     Sets all the autogenerated Molecule Start Values to the right values and updates their
        ///     "IsPresent" property.
        /// </summary>
        private void SetMoleculeStartValues(Model model)
        {
            foreach (var molInfo in _sbmlInformation.MoleculeInformation)
            {
                foreach (var msv in _moleculeStartValuesBuildingBlock)
                {
                    if (msv.Name != molInfo.GetMoleculeBuilderName())
                    {
                        continue;
                    }
                    if (molInfo.GetContainer().Any(x => x.Name == msv.ContainerPath.LastOrDefault()))
                    {
                        msv.IsPresent             = true;
                        msv.NegativeValuesAllowed = true;
                        var sbmlSpecies = molInfo.GetSpeciesIfOne();
                        if (sbmlSpecies == null)
                        {
                            return;
                        }
                        var sbmlUnit        = GetUnit(sbmlSpecies, model);
                        var amountDimension = _unitDefinitionImporter.DimensionFor(sbmlUnit);

                        //unit is set by the Unit of SubstanceUnit
                        if (sbmlSpecies.isSetInitialAmount())
                        {
                            msv.StartValue = sbmlSpecies.getInitialAmount();
                            if (amountDimension != null)
                            {
                                msv.Dimension = amountDimension;
                                molInfo.SetDimension(amountDimension);
                            }
                        }
                        if (!sbmlSpecies.isSetInitialConcentration())
                        {
                            continue;
                        }

                        //unit is {unit of amount}/{unit of size}
                        var baseValue = _unitDefinitionImporter.ToMobiBaseUnit(sbmlUnit, sbmlSpecies.getInitialConcentration());
                        msv.StartValue = baseValue.value;
                        msv.Formula    = _context.Create <ExplicitFormula>($"{msv.Name}_0").WithName($"{msv.Name}_0").WithDimension(amountDimension).WithFormulaString($"{baseValue.value} * {Constants.VOLUME_ALIAS}");
                        msv.Formula.AddObjectPath(
                            ObjectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, Constants.Parameters.VOLUME)
                            .WithAlias(Constants.VOLUME_ALIAS)
                            .WithDimension(_moBiDimensionFactory.Dimension(Constants.Dimension.VOLUME))
                            );
                        _moleculeStartValuesBuildingBlock.AddFormula(msv.Formula);
                        msv.Dimension = amountDimension;
                        molInfo.SetDimension(amountDimension);
                        UseConcentrations = true;
                    }
                    else
                    {
                        msv.IsPresent  = false;
                        msv.StartValue = 0;
                    }
                }
            }
        }
        /// <summary>
        ///     Creates a MoBi Parameter from a given SBML Parameter.
        /// </summary>
        public IFormulaUsable CreateParameter(Parameter sbmlParameter)
        {
            var value = 0.0;

            if (sbmlParameter.isSetValue())
            {
                value = sbmlParameter.getValue();
            }
            if (!sbmlParameter.isSetUnits())
            {
                return(ObjectBaseFactory.Create <IParameter>()
                       .WithName(sbmlParameter.getId())
                       .WithFormula(ObjectBaseFactory.Create <ConstantFormula>().WithValue(value)));
            }

            var sbmlUnit  = sbmlParameter.getUnits();
            var baseValue = _unitDefinitionImporter.ToMobiBaseUnit(sbmlUnit, value);

            return(ObjectBaseFactory.Create <IParameter>()
                   .WithName(sbmlParameter.getId())
                   .WithFormula(_formulaFactory.ConstantFormula(baseValue.value, baseValue.dimension))
                   .WithDimension(baseValue.dimension));
        }
Exemple #4
0
        /// <summary>
        ///     Creates a Volume Parameter for a MoBi Container.
        /// </summary>
        private IEntity CreateVolumeParameter(Compartment compartment)
        {
            var volume = 1.0;

            if (compartment.isSetVolume())
            {
                volume = compartment.getVolume();
            }
            else if (compartment.isSetSize())
            {
                volume = compartment.getSize();
            }

            var      unit      = compartment.getUnits();
            var      baseValue = _unitDefinitionImporter.ToMobiBaseUnit(unit, volume);
            IFormula formula   = _formulaFactory.ConstantFormula(baseValue.value, baseValue.dimension);

            var volumeParameter = _objectBaseFactory.Create <IParameter>()
                                  .WithName(SBMLConstants.VOLUME)
                                  .WithDimension(baseValue.dimension)
                                  .WithFormula(formula);

            return(volumeParameter);
        }