Search in sources :

Example 41 with Feature

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

the class ReactionCartoonTool method lineAction.

private void lineAction(SpeciesContext speciesContextStart, ReactionStep reactionEnd) throws Exception {
    Structure endStructure = reactionEnd.getStructure();
    Structure startStructure = speciesContextStart.getStructure();
    if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, startStructure)) {
        int stoichiometry = 1;
        Reactant reactant = null;
        for (ReactionParticipant participant : reactionEnd.getReactionParticipants()) {
            if (participant instanceof Reactant && participant.getSpeciesContext().equals(speciesContextStart)) {
                reactant = (Reactant) participant;
            }
        }
        if (reactant != null) {
            // only increase stoichiometry if reaction is SimpleReaction
            if (reactionEnd instanceof SimpleReaction) {
                reactant.setStoichiometry(reactant.getStoichiometry() + 1);
            }
            Shape shape = getReactionCartoon().getShapeFromModelObject(reactant);
            if (shape != null) {
                shape.refreshLabel();
            }
        } else {
            // add speciesContextEnd as pdt to reactionStart only if reactionStart is a SimpleRxn or if it is a FluxRxn and doesn't have a pdt.
            if (reactionEnd instanceof SimpleReaction || ((reactionEnd instanceof FluxReaction) && !(reactionEnd.hasReactant()))) {
                reactionEnd.addReactant(speciesContextStart, stoichiometry);
            }
        }
        if (((startStructure instanceof Feature && endStructure instanceof Feature) || (startStructure instanceof Membrane && endStructure instanceof Membrane)) && startStructure != endStructure) {
        // ============ change kinetics to lumped or warn user ?????????
        // simpleReactionEnd.setKinetics(new GeneralLumpedKinetics(simpleReactionEnd));
        }
        getReactionCartoon().notifyChangeEvent();
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) 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) Membrane(cbit.vcell.model.Membrane) FluxReaction(cbit.vcell.model.FluxReaction) Structure(cbit.vcell.model.Structure) Reactant(cbit.vcell.model.Reactant) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Feature(cbit.vcell.model.Feature) Point(java.awt.Point)

Example 42 with Feature

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

the class ReactionCartoonTool method lineAction.

