Search in sources :

Example 46 with Structure

use of cbit.vcell.model.Structure in project vcell by virtualcell.

the class BioModel method getVCID.

public VCID getVCID(Identifiable identifiable) {
    String localName;
    String className;
    if (identifiable instanceof SpeciesContext) {
        localName = ((SpeciesContext) identifiable).getName();
        className = "SpeciesContext";
    } else if (identifiable instanceof Species) {
        localName = ((Species) identifiable).getCommonName();
        className = VCID.CLASS_SPECIES;
    } else if (identifiable instanceof Structure) {
        localName = ((Structure) identifiable).getName();
        className = "Structure";
    } else if (identifiable instanceof ReactionStep) {
        localName = ((ReactionStep) identifiable).getName();
        className = VCID.CLASS_REACTION_STEP;
    } else if (identifiable instanceof BioModel) {
        localName = ((BioModel) identifiable).getName();
        className = VCID.CLASS_BIOMODEL;
    // }else if (identifiable instanceof SimulationContext){
    // localName = ((SimulationContext)identifiable).getName();
    // className = "Application";
    } else if (identifiable instanceof BioPaxObject) {
        localName = ((BioPaxObject) identifiable).getID();
        className = "BioPaxObject";
    } else if (identifiable instanceof MolecularType) {
        localName = ((MolecularType) identifiable).getName();
        className = "MolecularType";
    } else if (identifiable instanceof ReactionRule) {
        localName = ((ReactionRule) identifiable).getName();
        className = "ReactionRule";
    } else if (identifiable instanceof RbmObservable) {
        localName = ((RbmObservable) identifiable).getName();
        className = "RbmObservable";
    } else {
        throw new RuntimeException("unsupported Identifiable class");
    }
    localName = TokenMangler.mangleVCId(localName);
    VCID vcid;
    try {
        vcid = VCID.fromString(className + "(" + localName + ")");
    } catch (VCID.InvalidVCIDException e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage());
    }
    return vcid;
}
Also used : VCID(cbit.vcell.biomodel.meta.VCID) ReactionRule(cbit.vcell.model.ReactionRule) BioPaxObject(org.vcell.pathway.BioPaxObject) RbmObservable(cbit.vcell.model.RbmObservable) SpeciesContext(cbit.vcell.model.SpeciesContext) MolecularType(org.vcell.model.rbm.MolecularType) ReactionStep(cbit.vcell.model.ReactionStep) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species)

Example 47 with Structure

use of cbit.vcell.model.Structure in project vcell by virtualcell.

the class SbmlExtensionFilter method askUser.

