Search in sources :

Example 11 with Compartment

use of org.sbml.jsbml.Compartment 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 12 with Compartment

use of org.sbml.jsbml.Compartment 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

Compartment (org.sbml.jsbml.Compartment)12 InteriorPoint (org.sbml.jsbml.ext.spatial.InteriorPoint)11 BioModel (cbit.vcell.biomodel.BioModel)8 Model (cbit.vcell.model.Model)8 Expression (cbit.vcell.parser.Expression)8 ExpressionException (cbit.vcell.parser.ExpressionException)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 SBMLException (org.sbml.jsbml.SBMLException)6 StructureMapping (cbit.vcell.mapping.StructureMapping)5 Structure (cbit.vcell.model.Structure)5 Element (org.jdom.Element)5 ASTNode (org.sbml.jsbml.ASTNode)5 ListOf (org.sbml.jsbml.ListOf)5 Species (cbit.vcell.model.Species)4 SpeciesContext (cbit.vcell.model.SpeciesContext)4 CoordinateComponent (org.sbml.jsbml.ext.spatial.CoordinateComponent)4 VCImage (cbit.image.VCImage)3 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)3 Geometry (cbit.vcell.geometry.Geometry)3 GeometryClass (cbit.vcell.geometry.GeometryClass)3