Search in sources :

Example 26 with SimulationContext

use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.

the class StructureMappingTableRenderer method getTableCellRendererComponent.

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);
    if (table.getModel() instanceof StructureMappingTableModel) {
        StructureMappingTableModel structureMappingTableModel = (StructureMappingTableModel) table.getModel();
        String toolTip = structureMappingTableModel.getToolTip(row, column);
        if (value instanceof Structure) {
            Structure structure = (Structure) value;
            setText(structure.getName());
        } else if (value instanceof Double && structureMappingTableModel.isNewSizeColumn(column)) {
            StructureMapping structureMapping = structureMappingTableModel.getStructureMapping(row);
            if (structureMappingTableModel.isNonSpatial()) {
                VCUnitDefinition unitDefinition = structureMapping.getStructure().getStructureSize().getUnitDefinition();
                TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
                if (sizeIcon == null) {
                    sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
                    unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
                }
                setIcon(sizeIcon);
            } else {
                // spatial
                if (structureMapping.getUnitSizeParameter() != null) {
                    VCUnitDefinition unitDefinition = structureMapping.getUnitSizeParameter().getUnitDefinition();
                    TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
                    if (sizeIcon == null) {
                        sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
                        unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
                    }
                    setIcon(sizeIcon);
                }
            }
        }
        if (structureMappingTableModel.isSubdomainColumn(column)) {
            // can be null
            if (value == null) {
                setText("Unmapped");
                setForeground(Color.red);
                setIcon(null);
            } else {
                if (value instanceof GeometryClass) {
                    setText(((GeometryClass) value).getName());
                    if (value instanceof SubVolume) {
                        SubVolume subVolume = (SubVolume) value;
                        java.awt.Color handleColor = new java.awt.Color(colormap[subVolume.getHandle()]);
                        // small square icon with subdomain color
                        Icon icon = new ColorIcon(10, 10, handleColor, true);
                        setHorizontalTextPosition(SwingConstants.RIGHT);
                        setIcon(icon);
                    } else if (value instanceof SurfaceClass) {
                        SurfaceClass sc = (SurfaceClass) value;
                        Set<SubVolume> sv = sc.getAdjacentSubvolumes();
                        Iterator<SubVolume> iterator = sv.iterator();
                        SubVolume sv1 = iterator.next();
                        SubVolume sv2 = iterator.next();
                        java.awt.Color c1 = new java.awt.Color(colormap[sv2.getHandle()]);
                        java.awt.Color c2 = new java.awt.Color(colormap[sv1.getHandle()]);
                        Icon icon = new ColorIconEx(10, 10, c1, c2);
                        setIcon(icon);
                        setHorizontalTextPosition(SwingConstants.RIGHT);
                    }
                } else {
                    setText(value.toString());
                    setIcon(null);
                }
            }
        }
        if (value instanceof BoundaryConditionType) {
            // we get here only for spatial
            Object candidate = structureMappingTableModel.getValueAt(row, StructureMappingTableModel.SPATIAL_COLUMN_SUBDOMAIN);
            if (candidate instanceof SurfaceClass) {
                SurfaceClass surfaceClass = (SurfaceClass) candidate;
                cbit.vcell.model.Model model = structureMappingTableModel.getGeometryContext().getModel();
                SimulationContext simContext = structureMappingTableModel.getGeometryContext().getSimulationContext();
                Pair<SubVolume, SubVolume> ret = DiffEquMathMapping.computeBoundaryConditionSource(model, simContext, surfaceClass);
                SubVolume innerSubVolume = ret.one;
                java.awt.Color handleColor = new java.awt.Color(colormap[innerSubVolume.getHandle()]);
                // small square icon with subdomain color
                Icon icon = new ColorIcon(8, 8, handleColor, true);
                setHorizontalTextPosition(SwingConstants.LEFT);
                setIcon(icon);
                setText("from");
                // override default tooltip
                toolTip = "Boundary condition inherited from Subdomain '" + innerSubVolume.getName() + "'";
                setToolTipText(toolTip);
            } else {
                setText(((BoundaryConditionType) value).boundaryTypeStringValue());
            }
        }
        List<Issue> issueList = structureMappingTableModel.getIssues(row, column, Issue.SEVERITY_ERROR);
        if (issueList.size() > 0) {
            // override default tooltip
            setToolTipText(Issue.getHtmlIssueMessage(issueList));
            if (column == 0) {
                setBorder(new MatteBorder(1, 1, 1, 0, Color.red));
            } else if (column == table.getColumnCount() - 1) {
                setBorder(new MatteBorder(1, 0, 1, 1, Color.red));
            } else {
                setBorder(new MatteBorder(1, 0, 1, 0, Color.red));
            }
        } else {
            setToolTipText(toolTip);
            setBorder(DEFAULT_GAP);
        }
    }
    return this;
}
Also used : Color(java.awt.Color) GeometryClass(cbit.vcell.geometry.GeometryClass) Set(java.util.Set) Issue(org.vcell.util.Issue) SurfaceClass(cbit.vcell.geometry.SurfaceClass) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType) AttributedString(java.text.AttributedString) StructureMapping(cbit.vcell.mapping.StructureMapping) MatteBorder(javax.swing.border.MatteBorder) SubVolume(cbit.vcell.geometry.SubVolume) Iterator(java.util.Iterator) Structure(cbit.vcell.model.Structure) ColorIconEx(org.vcell.util.gui.ColorIconEx) ColorIcon(org.vcell.util.gui.ColorIcon) Color(java.awt.Color) SimulationContext(cbit.vcell.mapping.SimulationContext) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ColorIcon(org.vcell.util.gui.ColorIcon) Icon(javax.swing.Icon)

