Search in sources :

Example 86 with SimulationContext

use of cbit.vcell.mapping.SimulationContext 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 87 with SimulationContext

use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.

the class ModelProcessSpecsPanel method setSimulationContext.

/**
 * Sets the simulationContext property (cbit.vcell.mapping.SimulationContext) value.
 * @param simulationContext The new value for the property.
 * @see #getSimulationContext
 */
public void setSimulationContext(SimulationContext simulationContext) {
    SimulationContext oldValue = fieldSimulationContext;
    fieldSimulationContext = simulationContext;
    firePropertyChange("simulationContext", oldValue, simulationContext);
}
Also used : SimulationContext(cbit.vcell.mapping.SimulationContext)

Example 88 with SimulationContext

use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.

the class SpeciesContextSpecParameterTableModel method propertyChange.

/**
 * This method gets called when a bound property is changed.
 * @param evt A PropertyChangeEvent object describing the event source
 *   and the property that has changed.
 */
public void propertyChange(java.beans.PropertyChangeEvent evt) {
    // 
    try {
        // 
        if (fieldSpeciesContextSpec != null && evt.getSource() == fieldSpeciesContextSpec.getSimulationContext().getGeometryContext() && evt.getPropertyName().equals("geometry")) {
            refreshData();
        }
        // 
        if (fieldSpeciesContextSpec != null && evt.getSource() == fieldSpeciesContextSpec.getSimulationContext().getGeometryContext() && evt.getPropertyName().equals("structureMappings")) {
            StructureMapping[] oldStructureMappings = (StructureMapping[]) evt.getOldValue();
            for (int i = 0; oldStructureMappings != null && i < oldStructureMappings.length; i++) {
                oldStructureMappings[i].removePropertyChangeListener(this);
            }
            StructureMapping[] newStructureMappings = (StructureMapping[]) evt.getNewValue();
            for (int i = 0; newStructureMappings != null && i < newStructureMappings.length; i++) {
                newStructureMappings[i].addPropertyChangeListener(this);
            }
            refreshData();
        }
        // 
        if (evt.getSource() instanceof StructureMapping) {
            refreshData();
        }
        if (evt.getSource() == this && evt.getPropertyName().equals("speciesContextSpec")) {
            SpeciesContextSpec oldValue = (SpeciesContextSpec) evt.getOldValue();
            if (oldValue != null) {
                oldValue.removePropertyChangeListener(this);
                Parameter[] oldParameters = oldValue.getParameters();
                if (oldParameters != null) {
                    for (int i = 0; i < oldParameters.length; i++) {
                        oldParameters[i].removePropertyChangeListener(this);
                    }
                }
                SimulationContext oldSimContext = oldValue.getSimulationContext();
                if (oldSimContext != null) {
                    oldSimContext.getGeometryContext().removePropertyChangeListener(this);
                    StructureMapping[] oldStructureMappings = oldSimContext.getGeometryContext().getStructureMappings();
                    if (oldStructureMappings != null) {
                        for (int i = 0; i < oldStructureMappings.length; i++) {
                            oldStructureMappings[i].removePropertyChangeListener(this);
                        }
                    }
                }
            }
            SpeciesContextSpec newValue = (SpeciesContextSpec) evt.getNewValue();
            if (newValue != null) {
                newValue.addPropertyChangeListener(this);
                Parameter[] newParameters = newValue.getParameters();
                if (newParameters != null) {
                    for (int i = 0; i < newParameters.length; i++) {
                        newParameters[i].addPropertyChangeListener(this);
                    }
                }
                SimulationContext newSimContext = newValue.getSimulationContext();
                if (newSimContext != null) {
                    newSimContext.getGeometryContext().addPropertyChangeListener(this);
                    StructureMapping[] newStructureMappings = newSimContext.getGeometryContext().getStructureMappings();
                    if (newStructureMappings != null) {
                        for (int i = 0; i < newStructureMappings.length; i++) {
                            newStructureMappings[i].addPropertyChangeListener(this);
                        }
                    }
                }
            }
            refreshData();
        }
        if (evt.getSource() instanceof SpeciesContextSpec) {
            // if parameters changed must update listeners
            if (evt.getPropertyName().equals("parameters")) {
                Parameter[] oldParameters = (Parameter[]) evt.getOldValue();
                if (oldParameters != null) {
                    for (int i = 0; i < oldParameters.length; i++) {
                        oldParameters[i].removePropertyChangeListener(this);
                    }
                }
                Parameter[] newParameters = (Parameter[]) evt.getNewValue();
                if (newParameters != null) {
                    for (int i = 0; i < newParameters.length; i++) {
                        newParameters[i].addPropertyChangeListener(this);
                    }
                }
            }
            if (!evt.getPropertyName().equals(SpeciesContextSpec.PARAMETER_NAME_PROXY_PARAMETERS)) {
                // for any change to the SpeciesContextSpec, want to update all.
                // proxy parameters don't affect table
                refreshData();
            }
        }
        if (evt.getSource() instanceof Parameter) {
            refreshData();
        }
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) Parameter(cbit.vcell.model.Parameter) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) SimulationContext(cbit.vcell.mapping.SimulationContext) StructureMapping(cbit.vcell.mapping.StructureMapping) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 89 with SimulationContext

