Search in sources :

Example 26 with Feature

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

the class GeometryContext method fixMembraneMappings.

private void fixMembraneMappings() throws PropertyVetoException {
    StructureTopology structTopology = getModel().getStructureTopology();
    for (int j = 0; j < fieldStructureMappings.length; j++) {
        if (fieldStructureMappings[j] instanceof MembraneMapping) {
            MembraneMapping membraneMapping = (MembraneMapping) fieldStructureMappings[j];
            Membrane membrane = membraneMapping.getMembrane();
            Feature insideFeature = structTopology.getInsideFeature(membrane);
            Feature outsideFeature = structTopology.getOutsideFeature(membrane);
            // 
            if (insideFeature != null && outsideFeature != null) {
                FeatureMapping insideFM = (FeatureMapping) getStructureMapping(insideFeature);
                FeatureMapping outsideFM = (FeatureMapping) getStructureMapping(outsideFeature);
                GeometryClass insideGeometryClass = insideFM.getGeometryClass();
                GeometryClass outsideGeometryClass = outsideFM.getGeometryClass();
                // 
                if (insideFM != null && insideGeometryClass != null && outsideFM != null && outsideGeometryClass != null) {
                    // inside/outside both mapped to same domain ... membrane must be there too.
                    if (insideGeometryClass == outsideGeometryClass) {
                        membraneMapping.setGeometryClass(insideGeometryClass);
                    // inside/outside mapped to different subvolumes (try to map membrane to adjacent surfaceClass)
                    } else if (insideGeometryClass instanceof SubVolume && outsideGeometryClass instanceof SubVolume) {
                        GeometryClass[] geometryClasses = getGeometry().getGeometryClasses();
                        boolean bFound = false;
                        for (int i = 0; i < geometryClasses.length; i++) {
                            if (geometryClasses[i] instanceof SurfaceClass) {
                                SurfaceClass surfaceClass = (SurfaceClass) geometryClasses[i];
                                if (surfaceClass.isAdjacentTo((SubVolume) insideGeometryClass) && surfaceClass.isAdjacentTo((SubVolume) outsideGeometryClass)) {
                                    membraneMapping.setGeometryClass(surfaceClass);
                                    bFound = true;
                                }
                            }
                        }
                        if (!bFound) {
                            membraneMapping.setGeometryClass(null);
                        }
                    // inside/outside mapped to different membranes (membrane cannot be mapped ... must be cleared).
                    } else if (insideGeometryClass instanceof SurfaceClass && outsideGeometryClass instanceof SurfaceClass) {
                        membraneMapping.setGeometryClass(null);
                    // inside mapped to surface and outside mapped to subvolume (if adjacent, map membrane to surface ... else clear).
                    } else if (insideGeometryClass instanceof SurfaceClass && outsideGeometryClass instanceof SubVolume) {
                        SurfaceClass surface = (SurfaceClass) insideGeometryClass;
                        SubVolume subVolume = (SubVolume) outsideGeometryClass;
                        if (surface.isAdjacentTo(subVolume)) {
                            membraneMapping.setGeometryClass(surface);
                        } else {
                            membraneMapping.setGeometryClass(null);
                        }
                    // inside mapped to subvolume and outside mapped to surface (if adjacent, map membrane to surface ... else clear).
                    } else if (insideGeometryClass instanceof SubVolume && outsideGeometryClass instanceof SurfaceClass) {
                        SurfaceClass surface = (SurfaceClass) outsideGeometryClass;
                        SubVolume subVolume = (SubVolume) insideGeometryClass;
                        if (surface.isAdjacentTo(subVolume)) {
                            membraneMapping.setGeometryClass(surface);
                        } else {
                            membraneMapping.setGeometryClass(null);
                        }
                    }
                }
            }
        }
    }
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) StructureTopology(cbit.vcell.model.Model.StructureTopology) SurfaceClass(cbit.vcell.geometry.SurfaceClass) SubVolume(cbit.vcell.geometry.SubVolume) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) Membrane(cbit.vcell.model.Membrane) Feature(cbit.vcell.model.Feature)

Example 27 with Feature

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

the class ReactionPropertiesPanel method getJToggleButton.

