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
}
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
}
Aggregations