Search in sources :

Example 16 with MembraneMapping

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

the class StructureMappingTableModel method isCellEditable.

/**
 * Insert the method's description here.
 * Creation date: (2/24/01 12:27:46 AM)
 * @return boolean
 * @param rowIndex int
 * @param columnIndex int
 */
public boolean isCellEditable(int rowIndex, int columnIndex) {
    if (getGeometryContext() == null) {
        return false;
    }
    StructureMapping sm = getGeometryContext().getStructureMapping(rowIndex);
    if (bNonSpatial) {
        if (columnIndex == NONSPATIAL_COLUMN_SIZE) {
            // feature size are editable
            return true;
        }
        return false;
    } else {
        // 
        if (columnIndex == SPATIAL_COLUMN_SUBDOMAIN) {
            return ((sm instanceof FeatureMapping) || (sm instanceof MembraneMapping));
        }
        if (columnIndex == SPATIAL_COLUMN_SIZERATIO) {
            GeometryClass gc = sm.getGeometryClass();
            StructureMapping[] structureMappings = getGeometryContext().getStructureMappings(gc);
            boolean bDimensionless = sm.getUnitSizeParameter() != null && sm.getUnitSizeParameter().getUnitDefinition() != null && sm.getUnitSizeParameter().getUnitDefinition().isEquivalent(getGeometryContext().getModel().getUnitSystem().getInstance_DIMENSIONLESS());
            return (structureMappings != null && structureMappings.length > 1) || !bDimensionless;
        }
        // some boundary conditions are editable
        if ((columnIndex >= SPATIAL_COLUMN_X_MINUS) && (columnIndex <= SPATIAL_COLUMN_Z_PLUS)) {
            if (sm.getGeometryClass() instanceof SurfaceClass) {
                return false;
            }
            return true;
        }
    }
    return false;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) MembraneMapping(cbit.vcell.mapping.MembraneMapping) FeatureMapping(cbit.vcell.mapping.FeatureMapping) SurfaceClass(cbit.vcell.geometry.SurfaceClass) StructureMapping(cbit.vcell.mapping.StructureMapping)

Example 17 with MembraneMapping

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

the class ElectricalMembraneMappingTableModel method setValueAt.

public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    MembraneMapping membraneMapping = getValueAt(rowIndex);
    switch(columnIndex) {
        case COLUMN_CALCULATE_POTENTIAL:
            {
                boolean bCalculatePotential = ((Boolean) aValue).booleanValue();
                membraneMapping.setCalculateVoltage(bCalculatePotential);
                fireTableRowsUpdated(rowIndex, rowIndex);
                break;
            }
        case COLUMN_INITIAL_POTENTIAL:
            {
                Expression newExpression = null;
                try {
                    if (aValue instanceof String) {
                        String newExpressionString = (String) aValue;
                        newExpression = new Expression(newExpressionString);
                    }
                    membraneMapping.getInitialVoltageParameter().setExpression(newExpression);
                    fireTableRowsUpdated(rowIndex, rowIndex);
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
                }
                break;
            }
        case COLUMN_SPECIFIC_CAPACITANCE:
            {
                Expression newExpression = null;
                try {
                    if (aValue instanceof String) {
                        String newExpressionString = (String) aValue;
                        newExpression = new Expression(newExpressionString);
                    } else if (aValue instanceof ScopedExpression) {
                        // newExpression = ((ScopedExpression)aValue).getExpression();
                        throw new RuntimeException("unexpected value type ScopedExpression");
                    }
                    membraneMapping.getSpecificCapacitanceParameter().setExpression(newExpression);
                    fireTableRowsUpdated(rowIndex, rowIndex);
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
                }
                break;
            }
    }
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) ScopedExpression(cbit.gui.ScopedExpression) ScopedExpression(cbit.gui.ScopedExpression) Expression(cbit.vcell.parser.Expression) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 18 with MembraneMapping

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

the class ElectricalMembraneMappingTableModel method setGeometryContext.

/**
 * Sets the geometryContext property (cbit.vcell.mapping.GeometryContext) value.
 * @param geometryContext The new value for the property.
 * @see #getGeometryContext
 */
public void setGeometryContext(GeometryContext geometryContext) {
    GeometryContext oldValue = fieldGeometryContext;
    if (oldValue != null) {
        oldValue.removePropertyChangeListener(this);
        StructureMapping[] oldStructureMappings = oldValue.getStructureMappings();
        for (int i = 0; i < oldStructureMappings.length; i++) {
            if (oldStructureMappings[i] instanceof MembraneMapping) {
                oldStructureMappings[i].removePropertyChangeListener(this);
            }
        }
    }
    fieldGeometryContext = geometryContext;
    if (geometryContext != null) {
        geometryContext.addPropertyChangeListener(this);
        StructureMapping[] newStructureMappings = geometryContext.getStructureMappings();
        for (int i = 0; i < newStructureMappings.length; i++) {
            if (newStructureMappings[i] instanceof MembraneMapping) {
                newStructureMappings[i].addPropertyChangeListener(this);
            }
        }
    }
    refreshData();
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) GeometryContext(cbit.vcell.mapping.GeometryContext) StructureMapping(cbit.vcell.mapping.StructureMapping)