private JButton getJToggleButton() {
    if (jToggleButton == null) {
        jToggleButton = new JButton("Convert");
        jToggleButton.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent e) {
                ModelUnitSystem modelUnitSystem = reactionStep.getModel().getUnitSystem();
                Kinetics kinetics = reactionStep.getKinetics();
                if (kinetics instanceof DistributedKinetics) {
                    try {
                        reactionStep.setKinetics(LumpedKinetics.toLumpedKinetics((DistributedKinetics) kinetics));
                    } catch (Exception e2) {
                        e2.printStackTrace(System.out);
                        if (kinetics.getKineticsDescription().isElectrical()) {
                            DialogUtils.showErrorDialog(ReactionPropertiesPanel.this, "failed to translate into General Current Kinetics [" + modelUnitSystem.getCurrentUnit().getSymbolUnicode() + "]: " + e2.getMessage(), e2);
                        } else {
                            DialogUtils.showErrorDialog(ReactionPropertiesPanel.this, "failed to translate into General Lumped Kinetics [" + modelUnitSystem.getLumpedReactionRateUnit().getSymbolUnicode() + "]: " + e2.getMessage(), e2);
                        }
                    }
                } else if (kinetics instanceof LumpedKinetics) {
                    try {
                        reactionStep.setKinetics(DistributedKinetics.toDistributedKinetics((LumpedKinetics) kinetics));
                    } catch (Exception e2) {
                        e2.printStackTrace(System.out);
                        if (kinetics.getKineticsDescription().isElectrical()) {
                            DialogUtils.showErrorDialog(ReactionPropertiesPanel.this, "failed to translate into General Current Density Kinetics [" + modelUnitSystem.getCurrentDensityUnit().getSymbolUnicode() + "]: " + e2.getMessage(), e2);
                        } else {
                            if (kinetics.getReactionStep().getStructure() instanceof Feature) {
                                DialogUtils.showErrorDialog(ReactionPropertiesPanel.this, "failed to translate into General Kinetics [" + modelUnitSystem.getVolumeReactionRateUnit().getSymbolUnicode() + "]: " + e2.getMessage(), e2);
                            } else {
                                DialogUtils.showErrorDialog(ReactionPropertiesPanel.this, "failed to translate into General Kinetics [" + modelUnitSystem.getMembraneReactionRateUnit().getSymbolUnicode() + "]: " + e2.getMessage(), e2);
                            }
                        }
                    }
                }
            }
        });
    }
    return jToggleButton;
}
Also used : DistributedKinetics(cbit.vcell.model.DistributedKinetics) ActionListener(java.awt.event.ActionListener) LumpedKinetics(cbit.vcell.model.LumpedKinetics) JButton(javax.swing.JButton) Macroscopic_IRRKinetics(cbit.vcell.model.Macroscopic_IRRKinetics) Kinetics(cbit.vcell.model.Kinetics) MassActionKinetics(cbit.vcell.model.MassActionKinetics) DistributedKinetics(cbit.vcell.model.DistributedKinetics) HMM_IRRKinetics(cbit.vcell.model.HMM_IRRKinetics) Microscopic_IRRKinetics(cbit.vcell.model.Microscopic_IRRKinetics) LumpedKinetics(cbit.vcell.model.LumpedKinetics) HMM_REVKinetics(cbit.vcell.model.HMM_REVKinetics) Feature(cbit.vcell.model.Feature) PropertyVetoException(java.beans.PropertyVetoException) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 28 with Feature

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

the class ReactionPropertiesPanel method getKineticsTypeComboBox.