@Override
public void askUser(ChooseContext c) throws UserCancelException {
    BioModel bioModel = c.chosenContext.getBioModel();
    JFrame currentWindow = c.currentWindow;
    selectedSimWOSBE = null;
    selectedSimContext = c.chosenContext;
    // get user choice of structure and its size and computes absolute sizes of compartments using the StructureSizeSolver.
    Structure[] structures = bioModel.getModel().getStructures();
    // get the nonspatial simulationContexts corresponding to names in applicableAppNameList
    // This is needed in ApplnSelectionAndStructureSizeInputPanel
    String strucName = null;
    double structSize = 1.0;
    int structSelection = -1;
    int option = JOptionPane.CANCEL_OPTION;
    ApplnSelectionAndStructureSizeInputPanel applnStructInputPanel = null;
    while (structSelection < 0) {
        applnStructInputPanel = new ApplnSelectionAndStructureSizeInputPanel();
        applnStructInputPanel.setSimContext(c.chosenContext);
        applnStructInputPanel.setStructures(structures);
        if (applnStructInputPanel.isNeedStructureSizes()) {
            applnStructInputPanel.setPreferredSize(new java.awt.Dimension(350, 400));
            applnStructInputPanel.setMaximumSize(new java.awt.Dimension(350, 400));
            option = DialogUtils.showComponentOKCancelDialog(currentWindow, applnStructInputPanel, "Specify Structure Size to Export:");
            structSelection = applnStructInputPanel.getStructSelectionIndex();
            if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
                break;
            } else if (option == JOptionPane.OK_OPTION && structSelection < 0) {
                DialogUtils.showErrorDialog(currentWindow, "Please select a structure and set its size");
            }
        } else {
            // adapt to legacy logic ...
            structSelection = 0;
            option = JOptionPane.OK_OPTION;
        }
    }
    if (option == JOptionPane.OK_OPTION) {
        applnStructInputPanel.applyStructureNameAndSizeValues();
        strucName = applnStructInputPanel.getSelectedStructureName();
        selectedSimContext = applnStructInputPanel.getSelectedSimContext();
        GeometryContext geoContext = selectedSimContext.getGeometryContext();
        if (!isSpatial) {
            // calculate structure Sizes only if appln is not spatial
            structSize = applnStructInputPanel.getStructureSize();
            // Invoke StructureSizeEvaluator to compute absolute sizes of compartments if all sizes are not set
            if ((geoContext.isAllSizeSpecifiedNull() && geoContext.isAllVolFracAndSurfVolSpecifiedNull()) || ((strucName == null || structSize <= 0.0) && (geoContext.isAllSizeSpecifiedNull() && geoContext.isAllVolFracAndSurfVolSpecified())) || (!geoContext.isAllSizeSpecifiedPositive() && geoContext.isAllVolFracAndSurfVolSpecifiedNull()) || (!geoContext.isAllSizeSpecifiedPositive() && !geoContext.isAllVolFracAndSurfVolSpecified()) || (geoContext.isAllSizeSpecifiedNull() && !geoContext.isAllVolFracAndSurfVolSpecified())) {
                DialogUtils.showErrorDialog(currentWindow, "Cannot export to SBML without compartment sizes being set. This can be automatically " + " computed if the absolute size of at least one compartment and the relative sizes (Surface-to-volume-ratio/Volume-fraction) " + " of all compartments are known. Sufficient information is not available to perform this computation." + "\n\nThis can be fixed by going back to the application '" + selectedSimContext.getName() + "' and setting structure sizes in the 'StructureMapping' tab.");
                throw UserCancelException.CANCEL_XML_TRANSLATION;
            }
            if (!geoContext.isAllSizeSpecifiedPositive() && geoContext.isAllVolFracAndSurfVolSpecified()) {
                Structure chosenStructure = selectedSimContext.getModel().getStructure(strucName);
                StructureMapping chosenStructMapping = selectedSimContext.getGeometryContext().getStructureMapping(chosenStructure);
                try {
                    StructureSizeSolver.updateAbsoluteStructureSizes(selectedSimContext, chosenStructure, structSize, chosenStructMapping.getSizeParameter().getUnitDefinition());
                } catch (Exception e) {
                    throw new ProgrammingException("exception updating sizes", e);
                }
            }
        } else {
            if (!geoContext.isAllUnitSizeParameterSetForSpatial()) {
                DialogUtils.showErrorDialog(currentWindow, "Cannot export to SBML without compartment size ratios being set." + "\n\nThis can be fixed by going back to the application '" + selectedSimContext.getName() + "' and setting structure" + " size ratios in the 'StructureMapping' tab.");
                throw UserCancelException.CANCEL_XML_TRANSLATION;
            }
        }
        // Select simulation whose overrides need to be exported
        // If simContext doesn't have simulations, don't pop up simulationSelectionPanel
        Simulation[] sims = bioModel.getSimulations(selectedSimContext);
        // display only those simulations that have overrides in the simulationSelectionPanel.
        Vector<Simulation> orSims = new Vector<Simulation>();
        for (int s = 0; (sims != null) && (s < sims.length); s++) {
            if (sims[s].getMathOverrides().hasOverrides()) {
                orSims.addElement(sims[s]);
            }
        }
        Simulation[] overriddenSims = orSims.toArray(new Simulation[orSims.size()]);
        if (overriddenSims.length > 0) {
            SimulationSelectionPanel simSelectionPanel = new SimulationSelectionPanel();
            simSelectionPanel.setPreferredSize(new java.awt.Dimension(600, 400));
            simSelectionPanel.setMaximumSize(new java.awt.Dimension(600, 400));
            simSelectionPanel.setSimulations(overriddenSims);
            int simOption = DialogUtils.showComponentOKCancelDialog(currentWindow, simSelectionPanel, "Select Simulation whose overrides should be exported:");
            if (simOption == JOptionPane.OK_OPTION) {
                selectedSimWOSBE = simSelectionPanel.getSelectedSimulation();
            // if (chosenSimulation != null) {
            // CARRY						hashTable.put("selectedSimulation", chosenSimulation);
            // }
            } else if (simOption == JOptionPane.CANCEL_OPTION || simOption == JOptionPane.CLOSED_OPTION) {
                // Hence canceling the entire export to SBML operation.
                throw UserCancelException.CANCEL_XML_TRANSLATION;
            }
        }
    } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
        // Hence canceling the entire export to SBML operation.
        throw UserCancelException.CANCEL_XML_TRANSLATION;
    }
    if (selectedSimWOSBE != null) {
        String selectedFileName = c.filename;
        // rename file to contain exported simulation.
        String ext = FilenameUtils.getExtension(selectedFileName);
        String base = FilenameUtils.getBaseName(selectedFileName);
        String path = FilenameUtils.getPath(selectedFileName);
        base += "_" + TokenMangler.mangleToSName(selectedSimWOSBE.getName());
        selectedFileName = path + base + ext;
        c.selectedFile.renameTo(new File(selectedFileName));
    }
}
Also used : SimulationSelectionPanel(org.vcell.sbml.gui.SimulationSelectionPanel) StructureMapping(cbit.vcell.mapping.StructureMapping) ProgrammingException(org.vcell.util.ProgrammingException) UserCancelException(org.vcell.util.UserCancelException) Simulation(cbit.vcell.solver.Simulation) JFrame(javax.swing.JFrame) ApplnSelectionAndStructureSizeInputPanel(org.vcell.sbml.gui.ApplnSelectionAndStructureSizeInputPanel) BioModel(cbit.vcell.biomodel.BioModel) GeometryContext(cbit.vcell.mapping.GeometryContext) ProgrammingException(org.vcell.util.ProgrammingException) Structure(cbit.vcell.model.Structure) Vector(java.util.Vector) File(java.io.File)

