Search in sources :

Example 36 with Membrane

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

the class ReactionPropertiesPanel method initKineticChoices.

private void initKineticChoices() {
    KineticsDescription[] kineticTypes = reactionStep == null || reactionStep instanceof SimpleReaction ? Simple_Reaction_Kinetic_Types : Flux_Reaction_KineticTypes;
    javax.swing.DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (int i = 0; i < kineticTypes.length; i++) {
        if (!(kineticTypes[i].equals(KineticsDescription.Macroscopic_irreversible) || kineticTypes[i].equals(KineticsDescription.Microscopic_irreversible))) {
            model.addElement(kineticTypes[i]);
        } else // macroscopic/microscopic irreversible
        {
            // reactions on membrane in a 3D geometry
            if (reactionStep != null && reactionStep.getStructure() != null && reactionStep.getStructure() instanceof Membrane) {
                // check if reactants are all on membrane and calculate sum of reactants' stoichiometry
                ReactionParticipant[] rps = reactionStep.getReactionParticipants();
                int order = 0;
                boolean bAllMembraneReactants = true;
                for (ReactionParticipant rp : rps) {
                    if (rp instanceof Reactant) {
                        if (!(rp.getStructure() instanceof Membrane)) {
                            bAllMembraneReactants = false;
                            break;
                        }
                        order += rp.getStoichiometry();
                    }
                }
                // add only if 2nd order membrane reaction
                if (order == 2 && bAllMembraneReactants && !reactionStep.hasCatalyst()) {
                    model.addElement(kineticTypes[i]);
                }
            }
        }
    }
    getKineticsTypeComboBox().setModel(model);
    return;
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) KineticsDescription(cbit.vcell.model.KineticsDescription) Membrane(cbit.vcell.model.Membrane) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Reactant(cbit.vcell.model.Reactant)

Example 37 with Membrane

use of cbit.vcell.model.Membrane 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 38 with Membrane

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

the class StructurePropertiesPanel method setModel.

public void setModel(Model model) {
    fieldModel = model;
    DefaultComboBoxModel<String> dataModelPos = new DefaultComboBoxModel<String>();
    DefaultComboBoxModel<String> dataModelNeg = new DefaultComboBoxModel<String>();
    dataModelPos.addElement("");
    dataModelNeg.addElement("");
    for (Structure s : model.getStructures()) {
        if (s instanceof Feature) {
            dataModelPos.addElement(s.getName());
            dataModelNeg.addElement(s.getName());
        }
    }
    // fill the comboBoxes with feature names from the model.
    positiveFeatureComboBox.setModel(dataModelPos);
    // if selected structure is a membrane, if it has +ve/-ve feature set, set the comboBox with that selection.
    if (structure instanceof Membrane) {
        Membrane membrane = (Membrane) structure;
        if (fieldModel.getElectricalTopology().getPositiveFeature(membrane) != null) {
            positiveFeatureComboBox.setSelectedItem(fieldModel.getElectricalTopology().getPositiveFeature(membrane).getName());
        }
    }
    negativeFeatureComboBox.setModel(dataModelNeg);
    if (structure instanceof Membrane) {
        Membrane membrane = (Membrane) structure;
        if (fieldModel.getElectricalTopology().getNegativeFeature(membrane) != null) {
            negativeFeatureComboBox.setSelectedItem(fieldModel.getElectricalTopology().getNegativeFeature(membrane).getName());
        }
    }
}
Also used : Membrane(cbit.vcell.model.Membrane) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature)

Example 39 with Membrane

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

the class StructurePropertiesPanel method updateInterface.

/**
 * Comment
 */
