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();
}
}
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();
}
Aggregations