private javax.swing.JComboBox getKineticsTypeComboBox() {
    if (kineticsTypeComboBox == null) {
        try {
            kineticsTypeComboBox = new javax.swing.JComboBox();
            kineticsTypeComboBox.setName("JComboBox1");
            kineticsTypeComboBox.setRenderer(new DefaultListCellRenderer() {

                private static final String MU = "\u03BC";

                private static final String MICROMOLAR = MU + "M";

                private static final String SQUARED = "\u00B2";

                private static final String SQUAREMICRON = MU + "m" + SQUARED;

                private static final String MICRON = MU + "m";

                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    java.awt.Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                    if (value instanceof KineticsDescription) {
                        KineticsDescription kineticsDescription = (KineticsDescription) value;
                        setText(kineticsDescription.getDescription());
                        if (reactionStep != null) {
                            if (reactionStep instanceof SimpleReaction) {
                                if (reactionStep.getStructure() instanceof Feature) {
                                    if (kineticsDescription.equals(KineticsDescription.General)) {
                                        setText("General [" + MICROMOLAR + "/s]");
                                    } else if (kineticsDescription.equals(KineticsDescription.MassAction)) {
                                        setText("Mass Action [" + MICROMOLAR + "/s] (recommended for stochastic application)");
                                    } else if (kineticsDescription.equals(KineticsDescription.GeneralLumped)) {
                                        setText("General [molecules/s]");
                                    } else if (kineticsDescription.equals(KineticsDescription.HMM_irreversible)) {
                                        setText("Henri-Michaelis-Menten (Irreversible) [" + MICROMOLAR + "/s]");
                                    } else if (kineticsDescription.equals(KineticsDescription.HMM_reversible)) {
                                        setText("Henri-Michaelis-Menten (Reversible) [" + MICROMOLAR + "/s]");
                                    } else {
                                        setText(kineticsDescription.getDescription());
                                    }
                                } else if (reactionStep.getStructure() instanceof Membrane) {
                                    if (kineticsDescription.equals(KineticsDescription.General)) {
                                        setText("General [molecules/(" + SQUAREMICRON + " s)]");
                                    } else if (kineticsDescription.equals(KineticsDescription.MassAction)) {
                                        setText("Mass Action [molecules/(" + SQUAREMICRON + " s)]");
                                    } else if (kineticsDescription.equals(KineticsDescription.GeneralLumped)) {
                                        setText("General [molecules/s)]");
                                    } else if (kineticsDescription.equals(KineticsDescription.HMM_irreversible)) {
                                        setText("Henri-Michaelis-Menten (Irreversible) [molecules/(" + SQUAREMICRON + " s)]");
                                    } else if (kineticsDescription.equals(KineticsDescription.HMM_reversible)) {
                                        setText("Henri-Michaelis-Menten (Reversible) [molecules/(" + SQUAREMICRON + " s)]");
                                    } else if (kineticsDescription.equals(KineticsDescription.Macroscopic_irreversible)) {
                                        setText("Macroscopic (Irreversible) [molecules/(" + SQUAREMICRON + " s)]");
                                    } else if (kineticsDescription.equals(KineticsDescription.Microscopic_irreversible)) {
                                        setText("Microscopic (Irreversible) [molecules/(" + SQUAREMICRON + " s)]");
                                    }
                                }
                            } else if (reactionStep instanceof FluxReaction) {
                                if (kineticsDescription.equals(KineticsDescription.General)) {
                                    setText("General Flux Density (" + MICROMOLAR + "-" + MICRON + "/s)");
                                } else if (kineticsDescription.equals(KineticsDescription.GeneralLumped)) {
                                    setText("General Flux (molecules/s)");
                                } else if (kineticsDescription.equals(KineticsDescription.GeneralCurrent)) {
                                    setText("General Current Density (pA/" + SQUAREMICRON + ")");
                                } else if (kineticsDescription.equals(KineticsDescription.GeneralCurrentLumped)) {
                                    setText("General Current (pA)");
                                } else if (kineticsDescription.equals(KineticsDescription.GHK)) {
                                    setText("Goldman-Hodgkin-Katz Current Density (pA/" + SQUAREMICRON + ") - permeability in " + MICRON + "/s");
                                } else if (kineticsDescription.equals(KineticsDescription.Nernst)) {
                                    setText("Nernst Current Density (pA/" + SQUAREMICRON + ") - conductance in nS/" + SQUAREMICRON);
                                } else if (kineticsDescription.equals(KineticsDescription.GeneralPermeability)) {
                                    setText("General Permeability (" + MICROMOLAR + "-" + MICRON + "/s) - permeability in " + MICRON + "/s");
                                }
                            }
                        }
                    }
                    return component;
                }
            });
        // user code begin {1}
        // user code end
        } catch (java.lang.Throwable ivjExc) {
            // user code begin {2}
            // user code end
            handleException(ivjExc);
        }
    }
    return kineticsTypeComboBox;
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) KineticsDescription(cbit.vcell.model.KineticsDescription) FluxReaction(cbit.vcell.model.FluxReaction) Feature(cbit.vcell.model.Feature) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) Membrane(cbit.vcell.model.Membrane) BioPaxObject(org.vcell.pathway.BioPaxObject) RelationshipObject(org.vcell.relationship.RelationshipObject) Component(java.awt.Component) JList(javax.swing.JList)

