Search in sources :

Example 6 with ElectricalStimulus

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

the class ElectricalStimulusParameterTableModel 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) {
    if (evt.getSource() == this && evt.getPropertyName().equals("electricalStimulus")) {
        ElectricalStimulus oldValue = (ElectricalStimulus) evt.getOldValue();
        if (oldValue != null) {
            oldValue.removePropertyChangeListener(this);
            Parameter[] oldParameters = oldValue.getParameters();
            for (int i = 0; i < oldParameters.length; i++) {
                oldParameters[i].removePropertyChangeListener(this);
            }
        }
        ElectricalStimulus newValue = (ElectricalStimulus) evt.getNewValue();
        if (newValue != null) {
            newValue.addPropertyChangeListener(this);
            Parameter[] newParameters = newValue.getParameters();
            for (int i = 0; i < newParameters.length; i++) {
                newParameters[i].addPropertyChangeListener(this);
            }
        }
        refreshData();
    }
    if (evt.getSource() instanceof ElectricalStimulus && (evt.getPropertyName().equals("localParameters") || evt.getPropertyName().equals("proxyParameters"))) {
        Parameter[] oldParameters = (Parameter[]) evt.getOldValue();
        for (int i = 0; i < oldParameters.length; i++) {
            oldParameters[i].removePropertyChangeListener(this);
        }
        Parameter[] newParameters = (Parameter[]) evt.getNewValue();
        for (int i = 0; i < newParameters.length; i++) {
            newParameters[i].addPropertyChangeListener(this);
        }
        refreshData();
    }
    if (evt.getSource() instanceof LocalParameter && evt.getPropertyName().equals("expression")) {
        fireTableRowsUpdated(0, getRowCount() - 1);
    }
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) Parameter(cbit.vcell.model.Parameter) ProxyParameter(cbit.vcell.model.ProxyParameter)

Example 7 with ElectricalStimulus

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

the class ElectricalStimulusParameterTableModel method setElectricalStimulus.

/**
 * Sets the electricalStimulus property (cbit.vcell.mapping.ElectricalStimulus) value.
 * @param electricalStimulus The new value for the property.
 * @see #getElectricalStimulus
 */
public void setElectricalStimulus(ElectricalStimulus electricalStimulus) {
    ElectricalStimulus oldValue = fieldElectricalStimulus;
    fieldElectricalStimulus = electricalStimulus;
    if (electricalStimulus != null) {
        autoCompleteSymbolFilter = electricalStimulus.getAutoCompleteSymbolFilter();
    }
    firePropertyChange("electricalStimulus", oldValue, electricalStimulus);
}
Also used : ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus)

Example 8 with ElectricalStimulus

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

the class SimulationContextDbDriver method insertStimuliSQL.

/**
 * This method was created in VisualAge.
 */
private void insertStimuliSQL(InsertHashtable hash, Connection con, KeyValue simContextKey, SimulationContext simContext) throws SQLException, DataAccessException {
    StimulusTable stimulusTable = StimulusTable.table;
    ElectricalStimulus[] stimuli = simContext.getElectricalStimuli();
    // 
    for (int i = 0; i < stimuli.length; i++) {
        ElectricalStimulus stimulus = stimuli[i];
        KeyValue newStimuliKey = keyFactory.getNewKey(con);
        // 
        String sql = "INSERT INTO " + stimulusTable.getTableName() + " " + stimulusTable.getSQLColumnList() + " VALUES " + stimulusTable.getSQLValueList(hash, newStimuliKey, simContextKey, stimulus);
        // System.out.println(sql);
        updateCleanSQL(con, sql);
    }
    // 
    // store ground electrode
    // 
    Electrode groundElectrode = simContext.getGroundElectrode();
    if (groundElectrode != null) {
        KeyValue newStimuliKey = keyFactory.getNewKey(con);
        // 
        String sql = "INSERT INTO " + stimulusTable.getTableName() + " " + stimulusTable.getSQLColumnList() + " VALUES " + stimulusTable.getSQLValueList(hash, newStimuliKey, simContextKey, groundElectrode);
        // System.out.println(sql);
        updateCleanSQL(con, sql);
    }
}
Also used : ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus) KeyValue(org.vcell.util.document.KeyValue) Electrode(cbit.vcell.mapping.Electrode)

