Search in sources :

Example 41 with MolecularType

use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.

the class BioModelEditorModelPanel method deleteButtonPressed.

private void deleteButtonPressed() {
    try {
        ArrayList<Object> deleteList = new ArrayList<Object>();
        int selectedIndex = tabbedPane.getSelectedIndex();
        if (selectedIndex == ModelPanelTabID.reaction_diagram.ordinal()) {
            deleteList.addAll(Arrays.asList(reactionCartoonEditorPanel.getReactionCartoon().getSelectedObjects()));
        // } else if (selectedIndex == ModelPanelTabID.structure_diagram.ordinal()) {
        // deleteList.addAll(Arrays.asList(cartoonEditorPanel.getStructureCartoon().getSelectedObjects()));
        } else {
            computeCurrentSelectedTable();
            int[] rows = currentSelectedTable.getSelectedRows();
            if (rows == null || rows.length == 0) {
                return;
            }
            if (currentSelectedTable == speciesTable) {
                for (int r : rows) {
                    if (r < speciesTableModel.getRowCount()) {
                        SpeciesContext speciesContext = speciesTableModel.getValueAt(r);
                        if (speciesContext != null) {
                            deleteList.add(speciesContext);
                        }
                    }
                }
            } else if (currentSelectedTable == molecularTypeTable) {
                // TODO: delete stuff
                for (int r : rows) {
                    if (r < molecularTypeTableModel.getRowCount()) {
                        MolecularType mt = molecularTypeTableModel.getValueAt(r);
                        if (mt != null) {
                            deleteList.add(mt);
                        }
                    }
                }
            } else if (currentSelectedTable == observablesTable) {
                for (int r : rows) {
                    if (r < observableTableModel.getRowCount()) {
                        RbmObservable o = observableTableModel.getValueAt(r);
                        if (o != null) {
                            deleteList.add(o);
                        }
                    }
                }
            } else if (currentSelectedTable == structuresTable) {
                for (int r : rows) {
                    if (r < structureTableModel.getRowCount()) {
                        Structure rowValue = structureTableModel.getValueAt(r);
                        if (rowValue instanceof Feature || rowValue instanceof Membrane) {
                            deleteList.add(rowValue);
                        }
                    }
                }
            } else if (currentSelectedTable == reactionsTable) {
                for (int r : rows) {
                    if (r < reactionTableModel.getRowCount()) {
                        ModelProcess reaction = reactionTableModel.getValueAt(r);
                        if (reaction != null) {
                            deleteList.add(reaction);
                        }
                    }
                }
            }
        }
        if (deleteList.size() == 0) {
            return;
        }
        StringBuilder deleteListText = new StringBuilder();
        for (Object object : deleteList) {
            if (object instanceof SpeciesContext) {
                deleteListText.append("Species\t'" + ((SpeciesContext) object).getName() + "'\n");
            } else if (object instanceof MolecularType) {
                deleteListText.append(((MolecularType) object).getDisplayType() + "\t'" + ((MolecularType) object).getDisplayName() + "'\n");
            } else if (object instanceof RbmObservable) {
                deleteListText.append("Observable\t'" + ((RbmObservable) object).getName() + "'\n");
            } else if (object instanceof ReactionStep) {
                deleteListText.append("Reaction\t'" + ((ReactionStep) object).getName() + "'\n");
            } else if (object instanceof ReactionRule) {
                deleteListText.append("Reaction rule\t'" + ((ReactionRule) object).getName() + "'\n");
            } else if (object instanceof Structure) {
                deleteListText.append("Structure\t'" + ((Structure) object).getName() + "'\n");
            }
        }
        // TODO: once we display reaction rules in the carton editor panel we'll have to change the way we delete reaction rules
        if (deleteList.get(0) instanceof SpeciesContext || deleteList.get(0) instanceof ReactionStep) {
            try {
                ArrayList<SpeciesContext> speciesContextArrList = new ArrayList<SpeciesContext>();
                ArrayList<ReactionStep> reactionStepArrList = new ArrayList<ReactionStep>();
                for (Object obj : deleteList) {
                    if (obj instanceof SpeciesContext) {
                        speciesContextArrList.add((SpeciesContext) obj);
                    } else if (obj instanceof ReactionStep) {
                        reactionStepArrList.add((ReactionStep) obj);
                    } else {
                        throw new Exception("Unexpected delete object " + obj.getClass().getName());
                    }
                }
                ReactionCartoonTool.deleteReactionsAndSpecies(reactionCartoonEditorPanel, reactionStepArrList.toArray(new ReactionStep[0]), speciesContextArrList.toArray(new SpeciesContext[0]));
            } catch (UserCancelException uce) {
                return;
            }
            return;
        } else {
            String confirm = DialogUtils.showOKCancelWarningDialog(this, "Deleting", "You are going to delete the following:\n\n" + deleteListText + "\n Continue?");
            if (confirm.equals(UserMessage.OPTION_CANCEL)) {
                return;
            }
            for (Object object : deleteList) {
                if (object instanceof ReactionRule) {
                    ReactionRule rr = (ReactionRule) object;
                    bioModel.getModel().getRbmModelContainer().removeReactionRule(rr);
                } else if (object instanceof MolecularType) {
                    Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
                    MolecularType mt = (MolecularType) object;
                    if (!bioModel.getModel().getRbmModelContainer().isDeleteAllowed(mt, usedHere)) {
                        String errMsg = mt.getDisplayType() + " <b>'" + mt + "'</b> cannot be deleted because it's already being used by:<br>";
                        final int MaxListSize = 7;
                        int count = 0;
                        for (String key : usedHere.keySet()) {
                            System.out.println(key);
                            if (count >= MaxListSize) {
                                errMsg += "<br> ... and more.";
                                break;
                            }
                            Pair<Displayable, SpeciesPattern> o = usedHere.get(key);
                            Displayable e = o.one;
                            SpeciesPattern sp = o.two;
                            errMsg += "<br> - " + e.getDisplayType().toLowerCase() + " <b>" + e.getDisplayName() + "</b>";
                            errMsg += ", " + sp.getDisplayType().toLowerCase() + " " + " <b>" + sp.getDisplayName() + "</b>";
                            count++;
                        }
                        errMsg = "<html>" + errMsg + "</html>";
                        throw new RuntimeException(errMsg);
                    }
                    bioModel.getModel().getRbmModelContainer().removeMolecularType(mt);
                } else if (object instanceof RbmObservable) {
                    RbmObservable o = (RbmObservable) object;
                    bioModel.getModel().getRbmModelContainer().removeObservable(o);
                } else {
                    bioModel.getModel().removeObject(object);
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        DialogUtils.showErrorDialog(this, ex.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) UserCancelException(org.vcell.util.UserCancelException) SpeciesContext(cbit.vcell.model.SpeciesContext) Feature(cbit.vcell.model.Feature) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) Pair(org.vcell.util.Pair) Displayable(org.vcell.util.Displayable) ReactionRule(cbit.vcell.model.ReactionRule) RbmObservable(cbit.vcell.model.RbmObservable) ModelProcess(cbit.vcell.model.ModelProcess) PropertyVetoException(java.beans.PropertyVetoException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) UserCancelException(org.vcell.util.UserCancelException) MolecularType(org.vcell.model.rbm.MolecularType) ReactionStep(cbit.vcell.model.ReactionStep) RelationshipObject(org.vcell.relationship.RelationshipObject) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject) BioPaxObject(org.vcell.pathway.BioPaxObject) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 42 with MolecularType

use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.

the class SpeciesPropertiesTreeModel method createMolecularTypePatternNode.

private BioModelNode createMolecularTypePatternNode(MolecularTypePattern molecularTypePattern) {
    MolecularType molecularType = molecularTypePattern.getMolecularType();
    BioModelNode node = new BioModelNode(molecularTypePattern, true);
    for (MolecularComponent mc : molecularType.getComponentList()) {
        // Attention: we show all components even though the combination State Any + Bond Possible should be "invisible"
        // uncomment the "if" to hide the Any + Possible combination
        // if (bShowDetails || molecularTypePattern.getMolecularComponentPattern(mc).isbVisible()) {
        BioModelNode n = createMolecularComponentPatternNode(molecularTypePattern.getMolecularComponentPattern(mc));
        if (n != null) {
            node.add(n);
        // }
        }
    }
    return node;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) MolecularComponent(org.vcell.model.rbm.MolecularComponent) BioModelNode(cbit.vcell.desktop.BioModelNode)

Example 43 with MolecularType

use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.

the class ReactionCartoonTool method menuAction.

@Override
protected void menuAction(Shape shape, String menuAction) {
    if (shape == null) {
        return;
    }
    if (menuAction.equals(CartoonToolMiscActions.Properties.MENU_ACTION)) {
        if (shape instanceof FluxReactionShape) {
        // showFluxReactionPropertiesDialog((FluxReactionShape) shape);
        } else if (shape instanceof SimpleReactionShape) {
        // showSimpleReactionPropertiesDialog((SimpleReactionShape) shape);
        } else if (shape instanceof ReactantShape) {
        // Point locationOnScreen = shape.getSpaceManager().getAbsLoc();
        // Point graphPaneLocation = getGraphPane().getLocationOnScreen();
        // locationOnScreen.translate(graphPaneLocation.x,
        // graphPaneLocation.y);
        // showReactantPropertiesDialog((ReactantShape) shape,
        // locationOnScreen);
        } else if (shape instanceof ProductShape) {
        // Point locationOnScreen = shape.getSpaceManager().getAbsLoc();
        // Point graphPaneLocation = getGraphPane().getLocationOnScreen();
        // locationOnScreen.translate(graphPaneLocation.x,
        // graphPaneLocation.y);
        // showProductPropertiesDialog((ProductShape) shape,
        // locationOnScreen);
        } else if (shape instanceof SpeciesContextShape) {
        // showEditSpeciesDialog(getGraphPane(), getReactionCartoon()
        // .getModel(), ((SpeciesContextShape) shape)
        // .getSpeciesContext());
        } else if (shape instanceof ReactionContainerShape) {
        // ReactionContainerShape rcs = (ReactionContainerShape) shape;
        // if (rcs.getStructure() instanceof Feature) {
        // //
        // // showFeaturePropertyDialog is invoked in two modes:
        // //
        // // 1) parent!=null and child==null
        // // upon ok, it adds a new feature to the supplied parent.
        // //
        // // 2) parent==null and child!=null
        // // upon ok, edits the feature name
        // //
        // showFeaturePropertiesDialog(getGraphPane(),
        // (getReactionCartoon().getModel() == null ? null
        // : getReactionCartoon().getModel()), null,
        // (Feature) rcs.getStructure());
        // } else if (rcs.getStructure() instanceof Membrane) {
        // showMembranePropertiesDialog(getGraphPane(), (Membrane) rcs
        // .getStructure());
        // }
        }
    } else if (menuAction.equals(CartoonToolMiscActions.AddSpecies.MENU_ACTION)) {
        if (shape instanceof ReactionContainerShape) {
            getGraphModel().deselectShape(shape);
            // showCreateSpeciesContextDialog(getGraphPane(),
            // getReactionCartoon().getModel(),
            // ((ReactionContainerShape) shape).getStructure(), null);
            SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(((ReactionContainerShape) shape).getStructure());
            getGraphModel().select(speciesContext);
        }
    } else if (menuAction.equals(CartoonToolEditActions.Copy.MENU_ACTION)) {
        if (shape instanceof SpeciesContextShape || shape instanceof ReactionStepShape || // rule participants whose rule is not selected won't
        shape instanceof RuleParticipantSignatureDiagramShape || // be copied since standalone they are meaningless
        shape instanceof ReactionRuleDiagramShape) {
            SpeciesContext[] spArray = getSelectedSpeciesContextArray();
            ReactionStep[] rsArray = getSelectedReactionStepArray();
            ReactionRule[] rrArray = getSelectedReactionRuleArray();
            MolecularType[] mtArray = getSelectedMolecularTypeArray(rrArray, rsArray, spArray);
            Structure[] structArray = getSelectedStructuresArray(rrArray, rsArray, spArray, mtArray);
            Structure fromStruct = null;
            ReactionContainerShape rcs = null;
            Shape parentShape = shape.getParent();
            if (parentShape instanceof ReactionContainerShape) {
                rcs = (ReactionContainerShape) parentShape;
                fromStruct = rcs.getStructure();
            }
            ReactionSpeciesCopy reactionSpeciesCopy = new ReactionSpeciesCopy(spArray, rsArray, rrArray, mtArray, fromStruct, structArray);
            VCellTransferable.sendToClipboard(reactionSpeciesCopy);
        }
    } else if (/*menuAction.equals(CartoonToolEditActions.Paste.MENU_ACTION)
				|| */
    menuAction.equals(CartoonToolEditActions.PasteNew.MENU_ACTION)) {
        if (shape instanceof ReactionContainerShape) {
            pasteReactionsAndSpecies(((ReactionContainerShape) shape).getStructure());
        }
    } else if (menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
        try {
            if (getGraphModel().getSelectedShape() instanceof ReactionContainerShape && menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
                getModel().removeStructure(((ReactionContainerShape) getGraphModel().getSelectedShape()).getStructure());
                return;
            }
            if (getSelectedReactionStepArray() != null || getSelectedSpeciesContextArray() != null) {
                deleteReactionsAndSpecies(getGraphPane(), getSelectedReactionStepArray(), getSelectedSpeciesContextArray());
            }
            if (getSelectedReactionParticipantArray() != null && menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
                ReactionParticipant[] reactionParticipantArr = getSelectedReactionParticipantArray();
                String response = DialogUtils.showWarningDialog(getGraphPane(), "Delete " + reactionParticipantArr.length + " Reaction Stoichiometries", new String[] { RXSPECIES_DELETE, RXSPECIES_CANCEL }, RXSPECIES_CANCEL);
                if (response != null && response.equals(RXSPECIES_DELETE)) {
                    for (int i = 0; i < reactionParticipantArr.length; i++) {
                        ReactionStep reactionStep = reactionParticipantArr[i].getReactionStep();
                        reactionStep.removeReactionParticipant(reactionParticipantArr[i]);
                    }
                }
            }
        } catch (UserCancelException uce) {
            return;
        } catch (PropertyVetoException e) {
            DialogUtils.showErrorDialog(getGraphPane(), e.getMessage());
        } catch (Exception e) {
            DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
        }
    } else if (menuAction.equals(CartoonToolMiscActions.SearchReactions.MENU_ACTION)) {
        try {
            if (shape instanceof ReactionContainerShape) {
                showReactionBrowserDialog(((ReactionContainerShape) shape).getStructure(), null);
            }
        } catch (Exception e) {
            DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
        }
    } else if (menuAction.equals(CartoonToolSaveAsImageActions.MenuAction.MENU_ACTION)) {
        try {
            String resType = null;
            if (shape instanceof ReactionContainerShape) {
                showSaveReactionImageDialog();
            }
        } catch (Exception e) {
            e.printStackTrace();
            DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
        }
    } else if (menuAction.equals(CartoonToolMiscActions.Annotate.MENU_ACTION)) {
        if (shape instanceof ReactionStepShape) {
            // MIRIAMHelper.showMIRIAMAnnotationDialog(((SimpleReactionShape)shape).getReactionStep());
            // System.out.println("Menu action annotate activated...");
            ReactionStep rs = ((ReactionStepShape) shape).getReactionStep();
            VCMetaData vcMetaData = rs.getModel().getVcMetaData();
            try {
                String newAnnotation = DialogUtils.showAnnotationDialog(getGraphPane(), vcMetaData.getFreeTextAnnotation(rs));
                vcMetaData.setFreeTextAnnotation(rs, newAnnotation);
            } catch (UtilCancelException e) {
            // Do Nothing
            } catch (Throwable exc) {
                exc.printStackTrace(System.out);
                DialogUtils.showErrorDialog(getGraphPane(), "Failed to edit annotation!\n" + exc.getMessage(), exc);
            }
        }
    } else {
    // default action is to ignore
    }
}
Also used : ReactionSpeciesCopy(cbit.vcell.model.ReactionSpeciesCopy) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) ProductShape(cbit.vcell.graph.ProductShape) ContainerShape(cbit.gui.graph.ContainerShape) CatalystShape(cbit.vcell.graph.CatalystShape) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ContainerContainerShape(cbit.vcell.graph.ContainerContainerShape) ReactantShape(cbit.vcell.graph.ReactantShape) ElipseShape(cbit.gui.graph.ElipseShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) Shape(cbit.gui.graph.Shape) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) RubberBandEdgeShape(cbit.gui.graph.RubberBandEdgeShape) ReactionParticipantShape(cbit.vcell.graph.ReactionParticipantShape) ProductShape(cbit.vcell.graph.ProductShape) UserCancelException(org.vcell.util.UserCancelException) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) ReactantShape(cbit.vcell.graph.ReactantShape) SpeciesContext(cbit.vcell.model.SpeciesContext) VCMetaData(cbit.vcell.biomodel.meta.VCMetaData) Structure(cbit.vcell.model.Structure) UtilCancelException(org.vcell.util.UtilCancelException) ReactionRule(cbit.vcell.model.ReactionRule) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) MolecularType(org.vcell.model.rbm.MolecularType) PropertyVetoException(java.beans.PropertyVetoException) ReactionStep(cbit.vcell.model.ReactionStep) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 44 with MolecularType