Example 19 with MembraneMapping

use of cbit.vcell.mapping.MembraneMapping 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 20 with MembraneMapping

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

the class ElectricalCircuitGraph method getTotalMembraneCurrent.

/**
 * Insert the method's description here.
 * Creation date: (2/19/2002 12:56:13 PM)
 * @return cbit.vcell.parser.Expression
 * @param simContext cbit.vcell.mapping.SimulationContext
 * @param membrane cbit.vcell.model.Membrane
 */
private static Expression getTotalMembraneCurrent(SimulationContext simContext, Membrane membrane, AbstractMathMapping mathMapping) throws ExpressionException {
    MembraneMapping membraneMapping = (MembraneMapping) simContext.getGeometryContext().getStructureMapping(membrane);
    if (!membraneMapping.getCalculateVoltage()) {
        return new Expression(0.0);
    }
    // 
    // gather current terms
    // 
    Expression currentExp = new Expression(0.0);
    ReactionSpec[] reactionSpecs = simContext.getReactionContext().getReactionSpecs();
    StructureMappingParameter sizeParameter = membraneMapping.getSizeParameter();
    Expression area = null;
    if (simContext.getGeometry().getDimension() == 0 && (sizeParameter.getExpression() == null || sizeParameter.getExpression().isZero())) {
        System.out.println("size not set for membrane \"" + membrane.getName() + "\", refer to Structure Mapping in Application \"" + mathMapping.getSimulationContext().getName() + "\"");
        area = membraneMapping.getNullSizeParameterValue();
    } else {
        area = new Expression(sizeParameter, mathMapping.getNameScope());
    }
    for (int i = 0; i < reactionSpecs.length; i++) {
        // 
        if (reactionSpecs[i].isExcluded()) {
            continue;
        }
        if (reactionSpecs[i].getReactionStep().getKinetics() instanceof DistributedKinetics) {
            ReactionStep rs = reactionSpecs[i].getReactionStep();
            DistributedKinetics distributedKinetics = (DistributedKinetics) rs.getKinetics();
            if (rs.getStructure() == membrane) {
                if (!distributedKinetics.getCurrentDensityParameter().getExpression().isZero()) {
                    // 
                    // change sign convension from inward current to outward current (which is consistent with voltage convension)
                    // 
                    currentExp = Expression.add(currentExp, Expression.negate(Expression.mult(new Expression(distributedKinetics.getCurrentDensityParameter(), mathMapping.getNameScope()), area)));
                }
            }
        } else {
            ReactionStep rs = reactionSpecs[i].getReactionStep();
            LumpedKinetics lumpedKinetics = (LumpedKinetics) rs.getKinetics();
            if (rs.getStructure() == membrane) {
                if (!lumpedKinetics.getLumpedCurrentParameter().getExpression().isZero()) {
                    // 
                    if (!(membraneMapping.getGeometryClass() instanceof CompartmentSubVolume)) {
                        throw new RuntimeException("math generation for total currents within spatial electrophysiology not yet implemented");
                    }
                    Expression lumpedCurrentSymbolExp = new Expression(lumpedKinetics.getLumpedCurrentParameter(), mathMapping.getNameScope());
                    currentExp = Expression.add(currentExp, Expression.negate(lumpedCurrentSymbolExp));
                }
            }
        }
    }
    return currentExp.flatten();
}
Also used : DistributedKinetics(cbit.vcell.model.DistributedKinetics) MembraneMapping(cbit.vcell.mapping.MembraneMapping) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) LumpedKinetics(cbit.vcell.model.LumpedKinetics) Expression(cbit.vcell.parser.Expression) ReactionSpec(cbit.vcell.mapping.ReactionSpec) ReactionStep(cbit.vcell.model.ReactionStep) StructureMappingParameter(cbit.vcell.mapping.StructureMapping.StructureMappingParameter)

Aggregations

MembraneMapping (cbit.vcell.mapping.MembraneMapping)32 Expression (cbit.vcell.parser.Expression)24 Membrane (cbit.vcell.model.Membrane)20 FeatureMapping (cbit.vcell.mapping.FeatureMapping)17 StructureMapping (cbit.vcell.mapping.StructureMapping)17 Feature (cbit.vcell.model.Feature)14 Structure (cbit.vcell.model.Structure)13 ExpressionException (cbit.vcell.parser.ExpressionException)11 SubVolume (cbit.vcell.geometry.SubVolume)10 Model (cbit.vcell.model.Model)9 StructureTopology (cbit.vcell.model.Model.StructureTopology)9 SpeciesContext (cbit.vcell.model.SpeciesContext)9 SurfaceClass (cbit.vcell.geometry.SurfaceClass)8 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)8 ReactionSpec (cbit.vcell.mapping.ReactionSpec)7 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)7 StructureMappingParameter (cbit.vcell.mapping.StructureMapping.StructureMappingParameter)7 PropertyVetoException (java.beans.PropertyVetoException)6 ImageException (cbit.image.ImageException)5 GeometryClass (cbit.vcell.geometry.GeometryClass)5