Search in sources :

Example 21 with LocalParameter

use of cbit.vcell.mapping.ParameterContext.LocalParameter 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 22 with LocalParameter

use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.

the class ElectricalStimulusParameterTableModel method setValueAt.

public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    if (columnIndex < 0 || columnIndex >= getColumnCount()) {
        throw new RuntimeException("ParameterTableModel.setValueAt(), column = " + columnIndex + " out of range [" + 0 + "," + (getColumnCount() - 1) + "]");
    }
    Parameter parameter = getValueAt(rowIndex);
    // try {
    switch(columnIndex) {
        case COLUMN_VALUE:
            {
                try {
                    String newExpressionString = (String) aValue;
                    if (parameter instanceof LocalParameter) {
                        LocalParameter scsParm = (LocalParameter) parameter;
                        getElectricalStimulus().setParameterValue(scsParm, new Expression(newExpressionString));
                    // fireTableRowsUpdated(rowIndex,rowIndex);
                    }
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, e.getMessage(), e);
                }
                break;
            }
        case COLUMN_NAME:
            {
                try {
                    getElectricalStimulus().renameParameter(parameter.getName(), (String) aValue);
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, e.getMessage(), e);
                }
            }
    }
// }catch (java.beans.PropertyVetoException e){
// e.printStackTrace(System.out);
// }
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) ScopedExpression(cbit.gui.ScopedExpression) Expression(cbit.vcell.parser.Expression) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) Parameter(cbit.vcell.model.Parameter) ProxyParameter(cbit.vcell.model.ProxyParameter) ExpressionException(cbit.vcell.parser.ExpressionException) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 23 with LocalParameter

use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.

the class CurrentClampElectricalDevice method initializeParameters.

private void initializeParameters() throws ExpressionException {
    ElectricalDevice.ElectricalDeviceParameter[] parameters = new ElectricalDevice.ElectricalDeviceParameter[3];
    // 
    // set the transmembrane current (total current, if necessary derive it from the current density).
    // 
    ElectricalDeviceParameter transMembraneCurrent = null;
    ModelUnitSystem modelUnitSystem = mathMapping.getSimulationContext().getModel().getUnitSystem();
    VCUnitDefinition currentUnit = modelUnitSystem.getCurrentUnit();
    if (currentClampStimulus instanceof TotalCurrentClampStimulus) {
        TotalCurrentClampStimulus stimulus = (TotalCurrentClampStimulus) currentClampStimulus;
        LocalParameter currentParameter = stimulus.getCurrentParameter();
        transMembraneCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TransmembraneCurrent], new Expression(currentParameter.getExpression()), ROLE_TransmembraneCurrent, currentUnit);
    } else if (currentClampStimulus instanceof CurrentDensityClampStimulus) {
        CurrentDensityClampStimulus stimulus = (CurrentDensityClampStimulus) currentClampStimulus;
        LocalParameter currentDensityParameter = stimulus.getCurrentDensityParameter();
        // 
        // here we have to determine the expression for current (from current density).
        // 
        Feature feature1 = currentClampStimulus.getElectrode().getFeature();
        Feature feature2 = mathMapping.getSimulationContext().getGroundElectrode().getFeature();
        Membrane membrane = null;
        StructureTopology structTopology = mathMapping.getSimulationContext().getModel().getStructureTopology();
        if (structTopology.getParentStructure(feature1) != null && structTopology.getOutsideFeature((Membrane) structTopology.getParentStructure(feature1)) == feature2) {
            membrane = ((Membrane) structTopology.getParentStructure(feature1));
        } else if (structTopology.getParentStructure(feature2) != null && structTopology.getOutsideFeature((Membrane) structTopology.getParentStructure(feature2)) == feature1) {
            membrane = ((Membrane) structTopology.getParentStructure(feature2));
        }
        if (membrane == null) {
            throw new RuntimeException("current clamp based on current density crosses multiple membranes, unable to " + "determine single membrane to convert current density into current in Application '" + mathMapping.getSimulationContext().getName() + "'.");
        }
        MembraneMapping membraneMapping = (MembraneMapping) mathMapping.getSimulationContext().getGeometryContext().getStructureMapping(membrane);
        StructureMappingParameter sizeParameter = membraneMapping.getSizeParameter();
        Expression area = null;
        if (mathMapping.getSimulationContext().getGeometry().getDimension() == 0 && (sizeParameter.getExpression() == null || sizeParameter.getExpression().isZero())) {
            area = membraneMapping.getNullSizeParameterValue();
        } else {
            area = new Expression(sizeParameter, mathMapping.getNameScope());
        }
        transMembraneCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TransmembraneCurrent], Expression.mult(new Expression(currentDensityParameter.getExpression()), area), ROLE_TransmembraneCurrent, currentUnit);
    } else {
        throw new RuntimeException("unexpected current clamp stimulus type : " + currentClampStimulus.getClass().getName());
    }
    ElectricalDeviceParameter totalCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TotalCurrent], new Expression(transMembraneCurrent, getNameScope()), ROLE_TotalCurrent, currentUnit);
    ElectricalDeviceParameter voltage = new ElectricalDeviceParameter(DefaultNames[ROLE_Voltage], null, ROLE_Voltage, modelUnitSystem.getVoltageUnit());
    parameters[0] = totalCurrent;
    parameters[1] = transMembraneCurrent;
    parameters[2] = voltage;
    // 
    // add any user-defined parameters
    // 
    LocalParameter[] stimulusParameters = currentClampStimulus.getLocalParameters();
    for (int i = 0; stimulusParameters != null && i < stimulusParameters.length; i++) {
        if (stimulusParameters[i].getRole() == ElectricalStimulus.ElectricalStimulusParameterType.UserDefined) {
            ElectricalDeviceParameter newParam = new ElectricalDeviceParameter(stimulusParameters[i].getName(), new Expression(stimulusParameters[i].getExpression()), ROLE_UserDefined, stimulusParameters[i].getUnitDefinition());
            parameters = (ElectricalDeviceParameter[]) BeanUtils.addElement(parameters, newParam);
        }
    }
    setParameters(parameters);
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) StructureTopology(cbit.vcell.model.Model.StructureTopology) CurrentDensityClampStimulus(cbit.vcell.mapping.CurrentDensityClampStimulus) StructureMappingParameter(cbit.vcell.mapping.StructureMapping.StructureMappingParameter) TotalCurrentClampStimulus(cbit.vcell.mapping.TotalCurrentClampStimulus) Feature(cbit.vcell.model.Feature) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Membrane(cbit.vcell.model.Membrane) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 24 with LocalParameter

