Search in sources :

Example 81 with Issue

use of org.vcell.util.Issue in project vcell by virtualcell.

the class ModelOptimizationSpec method removeUncoupledParameters.

public void removeUncoupledParameters() {
    try {
        localIssueList.clear();
        MathMapping mathMapping = getSimulationContext().createNewMathMapping();
        MathDescription mathDesc = mathMapping.getMathDescription();
        MathSystemHash mathSystemHash = fromMath(mathDesc);
        Graph graph = mathSystemHash.getDependencyGraph(mathSystemHash.getSymbols());
        Tree[] spanningTrees = graph.getSpanningForest();
        // 
        for (int i = 0; i < spanningTrees.length; i++) {
            Node[] treeNodes = spanningTrees[i].getNodes();
            boolean bHasStateVariables = false;
            for (int j = 0; j < treeNodes.length; j++) {
                Node node = treeNodes[j];
                Variable var = mathDesc.getVariable(node.getName());
                if (var instanceof VolVariable || var instanceof MemVariable || var instanceof FilamentVariable || var instanceof VolumeRegionVariable || var instanceof MembraneRegionVariable || var instanceof FilamentRegionVariable) {
                    bHasStateVariables = true;
                    break;
                }
            }
            if (!bHasStateVariables) {
                spanningTrees = (Tree[]) BeanUtils.removeElement(spanningTrees, spanningTrees[i]);
                i--;
            }
        }
        // 
        // remove parameters not mapped to a surviving tree (not coupled to any state variables
        // 
        ArrayList<ParameterMappingSpec> paramMappingSpecsList = new ArrayList<ParameterMappingSpec>();
        paramMappingSpecsList.addAll(Arrays.asList(fieldParameterMappingSpecs));
        for (int i = 0; i < paramMappingSpecsList.size(); i++) {
            Parameter parameter = paramMappingSpecsList.get(i).getModelParameter();
            String mathName = mathMapping.getMathSymbolMapping().getVariable(parameter).getName();
            boolean bFoundInTree = false;
            for (int j = 0; j < spanningTrees.length; j++) {
                Node node = spanningTrees[j].getNode(mathName);
                if (node != null) {
                    bFoundInTree = true;
                }
            }
            if (!bFoundInTree) {
                paramMappingSpecsList.remove(i);
                i--;
            }
        }
        ParameterMappingSpec[] parameterMappingSpecs = new ParameterMappingSpec[paramMappingSpecsList.size()];
        paramMappingSpecsList.toArray(parameterMappingSpecs);
        setParameterMappingSpecs(parameterMappingSpecs);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        localIssueList.add(new Issue(this, localIssueContext, IssueCategory.ParameterEstimationGeneralWarning, e.getMessage(), Issue.SEVERITY_WARNING));
    // throw new RuntimeException(e.getMessage());
    }
}
Also used : MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MemVariable(cbit.vcell.math.MemVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) Issue(org.vcell.util.Issue) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) MathDescription(cbit.vcell.math.MathDescription) Node(cbit.util.graph.Node) ArrayList(java.util.ArrayList) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MemVariable(cbit.vcell.math.MemVariable) Tree(cbit.util.graph.Tree) VolVariable(cbit.vcell.math.VolVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) PropertyVetoException(java.beans.PropertyVetoException) ExpressionException(cbit.vcell.parser.ExpressionException) Graph(cbit.util.graph.Graph) FilamentVariable(cbit.vcell.math.FilamentVariable) MathMapping(cbit.vcell.mapping.MathMapping) Parameter(cbit.vcell.model.Parameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)

Example 82 with Issue

use of org.vcell.util.Issue 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)

Example 83 with Issue

use of org.vcell.util.Issue in project vcell by virtualcell.

the class SBMLImporter method checkIdentifiersNameLength.