Example 9 with ElectricalStimulus

use of cbit.vcell.mapping.ElectricalStimulus 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 10 with ElectricalStimulus

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

the class ModelUnitConverter method createBioModelWithNewUnitSystem.

public static BioModel createBioModelWithNewUnitSystem(BioModel oldBioModel, ModelUnitSystem newUnitSystem) throws ExpressionException, XmlParseException {
    // new BioModel has new unit system applied to all built-in units ... but expressions still need to be corrected (see below).
    BioModel newBioModel = XmlHelper.cloneBioModelWithNewUnitSystem(oldBioModel, newUnitSystem);
    Model newModel = newBioModel.getModel();
    Model oldModel = oldBioModel.getModel();
    for (Parameter p : newBioModel.getModel().getModelParameters()) {
        convertVarsWithUnitFactors(oldBioModel.getModel(), newBioModel.getModel(), p);
    }
    for (ReactionStep reactionStep : newBioModel.getModel().getReactionSteps()) {
        SymbolTable oldSymbolTable = oldBioModel.getModel().getReactionStep(reactionStep.getName());
        SymbolTable newSymbolTable = reactionStep;
        for (Parameter p : reactionStep.getKinetics().getUnresolvedParameters()) {
            convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
        }
        for (Parameter p : reactionStep.getKinetics().getKineticsParameters()) {
            convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
        }
    }
    for (ReactionRule reactionRule : newBioModel.getModel().getRbmModelContainer().getReactionRuleList()) {
        SymbolTable oldSymbolTable = oldBioModel.getModel().getRbmModelContainer().getReactionRule(reactionRule.getName()).getKineticLaw().getScopedSymbolTable();
        SymbolTable newSymbolTable = reactionRule.getKineticLaw().getScopedSymbolTable();
        for (Parameter p : reactionRule.getKineticLaw().getUnresolvedParameters()) {
            convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
        }
        for (Parameter p : reactionRule.getKineticLaw().getLocalParameters()) {
            convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
        }
    }
    for (SimulationContext simContext : newBioModel.getSimulationContexts()) {
        SimulationContext oldSimContext = oldBioModel.getSimulationContext(simContext.getName());
        // ArrayList<Parameter> parameterList = new ArrayList<Parameter>();
        for (StructureMapping mapping : simContext.getGeometryContext().getStructureMappings()) {
            Structure oldStructure = oldModel.getStructure(mapping.getStructure().getName());
            StructureMapping oldMapping = oldSimContext.getGeometryContext().getStructureMapping(oldStructure);
            for (Parameter p : mapping.computeApplicableParameterList()) {
                convertVarsWithUnitFactors(oldMapping, mapping, p);
            }
        }
        for (SpeciesContextSpec spec : simContext.getReactionContext().getSpeciesContextSpecs()) {
            SpeciesContext oldSpeciesContext = oldModel.getSpeciesContext(spec.getSpeciesContext().getName());
            SpeciesContextSpec oldSpec = oldSimContext.getReactionContext().getSpeciesContextSpec(oldSpeciesContext);
            for (Parameter p : spec.computeApplicableParameterList()) {
                convertVarsWithUnitFactors(oldSpec, spec, p);
            }
        }
        for (int i = 0; i < simContext.getElectricalStimuli().length; i++) {
            ElectricalStimulus newElectricalStimulus = simContext.getElectricalStimuli()[i];
            ElectricalStimulus oldElectricalStimulus = oldSimContext.getElectricalStimuli()[i];
            for (Parameter p : newElectricalStimulus.getParameters()) {
                convertVarsWithUnitFactors(oldElectricalStimulus.getNameScope().getScopedSymbolTable(), newElectricalStimulus.getNameScope().getScopedSymbolTable(), p);
            }
        }
        // convert events : trigger and delay parameters and event assignments
        for (int i = 0; simContext.getBioEvents() != null && oldSimContext.getBioEvents() != null && i < simContext.getBioEvents().length; i++) {
            BioEvent newBioEvent = simContext.getBioEvents()[i];
            BioEvent oldBioEvent = oldSimContext.getBioEvent(newBioEvent.getName());
            for (Parameter p : newBioEvent.getEventParameters()) {
                convertVarsWithUnitFactors(oldBioEvent.getNameScope().getScopedSymbolTable(), newBioEvent.getNameScope().getScopedSymbolTable(), p);
            }
            // for each event assignment expression
            for (int e = 0; e < newBioEvent.getEventAssignments().size(); e++) {
                ScopedSymbolTable newSymbolTable = newBioEvent.getNameScope().getScopedSymbolTable();
                ScopedSymbolTable oldSymbolTable = oldBioEvent.getNameScope().getScopedSymbolTable();
                EventAssignment newEventAssignment = newBioEvent.getEventAssignments().get(e);
                EventAssignment oldEventAssignment = oldBioEvent.getEventAssignments().get(e);
                VCUnitDefinition oldTargetUnit = oldEventAssignment.getTarget().getUnitDefinition();
                VCUnitDefinition newTargetUnit = newEventAssignment.getTarget().getUnitDefinition();
                Expression eventAssgnExpr = newEventAssignment.getAssignmentExpression();
                convertExprWithUnitFactors(oldSymbolTable, newSymbolTable, oldTargetUnit, newTargetUnit, eventAssgnExpr);
            }
        }
        /**
         * @TODO: If rate rule variable unit is TBD, we still need to handle the rate expression unit.
         */
        // convert rate rules
        RateRule[] rateRules = simContext.getRateRules();
        if (rateRules != null && rateRules.length > 0) {
            for (RateRule rateRule : rateRules) {
                RateRule oldRateRule = oldSimContext.getRateRule(rateRule.getName());
                ScopedSymbolTable oldSymbolTable = oldRateRule.getSimulationContext();
                ScopedSymbolTable newSymbolTable = rateRule.getSimulationContext();
                VCUnitDefinition oldTargetUnit = oldRateRule.getRateRuleVar().getUnitDefinition();
                VCUnitDefinition newTargetUnit = rateRule.getRateRuleVar().getUnitDefinition();
                Expression rateRuleExpr = rateRule.getRateRuleExpression();
                convertExprWithUnitFactors(oldSymbolTable, newSymbolTable, oldTargetUnit, newTargetUnit, rateRuleExpr);
            }
        }
    }
    // end  for - simulationContext
    return newBioModel;
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) EventAssignment(cbit.vcell.mapping.BioEvent.EventAssignment) ScopedSymbolTable(cbit.vcell.parser.ScopedSymbolTable) SymbolTable(cbit.vcell.parser.SymbolTable) SpeciesContext(cbit.vcell.model.SpeciesContext) SimulationContext(cbit.vcell.mapping.SimulationContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) Parameter(cbit.vcell.model.Parameter) RateRule(cbit.vcell.mapping.RateRule) ScopedSymbolTable(cbit.vcell.parser.ScopedSymbolTable) BioEvent(cbit.vcell.mapping.BioEvent) Structure(cbit.vcell.model.Structure)

