use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.
the class TopLevelWindowManager method prepareDocumentToLoad.
public void prepareDocumentToLoad(VCDocument doc, boolean bInNewWindow) throws Exception {
if (doc instanceof BioModel) {
Simulation[] simulations = ((BioModel) doc).getSimulations();
ArrayList<VCSimulationIdentifier> simIDs = new ArrayList<VCSimulationIdentifier>();
for (int i = 0; i < simulations.length; i++) {
SimulationInfo simulationInfo = simulations[i].getSimulationInfo();
if (simulationInfo != null) {
simIDs.add(simulationInfo.getAuthoritativeVCSimulationIdentifier());
}
}
RequestManager rm = getRequestManager();
ConnectionStatus stat = rm.getConnectionStatus();
if (stat.getStatus() == ConnectionStatus.CONNECTED) {
rm.getDocumentManager().preloadSimulationStatus(simIDs.toArray(new VCSimulationIdentifier[0]));
}
} else if (doc instanceof MathModel) {
Geometry geometry = ((MathModel) doc).getMathDescription().getGeometry();
geometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
Simulation[] simulations = ((MathModel) doc).getSimulations();
// VCSimulationIdentifier simIDs[] = new VCSimulationIdentifier[simulations.length];
ArrayList<VCSimulationIdentifier> simIDs = new ArrayList<>();
for (int i = 0; i < simulations.length; i++) {
if (simulations[i].getSimulationInfo() != null) {
simIDs.add(simulations[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier());
}
}
getRequestManager().getDocumentManager().preloadSimulationStatus(simIDs.toArray(new VCSimulationIdentifier[0]));
} else if (doc instanceof Geometry) {
((Geometry) doc).precomputeAll(new GeometryThumbnailImageFactoryAWT());
}
}
use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.
the class SimulationWorkspaceModelInfo method getMembraneName.
/**
* Insert the method's description here.
* Creation date: (9/19/2005 1:30:44 PM)
* @return java.lang.String
* @param subVolumeIdIn int
* @param subVolumeIdOut int
*/
public String getMembraneName(int subVolumeIdIn, int subVolumeIdOut, boolean bFromGeometry) {
String results = null;
if (simulationOwner instanceof MathModel) {
MathModel mathModel = (MathModel) simulationOwner;
final GeometrySpec geometrySpec = mathModel.getMathDescription().getGeometry().getGeometrySpec();
if (geometrySpec.getSubVolume(subVolumeIdIn) != null && geometrySpec.getSubVolume(subVolumeIdOut) != null) {
SubVolume svIn = geometrySpec.getSubVolume(subVolumeIdIn);
SubVolume svOut = geometrySpec.getSubVolume(subVolumeIdOut);
SurfaceClass membrane = mathModel.getMathDescription().getGeometry().getGeometrySurfaceDescription().getSurfaceClass(svIn, svOut);
results = membrane.getName();
}
} else if (simulationOwner instanceof SimulationContext) {
SimulationContext simContext = (SimulationContext) simulationOwner;
SubVolume svIn = simContext.getGeometry().getGeometrySpec().getSubVolume(subVolumeIdIn);
SubVolume svOut = simContext.getGeometry().getGeometrySpec().getSubVolume(subVolumeIdOut);
if (bFromGeometry) {
SurfaceClass membrane = simContext.getMathDescription().getGeometry().getGeometrySurfaceDescription().getSurfaceClass(svIn, svOut);
results = membrane.getName();
} else {
if (svIn != null && svOut != null) {
GeometryClass[] geometryClasses = simContext.getGeometry().getGeometryClasses();
for (int i = 0; i < geometryClasses.length; i++) {
if (geometryClasses[i] instanceof SurfaceClass) {
SurfaceClass surface = (SurfaceClass) geometryClasses[i];
if (surface.isAdjacentTo(svIn) && surface.isAdjacentTo(svOut)) {
StructureMapping[] structureMappings = simContext.getGeometryContext().getStructureMappings(surface);
if (structureMappings != null && structureMappings.length > 0) {
results = surface.getName() + "(";
for (int j = 0; j < structureMappings.length; j++) {
results += structureMappings[j].getStructure().getName() + " ";
}
results += ")";
return results;
}
}
}
}
}
}
}
return results;
}
use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.
the class VCellClientDataServiceImpl method getSimsFromOpenModels.
@Override
public List<SimulationDataSetRef> getSimsFromOpenModels() {
ArrayList<SimulationDataSetRef> simulationDataSetRefs = new ArrayList<SimulationDataSetRef>();
for (TopLevelWindowManager windowManager : vcellClient.getMdiManager().getWindowManagers()) {
Simulation[] simulations = null;
VCDocument modelDocument = null;
if (windowManager instanceof BioModelWindowManager) {
BioModelWindowManager selectedBioWindowManager = (BioModelWindowManager) windowManager;
BioModel bioModel = selectedBioWindowManager.getBioModel();
simulations = bioModel.getSimulations();
modelDocument = bioModel;
// simOwnerCount = bioModel.getNumSimulationContexts();
} else if (windowManager instanceof MathModelWindowManager) {
MathModelWindowManager selectedMathWindowManager = (MathModelWindowManager) windowManager;
MathModel mathModel = selectedMathWindowManager.getMathModel();
simulations = mathModel.getSimulations();
modelDocument = mathModel;
// simOwnerCount = 1;
}
if (simulations != null) {
for (Simulation simulation : simulations) {
if (!isVtkSupported(simulation)) {
continue;
}
Origin origin = simulation.getMathDescription().getGeometry().getOrigin();
Extent extent = simulation.getMathDescription().getGeometry().getExtent();
SimulationInfo simInfo = simulation.getSimulationInfo();
SimulationStatus simStatus = vcellClient.getRequestManager().getServerSimulationStatus(simInfo);
for (int jobIndex = 0; jobIndex < simulation.getScanCount(); jobIndex++) {
if (simStatus != null && simStatus.getHasData()) {
SimulationDataSetRef simulationDataSetReference = VCellClientDataServiceImpl.createSimulationDataSetRef(simulation, modelDocument, jobIndex, false);
simulationDataSetRefs.add(simulationDataSetReference);
}
}
}
}
}
File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
String[] simtaskFilenames = localSimDir.list((dir, name) -> (name.endsWith(".simtask.xml")));
for (String simtaskFilename : simtaskFilenames) {
try {
SimulationTask simTask = XmlHelper.XMLToSimTask(org.apache.commons.io.FileUtils.readFileToString(new File(localSimDir, simtaskFilename)));
VCDocument modelDocument = null;
SimulationDataSetRef simulationDataSetReference = VCellClientDataServiceImpl.createSimulationDataSetRef(simTask.getSimulation(), modelDocument, simTask.getSimulationJob().getJobIndex(), true);
simulationDataSetRefs.add(simulationDataSetReference);
} catch (ExpressionException | XmlParseException | IOException e) {
e.printStackTrace();
}
}
return simulationDataSetRefs;
}
use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.
the class ClientRequestManager method continueAfterMathModelGeomChangeWarning.
public static void continueAfterMathModelGeomChangeWarning(MathModelWindowManager mathModelWindowManager, Geometry newGeometry) throws UserCancelException {
MathModel mathModel = mathModelWindowManager.getMathModel();
if (mathModel != null && mathModel.getMathDescription() != null) {
Geometry oldGeometry = mathModel.getMathDescription().getGeometry();
if (oldGeometry != null && oldGeometry.getDimension() == 0) {
return;
}
boolean bMeshResolutionChange = true;
if (oldGeometry == null) {
bMeshResolutionChange = false;
}
if (newGeometry != null && oldGeometry != null && oldGeometry.getDimension() == newGeometry.getDimension()) {
bMeshResolutionChange = false;
}
boolean bHasSims = (mathModel.getSimulations() != null) && (mathModel.getSimulations().length > 0);
StringBuffer meshResolutionChangeSB = new StringBuffer();
if (bHasSims && bMeshResolutionChange) {
ISize newGeomISize = MeshSpecification.calulateResetSamplingSize(newGeometry);
for (int i = 0; i < mathModel.getSimulations().length; i++) {
if (mathModel.getSimulations()[i].getMeshSpecification() != null) {
String simName = mathModel.getSimulations()[i].getName();
ISize simMeshSize = mathModel.getSimulations()[i].getMeshSpecification().getSamplingSize();
meshResolutionChangeSB.append((i != 0 ? "\n" : "") + "'" + simName + "' Mesh" + simMeshSize + " will be reset to " + newGeomISize + "");
}
}
}
String result = DialogUtils.showWarningDialog(JOptionPane.getFrameForComponent(mathModelWindowManager.getComponent()), "After changing MathModel geometry please note:\n" + " 1. Check Geometry subvolume names match MathModel compartment names." + (bHasSims && bMeshResolutionChange ? "\n" + " 2. All existing simulations mesh sizes will be reset" + " because the new Geometry spatial dimension(" + newGeometry.getDimension() + "D)" + " does not equal the current Geometry spatial dimension(" + oldGeometry.getDimension() + "D)" + "\n" + meshResolutionChangeSB.toString() : ""), new String[] { "Continue", "Cancel" }, "Continue");
if (result != null && result.equals("Continue")) {
return;
}
} else {
return;
}
throw UserCancelException.CANCEL_GENERIC;
}
use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.
the class CopasiServicePython method makeOptProblem.
public static OptProblem makeOptProblem(ParameterEstimationTask parameterEstimationTask) throws IOException, ExpressionException, SBMLException, XMLStreamException {
OptimizationSpec optimizationSpec = parameterEstimationTask.getModelOptimizationMapping().getOptimizationSpec();
SimulationContext simulationContext = parameterEstimationTask.getSimulationContext();
MathMappingCallback callback = new MathMappingCallback() {
@Override
public void setProgressFraction(float fractionDone) {
Thread.dumpStack();
System.out.println("---> stdout mathMapping: progress = " + (fractionDone * 100.0) + "% done");
}
@Override
public void setMessage(String message) {
Thread.dumpStack();
System.out.println("---> stdout mathMapping: message = " + message);
}
@Override
public boolean isInterrupted() {
return false;
}
};
simulationContext.refreshMathDescription(callback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
MathModel vcellMathModel = new MathModel(null);
vcellMathModel.setMathDescription(simulationContext.getMathDescription());
// get math model string
String sbmlString = MathModel_SBMLExporter.getSBMLString(vcellMathModel, 2, 4);
OptProblem optProblem = new OptProblem();
optProblem.setMathModelSbmlContents(sbmlString);
optProblem.setNumberOfOptimizationRuns(parameterEstimationTask.getOptimizationSolverSpec().getNumOfRuns());
for (Parameter p : optimizationSpec.getParameters()) {
ParameterDescription pdesc = new ParameterDescription(p.getName(), p.getScale(), p.getLowerBound(), p.getUpperBound(), p.getInitialGuess());
optProblem.addToParameterDescriptionList(pdesc);
}
SimpleReferenceData refData = (SimpleReferenceData) parameterEstimationTask.getModelOptimizationSpec().getReferenceData();
// check if t is at the first column
int timeIndex = refData.findColumn(ReservedVariable.TIME.getName());
if (timeIndex != 0) {
throw new RuntimeException("t must be the first column");
}
DataSet dataset = new DataSet();
for (int rowIndex = 0; rowIndex < refData.getNumDataRows(); rowIndex++) {
DataRow dataRow = new DataRow();
double[] array = refData.getDataByRow(rowIndex);
for (double d : array) {
dataRow.addToData(d);
}
dataset.addToRows(dataRow);
}
optProblem.setExperimentalDataSet(dataset);
optProblem.addToReferenceVariableList(new ReferenceVariable(ReservedVariable.TIME.getName(), ReferenceVariableType.independent));
// add all other dependent variables, recall that the dependent variables start from 2nd column onward in reference data
for (int i = 1; i < refData.getNumDataColumns(); i++) {
ReferenceDataMappingSpec rdms = parameterEstimationTask.getModelOptimizationSpec().getReferenceDataMappingSpec(refData.getColumnNames()[i]);
optProblem.addToReferenceVariableList(new ReferenceVariable(rdms.getModelObject().getName(), ReferenceVariableType.dependent));
}
cbit.vcell.opt.CopasiOptimizationMethod vcellCopasiOptimizationMethod = parameterEstimationTask.getOptimizationSolverSpec().getCopasiOptimizationMethod();
OptimizationMethodType optMethodType = OptimizationMethodType.valueOf(vcellCopasiOptimizationMethod.getType().name());
CopasiOptimizationMethod thriftOptMethod = new CopasiOptimizationMethod();
thriftOptMethod.setOptimizationMethodType(optMethodType);
for (cbit.vcell.opt.CopasiOptimizationParameter optParam : vcellCopasiOptimizationMethod.getParameters()) {
org.vcell.optimization.thrift.CopasiOptimizationParameter p = new org.vcell.optimization.thrift.CopasiOptimizationParameter();
p.setValue(optParam.getValue());
org.vcell.optimization.thrift.OptimizationParameterType optParmType = null;
org.vcell.optimization.thrift.OptimizationParameterDataType optDataType = null;
switch(optParam.getType()) {
case Cooling_Factor:
optParmType = OptimizationParameterType.Cooling_Factor;
optDataType = OptimizationParameterDataType.DOUBLE;
break;
case IterationLimit:
optParmType = OptimizationParameterType.IterationLimit;
optDataType = OptimizationParameterDataType.INT;
break;
case Number_of_Generations:
optParmType = OptimizationParameterType.Number_of_Generations;
optDataType = OptimizationParameterDataType.INT;
break;
case Number_of_Iterations:
optParmType = OptimizationParameterType.Number_of_Iterations;
optDataType = OptimizationParameterDataType.INT;
break;
case Pf:
optParmType = OptimizationParameterType.Pf;
optDataType = OptimizationParameterDataType.DOUBLE;
break;
case Population_Size:
optParmType = OptimizationParameterType.Population_Size;
optDataType = OptimizationParameterDataType.INT;
break;
case Random_Number_Generator:
optParmType = OptimizationParameterType.Random_Number_Generator;
optDataType = OptimizationParameterDataType.INT;
break;
case Rho:
optParmType = OptimizationParameterType.Rho;
optDataType = OptimizationParameterDataType.DOUBLE;
break;
case Scale:
optParmType = OptimizationParameterType.Scale;
optDataType = OptimizationParameterDataType.DOUBLE;
break;
case Seed:
optParmType = OptimizationParameterType.Seed;
optDataType = OptimizationParameterDataType.INT;
break;
case Start_Temperature:
optParmType = OptimizationParameterType.Start_Temperature;
optDataType = OptimizationParameterDataType.DOUBLE;
break;
case Std_Deviation:
optParmType = OptimizationParameterType.Std_Deviation;
optDataType = OptimizationParameterDataType.DOUBLE;
break;
case Swarm_Size:
optParmType = OptimizationParameterType.Swarm_Size;
optDataType = OptimizationParameterDataType.INT;
break;
case Tolerance:
optParmType = OptimizationParameterType.Tolerance;
optDataType = OptimizationParameterDataType.DOUBLE;
break;
default:
throw new RuntimeException("unsupported parameter type :" + optParam.getType().name() + " in COPASI optimization solver");
}
p.setParamType(optParmType);
p.setDataType(optDataType);
thriftOptMethod.addToOptimizationParameterList(p);
}
optProblem.setOptimizationMethod(thriftOptMethod);
return optProblem;
}
Aggregations