Search in sources :

Example 1 with VCUnitSystem

use of cbit.vcell.units.VCUnitSystem in project vcell by virtualcell.

the class ParameterContext method setParameterValue.

public void setParameterValue(LocalParameter parm, Expression exp, boolean autocreateLocalParameters) throws PropertyVetoException, ExpressionException {
    LocalParameter p = getLocalParameterFromName(parm.getName());
    if (p != parm) {
        throw new RuntimeException("parameter " + parm.getName() + " not found");
    }
    Expression oldExpression = parm.getExpression();
    boolean bBound = false;
    try {
        if (autocreateLocalParameters) {
            // 
            // create local parameters for any unknown symbols.
            // 
            LocalParameter[] newLocalParameters = (LocalParameter[]) getLocalParameters().clone();
            // LocalProxyParameter newProxyParameters[] = (LocalProxyParameter[])getProxyParameters().clone();
            String[] symbols = exp.getSymbols();
            VCUnitSystem modelUnitSystem = unitSystemProvider.getUnitSystem();
            for (int i = 0; symbols != null && i < symbols.length; i++) {
                SymbolTableEntry ste = getEntry(symbols[i]);
                if (ste == null) {
                    newLocalParameters = (LocalParameter[]) BeanUtils.addElement(newLocalParameters, new LocalParameter(symbols[i], new Expression(0.0), RbmKineticLaw.RbmKineticLawParameterType.UserDefined, modelUnitSystem.getInstance_TBD(), RbmKineticLaw.RbmKineticLawParameterType.UserDefined.getDescription()));
                }
            }
            setLocalParameters(newLocalParameters);
        // setProxyParameters(newProxyParameters);
        }
        exp.bindExpression(this);
        parm.setExpression(exp);
        bBound = true;
    } finally {
        try {
            if (!bBound) {
                parm.setExpression(oldExpression);
            }
            cleanupParameters();
        } catch (PropertyVetoException e) {
            e.printStackTrace(System.out);
            throw new RuntimeException(e.getMessage());
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) VCUnitSystem(cbit.vcell.units.VCUnitSystem) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression)

Example 2 with VCUnitSystem

use of cbit.vcell.units.VCUnitSystem in project vcell by virtualcell.

the class ParameterContext method gatherIssues.

public void gatherIssues(IssueContext issueContext, List<Issue> issueList, ParameterRoleEnum userDefinedRole) {
    // 
    for (int i = 0; fieldUnresolvedParameters != null && i < fieldUnresolvedParameters.length; i++) {
        issueList.add(new Issue(fieldUnresolvedParameters[i], issueContext, IssueCategory.UnresolvedParameter, "Unresolved parameter '" + fieldUnresolvedParameters[i].getName(), Issue.SEVERITY_ERROR));
    }
    // 
    for (int i = 0; fieldParameters != null && i < fieldParameters.length; i++) {
        if (fieldParameters[i].getRole() == userDefinedRole) {
            try {
                if (!isReferenced(fieldParameters[i], 0)) {
                    issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.KineticsUnreferencedParameter, "Unreferenced Kinetic Parameter '" + fieldParameters[i].getName(), Issue.SEVERITY_WARNING));
                }
            } catch (ExpressionException e) {
                issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.KineticsExpressionError, "error resolving expression " + e.getMessage(), Issue.SEVERITY_WARNING));
            }
        }
    }
    // 
    if (fieldParameters != null) {
        for (LocalParameter parameter : this.fieldParameters) {
            if (parameter.getExpression() == null) {
                issueList.add(new Issue(parameter, issueContext, IssueCategory.KineticsExpressionMissing, "expression is missing", Issue.SEVERITY_INFO));
            } else {
                Expression exp = parameter.getExpression();
                String[] symbols = exp.getSymbols();
                String issueMessagePrefix = "parameter '" + parameter.getName() + "' ";
                if (symbols != null) {
                    for (int j = 0; j < symbols.length; j++) {
                        SymbolTableEntry ste = exp.getSymbolBinding(symbols[j]);
                        if (ste instanceof LocalProxyParameter) {
                            ste = ((LocalProxyParameter) ste).getTarget();
                        }
                        if (ste == null) {
                            issueList.add(new Issue(parameter, issueContext, IssueCategory.KineticsExpressionUndefinedSymbol, issueMessagePrefix + "references undefined symbol '" + symbols[j] + "'", Issue.SEVERITY_ERROR));
                        // } else if (ste instanceof SpeciesContext) {
                        // if (!getReactionStep().getModel().contains((SpeciesContext)ste)) {
                        // issueList.add(new Issue(parameter,issueContext,IssueCategory.KineticsExpressionUndefinedSymbol, issueMessagePrefix + "references undefined species '"+symbols[j]+"'",Issue.SEVERITY_ERROR));
                        // }
                        // if (reactionStep.countNumReactionParticipants((SpeciesContext)ste) == 0){
                        // issueList.add(new Issue(parameter,issueContext,IssueCategory.KineticsExpressionNonParticipantSymbol, issueMessagePrefix + "references species context '"+symbols[j]+"', but it is not a reactant/product/catalyst of this reaction",Issue.SEVERITY_WARNING));
                        // }
                        // } else if (ste instanceof ModelParameter) {
                        // if (!getReactionStep().getModel().contains((ModelParameter)ste)) {
                        // issueList.add(new Issue(parameter,issueContext,IssueCategory.KineticsExpressionUndefinedSymbol, issueMessagePrefix + "references undefined global parameter '"+symbols[j]+"'",Issue.SEVERITY_ERROR));
                        // }
                        }
                    }
                }
            }
        }
        // looking for local param which masks a global and issueing a warning
        for (LocalParameter parameter : fieldParameters) {
            String name = parameter.getName();
            SymbolTableEntry ste = nameScope.getExternalEntry(name, this);
            String steName;
            if (ste != null) {
                if (ste instanceof Displayable) {
                    steName = ((Displayable) ste).getDisplayType() + " " + ste.getName();
                } else {
                    steName = ste.getClass().getSimpleName() + " " + ste.getName();
                }
                String msg = steName + " is overriden by a local parameter " + name;
                issueList.add(new Issue(parameter, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_WARNING));
            }
        }
    }
    try {
        // 
        // determine unit consistency for each expression
        // 
        VCUnitSystem unitSystem = unitSystemProvider.getUnitSystem();
        VCUnitEvaluator unitEvaluator = new VCUnitEvaluator(unitSystem);
        for (int i = 0; i < fieldParameters.length; i++) {
            if (fieldParameters[i].getExpression() == null) {
                continue;
            }
            try {
                VCUnitDefinition paramUnitDef = fieldParameters[i].getUnitDefinition();
                VCUnitDefinition expUnitDef = unitEvaluator.getUnitDefinition(fieldParameters[i].getExpression());
                if (paramUnitDef == null) {
                    issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, "defined unit is null", Issue.SEVERITY_WARNING));
                } else if (paramUnitDef.isTBD()) {
                    issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, "undefined unit " + unitSystem.getInstance_TBD().getSymbol(), Issue.SEVERITY_WARNING));
                } else if (expUnitDef == null) {
                    issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, "computed unit is null", Issue.SEVERITY_WARNING));
                } else if (paramUnitDef.isTBD() || (!paramUnitDef.isEquivalent(expUnitDef) && !expUnitDef.isTBD())) {
                    issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, "inconsistent units, defined=[" + fieldParameters[i].getUnitDefinition().getSymbol() + "], computed=[" + expUnitDef.getSymbol() + "]", Issue.SEVERITY_WARNING));
                }
            } catch (VCUnitException e) {
                issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, e.getMessage(), Issue.SEVERITY_WARNING));
            } catch (ExpressionException e) {
                issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, e.getMessage(), Issue.SEVERITY_WARNING));
            }
        }
    } catch (Throwable e) {
        issueList.add(new Issue(parameterPolicy.getIssueSource(), issueContext, IssueCategory.Units, "unexpected exception: " + e.getMessage(), Issue.SEVERITY_INFO));
    }
    // 
    for (int i = 0; i < fieldParameters.length; i++) {
        RealInterval simpleBounds = parameterPolicy.getConstraintBounds(fieldParameters[i].getRole());
        if (simpleBounds != null) {
            String parmName = fieldParameters[i].getName();
            issueList.add(new SimpleBoundsIssue(fieldParameters[i], issueContext, simpleBounds, "parameter " + parmName + ": must be within " + simpleBounds.toString()));
        }
    }
}
Also used : Displayable(org.vcell.util.Displayable) VCUnitSystem(cbit.vcell.units.VCUnitSystem) SimpleBoundsIssue(cbit.vcell.model.SimpleBoundsIssue) Issue(org.vcell.util.Issue) SimpleBoundsIssue(cbit.vcell.model.SimpleBoundsIssue) RealInterval(net.sourceforge.interval.ia_math.RealInterval) ExpressionException(cbit.vcell.parser.ExpressionException) VCUnitException(cbit.vcell.units.VCUnitException) VCUnitEvaluator(cbit.vcell.parser.VCUnitEvaluator) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression)

