use of cbit.vcell.units.VCUnitDefinition 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 cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.
the class ITextWriter method writeKineticsParams.
protected void writeKineticsParams(Section reactionSection, ReactionStep rs) throws DocumentException {
Kinetics.KineticsParameter[] kineticsParameters = rs.getKinetics().getKineticsParameters();
Table paramTable = null;
int[] widths = { 1, 4, 3, 2 };
if (kineticsParameters.length > 0) {
paramTable = getTable(4, 100, 1, 3, 3);
paramTable.addCell(createCell("Kinetics Parameters", getBold(DEF_HEADER_FONT_SIZE), 4, 1, Element.ALIGN_CENTER, true));
paramTable.addCell(createHeaderCell("Name", getBold(), 1));
paramTable.addCell(createHeaderCell("Expression", getBold(), 1));
paramTable.addCell(createHeaderCell("Role", getBold(), 1));
paramTable.addCell(createHeaderCell("Unit", getBold(), 1));
paramTable.endHeaders();
for (int k = 0; k < kineticsParameters.length; k++) {
String name = kineticsParameters[k].getName();
Expression expression = kineticsParameters[k].getExpression();
String role = rs.getKinetics().getDefaultParameterDesc(kineticsParameters[k].getRole());
VCUnitDefinition unit = kineticsParameters[k].getUnitDefinition();
paramTable.addCell(createCell(name, getFont()));
paramTable.addCell(createCell((expression == null ? "" : expression.infix()), getFont()));
paramTable.addCell(createCell(role, getFont()));
// dimensionless will show as '1'.
paramTable.addCell(createCell((unit == null ? "" : unit.getSymbolUnicode()), getFont()));
}
}
if (paramTable != null) {
paramTable.setWidths(widths);
reactionSection.add(paramTable);
}
}
use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.
the class ModelUnitSystem method createDefaultSBMLLevel2Units.
public static ModelUnitSystem createDefaultSBMLLevel2Units() {
VCUnitSystem tempUnitSystem = new VCUnitSystem() {
};
VCUnitDefinition modelSubstanceUnit = tempUnitSystem.getInstance("mol");
VCUnitDefinition modelVolumeUnit = tempUnitSystem.getInstance("litre");
VCUnitDefinition modelAreaUnit = tempUnitSystem.getInstance("m2");
VCUnitDefinition modelLengthUnit = tempUnitSystem.getInstance("m");
VCUnitDefinition modelTimeUnit = tempUnitSystem.getInstance("s");
ModelUnitSystem modelUnitSystem = ModelUnitSystem.createUnitSystem(modelSubstanceUnit, modelSubstanceUnit, modelSubstanceUnit, modelVolumeUnit, modelAreaUnit, modelLengthUnit, modelTimeUnit);
return modelUnitSystem;
}
use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.
the class InitialConditionsPanel method initialize.
/**
* Initialize the class.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initialize() {
try {
// user code begin {1}
// user code end
setName("InitialConditionsPanel");
setLayout(new BorderLayout());
add(getRadioButtonAndCheckboxPanel(), BorderLayout.NORTH);
add(getScrollPaneTable().getEnclosingScrollPane(), BorderLayout.CENTER);
getScrollPaneTable().getSelectionModel().addListSelectionListener(ivjEventHandler);
getJMenuItemPaste().addActionListener(ivjEventHandler);
getJMenuItemCopy().addActionListener(ivjEventHandler);
getJMenuItemCopyAll().addActionListener(ivjEventHandler);
getJMenuItemPasteAll().addActionListener(ivjEventHandler);
getAmountRadioButton().addActionListener(ivjEventHandler);
getConcentrationRadioButton().addActionListener(ivjEventHandler);
getRandomizeInitCondnCheckbox().addActionListener(ivjEventHandler);
DefaultTableCellRenderer renderer = new DefaultScrollTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
setIcon(null);
defaultToolTipText = null;
if (value instanceof Species) {
setText(((Species) value).getCommonName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
} else if (value instanceof SpeciesContext) {
setText(((SpeciesContext) value).getName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
} else if (value instanceof Structure) {
setText(((Structure) value).getName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
} else if (value instanceof ScopedExpression) {
SpeciesContextSpec scSpec = tableModel.getValueAt(row);
VCUnitDefinition unit = null;
if (table.getColumnName(column).equals(SpeciesContextSpecsTableModel.ColumnType.COLUMN_INITIAL.label)) {
SpeciesContextSpecParameter initialConditionParameter = scSpec.getInitialConditionParameter();
unit = initialConditionParameter.getUnitDefinition();
} else if (table.getColumnName(column).equals(SpeciesContextSpecsTableModel.ColumnType.COLUMN_DIFFUSION.label)) {
SpeciesContextSpecParameter diffusionParameter = scSpec.getDiffusionParameter();
unit = diffusionParameter.getUnitDefinition();
}
if (unit != null) {
setHorizontalTextPosition(JLabel.LEFT);
setIcon(new TextIcon("[" + unit.getSymbolUnicode() + "]", DefaultScrollTableCellRenderer.uneditableForeground));
}
int rgb = 0x00ffffff & DefaultScrollTableCellRenderer.uneditableForeground.getRGB();
defaultToolTipText = "<html>" + StringEscapeUtils.escapeHtml4(getText()) + " <font color=#" + Integer.toHexString(rgb) + "> [" + unit.getSymbolUnicode() + "] </font></html>";
setToolTipText(defaultToolTipText);
if (unit != null) {
setText(defaultToolTipText);
}
}
TableModel tableModel = table.getModel();
if (tableModel instanceof SortTableModel) {
DefaultScrollTableCellRenderer.issueRenderer(this, defaultToolTipText, table, row, column, (SortTableModel) tableModel);
setHorizontalTextPosition(JLabel.TRAILING);
}
return this;
}
};
DefaultTableCellRenderer rbmSpeciesShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {
SpeciesPatternSmallShape spss = null;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == tableModel) {
selectedObject = tableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof SpeciesContextSpec) {
SpeciesContextSpec scs = (SpeciesContextSpec) selectedObject;
SpeciesContext sc = scs.getSpeciesContext();
// sp may be null for "plain" species contexts
SpeciesPattern sp = sc.getSpeciesPattern();
Graphics panelContext = table.getGraphics();
spss = new SpeciesPatternSmallShape(4, 2, sp, shapeManager, panelContext, sc, isSelected, issueManager);
}
} else {
spss = null;
}
}
setText("");
return this;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (spss != null) {
spss.paintSelf(g);
}
}
};
getScrollPaneTable().setDefaultRenderer(SpeciesContext.class, renderer);
getScrollPaneTable().setDefaultRenderer(Structure.class, renderer);
getScrollPaneTable().setDefaultRenderer(SpeciesPattern.class, rbmSpeciesShapeDepictionCellRenderer);
getScrollPaneTable().setDefaultRenderer(Species.class, renderer);
getScrollPaneTable().setDefaultRenderer(ScopedExpression.class, renderer);
getScrollPaneTable().setDefaultRenderer(Boolean.class, new ScrollTableBooleanCellRenderer());
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.
the class StructureMappingTableModel method setValueAt.
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if (rowIndex < 0 || rowIndex >= getRowCount()) {
throw new RuntimeException("StructureMappingTableModel.setValueAt(), row = " + rowIndex + " out of range [" + 0 + "," + (getRowCount() - 1) + "]");
}
if (columnIndex < 0 || columnIndex >= getColumnCount()) {
throw new RuntimeException("StructureMappingTableModel.setValueAt(), column = " + columnIndex + " out of range [" + 0 + "," + (getColumnCount() - 1) + "]");
}
StructureMapping structureMapping = getValueAt(rowIndex);
Structure structure = structureMapping.getStructure();
if (bNonSpatial) {
switch(columnIndex) {
case NONSPATIAL_COLUMN_SIZE:
{
try {
Expression exp = null;
if (aValue instanceof String) {
exp = new Expression((String) aValue);
} else if (aValue instanceof Double) {
exp = new Expression(((Double) aValue).doubleValue());
}
// if the input volumn is null, leave it as it was.
if (exp != null) {
// for old ode model, once one size is input, solve the rest. if it is unnamed compartment(the only one), we don't need to solve anything
if (!getGeometryContext().getSimulationContext().isStoch() && getGeometryContext().isAllSizeSpecifiedNull() && getGeometryContext().isAllVolFracAndSurfVolSpecified() && getGeometryContext().getStructureMappings().length > 1) {
structureMapping.getSizeParameter().setExpression(exp);
double size;
try {
size = exp.evaluateConstant();
VCUnitDefinition volumeUnit = getGeometryContext().getSimulationContext().getModel().getUnitSystem().getVolumeUnit();
StructureSizeSolver.updateAbsoluteStructureSizes(getGeometryContext().getSimulationContext(), structure, size, volumeUnit);
fireTableRowsUpdated(0, getRowCount());
} catch (ExpressionException ex) {
ex.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Size of Feature " + structure.getName() + " can not be solved as constant!");
} catch (Exception ex) {
ex.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
}
} else {
structureMapping.getSizeParameter().setExpression(exp);
// set fraction in stoch math description, because these might be used when copy from stoch app to ode app.
if (getGeometryContext().isAllSizeSpecifiedPositive()) /*&& !getGeometryContext().getSimulationContext().isStoch()*/
{
try {
StructureSizeSolver.updateRelativeStructureSizes(getGeometryContext().getSimulationContext());
} catch (Exception ex) {
ex.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
}
}
}
}
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
}
break;
}
}
} else {
switch(columnIndex) {
case SPATIAL_COLUMN_SUBDOMAIN:
{
GeometryClass geometryClass = null;
if (aValue instanceof String) {
String svname = (String) aValue;
geometryClass = getGeometryContext().getGeometry().getGeometryClass(svname);
} else if (aValue instanceof GeometryClass) {
geometryClass = (GeometryClass) aValue;
}
if (geometryClass != null) {
try {
getGeometryContext().assignStructure(structure, geometryClass);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
} catch (IllegalMappingException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
} catch (MappingException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
}
}
break;
}
case SPATIAL_COLUMN_SIZERATIO:
try {
Expression exp = null;
if (aValue instanceof String) {
exp = new Expression((String) aValue);
} else if (aValue instanceof Double) {
exp = new Expression(((Double) aValue).doubleValue());
}
if (exp != null) {
structureMapping.getUnitSizeParameter().setExpression(exp);
StructureSizeSolver.updateUnitStructureSizes(getGeometryContext().getSimulationContext(), structureMapping.getGeometryClass());
}
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
}
break;
case SPATIAL_COLUMN_X_MINUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeXm(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_X_PLUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeXp(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_Y_MINUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeYm(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_Y_PLUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeYp(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_Z_MINUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeZm(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_Z_PLUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeZp(new BoundaryConditionType((String) aValue));
}
break;
}
}
}
}
Aggregations