Search in sources :

Example 1 with Rule

use of org.sbml.jsbml.Rule in project vcell by virtualcell.

the class SBMLImporter method addAssignmentRules.

/**
 * addAssignmentRules : Adds Assignment Rules from the SBML document
 * Assignment rules are allowed (initial concentration of species; parameter
 * definitions, etc.
 */
protected void addAssignmentRules() throws Exception {
    if (sbmlModel == null) {
        throw new SBMLImportException("SBML model is NULL");
    }
    ListOf listofRules = sbmlModel.getListOfRules();
    if (listofRules == null) {
        System.out.println("No Rules specified");
        return;
    }
    for (int i = 0; i < sbmlModel.getNumRules(); i++) {
        Rule rule = (org.sbml.jsbml.Rule) listofRules.get(i);
        if (rule instanceof AssignmentRule) {
            // Get the assignment rule and store it in the hashMap.
            AssignmentRule assignmentRule = (AssignmentRule) rule;
            Expression assignmentRuleMathExpr = getExpressionFromFormula(assignmentRule.getMath());
            String assgnRuleVar = assignmentRule.getVariable();
            // check if assignment rule is for species. If so, check if
            // expression has x/y/z term. This is not allowed for
            // non-spatial models in vcell.
            org.sbml.jsbml.Species ruleSpecies = sbmlModel.getSpecies(assgnRuleVar);
            if (ruleSpecies != null) {
                if (assignmentRuleMathExpr != null) {
                    Model vcModel = vcBioModel.getSimulationContext(0).getModel();
                    if (!bSpatial) {
                        if (assignmentRuleMathExpr.hasSymbol(vcModel.getX().getName()) || assignmentRuleMathExpr.hasSymbol(vcModel.getY().getName()) || assignmentRuleMathExpr.hasSymbol(vcModel.getZ().getName())) {
                            logger.sendMessage(VCLogger.Priority.HighPriority, VCLogger.ErrorType.SpeciesError, "An assignment rule for species " + ruleSpecies.getId() + " contains " + RESERVED_SPATIAL + " variable(s) (x,y,z), this is not allowed for a non-spatial model in VCell");
                        }
                    }
                }
            }
            assignmentRulesHash.put(assignmentRule.getVariable(), assignmentRuleMathExpr);
        }
    }
// end - for i : rules
}
Also used : Expression(cbit.vcell.parser.Expression) AssignmentRule(org.sbml.jsbml.AssignmentRule) ListOf(org.sbml.jsbml.ListOf) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) AlgebraicRule(org.sbml.jsbml.AlgebraicRule) Rule(org.sbml.jsbml.Rule) AssignmentRule(org.sbml.jsbml.AssignmentRule) RateRule(org.sbml.jsbml.RateRule) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint)

Example 2 with Rule

use of org.sbml.jsbml.Rule in project vcell by virtualcell.

the class SBMLImporter method addRateRules.

/**
 * addRateRules : Adds Rate Rules from the SBML document Rate rules are
 * allowed (initial concentration of species; parameter definitions, etc.
 * @throws XMLStreamException
 * @throws SBMLException
 */
protected void addRateRules() throws ExpressionException, SBMLException, XMLStreamException {
    if (sbmlModel == null) {
        throw new SBMLImportException("SBML model is NULL");
    }
    ListOf listofRules = sbmlModel.getListOfRules();
    if (listofRules == null) {
        System.out.println("No Rules specified");
        return;
    }
    for (int i = 0; i < sbmlModel.getNumRules(); i++) {
        Rule rule = (org.sbml.jsbml.Rule) listofRules.get(i);
        if (rule instanceof RateRule) {
            // Get the rate rule and store it in the hashMap, and create
            // VCell rateRule.
            RateRule sbmlRateRule = (RateRule) rule;
            // rate rule name
            String rateruleName = sbmlRateRule.getId();
            if (rateruleName == null || rateruleName.length() == 0) {
                rateruleName = TokenMangler.mangleToSName(sbmlRateRule.getName());
                // from vcBioModel.getSimulationContext(0).
                if (rateruleName == null || rateruleName.length() == 0) {
                    rateruleName = vcBioModel.getSimulationContext(0).getFreeRateRuleName();
                }
            }
            // rate rule variable
            String varName = sbmlRateRule.getVariable();
            SymbolTableEntry rateRuleVar = vcBioModel.getSimulationContext(0).getEntry(varName);
            if (rateRuleVar instanceof Structure) {
                throw new SBMLImportException("Compartment '" + rateRuleVar.getName() + "' has a rate rule : not allowed in VCell at this time.");
            }
            try {
                if (rateRuleVar != null) {
                    Expression vcRateRuleExpr = getExpressionFromFormula(sbmlRateRule.getMath());
                    cbit.vcell.mapping.RateRule vcRateRule = new cbit.vcell.mapping.RateRule(rateruleName, rateRuleVar, vcRateRuleExpr, vcBioModel.getSimulationContext(0));
                    vcRateRule.bind();
                    rateRulesHash.put(rateRuleVar.getName(), vcRateRuleExpr);
                    vcBioModel.getSimulationContext(0).addRateRule(vcRateRule);
                }
            } catch (PropertyVetoException e) {
                e.printStackTrace(System.out);
                throw new SBMLImportException("Unable to create and add rate rule to VC model : " + e.getMessage());
            }
        }
    // end if - RateRule
    }
// end - for i : rules
}
Also used : InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) PropertyVetoException(java.beans.PropertyVetoException) ModelPropertyVetoException(cbit.vcell.model.ModelPropertyVetoException) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression) ListOf(org.sbml.jsbml.ListOf) RateRule(org.sbml.jsbml.RateRule) AlgebraicRule(org.sbml.jsbml.AlgebraicRule) Rule(org.sbml.jsbml.Rule) AssignmentRule(org.sbml.jsbml.AssignmentRule) RateRule(org.sbml.jsbml.RateRule) Structure(cbit.vcell.model.Structure)

Aggregations

Expression (cbit.vcell.parser.Expression)2 AlgebraicRule (org.sbml.jsbml.AlgebraicRule)2 AssignmentRule (org.sbml.jsbml.AssignmentRule)2 ListOf (org.sbml.jsbml.ListOf)2 RateRule (org.sbml.jsbml.RateRule)2 Rule (org.sbml.jsbml.Rule)2 InteriorPoint (org.sbml.jsbml.ext.spatial.InteriorPoint)2 BioModel (cbit.vcell.biomodel.BioModel)1 Model (cbit.vcell.model.Model)1 ModelPropertyVetoException (cbit.vcell.model.ModelPropertyVetoException)1 Structure (cbit.vcell.model.Structure)1 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)1 PropertyVetoException (java.beans.PropertyVetoException)1