private void updateInterface() {
    boolean bNonNullStructure = structure != null && fieldModel != null;
    nameTextField.setEditable(bNonNullStructure);
    annotationTextArea.setEditable(bNonNullStructure);
    boolean bMembrane = bNonNullStructure && structure instanceof Membrane;
    voltageLabel.setVisible(bMembrane);
    voltageTextField.setVisible(bMembrane);
    electrophysiologyLabel.setVisible(bMembrane);
    positiveFeatureLabel.setVisible(bMembrane);
    positiveFeatureComboBox.setVisible(bMembrane);
    negativeFeatureLabel.setVisible(bMembrane);
    negativeFeatureComboBox.setVisible(bMembrane);
    electrophysiologyExplanationLabel.setVisible(bMembrane);
    if (bNonNullStructure) {
        nameTextField.setText(structure.getName());
        annotationTextArea.setText(fieldModel.getVcMetaData().getFreeTextAnnotation(structure));
        StructureSize structureSize = structure.getStructureSize();
        sizeTextField.setText(structureSize.getName() + " [" + structureSize.getUnitDefinition().getSymbolUnicode() + "]");
        if (bMembrane) {
            Membrane membrane = (Membrane) structure;
            MembraneVoltage memVoltage = membrane.getMembraneVoltage();
            voltageTextField.setText(memVoltage.getName() + " [" + memVoltage.getUnitDefinition().getSymbolUnicode() + "]");
            // if membrane has +ve/-ve feature set, set the comboBox with that selection.
            ElectricalTopology electricalTopology = fieldModel.getElectricalTopology();
            Feature positiveFeature = electricalTopology.getPositiveFeature(membrane);
            if (positiveFeature != null) {
                positiveFeatureComboBox.setSelectedItem(positiveFeature.getName());
            }
            Feature negativeFeature = electricalTopology.getNegativeFeature(membrane);
            if (negativeFeature != null) {
                negativeFeatureComboBox.setSelectedItem(negativeFeature.getName());
            }
            this.electrophysiologyExplanationLabel.setText(getExplanationText());
        }
    } else {
        annotationTextArea.setText(null);
        nameTextField.setText(null);
        sizeTextField.setText(null);
        voltageTextField.setText(null);
    }
}
Also used : MembraneVoltage(cbit.vcell.model.Membrane.MembraneVoltage) ElectricalTopology(cbit.vcell.model.Model.ElectricalTopology) Membrane(cbit.vcell.model.Membrane) StructureSize(cbit.vcell.model.Structure.StructureSize) Feature(cbit.vcell.model.Feature)

Example 40 with Membrane

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

the class StructurePropertiesPanel method setStructure.

/**
 * Sets the speciesContext property (cbit.vcell.model.SpeciesContext) value.
 * @param speciesContext The new value for the property.
 * @see #getSpeciesContext
 */
void setStructure(Structure newValue) {
    if (newValue == structure) {
        return;
    }
    Structure oldValue = structure;
    if (oldValue != null) {
        oldValue.removePropertyChangeListener(eventHandler);
        oldValue.getStructureSize().removePropertyChangeListener(eventHandler);
        if (oldValue instanceof Membrane) {
            ((Membrane) oldValue).getMembraneVoltage().removePropertyChangeListener(eventHandler);
        }
    }
    // commit the changes before switch to another structure
    changeName();
    changeAnnotation();
    structure = newValue;
    if (newValue != null) {
        newValue.addPropertyChangeListener(eventHandler);
        newValue.getStructureSize().addPropertyChangeListener(eventHandler);
        if (newValue instanceof Membrane) {
            ((Membrane) newValue).getMembraneVoltage().addPropertyChangeListener(eventHandler);
        }
    }
    updateInterface();
}
Also used : Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure)

Aggregations

Membrane (cbit.vcell.model.Membrane)77 Feature (cbit.vcell.model.Feature)50 Structure (cbit.vcell.model.Structure)47 Expression (cbit.vcell.parser.Expression)31 SpeciesContext (cbit.vcell.model.SpeciesContext)25 MembraneMapping (cbit.vcell.mapping.MembraneMapping)20 StructureTopology (cbit.vcell.model.Model.StructureTopology)19 ExpressionException (cbit.vcell.parser.ExpressionException)18 PropertyVetoException (java.beans.PropertyVetoException)17 FluxReaction (cbit.vcell.model.FluxReaction)16 Model (cbit.vcell.model.Model)16 ReactionStep (cbit.vcell.model.ReactionStep)16 SimpleReaction (cbit.vcell.model.SimpleReaction)16 ArrayList (java.util.ArrayList)14 StructureMapping (cbit.vcell.mapping.StructureMapping)12 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)12 ReactionParticipant (cbit.vcell.model.ReactionParticipant)12 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)12 SubVolume (cbit.vcell.geometry.SubVolume)11 SurfaceClass (cbit.vcell.geometry.SurfaceClass)11