use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.

the class StructureMappingCartoonPanel method setSimulationContext.

/**
 * Sets the simulationContext property (cbit.vcell.mapping.SimulationContext) value.
 * @param simulationContext The new value for the property.
 * @see #getSimulationContext
 */
public void setSimulationContext(SimulationContext simulationContext) {
    SimulationContext oldValue = fieldSimulationContext;
    fieldSimulationContext = simulationContext;
    getMessageLabel().setVisible(this.hasMappableGeometry());
    getBoundaryMessageLabel().setVisible(this.hasMappableGeometry());
    firePropertyChange("simulationContext", oldValue, simulationContext);
}
Also used : SimulationContext(cbit.vcell.mapping.SimulationContext)

Example 90 with SimulationContext

use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.

the class StructureMappingCartoonPanel method setsimulationContext1.

/**
 * Set the simulationContext1 to a new value.
 * @param newValue cbit.vcell.mapping.SimulationContext
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void setsimulationContext1(SimulationContext newValue) {
    if (ivjsimulationContext1 != newValue) {
        try {
            SimulationContext oldValue = getsimulationContext1();
            /* Stop listening for events from the current object */
            if (ivjsimulationContext1 != null) {
                ivjsimulationContext1.removePropertyChangeListener(this);
            }
            ivjsimulationContext1 = newValue;
            /* Listen for events from the new object */
            if (ivjsimulationContext1 != null) {
                ivjsimulationContext1.addPropertyChangeListener(this);
            }
            connPtoP3SetSource();
            connEtoM15(ivjsimulationContext1);
            connEtoM3(ivjsimulationContext1);
            connEtoM10(ivjsimulationContext1);
            firePropertyChange("simulationContext", oldValue, newValue);
        // user code begin {1}
        // user code end
        } catch (java.lang.Throwable ivjExc) {
            // user code begin {2}
            // user code end
            handleException(ivjExc);
        }
    }
    ;
// user code begin {3}
// user code end
}
Also used : SimulationContext(cbit.vcell.mapping.SimulationContext)

Aggregations

SimulationContext (cbit.vcell.mapping.SimulationContext)181 BioModel (cbit.vcell.biomodel.BioModel)73 Simulation (cbit.vcell.solver.Simulation)57 MathDescription (cbit.vcell.math.MathDescription)32 Geometry (cbit.vcell.geometry.Geometry)29 PropertyVetoException (java.beans.PropertyVetoException)28 MathModel (cbit.vcell.mathmodel.MathModel)25 Model (cbit.vcell.model.Model)25 KeyValue (org.vcell.util.document.KeyValue)25 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)23 ArrayList (java.util.ArrayList)23 DataAccessException (org.vcell.util.DataAccessException)23 XMLSource (cbit.vcell.xml.XMLSource)22 XmlParseException (cbit.vcell.xml.XmlParseException)22 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)20 Expression (cbit.vcell.parser.Expression)20 ExpressionException (cbit.vcell.parser.ExpressionException)19 SpeciesContext (cbit.vcell.model.SpeciesContext)17 Structure (cbit.vcell.model.Structure)17 IOException (java.io.IOException)17