Search in sources :

Example 11 with EventAssignment

use of cbit.vcell.mapping.BioEvent.EventAssignment in project vcell by virtualcell.

the class SBMLImporter method addEvents.

protected void addEvents() {
    if (sbmlModel.getNumEvents() > 0) {
        // VCell does not support events in spatial model
        if (bSpatial) {
            throw new SBMLImportException("Events are not supported in a spatial VCell model.");
        }
        ListOf<Event> listofEvents = sbmlModel.getListOfEvents();
        Model vcModel = vcBioModel.getSimulationContext(0).getModel();
        for (int i = 0; i < sbmlModel.getNumEvents(); i++) {
            try {
                Event event = listofEvents.get(i);
                // trigger - adjust for species context and time conversion
                // factors if necessary
                Expression triggerExpr = null;
                if (event.isSetTrigger()) {
                    triggerExpr = getExpressionFromFormula(event.getTrigger().getMath());
                    triggerExpr = adjustExpression(triggerExpr, vcModel);
                }
                // create bioevent
                String eventName = event.getId();
                if (eventName == null || eventName.length() == 0) {
                    eventName = TokenMangler.mangleToSName(event.getName());
                    // vcBioModel.getSimulationContext(0).
                    if (eventName == null || eventName.length() == 0) {
                        eventName = vcBioModel.getSimulationContext(0).getFreeEventName(null);
                    }
                }
                // delay
                BioEvent vcEvent = new BioEvent(eventName, TriggerType.GeneralTrigger, true, vcBioModel.getSimulationContext(0));
                if (event.isSetDelay()) {
                    Expression durationExpr = null;
                    durationExpr = getExpressionFromFormula(event.getDelay().getMath());
                    durationExpr = adjustExpression(durationExpr, vcModel);
                    boolean bUseValsFromTriggerTime = true;
                    if (event.isSetUseValuesFromTriggerTime()) {
                        bUseValsFromTriggerTime = event.isSetUseValuesFromTriggerTime();
                    } else {
                        if (durationExpr != null && !durationExpr.isZero()) {
                            bUseValsFromTriggerTime = false;
                        }
                    }
                    if (durationExpr != null && !durationExpr.isZero()) {
                        bUseValsFromTriggerTime = false;
                    }
                    vcEvent.setUseValuesFromTriggerTime(bUseValsFromTriggerTime);
                    vcEvent.getParameter(BioEventParameterType.TriggerDelay).setExpression(durationExpr);
                }
                // event assignments
                ArrayList<EventAssignment> vcEvntAssgnList = new ArrayList<EventAssignment>();
                for (int j = 0; j < event.getNumEventAssignments(); j++) {
                    org.sbml.jsbml.EventAssignment sbmlEvntAssgn = event.getEventAssignment(j);
                    String varName = sbmlEvntAssgn.getVariable();
                    SymbolTableEntry varSTE = vcBioModel.getSimulationContext(0).getEntry(varName);
                    if (varSTE != null) {
                        Expression evntAssgnExpr = getExpressionFromFormula(sbmlEvntAssgn.getMath());
                        evntAssgnExpr = adjustExpression(evntAssgnExpr, vcModel);
                        EventAssignment vcEvntAssgn = vcEvent.new EventAssignment(varSTE, evntAssgnExpr);
                        vcEvntAssgnList.add(vcEvntAssgn);
                    } else {
                        logger.sendMessage(VCLogger.Priority.HighPriority, VCLogger.ErrorType.UnsupportedConstruct, "No symbolTableEntry for '" + varName + "'; Cannot add event assignment.");
                    }
                }
                vcEvent.setEventAssignmentsList(vcEvntAssgnList);
                vcEvent.bind();
                vcBioModel.getSimulationContext(0).addBioEvent(vcEvent);
            } catch (Exception e) {
                e.printStackTrace(System.out);
                throw new SBMLImportException(e.getMessage(), e);
            }
        // end - try/catch
        }
    // end - for(sbmlEvents)
    }
// end - if numEvents > 0)
}
Also used : EventAssignment(cbit.vcell.mapping.BioEvent.EventAssignment) ArrayList(java.util.ArrayList) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) XMLStreamException(javax.xml.stream.XMLStreamException) SbmlException(org.vcell.sbml.SbmlException) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) SBMLException(org.sbml.jsbml.SBMLException) ModelPropertyVetoException(cbit.vcell.model.ModelPropertyVetoException) ExpressionException(cbit.vcell.parser.ExpressionException) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) Event(org.sbml.jsbml.Event) BioEvent(cbit.vcell.mapping.BioEvent) BioEvent(cbit.vcell.mapping.BioEvent)

Aggregations

EventAssignment (cbit.vcell.mapping.BioEvent.EventAssignment)11 Expression (cbit.vcell.parser.Expression)8 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)6 ExpressionException (cbit.vcell.parser.ExpressionException)5 BioEvent (cbit.vcell.mapping.BioEvent)4 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)4 Model (cbit.vcell.model.Model)4 Parameter (cbit.vcell.model.Parameter)3 ReactionStep (cbit.vcell.model.ReactionStep)3 SpeciesContext (cbit.vcell.model.SpeciesContext)3 Structure (cbit.vcell.model.Structure)3 PropertyVetoException (java.beans.PropertyVetoException)3 SubVolume (cbit.vcell.geometry.SubVolume)2 SurfaceClass (cbit.vcell.geometry.SurfaceClass)2 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)2 SpeciesContextSpecProxyParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecProxyParameter)2 StructureMappingParameter (cbit.vcell.mapping.StructureMapping.StructureMappingParameter)2 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)2 Constant (cbit.vcell.math.Constant)2 Equation (cbit.vcell.math.Equation)2