Search in sources :

Example 11 with Electrode

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

the class SimulationContextDbDriver method assignStimuliSQL.

/**
 * This method was created in VisualAge.
 * @param simContext cbit.vcell.mapping.SimulationContext
 */
private void assignStimuliSQL(Connection con, KeyValue simContextKey, SimulationContext simContext) throws SQLException, DataAccessException {
    String sql;
    sql = " SELECT " + "*" + " FROM " + stimulusTable.getTableName() + " WHERE " + stimulusTable.simContextRef + " = " + simContextKey;
    Statement stmt = con.createStatement();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        while (rset.next()) {
            try {
                // KeyValue key = new KeyValue(rset.getBigDecimal(stimulusTable.id.toString()));
                KeyValue structureRef = new KeyValue(rset.getBigDecimal(stimulusTable.structRef.toString()));
                // KeyValue simContextRef = new KeyValue(rset.getBigDecimal(stimulusTable.simContextRef.toString()));
                // 
                // lookup structure from SimulationContext by its key
                // 
                // DBCache will not always give same instance consistently (usually this is
                // fixed up later in the ReferenceResolver at the Client).
                // 
                Structure theStructure = null;
                Structure[] structureArray = simContext.getModel().getStructures();
                for (int i = 0; i < structureArray.length; i++) {
                    Structure structure = structureArray[i];
                    if (structure.getKey().compareEqual(structureRef)) {
                        theStructure = structure;
                        break;
                    }
                }
                String name = rset.getString(stimulusTable.name.toString());
                if (rset.wasNull()) {
                    name = null;
                }
                int stimulusType = rset.getInt(stimulusTable.stimulusType.toString());
                Expression exp = null;
                String expString = rset.getString(stimulusTable.expression.toString());
                if (rset.wasNull()) {
                    exp = null;
                } else {
                    exp = new Expression(TokenMangler.getSQLRestoredString(expString));
                }
                double posX = rset.getBigDecimal(stimulusTable.positionX.toString()).doubleValue();
                double posY = rset.getBigDecimal(stimulusTable.positionY.toString()).doubleValue();
                double posZ = rset.getBigDecimal(stimulusTable.positionZ.toString()).doubleValue();
                org.vcell.util.CommentStringTokenizer paramsCST = null;
                String paramsS = rset.getString(StimulusTable.table.params.toString());
                if (!rset.wasNull()) {
                    paramsCST = new org.vcell.util.CommentStringTokenizer(org.vcell.util.TokenMangler.getSQLRestoredString(paramsS));
                }
                if (stimulusType == StimulusTable.GROUND_ELECTRODE) {
                    // 
                    // an Electrode (ground)
                    // 
                    Electrode groundElectrode = new Electrode((Feature) theStructure, new org.vcell.util.Coordinate(posX, posY, posZ));
                    simContext.setGroundElectrode(groundElectrode);
                } else if (stimulusType == StimulusTable.TOTALCURRENT_CLAMP_STIMULUS) {
                    Electrode electrode = new Electrode((Feature) theStructure, new org.vcell.util.Coordinate(posX, posY, posZ));
                    TotalCurrentClampStimulus stimulus = new TotalCurrentClampStimulus(electrode, name, exp, simContext);
                    stimulus.parameterVCMLSet(paramsCST);
                    ElectricalStimulus[] newStimuli = (ElectricalStimulus[]) org.vcell.util.BeanUtils.addElement(simContext.getElectricalStimuli(), stimulus);
                    simContext.setElectricalStimuli(newStimuli);
                } else if (stimulusType == StimulusTable.CURRENTDENSITY_CLAMP_STIMULUS) {
                    Electrode electrode = new Electrode((Feature) theStructure, new org.vcell.util.Coordinate(posX, posY, posZ));
                    CurrentDensityClampStimulus stimulus = new CurrentDensityClampStimulus(electrode, name, exp, simContext);
                    stimulus.parameterVCMLSet(paramsCST);
                    ElectricalStimulus[] newStimuli = (ElectricalStimulus[]) org.vcell.util.BeanUtils.addElement(simContext.getElectricalStimuli(), stimulus);
                    simContext.setElectricalStimuli(newStimuli);
                } else if (stimulusType == StimulusTable.VOLTAGE_CLAMP_STIMULUS) {
                    Electrode electrode = new Electrode((Feature) theStructure, new org.vcell.util.Coordinate(posX, posY, posZ));
                    VoltageClampStimulus stimulus = new VoltageClampStimulus(electrode, name, exp, simContext);
                    stimulus.parameterVCMLSet(paramsCST);
                    ElectricalStimulus[] newStimuli = (ElectricalStimulus[]) org.vcell.util.BeanUtils.addElement(simContext.getElectricalStimuli(), stimulus);
                    simContext.setElectricalStimuli(newStimuli);
                } else {
                    throw new DataAccessException("unknown stimulusType <" + stimulusType + ">");
                }
            } catch (ExpressionException | PropertyVetoException e) {
                lg.error(e.getMessage(), e);
            }
        }
    } finally {
        stmt.close();
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) Feature(cbit.vcell.model.Feature) TotalCurrentClampStimulus(cbit.vcell.mapping.TotalCurrentClampStimulus) ExpressionException(cbit.vcell.parser.ExpressionException) VoltageClampStimulus(cbit.vcell.mapping.VoltageClampStimulus) ResultSet(java.sql.ResultSet) Structure(cbit.vcell.model.Structure) DataAccessException(org.vcell.util.DataAccessException) Electrode(cbit.vcell.mapping.Electrode) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CurrentDensityClampStimulus(cbit.vcell.mapping.CurrentDensityClampStimulus) PropertyVetoException(java.beans.PropertyVetoException) ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus) Expression(cbit.vcell.parser.Expression)

Aggregations

Electrode (cbit.vcell.mapping.Electrode)11 ElectricalStimulus (cbit.vcell.mapping.ElectricalStimulus)8 CurrentDensityClampStimulus (cbit.vcell.mapping.CurrentDensityClampStimulus)6 TotalCurrentClampStimulus (cbit.vcell.mapping.TotalCurrentClampStimulus)6 VoltageClampStimulus (cbit.vcell.mapping.VoltageClampStimulus)6 Expression (cbit.vcell.parser.Expression)6 Feature (cbit.vcell.model.Feature)5 Structure (cbit.vcell.model.Structure)4 MembraneMapping (cbit.vcell.mapping.MembraneMapping)3 Model (cbit.vcell.model.Model)3 ExpressionException (cbit.vcell.parser.ExpressionException)3 PropertyVetoException (java.beans.PropertyVetoException)3 Edge (cbit.util.graph.Edge)2 Graph (cbit.util.graph.Graph)2 Node (cbit.util.graph.Node)2 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)2 SimulationContext (cbit.vcell.mapping.SimulationContext)2 StructureMapping (cbit.vcell.mapping.StructureMapping)2 MathException (cbit.vcell.math.MathException)2 Membrane (cbit.vcell.model.Membrane)2