Example 48 with Structure

use of cbit.vcell.model.Structure in project vcell by virtualcell.

the class GraphContainerLayoutReactions method getPreferedSizeReactionContainerShape.

public Dimension getPreferedSizeReactionContainerShape(ReactionContainerShape shape, Graphics2D g) {
    // get size when empty
    Font origFont = g.getFont();
    g.setFont(shape.getLabelFont(g));
    try {
        Dimension preferredSize = shape.getPreferedSizeSelf(g);
        // make larger than empty size so that children fit
        for (Shape child : shape.getChildren()) {
            if (child instanceof ReactionStepShape || child instanceof SpeciesContextShape || child instanceof RuleParticipantSignatureFullDiagramShape || child instanceof RuleParticipantSignatureShortDiagramShape || child instanceof ReactionRuleDiagramShape) {
                preferredSize.width = Math.max(preferredSize.width, child.getSpaceManager().getRelPos().x + child.getSpaceManager().getSize().width);
                preferredSize.height = Math.max(preferredSize.height, child.getSpaceManager().getRelPos().y + child.getSpaceManager().getSize().height);
            }
        }
        preferredSize.width = preferredSize.width + WIDTH_PADDING;
        preferredSize.height = preferredSize.height + HEIGHT_PADDING;
        Structure structure = shape.getStructure();
        int minWidthSum = 0;
        for (Structure structure2 : shape.getStructureSuite().getStructures()) {
            if (structure2 instanceof Feature) {
                minWidthSum += FEATURE_MIN_WIDTH;
            } else {
                minWidthSum += MEMBRANE_MIN_WIDTH;
            }
        }
        int compartmentMinWidth = 0;
        if (structure instanceof Feature) {
            compartmentMinWidth = FEATURE_MIN_WIDTH;
        } else {
            compartmentMinWidth = MEMBRANE_MIN_WIDTH;
        }
        int apportionedWidth = compartmentMinWidth * TOTAL_MIN_WIDTH / minWidthSum;
        if (preferredSize.width < compartmentMinWidth) {
            preferredSize.width = compartmentMinWidth;
        }
        if (preferredSize.width < apportionedWidth) {
            preferredSize.width = apportionedWidth;
        }
        if (preferredSize.height < MIN_HEIGHT) {
            preferredSize.height = MIN_HEIGHT;
        }
        return preferredSize;
    } finally {
        g.setFont(origFont);
    }
}
Also used : RuleParticipantSignatureShortDiagramShape(cbit.vcell.graph.RuleParticipantSignatureShortDiagramShape) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) RuleParticipantSignatureFullDiagramShape(cbit.vcell.graph.RuleParticipantSignatureFullDiagramShape) RuleParticipantSignatureShortDiagramShape(cbit.vcell.graph.RuleParticipantSignatureShortDiagramShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) ReactionRuleFullDiagramShape(cbit.vcell.graph.ReactionRuleFullDiagramShape) ContainerContainerShape(cbit.vcell.graph.ContainerContainerShape) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) RuleParticipantSignatureFullDiagramShape(cbit.vcell.graph.RuleParticipantSignatureFullDiagramShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) Dimension(java.awt.Dimension) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature) Font(java.awt.Font) Point(java.awt.Point)