private void checkIdentifiersNameLength() throws Exception {
    // Check compartment name lengths
    ListOf listofIds = sbmlModel.getListOfCompartments();
    boolean bLongCompartmentName = false;
    SBase issueSource = null;
    for (int i = 0; i < sbmlModel.getNumCompartments(); i++) {
        Compartment compartment = (Compartment) listofIds.get(i);
        String compartmentName = compartment.getId();
        if (compartmentName.length() > 64) {
            bLongCompartmentName = true;
            issueSource = compartment;
        }
    }
    // Check species name lengths
    listofIds = sbmlModel.getListOfSpecies();
    boolean bLongSpeciesName = false;
    for (int i = 0; i < sbmlModel.getNumSpecies(); i++) {
        org.sbml.jsbml.Species species = (org.sbml.jsbml.Species) listofIds.get(i);
        String speciesName = species.getId();
        if (speciesName.length() > 64) {
            bLongSpeciesName = true;
            issueSource = species;
        }
    }
    // Check parameter name lengths
    listofIds = sbmlModel.getListOfParameters();
    boolean bLongParameterName = false;
    for (int i = 0; i < sbmlModel.getNumParameters(); i++) {
        Parameter param = (Parameter) listofIds.get(i);
        String paramName = param.getId();
        if (paramName.length() > 64) {
            bLongParameterName = true;
            issueSource = param;
        }
    }
    // Check reaction name lengths
    listofIds = sbmlModel.getListOfReactions();
    boolean bLongReactionName = false;
    for (int i = 0; i < sbmlModel.getNumReactions(); i++) {
        Reaction rxn = (Reaction) listofIds.get(i);
        String rxnName = rxn.getId();
        if (rxnName.length() > 64) {
            bLongReactionName = true;
            issueSource = rxn;
        }
    }
    if (bLongCompartmentName || bLongSpeciesName || bLongParameterName || bLongReactionName) {
        String warningMsg = "WARNING: The imported model has one or more ";
        if (bLongCompartmentName) {
            warningMsg = warningMsg + "compartments, ";
        }
        if (bLongSpeciesName) {
            warningMsg = warningMsg + "species, ";
        }
        if (bLongParameterName) {
            warningMsg = warningMsg + "global parameters, ";
        }
        if (bLongReactionName) {
            warningMsg = warningMsg + "reactions ";
        }
        warningMsg = warningMsg + "that have ids/names that are longer than 64 characters. \n\nUser is STRONGLY recommeded to shorten " + "the names to avoid problems with the length of expressions these names might be used in.";
        localIssueList.add(new Issue(new SBMLIssueSource(issueSource), issueContext, IssueCategory.SBMLImport_UnsupportedAttributeOrElement, warningMsg, Issue.SEVERITY_WARNING));
    // logger.sendMessage(VCLogger.Priority.MediumPriority,
    // VCLogger.ErrorType.UnsupportedConstruct, warningMsg);
    }
}
Also used : 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) SpatialNamedSBase(org.sbml.jsbml.ext.spatial.SpatialNamedSBase) SBase(org.sbml.jsbml.SBase) ListOf(org.sbml.jsbml.ListOf) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) Parameter(org.sbml.jsbml.Parameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) LocalParameter(org.sbml.jsbml.LocalParameter) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) UnresolvedParameter(cbit.vcell.model.Kinetics.UnresolvedParameter) Species(cbit.vcell.model.Species)

Example 84 with Issue

use of org.vcell.util.Issue in project vcell by virtualcell.

the class SBMLImporter method addInitialAssignments.

