Search in sources :

Example 11 with IssueContext

use of org.vcell.util.IssueContext in project vcell by virtualcell.

the class MolecularTypeLargeShape method paintSpecies.

// --------------------------------------------------------------------------------------
private void paintSpecies(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Font fontOld = g2.getFont();
    Color colorOld = g2.getColor();
    Stroke strokeOld = g2.getStroke();
    Color primaryColor = null;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    if (mt == null && mtp == null) {
        // plain species context
        Color exterior;
        if (owner == null) {
            // for plain species, we just draw a circle based on height!!! we ignore width!!!
            // error
            exterior = Color.red.darker();
        } else {
            if (!shapePanel.isShowMoleculeColor()) {
                exterior = Color.GRAY;
            } else {
                // plain species
                exterior = Color.green.darker().darker();
            }
        }
        Point2D center = new Point2D.Float(xPos + baseHeight / 3, yPos + baseHeight / 3);
        float radius = baseHeight * 0.5f;
        Point2D focus = new Point2D.Float(xPos + baseHeight / 3 - 1, yPos + baseHeight / 3 - 1);
        float[] dist = { 0.1f, 1.0f };
        Color[] colors = { Color.white, exterior };
        RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
        g2.setPaint(p);
        Ellipse2D circle = new Ellipse2D.Double(xPos, yPos, baseHeight, baseHeight);
        g2.fill(circle);
        Ellipse2D circle2 = new Ellipse2D.Double(xPos - 1, yPos - 1, baseHeight + 0.7, baseHeight + 0.7);
        g2.setPaint(getDefaultColor(Color.DARK_GRAY));
        int z = shapePanel.getZoomFactor();
        g2.setStroke(new BasicStroke(2.0f + 0.14f * z));
        g2.draw(circle2);
        if (owner == null) {
            Font font = fontOld.deriveFont(Font.BOLD);
            g.setFont(font);
            g.setColor(Color.red.darker().darker());
            g2.drawString("Error parsing generated species!", xPos + baseHeight + 10, yPos + baseHeight - 9);
        }
        g2.setFont(fontOld);
        g2.setColor(colorOld);
        g2.setStroke(strokeOld);
        return;
    } else {
        // molecular type, species pattern, observable
        if (mt == null || mt.getModel() == null) {
            primaryColor = Color.blue.darker().darker();
        } else {
            if (shapePanel.getDisplayMode() == DisplayMode.participantSignatures) {
                if (!shapePanel.isShowMoleculeColor()) {
                    primaryColor = AbstractComponentShape.componentVeryLightGray;
                } else {
                    RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
                    List<MolecularType> mtList = rbmmc.getMolecularTypeList();
                    int index = mtList.indexOf(mt);
                    index = index % 7;
                    primaryColor = colorTable[index].darker().darker();
                }
                if (shapePanel.isShowDifferencesOnly()) {
                    ReactionRule reactionRule = (ReactionRule) owner;
                    switch(shapePanel.hasNoMatch(reactionRule.getName(), mtp)) {
                        case CHANGED:
                            primaryColor = AbstractComponentShape.deepOrange;
                            break;
                        case // keep whatever color we set above
                        UNCHANGED:
                            break;
                        case ANALYSISFAILED:
                            ArrayList<Issue> issueList = new ArrayList<Issue>();
                            reactionRule.gatherIssues(new IssueContext(), issueList);
                            boolean bRuleHasErrorIssues = false;
                            for (Issue issue : issueList) {
                                if (issue.getSeverity() == Severity.ERROR) {
                                    bRuleHasErrorIssues = true;
                                    break;
                                }
                            }
                            if (bRuleHasErrorIssues) {
                                primaryColor = AbstractComponentShape.componentHidden;
                            } else {
                                System.err.println("ReactionRule Analysis failed, but there are not Error Issues with ReactionRule " + reactionRule.getName());
                                primaryColor = Color.red.darker();
                            }
                            break;
                        default:
                            break;
                    }
                }
            } else if (shapePanel.getDisplayMode() == DisplayMode.rules) {
                if (!shapePanel.isShowMoleculeColor()) {
                    primaryColor = AbstractComponentShape.componentVeryLightGray;
                } else {
                    RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
                    List<MolecularType> mtList = rbmmc.getMolecularTypeList();
                    int index = mtList.indexOf(mt);
                    index = index % 7;
                    primaryColor = colorTable[index].darker().darker();
                }
                // if we show difference, we apply that now and override the color
                if (shapePanel.isShowDifferencesOnly()) {
                    ReactionRule reactionRule = (ReactionRule) owner;
                    switch(shapePanel.hasNoMatch(mtp)) {
                        case CHANGED:
                            primaryColor = AbstractComponentShape.deepOrange;
                            break;
                        case // keep whatever color we set above
                        UNCHANGED:
                            break;
                        case ANALYSISFAILED:
                            ArrayList<Issue> issueList = new ArrayList<Issue>();
                            reactionRule.gatherIssues(new IssueContext(), issueList);
                            boolean bRuleHasErrorIssues = false;
                            for (Issue issue : issueList) {
                                if (issue.getSeverity() == Severity.ERROR) {
                                    bRuleHasErrorIssues = true;
                                    break;
                                }
                            }
                            if (bRuleHasErrorIssues) {
                                primaryColor = AbstractComponentShape.componentHidden;
                            } else {
                                System.err.println("ReactionRule Analysis failed, but there are not Error Issues with ReactionRule " + reactionRule.getName());
                                primaryColor = Color.red.darker();
                            }
                            break;
                        default:
                            break;
                    }
                }
            } else {
                // TODO: do we ever get here legitimately? if not throw an exception!
                RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
                List<MolecularType> mtList = rbmmc.getMolecularTypeList();
                int index = mtList.indexOf(mt);
                index = index % 7;
                if (!shapePanel.isShowMoleculeColor()) {
                    primaryColor = AbstractComponentShape.componentVeryLightGray;
                } else {
                    primaryColor = isHighlighted() == true ? Color.white : colorTable[index].darker().darker();
                }
                if (hasErrorIssues(owner, mt)) {
                    primaryColor = isHighlighted() ? Color.white : Color.red;
                }
            }
        }
    }
    // paint the structure contour if applicable (only for anchored molecules!)
    if (structure != null && mt != null && !mt.isAnchorAll() && mt.getAnchors().size() > 0) {
        paintNarrowCompartmentRight(g);
    } else if (owner instanceof MolecularType && !mt.isAnchorAll()) {
        paintNarrowCompartmentRight(g);
    }
    // paint the shape of the molecule and fill it with color
    GradientPaint p = new GradientPaint(xPos, yPos, primaryColor, xPos, yPos + baseHeight / 2, Color.WHITE, true);
    g2.setPaint(p);
    RoundRectangle2D rect = new RoundRectangle2D.Float(xPos, yPos, width, baseHeight, cornerArc, cornerArc);
    g2.fill(rect);
    RoundRectangle2D inner = new RoundRectangle2D.Float(xPos + 1, yPos + 1, width - 2, baseHeight - 2, cornerArc - 3, cornerArc - 3);
    if (isHighlighted()) {
        if (hasErrorIssues(owner, mt)) {
            g2.setPaint(Color.red);
        } else {
            g2.setPaint(getDefaultColor(Color.BLACK));
        }
        g2.draw(inner);
        if (hasErrorIssues(owner, mt)) {
            g2.setPaint(Color.red);
        } else {
            g2.setPaint(getDefaultColor(Color.BLACK));
        }
        g2.draw(rect);
    } else {
        if (hasErrorIssues(owner, mt)) {
            g2.setPaint(Color.red.darker());
        } else {
            g2.setPaint(getDefaultColor(Color.GRAY));
        }
        g2.draw(inner);
        if (hasErrorIssues(owner, mt)) {
            g2.setPaint(Color.red.darker());
        } else {
            g2.setPaint(getDefaultColor(Color.DARK_GRAY));
        }
        g2.draw(rect);
    }
    // paint the anchor glyph
    Rectangle r = getAnchorHotspot();
    if (r != null) {
        // g2.drawRect(r.x, r.y, r.width, r.height);	// anchor tooltip hotspot area
        int z = shapePanel.getZoomFactor();
        int w = r.width;
        int x = r.x + w / 2;
        int y = r.y;
        int h = 12 + z / 2;
        h = z < -2 ? h - 1 : h;
        h = z < -4 ? h - 1 : h;
        Line2D line = new Line2D.Float(x, y, x, y + h);
        g2.setPaint(getDefaultColor(Color.RED.darker().darker()));
        g2.setStroke(new BasicStroke(2.6f + 0.13f * z));
        g2.draw(line);
        // TODO: adjust the arc at deep zoom!
        double a1 = z < -3 ? 245 : 240;
        // 60
        double a2 = z < -3 ? 52 : 59;
        Arc2D arc = new Arc2D.Double(x - h, y - h, 2 * h, 2 * h, a1, a2, Arc2D.OPEN);
        g2.setStroke(new BasicStroke(2.6f + 0.20f * z));
        g2.draw(arc);
        g2.setPaint(colorOld);
        g2.setStroke(strokeOld);
    }
    // the text inside the molecule shape
    if (mt == null && mtp == null) {
    // plain species context
    // don't write any text inside
    } else {
        // molecular type, species pattern
        Graphics gc = shapePanel.getGraphics();
        Font font = deriveMoleculeFontBold(g, shapePanel);
        g.setFont(font);
        // font color
        g.setColor(getDefaultColor(Color.BLACK));
        int fontSize = font.getSize();
        int textX = xPos + 11;
        int textY = yPos + baseHeight - (baseHeight - fontSize) / 2;
        g2.drawString(name, textX, textY);
        if (owner instanceof ReactionRule && mtp != null && mtp.hasExplicitParticipantMatch()) {
            int z = shapePanel.getZoomFactor();
            if (z >= LargeShapeCanvas.SmallestZoomFactorWithText) {
                // hide the matching too when we don't display the name
                FontMetrics fm = gc.getFontMetrics(font);
                int stringWidth = fm.stringWidth(name);
                Font smallerFont = font.deriveFont(font.getSize() * 0.8F);
                g.setFont(smallerFont);
                g2.drawString(mtp.getParticipantMatchLabel(), textX + stringWidth + 2, textY + 2);
            }
        }
    }
    g.setFont(fontOld);
    g.setColor(colorOld);
    g2.setStroke(strokeOld);
    for (MolecularComponentLargeShape mcls : componentShapes) {
        // paint the components
        mcls.paintSelf(g);
    }
    g2.setFont(fontOld);
    g2.setColor(colorOld);
    g2.setStroke(strokeOld);
}
Also used : BasicStroke(java.awt.BasicStroke) Issue(org.vcell.util.Issue) RoundRectangle2D(java.awt.geom.RoundRectangle2D) ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) RadialGradientPaint(java.awt.RadialGradientPaint) GradientPaint(java.awt.GradientPaint) Line2D(java.awt.geom.Line2D) Arc2D(java.awt.geom.Arc2D) Font(java.awt.Font) Ellipse2D(java.awt.geom.Ellipse2D) Point2D(java.awt.geom.Point2D) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) FontMetrics(java.awt.FontMetrics) IssueContext(org.vcell.util.IssueContext) ArrayList(java.util.ArrayList) List(java.util.List) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) ReactionRule(cbit.vcell.model.ReactionRule) Color(java.awt.Color) RadialGradientPaint(java.awt.RadialGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D) MolecularType(org.vcell.model.rbm.MolecularType) Graphics(java.awt.Graphics)

