use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class SimulationJobTable method getSimulationJobStatus.
/**
* This method was created in VisualAge.
* @return VCImage
* @param rset ResultSet
* @param log SessionLog
*/
public SimulationJobStatusPersistent getSimulationJobStatus(ResultSet rset) throws SQLException {
// serverid
String serID = rset.getString(this.serverID.toString());
if (rset.wasNull()) {
serID = null;
}
// simRef
KeyValue parsedSimKey = new KeyValue(rset.getBigDecimal(simRef.toString()));
// userKey
KeyValue userKey = new KeyValue(rset.getBigDecimal(SimulationTable.table.ownerRef.toString()));
// userKey
String userid = rset.getString(UserTable.table.userid.toString());
org.vcell.util.document.User owner = new org.vcell.util.document.User(userid, userKey);
// submitDate
java.util.Date parsedSubmitDate = rset.getTimestamp(submitDate.toString());
// taskID
int parsedTaskID = rset.getInt(taskID.toString());
// schedulerStatus
int parsedSchedulerStatusInt = rset.getInt(schedulerStatus.toString());
SchedulerStatus parsedSchedulerStatus = SchedulerStatus.fromDatabaseNumber(parsedSchedulerStatusInt);
// statusMsg
String parsedStatusMsg = TokenMangler.getSQLRestoredString(rset.getString(statusMsg.toString()));
SimulationMessagePersistent simulationMessage = SimulationMessagePersistent.fromSerialized(parsedSchedulerStatus, parsedStatusMsg);
//
// read queue stuff
//
// queueDate
java.util.Date parsedQueuedDate = rset.getTimestamp(queueDate.toString());
// queuePriority
int parsedQueuePriority = rset.getInt(queuePriority.toString());
if (rset.wasNull()) {
parsedQueuePriority = -1;
}
// queueID
int parsedQueueID = rset.getInt(queueID.toString());
if (rset.wasNull()) {
parsedQueueID = -1;
}
SimulationJobStatusPersistent.SimulationQueueID simulationQueueID = SimulationJobStatusPersistent.SimulationQueueID.fromDatabaseNumber(parsedQueueID);
SimulationQueueEntryStatusPersistent simQueueEntryStatus = new SimulationQueueEntryStatusPersistent(parsedQueuedDate, parsedQueuePriority, simulationQueueID);
//
// read solver stuff
//
// startDate
java.util.Date parsedStartDate = rset.getTimestamp(startDate.toString());
// computeHost
String parsedComputeHost = rset.getString(computeHost.toString());
// latestUpdateDate
java.util.Date parsedLatestUpdateDate = rset.getTimestamp(latestUpdateDate.toString());
// endDate
java.util.Date parsedEndDate = rset.getTimestamp(endDate.toString());
// hasData
String parsedHasData = rset.getString(hasData.toString());
HtcJobID parsedHtcJobID = null;
String htcJobIDString = rset.getString(pbsJobID.toString());
if (!rset.wasNull() && htcJobIDString != null && htcJobIDString.length() > 0) {
parsedHtcJobID = SimulationJobTable.fromDatabase(htcJobIDString);
}
SimulationExecutionStatusPersistent simExeStatus = new SimulationExecutionStatusPersistent(parsedStartDate, parsedComputeHost, parsedLatestUpdateDate, parsedEndDate, parsedHasData != null, parsedHtcJobID);
VCSimulationIdentifier parsedVCSimID = new VCSimulationIdentifier(parsedSimKey, owner);
// jobIndex
int parsedJobIndex = rset.getInt(jobIndex.toString());
SimulationJobStatusPersistent simulationJobStatus = new SimulationJobStatusPersistent(VCellServerID.getServerID(serID), parsedVCSimID, parsedJobIndex, parsedSubmitDate, parsedSchedulerStatus, parsedTaskID, simulationMessage, simQueueEntryStatus, simExeStatus);
// sysDate
java.util.Date parsedSysDate = rset.getTimestamp(DatabaseConstants.SYSDATE_COLUMN_NAME);
if (!rset.wasNull()) {
simulationJobStatus.setTimeDateStamp(parsedSysDate);
}
return simulationJobStatus;
}
use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class EstParams_ReacBindingPanel method simulateWithCurrentParameters.
private // used by reaction binding panel only. not used by VFRAP 1.1 though
void simulateWithCurrentParameters() {
fStudy = getFrapWorkspace().getWorkingFrapStudy();
// save external files if needed
AsynchClientTask saveTask = new AsynchClientTask("Preparing to run simulation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
// check external data before running simulation
if (!FRAPWorkspace.areExternalDataOK(getLocalWorkspace(), fStudy.getFrapDataExternalDataInfo(), fStudy.getRoiExternalDataInfo())) {
// if external files are missing/currupt or ROIs are changed, create keys and save them
fStudy.setFrapDataExternalDataInfo(FRAPStudy.createNewExternalDataInfo(getLocalWorkspace(), FRAPStudy.IMAGE_EXTDATA_NAME));
fStudy.setRoiExternalDataInfo(FRAPStudy.createNewExternalDataInfo(getLocalWorkspace(), FRAPStudy.ROI_EXTDATA_NAME));
try {
fStudy.saveROIsAsExternalData(getLocalWorkspace(), fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
fStudy.saveImageDatasetAsExternalData(getLocalWorkspace(), fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
// run simulation task
AsynchClientTask runSimTask = new AsynchClientTask("Running simulation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
BioModel bioModel = null;
KeyValue simKey = null;
// }
try {
bioModel = FRAPStudy.createNewSimBioModel(fStudy, getCurrentParameters(), null, LocalWorkspace.createNewKeyValue(), LocalWorkspace.getDefaultOwner(), fStudy.getStartingIndexForRecovery());
// we don't have to set the bioModel to frap study, we just need the results.
// change time bound and time step
// Simulation sim = bioModel.getSimulations()[0];
// sim.getSolverTaskDescription().setTimeBounds(getRefTimeBounds());
// sim.getSolverTaskDescription().setTimeStep(getRefTimeStep());
// sim.getSolverTaskDescription().setOutputTimeSpec(getRefTimeSpec());
// System.out.println("run FRAP Reference Simulation...");
// final double RUN_REFSIM_PROGRESS_FRACTION = 1.0;
// DataSetControllerImpl.ProgressListener runRefSimProgressListener =
// new DataSetControllerImpl.ProgressListener(){
// public void updateProgress(double progress) {
// if(progressListener != null){
// //To run to the steady state the time length is unpredictable. Progress increase 10 times
// //because we manually set ending time to 1000 and usually it will reach steady state in less than 100 seconds.
// //max allowed progress is 80%. this is heuristic.
// progressListener.updateProgress(Math.min(0.8, (progress*10)*RUN_REFSIM_PROGRESS_FRACTION));
// }
// }
// public void updateMessage(String message){
// if(progressListener != null){
// progressListener.updateMessage(message);
// }
// }
// };
// run simulation
FRAPStudy.runFVSolverStandalone(new File(getLocalWorkspace().getDefaultSimDataDirectory()), bioModel.getSimulation(0), fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), this.getClientTaskStatusSupport(), false);
/*//prepare to run native FV solver
Simulation simulation = bioModel.getSimulations()[0];
// clone and resample geometry
Geometry resampledGeometry = null;
try {
resampledGeometry = (Geometry) BeanUtils.cloneSerializable(simulation.getMathDescription().getGeometry());
GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
ISize newSize = simulation.getMeshSpecification().getSamplingSize();
geoSurfaceDesc.setVolumeSampleSize(newSize);
geoSurfaceDesc.updateAll();
} catch (Exception e) {
e.printStackTrace();
throw new SolverException(e.getMessage());
}
SimulationJob simJob = new SimulationJob(simulation, 0, null); //fielddata ID?
StringWriter simulationInputStringWriter = new StringWriter();
FiniteVolumeFileWriter fvFileWriter = new FiniteVolumeFileWriter(new PrintWriter(simulationInputStringWriter,true), simJob, resampledGeometry, new File(getLocalWorkspace().getDefaultSimDataDirectory())); //need dir?
fvFileWriter.write(null); //what are parameter names?
simulationInputStringWriter.close();
String fvInputStr = simulationInputStringWriter.getBuffer().toString();
//run simulation with native FV solver
double[][][] rawSimResults = new NativeFVSolver().solve(fvInputStr);*/
simKey = bioModel.getSimulations()[0].getVersion().getVersionKey();
} catch (Exception e) {
if (bioModel != null && bioModel.getSimulations() != null) {
FRAPStudy.removeExternalDataAndSimulationFiles(bioModel.getSimulations()[0].getVersion().getVersionKey(), null, null, getLocalWorkspace());
}
throw e;
}
// push sim key into hash table
// for all loaded file
hashTable.put(FRAPStudyPanel.SIMULATION_KEY, simKey);
}
};
// generate dimension reduced sim data
AsynchClientTask readDataTask = new AsynchClientTask("Reading simulation data ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
KeyValue simulationKey = (KeyValue) hashTable.get(FRAPStudyPanel.SIMULATION_KEY);
if (simulationKey != null) {
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simulationKey, LocalWorkspace.getDefaultOwner());
VCSimulationDataIdentifier vcSimDataID = new VCSimulationDataIdentifier(vcSimID, FieldDataFileOperationSpec.JOBINDEX_DEFAULT);
double[] rawSimTimePoints = getLocalWorkspace().getVCDataManager().getDataSetTimes(vcSimDataID);
// to store time points in frap model (simulation time points may be slightly different with exp time points)
setCurrentRawSimTimePoints(rawSimTimePoints);
// refDataTimePoints = timeShiftForBaseDiffRate(rawRefDataTimePoints);
// System.out.println("simulation done...");
// DataSetControllerImpl.ProgressListener reducedRefDataProgressListener =
// new DataSetControllerImpl.ProgressListener(){
// public void updateProgress(double progress) {
// if(progressListener != null){
// progressListener.setProgress((int)((.5+progress*(1-RUNSIM_PROGRESS_FRACTION))*100));
// }
// }
// public void updateMessage(String message){
// if(progressListener != null){
// progressListener.setMessage(message);
// }
// }
// };
double[][] results = FRAPOptimizationUtils.dataReduction(getLocalWorkspace().getVCDataManager(), vcSimDataID, rawSimTimePoints, fStudy.getFrapData().getRois(), this.getClientTaskStatusSupport(), false);
// to store data in frap model.
setCurrentSimResults(results);
System.out.println("generating dimension reduced ref data, done ....");
// remove reference simulation files
FRAPStudy.removeSimulationFiles(simulationKey, getLocalWorkspace());
}
}
};
// plot task
AsynchClientTask plotTask = new AsynchClientTask("Generating plots ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
try {
setData(fStudy.getFrapData(), getCurrentParameters(), fStudy.getFrapData().getImageDataset().getImageTimeStamps(), fStudy.getStartingIndexForRecovery(), fStudy.getSelectedROIsForErrorCalculation());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(System.out);
}
}
};
// dispatch
ClientTaskDispatcher.dispatch(EstParams_ReacBindingPanel.this, new Hashtable<String, Object>(), new AsynchClientTask[] { saveTask, runSimTask, readDataTask, plotTask }, false);
}
use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class IMGExporter method main.
public static void main(String[] args) throws Exception {
if (args.length < 7) {
System.out.println("Usage: IMGExporter username userkey simulationkey userdatadir beginTimeIndex endTimeIndex {varName1 varName2 ...}");
System.exit(0);
}
String userName = args[0];
String userKey = args[1];
String SimulationKey = args[2];
String primaryDirStr = args[3];
int beginTimeIndex = Integer.valueOf(args[4]);
int endTimeIndex = Integer.valueOf(args[5]);
String[] varNames = new String[args.length - 6];
if (args.length > 6) {
for (int i = 6; i < args.length; i++) {
varNames[i - 6] = args[i];
}
}
PropertyLoader.loadProperties();
User user = new User(userName, new KeyValue(userKey));
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(new KeyValue(SimulationKey), user);
VCSimulationDataIdentifier vcdID = new VCSimulationDataIdentifier(vcSimID, 0);
class PrintingExportServiceImpl extends ExportServiceImpl {
public PrintingExportServiceImpl() {
super();
}
@Override
protected void fireExportEvent(ExportEvent event) {
super.fireExportEvent(event);
System.out.println("Event type=" + event.getEventTypeID() + " JobID=" + event.getJobID() + " progress=" + event.getProgress());
}
}
ExportServiceImpl exportServiceImpl = new PrintingExportServiceImpl();
Cachetable cachetable = new Cachetable(10 * Cachetable.minute);
File primaryDir = new File(primaryDirStr);
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(cachetable, primaryDir, null);
DataServerImpl dataServerImpl = new DataServerImpl(dataSetControllerImpl, exportServiceImpl);
double[] allTimes = dataSetControllerImpl.getDataSetTimes(vcdID);
TimeSpecs timeSpecs = new TimeSpecs(beginTimeIndex, endTimeIndex, allTimes, ExportConstants.TIME_RANGE);
VariableSpecs variableSpecs = new VariableSpecs(varNames, ExportConstants.VARIABLE_MULTI);
GeometrySpecs geometrySpecs = new GeometrySpecs(null, 0, 0, ExportConstants.GEOMETRY_SLICE);
DisplayPreferences displayPreferences = new DisplayPreferences(DisplayAdapterService.BLUERED, new Range(0, 1), DisplayAdapterService.createBlueRedSpecialColors());
MovieSpecs movieSpecs = new MovieSpecs(// /
1000.0, // /
false, // /
new DisplayPreferences[] { displayPreferences }, // /
ExportFormat.FORMAT_JPEG, // /
0, // /
1, // /
1, // /
1, ImagePaneModel.MESH_MODE, FormatSpecificSpecs.CODEC_JPEG, 1.0f, false, FormatSpecificSpecs.PARTICLE_SELECT);
ExportSpecs exportSpecs = new ExportSpecs(vcdID, ExportFormat.QUICKTIME, variableSpecs, timeSpecs, geometrySpecs, movieSpecs, "IMGExporterTest", null);
exportServiceImpl.makeRemoteFile(null, user, dataServerImpl, exportSpecs);
}
use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class SimulationJobStatusEvent method fromJsonRep.
public static SimulationJobStatusEvent fromJsonRep(Object eventSource, SimulationJobStatusEventRepresentation eventRep) {
String simid = Simulation.createSimulationID(new KeyValue(eventRep.jobStatus.simulationKey));
int jobIndex = eventRep.jobStatus.jobIndex;
int taskID = eventRep.jobStatus.taskID;
VCellServerID serverID = VCellServerID.getServerID(eventRep.jobStatus.vcellServerID);
KeyValue simkey = new KeyValue(eventRep.jobStatus.simulationKey);
User owner = new User(eventRep.jobStatus.owner_userid, new KeyValue(eventRep.jobStatus.onwer_userkey));
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simkey, owner);
Date submitDate = eventRep.jobStatus.submitDate;
SchedulerStatus schedulerStatus = null;
if (eventRep.jobStatus.schedulerStatus != null) {
schedulerStatus = SchedulerStatus.valueOf(eventRep.jobStatus.schedulerStatus.name());
}
HtcJobID htcJobID = null;
Long htcJobNumber = eventRep.jobStatus.htcJobNumber;
SimulationJobStatusRepresentation.BatchSystemType htcBatchSystemType = eventRep.jobStatus.htcBatchSystemType;
if (htcJobNumber != null) {
htcJobID = new HtcJobID(htcJobNumber.toString(), BatchSystemType.valueOf(htcBatchSystemType.name()));
}
SimulationMessage simMessage = null;
DetailedState detailedState = DetailedState.valueOf(eventRep.jobStatus.detailedState.name());
String message = eventRep.jobStatus.detailedStateMessage;
if (detailedState != null) {
simMessage = SimulationMessage.create(detailedState, message, htcJobID);
}
SimulationQueueEntryStatus simQueueStatus = null;
Date queueDate = eventRep.jobStatus.queueDate;
Integer queuePriority = eventRep.jobStatus.queuePriority;
SimulationJobStatusRepresentation.SimulationQueueID queueId2 = eventRep.jobStatus.queueId;
if (queueDate != null && queuePriority != null) {
simQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationQueueID.valueOf(queueId2.name()));
}
SimulationExecutionStatus simExeStatus = null;
Date startDate = eventRep.jobStatus.simexe_startDate;
String computeHost = eventRep.jobStatus.computeHost;
Date latestUpdateDate = eventRep.jobStatus.simexe_latestUpdateDate;
Date endDate = eventRep.jobStatus.simexe_endDate;
Boolean hasData = eventRep.jobStatus.hasData;
if (latestUpdateDate != null) {
simExeStatus = new SimulationExecutionStatus(startDate, computeHost, latestUpdateDate, endDate, hasData, htcJobID);
}
SimulationJobStatus jobStatus = new SimulationJobStatus(serverID, vcSimID, jobIndex, submitDate, schedulerStatus, taskID, simMessage, simQueueStatus, simExeStatus);
Double progress = eventRep.progress;
Double timepoint = eventRep.timePoint;
String username = eventRep.username;
SimulationJobStatusEvent event = new SimulationJobStatusEvent(eventSource, simid, jobStatus, progress, timepoint, username);
return event;
}
use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class ClientDocumentManager method getBioModel.
/**
* Insert the method's description here.
* Creation date: (11/14/00 4:02:44 PM)
* @return cbit.vcell.biomodel.BioModel
* @param bioModelInfo cbit.vcell.biomodel.BioModelInfo
*/
public BioModel getBioModel(KeyValue bioModelKey) throws DataAccessException {
XMLHolder<BioModel> bioModelXML = getBioModelXML(bioModelKey);
BioModel bioModel = getBioModelFromDatabaseXML(bioModelXML);
// if the positive & negative features for the membranes are not already set, set them using struct topology.
bioModel.getModel().getElectricalTopology().populateFromStructureTopology();
//
// preload SimulationJobStatus for all simulations if any missing from hash.
//
Simulation[] simulations = bioModel.getSimulations();
KeyValue[] simKeys = new KeyValue[simulations.length];
for (int i = 0; i < simulations.length; i++) {
VCSimulationIdentifier vcSimulationIdentifier = simulations[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
simKeys[i] = vcSimulationIdentifier.getSimulationKey();
}
preloadSimulationStatus(simKeys);
return bioModel;
}
Aggregations