use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class ClientSimManager method runSmoldynParticleView.
public void runSmoldynParticleView(final Simulation originalSimulation) {
SimulationOwner simulationOwner = simWorkspace.getSimulationOwner();
Collection<AsynchClientTask> tasks;
if (simulationOwner instanceof SimulationContext) {
tasks = ClientRequestManager.updateMath(documentWindowManager.getComponent(), (SimulationContext) simulationOwner, false, NetworkGenerationRequirements.ComputeFullStandardTimeout);
} else {
tasks = new ArrayList<>();
}
AsynchClientTask pv = new AsynchClientTask("starting particle view", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
File[] exes = SolverUtilities.getExes(SolverDescription.Smoldyn);
assert exes.length == 1 : "one and only one smoldyn solver expected";
File smoldynExe = exes[0];
Simulation simulation = new TempSimulation(originalSimulation, false);
SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, null), 0);
File inputFile = new File(ResourceUtil.getLocalSimDir(User.tempUser.getName()), simTask.getSimulationJobID() + SimDataConstants.SMOLDYN_INPUT_FILE_EXTENSION);
inputFile.deleteOnExit();
PrintWriter pw = new PrintWriter(inputFile);
SmoldynFileWriter smf = new SmoldynFileWriter(pw, true, null, simTask, false);
smf.write();
pw.close();
String[] cmd = new String[] { smoldynExe.getAbsolutePath(), inputFile.getAbsolutePath() };
StringBuilder commandLine = new StringBuilder();
for (int i = 0; i < cmd.length; i++) {
if (i > 0) {
commandLine.append(" ");
}
commandLine.append(TokenMangler.getEscapedPathName(cmd[i]));
}
System.out.println(commandLine);
char[] charArrayOut = new char[10000];
char[] charArrayErr = new char[10000];
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
final Process process = processBuilder.start();
getClientTaskStatusSupport().addProgressDialogListener(new ProgressDialogListener() {
public void cancelButton_actionPerformed(EventObject newEvent) {
process.destroy();
}
});
InputStream errorStream = process.getErrorStream();
InputStreamReader errisr = new InputStreamReader(errorStream);
InputStream outputStream = process.getInputStream();
InputStreamReader outisr = new InputStreamReader(outputStream);
StringBuilder sb = new StringBuilder();
boolean running = true;
while (running) {
try {
process.exitValue();
running = false;
} catch (IllegalThreadStateException e) {
// process didn't exit yet, do nothing
}
if (outputStream.available() > 0) {
outisr.read(charArrayOut, 0, charArrayOut.length);
}
if (errorStream.available() > 0) {
errisr.read(charArrayErr, 0, charArrayErr.length);
sb.append(new String(charArrayErr));
}
}
if (sb.length() > 0) {
throw new RuntimeException(sb.toString());
}
}
};
tasks.add(pv);
ClientTaskDispatcher.dispatchColl(documentWindowManager.getComponent(), new Hashtable<String, Object>(), tasks, false, true, null);
}
use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class VFrapXmlHelper method ReplaceVFrapNamesWithSymbolNames.
//
// replace vFrap default names in field function arguments with data symbol names -----
//
public static void ReplaceVFrapNamesWithSymbolNames(BioModel bioModel) throws ExpressionException {
SimulationContext simContext = bioModel.getSimulationContexts()[0];
SpeciesContextSpec[] scsArray = simContext.getReactionContext().getSpeciesContextSpecs();
for (SpeciesContextSpec scs : scsArray) {
// vFrap('a','c',0.0,'volume')
Expression exp = scs.getInitialConditionParameter().getExpression();
FieldFunctionArguments[] fieldFunctionArgs = FieldUtilities.getFieldFunctionArguments(exp);
if (fieldFunctionArgs != null && fieldFunctionArgs.length > 0) {
for (FieldFunctionArguments args : fieldFunctionArgs) {
for (DataSymbol ds : simContext.getDataContext().getDataSymbols()) {
if (ds instanceof FieldDataSymbol) {
FieldDataSymbol fieldDataSymbol = (FieldDataSymbol) ds;
// String extDataIdentName = fieldDataSymbol.getExternalDataIdentifier().getName(); // name of field data
// String argsFieldName = args.getFieldName(); // roiData
// fieldDataSymbol.getFieldDataVarTime() == args.getTime().evaluateConstant()
// name of data symbol ex: postbleach_first_ccccF
String dataSymbolName = fieldDataSymbol.getName();
// name in expression as it comes from vFrap ex: postbleach_first
String argsVariableName = args.getVariableName();
if (dataSymbolName.startsWith(argsVariableName)) {
// vcField('roiData','postbleach_first',0.0,'Volume')
String oldExpression = args.infix();
exp.substituteInPlace(new Expression(oldExpression), new Expression(dataSymbolName));
exp.bindExpression(simContext);
}
}
}
}
}
}
}
use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class BioModelWindowManager method updateApplicationHash.
/**
* Insert the method's description here.
* Creation date: (6/1/2004 2:33:41 AM)
*/
private void updateApplicationHash(boolean reset) {
SimulationContext[] scs = getBioModel().getSimulationContexts();
Enumeration<SimulationContext> en = getApplicationsHash().keys();
while (en.hasMoreElements()) {
SimulationContext sc = (SimulationContext) en.nextElement();
ApplicationComponents appComponents = getApplicationsHash().get(sc);
if (!getBioModel().contains(sc)) {
if (reset) {
// find one with the same name, if available
SimulationContext found = null;
if (scs != null) {
for (int i = 0; i < scs.length; i++) {
if (scs[i].getName().equals(sc.getName())) {
found = scs[i];
break;
}
}
}
if (found != null) {
// update hash
getApplicationsHash().remove(sc);
getApplicationsHash().put(found, appComponents);
appComponents.resetSimulationContext(found);
// check simulation data windows
updateSimulationDataViewers(appComponents, found);
// rewire listener
sc.removePropertyChangeListener(this);
found.removePropertyChangeListener(this);
found.addPropertyChangeListener(this);
} else {
// we didn't find one, so remove from hash and close all of its windows
remove(appComponents, sc);
}
} else {
// shouldn't have it
remove(appComponents, sc);
}
}
}
}
use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class ClientRequestManager method createRuleBasedBioModelFromApplication.
public void createRuleBasedBioModelFromApplication(final BioModelWindowManager requester, final String name, final SimulationContext simContext) {
if (simContext == null) {
PopupGenerator.showErrorDialog(requester, "Selected Application is null, cannot generate corresponding bio model");
return;
}
AsynchClientTask task1 = new AsynchClientTask("Creating BioModel from BioModel Application", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
MathMappingCallback dummyCallback = new MathMappingCallback() {
public void setProgressFraction(float percentDone) {
}
public void setMessage(String message) {
}
public boolean isInterrupted() {
return false;
}
};
MathMapping transformedMathMapping = simContext.createNewMathMapping(dummyCallback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
// simContext.setMathDescription(transformedMathMapping.getMathDescription());
BioModel newBioModel = new BioModel(null);
SimulationContext transformedSimContext = transformedMathMapping.getTransformation().transformedSimContext;
Model model = transformedSimContext.getModel();
// for(ReactionStep rs : model.getReactionSteps()) {
// model.removeReactionStep(rs);
// }
newBioModel.setModel(model);
hashTable.put("newBioModel", newBioModel);
}
};
AsynchClientTask task2 = new AsynchClientTask("Creating BioModel from BioModel Application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
BioModel newBioModel = (BioModel) hashTable.get("newBioModel");
DocumentWindowManager windowManager = createDocumentWindowManager(newBioModel);
getMdiManager().createNewDocumentWindow(windowManager);
}
};
ClientTaskDispatcher.dispatch(requester.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, false);
}
use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class OutputFunctionsListTableModel method propertyChange.
/**
* This method gets called when a bound property is changed.
* @param evt A PropertyChangeEvent object describing the event source
* and the property that has changed.
*/
public void propertyChange(java.beans.PropertyChangeEvent evt) {
OutputFunctionContext fc = getOutputFunctionContext();
SimulationOwner so = null;
if (fc != null) {
so = fc.getSimulationOwner();
}
if (evt.getSource() == fc && evt.getPropertyName().equals(OutputFunctionContext.PROPERTY_OUTPUT_FUNCTIONS)) {
setData(outputFunctionContext.getOutputFunctionsList());
}
if (evt.getSource() instanceof SimulationContext && evt.getSource() == so && evt.getPropertyName().equals(Model.PROPERTY_NAME_MODEL_ENTITY_NAME)) {
SimulationContext simulationContext = (SimulationContext) so;
if (fc.getOutputFunctionsList() == null || fc.getOutputFunctionsList().isEmpty()) {
return;
}
Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
//
// WARNING: this should NOT be used under any circumstance for batch renaming
// MathDescription, MathMapping, expressions are NOT thread safe
//
AsynchClientTask task0 = new AsynchClientTask("Renaming Functions", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING, false, false) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
MathMappingCallback callback = new MathMappingCallback() {
@Override
public void setProgressFraction(float fractionDone) {
}
@Override
public void setMessage(String message) {
}
@Override
public boolean isInterrupted() {
return false;
}
};
MathMapping mathMapping = simulationContext.createNewMathMapping(callback, NetworkGenerationRequirements.ComputeFullNoTimeout);
MathDescription mathDesc = null;
try {
mathDesc = mathMapping.getMathDescription(callback);
} catch (MappingException | MathException | MatrixException | ExpressionException | ModelException e1) {
e1.printStackTrace();
}
String oldName = (String) evt.getOldValue();
String newName = (String) evt.getNewValue();
ArrayList<AnnotatedFunction> afList = fc.getOutputFunctionsList();
List<Expression> changedExpressions = new ArrayList<>();
for (AnnotatedFunction af : afList) {
if (af == null) {
continue;
}
Expression exp = af.getExpression();
if (exp == null || exp.getSymbols() == null || exp.getSymbols().length == 0) {
continue;
}
String errMsg = "Failed to rename symbol '" + oldName + "' with '" + newName + "' in the Expression of Function '" + af.getName() + "'.";
for (String symbol : exp.getSymbols()) {
if (symbol.contentEquals(oldName)) {
try {
exp.substituteInPlace(new Expression(oldName), new Expression(newName));
changedExpressions.add(exp);
} catch (ExpressionException e) {
e.printStackTrace();
throw new RuntimeException(errMsg);
}
}
}
}
if (changedExpressions.size() > 0) {
try {
simulationContext.setMathDescription(mathDesc);
for (Expression exp : changedExpressions) {
exp.bindExpression(outputFunctionContext);
}
} catch (ExpressionException | PropertyVetoException e) {
e.printStackTrace();
}
}
}
};
ClientTaskDispatcher.dispatch(ownerTable, hashTable, new AsynchClientTask[] { task0 }, false);
}
if (evt.getPropertyName().equals(GeometryOwner.PROPERTY_NAME_GEOMETRY)) {
Geometry oldGeometry = (Geometry) evt.getOldValue();
Geometry newGeometry = (Geometry) evt.getNewValue();
// changing from ode to pde
if (oldGeometry.getDimension() == 0 && newGeometry.getDimension() > 0) {
fireTableStructureChanged();
setData(getOutputFunctionContext().getOutputFunctionsList());
}
}
}
Aggregations