use of cbit.vcell.math.ParticleVariable in project vcell by virtualcell.
the class SmoldynFileWriter method writeRuntimeCommands.
// uncomment for debug
/*private void writeGraphicsLegend() throws MathException{
try {
java.awt.image.BufferedImage cmapImage = new java.awt.image.BufferedImage(200, particleVariableList.size()*30,java.awt.image.BufferedImage.TYPE_INT_RGB);
Graphics g = cmapImage.getGraphics();
for (int i = 0; i < particleVariableList.size(); i ++) {
Color c = colors[i];
System.out.println("color for legend: " + "red--"+ c.getRed() + " green--" + c.getGreen() + " blue--" + c.getBlue());
String variableName = getVariableName(particleVariableList.get(i),null);
g.setColor(c);
g.drawString(variableName, 5, 30*i + 20);
g.fillRect(105, 30*i + 10, 20, 10);
}
g.dispose();
File tmpFile = File.createTempFile("legend", ".jpg");
FileOutputStream fios = null;
try {
printWriter.println("# legend file: " + tmpFile.getAbsolutePath());
fios = new FileOutputStream(tmpFile);
ImageIO.write(cmapImage,"jpg",fios);
} finally {
if(fios != null) {fios.close();}
}
} catch (Exception e) {
e.printStackTrace();
throw new MathException(e.getMessage());
}
}*/
private void writeRuntimeCommands() throws SolverException, DivideByZeroException, DataAccessException, IOException, MathException, ExpressionException {
printWriter.println("# " + SmoldynVCellMapper.SmoldynKeyword.killmolincmpt + " runtime command to kill molecules misplaced during initial condtions");
for (ParticleVariable pv : particleVariableList) {
CompartmentSubDomain varDomain = mathDesc.getCompartmentSubDomain(pv.getDomain().getName());
if (varDomain == null) {
continue;
}
boolean bkillMol = false;
ArrayList<ParticleInitialCondition> iniConditionList = varDomain.getParticleProperties(pv).getParticleInitialConditions();
for (ParticleInitialCondition iniCon : iniConditionList) {
if (iniCon instanceof ParticleInitialConditionConcentration) {
try {
subsituteFlattenToConstant(((ParticleInitialConditionConcentration) iniCon).getDistribution());
} catch (// can not be evaluated to a constant
Exception e) {
bkillMol = true;
break;
}
}
}
if (bkillMol) {
Enumeration<SubDomain> subDomainEnumeration = mathDesc.getSubDomains();
while (subDomainEnumeration.hasMoreElements()) {
SubDomain subDomain = subDomainEnumeration.nextElement();
if (subDomain instanceof CompartmentSubDomain && varDomain != subDomain) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + SmoldynVCellMapper.SmoldynKeyword.killmolincmpt + " " + pv.getName() + "(" + SmoldynVCellMapper.SmoldynKeyword.all + ") " + subDomain.getName());
}
}
}
}
printWriter.println();
// write command to kill molecules on membrane for adsortption to nothing
printWriter.println("# kill membrane molecues that are absorbed (to nothing)");
for (String killMolCmd : killMolCommands) {
printWriter.println(killMolCmd);
}
printWriter.println();
printWriter.println("# runtime command");
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.E + " " + VCellSmoldynKeyword.vcellPrintProgress);
if (outputFile != null && cartesianMesh != null) {
OutputTimeSpec ots = simulation.getSolverTaskDescription().getOutputTimeSpec();
if (ots.isUniform()) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.output_files + " " + outputFile.getName());
ISize sampleSize = simulation.getMeshSpecification().getSamplingSize();
TimeStep timeStep = simulation.getSolverTaskDescription().getTimeStep();
int n = (int) Math.round(((UniformOutputTimeSpec) ots).getOutputTimeStep() / timeStep.getDefaultTimeStep());
if (simulation.getSolverTaskDescription().getSmoldynSimulationOptions().isSaveParticleLocations()) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + SmoldynVCellMapper.SmoldynKeyword.incrementfile + " " + outputFile.getName());
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + SmoldynVCellMapper.SmoldynKeyword.listmols + " " + outputFile.getName());
}
// DON'T CHANGE THE ORDER HERE.
// DataProcess must be before vcellWriteOutput
writeDataProcessor();
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + VCellSmoldynKeyword.vcellWriteOutput + " begin");
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + VCellSmoldynKeyword.vcellWriteOutput + " " + VCellSmoldynKeyword.dimension + " " + dimension);
printWriter.print(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + VCellSmoldynKeyword.vcellWriteOutput + " " + VCellSmoldynKeyword.sampleSize + " " + sampleSize.getX());
if (dimension > 1) {
printWriter.print(" " + sampleSize.getY());
if (dimension > 2) {
printWriter.print(" " + sampleSize.getZ());
}
}
printWriter.println();
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + VCellSmoldynKeyword.vcellWriteOutput + " " + VCellSmoldynKeyword.numMembraneElements + " " + cartesianMesh.getNumMembraneElements());
for (ParticleVariable pv : particleVariableList) {
String type = pv instanceof MembraneParticleVariable ? VCellSmoldynKeyword.membrane.name() : VCellSmoldynKeyword.volume.name();
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + VCellSmoldynKeyword.vcellWriteOutput + " " + VCellSmoldynKeyword.variable + " " + pv.getName() + " " + type + " " + pv.getDomain().getName());
}
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + VCellSmoldynKeyword.vcellWriteOutput + " end");
} else {
throw new SolverException(SolverDescription.Smoldyn.getDisplayLabel() + " only supports uniform output.");
}
}
printWriter.println();
}
Aggregations