Aggregations

ElectricalStimulus (cbit.vcell.mapping.ElectricalStimulus)14 Electrode (cbit.vcell.mapping.Electrode)7 StructureMapping (cbit.vcell.mapping.StructureMapping)7 Expression (cbit.vcell.parser.Expression)7 SimulationContext (cbit.vcell.mapping.SimulationContext)6 CurrentDensityClampStimulus (cbit.vcell.mapping.CurrentDensityClampStimulus)5 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)5 TotalCurrentClampStimulus (cbit.vcell.mapping.TotalCurrentClampStimulus)5 VoltageClampStimulus (cbit.vcell.mapping.VoltageClampStimulus)5 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)4 SpatialProcess (cbit.vcell.mapping.spatial.processes.SpatialProcess)4 Model (cbit.vcell.model.Model)4 Parameter (cbit.vcell.model.Parameter)4 ProxyParameter (cbit.vcell.model.ProxyParameter)4 Structure (cbit.vcell.model.Structure)4 ExpressionException (cbit.vcell.parser.ExpressionException)4 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)4 PropertyVetoException (java.beans.PropertyVetoException)4 MembraneMapping (cbit.vcell.mapping.MembraneMapping)3 SimulationContextParameter (cbit.vcell.mapping.SimulationContext.SimulationContextParameter)3