Search in sources :

Example 6 with ParticleInitialCondition

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;
}
Also used : ParticleInitialConditionConcentration(cbit.vcell.math.ParticleProperties.ParticleInitialConditionConcentration) ParticleInitialCondition(cbit.vcell.math.ParticleProperties.ParticleInitialCondition) Element(org.jdom.Element) ParticleInitialConditionCount(cbit.vcell.math.ParticleProperties.ParticleInitialConditionCount) Element(org.jdom.Element)

Example 7 with ParticleInitialCondition

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();
}
Also used : ParticleInitialConditionConcentration(cbit.vcell.math.ParticleProperties.ParticleInitialConditionConcentration) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) ISize(org.vcell.util.ISize) ProgrammingException(org.vcell.util.ProgrammingException) GeometryException(cbit.vcell.geometry.GeometryException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) ImageException(cbit.image.ImageException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) SolverException(cbit.vcell.solver.SolverException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) TimeStep(cbit.vcell.solver.TimeStep) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) ParticleInitialCondition(cbit.vcell.math.ParticleProperties.ParticleInitialCondition) SolverException(cbit.vcell.solver.SolverException)

Aggregations

ParticleInitialCondition (cbit.vcell.math.ParticleProperties.ParticleInitialCondition)7 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)5 ParticleProperties (cbit.vcell.math.ParticleProperties)5 ParticleInitialConditionConcentration (cbit.vcell.math.ParticleProperties.ParticleInitialConditionConcentration)5 ParticleInitialConditionCount (cbit.vcell.math.ParticleProperties.ParticleInitialConditionCount)5 MathException (cbit.vcell.math.MathException)4 ParticleVariable (cbit.vcell.math.ParticleVariable)4 SubDomain (cbit.vcell.math.SubDomain)4 VolumeParticleVariable (cbit.vcell.math.VolumeParticleVariable)4 ExpressionException (cbit.vcell.parser.ExpressionException)4 MembraneParticleVariable (cbit.vcell.math.MembraneParticleVariable)3 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)3 Variable (cbit.vcell.math.Variable)3 Expression (cbit.vcell.parser.Expression)3 ArrayList (java.util.ArrayList)3 Element (org.jdom.Element)3 GeometryClass (cbit.vcell.geometry.GeometryClass)2 SubVolume (cbit.vcell.geometry.SubVolume)2 Constant (cbit.vcell.math.Constant)2 MacroscopicRateConstant (cbit.vcell.math.MacroscopicRateConstant)2