Example 29 with Feature

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

the class Generate2DExpModelOpAbstract method generateModel.

public final GeneratedModelResults generateModel(double deltaX, double bleachRadius, double cellRadius, double bleachDuration, double bleachRate, double postbleachDelay, double postbleachDuration, double psfSigma, double outputTimeStep, double primaryDiffusionRate, double primaryFraction, double bleachMonitorRate, double secondaryDiffusionRate, double secondaryFraction, String extracellularName, String cytosolName, Context context) throws PropertyVetoException, ExpressionException, GeometryException, ImageException, ModelException, MappingException, MathException, MatrixException {
    double domainSize = 2.2 * cellRadius;
    Extent extent = new Extent(domainSize, domainSize, 1.0);
    Origin origin = new Origin(-extent.getX() / 2.0, -extent.getY() / 2.0, -extent.getZ() / 2.0);
    String EXTRACELLULAR_NAME = extracellularName;
    String CYTOSOL_NAME = cytosolName;
    AnalyticSubVolume cytosolSubVolume = new AnalyticSubVolume(CYTOSOL_NAME, new Expression("pow(x,2)+pow(y,2)<pow(" + cellRadius + ",2)"));
    AnalyticSubVolume extracellularSubVolume = new AnalyticSubVolume(EXTRACELLULAR_NAME, new Expression(1.0));
    Geometry geometry = new Geometry("geometry", 2);
    geometry.getGeometrySpec().setExtent(extent);
    geometry.getGeometrySpec().setOrigin(origin);
    geometry.getGeometrySpec().addSubVolume(extracellularSubVolume);
    geometry.getGeometrySpec().addSubVolume(cytosolSubVolume, true);
    geometry.getGeometrySurfaceDescription().updateAll();
    BioModel bioModel = new BioModel(null);
    bioModel.setName("unnamed");
    Model model = new Model("model");
    bioModel.setModel(model);
    model.addFeature(EXTRACELLULAR_NAME);
    Feature extracellular = (Feature) model.getStructure(EXTRACELLULAR_NAME);
    model.addFeature(CYTOSOL_NAME);
    Feature cytosol = (Feature) model.getStructure(CYTOSOL_NAME);
    SpeciesContext immobileSC = model.createSpeciesContext(cytosol);
    SpeciesContext primarySC = model.createSpeciesContext(cytosol);
    SpeciesContext secondarySC = model.createSpeciesContext(cytosol);
    // 
    // common bleaching rate for all species
    // 
    double bleachStart = 10 * outputTimeStep - bleachDuration - postbleachDelay;
    double bleachEnd = bleachStart + bleachDuration;
    Expression bleachRateExp = createBleachExpression(bleachRadius, bleachRate, bleachMonitorRate, bleachStart, bleachEnd);
    {
        SimpleReaction immobileBWM = model.createSimpleReaction(cytosol);
        GeneralKinetics immobileBWMKinetics = new GeneralKinetics(immobileBWM);
        immobileBWM.setKinetics(immobileBWMKinetics);
        immobileBWM.addReactant(immobileSC, 1);
        immobileBWMKinetics.getReactionRateParameter().setExpression(Expression.mult(bleachRateExp, new Expression(immobileSC.getName())));
    }
    {
        SimpleReaction primaryBWM = model.createSimpleReaction(cytosol);
        GeneralKinetics primaryBWMKinetics = new GeneralKinetics(primaryBWM);
        primaryBWM.setKinetics(primaryBWMKinetics);
        primaryBWM.addReactant(primarySC, 1);
        primaryBWMKinetics.getReactionRateParameter().setExpression(Expression.mult(bleachRateExp, new Expression(primarySC.getName())));
    }
    {
        SimpleReaction secondaryBWM = model.createSimpleReaction(cytosol);
        GeneralKinetics secondaryBWMKinetics = new GeneralKinetics(secondaryBWM);
        secondaryBWM.setKinetics(secondaryBWMKinetics);
        secondaryBWM.addReactant(secondarySC, 1);
        secondaryBWMKinetics.getReactionRateParameter().setExpression(Expression.mult(bleachRateExp, new Expression(secondarySC.getName())));
    }
    // create simulation context
    SimulationContext simContext = bioModel.addNewSimulationContext("simContext", SimulationContext.Application.NETWORK_DETERMINISTIC);
    simContext.setGeometry(geometry);
    FeatureMapping cytosolFeatureMapping = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(cytosol);
    FeatureMapping extracellularFeatureMapping = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(extracellular);
    SubVolume cytSubVolume = geometry.getGeometrySpec().getSubVolume(CYTOSOL_NAME);
    SubVolume exSubVolume = geometry.getGeometrySpec().getSubVolume(EXTRACELLULAR_NAME);
    // unused? SurfaceClass pmSurfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(exSubVolume, cytSubVolume);
    cytosolFeatureMapping.setGeometryClass(cytSubVolume);
    extracellularFeatureMapping.setGeometryClass(exSubVolume);
    cytosolFeatureMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
    extracellularFeatureMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
    double fixedFraction = 1.0 - primaryFraction - secondaryFraction;
    SpeciesContextSpec immobileSCS = simContext.getReactionContext().getSpeciesContextSpec(immobileSC);
    immobileSCS.getInitialConditionParameter().setExpression(new Expression(fixedFraction));
    immobileSCS.getDiffusionParameter().setExpression(new Expression(0.0));
    SpeciesContextSpec primarySCS = simContext.getReactionContext().getSpeciesContextSpec(primarySC);
    primarySCS.getInitialConditionParameter().setExpression(new Expression(primaryFraction));
    primarySCS.getDiffusionParameter().setExpression(new Expression(primaryDiffusionRate));
    SpeciesContextSpec secondarySCS = simContext.getReactionContext().getSpeciesContextSpec(secondarySC);
    secondarySCS.getInitialConditionParameter().setExpression(new Expression(secondaryFraction));
    secondarySCS.getDiffusionParameter().setExpression(new Expression(secondaryDiffusionRate));
    simContext.getMicroscopeMeasurement().addFluorescentSpecies(immobileSC);
    simContext.getMicroscopeMeasurement().addFluorescentSpecies(primarySC);
    simContext.getMicroscopeMeasurement().addFluorescentSpecies(secondarySC);
    simContext.getMicroscopeMeasurement().setConvolutionKernel(new GaussianConvolutionKernel(new Expression(psfSigma), new Expression(psfSigma)));
    MathMapping mathMapping = simContext.createNewMathMapping();
    MathDescription mathDesc = mathMapping.getMathDescription();
    simContext.setMathDescription(mathDesc);
    User owner = context.getDefaultOwner();
    int meshSize = (int) (domainSize / deltaX);
    if (meshSize % 2 == 0) {
        // want an odd-sized mesh in x and y ... so centered at the origin.
        meshSize = meshSize + 1;
    }
    TimeBounds timeBounds = new TimeBounds(0.0, postbleachDuration);
    // 
    // simulation to use for data generation (output time steps as recorded by the microscope)
    // 
    double bleachBlackoutBegin = bleachStart - postbleachDelay;
    double bleachBlackoutEnd = bleachEnd + postbleachDelay;
    // ArrayList<Double> times = new ArrayList<Double>();
    // double time = 0;
    // while (time<=timeBounds.getEndingTime()){
    // if (time<=bleachBlackoutBegin || time>bleachBlackoutEnd){
    // // postbleachDelay is the time it takes to switch the filters.
    // times.add(time);
    // }
    // time += outputTimeStep.getData();
    // }
    // double[] timeArray = new double[times.size()];
    // for (int i=0;i<timeArray.length;i++){
    // timeArray[i] = times.get(i);
    // }
    // OutputTimeSpec fakeDataSimOutputTimeSpec = new ExplicitOutputTimeSpec(timeArray);
    OutputTimeSpec fakeDataSimOutputTimeSpec = new UniformOutputTimeSpec(outputTimeStep);
    KeyValue fakeDataSimKey = context.createNewKeyValue();
    SimulationVersion fakeDataSimVersion = new SimulationVersion(fakeDataSimKey, "fakeDataSim", owner, new GroupAccessNone(), new KeyValue("0"), new BigDecimal(0), new Date(), VersionFlag.Current, "", null);
    Simulation fakeDataSim = new Simulation(fakeDataSimVersion, mathDesc);
    simContext.addSimulation(fakeDataSim);
    fakeDataSim.getSolverTaskDescription().setTimeBounds(timeBounds);
    fakeDataSim.getMeshSpecification().setSamplingSize(new ISize(meshSize, meshSize, 1));
    fakeDataSim.getSolverTaskDescription().setSolverDescription(SolverDescription.SundialsPDE);
    fakeDataSim.getSolverTaskDescription().setOutputTimeSpec(fakeDataSimOutputTimeSpec);
    // 
    // simulation to use for viewing the protocol (output time steps to understand the physics)
    // 
    KeyValue fullExperimentSimKey = context.createNewKeyValue();
    SimulationVersion fullExperimentSimVersion = new SimulationVersion(fullExperimentSimKey, "fullExperiment", owner, new GroupAccessNone(), new KeyValue("0"), new BigDecimal(0), new Date(), VersionFlag.Current, "", null);
    Simulation fullExperimentSim = new Simulation(fullExperimentSimVersion, mathDesc);
    simContext.addSimulation(fullExperimentSim);
    OutputTimeSpec fullExperimentOutputTimeSpec = new UniformOutputTimeSpec(outputTimeStep / 10.0);
    fullExperimentSim.getSolverTaskDescription().setTimeBounds(timeBounds);
    fullExperimentSim.getMeshSpecification().setSamplingSize(new ISize(meshSize, meshSize, 1));
    fullExperimentSim.getSolverTaskDescription().setSolverDescription(SolverDescription.SundialsPDE);
    fullExperimentSim.getSolverTaskDescription().setOutputTimeSpec(fullExperimentOutputTimeSpec);
    GeneratedModelResults results = new GeneratedModelResults();
    results.bioModel_2D = bioModel;
    results.simulation_2D = fakeDataSim;
    results.bleachBlackoutBeginTime = bleachBlackoutBegin;
    results.bleachBlackoutEndTime = bleachBlackoutEnd;
    return results;
}
Also used : Origin(org.vcell.util.Origin) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) Extent(org.vcell.util.Extent) MathDescription(cbit.vcell.math.MathDescription) ISize(org.vcell.util.ISize) SpeciesContext(cbit.vcell.model.SpeciesContext) GeneralKinetics(cbit.vcell.model.GeneralKinetics) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) Feature(cbit.vcell.model.Feature) TimeBounds(cbit.vcell.solver.TimeBounds) GroupAccessNone(org.vcell.util.document.GroupAccessNone) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) SimulationVersion(org.vcell.util.document.SimulationVersion) FeatureMapping(cbit.vcell.mapping.FeatureMapping) SubVolume(cbit.vcell.geometry.SubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) SimpleReaction(cbit.vcell.model.SimpleReaction) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) SimulationContext(cbit.vcell.mapping.SimulationContext) GaussianConvolutionKernel(cbit.vcell.mapping.MicroscopeMeasurement.GaussianConvolutionKernel) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) BioModel(cbit.vcell.biomodel.BioModel) BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) MathMapping(cbit.vcell.mapping.MathMapping) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume)