Example 3 with VCUnitSystem

use of cbit.vcell.units.VCUnitSystem in project vcell by virtualcell.

the class ModelUnitSystem method createDefaultSBMLLevel2Units.

public static ModelUnitSystem createDefaultSBMLLevel2Units() {
    VCUnitSystem tempUnitSystem = new VCUnitSystem() {
    };
    VCUnitDefinition modelSubstanceUnit = tempUnitSystem.getInstance("mol");
    VCUnitDefinition modelVolumeUnit = tempUnitSystem.getInstance("litre");
    VCUnitDefinition modelAreaUnit = tempUnitSystem.getInstance("m2");
    VCUnitDefinition modelLengthUnit = tempUnitSystem.getInstance("m");
    VCUnitDefinition modelTimeUnit = tempUnitSystem.getInstance("s");
    ModelUnitSystem modelUnitSystem = ModelUnitSystem.createUnitSystem(modelSubstanceUnit, modelSubstanceUnit, modelSubstanceUnit, modelVolumeUnit, modelAreaUnit, modelLengthUnit, modelTimeUnit);
    return modelUnitSystem;
}
Also used : VCUnitSystem(cbit.vcell.units.VCUnitSystem) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition)

Example 4 with VCUnitSystem

use of cbit.vcell.units.VCUnitSystem in project vcell by virtualcell.

