コード例 #1
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;
                    }
                }
            }
        }