Example 30 with Feature

use of cbit.vcell.model.Feature 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)

Aggregations

Feature (cbit.vcell.model.Feature)71 Membrane (cbit.vcell.model.Membrane)50 Structure (cbit.vcell.model.Structure)36 Expression (cbit.vcell.parser.Expression)29 SpeciesContext (cbit.vcell.model.SpeciesContext)25 PropertyVetoException (java.beans.PropertyVetoException)18 Model (cbit.vcell.model.Model)16 StructureTopology (cbit.vcell.model.Model.StructureTopology)16 SimpleReaction (cbit.vcell.model.SimpleReaction)15 SubVolume (cbit.vcell.geometry.SubVolume)14 MembraneMapping (cbit.vcell.mapping.MembraneMapping)14 SurfaceClass (cbit.vcell.geometry.SurfaceClass)13 FeatureMapping (cbit.vcell.mapping.FeatureMapping)13 ExpressionException (cbit.vcell.parser.ExpressionException)13 FluxReaction (cbit.vcell.model.FluxReaction)12 ReactionStep (cbit.vcell.model.ReactionStep)12 KeyValue (org.vcell.util.document.KeyValue)12 BioModel (cbit.vcell.biomodel.BioModel)11 StructureMapping (cbit.vcell.mapping.StructureMapping)11 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)11