Search in sources :

Example 91 with ExpressionException

use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.

the class ModelProcessEquation method parseReaction.

public static ReactionParticipant[] parseReaction(ReactionStep reactionStep, Model model, String equationString) throws ExpressionException, PropertyVetoException {
    int gotoIndex = equationString.indexOf(REACTION_GOESTO);
    if (gotoIndex < 1 && equationString.length() == 0) {
        throw new ExpressionException("Syntax error! " + REACTION_GOESTO + " not found. (e.g. a+b->c)");
    }
    if (reactionStep == null) {
        return null;
    }
    String leftHand = equationString.substring(0, gotoIndex);
    String rightHand = equationString.substring(gotoIndex + REACTION_GOESTO.length());
    StringTokenizer st = new StringTokenizer(leftHand, "+");
    ArrayList<ReactionParticipant> rplist = new ArrayList<ReactionParticipant>();
    HashMap<String, SpeciesContext> speciesContextMap = new HashMap<String, SpeciesContext>();
    Structure rxnStructure = reactionStep.getStructure();
    while (st.hasMoreElements()) {
        String nextToken = st.nextToken().trim();
        if (nextToken.length() == 0) {
            continue;
        }
        int stoichiIndex = 0;
        while (true) {
            if (Character.isDigit(nextToken.charAt(stoichiIndex))) {
                stoichiIndex++;
            } else {
                break;
            }
        }
        int stoichi = 1;
        String tmp = nextToken.substring(0, stoichiIndex);
        if (tmp.length() > 0) {
            stoichi = Integer.parseInt(tmp);
        }
        String var = nextToken.substring(stoichiIndex).trim();
        SpeciesContext sc = model.getSpeciesContext(var);
        if (sc == null) {
            sc = speciesContextMap.get(var);
            if (sc == null) {
                Species species = model.getSpecies(var);
                if (species == null) {
                    species = new Species(var, null);
                }
                sc = new SpeciesContext(species, rxnStructure);
                sc.setName(var);
                speciesContextMap.put(var, sc);
            }
        }
        // if (reactionStep instanceof SimpleReaction) {
        rplist.add(new Reactant(null, (SimpleReaction) reactionStep, sc, stoichi));
    // } else if (reactionStep instanceof FluxReaction) {
    // rplist.add(new Flux(null, (FluxReaction) reactionStep, sc));
    // }
    }
    st = new StringTokenizer(rightHand, "+");
    while (st.hasMoreElements()) {
        String nextToken = st.nextToken().trim();
        if (nextToken.length() == 0) {
            continue;
        }
        int stoichiIndex = 0;
        while (true) {
            if (Character.isDigit(nextToken.charAt(stoichiIndex))) {
                stoichiIndex++;
            } else {
                break;
            }
        }
        int stoichi = 1;
        String tmp = nextToken.substring(0, stoichiIndex);
        if (tmp.length() > 0) {
            stoichi = Integer.parseInt(tmp);
        }
        String var = nextToken.substring(stoichiIndex);
        SpeciesContext sc = model.getSpeciesContext(var);
        if (sc == null) {
            sc = speciesContextMap.get(var);
            if (sc == null) {
                Species species = model.getSpecies(var);
                if (species == null) {
                    species = new Species(var, null);
                }
                sc = new SpeciesContext(species, rxnStructure);
                sc.setName(var);
                speciesContextMap.put(var, sc);
            }
        }
        // if (reactionStep instanceof SimpleReaction) {
        rplist.add(new Product(null, (SimpleReaction) reactionStep, sc, stoichi));
    // } else if (reactionStep instanceof FluxReaction) {
    // rplist.add(new Flux(null, (FluxReaction) reactionStep, sc));
    // }
    }
    return rplist.toArray(new ReactionParticipant[0]);
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(cbit.vcell.model.Product) SpeciesContext(cbit.vcell.model.SpeciesContext) Reactant(cbit.vcell.model.Reactant) ExpressionException(cbit.vcell.parser.ExpressionException) StringTokenizer(java.util.StringTokenizer) Structure(cbit.vcell.model.Structure) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Species(cbit.vcell.model.Species)

Example 92 with ExpressionException

use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.

the class OutputFunctionsPanel method nextButtonClicked.

private void nextButtonClicked() throws ExpressionException, InconsistentDomainException {
    boolean bSpatial = simulationWorkspace.getSimulationOwner().getGeometry().getDimension() > 0;
    if (bSpatial) {
        DefaultComboBoxModel aModel = new DefaultComboBoxModel();
        ArrayList<Object> objectsList = null;
        String exprStr = getFunctionExpressionTextField().getText();
        if (exprStr == null) {
            throw new ExpressionException("No expression provided for output function.");
        }
        Expression expr = new Expression(exprStr);
        objectsList = getPossibleGeometryClassesAndVariableTypes(expr);
        for (Object ob : objectsList) {
            aModel.addElement(ob);
        }
        getSubdomainComboBox().setModel(aModel);
        getSubdomainComboBox().setSelectedIndex(0);
    }
    cardLayout.show(functionPanel, geometryClassPanel.getName());
}
Also used : Expression(cbit.vcell.parser.Expression) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 93 with ExpressionException

use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.

the class RestDatabaseService method query.

public SimulationStatusRepresentation[] query(SimulationStatusServerResource resource, User vcellUser) throws SQLException, DataAccessException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    String userID = vcellUser.getName();
    SimpleJobStatusQuerySpec simQuerySpec = new SimpleJobStatusQuerySpec();
    simQuerySpec.userid = userID;
    simQuerySpec.simId = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_SIM_ID);
    String hasData = resource.getQueryValue(SimulationStatusServerResource.PARAM_HAS_DATA);
    if (hasData != null && hasData.equals("yes")) {
        simQuerySpec.hasData = true;
    } else if (hasData != null && hasData.equals("no")) {
        simQuerySpec.hasData = false;
    } else {
        simQuerySpec.hasData = null;
    }
    simQuerySpec.waiting = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_ACTIVE, false);
    simQuerySpec.queued = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_ACTIVE, false);
    simQuerySpec.dispatched = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_ACTIVE, false);
    simQuerySpec.running = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_ACTIVE, false);
    simQuerySpec.completed = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_COMPLETED, false);
    simQuerySpec.failed = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_FAILED, false);
    simQuerySpec.stopped = resource.getBooleanQueryValue(SimulationStatusServerResource.PARAM_STATUS_STOPPED, false);
    simQuerySpec.submitLowMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_SUBMIT_LOW);
    simQuerySpec.submitHighMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_SUBMIT_HIGH);
    simQuerySpec.startLowMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_START_LOW);
    simQuerySpec.startHighMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_START_HIGH);
    simQuerySpec.endLowMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_END_LOW);
    simQuerySpec.endHighMS = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_END_HIGH);
    Long startRowParam = resource.getLongQueryValue(SimulationStatusServerResource.PARAM_START_ROW);
    // default
    simQuerySpec.startRow = 1;
    if (startRowParam != null) {
        simQuerySpec.startRow = startRowParam.intValue();
    }
    Long maxRowsParam = resource.getLongQueryValue(SimulationTasksServerResource.PARAM_MAX_ROWS);
    // default
    simQuerySpec.maxRows = 10;
    if (maxRowsParam != null) {
        simQuerySpec.maxRows = maxRowsParam.intValue();
    }
    SimulationStatus[] simStatuses = null;
    HashMap<KeyValue, SimulationDocumentLink> simDocLinks = new HashMap<KeyValue, SimulationDocumentLink>();
    // 
    // ask server for simJobStatuses with above query spec.
    // find set of simulation IDs from the result set of simJobStatus
    // ask server for simulationStatuses from list of sim IDs.
    // 
    VCMessageSession rpcSession = vcMessagingService.createProducerSession();
    try {
        UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(), null);
        try {
            userLoginInfo.setUser(vcellUser);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAccessException(e.getMessage());
        }
        RpcSimServerProxy rpcSimServerProxy = new RpcSimServerProxy(userLoginInfo, rpcSession);
        SimpleJobStatus[] simpleJobStatusArray = rpcSimServerProxy.getSimpleJobStatus(vcellUser, simQuerySpec);
        // gather unique simIDs and go back and ask server for SimulationStatuses
        for (SimpleJobStatus simpleJobStatus : simpleJobStatusArray) {
            KeyValue simulationKey = simpleJobStatus.jobStatus.getVCSimulationIdentifier().getSimulationKey();
            SimulationDocumentLink simulationDocumentLink = simpleJobStatus.simulationDocumentLink;
            simDocLinks.put(simulationKey, simulationDocumentLink);
        }
        KeyValue[] simKeys = simDocLinks.keySet().toArray(new KeyValue[0]);
        if (simKeys.length > 0) {
            simStatuses = rpcSimServerProxy.getSimulationStatus(vcellUser, simKeys);
        }
    } finally {
        rpcSession.close();
    }
    ArrayList<SimulationStatusRepresentation> simStatusReps = new ArrayList<SimulationStatusRepresentation>();
    for (int i = 0; simStatuses != null && i < simStatuses.length; i++) {
        KeyValue simulationKey = simStatuses[i].getVCSimulationIdentifier().getSimulationKey();
        SimulationRep simRep = getSimulationRep(simulationKey);
        try {
            SimulationRepresentation simRepresentation = new SimulationRepresentation(simRep, simDocLinks.get(simulationKey));
            simStatusReps.add(new SimulationStatusRepresentation(simRepresentation, simStatuses[i]));
        } catch (ExpressionException e) {
            e.printStackTrace(System.out);
        }
    }
    return simStatusReps.toArray(new SimulationStatusRepresentation[0]);
}
Also used : SimpleJobStatusQuerySpec(cbit.vcell.server.SimpleJobStatusQuerySpec) KeyValue(org.vcell.util.document.KeyValue) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) RpcSimServerProxy(org.vcell.rest.rpc.RpcSimServerProxy) VCMessageSession(cbit.vcell.message.VCMessageSession) ArrayList(java.util.ArrayList) BigString(org.vcell.util.BigString) PropertyVetoException(java.beans.PropertyVetoException) MatrixException(cbit.vcell.matrix.MatrixException) ModelException(cbit.vcell.model.ModelException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) UseridIDExistsException(org.vcell.util.UseridIDExistsException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) ExpressionException(cbit.vcell.parser.ExpressionException) SimpleJobStatus(cbit.vcell.server.SimpleJobStatus) SimulationRepresentation(org.vcell.rest.common.SimulationRepresentation) SimulationDocumentLink(cbit.vcell.server.SimulationDocumentLink) SimulationStatus(cbit.vcell.server.SimulationStatus) UserLoginInfo(org.vcell.util.document.UserLoginInfo) DataAccessException(org.vcell.util.DataAccessException) SimulationRep(cbit.vcell.modeldb.SimulationRep) SimulationStatusRepresentation(org.vcell.rest.common.SimulationStatusRepresentation)