protected void addInitialAssignments() {
    if (sbmlModel == null) {
        throw new SBMLImportException("SBML model is NULL");
    }
    ListOf listofInitialAssgns = sbmlModel.getListOfInitialAssignments();
    if (listofInitialAssgns == null) {
        System.out.println("No Initial Assignments specified");
        return;
    }
    Model vcModel = vcBioModel.getSimulationContext(0).getModel();
    for (int i = 0; i < sbmlModel.getNumInitialAssignments(); i++) {
        try {
            InitialAssignment initAssgn = (InitialAssignment) listofInitialAssgns.get(i);
            String initAssgnSymbol = initAssgn.getSymbol();
            Expression initAssignMathExpr = getExpressionFromFormula(initAssgn.getMath());
            // support compartmentSize expressions, warn and bail out.
            if (sbmlModel.getCompartment(initAssgnSymbol) != null) {
                if (!initAssignMathExpr.isNumeric()) {
                    logger.sendMessage(VCLogger.Priority.HighPriority, VCLogger.ErrorType.CompartmentError, "compartment '" + initAssgnSymbol + "' size has an initial assignment, cannot handle it at this time.");
                }
            // if init assgn for compartment is numeric, the numeric
            // value for size is set in addCompartments().
            }
            // or other species. Not allowed for species.
            if (!bSpatial && sbmlModel.getSpecies(initAssgnSymbol) != null) {
                if (initAssignMathExpr.hasSymbol(vcModel.getX().getName()) || initAssignMathExpr.hasSymbol(vcModel.getY().getName()) || initAssignMathExpr.hasSymbol(vcModel.getZ().getName())) {
                    logger.sendMessage(VCLogger.Priority.HighPriority, VCLogger.ErrorType.SpeciesError, "species '" + initAssgnSymbol + "' initial assignment expression cannot contain 'x', 'y', 'z'.");
                }
            }
            initAssignMathExpr = adjustExpression(initAssignMathExpr, vcModel);
            // set the init assgn expr on VCell species init condn or global
            // parameter expression
            SpeciesContextSpec scs = vcBioModel.getSimulationContext(0).getReactionContext().getSpeciesContextSpec(vcBioModel.getSimulationContext(0).getModel().getSpeciesContext(initAssgnSymbol));
            ModelParameter mp = vcBioModel.getSimulationContext(0).getModel().getModelParameter(initAssgnSymbol);
            if (scs != null) {
                scs.getInitialConditionParameter().setExpression(initAssignMathExpr);
            } else if (mp != null) {
                mp.setExpression(initAssignMathExpr);
            } else {
                localIssueList.add(new Issue(new SBMLIssueSource(initAssgn), issueContext, IssueCategory.SBMLImport_UnsupportedAttributeOrElement, "Symbol '" + initAssgnSymbol + "' not a species or global parameter in VCell; initial assignment ignored.", Issue.SEVERITY_WARNING));
            // logger.sendMessage(VCLogger.Priority.MediumPriority,
            // VCLogger.ErrorType.UnsupportedConstruct,
            // "Symbol '"+initAssgnSymbol+"' not a species or global parameter in VCell; initial assignment ignored..");
            }
        } catch (Exception e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("Error reading InitialAssignment : " + e.getMessage());
        }
    }
}
Also used : Issue(org.vcell.util.Issue) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) XMLStreamException(javax.xml.stream.XMLStreamException) SbmlException(org.vcell.sbml.SbmlException) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) SBMLException(org.sbml.jsbml.SBMLException) ModelPropertyVetoException(cbit.vcell.model.ModelPropertyVetoException) ExpressionException(cbit.vcell.parser.ExpressionException) InitialAssignment(org.sbml.jsbml.InitialAssignment) ModelParameter(cbit.vcell.model.Model.ModelParameter) Expression(cbit.vcell.parser.Expression) ListOf(org.sbml.jsbml.ListOf) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel)

Example 85 with Issue

use of org.vcell.util.Issue in project vcell by virtualcell.

the class SBMLImporter method setSpeciesInitialConditions.

/**
 * setSpeciesInitialConditions : called after speciesContexts and global
 * parameters have been set. Checks for init conditions set on species in
 * the Sbml model, and if it is set using an assignment rule, obtain the
 * corresponding expression. Obtain the sbml -> vc unit conversion factor
 * for species concentrations to adjust the species initial condition
 * units/factor.
 */
