use of cbit.vcell.mapping.BioEvent in project vcell by virtualcell.
the class SimContextTable method readAppComponents.
/**
* readAppComponents : reads the additional simContext components like bioevents/application related flags (for stochastic, at the moment), if present, and sets them on simContext.
* @param con
* @param simContext
* @return
* @throws SQLException
* @throws DataAccessException
* @throws PropertyVetoException
*/
public void readAppComponents(Connection con, SimulationContext simContext, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException, PropertyVetoException {
try {
Element appComponentsElement = getAppComponentsElement(con, simContext.getVersion().getVersionKey(), dbSyntax);
if (appComponentsElement != null) {
Element appRelatedFlags = appComponentsElement.getChild(XMLTags.ApplicationSpecificFlagsTag);
if (appRelatedFlags != null) {
// for now, only reading the 'randomizeInitCondition' attribute, since 'isStoch' and 'isUsingconcentration' are read in by other means; so not messing with those fields of simContext.
boolean bRandomizeInitCondition = false;
if ((appRelatedFlags.getAttributeValue(XMLTags.RandomizeInitConditionTag) != null) && (appRelatedFlags.getAttributeValue(XMLTags.RandomizeInitConditionTag).equals("true"))) {
bRandomizeInitCondition = true;
}
simContext.setRandomizeInitConditions(bRandomizeInitCondition);
}
if ((appComponentsElement.getAttributeValue(XMLTags.InsufficientIterationsTag) != null) && (appComponentsElement.getAttributeValue(XMLTags.InsufficientIterationsTag).equals("true"))) {
simContext.setInsufficientIterations(true);
} else {
simContext.setInsufficientIterations(false);
}
if ((appComponentsElement.getAttributeValue(XMLTags.InsufficientMaxMoleculesTag) != null) && (appComponentsElement.getAttributeValue(XMLTags.InsufficientMaxMoleculesTag).equals("true"))) {
simContext.setInsufficientMaxMolecules(true);
} else {
simContext.setInsufficientMaxMolecules(false);
}
if ((appComponentsElement.getAttributeValue(XMLTags.MassConservationModelReductionTag) != null) && (appComponentsElement.getAttributeValue(XMLTags.MassConservationModelReductionTag).equals("true"))) {
simContext.setUsingMassConservationModelReduction(true);
} else {
simContext.setUsingMassConservationModelReduction(false);
}
XmlReader xmlReader = new XmlReader(false);
NetworkConstraints nc = null;
Element ncElement = appComponentsElement.getChild(XMLTags.RbmNetworkConstraintsTag);
if (ncElement != null) {
// one network constraint element
nc = xmlReader.getAppNetworkConstraints(ncElement, simContext.getModel());
}
simContext.setNetworkConstraints(nc);
// get spatial objects
Element spatialObjectsElement = appComponentsElement.getChild(XMLTags.SpatialObjectsTag);
if (spatialObjectsElement != null) {
SpatialObject[] spatialObjects = xmlReader.getSpatialObjects(simContext, spatialObjectsElement);
simContext.setSpatialObjects(spatialObjects);
}
// get application parameters
Element appParamsElement = appComponentsElement.getChild(XMLTags.ApplicationParametersTag);
if (appParamsElement != null) {
SimulationContextParameter[] appParams = xmlReader.getSimulationContextParams(appParamsElement, simContext);
simContext.setSimulationContextParameters(appParams);
}
// get bioEvents
Element bioEventsElement = appComponentsElement.getChild(XMLTags.BioEventsTag);
if (bioEventsElement != null) {
BioEvent[] bioEvents = xmlReader.getBioEvents(simContext, bioEventsElement);
simContext.setBioEvents(bioEvents);
}
// get spatial processes
Element spatialProcessesElement = appComponentsElement.getChild(XMLTags.SpatialProcessesTag);
if (spatialProcessesElement != null) {
SpatialProcess[] spatialProcesses = xmlReader.getSpatialProcesses(simContext, spatialProcessesElement);
simContext.setSpatialProcesses(spatialProcesses);
}
// get microscope measurements
Element element = appComponentsElement.getChild(XMLTags.MicroscopeMeasurement);
if (element != null) {
xmlReader.getMicroscopeMeasurement(element, simContext);
}
// get rate rules
Element rateRulesElement = appComponentsElement.getChild(XMLTags.RateRulesTag);
if (rateRulesElement != null) {
RateRule[] rateRules = xmlReader.getRateRules(simContext, rateRulesElement);
simContext.setRateRules(rateRules);
}
Element assignmentRulesElement = appComponentsElement.getChild(XMLTags.AssignmentRulesTag);
if (assignmentRulesElement != null) {
AssignmentRule[] assignmentRules = xmlReader.getAssignmentRules(simContext, assignmentRulesElement);
simContext.setAssignmentRules(assignmentRules);
}
// get reaction rule specs
Element reactionRuleSpecsElement = appComponentsElement.getChild(XMLTags.ReactionRuleSpecsTag);
if (reactionRuleSpecsElement != null) {
ReactionRuleSpec[] reactionRuleSpecs = xmlReader.getReactionRuleSpecs(simContext, reactionRuleSpecsElement);
simContext.getReactionContext().setReactionRuleSpecs(reactionRuleSpecs);
}
}
} catch (XmlParseException e) {
throw new DataAccessException("Error retrieving bioevents : " + e.getMessage(), e);
}
}
use of cbit.vcell.mapping.BioEvent 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)
}
use of cbit.vcell.mapping.BioEvent in project vcell by virtualcell.
the class EventAssignmentsTableModel method setBioEvent.
public void setBioEvent(BioEvent argBioEvent) {
BioEvent oldValue = fieldBioEvent;
fieldBioEvent = argBioEvent;
if (oldValue != null) {
oldValue.removePropertyChangeListener(this);
}
if (fieldBioEvent != null) {
fieldBioEvent.addPropertyChangeListener(this);
}
firePropertyChange("bioEvent", oldValue, argBioEvent);
}
use of cbit.vcell.mapping.BioEvent in project vcell by virtualcell.
the class EventsDisplayPanel method deleteButtonPressed.
@Override
protected void deleteButtonPressed() {
int[] rows = table.getSelectedRows();
ArrayList<BioEvent> deleteList = new ArrayList<BioEvent>();
for (int r : rows) {
if (r < tableModel.getRowCount()) {
BioEvent bioEvent = tableModel.getValueAt(r);
if (bioEvent != null) {
deleteList.add(bioEvent);
}
}
}
try {
for (BioEvent bioEvent : deleteList) {
simulationContext.removeBioEvent(bioEvent);
}
} catch (PropertyVetoException ex) {
ex.printStackTrace();
DialogUtils.showErrorDialog(this, ex.getMessage());
}
}
use of cbit.vcell.mapping.BioEvent in project vcell by virtualcell.
the class EventsDisplayPanel method createOrEditTrigger.
public static void createOrEditTrigger(Component owner, SimulationContext simulationContext, BioEvent existingBioEvent) {
boolean bAddNew = existingBioEvent == null;
try {
TriggerTemplatePanel triggerTemplatePanel = new TriggerTemplatePanel();
BioEvent bioEvent = null;
if (bAddNew) {
bioEvent = simulationContext.createBioEvent();
} else {
bioEvent = existingBioEvent;
}
triggerTemplatePanel.init(simulationContext, EventPanel.getAutoCompleteFilter(), bioEvent);
while (true) {
try {
int result = DialogUtils.showComponentOKCancelDialog(owner, triggerTemplatePanel, "event trigger");
if (result != JOptionPane.OK_OPTION) {
try {
if (bAddNew) {
// remove pre-allocated bioevent
simulationContext.removeBioEvent(bioEvent);
}
} catch (Exception e) {
// catch here to exit loop
e.printStackTrace();
}
return;
}
triggerTemplatePanel.setTrigger(bioEvent);
break;
} catch (Exception e) {
DialogUtils.showErrorDialog(owner, "Error editing event: \n" + e.getMessage());
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
DialogUtils.showErrorDialog(owner, "Error " + (bAddNew ? "adding" : "editing") + " Event : " + e.getMessage());
}
}
Aggregations