Example 94 with ExpressionException

use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.

the class ElectricalStimulusPanel method getProtocolParameterExprPreview.

public static Expression getProtocolParameterExprPreview(Expression expr, SymbolTable symbolTable, ReservedSymbol timeSymbol) throws Exception {
    Expression protocolParameterExp = new Expression(expr);
    protocolParameterExp = MathUtilities.substituteModelParameters(protocolParameterExp, symbolTable);
    String[] symbols = protocolParameterExp.getSymbols();
    for (int i = 0; symbols != null && i < symbols.length; i++) {
        SymbolTableEntry ste = protocolParameterExp.getSymbolBinding(symbols[i]);
        if (!ste.equals(timeSymbol) && !(ste instanceof LocalProxyParameter && ((LocalProxyParameter) ste).getTarget().equals(timeSymbol))) {
            throw new ExpressionException("Expression symbol '" + ste.getName() + "' doesn't match timeSymbol " + timeSymbol.getName());
        }
    }
    return protocolParameterExp;
}
Also used : LocalProxyParameter(cbit.vcell.mapping.ParameterContext.LocalProxyParameter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 95 with ExpressionException

use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.

the class ElectricalStimulusParameterTableModel method setValueAt.

public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    if (columnIndex < 0 || columnIndex >= getColumnCount()) {
        throw new RuntimeException("ParameterTableModel.setValueAt(), column = " + columnIndex + " out of range [" + 0 + "," + (getColumnCount() - 1) + "]");
    }
    Parameter parameter = getValueAt(rowIndex);
    // try {
    switch(columnIndex) {
        case COLUMN_VALUE:
            {
                try {
                    String newExpressionString = (String) aValue;
                    if (parameter instanceof LocalParameter) {
                        LocalParameter scsParm = (LocalParameter) parameter;
                        getElectricalStimulus().setParameterValue(scsParm, new Expression(newExpressionString));
                    // fireTableRowsUpdated(rowIndex,rowIndex);
                    }
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, e.getMessage(), e);
                }
                break;
            }
        case COLUMN_NAME:
            {
                try {
                    getElectricalStimulus().renameParameter(parameter.getName(), (String) aValue);
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, e.getMessage(), e);
                }
            }
    }