private void setSpeciesInitialConditions() {
    try {
        // fill in SpeciesContextSpec for each speciesContext
        Model vcModel = vcBioModel.getSimulationContext(0).getModel();
        SpeciesContext[] vcSpeciesContexts = vcModel.getSpeciesContexts();
        for (int i = 0; i < vcSpeciesContexts.length; i++) {
            org.sbml.jsbml.Species sbmlSpecies = (org.sbml.jsbml.Species) sbmlModel.getSpecies(vcSpeciesContexts[i].getName());
            // Sometimes, the species name can be null or a blank string; in
            // that case, use species id as the name.
            String speciesName = sbmlSpecies.getId();
            Compartment compartment = (Compartment) sbmlModel.getCompartment(sbmlSpecies.getCompartment());
            Expression initExpr = null;
            if (sbmlSpecies.isSetInitialConcentration()) {
                // If initial
                // Concentration
                // is set
                Expression initConcentration = new Expression(sbmlSpecies.getInitialConcentration());
                // check if initConc is set by a (assignment) rule. That
                // takes precedence over initConc value set on species.
                initExpr = getValueFromAssignmentRule(speciesName);
                if (initExpr == null) {
                    initExpr = new Expression(initConcentration);
                }
            } else if (sbmlSpecies.isSetInitialAmount()) {
                // If initial
                // amount is set
                double initAmount = sbmlSpecies.getInitialAmount();
                // initConcentration. Else, throw exception.
                if (compartment.isSetSize()) {
                    double compartmentSize = compartment.getSize();
                    Expression initConcentration = new Expression(0.0);
                    if (compartmentSize != 0.0) {
                        initConcentration = new Expression(initAmount / compartmentSize);
                    } else {
                        logger.sendMessage(VCLogger.Priority.HighPriority, VCLogger.ErrorType.UnitError, "compartment '" + compartment.getId() + "' has zero size, unable to determine initial concentration for species " + speciesName);
                    }
                    // check if initConc is set by a (assignment) rule. That
                    // takes precedence over initConc/initAmt value set on
                    // species.
                    initExpr = getValueFromAssignmentRule(speciesName);
                    if (initExpr == null) {
                        initExpr = new Expression(initConcentration);
                    }
                } else {
                    logger.sendMessage(VCLogger.Priority.HighPriority, VCLogger.ErrorType.SpeciesError, " Compartment '" + compartment.getId() + "' size not set or is defined by a rule; cannot calculate initConc.");
                }
            } else {
                // initConc/initAmt not set; check if species has a
                // (assignment) rule.
                initExpr = getValueFromAssignmentRule(speciesName);
                if (initExpr == null) {
                    // warning and set it to 0.0
                    if (sbmlModel.getInitialAssignment(speciesName) == null) {
                        localIssueList.add(new Issue(new SBMLIssueSource(sbmlModel.getSpecies(speciesName)), issueContext, IssueCategory.SBMLImport_MissingSpeciesInitCondition, "no initial condition for species " + speciesName + ", assuming 0.0", Issue.SEVERITY_WARNING));
                    // logger.sendMessage(VCLogger.Priority.MediumPriority,
                    // VCLogger.ErrorType.UnitError,
                    // "no initial condition for species "+speciesName+", assuming 0.0");
                    }
                    initExpr = new Expression(0.0);
                }
            }
            // similar to the conversion that is done in reactions.
            if (initExpr != null) {
                // initExpr will be changed
                initExpr = adjustExpression(initExpr, vcModel);
            }
            // If any of the symbols in the expression for speciesConc is a
            // rule, expand it.
            substituteGlobalParamRulesInPlace(initExpr, false);
            SpeciesContextSpec speciesContextSpec = vcBioModel.getSimulationContext(0).getReactionContext().getSpeciesContextSpec(vcSpeciesContexts[i]);
            speciesContextSpec.getInitialConditionParameter().setExpression(initExpr);
            speciesContextSpec.setConstant(sbmlSpecies.getBoundaryCondition() || sbmlSpecies.getConstant());
        }
    } catch (Throwable e) {
        e.printStackTrace(System.out);
        throw new SBMLImportException("Error setting initial condition for species context; " + e.getMessage(), e);
    }
}
Also used : Issue(org.vcell.util.Issue) Compartment(org.sbml.jsbml.Compartment) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) Expression(cbit.vcell.parser.Expression) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) Species(cbit.vcell.model.Species)

Aggregations

Issue (org.vcell.util.Issue)88 ArrayList (java.util.ArrayList)18 IssueContext (org.vcell.util.IssueContext)14 Expression (cbit.vcell.parser.Expression)13 ExpressionException (cbit.vcell.parser.ExpressionException)13 PropertyVetoException (java.beans.PropertyVetoException)9 MolecularType (org.vcell.model.rbm.MolecularType)9 Structure (cbit.vcell.model.Structure)8 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)8 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)7 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)7 Model (cbit.vcell.model.Model)6 ModelParameter (cbit.vcell.model.Model.ModelParameter)6 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)6 BioModel (cbit.vcell.biomodel.BioModel)5 ModelException (cbit.vcell.model.ModelException)5 Product (cbit.vcell.model.Product)5 Reactant (cbit.vcell.model.Reactant)5 ReactionParticipant (cbit.vcell.model.ReactionParticipant)5 InteriorPoint (org.sbml.jsbml.ext.spatial.InteriorPoint)5