the class ParameterContext method resolveUndefinedUnits.

public void resolveUndefinedUnits() {
    // 
    if (!bResolvingUnits) {
        VCUnitSystem unitSystem = unitSystemProvider.getUnitSystem();
        try {
            bResolvingUnits = true;
            boolean bAnyTBDUnits = false;
            for (int i = 0; i < fieldParameters.length; i++) {
                if (fieldParameters[i].getUnitDefinition() == null) {
                    // not ready to resolve units yet
                    return;
                } else if (fieldParameters[i].getUnitDefinition().isTBD()) {
                    bAnyTBDUnits = true;
                }
            }
            // 
            if (bAnyTBDUnits) {
                VCUnitEvaluator unitEvaluator = new VCUnitEvaluator(unitSystem);
                VCUnitDefinition[] vcUnitDefinitions = unitEvaluator.suggestUnitDefinitions(fieldParameters);
                for (int i = 0; i < fieldParameters.length; i++) {
                    if (!fieldParameters[i].getUnitDefinition().isEquivalent(vcUnitDefinitions[i])) {
                        fieldParameters[i].setUnitDefinition(vcUnitDefinitions[i]);
                    }
                }
            // System.out.println("successfully completed Kinetics.resolveUndefinedUnits() for ReactionStep '"+getReactionStep()+"'");
            }
        } catch (ExpressionBindingException e) {
            System.out.println("ParameterContext.resolveUndefinedUnits(): EXCEPTION: " + e.getMessage());
        } catch (Exception e) {
            System.out.println("ParameterContext.resolveUndefinedUnits(): EXCEPTION: " + e.getMessage());
        } finally {
            bResolvingUnits = false;
        }
    }
}
Also used : VCUnitEvaluator(cbit.vcell.parser.VCUnitEvaluator) VCUnitSystem(cbit.vcell.units.VCUnitSystem) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) VCUnitException(cbit.vcell.units.VCUnitException) PropertyVetoException(java.beans.PropertyVetoException) ExpressionException(cbit.vcell.parser.ExpressionException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException)