Example 27 with SimulationContext

use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.

the class SpeciesContextSpecsTableModel method setSimulationContext.

/**
 * Sets the simulationContext property (cbit.vcell.mapping.SimulationContext) value.
 * @param simulationContext The new value for the property.
 * @see #getSimulationContext
 */
public void setSimulationContext(SimulationContext simulationContext) {
    SimulationContext oldValue = fieldSimulationContext;
    int oldColumnCount = getColumnCount();
    if (oldValue != null) {
        oldValue.removePropertyChangeListener(this);
        oldValue.getGeometryContext().removePropertyChangeListener(this);
        updateListenersReactionContext(oldValue.getReactionContext(), true);
    }
    fieldSimulationContext = simulationContext;
    refreshColumns();
    int newColumnCount = getColumnCount();
    if (oldColumnCount != newColumnCount) {
        fireTableStructureChanged();
    }
    if (simulationContext != null) {
        simulationContext.addPropertyChangeListener(this);
        simulationContext.getGeometryContext().addPropertyChangeListener(this);
        updateListenersReactionContext(simulationContext.getReactionContext(), false);
        autoCompleteSymbolFilter = simulationContext.getAutoCompleteSymbolFilter();
        refreshData();
    }
}
Also used : SimulationContext(cbit.vcell.mapping.SimulationContext)

Example 28 with SimulationContext

use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.

the class GeneratedReactionTableModel method getValueAt.

public Object getValueAt(int iRow, int iCol) {
    GeneratedReactionTableRow reactionTableRow = getValueAt(iRow);
    BNGReaction reactionObject = reactionTableRow.getReactionObject();
    String name = reactionObject.getRuleName();
    switch(iCol) {
        case iColRule:
            if (name.endsWith(ReactionRule.DirectHalf)) {
                name = name.substring(0, name.indexOf(ReactionRule.DirectHalf));
            }
            if (name.endsWith(ReactionRule.InverseHalf)) {
                name = name.substring(0, name.indexOf(ReactionRule.InverseHalf));
                name += " (rev)";
            }
            return name;
        case iColStructure:
            if (name.endsWith(ReactionRule.DirectHalf)) {
                name = name.substring(0, name.indexOf(ReactionRule.DirectHalf));
            }
            if (name.endsWith(ReactionRule.InverseHalf)) {
                name = name.substring(0, name.indexOf(ReactionRule.InverseHalf));
            }
            SimulationContext sc = owner.getSimulationContext();
            ReactionRule rr = sc.getModel().getRbmModelContainer().getReactionRule(name);
            if (rr != null && rr.getStructure() != null) {
                return rr.getStructure().getName();
            } else {
                return "?";
            }
        case iColDepiction:
        case iColDefinition:
            return reactionTableRow.getExpression();
        default:
            return null;
    }
}
Also used : BNGReaction(cbit.vcell.bionetgen.BNGReaction) ReactionRule(cbit.vcell.model.ReactionRule) SimulationContext(cbit.vcell.mapping.SimulationContext)