Example 12 with IssueContext

use of org.vcell.util.IssueContext in project vcell by virtualcell.

the class TestingFrameworkWindowManager method hasDuplicateIdentifiers.

private boolean hasDuplicateIdentifiers(BioModel bioModel) {
    ArrayList<Issue> issueList = new ArrayList<Issue>();
    IssueContext issueContext = new IssueContext();
    bioModel.gatherIssues(issueContext, issueList);
    boolean bFoundIdentifierConflictUponLoading = false;
    for (Issue issue : issueList) {
        if (issue.getCategory() == IssueCategory.Identifiers && issue.getSource() == bioModel.getModel() && issue.getSeverity() == Severity.ERROR) {
            bFoundIdentifierConflictUponLoading = true;
            break;
        }
    }
    return bFoundIdentifierConflictUponLoading;
}
Also used : Issue(org.vcell.util.Issue) ArrayList(java.util.ArrayList) IssueContext(org.vcell.util.IssueContext)

Example 13 with IssueContext

use of org.vcell.util.IssueContext in project vcell by virtualcell.

the class IssuePanel method invokeHyperlink.

private void invokeHyperlink(Issue issue) {
    if (selectionManager != null) {
        // followHyperlink is no-op if selectionManger null, so no point in proceeding if it is
        IssueContext issueContext = issue.getIssueContext();
        IssueSource object = issue.getSource();
        if (object instanceof DecoratedIssueSource) {
            DecoratedIssueSource dis = (DecoratedIssueSource) object;
            dis.activateView(selectionManager);
        } else if (object instanceof Parameter) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.BIOMODEL_PARAMETERS_NODE, ActiveViewID.parameters_functions), new Object[] { object });
        } else if (object instanceof StructureMapping) {
            StructureMapping structureMapping = (StructureMapping) object;
            StructureMappingNameScope structureMappingNameScope = (StructureMappingNameScope) structureMapping.getNameScope();
            SimulationContext simulationContext = ((SimulationContextNameScope) (structureMappingNameScope.getParent())).getSimulationContext();
            followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.structure_mapping), new Object[] { object });
        } else if (object instanceof SpatialObject) {
            SpatialObject spatialObject = (SpatialObject) object;
            SimulationContext simulationContext = spatialObject.getSimulationContext();
            followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.spatial_objects), new Object[] { object });
        } else if (object instanceof SpatialProcess) {
            SpatialProcess spatialProcess = (SpatialProcess) object;
            SimulationContext simulationContext = spatialProcess.getSimulationContext();
            followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.spatial_processes), new Object[] { object });
        } else if (object instanceof GeometryContext.UnmappedGeometryClass) {
            UnmappedGeometryClass unmappedGeometryClass = (UnmappedGeometryClass) object;
            SimulationContext simulationContext = unmappedGeometryClass.getSimulationContext();
            followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.structure_mapping), new Object[] { object });
        } else if (object instanceof MicroscopeMeasurement) {
            SimulationContext simulationContext = ((MicroscopeMeasurement) object).getSimulationContext();
            followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.PROTOCOLS_NODE, ActiveViewID.microscope_measuremments), new Object[] { object });
        } else if (object instanceof BioEvent) {
            BioEvent be = (BioEvent) object;
            SimulationContext simulationContext = be.getSimulationContext();
            followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.PROTOCOLS_NODE, ActiveViewID.events), new Object[] { object });
        } else if (object instanceof OutputFunctionIssueSource) {
            SimulationOwner simulationOwner = ((OutputFunctionIssueSource) object).getOutputFunctionContext().getSimulationOwner();
            if (simulationOwner instanceof SimulationContext) {
                SimulationContext simulationContext = (SimulationContext) simulationOwner;
                followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.SIMULATIONS_NODE, ActiveViewID.output_functions), new Object[] { ((OutputFunctionIssueSource) object).getAnnotatedFunction() });
            } else if (simulationOwner instanceof MathModel) {
                followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MATH_OUTPUT_FUNCTIONS_NODE, ActiveViewID.math_output_functions), new Object[] { ((OutputFunctionIssueSource) object).getAnnotatedFunction() });
            }
        } else if (object instanceof Simulation) {
            Simulation simulation = (Simulation) object;
            SimulationOwner simulationOwner = simulation.getSimulationOwner();
            if (simulationOwner instanceof SimulationContext) {
                SimulationContext simulationContext = (SimulationContext) simulationOwner;
                followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.SIMULATIONS_NODE, ActiveViewID.simulations), new Object[] { simulation });
            } else if (simulationOwner instanceof MathModel) {
                followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MATH_SIMULATIONS_NODE, ActiveViewID.math_simulations), new Object[] { simulation });
            }
        } else if (object instanceof GeometryContext) {
            setActiveView(new ActiveView(((GeometryContext) object).getSimulationContext(), DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.geometry_definition));
        } else if (object instanceof Structure) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.STRUCTURES_NODE, ActiveViewID.structures), new Object[] { object });
        } else if (object instanceof MolecularType) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MOLECULAR_TYPES_NODE, ActiveViewID.structures), new Object[] { object });
        } else if (object instanceof ReactionStep) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.REACTIONS_NODE, ActiveViewID.reactions), new Object[] { object });
        } else if (object instanceof ReactionRule) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.REACTIONS_NODE, ActiveViewID.reactions), new Object[] { object });
        } else if (object instanceof SpeciesContextSpec) {
            SpeciesContextSpec scs = (SpeciesContextSpec) object;
            ActiveView av = new ActiveView(scs.getSimulationContext(), DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.species_settings);
            followHyperlink(av, new Object[] { object });
        } else if (object instanceof ReactionCombo) {
            ReactionCombo rc = (ReactionCombo) object;
            followHyperlink(new ActiveView(rc.getReactionContext().getSimulationContext(), DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.reaction_setting), new Object[] { ((ReactionCombo) object).getReactionSpec() });
        } else if (object instanceof SpeciesContext) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.SPECIES_NODE, ActiveViewID.species), new Object[] { object });
        } else if (object instanceof RbmObservable) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.OBSERVABLES_NODE, ActiveViewID.observables), new Object[] { object });
        } else if (object instanceof MathDescription) {
            // followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MATH_SIMULATIONS_NODE, ActiveViewID.generated_math), new Object[] {object});
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.structure_mapping), new Object[] { object });
        } else if (object instanceof SpeciesPattern) {
            // if (issue.getIssueContext().hasContextType(ContextType.SpeciesContext)){
            // SpeciesContext thing = (SpeciesContext)issue.getIssueContext().getContextObject(ContextType.SpeciesContext);
            // followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.SPECIES_NODE, ActiveViewID.species), new Object[] {thing});
            // }else if(issue.getIssueContext().hasContextType(ContextType.ReactionRule)) {
            // ReactionRule thing = (ReactionRule)issue.getIssueContext().getContextObject(ContextType.ReactionRule);
            // followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.REACTIONS_NODE, ActiveViewID.reactions), new Object[] {thing});
            // }else if(issue.getIssueContext().hasContextType(ContextType.RbmObservable)) {
            // RbmObservable thing = (RbmObservable)issue.getIssueContext().getContextObject(ContextType.RbmObservable);
            // followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.OBSERVABLES_NODE, ActiveViewID.observables), new Object[] {thing});
            // } else {
            System.err.println("SpeciesPattern object missing a proper issue context.");
        // }
        } else if (object instanceof SimulationContext) {
            SimulationContext sc = (SimulationContext) object;
            IssueCategory ic = issue.getCategory();
            switch(ic) {
                case RbmNetworkConstraintsBad:
                    NetworkConstraints nc = sc.getNetworkConstraints();
                    if (issue.getMessage() == SimulationContext.IssueInsufficientMolecules) {
                        NetworkConstraintsEntity nce = new NetworkConstraintsEntity(NetworkConstraintsTableModel.sMaxMoleculesName, NetworkConstraintsTableModel.sValueType, nc.getMaxMoleculesPerSpecies() + "");
                        followHyperlink(new ActiveView(sc, DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.network_setting), new Object[] { nce });
                    } else {
                        NetworkConstraintsEntity nce = new NetworkConstraintsEntity(NetworkConstraintsTableModel.sMaxIterationName, NetworkConstraintsTableModel.sValueType, nc.getMaxIteration() + "");
                        followHyperlink(new ActiveView(sc, DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.network_setting), new Object[] { nce });
                    }
                    break;
                default:
                    followHyperlink(new ActiveView(sc, DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.network_setting), new Object[] { object });
                    break;
            }
        } else if (object instanceof Geometry) {
            if (issueContext.hasContextType(ContextType.SimContext)) {
                SimulationContext simContext = (SimulationContext) issueContext.getContextObject(ContextType.SimContext);
                followHyperlink(new ActiveView(simContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.geometry_definition), new Object[] { object });
            } else if (issueContext.hasContextType(ContextType.MathModel)) {
                followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MATH_GEOMETRY_NODE, ActiveViewID.math_geometry), new Object[] { object });
            } else if (issueContext.hasContextType(ContextType.MathDescription)) {
                followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.geometry_definition), new Object[] { object });
            }
        } else {
            System.err.println("unknown object type in IssuePanel.invokeHyperlink(): " + object.getClass() + ", context type: " + issueContext.getContextType());
        }
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) IssueCategory(org.vcell.util.Issue.IssueCategory) MathDescription(cbit.vcell.math.MathDescription) NetworkConstraintsEntity(org.vcell.model.rbm.common.NetworkConstraintsEntity) SpeciesContext(cbit.vcell.model.SpeciesContext) ActiveView(cbit.vcell.client.desktop.biomodel.SelectionManager.ActiveView) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) StructureMappingNameScope(cbit.vcell.mapping.StructureMapping.StructureMappingNameScope) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) UnmappedGeometryClass(cbit.vcell.mapping.GeometryContext.UnmappedGeometryClass) SimulationOwner(cbit.vcell.solver.SimulationOwner) DecoratedIssueSource(cbit.vcell.client.desktop.DecoratedIssueSource) IssueSource(org.vcell.util.Issue.IssueSource) OutputFunctionIssueSource(cbit.vcell.solver.OutputFunctionContext.OutputFunctionIssueSource) OutputFunctionIssueSource(cbit.vcell.solver.OutputFunctionContext.OutputFunctionIssueSource) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) IssueContext(org.vcell.util.IssueContext) UnmappedGeometryClass(cbit.vcell.mapping.GeometryContext.UnmappedGeometryClass) MicroscopeMeasurement(cbit.vcell.mapping.MicroscopeMeasurement) GeometryContext(cbit.vcell.mapping.GeometryContext) Structure(cbit.vcell.model.Structure) ReactionCombo(cbit.vcell.mapping.ReactionSpec.ReactionCombo) ReactionRule(cbit.vcell.model.ReactionRule) DecoratedIssueSource(cbit.vcell.client.desktop.DecoratedIssueSource) RbmObservable(cbit.vcell.model.RbmObservable) SimulationContextNameScope(cbit.vcell.mapping.SimulationContext.SimulationContextNameScope) SimulationContext(cbit.vcell.mapping.SimulationContext) MolecularType(org.vcell.model.rbm.MolecularType) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) ReactionStep(cbit.vcell.model.ReactionStep) Parameter(cbit.vcell.model.Parameter) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) BioEvent(cbit.vcell.mapping.BioEvent) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 14 with IssueContext