use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.

the class CurrentClampElectricalDevice method initializeParameters.

private void initializeParameters() throws ExpressionException {
    ElectricalDevice.ElectricalDeviceParameter[] parameters = new ElectricalDevice.ElectricalDeviceParameter[3];
    // 
    // set the transmembrane current (total current, if necessary derive it from the current density).
    // 
    ElectricalDeviceParameter transMembraneCurrent = null;
    ModelUnitSystem modelUnitSystem = mathMapping_4_8.getSimulationContext().getModel().getUnitSystem();
    VCUnitDefinition currentUnit = modelUnitSystem.getCurrentUnit();
    if (currentClampStimulus instanceof TotalCurrentClampStimulus) {
        TotalCurrentClampStimulus stimulus = (TotalCurrentClampStimulus) currentClampStimulus;
        LocalParameter currentParameter = stimulus.getCurrentParameter();
        transMembraneCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TransmembraneCurrent], new Expression(currentParameter.getExpression()), ROLE_TransmembraneCurrent, currentUnit);
    } else if (currentClampStimulus instanceof CurrentDensityClampStimulus) {
        CurrentDensityClampStimulus stimulus = (CurrentDensityClampStimulus) currentClampStimulus;
        LocalParameter currentDensityParameter = stimulus.getCurrentDensityParameter();
        // 
        // here we have to determine the expression for current (from current density).
        // 
        Feature feature1 = currentClampStimulus.getElectrode().getFeature();
        Feature feature2 = mathMapping_4_8.getSimulationContext().getGroundElectrode().getFeature();
        Membrane membrane = null;
        StructureTopology structTopology = mathMapping_4_8.getSimulationContext().getModel().getStructureTopology();
        if (structTopology.getParentStructure(feature1) != null && structTopology.getOutsideFeature((Membrane) structTopology.getParentStructure(feature1)) == feature2) {
            membrane = ((Membrane) structTopology.getParentStructure(feature1));
        } else if (structTopology.getParentStructure(feature2) != null && structTopology.getOutsideFeature((Membrane) structTopology.getParentStructure(feature2)) == feature1) {
            membrane = ((Membrane) structTopology.getParentStructure(feature2));
        }
        if (membrane == null) {
            throw new RuntimeException("current clamp based on current density crosses multiple membranes, unable to " + "determine single membrane to convert current density into current in Application '" + mathMapping_4_8.getSimulationContext().getName() + "'.");
        }
        MembraneMapping membraneMapping = (MembraneMapping) mathMapping_4_8.getSimulationContext().getGeometryContext().getStructureMapping(membrane);
        StructureMappingParameter sizeParameter = membraneMapping.getSizeParameter();
        Expression area = null;
        if (mathMapping_4_8.getSimulationContext().getGeometry().getDimension() == 0 && (sizeParameter.getExpression() == null || sizeParameter.getExpression().isZero())) {
            area = membraneMapping.getNullSizeParameterValue();
        } else {
            area = new Expression(sizeParameter, mathMapping_4_8.getNameScope());
        }
        transMembraneCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TransmembraneCurrent], Expression.mult(new Expression(currentDensityParameter.getExpression()), area), ROLE_TransmembraneCurrent, currentUnit);
    } else {
        throw new RuntimeException("unexpected current clamp stimulus type : " + currentClampStimulus.getClass().getName());
    }
    ElectricalDeviceParameter totalCurrent = new ElectricalDeviceParameter(DefaultNames[ROLE_TotalCurrent], new Expression(transMembraneCurrent, getNameScope()), ROLE_TotalCurrent, currentUnit);
    ElectricalDeviceParameter voltage = new ElectricalDeviceParameter(DefaultNames[ROLE_Voltage], null, ROLE_Voltage, modelUnitSystem.getVoltageUnit());
    parameters[0] = totalCurrent;
    parameters[1] = transMembraneCurrent;
    parameters[2] = voltage;
    // 
    // add any user-defined parameters
    // 
    LocalParameter[] stimulusParameters = currentClampStimulus.getLocalParameters();
    for (int i = 0; stimulusParameters != null && i < stimulusParameters.length; i++) {
        if (stimulusParameters[i].getRole() == ElectricalStimulus.ElectricalStimulusParameterType.UserDefined) {
            ElectricalDeviceParameter newParam = new ElectricalDeviceParameter(stimulusParameters[i].getName(), new Expression(stimulusParameters[i].getExpression()), ROLE_UserDefined, stimulusParameters[i].getUnitDefinition());
            parameters = (ElectricalDeviceParameter[]) BeanUtils.addElement(parameters, newParam);
        }
    }
    setParameters(parameters);
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) StructureTopology(cbit.vcell.model.Model.StructureTopology) CurrentDensityClampStimulus(cbit.vcell.mapping.CurrentDensityClampStimulus) StructureMappingParameter(cbit.vcell.mapping.StructureMapping.StructureMappingParameter) TotalCurrentClampStimulus(cbit.vcell.mapping.TotalCurrentClampStimulus) Feature(cbit.vcell.model.Feature) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Membrane(cbit.vcell.model.Membrane) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 25 with LocalParameter