Example 29 with SimulationContext

use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.

the class NfsimExtensionFilter method writeBioModel.

@Override
public void writeBioModel(DocumentManager documentManager, BioModel bioModel, File exportFile, SimulationContext simulationContext) throws Exception {
    // TODO: get the first thing we find for now, in the future we'll need to modify ChooseFile
    // to only offer the applications / simulations with bngl content
    // This should be done by creating one or more additional Selector values and add the filtering logic to ChooseFile
    SimulationContext[] simContexts = bioModel.getSimulationContexts();
    Simulation selectedSim = simulationContext.getSimulations(0);
    // Simulation selectedSim = (Simulation)hashTable.get("selectedSimulation");
    SimulationTask simTask = new SimulationTask(new SimulationJob(selectedSim, 0, null), 0);
    // a fixed seed will allow us to run reproducible simulations
    long randomSeed = 0;
    // long randomSeed = System.currentTimeMillis();
    NFsimSimulationOptions nfsimSimulationOptions = new NFsimSimulationOptions();
    // we get the data we need from the math description
    boolean bUseLocationMarks = true;
    Element root = NFsimXMLWriter.writeNFsimXML(simTask, randomSeed, nfsimSimulationOptions, bUseLocationMarks);
    Document doc = new Document();
    doc.setRootElement(root);
    XMLOutputter xmlOut = new XMLOutputter();
    String resultString = xmlOut.outputString(doc);
    FileUtils.writeStringToFile(exportFile, resultString);
}
Also used : NFsimSimulationOptions(cbit.vcell.solver.NFsimSimulationOptions) XMLOutputter(org.jdom.output.XMLOutputter) SimulationTask(cbit.vcell.messaging.server.SimulationTask) Simulation(cbit.vcell.solver.Simulation) Element(org.jdom.Element) SimulationContext(cbit.vcell.mapping.SimulationContext) Document(org.jdom.Document) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 30 with SimulationContext

use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.

the class SmoldynExtensionFilter method askUser.

@Override
public void askUser(ChooseContext ctx) throws UserCancelException {
    SimulationContext chosenSimContext = ctx.chosenContext;
    String[] simNames = new String[chosenSimContext.getSimulations().length];
    Simulation[] sims = chosenSimContext.getSimulations();
    for (int i = 0; i < sims.length; i++) {
        simNames[i] = sims[i].getName();
    }
    Object choice = PopupGenerator.showListDialog(ctx.topLevelWindowManager, simNames, "Please select " + chosenSimContext.getName() + " simulation to export");
    if (choice == null) {
        throw UserCancelException.CANCEL_FILE_SELECTION;
    }
    String chosenSimulationName = (String) choice;
    Simulation chosenSimulation = chosenSimContext.getSimulation(chosenSimulationName);
    Objects.requireNonNull(chosenSimulation);
    // PENDING delete
    ctx.hashTable.put(SIM_KEY, chosenSimulation);
    selectedSim = chosenSimulation;
}
Also used : Simulation(cbit.vcell.solver.Simulation) SimulationContext(cbit.vcell.mapping.SimulationContext)

Aggregations

SimulationContext (cbit.vcell.mapping.SimulationContext)217 BioModel (cbit.vcell.biomodel.BioModel)98 Simulation (cbit.vcell.solver.Simulation)64 MathDescription (cbit.vcell.math.MathDescription)35 Model (cbit.vcell.model.Model)35 PropertyVetoException (java.beans.PropertyVetoException)35 Expression (cbit.vcell.parser.Expression)34 MathModel (cbit.vcell.mathmodel.MathModel)33 ExpressionException (cbit.vcell.parser.ExpressionException)32 Geometry (cbit.vcell.geometry.Geometry)31 XmlParseException (cbit.vcell.xml.XmlParseException)31 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)29 XMLSource (cbit.vcell.xml.XMLSource)28 DataAccessException (org.vcell.util.DataAccessException)27 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)26 KeyValue (org.vcell.util.document.KeyValue)26 SpeciesContext (cbit.vcell.model.SpeciesContext)24 Structure (cbit.vcell.model.Structure)23 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)22