use of org.vcell.util.IssueContext in project vcell by virtualcell.

the class MathOverrides method removeUnusedOverrides.

/**
 * explicit user action invokes this method (currently pressing a button), this is not automatic cleanup of old/obsolete models ... we want the user to address the issues.
 */
public void removeUnusedOverrides() {
    MathDescription mathDescription = getSimulation().getMathDescription();
    // 
    // get list of names of constants in this math
    // 
    Enumeration<Constant> enumeration = mathDescription.getConstants();
    java.util.HashSet<String> mathDescriptionHash = new java.util.HashSet<String>();
    while (enumeration.hasMoreElements()) {
        Constant constant = enumeration.nextElement();
        mathDescriptionHash.add(constant.getName());
    }
    // 
    // for any elements in this MathOverrides but not in the new MathDescription, add an "error" issue
    // 
    ArrayList<String> overridesToDelete = new ArrayList<String>();
    Enumeration<String> mathOverrideNamesEnum = getOverridesHash().keys();
    while (mathOverrideNamesEnum.hasMoreElements()) {
        String name = mathOverrideNamesEnum.nextElement();
        if (!mathDescriptionHash.contains(name)) {
            // constant 'name' no longer part of mathDescription
            overridesToDelete.add(name);
        } else if (getSimulation().getSimulationOwner() != null) {
            IssueContext issueContext = new IssueContext(ContextType.Simulation, getSimulation(), null);
            if (getSimulation().getSimulationOwner().gatherIssueForMathOverride(issueContext, getSimulation(), name) != null) {
                // constant 'name' is part of math, but simulation owner doesn't want you to override it.
                overridesToDelete.add(name);
            }
        }
    }
    for (String deletedName : overridesToDelete) {
        removeConstant(deletedName);
    }
}
Also used : MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) ArrayList(java.util.ArrayList) IssueContext(org.vcell.util.IssueContext)