use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.

the class ElectricalStimulus method setParameterValue.

/**
 * This method was created by a SmartGuide.
 * @param expressionString java.lang.String
 * @exception java.lang.Exception The exception description.
 */
public void setParameterValue(LocalParameter parm, Expression exp) throws ExpressionException, PropertyVetoException {
    Parameter p = parameterContext.getLocalParameterFromName(parm.getName());
    if (p != parm) {
        throw new RuntimeException("parameter " + parm.getName() + " not found");
    }
    Expression oldExpression = parm.getExpression();
    boolean bBound = false;
    try {
        LocalParameter[] newLocalParameters = (LocalParameter[]) parameterContext.getLocalParameters().clone();
        String[] symbols = exp.getSymbols();
        Vector<String> symbolsToAdd = new Vector<String>();
        for (int i = 0; symbols != null && i < symbols.length; i++) {
            if (parameterContext.getEntry(symbols[i]) == null) {
                symbolsToAdd.add(symbols[i]);
            }
        }
        ModelUnitSystem modelUnitSystem = simulationContext.getModel().getUnitSystem();
        for (int i = 0; i < symbolsToAdd.size(); i++) {
            newLocalParameters = (LocalParameter[]) BeanUtils.addElement(newLocalParameters, parameterContext.new LocalParameter(symbolsToAdd.elementAt(i), new Expression(0.0), ElectricalStimulusParameterType.UserDefined, modelUnitSystem.getInstance_TBD(), ElectricalStimulusParameterType.UserDefined.databaseRoleTag));
        }
        parameterContext.setLocalParameters(newLocalParameters);
        exp.bindExpression(parameterContext);
        parm.setExpression(exp);
        bBound = true;
    } finally {
        try {
            if (!bBound) {
                parm.setExpression(oldExpression);
            }
            parameterContext.cleanupParameters();
        } catch (PropertyVetoException e) {
            e.printStackTrace(System.out);
            throw new RuntimeException(e.getMessage());
        }
    }
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) PropertyVetoException(java.beans.PropertyVetoException) Expression(cbit.vcell.parser.Expression) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) Parameter(cbit.vcell.model.Parameter) Vector(java.util.Vector) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Aggregations

LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)45 Expression (cbit.vcell.parser.Expression)31 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)17 PropertyVetoException (java.beans.PropertyVetoException)12 ModelParameter (cbit.vcell.model.Model.ModelParameter)11 SpeciesContext (cbit.vcell.model.SpeciesContext)11 ExpressionException (cbit.vcell.parser.ExpressionException)11 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)9 Parameter (cbit.vcell.model.Parameter)9 ArrayList (java.util.ArrayList)9 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)8 Element (org.jdom.Element)8 ProxyParameter (cbit.vcell.model.ProxyParameter)7 CurrentDensityClampStimulus (cbit.vcell.mapping.CurrentDensityClampStimulus)6 LocalProxyParameter (cbit.vcell.mapping.ParameterContext.LocalProxyParameter)6 TotalCurrentClampStimulus (cbit.vcell.mapping.TotalCurrentClampStimulus)6 Model (cbit.vcell.model.Model)6 ElectricalStimulus (cbit.vcell.mapping.ElectricalStimulus)5 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)5 Domain (cbit.vcell.math.Variable.Domain)5