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]);
}
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());
}
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]);
}
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;
}
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);
// }
}
Aggregations