Search in sources :

Example 1 with Trigger

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);
            }
        }
    }
}
Also used : EventAssignment(cbit.vcell.mapping.BioEvent.EventAssignment) ExpressionException(cbit.vcell.parser.ExpressionException) Delay(org.sbml.jsbml.Delay) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Trigger(org.sbml.jsbml.Trigger) Expression(cbit.vcell.parser.Expression) ASTNode(org.sbml.jsbml.ASTNode) Event(org.sbml.jsbml.Event) BioEvent(cbit.vcell.mapping.BioEvent) BioEvent(cbit.vcell.mapping.BioEvent)

Example 2 with Trigger

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);
    }
}
Also used : ReservedVariable(cbit.vcell.math.ReservedVariable) Variable(cbit.vcell.math.Variable) EventAssignment(cbit.vcell.math.Event.EventAssignment) Delay(org.sbml.jsbml.Delay) Trigger(org.sbml.jsbml.Trigger) Expression(cbit.vcell.parser.Expression) ASTNode(org.sbml.jsbml.ASTNode) Event(cbit.vcell.math.Event)

Aggregations

Expression (cbit.vcell.parser.Expression)2 ASTNode (org.sbml.jsbml.ASTNode)2 Delay (org.sbml.jsbml.Delay)2 Trigger (org.sbml.jsbml.Trigger)2 BioEvent (cbit.vcell.mapping.BioEvent)1 EventAssignment (cbit.vcell.mapping.BioEvent.EventAssignment)1 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)1 Event (cbit.vcell.math.Event)1 EventAssignment (cbit.vcell.math.Event.EventAssignment)1 ReservedVariable (cbit.vcell.math.ReservedVariable)1 Variable (cbit.vcell.math.Variable)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)1 Event (org.sbml.jsbml.Event)1 InteriorPoint (org.sbml.jsbml.ext.spatial.InteriorPoint)1