Search in sources :

Example 6 with VoltageClampStimulus

use of cbit.vcell.mapping.VoltageClampStimulus 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)

Example 7 with VoltageClampStimulus

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

the class StimulusTable method getSQLValueList.

/**
 * This method was created in VisualAge.
 * @return java.lang.String
 * @param key KeyValue
 * @param modelName java.lang.String
 */
public String getSQLValueList(InsertHashtable hash, KeyValue Key, KeyValue simContextKey, ElectricalStimulus stimulus) throws DataAccessException {
    KeyValue structureKey = hash.getDatabaseKey(stimulus.getElectrode().getFeature());
    if (structureKey == null) {
        structureKey = stimulus.getElectrode().getFeature().getKey();
        if (structureKey == null) {
            throw new DataAccessException("no key for structure " + stimulus.getElectrode().getFeature());
        }
    }
    Expression exp = null;
    int stimulusType = UNKNOWN_STIMULUS;
    if (stimulus instanceof CurrentDensityClampStimulus) {
        stimulusType = CURRENTDENSITY_CLAMP_STIMULUS;
        LocalParameter currentDensityParameter = ((CurrentDensityClampStimulus) stimulus).getCurrentDensityParameter();
        exp = currentDensityParameter.getExpression();
    } else if (stimulus instanceof TotalCurrentClampStimulus) {
        stimulusType = TOTALCURRENT_CLAMP_STIMULUS;
        LocalParameter totalCurrentParameter = ((TotalCurrentClampStimulus) stimulus).getCurrentParameter();
        exp = totalCurrentParameter.getExpression();
    } else if (stimulus instanceof VoltageClampStimulus) {
        stimulusType = VOLTAGE_CLAMP_STIMULUS;
        LocalParameter voltageParameter = ((VoltageClampStimulus) stimulus).getVoltageParameter();
        exp = voltageParameter.getExpression();
    } else {
        throw new DataAccessException("storage for Stimulus type " + stimulus.getClass().getName() + " not yet supported");
    }
    java.io.StringWriter esParameterWriter = new java.io.StringWriter();
    java.io.PrintWriter pw = new java.io.PrintWriter(esParameterWriter);
    stimulus.parameterVCMLWrite(pw);
    pw.flush();
    pw.close();
    StringBuffer buffer = new StringBuffer();
    buffer.append("(");
    buffer.append(Key + ",");
    buffer.append(structureKey + ",");
    buffer.append(simContextKey + ",");
    buffer.append("'" + stimulus.getName() + "',");
    buffer.append(stimulusType + ",");
    buffer.append("'" + TokenMangler.getSQLEscapedString(exp.infix()) + "',");
    buffer.append(stimulus.getElectrode().getPosition().getX() + ",");
    buffer.append(stimulus.getElectrode().getPosition().getY() + ",");
    buffer.append(stimulus.getElectrode().getPosition().getZ() + ",");
    buffer.append("'" + TokenMangler.getSQLEscapedString(esParameterWriter.getBuffer().toString()) + "'");
    buffer.append(")");
    return buffer.toString();
}
Also used : KeyValue(org.vcell.util.document.KeyValue) CurrentDensityClampStimulus(cbit.vcell.mapping.CurrentDensityClampStimulus) TotalCurrentClampStimulus(cbit.vcell.mapping.TotalCurrentClampStimulus) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) Expression(cbit.vcell.parser.Expression) VoltageClampStimulus(cbit.vcell.mapping.VoltageClampStimulus) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

CurrentDensityClampStimulus (cbit.vcell.mapping.CurrentDensityClampStimulus)7 TotalCurrentClampStimulus (cbit.vcell.mapping.TotalCurrentClampStimulus)7 VoltageClampStimulus (cbit.vcell.mapping.VoltageClampStimulus)7 Expression (cbit.vcell.parser.Expression)6 ElectricalStimulus (cbit.vcell.mapping.ElectricalStimulus)5 Electrode (cbit.vcell.mapping.Electrode)5 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)4 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)3 MembraneMapping (cbit.vcell.mapping.MembraneMapping)2 Feature (cbit.vcell.model.Feature)2 Model (cbit.vcell.model.Model)2 Structure (cbit.vcell.model.Structure)2 Element (org.jdom.Element)2 DataAccessException (org.vcell.util.DataAccessException)2 KeyValue (org.vcell.util.document.KeyValue)2 Edge (cbit.util.graph.Edge)1 Graph (cbit.util.graph.Graph)1 Node (cbit.util.graph.Node)1 BioModel (cbit.vcell.biomodel.BioModel)1 FeatureMapping (cbit.vcell.mapping.FeatureMapping)1