예제 #1
0
        /// <summary>
        ///     Converts a SBML UnitDefinition into a MoBi Unit.
        /// </summary>
        public IDimension ConvertUnit(UnitDefinition unitDefinition)
        {
            var sbmlUnit  = unitDefinition.getId();
            var dimension = _moBiDimensionFactory.TryGetDimensionCaseInsensitive(sbmlUnit);

            if (dimension != Constants.Dimension.NO_DIMENSION)
            {
                _sbmlInformation.MobiDimension[sbmlUnit] = dimension;
                return(dimension);
            }

            var newFactor = 1.0;
            var unitsList = new List <Unit>();
            var brList    = new List <BaseDimensionRepresentation>();

            for (long i = 0; i < unitDefinition.getNumUnits(); i++)
            {
                var mobiUnit = SBMLBaseUnitToMoBi(unitDefinition.getUnit(i));
                if (mobiUnit == null)
                {
                    continue;
                }
                var unitDimension = _moBiDimensionFactory.DimensionForUnit(mobiUnit.Name);
                var unitBr        = unitDimension.BaseRepresentation;
                unitBr = SetExponents(unitDefinition, unitBr, i);
                brList.Add(unitBr);

                if (Math.Abs(newFactor) < 0.0001)
                {
                    newFactor = unitDefinition.getUnit(i).getMultiplier() * Math.Pow(10, unitDefinition.getUnit(i).getScale()) * Math.Pow(mobiUnit.Factor, unitDefinition.getUnit(i).getExponent());
                }
                else
                {
                    newFactor = newFactor * unitDefinition.getUnit(i).getMultiplier() * Math.Pow(10, unitDefinition.getUnit(i).getScale()) * Math.Pow(mobiUnit.Factor, unitDefinition.getUnit(i).getExponent());
                }
                unitsList.Add(mobiUnit);
            }

            var baseDimensionRepresentation = CreateBaseDimRepresentationExponents(brList);

            IDimension newDim = new Dimension(baseDimensionRepresentation, String.Format("SBML_{0}", unitDefinition.getId()), String.Format("SBML_{0}_BaseUnit", unitDefinition.getId()));

            var newBaseUnit = newDim.BaseUnit;

            newBaseUnit.Visible = false;
            var newUnit = new Unit(unitDefinition.getId(), newFactor, 0);

            newDim.AddUnit(newUnit);
            newDim.DefaultUnit = newUnit;

            _sbmlInformation.MobiDimension[sbmlUnit] = newDim;
            if (_moBiDimensionFactory.Dimensions.All(dim => dim.Name != newDim.Name))
            {
                _moBiDimensionFactory.AddDimension(newDim);
            }
            return(newDim);
        }
예제 #2
0
        /// <summary>
        ///     Gets the dimension of the size Parameter of the container/compartment in which the given Species is located.
        /// </summary>
        private IDimension GetSizeDimensionFromCompartment(Species species, Model model)
        {
            var compartmentSizeUnit = model.getCompartment(species.getCompartment()).getUnits();

            var sizeDimension = _moBiDimensionFactory.TryGetDimensionCaseInsensitive(compartmentSizeUnit);

            if (sizeDimension == OSPSuite.Core.Domain.Constants.Dimension.NO_DIMENSION)
            {
                return(sizeDimension);
            }

            if (_sbmlInformation.MobiDimension.ContainsKey(compartmentSizeUnit))
            {
                sizeDimension = _sbmlInformation.MobiDimension[compartmentSizeUnit];
            }

            if (_moBiDimensionFactory.Dimensions.All(dim => dim.Name != sizeDimension.Name))
            {
                _moBiDimensionFactory.AddDimension(sizeDimension);
            }

            return(sizeDimension);
        }