use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.

the class BioCartoonTool method pasteReactionsAndRules.

public static final void pasteReactionsAndRules(Component requester, ReactionSpeciesCopy rsCopy, Model pasteModel, Structure structTo, RXPasteInterface rxPasteInterface) {
    PasteHelper[] pasteHelper = new PasteHelper[1];
    AsynchClientTask issueTask = new AsynchClientTask("Checking Issues...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Model clonedModel = (Model) org.vcell.util.BeanUtils.cloneSerializable(pasteModel);
            clonedModel.refreshDependencies();
            // Model clonedModel = pasteModel;
            IssueContext issueContext = new IssueContext(ContextType.Model, clonedModel, null);
            Vector<Issue> issues = new Vector<>();
            checkStructuresCompatibility(rsCopy, clonedModel, structTo, issues, issueContext);
            Set<MolecularType> mtFromListStrict = getMoleculesFromStrict(rsCopy, clonedModel, issues, issueContext);
            if (issues.size() != 0) {
                // at this point we can only have fatal error issues or no issues at all
                if (!printIssues(issues, requester)) {
                    throw UserCancelException.CANCEL_GENERIC;
                }
            }
            // map all the structures of the reactions, rules and their participants to existing structures, at need make new structures
            // key is the "from" structure, value is the name of the equivalent "to" structure
            // on the first position we have the struct from where we copy (key) and the struct where we paste (value)
            Map<Structure, String> structuresMap;
            if (rsCopy.getStructuresArr().length > 1) {
                // throws CANCEL_GENERIC if the user cancels
                structuresMap = mapStructures(requester, rsCopy, clonedModel, structTo, issueContext);
            } else {
                // if length == 1 it's just structFrom which automatically maps to structTo
                structuresMap = new LinkedHashMap<>();
                structuresMap.put(rsCopy.getFromStructure(), structTo.getName());
            }
            pasteMolecules(mtFromListStrict, clonedModel, structuresMap);
            List<ReactionRule> rulesTo = pasteRules(rsCopy, clonedModel, structTo, issues, issueContext, structuresMap);
            // for(ReactionRule rr : rulesTo) {
            // clonedModel.getRbmModelContainer().addReactionRule(rr);
            // }
            clonedModel.getRbmModelContainer().addReactionRules(rulesTo);
            // TODO: make any final verifications in the cloned model here
            // if anything is wrong exit here with some helpful message
            // .....
            // otherwise go directly to populating the real model
            mapStructures(structuresMap, pasteModel);
            pasteMolecules(mtFromListStrict, pasteModel, structuresMap);
            // we repeat all the steps to paste the rules in the real model instead of the clone
            rulesTo = pasteRules(rsCopy, pasteModel, structTo, issues, issueContext, structuresMap);
            // for(ReactionRule rr : rulesTo) {
            // pasteModel.getRbmModelContainer().addReactionRule(rr);
            // }
            pasteModel.getRbmModelContainer().addReactionRules(rulesTo);
            System.out.println("done");
        }
    };
    AsynchClientTask pasteRXTask = new AsynchClientTask("Pasting Reaction...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            IssueContext issueContext = new IssueContext(ContextType.Model, pasteModel, null);
        // if (pasteHelper[0].issues.size() != 0) {
        // printIssues(pasteHelper[0].issues, requester);
        // }
        // if(rxPasteInterface != null){
        // for(BioModelEntityObject newBioModelEntityObject:pasteHelper[0].reactionsAndSpeciesContexts.keySet()) {
        // ReactionCartoonTool.copyRelativePosition(rxPasteInterface.getGraphPane().getGraphModel(), pasteHelper[0].reactionsAndSpeciesContexts.get(newBioModelEntityObject), newBioModelEntityObject);
        // }
        // ReactionCartoonTool.selectAndSaveDiagram(rxPasteInterface, new ArrayList<BioModelEntityObject>(pasteHelper[0].reactionsAndSpeciesContexts.keySet()));
        // //					//Setup to allow dispatcher to set focus on a specified component after it closes the ProgressPopup
        // setFinalWindow(hashTable, rxPasteInterface.getGraphPane());
        // }
        }
    };
    ClientTaskDispatcher.dispatch(requester, new Hashtable<>(), new AsynchClientTask[] { issueTask, pasteRXTask }, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Issue(org.vcell.util.Issue) ReactionRule(cbit.vcell.model.ReactionRule) Hashtable(java.util.Hashtable) MolecularType(org.vcell.model.rbm.MolecularType) Model(cbit.vcell.model.Model) IssueContext(org.vcell.util.IssueContext) Structure(cbit.vcell.model.Structure) Vector(java.util.Vector)

Example 45 with MolecularType

use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.

the class BioCartoonTool method getMoleculesFromStrict.

// returns a list with the "from" molecules we need to add to the modelTo
// it's a "strict" list, where we have eliminated any conflicting molecules and the ones already present
private static Set<MolecularType> getMoleculesFromStrict(ReactionSpeciesCopy rsCopy, Model modelTo, Vector<Issue> issueVector, IssueContext issueContext) {
    // molecular types
    Set<MolecularType> mtFromListStrict = new HashSet<>();
    Set<MolecularType> mtConflictList = new HashSet<>();
    Set<MolecularType> mtAlreadyList = new HashSet<>();
    RbmModelContainer rbmmcTo = modelTo.getRbmModelContainer();
    if (rsCopy.getMolecularTypeArr() != null) {
        for (MolecularType mtFrom : rsCopy.getMolecularTypeArr()) {
            // the molecules we try to paste here
            MolecularType mtTo = rbmmcTo.getMolecularType(mtFrom.getName());
            if (mtTo == null) {
                // mtTo = new MolecularType(mtFrom, modelTo);
                mtFromListStrict.add(mtFrom);
            } else {
                if (!mtTo.compareEqual(mtFrom)) {
                    // conflict: a different mt with the same name already exists
                    String msg = "Molecule " + RbmUtils.toBnglString(mtFrom, null, CompartmentMode.hide);
                    msg += " to be pasted conflicts with an existing molecule " + RbmUtils.toBnglString(mtTo, null, CompartmentMode.hide) + ".";
                    Issue issue = new Issue(mtFrom, issueContext, IssueCategory.CopyPaste, msg, Issue.Severity.ERROR);
                    issueVector.add(issue);
                    mtConflictList.add(mtFrom);
                } else {
                    mtAlreadyList.add(mtFrom);
                }
            }
        }
        if (!mtConflictList.isEmpty()) {
            System.out.println("Found " + mtConflictList.size() + " conflicting molecule(s).");
        }
        if (!mtAlreadyList.isEmpty()) {
            System.out.println("Found " + mtAlreadyList.size() + " molecule(s) already there.");
        }
    }
    return mtFromListStrict;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) Issue(org.vcell.util.Issue) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) HashSet(java.util.HashSet)

Aggregations

MolecularType (org.vcell.model.rbm.MolecularType)78 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)25 MolecularComponent (org.vcell.model.rbm.MolecularComponent)23 Structure (cbit.vcell.model.Structure)20 ArrayList (java.util.ArrayList)20 ReactionRule (cbit.vcell.model.ReactionRule)19 SpeciesContext (cbit.vcell.model.SpeciesContext)19 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)16 PropertyVetoException (java.beans.PropertyVetoException)15 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)15 RbmObservable (cbit.vcell.model.RbmObservable)14 List (java.util.List)13 RbmModelContainer (cbit.vcell.model.Model.RbmModelContainer)12 Point (java.awt.Point)12 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)12 BioPaxObject (org.vcell.pathway.BioPaxObject)11 RelationshipObject (org.vcell.relationship.RelationshipObject)11 BioModelNode (cbit.vcell.desktop.BioModelNode)10 ModelException (cbit.vcell.model.ModelException)10 ParticleMolecularType (cbit.vcell.math.ParticleMolecularType)9