Search in sources :

Example 11 with BioEvent

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);
    }
}
Also used : AssignmentRule(cbit.vcell.mapping.AssignmentRule) ReactionRuleSpec(cbit.vcell.mapping.ReactionRuleSpec) Element(org.jdom.Element) XmlReader(cbit.vcell.xml.XmlReader) XmlParseException(cbit.vcell.xml.XmlParseException) SimulationContextParameter(cbit.vcell.mapping.SimulationContext.SimulationContextParameter) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) RateRule(cbit.vcell.mapping.RateRule) BioEvent(cbit.vcell.mapping.BioEvent) DataAccessException(org.vcell.util.DataAccessException) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 12 with BioEvent

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

Example 13 with BioEvent

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);
}
Also used : BioEvent(cbit.vcell.mapping.BioEvent)

Example 14 with BioEvent

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());
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ArrayList(java.util.ArrayList) BioEvent(cbit.vcell.mapping.BioEvent)

Example 15 with BioEvent

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());
    }
}
Also used : BioEvent(cbit.vcell.mapping.BioEvent) PropertyVetoException(java.beans.PropertyVetoException)

Aggregations

BioEvent (cbit.vcell.mapping.BioEvent)23 AssignmentRule (cbit.vcell.mapping.AssignmentRule)8 RateRule (cbit.vcell.mapping.RateRule)8 SimulationContext (cbit.vcell.mapping.SimulationContext)8 SpatialObject (cbit.vcell.mapping.spatial.SpatialObject)8 SpatialProcess (cbit.vcell.mapping.spatial.processes.SpatialProcess)8 PropertyVetoException (java.beans.PropertyVetoException)8 Model (cbit.vcell.model.Model)7 Expression (cbit.vcell.parser.Expression)7 ExpressionException (cbit.vcell.parser.ExpressionException)7 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)7 EventAssignment (cbit.vcell.mapping.BioEvent.EventAssignment)6 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)6 StructureMapping (cbit.vcell.mapping.StructureMapping)6 ReactionStep (cbit.vcell.model.ReactionStep)6 SpeciesContext (cbit.vcell.model.SpeciesContext)6 Structure (cbit.vcell.model.Structure)6 Element (org.jdom.Element)6 BioModel (cbit.vcell.biomodel.BioModel)5 ReactionRule (cbit.vcell.model.ReactionRule)5