use of cbit.vcell.math.MembraneParticleVariable in project vcell by virtualcell.
the class Xmlproducer method getXML.
private Element getXML(ParticleVariable param) {
org.jdom.Element e = null;
if (param instanceof VolumeParticleVariable) {
e = new org.jdom.Element(XMLTags.VolumeParticleVariableTag);
} else if (param instanceof VolumeParticleSpeciesPattern) {
e = new org.jdom.Element(XMLTags.VolumeParticleSpeciesPatternTag);
String locationName = ((VolumeParticleSpeciesPattern) param).getLocationName();
if (locationName != null) {
e.setAttribute(XMLTags.LocationAttrTag, mangle(locationName));
}
for (ParticleMolecularTypePattern pp : ((VolumeParticleSpeciesPattern) param).getParticleMolecularTypePatterns()) {
e.addContent(getXML(pp));
}
} else if (param instanceof MembraneParticleVariable) {
e = new org.jdom.Element(XMLTags.MembraneParticleVariableTag);
} else {
System.out.println("Unexpected element" + param);
}
// Add atribute
e.setAttribute(XMLTags.NameAttrTag, mangle(param.getName()));
if (param.getDomain() != null) {
e.setAttribute(XMLTags.DomainAttrTag, mangle(param.getDomain().getName()));
}
return e;
}
use of cbit.vcell.math.MembraneParticleVariable in project vcell by virtualcell.
the class ParticleMathMapping method refreshVariables.
/**
* This method was created in VisualAge.
* @Override
*/
private void refreshVariables() throws MappingException {
Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
//
// non-constant independent variables require either a membrane or volume variable
//
enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
SpeciesContextSpec scs = getSimulationContext().getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
// if (scm.getDependencyExpression() == null && (!scs.isConstant() || getSimulationContext().hasEventAssignment(scs.getSpeciesContext()))){
StructureMapping sm = getSimulationContext().getGeometryContext().getStructureMapping(scm.getSpeciesContext().getStructure());
Structure struct = scm.getSpeciesContext().getStructure();
Domain domain = null;
if (sm.getGeometryClass() != null) {
domain = new Domain(sm.getGeometryClass());
}
if (struct instanceof Feature || struct instanceof Membrane) {
if (sm.getGeometryClass() instanceof SurfaceClass) {
if (scs.isWellMixed()) {
// scm.setVariable(new StochMembraneRegionVariable(scm.getSpeciesContext().getName(),domain));
throw new MappingException("stochastic membrane region variables not yet supported");
} else {
scm.setVariable(new MembraneParticleVariable(scm.getSpeciesContext().getName(), domain));
}
} else {
if (scs.isWellMixed()) {
throw new MappingException("stochastic volume region variables not yet supported");
// scm.setVariable(new StochVolumeRegionVariable(scm.getSpeciesContext().getName(),domain));
} else {
scm.setVariable(new VolumeParticleVariable(scm.getSpeciesContext().getName(), domain));
}
}
} else {
throw new MappingException("class " + scm.getSpeciesContext().getStructure().getClass() + " not supported");
}
mathSymbolMapping.put(scm.getSpeciesContext(), scm.getVariable().getName());
// }
}
}
use of cbit.vcell.math.MembraneParticleVariable in project vcell by virtualcell.
the class XmlReader method getMembraneParticalVariable.
private MembraneParticleVariable getMembraneParticalVariable(Element param) {
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
Domain domain = null;
if (domainStr != null) {
domain = new Domain(domainStr);
}
// -- create new VolVariable object
MembraneParticleVariable var = new MembraneParticleVariable(name, domain);
transcribeComments(param, var);
return var;
}
use of cbit.vcell.math.MembraneParticleVariable in project vcell by virtualcell.
the class FiniteVolumeFileWriter method writeVariables.
/**
*# Variables : type name unit time_dependent_flag advection_flag solve_whole_mesh_flag solve_regions
*VARIABLE_BEGIN
*VOLUME_ODE rB uM
*VOLUME_PDE rf uM false false
*VOLUME_PDE r uM false false
*VOLUME_ODE rfB uM
*VARIABLE_END
* @throws MathException
* @throws ExpressionException
* @throws IOException
*/
private void writeVariables() throws MathException, ExpressionException, IOException {
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
printWriter.println("# Variables : type name domain time_dependent_flag advection_flag grad_flag solve_whole_mesh_flag solve_regions");
printWriter.println(FVInputFileKeyword.VARIABLE_BEGIN);
MathDescription mathDesc = simSymbolTable.getSimulation().getMathDescription();
Variable[] vars = simSymbolTable.getVariables();
ArrayList<RandomVariable> rvList = new ArrayList<RandomVariable>();
for (int i = 0; i < vars.length; i++) {
String varName = vars[i].getName();
String domainName = vars[i].getDomain() == null ? null : vars[i].getDomain().getName();
if (vars[i] instanceof VolumeRandomVariable || vars[i] instanceof MembraneRandomVariable) {
rvList.add((RandomVariable) vars[i]);
} else if (vars[i] instanceof VolVariable) {
if (bChomboSolver && domainName == null) {
throw new MathException(simTask.getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel() + " requires that every variable is defined in a single domain");
}
VolVariable volVar = (VolVariable) vars[i];
if (mathDesc.isPDE(volVar)) {
boolean hasTimeVaryingDiffusionOrAdvection = simSymbolTable.hasTimeVaryingDiffusionOrAdvection(volVar);
final boolean hasVelocity = mathDesc.hasVelocity(volVar);
final boolean hasGradient = mathDesc.hasGradient(volVar);
if (mathDesc.isPdeSteady(volVar)) {
printWriter.print("VOLUME_PDE_STEADY ");
} else {
printWriter.print("VOLUME_PDE ");
}
printWriter.print(varName + " " + domainName + " " + hasTimeVaryingDiffusionOrAdvection + " " + hasVelocity + " " + hasGradient);
} else {
printWriter.print("VOLUME_ODE " + varName + " " + domainName);
}
if (domainName == null) {
Vector<SubDomain> listOfSubDomains = new Vector<SubDomain>();
int totalNumCompartments = 0;
Enumeration<SubDomain> subDomainEnum = mathDesc.getSubDomains();
while (subDomainEnum.hasMoreElements()) {
SubDomain subDomain = subDomainEnum.nextElement();
if (subDomain instanceof CompartmentSubDomain) {
CompartmentSubDomain compartmentSubDomain = (CompartmentSubDomain) subDomain;
totalNumCompartments++;
Equation varEquation = subDomain.getEquation(vars[i]);
if (varEquation != null) {
if (!(varEquation instanceof PdeEquation) || !((PdeEquation) varEquation).isDummy(simSymbolTable, compartmentSubDomain)) {
listOfSubDomains.add(compartmentSubDomain);
}
}
}
}
if ((totalNumCompartments == listOfSubDomains.size()) || (listOfSubDomains.size() == 0 && simTask.getSimulation().getSolverTaskDescription().getSolverDescription().equals(SolverDescription.SundialsPDE))) {
printWriter.print(" true");
} else {
printWriter.print(" false");
for (int j = 0; j < listOfSubDomains.size(); j++) {
CompartmentSubDomain compartmentSubDomain = (CompartmentSubDomain) listOfSubDomains.elementAt(j);
printWriter.print(" " + compartmentSubDomain.getName());
}
}
printWriter.println();
} else {
printWriter.println(" false " + domainName);
}
} else if (vars[i] instanceof VolumeParticleVariable) {
printWriter.println(FVInputFileKeyword.VOLUME_PARTICLE + " " + varName + " " + domainName);
} else if (vars[i] instanceof MembraneParticleVariable) {
printWriter.println(FVInputFileKeyword.MEMBRANE_PARTICLE + " " + varName + " " + domainName);
} else if (vars[i] instanceof VolumeRegionVariable) {
printWriter.println("VOLUME_REGION " + varName + " " + domainName);
} else if (vars[i] instanceof MemVariable) {
if (bChomboSolver && domainName == null) {
throw new MathException(simTask.getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel() + " requires that every variable is defined in a single domain");
}
MemVariable memVar = (MemVariable) vars[i];
if (mathDesc.isPDE(memVar)) {
printWriter.println("MEMBRANE_PDE " + varName + " " + domainName + " " + simSymbolTable.hasTimeVaryingDiffusionOrAdvection(memVar));
} else {
printWriter.println("MEMBRANE_ODE " + varName + " " + domainName);
}
} else if (vars[i] instanceof MembraneRegionVariable) {
printWriter.println("MEMBRANE_REGION " + varName + " " + domainName);
} else if (vars[i] instanceof FilamentVariable) {
throw new RuntimeException("Filament application not supported yet");
}
}
int numRandomVariables = rvList.size();
if (numRandomVariables > 0) {
ISize samplingSize = simTask.getSimulation().getMeshSpecification().getSamplingSize();
String[] varNameArr = new String[numRandomVariables];
VariableType[] varTypeArr = new VariableType[numRandomVariables];
double[][] dataArr = new double[numRandomVariables][];
for (int i = 0; i < numRandomVariables; i++) {
RandomVariable rv = rvList.get(i);
varNameArr[i] = rv.getName();
int numRandomNumbers = 0;
if (rv instanceof VolumeRandomVariable) {
printWriter.print("VOLUME_RANDOM");
varTypeArr[i] = VariableType.VOLUME;
numRandomNumbers = samplingSize.getXYZ();
} else if (rv instanceof MembraneRandomVariable) {
printWriter.print("MEMBRANE_RANDOM");
varTypeArr[i] = VariableType.MEMBRANE;
numRandomNumbers = resampledGeometry.getGeometrySurfaceDescription().getSurfaceCollection().getTotalPolygonCount();
} else {
throw new RuntimeException("Unknown RandomVariable type");
}
printWriter.println(" " + varNameArr[i]);
dataArr[i] = generateRandomNumbers(rv, numRandomNumbers);
}
File rvFile = new File(workingDirectory, simTask.getSimulationJobID() + RANDOM_VARIABLE_FILE_EXTENSION);
DataSet.writeNew(rvFile, varNameArr, varTypeArr, samplingSize, dataArr);
}
printWriter.println(FVInputFileKeyword.VARIABLE_END);
printWriter.println();
}
use of cbit.vcell.math.MembraneParticleVariable 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