// }catch (java.beans.PropertyVetoException e){
// e.printStackTrace(System.out);
// }
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) ScopedExpression(cbit.gui.ScopedExpression) Expression(cbit.vcell.parser.Expression) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) Parameter(cbit.vcell.model.Parameter) ProxyParameter(cbit.vcell.model.ProxyParameter) ExpressionException(cbit.vcell.parser.ExpressionException) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

ExpressionException (cbit.vcell.parser.ExpressionException)199 Expression (cbit.vcell.parser.Expression)138 MathException (cbit.vcell.math.MathException)58 PropertyVetoException (java.beans.PropertyVetoException)51 DataAccessException (org.vcell.util.DataAccessException)34 ArrayList (java.util.ArrayList)32 Variable (cbit.vcell.math.Variable)30 IOException (java.io.IOException)29 Element (org.jdom.Element)26 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)25 MappingException (cbit.vcell.mapping.MappingException)24 Function (cbit.vcell.math.Function)24 Vector (java.util.Vector)24 ModelException (cbit.vcell.model.ModelException)23 SolverException (cbit.vcell.solver.SolverException)23 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)22 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)21 Constant (cbit.vcell.math.Constant)20 MathDescription (cbit.vcell.math.MathDescription)19 Structure (cbit.vcell.model.Structure)18