use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class ConvFunctionDefinition method differentiate.
public Expression differentiate(Expression[] args, String variable) throws ExpressionException {
if (variable == null) {
throw new RuntimeException("cannot differentiate with respect to a null variable");
}
if (args.length != 2) {
throw new IllegalArgumentException("expecting 2 arguments for vcConv()");
}
if (variable.equals(ReservedVariable.X.getName()) || variable.equals(ReservedVariable.Y.getName()) || variable.equals(ReservedVariable.Z.getName())) {
throw new ExpressionException("differentiation with respect to x,y,z not supported for vcConv() function");
}
//
// TODO: take advantage of commutative property of differential operators: d/dvar(conv(u,v)) = conv(du/dvar,dv/dvar) ????? (check this).
// so, if du/dvar=constant then grad(du/dvar) = 0, since grad(constant)=0
//
Expression exp0 = args[0].differentiate(variable).flatten();
Expression exp1 = args[1].differentiate(variable).flatten();
if (exp0.isNumeric() || exp1.isNumeric()) {
// conv(0,f) = 0
return new Expression(0.0);
} else {
return new Expression(Expression.function(FUNCTION_name, exp0, exp1));
}
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class FieldFunctionDefinition method differentiate.
public Expression differentiate(Expression[] args, String variable) throws ExpressionException {
if (variable == null) {
throw new RuntimeException("cannot differentiate with respect to a null variable");
}
if (args.length != 4) {
throw new IllegalArgumentException("expecting 4 arguments for vcField()");
}
if (variable.equals(ReservedVariable.X.getName()) || variable.equals(ReservedVariable.Y.getName()) || variable.equals(ReservedVariable.Z.getName())) {
throw new ExpressionException("differentiation with respect to x,y,z not supported for fields");
}
Expression timeArgument = args[2];
Expression exp = timeArgument.differentiate(variable);
if (exp.isZero()) {
return new Expression(0.0);
} else {
throw new ExpressionException("differentiation with respect to '" + variable + "' not supported for function vcField() with time argument '" + timeArgument.infix() + "'");
}
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class GradientFunctionDefinition method differentiate.
public Expression differentiate(Expression[] args, String variable) throws ExpressionException {
if (variable == null) {
throw new RuntimeException("cannot differentiate with respect to a null variable");
}
if (args.length != 2) {
throw new IllegalArgumentException("expecting 2 arguments for vcGrad()");
}
if (variable.equals(ReservedVariable.X.getName()) || variable.equals(ReservedVariable.Y.getName()) || variable.equals(ReservedVariable.Z.getName())) {
throw new ExpressionException("differentiation with respect to x,y,z not supported for vcGrad() function");
}
//
// take advantage of commutative property of differential operators: d/dvar(grad(u)) = grad(du/dvar)
// so, if du/dvar=constant then grad(du/dvar) = 0, since grad(constant)=0
//
Expression variableArgument = args[0];
Expression exp = variableArgument.differentiate(variable).flatten();
if (exp.isNumeric()) {
return new Expression(0.0);
} else {
throw new ExpressionException("differentiation with respect to '" + variable + "' not supported for function vcField() with time argument '" + variableArgument.infix() + "'");
}
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class FRAPEstimationPanel_NotUsed method initialize.
private void initialize() {
initTable();
for (int i = 0; i < FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults.BLEACH_TYPE_NAMES.length; i++) {
bleachEstimationComboBox.addItem(FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults.BLEACH_TYPE_NAMES[i]);
// bleachEstimationComboBox.insertItemAt(/*"Estimation method '"+*/"'"+FrapDataAnalysisResults.BLEACH_TYPE_NAMES[i]+"'", i);
}
bleachEstimationComboBox.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
// }else
if (bleachEstimationComboBox.getSelectedItem().equals(FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults.BLEACH_TYPE_NAMES[FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults.BleachType_GaussianSpot])) {
// expression on canvas
try {
String[] prefixes = new String[] { "I(t) = ", "u(t)= ", "D = " };
Expression[] expressions = new Expression[] { new Expression(FRAPDataAnalysis.gaussianSpot_IntensityFunc), new Expression(FRAPDataAnalysis.gaussianSpot_MuFunc), new Expression(FRAPDataAnalysis.gaussianSpot_DiffFunc) };
String[] suffixes = new String[] { "", "", "[um2.s-1]" };
expressionCanvas.setExpressions(expressions, prefixes, suffixes);
} catch (ExpressionException e2) {
e2.printStackTrace(System.out);
}
} else if (bleachEstimationComboBox.getSelectedItem().equals(FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults.BLEACH_TYPE_NAMES[FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults.BleachType_HalfCell])) {
// expression on canvas
try {
String[] prefixes = new String[] { "I(t) = ", "u(t)= ", "D = " };
Expression[] expressions = new Expression[] { new Expression(FRAPDataAnalysis.halfCell_IntensityFunc), new Expression(FRAPDataAnalysis.halfCell_MuFunc), new Expression(FRAPDataAnalysis.halfCell_DiffFunc) };
String[] suffixes = new String[] { "", "", "[um2.s-1]" };
expressionCanvas.setExpressions(expressions, prefixes, suffixes);
} catch (ExpressionException e2) {
e2.printStackTrace(System.out);
}
}
frapModelParameterLabel.setText(PARAM_EST_EQUATION_STRING + " ('" + bleachEstimationComboBox.getSelectedItem() + "')");
// FrapDataAnalysisResults.BLEACH_TYPE_NAMES[bleachEstimationComboBox.getSelectedIndex()]+"')");
try {
refreshFRAPModelParameterEstimates(initFRAPData, FRAPDataAnalysis.calculateRecoveryIndex(initFRAPData));
} catch (Exception e2) {
e2.printStackTrace();
DialogUtils.showErrorDialog(FRAPEstimationPanel_NotUsed.this, "Error setting estimation method " + FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults.BLEACH_TYPE_NAMES[bleachEstimationComboBox.getSelectedIndex()] + "\n" + e2.getMessage());
}
}
});
bleachEstimationComboBox.setSelectedItem(FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults.BLEACH_TYPE_NAMES[FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults.BleachType_GaussianSpot]);
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class BNGOutputFileParser method createBngSpeciesOutputSpec.
public static List<BNGSpecies> createBngSpeciesOutputSpec(String inputString) {
String newLineDelimiters = "\n\r";
StringTokenizer lineTokenizer = new StringTokenizer(inputString, newLineDelimiters);
String token1 = new String("");
String token2 = new String("");
String blankDelimiters = " \t";
List<BNGSpecies> speciesVector = new ArrayList<>();
while (lineTokenizer.hasMoreTokens()) {
token1 = lineTokenizer.nextToken();
StringTokenizer nextLine = null;
// Fill in list of species ONLY
nextLine = new StringTokenizer(token1, blankDelimiters);
int i = 0;
int speciesNtwkFileIndx = 0;
String speciesName = null;
Expression speciesConcExpr = null;
// 'nextLine' is the line with a species and its concentration; the index is necessary to build the reactions.
while (nextLine.hasMoreTokens()) {
token2 = nextLine.nextToken();
if (token2 != null) {
token2 = token2.trim();
}
// First token is index number, second is the name, last token is the concentration.
if (i == 0) {
speciesNtwkFileIndx = Integer.parseInt(token2);
} else if (i == 1) {
speciesName = token2;
} else if (i == 2) {
try {
speciesConcExpr = new Expression(token2);
} catch (ExpressionException e) {
throw new RuntimeException("Error in reading expression for species concentration \"" + speciesName + "\"");
}
}
i++;
}
// After parsing species from the line, create a new BNGSpecies and add it to speciesVector.
if (speciesName != null && speciesConcExpr != null && speciesNtwkFileIndx > 0) {
BNGSpecies newSpecies = null;
if (speciesName.indexOf(".") >= 0) {
newSpecies = new BNGComplexSpecies(speciesName, speciesConcExpr, speciesNtwkFileIndx);
} else if ((speciesName.indexOf("(") > 0) && (speciesName.indexOf(".") < 0)) {
newSpecies = new BNGMultiStateSpecies(speciesName, speciesConcExpr, speciesNtwkFileIndx);
} else {
newSpecies = new BNGSingleStateSpecies(speciesName, speciesConcExpr, speciesNtwkFileIndx);
}
speciesVector.add(newSpecies);
}
}
return speciesVector;
}
Aggregations