use of com.lowagie.text.Section in project vcell by virtualcell.
the class ITextWriter method writeSubDomainsEquationsAsText.
protected void writeSubDomainsEquationsAsText(Section mathDescSection, MathDescription mathDesc) throws DocumentException {
Enumeration<SubDomain> subDomains = mathDesc.getSubDomains();
Section volDomains = mathDescSection.addSection("Volume Domains", mathDescSection.depth() + 1);
Section memDomains = mathDescSection.addSection("Membrane Domains", mathDescSection.depth() + 1);
Section filDomains = mathDescSection.addSection("Filament Domains", mathDescSection.depth() + 1);
while (subDomains.hasMoreElements()) {
Section tempSection = null;
SubDomain subDomain = subDomains.nextElement();
if (subDomain instanceof CompartmentSubDomain) {
tempSection = volDomains.addSection(subDomain.getName(), volDomains.depth() + 1);
} else if (subDomain instanceof MembraneSubDomain) {
tempSection = memDomains.addSection(subDomain.getName(), memDomains.depth() + 1);
} else if (subDomain instanceof FilamentSubDomain) {
tempSection = filDomains.addSection(subDomain.getName(), filDomains.depth() + 1);
}
Enumeration<Equation> equationsList = subDomain.getEquations();
while (equationsList.hasMoreElements()) {
Equation equ = equationsList.nextElement();
writeEquation(tempSection, equ);
}
if (subDomain.getFastSystem() != null) {
writeFastSystem(tempSection, subDomain.getFastSystem());
}
if (subDomain instanceof MembraneSubDomain) {
Enumeration<JumpCondition> jcList = ((MembraneSubDomain) subDomain).getJumpConditions();
while (jcList.hasMoreElements()) {
JumpCondition jc = jcList.nextElement();
writeJumpCondition(tempSection, jc);
}
}
}
if (volDomains.isEmpty()) {
mathDescSection.remove(volDomains);
}
if (memDomains.isEmpty()) {
mathDescSection.remove(memDomains);
}
if (filDomains.isEmpty()) {
mathDescSection.remove(filDomains);
}
}
use of com.lowagie.text.Section in project vcell by virtualcell.
the class ITextWriter method writeSimulation.
// container can be a chapter or a section of a chapter.
protected void writeSimulation(Section container, Simulation sim) throws DocumentException {
if (sim == null) {
return;
}
Section simSection = container.addSection(sim.getName(), container.numberDepth() + 1);
writeMetadata(simSection, sim.getName(), sim.getDescription(), null, "Simulation ");
// add overriden params
Table overParamTable = null;
MathOverrides mo = sim.getMathOverrides();
if (mo != null) {
String[] constants = mo.getOverridenConstantNames();
for (int i = 0; i < constants.length; i++) {
String actualStr = "", defStr = "";
Expression tempExp = mo.getDefaultExpression(constants[i]);
if (tempExp != null) {
defStr = tempExp.infix();
}
if (mo.isScan(constants[i])) {
actualStr = mo.getConstantArraySpec(constants[i]).toString();
} else {
tempExp = mo.getActualExpression(constants[i], 0);
if (tempExp != null) {
actualStr = tempExp.infix();
}
}
if (overParamTable == null) {
overParamTable = getTable(3, 75, 1, 3, 3);
overParamTable.setAlignment(Table.ALIGN_LEFT);
overParamTable.addCell(createCell("Overriden Parameters", getBold(DEF_HEADER_FONT_SIZE), 3, 1, Element.ALIGN_CENTER, true));
overParamTable.addCell(createHeaderCell("Name", getBold(), 1));
overParamTable.addCell(createHeaderCell("Actual Value", getBold(), 1));
overParamTable.addCell(createHeaderCell("Default Value", getBold(), 1));
}
overParamTable.addCell(createCell(constants[i], getFont()));
overParamTable.addCell(createCell(actualStr, getFont()));
overParamTable.addCell(createCell(defStr, getFont()));
}
}
if (overParamTable != null) {
simSection.add(overParamTable);
}
// add spatial details
// sim.isSpatial();
Table meshTable = null;
MeshSpecification mesh = sim.getMeshSpecification();
if (mesh != null) {
Geometry geom = mesh.getGeometry();
Extent extent = geom.getExtent();
String extentStr = "(" + extent.getX() + ", " + extent.getY() + ", " + extent.getZ() + ")";
ISize meshSize = mesh.getSamplingSize();
String meshSizeStr = "(" + meshSize.getX() + ", " + meshSize.getY() + ", " + meshSize.getZ() + ")";
meshTable = getTable(2, 75, 1, 3, 3);
meshTable.setAlignment(Table.ALIGN_LEFT);
meshTable.addCell(createCell("Geometry Setting", getBold(DEF_HEADER_FONT_SIZE), 2, 1, Element.ALIGN_CENTER, true));
meshTable.addCell(createCell("Geometry Size (um)", getFont()));
meshTable.addCell(createCell(extentStr, getFont()));
meshTable.addCell(createCell("Mesh Size (elements)", getFont()));
meshTable.addCell(createCell(meshSizeStr, getFont()));
}
if (meshTable != null) {
simSection.add(meshTable);
}
// write advanced sim settings
Table simAdvTable = null;
SolverTaskDescription solverDesc = sim.getSolverTaskDescription();
if (solverDesc != null) {
String solverName = solverDesc.getSolverDescription().getDisplayLabel();
simAdvTable = getTable(2, 75, 1, 3, 3);
simAdvTable.setAlignment(Table.ALIGN_LEFT);
simAdvTable.addCell(createCell("Advanced Settings", getBold(DEF_HEADER_FONT_SIZE), 2, 1, Element.ALIGN_CENTER, true));
simAdvTable.addCell(createCell("Solver Name", getFont()));
simAdvTable.addCell(createCell(solverName, getFont()));
simAdvTable.addCell(createCell("Time Bounds - Starting", getFont()));
simAdvTable.addCell(createCell("" + solverDesc.getTimeBounds().getStartingTime(), getFont()));
simAdvTable.addCell(createCell("Time Bounds - Ending", getFont()));
simAdvTable.addCell(createCell("" + solverDesc.getTimeBounds().getEndingTime(), getFont()));
simAdvTable.addCell(createCell("Time Step - Min", getFont()));
simAdvTable.addCell(createCell("" + solverDesc.getTimeStep().getMinimumTimeStep(), getFont()));
simAdvTable.addCell(createCell("Time Step - Default", getFont()));
simAdvTable.addCell(createCell("" + solverDesc.getTimeStep().getDefaultTimeStep(), getFont()));
simAdvTable.addCell(createCell("Time Step - Max", getFont()));
simAdvTable.addCell(createCell("" + solverDesc.getTimeStep().getMaximumTimeStep(), getFont()));
ErrorTolerance et = solverDesc.getErrorTolerance();
if (et != null) {
simAdvTable.addCell(createCell("Error Tolerance - Absolute", getFont()));
simAdvTable.addCell(createCell("" + et.getAbsoluteErrorTolerance(), getFont()));
simAdvTable.addCell(createCell("Error Tolerance - Relative", getFont()));
simAdvTable.addCell(createCell("" + et.getRelativeErrorTolerance(), getFont()));
}
OutputTimeSpec ots = solverDesc.getOutputTimeSpec();
if (ots.isDefault()) {
simAdvTable.addCell(createCell("Keep Every", getFont()));
simAdvTable.addCell(createCell("" + ((DefaultOutputTimeSpec) ots).getKeepEvery(), getFont()));
simAdvTable.addCell(createCell("Keep At Most", getFont()));
simAdvTable.addCell(createCell("" + ((DefaultOutputTimeSpec) ots).getKeepAtMost(), getFont()));
} else if (ots.isUniform()) {
simAdvTable.addCell(createCell("Output Time Step", getFont()));
simAdvTable.addCell(createCell("" + ((UniformOutputTimeSpec) ots).getOutputTimeStep(), getFont()));
} else if (ots.isExplicit()) {
simAdvTable.addCell(createCell("Output Time Points", getFont()));
simAdvTable.addCell(createCell("" + ((ExplicitOutputTimeSpec) ots).toCommaSeperatedOneLineOfString(), getFont()));
}
simAdvTable.addCell(createCell("Use Symbolic Jacobian (T/F)", getFont()));
simAdvTable.addCell(createCell((solverDesc.getUseSymbolicJacobian() ? " T " : " F "), getFont()));
Constant sp = solverDesc.getSensitivityParameter();
if (sp != null) {
simAdvTable.addCell(createCell("Sensitivity Analysis Param", getFont()));
simAdvTable.addCell(createCell(sp.getName(), getFont()));
}
}
if (simAdvTable != null) {
simSection.add(simAdvTable);
}
}
use of com.lowagie.text.Section in project vcell by virtualcell.
the class ITextWriter method writeModel.
// model description ignored.
protected void writeModel(Chapter physioChapter, Model model) throws DocumentException {
Section structSection = null;
// add structures image
// if (model.getNumStructures() > 0) {
// try {
// ByteArrayOutputStream bos = generateDocStructureImage(model, ITextWriter.LOW_RESOLUTION);
// structSection = physioChapter.addSection("Structures For: " + model.getName(), physioChapter.numberDepth() + 1);
// addImage(structSection, bos);
// } catch(Exception e) {
// System.err.println("Unable to add structures image for model: " + model.getName());
// e.printStackTrace();
// }
// }
// write structures
Table structTable = null;
for (int i = 0; i < model.getNumStructures(); i++) {
if (structTable == null) {
structTable = getTable(4, 100, 1, 3, 3);
structTable.addCell(createCell("Structures", getBold(DEF_HEADER_FONT_SIZE), 4, 1, Element.ALIGN_CENTER, true));
structTable.addCell(createHeaderCell("Name", getFont(), 1));
structTable.addCell(createHeaderCell("Type", getFont(), 1));
structTable.addCell(createHeaderCell("Inside", getFont(), 1));
structTable.addCell(createHeaderCell("Outside", getFont(), 1));
structTable.endHeaders();
}
writeStructure(model, model.getStructure(i), structTable);
}
// if (structTable != null) {
// structSection.add(structTable);
// }
// write reactions
writeReactions(physioChapter, model);
}
use of com.lowagie.text.Section in project vcell by virtualcell.
the class ITextWriter method writeReactionContext.
// ReactionContext - SpeciesContextSpec: ignored boundary conditions.
protected void writeReactionContext(Section simContextSection, SimulationContext simContext) throws DocumentException {
ReactionContext rc = simContext.getReactionContext();
if (rc == null) {
return;
}
Section rcSection = null;
// add reaction specs
ReactionSpec[] reactionSpecs = rc.getReactionSpecs();
Table reactionSpecTable = null;
for (int i = 0; i < reactionSpecs.length; i++) {
if (i == 0) {
reactionSpecTable = getTable(4, 100, 1, 3, 3);
// reactionSpecTable.setTableFitsPage(true);
reactionSpecTable.addCell(createCell("Reaction Mapping", getBold(DEF_HEADER_FONT_SIZE), 4, 1, Element.ALIGN_CENTER, true));
reactionSpecTable.addCell(createHeaderCell("Name", getBold(), 1));
reactionSpecTable.addCell(createHeaderCell("Type", getBold(), 1));
reactionSpecTable.addCell(createHeaderCell("Enabled (T/F)", getBold(), 1));
reactionSpecTable.addCell(createHeaderCell("Fast (T/F)", getBold(), 1));
reactionSpecTable.endHeaders();
}
String reactionName = reactionSpecs[i].getReactionStep().getName();
String reactionType = reactionSpecs[i].getReactionStep().getDisplayType();
reactionSpecTable.addCell(createCell(reactionName, getFont()));
reactionSpecTable.addCell(createCell(reactionType, getFont()));
reactionSpecTable.addCell(createCell((reactionSpecs[i].isExcluded() ? " F " : " T "), getFont()));
reactionSpecTable.addCell(createCell((reactionSpecs[i].isFast() ? " T " : " F "), getFont()));
}
if (reactionSpecTable != null) {
rcSection = simContextSection.addSection("Reaction Mapping For " + simContext.getName(), simContextSection.numberDepth() + 1);
rcSection.add(reactionSpecTable);
}
// add species context specs
SpeciesContextSpec[] speciesContSpecs = rc.getSpeciesContextSpecs();
Table speciesSpecTable = null;
int[] widths = { 2, 2, 4, 4, 1 };
for (int i = 0; i < speciesContSpecs.length; i++) {
if (i == 0) {
speciesSpecTable = getTable(5, 100, 1, 3, 3);
speciesSpecTable.addCell(createCell("Initial Conditions", getBold(DEF_HEADER_FONT_SIZE), 5, 1, Element.ALIGN_CENTER, true));
speciesSpecTable.addCell(createHeaderCell("Species", getBold(), 1));
speciesSpecTable.addCell(createHeaderCell("Structure", getBold(), 1));
speciesSpecTable.addCell(createHeaderCell("Initial Conc.", getBold(), 1));
speciesSpecTable.addCell(createHeaderCell("Diffusion Const.", getBold(), 1));
speciesSpecTable.addCell(createHeaderCell("Fixed (T/F)", getBold(), 1));
speciesSpecTable.endHeaders();
}
String speciesName = speciesContSpecs[i].getSpeciesContext().getSpecies().getCommonName();
String structName = speciesContSpecs[i].getSpeciesContext().getStructure().getName();
String diff = speciesContSpecs[i].getDiffusionParameter().getExpression().infix();
VCUnitDefinition diffUnit = speciesContSpecs[i].getDiffusionParameter().getUnitDefinition();
SpeciesContextSpecParameter initParam = speciesContSpecs[i].getInitialConditionParameter();
String initConc = initParam == null ? "" : initParam.getExpression().infix();
VCUnitDefinition initConcUnit = initParam == null ? null : initParam.getUnitDefinition();
speciesSpecTable.addCell(createCell(speciesName, getFont()));
speciesSpecTable.addCell(createCell(structName, getFont()));
speciesSpecTable.addCell(createCell(initConc + (initConcUnit == null ? "" : " " + initConcUnit.getSymbolUnicode()), getFont()));
speciesSpecTable.addCell(createCell(diff + (diffUnit == null ? "" : " " + diffUnit.getSymbolUnicode()), getFont()));
speciesSpecTable.addCell(createCell((speciesContSpecs[i].isConstant() ? " T " : " F "), getFont()));
}
if (speciesSpecTable != null) {
if (rcSection == null) {
rcSection = simContextSection.addSection("Reaction Mapping For " + simContext.getName(), simContextSection.numberDepth() + 1);
}
speciesSpecTable.setWidths(widths);
rcSection.add(speciesSpecTable);
}
}
use of com.lowagie.text.Section in project vcell by virtualcell.
the class ITextWriter method writeReactions.
// each reaction has its own table, ordered by the structures.
protected void writeReactions(Chapter physioChapter, Model model) throws DocumentException {
if (model == null) {
return;
}
Paragraph reactionParagraph = new Paragraph();
reactionParagraph.add(new Chunk("Structures and Reactions Diagram").setLocalDestination(model.getName()));
Section reactionDiagramSection = physioChapter.addSection(reactionParagraph, physioChapter.numberDepth() + 1);
try {
addImage(reactionDiagramSection, encodeJPEG(generateDocReactionsImage(model, null)));
} catch (Exception e) {
e.printStackTrace();
throw new DocumentException(e.getClass().getName() + ": " + e.getMessage());
}
for (int i = 0; i < model.getNumStructures(); i++) {
ReactionStep[] reactionSteps = model.getReactionSteps();
ReactionStep rs = null;
Table modifierTable = null;
Table reactionTable = null;
boolean firstTime = true;
Section reactStructSection = null;
for (int j = 0; j < reactionSteps.length; j++) {
if (reactionSteps[j].getStructure() == model.getStructure(i)) {
// can also use structureName1.equals(structureName2)
if (firstTime) {
Paragraph linkParagraph = new Paragraph();
linkParagraph.add(new Chunk("Reaction(s) in " + model.getStructure(i).getName()).setLocalDestination(model.getStructure(i).getName()));
reactStructSection = physioChapter.addSection(linkParagraph, physioChapter.numberDepth() + 1);
firstTime = false;
}
rs = reactionSteps[j];
String type;
if (rs instanceof SimpleReaction) {
type = "Reaction";
} else {
type = "Flux";
}
// write Reaction equation as a table
// Get the image arrow cell depending on type of reactionStep : MassAction => double arrow, otherwise, forward arrow
boolean bReversible = false;
if (rs.getKinetics() instanceof MassActionKinetics) {
bReversible = true;
}
Cell arrowImageCell = getReactionArrowImageCell(bReversible);
// Get reactants and products strings
ReactionCanvas rc = new ReactionCanvas();
rc.setReactionStep(rs);
ReactionCanvasDisplaySpec rcdSpec = rc.getReactionCanvasDisplaySpec();
String reactants = rcdSpec.getLeftText();
String products = rcdSpec.getRightText();
// Create table and add cells for reactants, arrow(s) images, products
int[] widths = { 8, 1, 8 };
reactionTable = getTable(3, 100, 0, 2, 2);
// Add reactants as cell
Cell tableCell = createCell(reactants, getBold());
tableCell.setHorizontalAlignment(Cell.ALIGN_RIGHT);
tableCell.setBorderColor(Color.white);
reactionTable.addCell(tableCell);
// add arrow(s) image as cell
if (arrowImageCell != null) {
arrowImageCell.setHorizontalAlignment(Cell.ALIGN_CENTER);
arrowImageCell.setBorderColor(Color.white);
reactionTable.addCell(arrowImageCell);
}
// add products as cell
tableCell = createCell(products, getBold());
tableCell.setBorderColor(Color.white);
reactionTable.addCell(tableCell);
// reactionTable.setBorderColor(Color.white);
reactionTable.setWidths(widths);
// Identify modifiers,
ReactionParticipant[] rpArr = rs.getReactionParticipants();
Vector<ReactionParticipant> modifiersVector = new Vector<ReactionParticipant>();
for (int k = 0; k < rpArr.length; k += 1) {
if (rpArr[k] instanceof Catalyst) {
modifiersVector.add(rpArr[k]);
}
}
// Write the modifiers in a separate table, if present
if (modifiersVector.size() > 0) {
modifierTable = getTable(1, 50, 0, 1, 1);
modifierTable.addCell(createCell("Modifiers List", getBold(DEF_HEADER_FONT_SIZE), 1, 1, Element.ALIGN_CENTER, true));
StringBuffer modifierNames = new StringBuffer();
for (int k = 0; k < modifiersVector.size(); k++) {
modifierNames.append(((Catalyst) modifiersVector.elementAt(k)).getName() + "\n");
}
modifierTable.addCell(createCell(modifierNames.toString().trim(), getFont()));
modifiersVector.removeAllElements();
}
Section reactionSection = reactStructSection.addSection(type + " " + rs.getName(), reactStructSection.numberDepth() + 1);
// Annotation
VCMetaData vcMetaData = rs.getModel().getVcMetaData();
if (vcMetaData.getFreeTextAnnotation(rs) != null) {
Table annotTable = getTable(1, 100, 1, 3, 3);
annotTable.addCell(createCell("Reaction Annotation", getBold(DEF_HEADER_FONT_SIZE), 1, 1, Element.ALIGN_CENTER, true));
annotTable.addCell(createCell(vcMetaData.getFreeTextAnnotation(rs), getFont()));
reactionSection.add(annotTable);
// reactionSection.add(new Paragraph("\""+rs.getAnnotation()+"\""));
}
// reaction table
if (reactionTable != null) {
reactionSection.add(reactionTable);
// re-set reactionTable
reactionTable = null;
}
if (modifierTable != null) {
reactionSection.add(modifierTable);
modifierTable = null;
}
// Write kinetics parameters, etc. in a table
writeKineticsParams(reactionSection, rs);
}
}
}
}
Aggregations