private void lineAction(Structure startStructure, Structure endStructure, Shape endShape) throws Exception, PropertyVetoException, ExpressionException {
    Point startPos = edgeShape.getStart();
    Point endPos = edgeShape.getEnd();
    if (endStructure.equals(startStructure)) {
        SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
        SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
        SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(endStructure);
        reaction.addReactant(speciesContext1, 1);
        reaction.addProduct(speciesContext2, 1);
        getReactionCartoon().notifyChangeEvent();
        positionShapeForObject(endStructure, speciesContext1, startPos);
        positionShapeForObject(endStructure, speciesContext2, endPos);
        positionShapeForObject(endStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
        getGraphModel().clearSelection();
        getGraphModel().select(reaction);
    } else {
        if (endStructure instanceof Membrane && startStructure instanceof Feature) {
            Membrane endMembrane = (Membrane) endStructure;
            Feature startFeature = (Feature) startStructure;
            // if(structTopology.getOutsideFeature(endMembrane).equals(startFeature) || structTopology.getInsideFeature(endMembrane).equals(startFeature))
            // {
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startFeature);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endMembrane);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(endMembrane);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startFeature, speciesContext1, startPos);
            positionShapeForObject(endMembrane, speciesContext2, endPos);
            // finding correct insertion point for reaction, statements below should be put into a utility if used often
            int memAbsXmin = endShape.getSpaceManager().getAbsLoc().x;
            int memAbsXmax = memAbsXmin + endShape.getSpaceManager().getSize().width;
            int reactionWidth = new SimpleReactionShape(reaction, getReactionCartoon()).getSpaceManager().getSize().width;
            int reactionAbsX = (startPos.x + endPos.x) / 2;
            if ((memAbsXmax - memAbsXmin) <= reactionWidth) {
                reactionAbsX = memAbsXmin;
            } else {
                reactionAbsX = Math.max(reactionAbsX, memAbsXmin);
                reactionAbsX = Math.min(reactionAbsX, (memAbsXmax - reactionWidth));
            }
            positionShapeForObject(endMembrane, reaction, new Point(reactionAbsX, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        // }
        } else if (endStructure instanceof Feature && startStructure instanceof Membrane) {
            Membrane startMembrane = (Membrane) startStructure;
            Feature endFeature = (Feature) endStructure;
            // if(structTopology.getOutsideFeature(startMembrane).equals(endFeature) || structTopology.getInsideFeature(startMembrane).equals(endFeature))
            // {
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startMembrane);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endFeature);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startMembrane);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startMembrane, speciesContext1, startPos);
            positionShapeForObject(endFeature, speciesContext2, endPos);
            // finding correct insertion point for reaction, statements below should be put into a utility if used often
            int memAbsXmin = startShape.getSpaceManager().getAbsLoc().x;
            int memAbsXmax = memAbsXmin + startShape.getSpaceManager().getSize().width;
            int reactionWidth = new SimpleReactionShape(reaction, getReactionCartoon()).getSpaceManager().getSize().width;
            int reactionAbsX = (startPos.x + endPos.x) / 2;
            if ((memAbsXmax - memAbsXmin) <= reactionWidth) {
                reactionAbsX = memAbsXmin;
            } else {
                reactionAbsX = Math.max(reactionAbsX, memAbsXmin);
                reactionAbsX = Math.min(reactionAbsX, (memAbsXmax - reactionWidth));
            }
            positionShapeForObject(startMembrane, reaction, new Point(reactionAbsX, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        // }
        } else if (endStructure instanceof Feature && startStructure instanceof Feature) {
            Feature startFeature = (Feature) startStructure;
            Feature endFeature = (Feature) endStructure;
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startStructure);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startStructure);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            reaction.setKinetics(new GeneralLumpedKinetics(reaction));
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startStructure, speciesContext1, startPos);
            positionShapeForObject(endStructure, speciesContext2, endPos);
            positionShapeForObject(startStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        } else if (endStructure instanceof Membrane && startStructure instanceof Membrane) {
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startStructure);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startStructure);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            reaction.setKinetics(new GeneralLumpedKinetics(reaction));
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startStructure, speciesContext1, startPos);
            positionShapeForObject(endStructure, speciesContext2, endPos);
            positionShapeForObject(startStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        }
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) Membrane(cbit.vcell.model.Membrane) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) Point(java.awt.Point) SpeciesContext(cbit.vcell.model.SpeciesContext) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) Feature(cbit.vcell.model.Feature) Point(java.awt.Point)

Example 43 with Feature

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

the class ElectricalStimulusPanel method newStimulus.

/**
 * Comment
 */
