use of cbit.vcell.solver.DataProcessingInstructions in project vcell by virtualcell.
the class SmoldynFileWriter method writeDataProcessor.
private void writeDataProcessor() throws DataAccessException, IOException, MathException, DivideByZeroException, ExpressionException {
Simulation simulation = simTask.getSimulation();
DataProcessingInstructions dpi = simulation.getDataProcessingInstructions();
if (dpi == null) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " begin " + DataProcessingInstructions.ROI_TIME_SERIES);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " end");
} else {
FieldDataIdentifierSpec fdis = dpi.getSampleImageFieldData(simulation.getVersion().getOwner());
if (fdis == null) {
throw new DataAccessException("Can't find sample image in data processing instructions");
}
File userDirectory = outputFile.getParentFile();
String secondarySimDataDir = PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, null);
DataSetControllerImpl dsci = new DataSetControllerImpl(null, userDirectory.getParentFile(), secondarySimDataDir == null ? null : new File(secondarySimDataDir));
CartesianMesh origMesh = dsci.getMesh(fdis.getExternalDataIdentifier());
SimDataBlock simDataBlock = dsci.getSimDataBlock(null, fdis.getExternalDataIdentifier(), fdis.getFieldFuncArgs().getVariableName(), fdis.getFieldFuncArgs().getTime().evaluateConstant());
VariableType varType = fdis.getFieldFuncArgs().getVariableType();
VariableType dataVarType = simDataBlock.getVariableType();
if (!varType.equals(VariableType.UNKNOWN) && !varType.equals(dataVarType)) {
throw new IllegalArgumentException("field function variable type (" + varType.getTypeName() + ") doesn't match real variable type (" + dataVarType.getTypeName() + ")");
}
double[] origData = simDataBlock.getData();
String filename = SimulationJob.createSimulationJobID(Simulation.createSimulationID(simulation.getKey()), simTask.getSimulationJob().getJobIndex()) + SimulationData.getDefaultFieldDataFileNameForSimulation(fdis.getFieldFuncArgs());
File fdatFile = new File(userDirectory, filename);
DataSet.writeNew(fdatFile, new String[] { fdis.getFieldFuncArgs().getVariableName() }, new VariableType[] { simDataBlock.getVariableType() }, new ISize(origMesh.getSizeX(), origMesh.getSizeY(), origMesh.getSizeZ()), new double[][] { origData });
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " begin " + dpi.getScriptName());
StringTokenizer st = new StringTokenizer(dpi.getScriptInput(), "\n\r");
while (st.hasMoreTokens()) {
String str = st.nextToken();
if (str.trim().length() > 0) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " " + str);
}
}
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " SampleImageFile " + fdis.getFieldFuncArgs().getVariableName() + " " + fdis.getFieldFuncArgs().getTime().infix() + " " + fdatFile);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " end");
}
}
use of cbit.vcell.solver.DataProcessingInstructions in project vcell by virtualcell.
the class XmlReader method getSimulation.
/**
* This method returns a Simulation object from a XML element.
* Creation date: (4/26/2001 12:14:30 PM)
* @return cbit.vcell.solver.Simulation
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
Simulation getSimulation(Element param, MathDescription mathDesc) throws XmlParseException {
// retrive metadata (if any)
SimulationVersion simulationVersion = getSimulationVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
// create new simulation
Simulation simulation = null;
if (simulationVersion != null) {
simulation = new Simulation(simulationVersion, mathDesc);
} else {
simulation = new Simulation(mathDesc);
}
// set attributes
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
try {
simulation.setName(name);
// String annotation = param.getAttributeValue(XMLTags.AnnotationAttrTag);
// if (annotation!=null) {
// simulation.setDescription(unMangle(annotation));
// }
// Add Annotation
String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotationText != null && annotationText.length() > 0) {
simulation.setDescription(unMangle(annotationText));
}
} catch (java.beans.PropertyVetoException e) {
throw new XmlParseException(e);
}
// Retrieve MathOverrides
simulation.setMathOverrides(getMathOverrides(param.getChild(XMLTags.MathOverridesTag, vcNamespace), simulation));
// Retrieve SolverTaskDescription
try {
simulation.setSolverTaskDescription(getSolverTaskDescription(param.getChild(XMLTags.SolverTaskDescriptionTag, vcNamespace), simulation));
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException was fired when setting the SolverTaskDescroiption object to the Simulation object " + name, e);
}
Element dataProcessingInstructionsElement = param.getChild(XMLTags.DataProcessingInstructionsTag, vcNamespace);
if (dataProcessingInstructionsElement != null) {
String scriptName = dataProcessingInstructionsElement.getAttributeValue(XMLTags.DataProcessingScriptNameAttrTag);
String scriptInput = dataProcessingInstructionsElement.getText();
simulation.setDataProcessingInstructions(new DataProcessingInstructions(scriptName, scriptInput));
}
// Retrieve MeshEspecification (if any)
Element tempElement = param.getChild(XMLTags.MeshSpecTag, vcNamespace);
if (tempElement != null) {
try {
simulation.setMeshSpecification(getMeshSpecification(tempElement, mathDesc.getGeometry()));
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A ProperyVetoException was fired when setting the MeshSpecification to a new Simulation!", e);
}
}
return simulation;
}
use of cbit.vcell.solver.DataProcessingInstructions in project vcell by virtualcell.
the class ClientSimManager method runQuickSimulation.
public void runQuickSimulation(final Simulation originalSimulation, ViewerType viewerType) {
Collection<AsynchClientTask> taskList = new ArrayList<AsynchClientTask>();
final SimulationOwner simulationOwner = simWorkspace.getSimulationOwner();
// ----------- update math if it is from biomodel (simulationContext)
if (simulationOwner instanceof SimulationContext) {
Collection<AsynchClientTask> ut = ClientRequestManager.updateMath(documentWindowManager.getComponent(), ((SimulationContext) simulationOwner), false, NetworkGenerationRequirements.ComputeFullStandardTimeout);
taskList.addAll(ut);
}
// Let user tell how many simultaneous processes to run if this is local paramscan
final int[] simultaneousSimsSetting = new int[] { 1 };
if (originalSimulation.getScanCount() > 1) {
try {
String simultaneousSims = DialogUtils.showInputDialog0(getDocumentWindowManager().getComponent(), "Local multi-scan simulation, enter maximum simulataneous sims to run at once", "1");
simultaneousSimsSetting[0] = Integer.parseInt(simultaneousSims);
} catch (UtilCancelException e) {
return;
}
}
// ----------- run simulation(s)
final File localSimDataDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
AsynchClientTask runSimTask = new AsynchClientTask("running simulation", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Simulation simulation = new TempSimulation(originalSimulation, false);
simulation.setSimulationOwner(originalSimulation.getSimulationOwner());
SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, null), 0);
Solver solver = createQuickRunSolver(localSimDataDir, simTask);
if (solver == null) {
throw new RuntimeException("null solver");
}
// check if spatial stochastic simulation (smoldyn solver) has data processing instructions with field data - need to access server for field data, so cannot do local simulation run.
if (solver instanceof SmoldynSolver) {
DataProcessingInstructions dpi = simulation.getDataProcessingInstructions();
if (dpi != null) {
FieldDataIdentifierSpec fdis = dpi.getSampleImageFieldData(simulation.getVersion().getOwner());
if (fdis != null) {
throw new RuntimeException("Spatial Stochastic simulation '" + simulation.getName() + "' (Smoldyn solver) with field data (in data processing instructions) cannot be run locally at this time since field data needs to be retrieved from the VCell server.");
}
}
}
solver.addSolverListener(new SolverListener() {
public void solverStopped(SolverEvent event) {
getClientTaskStatusSupport().setMessage(event.getSimulationMessage().getDisplayMessage());
}
public void solverStarting(SolverEvent event) {
String displayMessage = event.getSimulationMessage().getDisplayMessage();
System.out.println(displayMessage);
getClientTaskStatusSupport().setMessage(displayMessage);
if (displayMessage.equals(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT.getDisplayMessage())) {
getClientTaskStatusSupport().setProgress(75);
} else if (displayMessage.equals(SimulationMessage.MESSAGE_SOLVER_RUNNING_INPUT_FILE.getDisplayMessage())) {
getClientTaskStatusSupport().setProgress(90);
}
}
public void solverProgress(SolverEvent event) {
getClientTaskStatusSupport().setMessage("Running...");
int progress = (int) (event.getProgress() * 100);
getClientTaskStatusSupport().setProgress(progress);
}
public void solverPrinted(SolverEvent event) {
getClientTaskStatusSupport().setMessage("Running...");
}
public void solverFinished(SolverEvent event) {
getClientTaskStatusSupport().setMessage(event.getSimulationMessage().getDisplayMessage());
}
public void solverAborted(SolverEvent event) {
getClientTaskStatusSupport().setMessage(event.getSimulationMessage().getDisplayMessage());
}
});
solver.startSolver();
while (true) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
if (getClientTaskStatusSupport().isInterrupted()) {
solver.stopSolver();
throw UserCancelException.CANCEL_GENERIC;
}
SolverStatus solverStatus = solver.getSolverStatus();
if (solverStatus != null) {
if (solverStatus.getStatus() == SolverStatus.SOLVER_ABORTED) {
String simulationMessage = solverStatus.getSimulationMessage().getDisplayMessage();
String translatedMessage = solver.translateSimulationMessage(simulationMessage);
if (translatedMessage.startsWith(BeanUtils.FD_EXP_MESSG)) {
throw new RuntimeException("Sims with FieldData can only be run remotely (cannot use QuickRun).\n" + translatedMessage);
} else {
throw new RuntimeException(translatedMessage);
}
}
if (solverStatus.getStatus() != SolverStatus.SOLVER_STARTING && solverStatus.getStatus() != SolverStatus.SOLVER_READY && solverStatus.getStatus() != SolverStatus.SOLVER_RUNNING) {
break;
}
}
}
ArrayList<AnnotatedFunction> outputFunctionsList = getSimWorkspace().getSimulationOwner().getOutputFunctionContext().getOutputFunctionsList();
OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
Simulation[] simsArray = new Simulation[] { simulation };
hashTable.put("outputContext", outputContext);
hashTable.put("simsArray", simsArray);
}
};
taskList.add(runSimTask);
// --------- add tasks from showSimResults : retrieve data, display results
AsynchClientTask[] showResultsTask = showSimulationResults0(true, viewerType);
for (AsynchClientTask task : showResultsTask) {
taskList.add(task);
}
AsynchClientTask runOthers = new AsynchClientTask("running scans", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (getClientTaskStatusSupport().isInterrupted()) {
throw UserCancelException.CANCEL_GENERIC;
}
Simulation[] sims = (Simulation[]) hashTable.get("simsArray");
Simulation simulation = sims[0];
// Run param scans to generate data for scansnum > 0
if (simulation.getScanCount() > 1) {
// Start master thread so clientdispatcher modal dialog can end
new Thread(new Runnable() {
@Override
public void run() {
// Flag (set by dataviewer being closed) so sim scan threads know if they should stop
final boolean[] bWinCloseHolder = new boolean[] { false };
// Add close listener to dataviewer to end all scans and exit
final SimulationWindow haveSimulationWindow = getDocumentWindowManager().haveSimulationWindow(simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier());
final Window window = (Window) BeanUtils.findTypeParentOfComponent(haveSimulationWindow.getDataViewer(), Window.class);
window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
super.windowClosing(e);
bWinCloseHolder[0] = true;
}
});
// First sim scan (0) is done already before viewer is shown
((SimResultsViewer) haveSimulationWindow.getDataViewer()).setLocalScanProgress(1);
// Counter of how many simultaneous param scan threads are running (decremented when scan thread finishes)
final int[] currentlyRunningCountHolder = new int[] { 0 };
// Run other scans starting at 1 (scan 0 is already done if we got here)
for (int i = 1; i < simulation.getScanCount(); i++) {
// Check if we can start another new param scan thread
while (currentlyRunningCountHolder[0] >= simultaneousSimsSetting[0]) {
try {
Thread.sleep(50);
// Check if user closed the viewer window, no need to continue
if (bWinCloseHolder[0]) {
return;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
final int scanNum = i;
// increment the concurrent running counter
currentlyRunningCountHolder[0] += 1;
// Start new param scan thread
new Thread(new Runnable() {
@Override
public void run() {
try {
SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, scanNum, null), 0);
Solver solver = createQuickRunSolver(localSimDataDir, simTask);
solver.startSolver();
while (true) {
SolverStatus solverStatus = solver.getSolverStatus();
// System.out.println("ScanNum="+scanNum+" "+solverStatus);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
// Stop if user closed the dataviewer window
if (bWinCloseHolder[0]) {
solver.stopSolver();
break;
}
if (solverStatus != null) {
if (solverStatus.getStatus() == SolverStatus.SOLVER_ABORTED) {
String simulationMessage = solverStatus.getSimulationMessage().getDisplayMessage();
String translatedMessage = solver.translateSimulationMessage(simulationMessage);
if (translatedMessage.startsWith(BeanUtils.FD_EXP_MESSG)) {
throw new RuntimeException("Sims with FieldData can only be run remotely (cannot use QuickRun).\n" + translatedMessage);
} else {
throw new RuntimeException(translatedMessage);
}
}
if (solverStatus.getStatus() != SolverStatus.SOLVER_STARTING && solverStatus.getStatus() != SolverStatus.SOLVER_READY && solverStatus.getStatus() != SolverStatus.SOLVER_RUNNING) {
break;
}
}
}
// SolverStatus solverStatus = solver.getSolverStatus();
// System.out.println("ScanNum="+scanNum+" "+"FinalStatus="+solverStatus);
} catch (Exception e) {
e.printStackTrace();
} finally {
// decrement the concurrent running counter
currentlyRunningCountHolder[0] -= 1;
// Set progress on dataviewer
if (((SimResultsViewer) haveSimulationWindow.getDataViewer()).getLocalScanProgress() < (scanNum + 1)) {
((SimResultsViewer) haveSimulationWindow.getDataViewer()).setLocalScanProgress(scanNum + 1);
}
}
}
}).start();
}
}
}).start();
}
}
};
taskList.add(runOthers);
// ------- dispatch
AsynchClientTask[] taskArray = new AsynchClientTask[taskList.size()];
taskList.toArray(taskArray);
ClientTaskDispatcher.dispatch(documentWindowManager.getComponent(), new Hashtable<String, Object>(), taskArray, true, true, null);
}
use of cbit.vcell.solver.DataProcessingInstructions in project vcell by virtualcell.
the class DataProcessingInstructionPanel method editDataProcessor.
/**
* Method to handle events for the ActionListener interface.
* @param e java.awt.event.ActionEvent
*/
private void editDataProcessor(boolean bEdit) {
DataProcessingInstructions dpi = solverTaskDescription.getSimulation().getDataProcessingInstructions();
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JLabel nameLabel = new JLabel("Name");
panel.add(nameLabel);
JComboBox nameComboBox = new JComboBox();
nameComboBox.addItem(DataProcessingInstructions.ROI_TIME_SERIES);
nameComboBox.addItem(DataProcessingInstructions.VFRAP);
if (dpi != null) {
nameComboBox.setSelectedItem(dpi.getScriptName());
}
panel.add(nameComboBox);
mainPanel.add(panel, BorderLayout.NORTH);
panel = new JPanel(new GridBagLayout());
JLabel label = new JLabel("Text");
GridBagConstraints cbc = new GridBagConstraints();
cbc.gridx = 0;
cbc.gridy = 0;
cbc.insets = new Insets(4, 4, 4, 8);
panel.add(label, cbc);
JScrollPane sp = new JScrollPane();
sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
JTextArea textArea = new JTextArea();
if (dpi != null) {
textArea.setText(dpi.getScriptInput());
}
textArea.setColumns(20);
textArea.setRows(8);
sp.setViewportView(textArea);
cbc = new GridBagConstraints();
cbc.gridx = 1;
cbc.gridy = 0;
cbc.weightx = 1;
cbc.weighty = 1;
cbc.fill = GridBagConstraints.BOTH;
panel.add(sp, cbc);
mainPanel.add(panel, BorderLayout.CENTER);
int ok = DialogUtils.showComponentOKCancelDialog(this.getParent(), mainPanel, "Add Data Processor");
if (ok == JOptionPane.OK_OPTION && textArea.getText().length() > 0) {
String name = (String) nameComboBox.getSelectedItem();
solverTaskDescription.getSimulation().setDataProcessingInstructions(new DataProcessingInstructions(name, textArea.getText()));
} else {
if (!bEdit) {
solverTaskDescription.getSimulation().setDataProcessingInstructions(null);
}
}
}
use of cbit.vcell.solver.DataProcessingInstructions in project vcell by virtualcell.
the class DataProcessingInstructionPanel method refresh.
private void refresh() {
if (solverTaskDescription == null) {
return;
}
SolverDescription solverDesc = solverTaskDescription.getSolverDescription();
if (solverDesc.supports(SolverFeature.Feature_DataProcessingInstructions)) {
setVisible(true);
DataProcessingInstructions dpi = solverTaskDescription.getSimulation().getDataProcessingInstructions();
if (dpi != null) {
dataProcessorCheckBox.setSelected(true);
editDataProcessorButton.setEnabled(true);
} else {
editDataProcessorButton.setEnabled(false);
}
} else {
setVisible(false);
}
}
Aggregations