Example 5 with VCUnitSystem

use of cbit.vcell.units.VCUnitSystem in project vcell by virtualcell.

the class SBMLImporter method createSBMLUnitSystemForVCModel.

private ModelUnitSystem createSBMLUnitSystemForVCModel() throws Exception {
    if (sbmlModel == null) {
        throw new SBMLImportException("SBML model is NULL");
    }
    ListOf listofUnitDefns = sbmlModel.getListOfUnitDefinitions();
    if (listofUnitDefns == null) {
        System.out.println("No Unit Definitions");
        // @TODO: deal with SBML level < 3.
        return ModelUnitSystem.createDefaultVCModelUnitSystem();
    }
    @SuppressWarnings("serial") VCUnitSystem tempVCUnitSystem = new VCUnitSystem() {
    };
    sbmlUnitIdentifierHash = new HashMap<String, VCUnitDefinition>();
    // add base SI unit identifiers (as defined in SBML spec) to hash
    sbmlUnitIdentifierHash.put("ampere", tempVCUnitSystem.getInstance("A"));
    sbmlUnitIdentifierHash.put("avogadro", tempVCUnitSystem.getInstance("6.02e23"));
    // sbmlUnitIdentifierHash.put("becquerel",
    // tempVCUnitSystem.getInstance("becquerel"));
    // sbmlUnitIdentifierHash.put("candela",
    // tempVCUnitSystem.getInstance("candela"));
    sbmlUnitIdentifierHash.put("coulomb", tempVCUnitSystem.getInstance("C"));
    sbmlUnitIdentifierHash.put("dimensionless", tempVCUnitSystem.getInstance("1"));
    sbmlUnitIdentifierHash.put("farad", tempVCUnitSystem.getInstance("F"));
    sbmlUnitIdentifierHash.put("gram", tempVCUnitSystem.getInstance("g"));
    // sbmlUnitIdentifierHash.put("gray",
    // tempVCUnitSystem.getInstance("gray"));
    sbmlUnitIdentifierHash.put("henry", tempVCUnitSystem.getInstance("H"));
    sbmlUnitIdentifierHash.put("hertz", tempVCUnitSystem.getInstance("Hz"));
    sbmlUnitIdentifierHash.put("item", tempVCUnitSystem.getInstance("molecules"));
    sbmlUnitIdentifierHash.put("joule", tempVCUnitSystem.getInstance("J"));
    // sbmlUnitIdentifierHash.put("katal",
    // tempVCUnitSystem.getInstance("katal"));
    sbmlUnitIdentifierHash.put("kelvin", tempVCUnitSystem.getInstance("K"));
    sbmlUnitIdentifierHash.put("kilogram", tempVCUnitSystem.getInstance("kg"));
    sbmlUnitIdentifierHash.put("litre", tempVCUnitSystem.getInstance("litre"));
    // sbmlUnitIdentifierHash.put("lumen",
    // tempVCUnitSystem.getInstance("lumen"));
    // sbmlUnitIdentifierHash.put("lux",
    // tempVCUnitSystem.getInstance("lux"));
    sbmlUnitIdentifierHash.put("metre", tempVCUnitSystem.getInstance("m"));
    sbmlUnitIdentifierHash.put("mole", tempVCUnitSystem.getInstance("mol"));
    sbmlUnitIdentifierHash.put("newton", tempVCUnitSystem.getInstance("N"));
    // sbmlUnitIdentifierHash.put("ohm",
    // tempVCUnitSystem.getInstance("ohm"));
    // sbmlUnitIdentifierHash.put("pascal",
    // tempVCUnitSystem.getInstance("pascal"));
    // sbmlUnitIdentifierHash.put("radian",
    // tempVCUnitSystem.getInstance("radian"));
    sbmlUnitIdentifierHash.put("second", tempVCUnitSystem.getInstance("s"));
    sbmlUnitIdentifierHash.put("siemens", tempVCUnitSystem.getInstance("S"));
    // sbmlUnitIdentifierHash.put("sievert",
    // tempVCUnitSystem.getInstance("sievert"));
    // sbmlUnitIdentifierHash.put("steradian",
    // tempVCUnitSystem.getInstance("steradian"));
    // sbmlUnitIdentifierHash.put("tesla",
    // tempVCUnitSystem.getInstance("tesla"));
    sbmlUnitIdentifierHash.put("volt", tempVCUnitSystem.getInstance("V"));
    sbmlUnitIdentifierHash.put("watt", tempVCUnitSystem.getInstance("W"));
    sbmlUnitIdentifierHash.put("weber", tempVCUnitSystem.getInstance("Wb"));
    long sbmlLevel = sbmlModel.getLevel();
    if (sbmlLevel < 3) {
        // SBML predefined unit identifiers
        sbmlUnitIdentifierHash.put(UnitDefinition.SUBSTANCE, tempVCUnitSystem.getInstance("mole"));
        sbmlUnitIdentifierHash.put(UnitDefinition.VOLUME, tempVCUnitSystem.getInstance("litre"));
        sbmlUnitIdentifierHash.put(UnitDefinition.AREA, tempVCUnitSystem.getInstance("m2"));
        sbmlUnitIdentifierHash.put(UnitDefinition.LENGTH, tempVCUnitSystem.getInstance("m"));
        sbmlUnitIdentifierHash.put(UnitDefinition.TIME, tempVCUnitSystem.getInstance("s"));
    }
    if (sbmlModel.isSetSubstanceUnits()) {
        UnitDefinition ud = sbmlModel.getSubstanceUnitsInstance();
        VCUnitDefinition vcUnitDef = SBMLUnitTranslator.getVCUnitDefinition(ud, tempVCUnitSystem);
        sbmlUnitIdentifierHash.put(UnitDefinition.SUBSTANCE, vcUnitDef);
    }
    if (sbmlModel.isSetVolumeUnits()) {
        UnitDefinition ud = sbmlModel.getVolumeUnitsInstance();
        VCUnitDefinition vcUnitDef = SBMLUnitTranslator.getVCUnitDefinition(ud, tempVCUnitSystem);
        sbmlUnitIdentifierHash.put(UnitDefinition.VOLUME, vcUnitDef);
    }
    if (sbmlModel.isSetAreaUnits()) {
        UnitDefinition ud = sbmlModel.getAreaUnitsInstance();
        VCUnitDefinition vcUnitDef = SBMLUnitTranslator.getVCUnitDefinition(ud, tempVCUnitSystem);
        sbmlUnitIdentifierHash.put(UnitDefinition.AREA, vcUnitDef);
    }
    if (sbmlModel.isSetLengthUnits()) {
        UnitDefinition ud = sbmlModel.getLengthUnitsInstance();
        VCUnitDefinition vcUnitDef = SBMLUnitTranslator.getVCUnitDefinition(ud, tempVCUnitSystem);
        sbmlUnitIdentifierHash.put(UnitDefinition.LENGTH, vcUnitDef);
    }
    if (sbmlModel.isSetTimeUnits()) {
        UnitDefinition ud = sbmlModel.getTimeUnitsInstance();
        VCUnitDefinition vcUnitDef = SBMLUnitTranslator.getVCUnitDefinition(ud, tempVCUnitSystem);
        sbmlUnitIdentifierHash.put(UnitDefinition.TIME, vcUnitDef);
    }
    // read unit definition (identifiers) declared in SBML model
    for (int i = 0; i < sbmlModel.getNumUnitDefinitions(); i++) {
        UnitDefinition ud = (org.sbml.jsbml.UnitDefinition) listofUnitDefns.get(i);
        String unitName = ud.getId();
        VCUnitDefinition vcUnitDef = SBMLUnitTranslator.getVCUnitDefinition(ud, tempVCUnitSystem);
        sbmlUnitIdentifierHash.put(unitName, vcUnitDef);
    }
    // For SBML level 2
    // default units
    VCUnitDefinition defaultSubstanceUnit = sbmlUnitIdentifierHash.get(UnitDefinition.SUBSTANCE);
    VCUnitDefinition defaultVolumeUnit = sbmlUnitIdentifierHash.get(UnitDefinition.VOLUME);
    VCUnitDefinition defaultAreaUnit = sbmlUnitIdentifierHash.get(UnitDefinition.AREA);
    VCUnitDefinition defaultLengthUnit = sbmlUnitIdentifierHash.get(UnitDefinition.LENGTH);
    VCUnitDefinition defaultTimeUnit = sbmlUnitIdentifierHash.get(UnitDefinition.TIME);
    VCUnitDefinition modelSubstanceUnit = null;
    VCUnitDefinition modelVolumeUnit = null;
    VCUnitDefinition modelAreaUnit = null;
    VCUnitDefinition modelLengthUnit = null;
    VCUnitDefinition modelTimeUnit = null;
    // units in SBML model
    // compartments
    ListOf<Compartment> listOfCompartments = sbmlModel.getListOfCompartments();
    for (int i = 0; i < listOfCompartments.size(); i++) {
        Compartment sbmlComp = listOfCompartments.get(i);
        double dim = 3;
        if (sbmlComp.isSetSpatialDimensions()) {
            dim = sbmlComp.getSpatialDimensions();
        }
        String unitStr = sbmlComp.getUnits();
        VCUnitDefinition sbmlUnitDefinition = null;
        if (unitStr != null && unitStr.length() > 0) {
            sbmlUnitDefinition = sbmlUnitIdentifierHash.get(unitStr);
        } else {
            // applying default unit if not defined for this compartment
            if (dim == 3) {
                sbmlUnitDefinition = defaultVolumeUnit;
            } else if (dim == 2) {
                sbmlUnitDefinition = defaultAreaUnit;
            } else if (dim == 1) {
                sbmlUnitDefinition = defaultLengthUnit;
            }
        }
        if (dim == 3) {
            if (sbmlUnitDefinition == null) {
                sbmlUnitDefinition = defaultVolumeUnit;
            }
            if (modelVolumeUnit == null) {
                modelVolumeUnit = sbmlUnitDefinition;
            } else if (!sbmlUnitDefinition.isEquivalent(modelVolumeUnit)) {
                localIssueList.add(new Issue(new SBMLIssueSource(sbmlComp), issueContext, IssueCategory.Units, "unit for compartment '" + sbmlComp.getId() + "' (" + unitStr + ") : (" + sbmlUnitDefinition.getSymbol() + ") not compatible with current vol unit (" + modelVolumeUnit.getSymbol() + ")", Issue.SEVERITY_WARNING));
            // logger.sendMessage(VCLogger.Priority.MediumPriority,
            // VCLogger.ErrorType.UnitError, "unit for compartment '" +
            // sbmlComp.getId() + "' (" + unitStr + ") : (" +
            // sbmlUnitDefinition.getSymbol() +
            // ") not compatible with current vol unit (" +
            // modelVolumeUnit.getSymbol() + ")");
            }
        } else if (dim == 2) {
            if (modelAreaUnit == null) {
                modelAreaUnit = sbmlUnitDefinition;
            } else if (!sbmlUnitDefinition.isEquivalent(modelAreaUnit)) {
                localIssueList.add(new Issue(new SBMLIssueSource(sbmlComp), issueContext, IssueCategory.Units, "unit for compartment '" + sbmlComp.getId() + "' (" + unitStr + ") : (" + sbmlUnitDefinition.getSymbol() + ") not compatible with current area unit (" + modelAreaUnit.getSymbol() + ")", Issue.SEVERITY_WARNING));
            // logger.sendMessage(VCLogger.Priority.MediumPriority,
            // VCLogger.ErrorType.UnitError, "unit for compartment '" +
            // sbmlComp.getId() + "' (" + unitStr + ") : (" +
            // sbmlUnitDefinition.getSymbol() +
            // ") not compatible with current area unit (" +
            // modelAreaUnit.getSymbol() + ")");
            }
        }
    }
    // species
    ListOf<org.sbml.jsbml.Species> listOfSpecies = sbmlModel.getListOfSpecies();
    for (int i = 0; i < listOfSpecies.size(); i++) {
        org.sbml.jsbml.Species sbmlSpecies = listOfSpecies.get(i);
        String unitStr = sbmlSpecies.getSubstanceUnits();
        VCUnitDefinition sbmlUnitDefinition = null;
        if (unitStr != null && unitStr.length() > 0) {
            sbmlUnitDefinition = sbmlUnitIdentifierHash.get(unitStr);
        } else {
            // apply default substance unit
            sbmlUnitDefinition = defaultSubstanceUnit;
        }
        if (modelSubstanceUnit == null) {
            modelSubstanceUnit = sbmlUnitDefinition;
        } else if (!sbmlUnitDefinition.isEquivalent(modelSubstanceUnit)) {
            localIssueList.add(new Issue(new SBMLIssueSource(sbmlSpecies), issueContext, IssueCategory.Units, "unit for species '" + sbmlSpecies.getId() + "' (" + unitStr + ") : (" + sbmlUnitDefinition.getSymbol() + ") not compatible with current substance unit (" + modelSubstanceUnit.getSymbol() + ")", Issue.SEVERITY_WARNING));
        // logger.sendMessage(VCLogger.Priority.MediumPriority,
        // VCLogger.ErrorType.UnitError, "unit for species '" +
        // sbmlSpecies.getId() + "' (" + unitStr + ") : (" +
        // sbmlUnitDefinition.getSymbol() +
        // ") not compatible with current substance unit (" +
        // modelSubstanceUnit.getSymbol() + ")");
        }
    }
    // reactions for SBML level 2 version < 3
    long sbmlVersion = sbmlModel.getVersion();
    if (sbmlVersion < 3) {
        ListOf<Reaction> listOfReactions = sbmlModel.getListOfReactions();
        for (int i = 0; i < listOfReactions.size(); i++) {
            Reaction sbmlReaction = listOfReactions.get(i);
            KineticLaw kineticLaw = sbmlReaction.getKineticLaw();
            if (kineticLaw != null) {
                // first check substance unit
                String unitStr = kineticLaw.getSubstanceUnits();
                VCUnitDefinition sbmlUnitDefinition = null;
                if (unitStr != null && unitStr.length() > 0) {
                    sbmlUnitDefinition = sbmlUnitIdentifierHash.get(unitStr);
                } else {
                    // apply default substance unit
                    sbmlUnitDefinition = defaultSubstanceUnit;
                }
                if (modelSubstanceUnit == null) {
                    modelSubstanceUnit = sbmlUnitDefinition;
                } else if (!sbmlUnitDefinition.isEquivalent(modelSubstanceUnit)) {
                    localIssueList.add(new Issue(new SBMLIssueSource(sbmlReaction), issueContext, IssueCategory.Units, "substance unit for reaction '" + sbmlReaction.getId() + "' (" + unitStr + ") : (" + sbmlUnitDefinition.getSymbol() + ") not compatible with current substance unit (" + modelSubstanceUnit.getSymbol() + ")", Issue.SEVERITY_WARNING));
                // logger.sendMessage(VCLogger.Priority.MediumPriority,
                // VCLogger.ErrorType.UnitError,
                // "substance unit for reaction '" +
                // sbmlReaction.getId() + "' (" + unitStr + ") : (" +
                // sbmlUnitDefinition.getSymbol() +
                // ") not compatible with current substance unit (" +
                // modelSubstanceUnit.getSymbol() + ")");
                }
                // check time unit
                unitStr = kineticLaw.getTimeUnits();
                if (unitStr != null && unitStr.length() > 0) {
                    sbmlUnitDefinition = sbmlUnitIdentifierHash.get(unitStr);
                } else {
                    // apply default time unit
                    sbmlUnitDefinition = defaultTimeUnit;
                }
                if (modelTimeUnit == null) {
                    modelTimeUnit = sbmlUnitDefinition;
                } else if (!sbmlUnitDefinition.isEquivalent(modelTimeUnit)) {
                    localIssueList.add(new Issue(new SBMLIssueSource(sbmlReaction), issueContext, IssueCategory.Units, "time unit for reaction '" + sbmlReaction.getId() + "' (" + unitStr + ") : (" + sbmlUnitDefinition.getSymbol() + ") not compatible with current time unit (" + modelTimeUnit.getSymbol() + ")", Issue.SEVERITY_WARNING));
                // logger.sendMessage(VCLogger.Priority.MediumPriority,
                // VCLogger.ErrorType.UnitError,
                // "time unit for reaction '" + sbmlReaction.getId() +
                // "' (" + unitStr + ") : (" +
                // sbmlUnitDefinition.getSymbol() +
                // ") not compatible with current time unit (" +
                // modelTimeUnit.getSymbol() + ")");
                }
            }
        }
    }
    if (modelSubstanceUnit == null) {
        modelSubstanceUnit = defaultSubstanceUnit;
    }
    if (modelVolumeUnit == null) {
        modelVolumeUnit = defaultVolumeUnit;
    }
    if (modelAreaUnit == null) {
        modelAreaUnit = defaultAreaUnit;
    }
    if (modelLengthUnit == null) {
        modelLengthUnit = defaultLengthUnit;
    }
    if (modelTimeUnit == null) {
        modelTimeUnit = defaultTimeUnit;
    }
    if (modelSubstanceUnit == null && modelVolumeUnit == null && modelAreaUnit == null && modelLengthUnit == null && modelTimeUnit == null) {
        // default (VC)modelUnitSystem
        return ModelUnitSystem.createDefaultVCModelUnitSystem();
    } else {
        return ModelUnitSystem.createSBMLUnitSystem(modelSubstanceUnit, modelVolumeUnit, modelAreaUnit, modelLengthUnit, modelTimeUnit);
    }
}
Also used : VCUnitSystem(cbit.vcell.units.VCUnitSystem) Issue(org.vcell.util.Issue) Compartment(org.sbml.jsbml.Compartment) Reaction(org.sbml.jsbml.Reaction) SimpleReaction(cbit.vcell.model.SimpleReaction) FluxReaction(cbit.vcell.model.FluxReaction) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ListOf(org.sbml.jsbml.ListOf) Species(cbit.vcell.model.Species) KineticLaw(org.sbml.jsbml.KineticLaw) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) UnitDefinition(org.sbml.jsbml.UnitDefinition)

Aggregations

VCUnitSystem (cbit.vcell.units.VCUnitSystem)6 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)5 Expression (cbit.vcell.parser.Expression)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)2 VCUnitEvaluator (cbit.vcell.parser.VCUnitEvaluator)2 VCUnitException (cbit.vcell.units.VCUnitException)2 PropertyVetoException (java.beans.PropertyVetoException)2 UnitDefinition (org.sbml.jsbml.UnitDefinition)2 Issue (org.vcell.util.Issue)2 BioModel (cbit.vcell.biomodel.BioModel)1 FluxReaction (cbit.vcell.model.FluxReaction)1 SimpleBoundsIssue (cbit.vcell.model.SimpleBoundsIssue)1 SimpleReaction (cbit.vcell.model.SimpleReaction)1 Species (cbit.vcell.model.Species)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 File (java.io.File)1 IOException (java.io.IOException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 RealInterval (net.sourceforge.interval.ia_math.RealInterval)1