private void newStimulus() {
    try {
        SimulationContext simContext = getSimulationContext();
        if (simContext == null) {
            return;
        }
        // 
        // When the voltage and current clamp radio buttons is deselected within the same simulation context (application),
        // display a warning saying that the present clamp settings will be lost (not applicable when the 'no clamp'
        // radiobutton is deselected.
        // 
        ElectricalStimulus currElectricalStimulus = null;
        if (simContext.getElectricalStimuli() != null && simContext.getElectricalStimuli().length > 0) {
            currElectricalStimulus = simContext.getElectricalStimuli()[0];
        }
        // 
        // ignore selection if already selected
        // warn upon deselect if about to loose edits
        // 
        Clamp selectedClamp = (Clamp) clampComboBox.getSelectedItem();
        if (currElectricalStimulus instanceof VoltageClampStimulus) {
            if (selectedClamp == Clamp.Voltage_Clamp) {
                return;
            }
            String response = PopupGenerator.showWarningDialog(this, "warning: the present voltage clamp settings will be lost", new String[] { UserMessage.OPTION_CONTINUE, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CONTINUE);
            if (response == null || response.equals(UserMessage.OPTION_CANCEL)) {
                // revert back to Voltage Clamp
                clampComboBox.setSelectedItem(Clamp.Voltage_Clamp);
                return;
            }
        }
        if (currElectricalStimulus instanceof TotalCurrentClampStimulus) {
            if (selectedClamp == Clamp.Total_Current_Clamp) {
                return;
            }
            String response = PopupGenerator.showWarningDialog(this, "warning: the present current clamp settings will be lost", new String[] { UserMessage.OPTION_CONTINUE, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CONTINUE);
            if (response == null || response.equals(UserMessage.OPTION_CANCEL)) {
                // revert back to Current Clamp
                clampComboBox.setSelectedItem(Clamp.Total_Current_Clamp);
                return;
            }
        }
        if (currElectricalStimulus instanceof CurrentDensityClampStimulus) {
            if (selectedClamp == Clamp.Current_Density_Clamp) {
                return;
            }
            String response = PopupGenerator.showWarningDialog(this, "warning: the present current clamp settings will be lost", new String[] { UserMessage.OPTION_CONTINUE, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CONTINUE);
            if (response == null || response.equals(UserMessage.OPTION_CANCEL)) {
                // revert back to Current Clamp
                clampComboBox.setSelectedItem(Clamp.Current_Density_Clamp);
                return;
            }
        }
        if (currElectricalStimulus == null && selectedClamp == Clamp.No_Clamp) {
            return;
        }
        StructureTopology structTopology = getSimulationContext().getModel().getStructureTopology();
        Structure[] structures = getSimulationContext().getModel().getStructures();
        ArrayList<Feature> features = new ArrayList<Feature>();
        for (Structure structure : structures) {
            if (structure instanceof Feature) {
                features.add((Feature) structure);
            }
        }
        if (features.size() < 2) {
            PopupGenerator.showErrorDialog(this, "error: electrodes must be placed in distinct volumetric structures, found " + features.size() + " volumetric structures in model");
            return;
        }
        Feature groundFeature = features.get(0);
        Feature clampedFeature = features.get(1);
        // 
        if (selectedClamp == Clamp.Total_Current_Clamp) {
            if (simContext.getElectricalStimuli().length == 0 || !(simContext.getElectricalStimuli()[0] instanceof TotalCurrentClampStimulus)) {
                Electrode probeElectrode = new Electrode(clampedFeature, new Coordinate(0, 0, 0));
                TotalCurrentClampStimulus ccStimulus = new TotalCurrentClampStimulus(probeElectrode, "ccElectrode", new Expression(0.0), simContext);
                System.out.println(" Geo's dim = " + simContext.getGeometry().getDimension());
                simContext.setElectricalStimuli(new ElectricalStimulus[] { ccStimulus });
                simContext.setGroundElectrode(new Electrode(groundFeature, new Coordinate(0, 0, 0)));
            }
        }
        // 
        if (selectedClamp == Clamp.Current_Density_Clamp) {
            if (simContext.getElectricalStimuli().length == 0 || !(simContext.getElectricalStimuli()[0] instanceof CurrentDensityClampStimulus)) {
                Electrode probeElectrode = new Electrode(clampedFeature, new Coordinate(0, 0, 0));
                CurrentDensityClampStimulus ccStimulus = new CurrentDensityClampStimulus(probeElectrode, "ccElectrode", new Expression(0.0), simContext);
                System.out.println(" Geo's dim = " + simContext.getGeometry().getDimension());
                simContext.setElectricalStimuli(new ElectricalStimulus[] { ccStimulus });
                simContext.setGroundElectrode(new Electrode(groundFeature, new Coordinate(0, 0, 0)));
            }
        }
        // 
        if (selectedClamp == Clamp.No_Clamp) {
            if (simContext.getElectricalStimuli().length > 0) {
                simContext.setElectricalStimuli(new ElectricalStimulus[0]);
            }
        }
        // 
        if (selectedClamp == Clamp.Voltage_Clamp) {
            if (simContext.getElectricalStimuli().length == 0 || !(simContext.getElectricalStimuli()[0] instanceof VoltageClampStimulus)) {
                Electrode probeElectrode = new Electrode(clampedFeature, new Coordinate(0, 0, 0));
                VoltageClampStimulus vcStimulus = new VoltageClampStimulus(probeElectrode, "vcElectrode", new Expression(0.0), simContext);
                System.out.println(" Geo's dim = " + simContext.getGeometry().getDimension());
                simContext.setElectricalStimuli(new ElectricalStimulus[] { vcStimulus });
                simContext.setGroundElectrode(new Electrode(groundFeature, new Coordinate(0, 0, 0)));
            }
        }
    } catch (java.beans.PropertyVetoException e) {
        PopupGenerator.showErrorDialog(this, "Error setting electrical stimulus: " + e.getMessage());
    }
}
Also used : Electrode(cbit.vcell.mapping.Electrode) StructureTopology(cbit.vcell.model.Model.StructureTopology) ArrayList(java.util.ArrayList) CurrentDensityClampStimulus(cbit.vcell.mapping.CurrentDensityClampStimulus) SimulationContext(cbit.vcell.mapping.SimulationContext) TotalCurrentClampStimulus(cbit.vcell.mapping.TotalCurrentClampStimulus) Feature(cbit.vcell.model.Feature) ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus) Coordinate(org.vcell.util.Coordinate) Expression(cbit.vcell.parser.Expression) VoltageClampStimulus(cbit.vcell.mapping.VoltageClampStimulus) Structure(cbit.vcell.model.Structure)

Example 44 with Feature

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

the class ElectrodePanel method selectFeature.

/**
 * Comment
 */
private void selectFeature() {
    Feature[] features = (electrodeFeatureListProvider != null ? electrodeFeatureListProvider.getFeatures(this) : new Feature[0]);
    if (features == null || features.length == 0) {
        PopupGenerator.showErrorDialog(this, "No defined feature present !");
        return;
    }
    String[] featureNames = new String[features.length];
    for (int i = 0; i < featureNames.length; i++) {
        featureNames[i] = features[i].getName();
    }
    String selection = (String) PopupGenerator.showListDialog(this, featureNames, "Select feature for electrode:");
    if (selection == null) {
        return;
    }
    Feature feature = null;
    for (int i = 0; i < features.length; i++) {
        if (features[i].getName().equals(selection)) {
            feature = features[i];
            break;
        }
    }
    try {
        if (feature == null) {
            throw new Exception("Couldn't find Structure for selected name '" + selection + "'");
        }
        getelectrode1().setFeature(feature);
    } catch (Exception e) {
        handleException(e);
        PopupGenerator.showErrorDialog(this, "Error changing feature for electrode", e);
    }
}
Also used : Feature(cbit.vcell.model.Feature)

Example 45 with Feature

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

the class SimulationContext method refreshElectrodes.

/**
 * This method was created by a SmartGuide.
 */
private void refreshElectrodes() {
    // 
    // step through all stimuli
    // 
    // if any are added or removed, then create new array
    ElectricalStimulus[] newStimuli = fieldElectricalStimuli;
    Structure[] modelStructures = getModel().getStructures();
    for (int i = 0; i < newStimuli.length; i++) {
        ElectricalStimulus stimulus = newStimuli[i];
        Electrode electrode = stimulus.getElectrode();
        Feature feature = electrode.getFeature();
        Feature newFeature = null;
        // 
        for (int j = 0; j < modelStructures.length; j++) {
            Structure modelStructure = modelStructures[j];
            if (modelStructure.compareEqual(feature)) {
                newFeature = (Feature) modelStructure;
            }
        }
        // 
        if (newFeature != null) {
            try {
                electrode.setFeature(newFeature);
            } catch (PropertyVetoException e) {
                e.printStackTrace(System.out);
            }
        } else {
            newStimuli = (ElectricalStimulus[]) BeanUtils.removeElement(newStimuli, stimulus);
            i--;
        }
    }
    if (newStimuli != fieldElectricalStimuli) {
        try {
            setElectricalStimuli(newStimuli);
        } catch (PropertyVetoException e) {
            e.printStackTrace(System.out);
            throw new RuntimeException(e.getMessage());
        }
    }
    // 
    if (getGroundElectrode() != null) {
        Feature feature = getGroundElectrode().getFeature();
        Feature newFeature = null;
        // 
        for (int j = 0; j < modelStructures.length; j++) {
            Structure modelStructure = modelStructures[j];
            if (modelStructure.compareEqual(feature)) {
                newFeature = (Feature) modelStructure;
            }
        }
        // 
        if (newFeature != null) {
            try {
                getGroundElectrode().setFeature(newFeature);
            } catch (PropertyVetoException e) {
                e.printStackTrace(System.out);
            }
        } else {
            try {
                setGroundElectrode(null);
            } catch (PropertyVetoException e) {
                e.printStackTrace(System.out);
            }
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature)

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