use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.
the class ParameterEstimationRunTaskPanel method plot.
private void plot() {
try {
java.util.Vector<DataSource> dataSourceList = new java.util.Vector<DataSource>();
java.util.Vector<String> nameVector = new java.util.Vector<String>();
ModelOptimizationSpec modelOptimizationSpec = parameterEstimationTask.getModelOptimizationSpec();
final ReferenceDataMappingSpec[] mappingSpecs = modelOptimizationSpec.getReferenceDataMappingSpecs();
int timeIndex = modelOptimizationSpec.getReferenceDataTimeColumnIndex();
ReferenceData referenceData = modelOptimizationSpec.getReferenceData();
if (referenceData != null) {
dataSourceList.add(new DataSource.DataSourceReferenceData("EXPT", timeIndex, referenceData));
String[] refColumnNames = referenceData.getColumnNames();
for (int i = 0; i < refColumnNames.length; i++) {
if (i == timeIndex) {
continue;
}
nameVector.add(refColumnNames[i]);
break;
}
}
ParameterEstimationTaskSimulatorIDA parestSimulator = new ParameterEstimationTaskSimulatorIDA();
ODESolverResultSet odeSolverResultSet = parestSimulator.getOdeSolverResultSet(parameterEstimationTask);
if (odeSolverResultSet != null) {
dataSourceList.add(new DataSource.DataSourceRowColumnResultSet("EST", odeSolverResultSet));
if (mappingSpecs != null) {
for (int i = 0; i < mappingSpecs.length; i++) {
if (i == timeIndex) {
continue;
}
Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(mappingSpecs[i].getModelObject());
nameVector.add(var.getName());
break;
}
}
}
DataSource[] dataSources = (DataSource[]) BeanUtils.getArray(dataSourceList, DataSource.class);
MultisourcePlotPane multisourcePlotPane = new MultisourcePlotPane();
multisourcePlotPane.setGroupingListSorter(new Comparator<SortDataReferenceHelper>() {
@Override
public int compare(SortDataReferenceHelper o1, SortDataReferenceHelper o2) {
DataSource ds01 = o1.dataReference.getDataSource();
DataSource ds02 = o2.dataReference.getDataSource();
// System.out.println(ds01.getClass().getSimpleName()+" "+o1.dataReference.getIdentifier()+" "+ds02.getClass().getSimpleName()+" "+o2.dataReference.getIdentifier());
if (ds01 instanceof DataSource.DataSourceReferenceData) {
if (ds02 instanceof DataSource.DataSourceReferenceData) {
// both reference data, sort names
ReferenceDataMappingSpec mspec01 = null;
ReferenceDataMappingSpec mspec02 = null;
for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
// Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
continue;
}
if (o1.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
mspec01 = rdMappingSpec;
o1.setReferenceDataMappingSpec(rdMappingSpec);
} else if (o2.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
mspec02 = rdMappingSpec;
o2.setReferenceDataMappingSpec(rdMappingSpec);
}
}
if (mspec01 == null && mspec02 == null) {
return o1.dataReference.getIdentifier().compareToIgnoreCase(o2.dataReference.getIdentifier());
} else if (mspec01 != null && mspec02 != null) {
return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
} else if (mspec01 != null && mspec02 == null) {
return -1;
} else {
return 1;
}
} else {
// compare ref to ode
ReferenceDataMappingSpec mspec01 = null;
ReferenceDataMappingSpec mspec02 = null;
for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
continue;
}
if (o1.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
mspec01 = rdMappingSpec;
o1.setReferenceDataMappingSpec(rdMappingSpec);
} else if (o2.dataReference.getIdentifier().equals(var.getName())) {
mspec02 = rdMappingSpec;
o2.setReferenceDataMappingSpec(rdMappingSpec);
}
}
if (mspec01 == null && mspec02 == null) {
return -1;
} else if (mspec01 != null && mspec02 == null) {
return -1;
} else if (mspec02 != null && mspec01 == null) {
return 1;
} else {
// BeanUtils.forceStringSize(mspec02.getReferenceDataColumnName(), 25, " ", true));
return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
}
}
} else {
if (ds02 instanceof DataSource.DataSourceRowColumnResultSet) {
// both OdeSolverResultSet data, sort names
ReferenceDataMappingSpec mspec01 = null;
ReferenceDataMappingSpec mspec02 = null;
for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
continue;
}
if (o1.dataReference.getIdentifier().equals(var.getName())) {
mspec01 = rdMappingSpec;
o1.setReferenceDataMappingSpec(rdMappingSpec);
} else if (o2.dataReference.getIdentifier().equals(var.getName())) {
mspec02 = rdMappingSpec;
o2.setReferenceDataMappingSpec(rdMappingSpec);
}
}
if (mspec01 == null && mspec02 == null) {
return o1.dataReference.getIdentifier().compareToIgnoreCase(o2.dataReference.getIdentifier());
} else if (mspec01 != null && mspec02 != null) {
return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
} else if (mspec01 != null && mspec02 == null) {
return -1;
} else {
return 1;
}
} else {
// compare ode to ref
ReferenceDataMappingSpec mspec01 = null;
ReferenceDataMappingSpec mspec02 = null;
for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
continue;
}
if (o2.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
mspec02 = rdMappingSpec;
o2.setReferenceDataMappingSpec(rdMappingSpec);
} else if (o1.dataReference.getIdentifier().equals(var.getName())) {
mspec01 = rdMappingSpec;
o1.setReferenceDataMappingSpec(rdMappingSpec);
}
}
if (mspec01 == null && mspec02 == null) {
return 1;
} else if (mspec01 != null && mspec02 == null) {
return -1;
} else if (mspec02 != null && mspec01 == null) {
return 1;
} else {
// BeanUtils.forceStringSize(mspec02.getReferenceDataColumnName(), 25, " ", true));
return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
}
}
}
}
});
multisourcePlotPane.setDataSources(dataSources);
String[] nameArray = new String[nameVector.size()];
nameArray = (String[]) BeanUtils.getArray(nameVector, String.class);
multisourcePlotPane.select(nameArray);
DialogUtils.showComponentCloseDialog(JOptionPane.getFrameForComponent(this), multisourcePlotPane, "Data Plot");
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.
the class VCellSedMLSolver method doWork.
// everything is done here
public void doWork(ExternalDocInfo externalDocInfo, AbstractTask sedmlTask, SedML sedml) throws Exception {
// create the VCDocument (bioModel + application + simulation), do sanity checks
cbit.util.xml.VCLogger sedmlImportLogger = new LocalLogger();
List<AbstractTask> tasks = new ArrayList<AbstractTask>();
tasks.add(sedmlTask);
List<VCDocument> docs = XmlHelper.sedmlToBioModel(sedmlImportLogger, externalDocInfo, sedml, tasks, null, false);
VCDocument doc = docs.get(0);
sanityCheck(doc);
// create the work directory for this task, invoke the solver
String docName = doc.getName();
String outString = VCellSedMLSolver.OUT_ROOT_STRING + "/" + docName + "/" + sedmlTask.getId();
File outDir = new File(outString);
if (!outDir.exists()) {
outDir.mkdirs();
}
BioModel bioModel = (BioModel) doc;
SimulationContext simContext = bioModel.getSimulationContext(0);
MathDescription mathDesc = simContext.getMathDescription();
String vcml = mathDesc.getVCML();
try (PrintWriter pw = new PrintWriter(outString + "/vcmlTrace.xml")) {
pw.println(vcml);
}
Simulation sim = bioModel.getSimulation(0);
SolverTaskDescription std = sim.getSolverTaskDescription();
SolverDescription sd = std.getSolverDescription();
String kisao = sd.getKisao();
if (SolverDescription.CVODE.getKisao().contentEquals(kisao)) {
ODESolverResultSet odeSolverResultSet = solveCvode(outDir, bioModel);
System.out.println("Finished: " + docName + ": - task '" + sedmlTask.getId() + "'.");
} else if (SolverDescription.StochGibson.getKisao().contentEquals(kisao)) {
ODESolverResultSet odeSolverResultSet = solveGibson(outDir, bioModel);
System.out.println("Finished: " + docName + ": - task '" + sedmlTask.getId() + "'.");
} else if (SolverDescription.IDA.getKisao().contentEquals(kisao)) {
ODESolverResultSet odeSolverResultSet = solveIDA(outDir, bioModel);
System.out.println("Finished: " + docName + ": - task '" + sedmlTask.getId() + "'.");
} else {
System.out.println("Unsupported solver: " + kisao);
}
System.out.println("-------------------------------------------------------------------------");
}
use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.
the class VCellSedMLSolver method solveGibson.
private static ODESolverResultSet solveGibson(File outDir, BioModel bioModel) throws Exception {
String docName = bioModel.getName();
Simulation sim = bioModel.getSimulation(0);
File gibsonInputFile = new File(outDir, docName + SimDataConstants.STOCHINPUT_DATA_EXTENSION);
PrintWriter gibsonPW = new java.io.PrintWriter(gibsonInputFile);
SimulationJob simJob = new SimulationJob(sim, 0, null);
SimulationTask simTask = new SimulationTask(simJob, 0);
StochFileWriter stFileWriter = new StochFileWriter(gibsonPW, simTask, false);
stFileWriter.write();
gibsonPW.close();
File gibsonOutputFile = new File(outDir, docName + SimDataConstants.IDA_DATA_EXTENSION);
writeFunctionFile(outDir, docName, SimDataConstants.FUNCTIONFILE_EXTENSION, simTask);
String executableName = null;
try {
executableName = SolverUtilities.getExes(SolverDescription.StochGibson)[0].getAbsolutePath();
} catch (IOException e) {
throw new RuntimeException("failed to get executable for solver " + SolverDescription.StochGibson.getDisplayLabel() + ": " + e.getMessage(), e);
}
Executable executable = new Executable(new String[] { executableName, "gibson", gibsonInputFile.getAbsolutePath(), gibsonOutputFile.getAbsolutePath() });
executable.start();
ODESolverResultSet odeSolverResultSet = VCellSBMLSolver.getODESolverResultSet(simJob, gibsonOutputFile.getPath());
return odeSolverResultSet;
}
use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.
the class VCellSedMLSolver method solveCvode.
private static ODESolverResultSet solveCvode(File outDir, BioModel bioModel) throws Exception {
String docName = bioModel.getName();
Simulation sim = bioModel.getSimulation(0);
File cvodeInputFile = new File(outDir, docName + SimDataConstants.CVODEINPUT_DATA_EXTENSION);
PrintWriter cvodePW = new java.io.PrintWriter(cvodeInputFile);
SimulationJob simJob = new SimulationJob(sim, 0, null);
SimulationTask simTask = new SimulationTask(simJob, 0);
CVodeFileWriter cvodeFileWriter = new CVodeFileWriter(cvodePW, simTask);
cvodeFileWriter.write();
cvodePW.close();
// use the cvodeStandalone solver
String outDirPath = outDir.getAbsolutePath();
int indexOfLastSlash = outDirPath.lastIndexOf("/");
String task_name = outDirPath.substring(indexOfLastSlash + 1);
String idaFilePath = outDirPath.substring(0, indexOfLastSlash);
File cvodeOutputFile = new File(idaFilePath, task_name + SimDataConstants.IDA_DATA_EXTENSION);
String executableName = null;
try {
// we need to specify the vCell install dir in the Eclipse Debug configuration, as VM argument
// so that the code next knows where to look for the solver
// -Dvcell.installDir=G:\dan\jprojects\git\vcell
// OR
// just type the string with the full path explicitly
// OR
// provide a .properties file in the working directory
executableName = SolverUtilities.getExes(SolverDescription.CVODE)[0].getAbsolutePath();
} catch (IOException e) {
throw new RuntimeException("failed to get executable for solver " + SolverDescription.CVODE.getDisplayLabel() + ": " + e.getMessage(), e);
}
Executable executable = new Executable(new String[] { executableName, cvodeInputFile.getAbsolutePath(), cvodeOutputFile.getAbsolutePath() });
executable.start();
ODESolverResultSet odeSolverResultSet = VCellSBMLSolver.getODESolverResultSet(simJob, cvodeOutputFile.getPath());
return odeSolverResultSet;
}
use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.
the class BNGDataPlotListModel method setOdeSolverResultSet.
/**
* Sets the dataSource property (cbit.vcell.modelopt.gui.DataSource) value.
* @param dataSource The new value for the property.
* @see #getDataSource
*/
public void setOdeSolverResultSet(ODESolverResultSet odeSolverResultSet) {
ODESolverResultSet oldValue = fieldOdeSolverResultSet;
fieldOdeSolverResultSet = odeSolverResultSet;
firePropertyChange("odeSolverResultSet", oldValue, odeSolverResultSet);
}
Aggregations