use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.
the class BNGDataPlotPanel method setOdeSolverResultSet.
/**
* Sets the dataSource property (cbit.vcell.modelopt.gui.DataSource) value.
* @param dataSource The new value for the property.
* @see #getDataSource
*/
public void setOdeSolverResultSet(ODESolverResultSet odeSolverResultSet) {
ODESolverResultSet oldValue = fieldOdeSolverResultSet;
fieldOdeSolverResultSet = odeSolverResultSet;
firePropertyChange("odeSolverResultSet", oldValue, odeSolverResultSet);
}
use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.
the class BNGOutputPanel method getOdeSolverResultSet.
/**
* Comment
*/
private ODESolverResultSet getOdeSolverResultSet(String fileContent) {
java.util.StringTokenizer tokenizer1 = new java.util.StringTokenizer(fileContent, "\n");
ODESolverResultSet odeResultSet = new ODESolverResultSet();
double[] values = null;
boolean bcolNamesRead = false;
while (tokenizer1.hasMoreTokens()) {
java.util.StringTokenizer tokenizer2 = new java.util.StringTokenizer(tokenizer1.nextToken(), ", \t\n\r\f");
if (!bcolNamesRead) {
bcolNamesRead = true;
while (tokenizer2.hasMoreTokens()) {
String token = tokenizer2.nextToken();
if (token.equals("#")) {
continue;
}
if (token.equalsIgnoreCase("time")) {
token = "t";
}
odeResultSet.addDataColumn(new ODESolverResultSetColumnDescription(token));
}
} else {
int i = 0;
values = new double[odeResultSet.getColumnDescriptionsCount()];
while (tokenizer2.hasMoreTokens()) {
values[i++] = Double.parseDouble(tokenizer2.nextToken());
}
odeResultSet.addRow(values);
}
}
return odeResultSet;
}
use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.
the class CopasiOptimizationSolver method getOdeSolverResultSet.
private static ODESolverResultSet getOdeSolverResultSet(RowColumnResultSet rcResultSet, SimulationSymbolTable simSymbolTable, String[] parameterNames, double[] parameterValues) {
//
// get simulation results - copy from RowColumnResultSet into OdeSolverResultSet
//
ODESolverResultSet odeSolverResultSet = new ODESolverResultSet();
for (int i = 0; i < rcResultSet.getDataColumnCount(); i++) {
odeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(rcResultSet.getColumnDescriptions(i).getName()));
}
for (int i = 0; i < rcResultSet.getRowCount(); i++) {
odeSolverResultSet.addRow(rcResultSet.getRow(i));
}
//
// add appropriate Function columns to result set
//
Function[] functions = simSymbolTable.getFunctions();
for (int i = 0; i < functions.length; i++) {
if (SimulationSymbolTable.isFunctionSaved(functions[i])) {
Expression exp1 = new Expression(functions[i].getExpression());
try {
exp1 = simSymbolTable.substituteFunctions(exp1).flatten();
//
for (int j = 0; parameterNames != null && j < parameterNames.length; j++) {
exp1.substituteInPlace(new Expression(parameterNames[j]), new Expression(parameterValues[j]));
}
} catch (MathException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
}
try {
FunctionColumnDescription cd = new FunctionColumnDescription(exp1.flatten(), functions[i].getName(), null, functions[i].getName(), false);
odeSolverResultSet.addFunctionColumn(cd);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
}
}
}
return odeSolverResultSet;
}
use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.
the class GibsonSolver method getStochSolverResultSet.
/**
* Get data columns and function columns to be ready for plot.
* Creation date: (8/15/2006 11:36:43 AM)
* @return cbit.vcell.solver.stoch.StochSolverResultSet
*/
public ODESolverResultSet getStochSolverResultSet() {
// read .stoch file, this funciton here equals to getODESolverRestultSet()+getStateVariableResultSet() in ODE.
ODESolverResultSet stSolverResultSet = new ODESolverResultSet();
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(getBaseName() + IDA_DATA_EXTENSION);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
// Read header
String line = bufferedReader.readLine();
if (line == null) {
// throw exception
System.out.println("There is no data in output file!");
return null;
}
while (line.indexOf(':') > 0) {
String name = line.substring(0, line.indexOf(':'));
stSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(name));
line = line.substring(line.indexOf(':') + 1);
}
// Read data
while ((line = bufferedReader.readLine()) != null) {
line = line + "\t";
double[] values = new double[stSolverResultSet.getDataColumnCount()];
boolean bCompleteRow = true;
for (int i = 0; i < stSolverResultSet.getDataColumnCount(); i++) {
if (line.indexOf('\t') == -1) {
bCompleteRow = false;
break;
} else {
String value = line.substring(0, line.indexOf('\t')).trim();
values[i] = Double.valueOf(value).doubleValue();
line = line.substring(line.indexOf('\t') + 1);
}
}
if (bCompleteRow) {
stSolverResultSet.addRow(values);
} else {
break;
}
}
//
} catch (Exception e) {
e.printStackTrace(System.out);
return null;
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (Exception ex) {
lg.error(ex.getMessage(), ex);
}
}
/*
Add appropriate Function columns to result set if the stochastic simulation is to display the trajectory.
No function columns for the results of multiple stochastic trials
*/
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
if (simSymbolTable.getSimulation().getSolverTaskDescription().getStochOpt().getNumOfTrials() == 1) {
Function[] functions = simSymbolTable.getFunctions();
for (int i = 0; i < functions.length; i++) {
if (SimulationSymbolTable.isFunctionSaved(functions[i])) {
Expression exp1 = new Expression(functions[i].getExpression());
try {
exp1 = simSymbolTable.substituteFunctions(exp1);
} catch (MathException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
}
try {
FunctionColumnDescription cd = new FunctionColumnDescription(exp1.flatten(), functions[i].getName(), null, functions[i].getName(), false);
stSolverResultSet.addFunctionColumn(cd);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
}
}
}
}
return stSolverResultSet;
}
use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.
the class HybridSolver method getHybridSolverResultSet.
/**
* Get data columns and function columns to be ready for plot.
* Creation date: (8/15/2006 11:36:43 AM)
* @return cbit.vcell.solver.stoch.StochSolverResultSet
*/
private ODESolverResultSet getHybridSolverResultSet() {
// read .stoch file, this funciton here equals to getODESolverRestultSet()+getStateVariableResultSet() in ODE.
ODESolverResultSet stSolverResultSet = new ODESolverResultSet();
try {
String filename = getBaseName() + NETCDF_DATA_EXTENSION;
NetCDFEvaluator ncEva = new NetCDFEvaluator();
NetCDFReader ncReader = null;
try {
ncEva.setNetCDFTarget(filename);
ncReader = ncEva.getNetCDFReader();
} catch (Exception e) {
e.printStackTrace(System.err);
throw new RuntimeException("Cannot open simulation result file: " + filename + "!");
}
// Read result according to trial number
if (ncReader.getNumTrials() == 1) {
// Read header
String[] varNames = ncReader.getSpeciesNames_val();
// first column will be time t.
stSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
// following columns are stoch variables
for (int i = 0; i < varNames.length; i++) {
stSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(varNames[i]));
}
// Read data
// data only, no time points
ArrayDouble data = (ArrayDouble) ncEva.getTimeSeriesData(1);
double[] timePoints = ncReader.getTimePoints();
System.out.println("time points length is " + timePoints.length);
// shape[0]:num of timepoints, shape[1]: num of species
int[] shape = data.getShape();
if (// one species
shape.length == 1) {
ArrayDouble.D1 temData = (ArrayDouble.D1) data;
System.out.println("one species in time series data and size is " + temData.getSize());
for (// rows
int k = 0; // rows
k < timePoints.length; // rows
k++) {
double[] values = new double[stSolverResultSet.getDataColumnCount()];
values[0] = timePoints[k];
for (int i = 1; i < stSolverResultSet.getDataColumnCount(); i++) {
values[i] = temData.get(k);
}
stSolverResultSet.addRow(values);
}
}
if (// more than one species
shape.length == 2) {
ArrayDouble.D2 temData = (ArrayDouble.D2) data;
System.out.println("multiple species in time series, the length of time series is :" + data.getShape()[0] + ", and the total number of speceis is: " + data.getShape()[1]);
for (// rows
int k = 0; // rows
k < timePoints.length; // rows
k++) {
double[] values = new double[stSolverResultSet.getDataColumnCount()];
values[0] = timePoints[k];
for (int i = 1; i < stSolverResultSet.getDataColumnCount(); i++) {
values[i] = temData.get(k, i - 1);
}
stSolverResultSet.addRow(values);
}
}
} else if (ncReader.getNumTrials() > 1) {
// Read header
String[] varNames = ncReader.getSpeciesNames_val();
// first column will be time t.
stSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("TrialNo"));
// following columns are stoch variables
for (int i = 0; i < varNames.length; i++) {
stSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(varNames[i]));
}
// Read data
// data only, no trial numbers
ArrayDouble data = (ArrayDouble) ncEva.getDataOverTrials(ncReader.getTimePoints().length - 1);
int[] trialNum = ncEva.getNetCDFReader().getTrialNumbers();
// System.out.println("total trials are "+trialNum.length);
// shape[0]:number of trials, shape[1]: num of species
int[] shape = data.getShape();
if (// one species
shape.length == 1) {
ArrayDouble.D1 temData = (ArrayDouble.D1) data;
// System.out.println("one species over trials, size is: "+temData.getSize());
for (// rows
int k = 0; // rows
k < trialNum.length; // rows
k++) {
double[] values = new double[stSolverResultSet.getDataColumnCount()];
values[0] = trialNum[k];
for (int i = 1; i < stSolverResultSet.getDataColumnCount(); i++) {
values[i] = temData.get(k);
}
stSolverResultSet.addRow(values);
}
}
if (// more than one species
shape.length == 2) {
ArrayDouble.D2 temData = (ArrayDouble.D2) data;
// System.out.println("multiple species in multiple trials, the length of trials is :"+data.getShape()[0]+", and the total number of speceis is: "+data.getShape()[1]);
for (// rows
int k = 0; // rows
k < trialNum.length; // rows
k++) {
double[] values = new double[stSolverResultSet.getDataColumnCount()];
values[0] = trialNum[k];
for (int i = 1; i < stSolverResultSet.getDataColumnCount(); i++) {
values[i] = temData.get(k, i - 1);
}
stSolverResultSet.addRow(values);
}
}
} else {
throw new RuntimeException("Number of trials should be a countable positive value, from 1 to N.");
}
} catch (Exception e) {
e.printStackTrace(System.err);
throw new RuntimeException("Problem encountered in parsing hybrid simulation results.\n" + e.getMessage());
}
/*
*Add appropriate Function columns to result set if the stochastic simulation is to display the trajectory.
*No function columns for the results of multiple stochastic trials.
*In stochastic simulation the functions include probability functions and clamped variable.
*/
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
if (simSymbolTable.getSimulation().getSolverTaskDescription().getStochOpt().getNumOfTrials() == 1) {
Function[] functions = simSymbolTable.getFunctions();
for (int i = 0; i < functions.length; i++) {
if (SimulationSymbolTable.isFunctionSaved(functions[i])) {
Expression exp1 = new Expression(functions[i].getExpression());
try {
exp1 = simSymbolTable.substituteFunctions(exp1);
} catch (MathException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
}
try {
FunctionColumnDescription cd = new FunctionColumnDescription(exp1.flatten(), functions[i].getName(), null, functions[i].getName(), false);
stSolverResultSet.addFunctionColumn(cd);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
}
}
}
}
return stSolverResultSet;
}
Aggregations