use of cbit.vcell.solver.OutputTimeSpec in project vcell by virtualcell.
the class RuleBasedTest method checkNonspatialStochasticSimContext.
private static void checkNonspatialStochasticSimContext(SimulationContext srcSimContext, File baseDirectory, int numTrials) throws Exception {
if (!srcSimContext.getApplicationType().equals(Application.NETWORK_STOCHASTIC) || srcSimContext.getGeometry().getDimension() != 0) {
throw new RuntimeException("simContext is of type " + srcSimContext.getApplicationType() + " and geometry dimension of " + srcSimContext.getGeometry().getDimension() + ", expecting nonspatial stochastic");
}
BioModel origBioModel = srcSimContext.getBioModel();
BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(XmlHelper.bioModelToXML(origBioModel)));
bioModel.refreshDependencies();
// create ODE and RuleBased
SimulationContext newODEApp = SimulationContext.copySimulationContext(srcSimContext, "aUniqueNewODEApp", false, Application.NETWORK_DETERMINISTIC);
SimulationContext newRuleBasedApp = SimulationContext.copySimulationContext(srcSimContext, "aUniqueNewRuleBasedApp", false, Application.RULE_BASED_STOCHASTIC);
newODEApp.setBioModel(bioModel);
newRuleBasedApp.setBioModel(bioModel);
ArrayList<AnnotatedFunction> outputFunctionsList = srcSimContext.getOutputFunctionContext().getOutputFunctionsList();
// OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
newODEApp.getOutputFunctionContext().setOutputFunctions(outputFunctionsList);
newRuleBasedApp.getOutputFunctionContext().setOutputFunctions(outputFunctionsList);
NetworkGenerationRequirements networkGenerationRequirements = NetworkGenerationRequirements.AllowTruncatedStandardTimeout;
bioModel.addSimulationContext(newODEApp);
newODEApp.refreshMathDescription(new MathMappingCallbackTaskAdapter(null), networkGenerationRequirements);
bioModel.addSimulationContext(newRuleBasedApp);
newRuleBasedApp.refreshMathDescription(new MathMappingCallbackTaskAdapter(null), networkGenerationRequirements);
srcSimContext.refreshMathDescription(new MathMappingCallbackTaskAdapter(null), networkGenerationRequirements);
// Create non-spatialStoch, ODE and RuleBased sims
Simulation nonspatialStochAppNewSim = srcSimContext.addNewSimulation(STOCH_SIM_NAME, /*SimulationOwner.DEFAULT_SIM_NAME_PREFIX*/
new MathMappingCallbackTaskAdapter(null), networkGenerationRequirements);
Simulation newODEAppNewSim = newODEApp.addNewSimulation(ODE_SIM_NAME, new MathMappingCallbackTaskAdapter(null), networkGenerationRequirements);
Simulation newRuleBasedAppNewSim = newRuleBasedApp.addNewSimulation(NFS_SIM_NAME, new MathMappingCallbackTaskAdapter(null), networkGenerationRequirements);
nonspatialStochAppNewSim.setSimulationOwner(srcSimContext);
newODEAppNewSim.setSimulationOwner(newODEApp);
newRuleBasedAppNewSim.setSimulationOwner(newRuleBasedApp);
try {
bioModel.getModel().getSpeciesContexts();
ArrayList<String> varNameList = new ArrayList<String>();
for (SpeciesContextSpec scs : srcSimContext.getReactionContext().getSpeciesContextSpecs()) {
varNameList.add(scs.getSpeciesContext().getName());
}
String[] varNames = varNameList.toArray(new String[0]);
OutputTimeSpec outputTimeSpec = nonspatialStochAppNewSim.getSolverTaskDescription().getOutputTimeSpec();
ArrayList<Double> sampleTimeList = new ArrayList<Double>();
if (outputTimeSpec instanceof UniformOutputTimeSpec) {
double endingTime = nonspatialStochAppNewSim.getSolverTaskDescription().getTimeBounds().getEndingTime();
double dT = ((UniformOutputTimeSpec) outputTimeSpec).getOutputTimeStep();
int currTimeIndex = 0;
while (currTimeIndex * dT <= (endingTime + 1e-8)) {
sampleTimeList.add(currTimeIndex * dT);
currTimeIndex++;
}
}
double[] sampleTimes = new double[sampleTimeList.size()];
for (int i = 0; i < sampleTimes.length; i++) {
sampleTimes[i] = sampleTimeList.get(i);
}
TimeSeriesMultitrialData sampleDataStoch1 = new TimeSeriesMultitrialData("stochastic1", varNames, sampleTimes, numTrials);
TimeSeriesMultitrialData sampleDataStoch2 = new TimeSeriesMultitrialData("stochastic2", varNames, sampleTimes, numTrials);
TimeSeriesMultitrialData sampleDataDeterministic = new TimeSeriesMultitrialData("determinstic", varNames, sampleTimes, 1);
runsolver(nonspatialStochAppNewSim, baseDirectory, numTrials, sampleDataStoch1);
runsolver(newODEAppNewSim, baseDirectory, 1, sampleDataDeterministic);
runsolver(newRuleBasedAppNewSim, baseDirectory, numTrials, sampleDataStoch2);
writeVarDiffData(baseDirectory, sampleDataStoch1, sampleDataStoch2);
writeKolmogorovSmirnovTest(baseDirectory, sampleDataStoch1, sampleDataStoch2);
writeChiSquareTest(baseDirectory, sampleDataStoch1, sampleDataStoch2);
writeData(baseDirectory, sampleDataStoch1);
writeData(baseDirectory, sampleDataStoch2);
writeData(baseDirectory, sampleDataDeterministic);
} finally {
srcSimContext.removeSimulation(nonspatialStochAppNewSim);
newODEApp.removeSimulation(newODEAppNewSim);
newRuleBasedApp.removeSimulation(newRuleBasedAppNewSim);
}
}
use of cbit.vcell.solver.OutputTimeSpec in project vcell by virtualcell.
the class SimulationListPanel method initConnections.
/**
* Initializes connections
* @exception java.lang.Exception The exception description.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initConnections() throws java.lang.Exception {
// user code begin {1}
// user code end
getNewButton().addActionListener(ivjEventHandler);
getEditButton().addActionListener(ivjEventHandler);
getDeleteButton().addActionListener(ivjEventHandler);
getRunButton().addActionListener(ivjEventHandler);
// getPythonResultsButton().addActionListener(ivjEventHandler);
getNativeResultsButton().addActionListener(ivjEventHandler);
getMoreActionsButton().addActionListener(ivjEventHandler);
getScrollPaneTable().addPropertyChangeListener(ivjEventHandler);
getOutputFunctionsPanel().addPropertyChangeListener(ivjEventHandler);
getScrollPaneTable().getSelectionModel().addListSelectionListener(ivjEventHandler);
DefaultScrollTableCellRenderer renderer = new DefaultScrollTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (value instanceof OutputTimeSpec) {
SimulationWorkspace sw = getSimulationWorkspace();
SimulationOwner so = sw.getSimulationOwner();
UnitInfo unitInfo = so.getUnitInfo();
Objects.requireNonNull(unitInfo);
OutputTimeSpec ots = (OutputTimeSpec) value;
String text = ots.describe(unitInfo);
setText(text);
} else if (value instanceof Double) {
setText(value + "");
}
boolean bFinitVolumeRerun = false;
if (value instanceof SolverDescription) {
SolverDescription solverDescription = (SolverDescription) value;
try {
if (FINITEVOLUME_CUTTOFF != null && solverDescription.equals(SolverDescription.FiniteVolume)) /*Compiled Solver*/
{
SimulationStatus simStatus = getSimulationWorkspace().getSimulationStatus(getSimulationListTableModel1().getValueAt(row));
if (simStatus.getHasData()) {
int statusIndex = 0;
while (simStatus.getJobStatus(statusIndex) != null) {
if (simStatus.getJobStatus(statusIndex).getEndDate().compareTo(FINITEVOLUME_CUTTOFF) > 0) {
bFinitVolumeRerun = true;
break;
}
statusIndex++;
}
}
}
} catch (Exception e) {
// ignore, let table cell render anyway
e.printStackTrace();
}
setText(solverDescription.getShortDisplayLabel());
setToolTipText(solverDescription.getDisplayLabel());
} else {
setToolTipText(getText());
}
if (bFinitVolumeRerun) {
setText(getText() + (bFinitVolumeRerun ? "(*)" : ""));
setToolTipText(getToolTipText() + (bFinitVolumeRerun ? " (data regenerated using FiniteVolumeStandalone)" : ""));
}
return this;
}
};
getScrollPaneTable().setDefaultRenderer(OutputTimeSpec.class, renderer);
getScrollPaneTable().setDefaultRenderer(Double.class, renderer);
getScrollPaneTable().setDefaultRenderer(String.class, renderer);
getScrollPaneTable().setDefaultRenderer(SolverDescription.class, renderer);
getScrollPaneTable().setDefaultEditor(OutputTimeSpec.class, new DefaultCellEditor(new JTextField()));
getScrollPaneTable().setDefaultRenderer(SimulationStatus.class, new DefaultScrollTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Object obj = getSimulationStatusDisplay(row);
if (obj instanceof JProgressBar) {
return (JProgressBar) obj;
}
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (value instanceof SimulationStatus) {
setText(obj.toString());
String details = ((SimulationStatus) value).getDetails();
setToolTipText(details);
}
return this;
}
});
}
use of cbit.vcell.solver.OutputTimeSpec in project vcell by virtualcell.
the class SimulationListTableModel method setValueAt.
/**
* Insert the method's description here.
* Creation date: (7/12/2004 2:01:23 PM)
* @param aValue java.lang.Object
* @param rowIndex int
* @param columnIndex int
*/
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
Simulation simulation = getValueAt(rowIndex);
try {
switch(columnIndex) {
case COLUMN_NAME:
if (aValue instanceof String) {
String newName = (String) aValue;
if (!simulation.getName().equals(newName)) {
simulation.setName(newName);
}
}
break;
case COLUMN_ENDTIME:
if (aValue instanceof Double) {
SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
double newEndTime = (Double) aValue;
if (newEndTime != solverTaskDescription.getTimeBounds().getEndingTime()) {
ClientTaskManager.changeEndTime(ownerTable, solverTaskDescription, newEndTime);
simulation.setIsDirty(true);
}
}
break;
case COLUMN_OUTPUT:
if (aValue instanceof String) {
SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
OutputTimeSpec ots = solverTaskDescription.getOutputTimeSpec();
OutputTimeSpec newOts = null;
if (ots instanceof DefaultOutputTimeSpec) {
int newValue = Integer.parseInt((String) aValue);
newOts = new DefaultOutputTimeSpec(newValue, ((DefaultOutputTimeSpec) ots).getKeepAtMost());
} else if (ots instanceof UniformOutputTimeSpec) {
try {
boolean bValid = true;
double outputTime = Double.parseDouble((String) aValue);
if (solverTaskDescription.getOutputTimeSpec().isUniform()) {
if (solverTaskDescription.getSolverDescription().hasVariableTimestep()) {
newOts = new UniformOutputTimeSpec(outputTime);
} else {
double timeStep = solverTaskDescription.getTimeStep().getDefaultTimeStep();
double suggestedInterval = outputTime;
if (outputTime < timeStep) {
suggestedInterval = timeStep;
bValid = false;
} else {
if (!BeanUtils.isIntegerMultiple(outputTime, timeStep)) {
double n = outputTime / timeStep;
int intn = (int) Math.round(n);
suggestedInterval = (intn * timeStep);
if (suggestedInterval != outputTime) {
bValid = false;
}
}
}
if (bValid) {
newOts = new UniformOutputTimeSpec(outputTime);
} else {
String ret = PopupGenerator.showWarningDialog(ownerTable, "Output Interval", "Output Interval must " + "be integer multiple of time step.\n\nChange Output Interval to " + suggestedInterval + "?", new String[] { UserMessage.OPTION_YES, UserMessage.OPTION_NO }, UserMessage.OPTION_YES);
if (ret.equals(UserMessage.OPTION_YES)) {
newOts = new UniformOutputTimeSpec(suggestedInterval);
}
}
}
}
} catch (NumberFormatException ex) {
DialogUtils.showErrorDialog(ownerTable, "Wrong number format " + ex.getMessage().toLowerCase());
}
} else if (ots instanceof ExplicitOutputTimeSpec) {
newOts = ExplicitOutputTimeSpec.fromString((String) aValue);
}
if (newOts != null && !newOts.compareEqual(ots)) {
solverTaskDescription.setOutputTimeSpec(newOts);
simulation.setIsDirty(true);
}
}
break;
}
} catch (Exception ex) {
ex.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
}
}
use of cbit.vcell.solver.OutputTimeSpec in project vcell by virtualcell.
the class OdeFileWriter method write.
/**
* Insert the method's description here.
* Creation date: (3/8/00 10:31:52 PM)
*/
public void write(String[] parameterNames) throws Exception {
createStateVariables();
createSymbolTable();
Simulation simulation = simTask.getSimulation();
if (simulation.getSolverTaskDescription().getUseSymbolicJacobian()) {
throw new RuntimeException("symbolic jacobian option not yet supported in interpreted Stiff solver");
}
writeJMSParamters();
SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
TimeBounds timeBounds = solverTaskDescription.getTimeBounds();
ErrorTolerance errorTolerance = solverTaskDescription.getErrorTolerance();
printWriter.println("SOLVER " + getSolverName());
printWriter.println("STARTING_TIME " + timeBounds.getStartingTime());
printWriter.println("ENDING_TIME " + timeBounds.getEndingTime());
printWriter.println("RELATIVE_TOLERANCE " + errorTolerance.getRelativeErrorTolerance());
printWriter.println("ABSOLUTE_TOLERANCE " + errorTolerance.getAbsoluteErrorTolerance());
printWriter.println("MAX_TIME_STEP " + simulation.getSolverTaskDescription().getTimeStep().getMaximumTimeStep());
OutputTimeSpec ots = simulation.getSolverTaskDescription().getOutputTimeSpec();
if (ots.isDefault()) {
printWriter.println("KEEP_EVERY " + ((DefaultOutputTimeSpec) ots).getKeepEvery());
} else if (ots.isUniform()) {
printWriter.println("OUTPUT_TIME_STEP " + ((UniformOutputTimeSpec) ots).getOutputTimeStep());
} else if (ots.isExplicit()) {
printWriter.println("OUTPUT_TIMES " + ((ExplicitOutputTimeSpec) ots).getNumTimePoints());
printWriter.println(((ExplicitOutputTimeSpec) ots).toSpaceSeperatedMultiLinesOfString());
}
if (parameterNames != null && parameterNames.length != 0) {
printWriter.println("NUM_PARAMETERS " + parameterNames.length);
for (int i = 0; i < parameterNames.length; i++) {
printWriter.println(parameterNames[i]);
}
}
HashMap<Discontinuity, String> discontinuityNameMap = new HashMap<Discontinuity, String>();
String eventString = null;
if (simulation.getMathDescription().hasEvents()) {
eventString = writeEvents(discontinuityNameMap);
}
String equationString = writeEquations(discontinuityNameMap);
if (discontinuityNameMap.size() > 0) {
printWriter.println("DISCONTINUITIES " + discontinuityNameMap.size());
for (Discontinuity od : discontinuityNameMap.keySet()) {
printWriter.println(discontinuityNameMap.get(od) + " " + od.getDiscontinuityExp().flatten().infix() + "; " + od.getRootFindingExp().flatten().infix() + ";");
}
}
if (eventString != null) {
printWriter.print(eventString);
}
printWriter.println("NUM_EQUATIONS " + getStateVariableCount());
printWriter.println(equationString);
}
use of cbit.vcell.solver.OutputTimeSpec in project vcell by virtualcell.
the class NFSimSolver method getMathExecutableCommand.
@Override
protected String[] getMathExecutableCommand() {
String executableName = null;
try {
executableName = SolverUtilities.getExes(SolverDescription.NFSim)[0].getAbsolutePath();
} catch (IOException e) {
throw new RuntimeException("failed to get executable for solver " + SolverDescription.NFSim.getDisplayLabel() + ": " + e.getMessage(), e);
}
String inputFilename = getInputFilename();
String outputFilename = getOutputFilename();
String speciesOutputFilename = getSpeciesOutputFilename();
NFsimSimulationOptions nfsso = simTask.getSimulation().getSolverTaskDescription().getNFSimSimulationOptions();
ArrayList<String> adv = new ArrayList<String>();
boolean observableComputationOff = nfsso.getObservableComputationOff();
if (observableComputationOff == true) {
// false is by default, no need to specify
adv.add("-notf");
}
Integer moleculeDistance = nfsso.getMoleculeDistance();
if (moleculeDistance != null) {
adv.add("-utl");
adv.add(moleculeDistance + "");
}
boolean aggregateBookkeeping = nfsso.getAggregateBookkeeping();
if (aggregateBookkeeping == true || simTask.getSimulation().getMathDescription().hasSpeciesObservable()) {
// false is by default, no need to specify
adv.add("-cb");
}
Integer maxMoleculesPerType = nfsso.getMaxMoleculesPerType();
if (maxMoleculesPerType != null) {
adv.add("-gml");
adv.add(maxMoleculesPerType + "");
}
Integer equilibrateTime = nfsso.getEquilibrateTime();
if (equilibrateTime != null) {
adv.add("-eq");
adv.add(equilibrateTime + "");
}
boolean preventIntraBonds = nfsso.getPreventIntraBonds();
if (preventIntraBonds == true) {
// false is by default, no need to specify
adv.add("-bscb");
}
TimeBounds tb = getSimulationJob().getSimulation().getSolverTaskDescription().getTimeBounds();
double dtime = tb.getEndingTime() - tb.getStartingTime();
String timeSpecOption1 = "-oSteps";
String timeSpecOption2 = "10";
OutputTimeSpec outputTimeSpec = getSimulationJob().getSimulation().getSolverTaskDescription().getOutputTimeSpec();
if (outputTimeSpec instanceof DefaultOutputTimeSpec) {
DefaultOutputTimeSpec dots = (DefaultOutputTimeSpec) outputTimeSpec;
int steps = dots.getKeepAtMost();
timeSpecOption1 = "-oSteps";
timeSpecOption2 = Integer.toString(steps);
} else if (outputTimeSpec instanceof UniformOutputTimeSpec) {
UniformOutputTimeSpec dots = (UniformOutputTimeSpec) outputTimeSpec;
double steps = dtime / dots.getOutputTimeStep();
timeSpecOption1 = "-oSteps";
int stepsi = (int) Math.round(steps);
timeSpecOption2 = Integer.toString(stepsi);
} else {
throw new RuntimeException("Unsupported output time spec class");
}
String[] baseCommands = { "-xml", inputFilename, "-o", outputFilename, "-sim", Double.toString(dtime), "-ss", speciesOutputFilename };
ArrayList<String> cmds = new ArrayList<String>();
cmds.add(executableName);
Integer seed = nfsso.getRandomSeed();
if (seed != null) {
cmds.add("-seed");
cmds.add(seed.toString());
} else {
long randomSeed = System.currentTimeMillis();
randomSeed = randomSeed + simTask.getSimulationJob().getJobIndex();
// multiply with a large prime number to spread numbers that are too close and in sequence
randomSeed = randomSeed * 89611;
Integer rs = (int) randomSeed;
String str = rs.toString();
if (str.startsWith("-")) {
// NFSim wants a positive integer, for anything else is initializing with 0
str = str.substring(1);
}
cmds.add("-seed");
cmds.add(str);
// PrintWriter writer;
// try {
// writer = new PrintWriter("c:\\TEMP\\aaa\\" + randomSeed + ".txt", "UTF-8");
// writer.println(str);
// writer.close();
// } catch (FileNotFoundException | UnsupportedEncodingException e) {
// // Auto-generated catch block
// e.printStackTrace();
// }
}
cmds.add("-vcell");
cmds.addAll(new ArrayList<String>(Arrays.asList(baseCommands)));
cmds.add(timeSpecOption1);
cmds.add(timeSpecOption2);
cmds.addAll(adv);
if (bMessaging) {
cmds.add("-v");
}
return cmds.toArray(new String[cmds.size()]);
}
Aggregations