use of cbit.vcell.math.ParticleProperties.ParticleInitialCondition in project vcell by virtualcell.
the class Xmlproducer method getXML.
private org.jdom.Element getXML(ParticleProperties param) throws XmlParseException {
org.jdom.Element particleProperties = new org.jdom.Element(XMLTags.ParticlePropertiesTag);
particleProperties.setAttribute(XMLTags.NameAttrTag, mangle(param.getVariable().getName()));
for (ParticleInitialCondition pic : param.getParticleInitialConditions()) {
org.jdom.Element particleInitial = null;
if (pic instanceof ParticleInitialConditionCount) {
particleInitial = new org.jdom.Element(XMLTags.ParticleInitialCountTag);
ParticleInitialConditionCount ppic = (ParticleInitialConditionCount) pic;
Element e = new Element(XMLTags.ParticleCountTag);
e.setText(mangleExpression(ppic.getCount()));
particleInitial.addContent(e);
if (ppic.getLocationX() != null) {
e = new Element(XMLTags.ParticleLocationXTag);
e.setText(mangleExpression(ppic.getLocationX()));
particleInitial.addContent(e);
}
if (ppic.getLocationY() != null) {
e = new Element(XMLTags.ParticleLocationYTag);
e.setText(mangleExpression(ppic.getLocationY()));
particleInitial.addContent(e);
}
if (ppic.getLocationZ() != null) {
e = new Element(XMLTags.ParticleLocationZTag);
e.setText(mangleExpression(ppic.getLocationZ()));
particleInitial.addContent(e);
}
} else if (pic instanceof ParticleInitialConditionConcentration) {
particleInitial = new org.jdom.Element(XMLTags.ParticleInitialConcentrationTag);
ParticleInitialConditionConcentration ppic = (ParticleInitialConditionConcentration) pic;
Element e = new Element(XMLTags.ParticleDistributionTag);
e.setText(mangleExpression(ppic.getDistribution()));
particleInitial.addContent(e);
}
particleProperties.addContent(particleInitial);
}
Element diff = new Element(XMLTags.ParticleDiffusionTag);
diff.setText(mangleExpression(param.getDiffusion()));
particleProperties.addContent(diff);
if (param.getDriftX() != null) {
Element driftX = new Element(XMLTags.ParticleDriftXTag);
driftX.setText(mangleExpression(param.getDriftX()));
particleProperties.addContent(driftX);
}
if (param.getDriftY() != null) {
Element driftY = new Element(XMLTags.ParticleDriftYTag);
driftY.setText(mangleExpression(param.getDriftY()));
particleProperties.addContent(driftY);
}
if (param.getDriftZ() != null) {
Element driftZ = new Element(XMLTags.ParticleDriftZTag);
driftZ.setText(mangleExpression(param.getDriftZ()));
particleProperties.addContent(driftZ);
}
return particleProperties;
}
use of cbit.vcell.math.ParticleProperties.ParticleInitialCondition 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