Example 49 with Structure

use of cbit.vcell.model.Structure in project vcell by virtualcell.

the class MolecularTypeLargeShape method getAnchorsHTML.

// ----------------------------------------------------------------------------------------
public String getAnchorsHTML() {
    String str = "";
    if (mt != null && !mt.isAnchorAll() && mt.getAnchors().size() > 0) {
        str += "<html>";
        boolean first = true;
        for (Structure s : mt.getAnchors()) {
            if (!first) {
                str += "<br>";
            }
            first = false;
            str += s.getName();
        }
        str += "</html>";
    }
    return str;
}
Also used : Structure(cbit.vcell.model.Structure)

Example 50 with Structure

use of cbit.vcell.model.Structure in project vcell by virtualcell.

the class MolecularTypeLargeShape method paintNarrowCompartmentRight.

public void paintNarrowCompartmentRight(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Color colorOld = g2.getColor();
    Paint paintOld = g2.getPaint();
    int z = shapePanel.getZoomFactor();
    Rectangle r = getAnchorRectangleRight();
    Rectangle2D border = new Rectangle2D.Double(r.x, r.y, r.width, r.height);
    // a bit darker for border
    Color darker = getDefaultColor(Color.gray);
    g2.setColor(darker);
    g2.draw(border);
    Color lighter;
    if (owner instanceof MolecularType) {
        if (mt.getAnchors().size() == 0) {
            lighter = MolecularComponentLargeShape.componentBad;
        } else {
            // molecules may be anchored to multiple structures,
            // so we leave it white since it may be a mix of membranes and compartments
            lighter = Color.white;
        }
    } else {
        // non molecular type, we make sure before calling this that structure is not null
        boolean found = false;
        for (Structure struct : mt.getAnchors()) {
            if (structure.getName().equals(struct.getName())) {
                found = true;
                break;
            }
        }
        if (!found) {
            // molecule can't be in the structure where the species pattern is
            lighter = MolecularComponentLargeShape.componentBad;
        } else {
            if (structure.getTypeName().equals(Structure.TYPE_NAME_MEMBRANE)) {
                // 192	208
                lighter = new Color(192, 192, 192);
            } else {
                // 244
                lighter = new Color(240, 240, 240);
            }
        }
    }
    Rectangle2D filling = new Rectangle2D.Double(r.x, r.y + 1, r.width, r.height - 1);
    g2.setPaint(lighter);
    g2.fill(filling);
    g2.setPaint(paintOld);
    g2.setColor(colorOld);
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) Color(java.awt.Color) Rectangle(java.awt.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Structure(cbit.vcell.model.Structure) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Aggregations

Structure (cbit.vcell.model.Structure)159 SpeciesContext (cbit.vcell.model.SpeciesContext)57 Membrane (cbit.vcell.model.Membrane)47 PropertyVetoException (java.beans.PropertyVetoException)42 Feature (cbit.vcell.model.Feature)36 Model (cbit.vcell.model.Model)35 ArrayList (java.util.ArrayList)35 ReactionStep (cbit.vcell.model.ReactionStep)33 Expression (cbit.vcell.parser.Expression)33 ReactionRule (cbit.vcell.model.ReactionRule)27 ExpressionException (cbit.vcell.parser.ExpressionException)27 BioModel (cbit.vcell.biomodel.BioModel)23 StructureMapping (cbit.vcell.mapping.StructureMapping)22 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)22 Species (cbit.vcell.model.Species)21 MolecularType (org.vcell.model.rbm.MolecularType)20 ReactionParticipant (cbit.vcell.model.ReactionParticipant)19 SimpleReaction (cbit.vcell.model.SimpleReaction)19 SimulationContext (cbit.vcell.mapping.SimulationContext)18 ModelException (cbit.vcell.model.ModelException)18