use of org.sbml.jsbml.Trigger in project vcell by virtualcell.
the class SBMLExporter method addEvents.
/**
* Export events
*/
protected void addEvents() {
BioEvent[] vcBioevents = getSelectedSimContext().getBioEvents();
if (vcBioevents != null) {
for (BioEvent vcEvent : vcBioevents) {
Event sbmlEvent = sbmlModel.createEvent();
sbmlEvent.setId(vcEvent.getName());
// create trigger
Trigger trigger = sbmlEvent.createTrigger();
try {
Expression triggerExpr = vcEvent.generateTriggerExpression();
ASTNode math = getFormulaFromExpression(triggerExpr, MathType.BOOLEAN);
trigger.setMath(math);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException("failed to generate trigger expression for event " + vcEvent.getName() + ": " + e.getMessage());
}
// create delay
LocalParameter delayParam = vcEvent.getParameter(BioEventParameterType.TriggerDelay);
if (delayParam != null && delayParam.getExpression() != null && !delayParam.getExpression().isZero()) {
Delay delay = sbmlEvent.createDelay();
Expression delayExpr = delayParam.getExpression();
ASTNode math = getFormulaFromExpression(delayExpr);
delay.setMath(math);
sbmlEvent.setUseValuesFromTriggerTime(vcEvent.getUseValuesFromTriggerTime());
}
// create eventAssignments
ArrayList<EventAssignment> vcEventAssgns = vcEvent.getEventAssignments();
for (int j = 0; j < vcEventAssgns.size(); j++) {
org.sbml.jsbml.EventAssignment sbmlEA = sbmlEvent.createEventAssignment();
SymbolTableEntry target = vcEventAssgns.get(j).getTarget();
sbmlEA.setVariable(target.getName());
Expression eventAssgnExpr = new Expression(vcEventAssgns.get(j).getAssignmentExpression());
ASTNode eaMath = getFormulaFromExpression(eventAssgnExpr);
sbmlEA.setMath(eaMath);
}
}
}
}
use of org.sbml.jsbml.Trigger in project vcell by virtualcell.
the class MathModel_SBMLExporter method addSbmlEvent.
protected static void addSbmlEvent(Model sbmlModel, Event vcellMathEvent) {
org.sbml.jsbml.Event sbmlEvent = sbmlModel.createEvent();
sbmlEvent.setId(vcellMathEvent.getName());
// create trigger
Trigger trigger = sbmlEvent.createTrigger();
Expression triggerExpr = vcellMathEvent.getTriggerExpression();
//
// if trigger expression is not already in "boolean" form, then new expression is (exp != 0.0) ...nonzero is true.
//
ASTNode triggerMath = getFormulaFromExpression(triggerExpr, MathType.BOOLEAN);
trigger.setMath(triggerMath);
// create delay
cbit.vcell.math.Event.Delay vcellMathDelay = vcellMathEvent.getDelay();
if (vcellMathDelay != null && vcellMathDelay.getDurationExpression() != null && !vcellMathDelay.getDurationExpression().isZero()) {
Delay delay = sbmlEvent.createDelay();
Expression delayExpr = vcellMathDelay.getDurationExpression();
ASTNode delayMath = getFormulaFromExpression(delayExpr, MathType.REAL);
delay.setMath(delayMath);
sbmlEvent.setUseValuesFromTriggerTime(vcellMathDelay.useValuesFromTriggerTime());
}
// create eventAssignments
Iterator<EventAssignment> vcEventAssignments = vcellMathEvent.getEventAssignments();
while (vcEventAssignments.hasNext()) {
EventAssignment vcEventAssignment = vcEventAssignments.next();
org.sbml.jsbml.EventAssignment sbmlEA = sbmlEvent.createEventAssignment();
Variable target = vcEventAssignment.getVariable();
sbmlEA.setVariable(target.getName());
Expression eventAssgnExpr = new Expression(vcEventAssignment.getAssignmentExpression());
ASTNode eaMath = getFormulaFromExpression(eventAssgnExpr, MathType.REAL);
sbmlEA.setMath(eaMath);
}
}
Aggregations