Example 15 with IssueContext

use of org.vcell.util.IssueContext in project vcell by virtualcell.

the class ModelOptimizationMapping method computeOptimizationSpec.

/**
 * Insert the method's description here.
 * Creation date: (8/22/2005 9:26:52 AM)
 * @return cbit.vcell.opt.OptimizationSpec
 * @param modelOptimizationSpec cbit.vcell.modelopt.ModelOptimizationSpec
 */
MathSymbolMapping computeOptimizationSpec() throws MathException, MappingException {
    if (getModelOptimizationSpec().getReferenceData() == null) {
        System.out.println("no referenced data defined");
        return null;
    }
    OptimizationSpec optSpec = new OptimizationSpec();
    optSpec.setComputeProfileDistributions(modelOptimizationSpec.isComputeProfileDistributions());
    parameterMappings = null;
    // 
    // get original MathDescription (later to be substituted for local/global parameters).
    // 
    SimulationContext simContext = modelOptimizationSpec.getSimulationContext();
    MathMapping mathMapping = simContext.createNewMathMapping();
    MathDescription origMathDesc = null;
    mathSymbolMapping = null;
    try {
        origMathDesc = mathMapping.getMathDescription();
        mathSymbolMapping = mathMapping.getMathSymbolMapping();
    } catch (MatrixException e) {
        e.printStackTrace(System.out);
        throw new MappingException(e.getMessage());
    } catch (ModelException e) {
        e.printStackTrace(System.out);
        throw new MappingException(e.getMessage());
    } catch (ExpressionException e) {
        e.printStackTrace(System.out);
        throw new MathException(e.getMessage());
    }
    // 
    // create objective function (mathDesc and data)
    // 
    ReferenceData referenceData = getRemappedReferenceData(mathMapping);
    if (referenceData == null) {
        throw new RuntimeException("no referenced data defined");
    }
    // 
    // get parameter mappings
    // 
    ParameterMappingSpec[] parameterMappingSpecs = modelOptimizationSpec.getParameterMappingSpecs();
    Vector<ParameterMapping> parameterMappingList = new Vector<ParameterMapping>();
    Variable[] allVars = (Variable[]) BeanUtils.getArray(origMathDesc.getVariables(), Variable.class);
    for (int i = 0; i < parameterMappingSpecs.length; i++) {
        cbit.vcell.model.Parameter modelParameter = parameterMappingSpecs[i].getModelParameter();
        String mathSymbol = null;
        Variable mathVariable = null;
        if (mathSymbolMapping != null) {
            Variable variable = mathSymbolMapping.getVariable(modelParameter);
            if (variable != null) {
                mathSymbol = variable.getName();
            }
            if (mathSymbol != null) {
                mathVariable = origMathDesc.getVariable(mathSymbol);
            }
        }
        if (mathVariable != null) {
            if (parameterMappingSpecs[i].isSelected()) {
                if (parameterMappingSpecs[i].getHigh() < parameterMappingSpecs[i].getLow()) {
                    throw new MathException("The lower bound for Parameter '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is greater than its upper bound.");
                }
                if (parameterMappingSpecs[i].getCurrent() < parameterMappingSpecs[i].getLow()) {
                    throw new MathException("The initial guess of '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is smaller than its lower bound.");
                }
                if (parameterMappingSpecs[i].getCurrent() > parameterMappingSpecs[i].getHigh()) {
                    throw new MathException("The initial guess of '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is greater than its upper bound.");
                }
                if (parameterMappingSpecs[i].getLow() < 0) {
                    throw new MathException("The lower bound for Parameter '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is negative. All lower bounds must not be negative.");
                }
                if (Double.isInfinite(parameterMappingSpecs[i].getLow())) {
                    throw new MathException("The lower bound for Parameter '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is infinity. Lower bounds must not be infinity.");
                }
                if (parameterMappingSpecs[i].getHigh() <= 0) {
                    throw new MathException("The upper bound for Parameter '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is negative. All upper bounds must be positive.");
                }
                if (Double.isInfinite(parameterMappingSpecs[i].getHigh())) {
                    throw new MathException("The upper bound for Parameter '" + parameterMappingSpecs[i].getModelParameter().getName() + "' is infinity. Upper bounds must not be infinity.");
                }
            }
            double low = parameterMappingSpecs[i].isSelected() && parameterMappingSpecs[i].getLow() == 0 ? 1e-8 : parameterMappingSpecs[i].getLow();
            double high = parameterMappingSpecs[i].getHigh();
            double scale = Math.abs(parameterMappingSpecs[i].getCurrent()) < 1.0E-10 ? 1.0 : Math.abs(parameterMappingSpecs[i].getCurrent());
            double current = parameterMappingSpecs[i].getCurrent();
            low = Math.min(low, current);
            high = Math.max(high, current);
            Parameter optParameter = new Parameter(mathSymbol, low, high, scale, current);
            ParameterMapping parameterMapping = new ParameterMapping(modelParameter, optParameter, mathVariable);
            // 
            if (mathVariable instanceof Constant) {
                Constant origConstant = (Constant) mathVariable;
                for (int j = 0; j < allVars.length; j++) {
                    if (allVars[j].equals(origConstant)) {
                        if (parameterMappingSpecs[i].isSelected()) {
                            allVars[j] = new ParameterVariable(origConstant.getName());
                        } else {
                            allVars[j] = new Constant(origConstant.getName(), new Expression(optParameter.getInitialGuess()));
                        }
                        break;
                    }
                }
            }
            // 
            if (parameterMappingSpecs[i].isSelected()) {
                parameterMappingList.add(parameterMapping);
            }
        }
    }
    parameterMappings = (ParameterMapping[]) BeanUtils.getArray(parameterMappingList, ParameterMapping.class);
    try {
        origMathDesc.setAllVariables(allVars);
    } catch (ExpressionBindingException e) {
        e.printStackTrace(System.out);
        throw new MathException(e.getMessage());
    }
    // 
    for (int i = 0; i < parameterMappings.length; i++) {
        optSpec.addParameter(parameterMappings[i].getOptParameter());
    }
    Vector<Issue> issueList = new Vector<Issue>();
    IssueContext issueContext = new IssueContext();
    optSpec.gatherIssues(issueContext, issueList);
    for (int i = 0; i < issueList.size(); i++) {
        Issue issue = issueList.elementAt(i);
        if (issue.getSeverity() == Issue.SEVERITY_ERROR) {
            throw new RuntimeException(issue.getMessage());
        }
    }
    // 
    // 
    // 
    optimizationSpec = optSpec;
    return mathSymbolMapping;
}
Also used : ParameterVariable(cbit.vcell.math.ParameterVariable) Variable(cbit.vcell.math.Variable) Issue(org.vcell.util.Issue) MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) ParameterVariable(cbit.vcell.math.ParameterVariable) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MatrixException(cbit.vcell.matrix.MatrixException) IssueContext(org.vcell.util.IssueContext) OptimizationSpec(cbit.vcell.opt.OptimizationSpec) Vector(java.util.Vector) ModelException(cbit.vcell.model.ModelException) SimulationContext(cbit.vcell.mapping.SimulationContext) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) Expression(cbit.vcell.parser.Expression) MathException(cbit.vcell.math.MathException) MathMapping(cbit.vcell.mapping.MathMapping) Parameter(cbit.vcell.opt.Parameter)

Aggregations

IssueContext (org.vcell.util.IssueContext)17 Issue (org.vcell.util.Issue)14 ArrayList (java.util.ArrayList)9 ReactionRule (cbit.vcell.model.ReactionRule)4 Vector (java.util.Vector)4 MolecularType (org.vcell.model.rbm.MolecularType)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)3 MathDescription (cbit.vcell.math.MathDescription)3 Structure (cbit.vcell.model.Structure)3 Hashtable (java.util.Hashtable)3 SimulationContext (cbit.vcell.mapping.SimulationContext)2 Constant (cbit.vcell.math.Constant)2 Model (cbit.vcell.model.Model)2 RbmObservable (cbit.vcell.model.RbmObservable)2 SpeciesContext (cbit.vcell.model.SpeciesContext)2 OptimizationException (cbit.vcell.opt.OptimizationException)2 OptimizationResultSet (cbit.vcell.opt.OptimizationResultSet)2 Color (java.awt.Color)2 ParameterEstimationTaskSimulatorIDA (org.vcell.optimization.ParameterEstimationTaskSimulatorIDA)2 DecoratedIssueSource (cbit.vcell.client.desktop.DecoratedIssueSource)1