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