Search in sources :

Example 56 with MathModel

use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.

the class IssuePanel method invokeHyperlink.

private void invokeHyperlink(Issue issue) {
    if (selectionManager != null) {
        // followHyperlink is no-op if selectionManger null, so no point in proceeding if it is
        IssueContext issueContext = issue.getIssueContext();
        IssueSource object = issue.getSource();
        if (object instanceof DecoratedIssueSource) {
            DecoratedIssueSource dis = (DecoratedIssueSource) object;
            dis.activateView(selectionManager);
        } else if (object instanceof Parameter) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.BIOMODEL_PARAMETERS_NODE, ActiveViewID.parameters_functions), new Object[] { object });
        } else if (object instanceof StructureMapping) {
            StructureMapping structureMapping = (StructureMapping) object;
            StructureMappingNameScope structureMappingNameScope = (StructureMappingNameScope) structureMapping.getNameScope();
            SimulationContext simulationContext = ((SimulationContextNameScope) (structureMappingNameScope.getParent())).getSimulationContext();
            followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.structure_mapping), new Object[] { object });
        } else if (object instanceof SpatialObject) {
            SpatialObject spatialObject = (SpatialObject) object;
            SimulationContext simulationContext = spatialObject.getSimulationContext();
            followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.spatial_objects), new Object[] { object });
        } else if (object instanceof SpatialProcess) {
            SpatialProcess spatialProcess = (SpatialProcess) object;
            SimulationContext simulationContext = spatialProcess.getSimulationContext();
            followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.spatial_processes), new Object[] { object });
        } else if (object instanceof GeometryContext.UnmappedGeometryClass) {
            UnmappedGeometryClass unmappedGeometryClass = (UnmappedGeometryClass) object;
            SimulationContext simulationContext = unmappedGeometryClass.getSimulationContext();
            followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.structure_mapping), new Object[] { object });
        } else if (object instanceof MicroscopeMeasurement) {
            SimulationContext simulationContext = ((MicroscopeMeasurement) object).getSimulationContext();
            followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.PROTOCOLS_NODE, ActiveViewID.microscope_measuremments), new Object[] { object });
        } else if (object instanceof BioEvent) {
            BioEvent be = (BioEvent) object;
            SimulationContext simulationContext = be.getSimulationContext();
            followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.PROTOCOLS_NODE, ActiveViewID.events), new Object[] { object });
        } else if (object instanceof OutputFunctionIssueSource) {
            SimulationOwner simulationOwner = ((OutputFunctionIssueSource) object).getOutputFunctionContext().getSimulationOwner();
            if (simulationOwner instanceof SimulationContext) {
                SimulationContext simulationContext = (SimulationContext) simulationOwner;
                followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.SIMULATIONS_NODE, ActiveViewID.output_functions), new Object[] { ((OutputFunctionIssueSource) object).getAnnotatedFunction() });
            } else if (simulationOwner instanceof MathModel) {
                followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MATH_OUTPUT_FUNCTIONS_NODE, ActiveViewID.math_output_functions), new Object[] { ((OutputFunctionIssueSource) object).getAnnotatedFunction() });
            }
        } else if (object instanceof Simulation) {
            Simulation simulation = (Simulation) object;
            SimulationOwner simulationOwner = simulation.getSimulationOwner();
            if (simulationOwner instanceof SimulationContext) {
                SimulationContext simulationContext = (SimulationContext) simulationOwner;
                followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.SIMULATIONS_NODE, ActiveViewID.simulations), new Object[] { simulation });
            } else if (simulationOwner instanceof MathModel) {
                followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MATH_SIMULATIONS_NODE, ActiveViewID.math_simulations), new Object[] { simulation });
            }
        } else if (object instanceof GeometryContext) {
            setActiveView(new ActiveView(((GeometryContext) object).getSimulationContext(), DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.geometry_definition));
        } else if (object instanceof Structure) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.STRUCTURES_NODE, ActiveViewID.structures), new Object[] { object });
        } else if (object instanceof MolecularType) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MOLECULAR_TYPES_NODE, ActiveViewID.structures), new Object[] { object });
        } else if (object instanceof ReactionStep) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.REACTIONS_NODE, ActiveViewID.reactions), new Object[] { object });
        } else if (object instanceof ReactionRule) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.REACTIONS_NODE, ActiveViewID.reactions), new Object[] { object });
        } else if (object instanceof SpeciesContextSpec) {
            SpeciesContextSpec scs = (SpeciesContextSpec) object;
            ActiveView av = new ActiveView(scs.getSimulationContext(), DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.species_settings);
            followHyperlink(av, new Object[] { object });
        } else if (object instanceof ReactionCombo) {
            ReactionCombo rc = (ReactionCombo) object;
            followHyperlink(new ActiveView(rc.getReactionContext().getSimulationContext(), DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.reaction_setting), new Object[] { ((ReactionCombo) object).getReactionSpec() });
        } else if (object instanceof SpeciesContext) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.SPECIES_NODE, ActiveViewID.species), new Object[] { object });
        } else if (object instanceof RbmObservable) {
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.OBSERVABLES_NODE, ActiveViewID.observables), new Object[] { object });
        } else if (object instanceof MathDescription) {
            // followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MATH_SIMULATIONS_NODE, ActiveViewID.generated_math), new Object[] {object});
            followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.structure_mapping), new Object[] { object });
        } else if (object instanceof SpeciesPattern) {
            // if (issue.getIssueContext().hasContextType(ContextType.SpeciesContext)){
            // SpeciesContext thing = (SpeciesContext)issue.getIssueContext().getContextObject(ContextType.SpeciesContext);
            // followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.SPECIES_NODE, ActiveViewID.species), new Object[] {thing});
            // }else if(issue.getIssueContext().hasContextType(ContextType.ReactionRule)) {
            // ReactionRule thing = (ReactionRule)issue.getIssueContext().getContextObject(ContextType.ReactionRule);
            // followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.REACTIONS_NODE, ActiveViewID.reactions), new Object[] {thing});
            // }else if(issue.getIssueContext().hasContextType(ContextType.RbmObservable)) {
            // RbmObservable thing = (RbmObservable)issue.getIssueContext().getContextObject(ContextType.RbmObservable);
            // followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.OBSERVABLES_NODE, ActiveViewID.observables), new Object[] {thing});
            // } else {
            System.err.println("SpeciesPattern object missing a proper issue context.");
        // }
        } else if (object instanceof SimulationContext) {
            SimulationContext sc = (SimulationContext) object;
            IssueCategory ic = issue.getCategory();
            switch(ic) {
                case RbmNetworkConstraintsBad:
                    NetworkConstraints nc = sc.getNetworkConstraints();
                    if (issue.getMessage() == SimulationContext.IssueInsufficientMolecules) {
                        NetworkConstraintsEntity nce = new NetworkConstraintsEntity(NetworkConstraintsTableModel.sMaxMoleculesName, NetworkConstraintsTableModel.sValueType, nc.getMaxMoleculesPerSpecies() + "");
                        followHyperlink(new ActiveView(sc, DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.network_setting), new Object[] { nce });
                    } else {
                        NetworkConstraintsEntity nce = new NetworkConstraintsEntity(NetworkConstraintsTableModel.sMaxIterationName, NetworkConstraintsTableModel.sValueType, nc.getMaxIteration() + "");
                        followHyperlink(new ActiveView(sc, DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.network_setting), new Object[] { nce });
                    }
                    break;
                default:
                    followHyperlink(new ActiveView(sc, DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.network_setting), new Object[] { object });
                    break;
            }
        } else if (object instanceof Geometry) {
            if (issueContext.hasContextType(ContextType.SimContext)) {
                SimulationContext simContext = (SimulationContext) issueContext.getContextObject(ContextType.SimContext);
                followHyperlink(new ActiveView(simContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.geometry_definition), new Object[] { object });
            } else if (issueContext.hasContextType(ContextType.MathModel)) {
                followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MATH_GEOMETRY_NODE, ActiveViewID.math_geometry), new Object[] { object });
            } else if (issueContext.hasContextType(ContextType.MathDescription)) {
                followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.geometry_definition), new Object[] { object });
            }
        } else {
            System.err.println("unknown object type in IssuePanel.invokeHyperlink(): " + object.getClass() + ", context type: " + issueContext.getContextType());
        }
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) IssueCategory(org.vcell.util.Issue.IssueCategory) MathDescription(cbit.vcell.math.MathDescription) NetworkConstraintsEntity(org.vcell.model.rbm.common.NetworkConstraintsEntity) SpeciesContext(cbit.vcell.model.SpeciesContext) ActiveView(cbit.vcell.client.desktop.biomodel.SelectionManager.ActiveView) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) StructureMappingNameScope(cbit.vcell.mapping.StructureMapping.StructureMappingNameScope) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) UnmappedGeometryClass(cbit.vcell.mapping.GeometryContext.UnmappedGeometryClass) SimulationOwner(cbit.vcell.solver.SimulationOwner) DecoratedIssueSource(cbit.vcell.client.desktop.DecoratedIssueSource) IssueSource(org.vcell.util.Issue.IssueSource) OutputFunctionIssueSource(cbit.vcell.solver.OutputFunctionContext.OutputFunctionIssueSource) OutputFunctionIssueSource(cbit.vcell.solver.OutputFunctionContext.OutputFunctionIssueSource) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) IssueContext(org.vcell.util.IssueContext) UnmappedGeometryClass(cbit.vcell.mapping.GeometryContext.UnmappedGeometryClass) MicroscopeMeasurement(cbit.vcell.mapping.MicroscopeMeasurement) GeometryContext(cbit.vcell.mapping.GeometryContext) Structure(cbit.vcell.model.Structure) ReactionCombo(cbit.vcell.mapping.ReactionSpec.ReactionCombo) ReactionRule(cbit.vcell.model.ReactionRule) DecoratedIssueSource(cbit.vcell.client.desktop.DecoratedIssueSource) RbmObservable(cbit.vcell.model.RbmObservable) SimulationContextNameScope(cbit.vcell.mapping.SimulationContext.SimulationContextNameScope) SimulationContext(cbit.vcell.mapping.SimulationContext) MolecularType(org.vcell.model.rbm.MolecularType) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) ReactionStep(cbit.vcell.model.ReactionStep) Parameter(cbit.vcell.model.Parameter) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) BioEvent(cbit.vcell.mapping.BioEvent) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 57 with MathModel

use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.

the class GeometryViewer method resample.

private void resample() {
    AsynchClientTask precomputeCurrentGeometryTask = new AsynchClientTask("computing surfaces for existing geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (getGeometry().getGeometrySurfaceDescription().getRegionImage() == null) {
                getGeometry().precomputeAll(new GeometryThumbnailImageFactoryAWT(), true, true);
            }
        }
    };
    AsynchClientTask sampleSizeTask = new AsynchClientTask("specify sample size", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            VCImage currSampledImage = getGeometry().getGeometrySpec().getSampledImage().getCurrentValue();
            int currNumSamples = currSampledImage.getNumXYZ();
            ISize currSize = new ISize(currSampledImage.getNumX(), currSampledImage.getNumY(), currSampledImage.getNumZ());
            ISize sampleSize_times_ten = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), currNumSamples * 10);
            ISize sampleSize_div_ten = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), currNumSamples / 10);
            ISize sampleSize_1e2 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e2);
            ISize sampleSize_1e3 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e3);
            ISize sampleSize_1e4 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e4);
            ISize sampleSize_1e5 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e5);
            ISize sampleSize_1e6 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e6);
            ISize sampleSize_1e7 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e7);
            ISize sampleSize_1e8 = GeometrySpec.calulateResetSamplingSize(3, getGeometry().getExtent(), (int) 1e8);
            String[] columnNames = new String[] { "description", "num samples", "(X,Y,Z)" };
            Object[][] rowData = new Object[][] { new Object[] { "same size", new Integer(currSize.getXYZ()), currSize }, new Object[] { "10 times smaller", new Integer(sampleSize_div_ten.getXYZ()), sampleSize_div_ten }, new Object[] { "10 times bigger", new Integer(sampleSize_times_ten.getXYZ()), sampleSize_times_ten }, new Object[] { "        100 samples", new Integer(sampleSize_1e2.getXYZ()), sampleSize_1e2 }, new Object[] { "      1,000 samples", new Integer(sampleSize_1e3.getXYZ()), sampleSize_1e3 }, new Object[] { "     10,000 samples", new Integer(sampleSize_1e4.getXYZ()), sampleSize_1e4 }, new Object[] { "    100,000 samples", new Integer(sampleSize_1e5.getXYZ()), sampleSize_1e5 }, new Object[] { "  1,000,000 samples", new Integer(sampleSize_1e6.getXYZ()), sampleSize_1e6 }, new Object[] { " 10,000,000 samples", new Integer(sampleSize_1e7.getXYZ()), sampleSize_1e7 }, new Object[] { "100,000,000 samples", new Integer(sampleSize_1e8.getXYZ()), sampleSize_1e8 } };
            int[] selectedRows = DialogUtils.showComponentOKCancelTableList(GeometryViewer.this, "sample size", columnNames, rowData, ListSelectionModel.SINGLE_SELECTION);
            ISize sampleSize = (ISize) rowData[selectedRows[0]][2];
            hashTable.put("sampleSize", sampleSize);
        }
    };
    AsynchClientTask resampleTask = new AsynchClientTask("resample geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            ISize sampleSize = (ISize) hashTable.get("sampleSize");
            Geometry newGeometry = RayCaster.resampleGeometry(new GeometryThumbnailImageFactoryAWT(), getGeometry(), sampleSize);
            hashTable.put("newGeometry", newGeometry);
        }
    };
    AsynchClientTask setGeometryTask = new AsynchClientTask("loading geometry", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Geometry newGeometry = (Geometry) hashTable.get("newGeometry");
            if (getGeometryOwner() instanceof SimulationContext) {
                ((SimulationContext) getGeometryOwner()).setGeometry(newGeometry);
            } else if (getGeometryOwner() instanceof MathModel) {
                ((MathModel) getGeometryOwner()).getMathDescription().setGeometry(newGeometry);
            } else {
                throw new RuntimeException("unexpected geometry owner, could not set resampled geometry");
            }
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { precomputeCurrentGeometryTask, sampleSizeTask, resampleTask, setGeometryTask }, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) MathModel(cbit.vcell.mathmodel.MathModel) Hashtable(java.util.Hashtable) ISize(org.vcell.util.ISize) VCImage(cbit.image.VCImage) SimulationContext(cbit.vcell.mapping.SimulationContext) Geometry(cbit.vcell.geometry.Geometry) GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)

Example 58 with MathModel

use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.

the class ChooseFile method showMathModelXMLFileChooser.

/**
 * Insert the method's description here.
 * Creation date: (5/31/2004 6:04:14 PM)
 * @param hashTable java.util.Hashtable
 * @param clientWorker cbit.vcell.desktop.controls.ClientWorker
 */
private File showMathModelXMLFileChooser(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    // for mathmodels:
    MathModel mathModel = (MathModel) hashTable.get("documentToExport");
    JFrame currentWindow = (JFrame) hashTable.get("currentWindow");
    UserPreferences userPreferences = (UserPreferences) hashTable.get("userPreferences");
    TopLevelWindowManager topLevelWindowManager = (TopLevelWindowManager) hashTable.get("topLevelWindowManager");
    if (topLevelWindowManager == null) {
        throw new RuntimeException("toplLevelWindowManager required");
    }
    File defaultPath = userPreferences.getCurrentDialogPath();
    VCFileChooser fileChooser = new VCFileChooser(defaultPath);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);
    // fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_21);		// Can export Mathmodel to L2V1 ??
    fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_23);
    fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SBML_24);
    // fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_CELLML);
    fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_MATLABV6);
    fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_PDF);
    fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_SMOLDYN_INPUT);
    // remove all selector
    fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
    // set the default file filter...
    fileChooser.setFileFilter(FileFilters.FILE_FILTER_VCML);
    fileChooser.setSelectedFile(new java.io.File(TokenMangler.fixTokenStrict(mathModel.getName())));
    fileChooser.setDialogTitle("Export Virtual Cell MathModel As...");
    if (fileChooser.showSaveDialog(currentWindow) != JFileChooser.APPROVE_OPTION) {
        // user didn't choose save
        throw UserCancelException.CANCEL_FILE_SELECTION;
    } else {
        File selectedFile = fileChooser.getSelectedFile();
        javax.swing.filechooser.FileFilter fileFilter = fileChooser.getFileFilter();
        if (selectedFile == null) {
            // no file selected (no name given)
            throw UserCancelException.CANCEL_FILE_SELECTION;
        } else {
            // /
            String selectedFileName = recordAndRemoveExtension(selectedFile.getPath());
            String n = selectedFile.getPath().toLowerCase();
            if (fileFilter == FileFilters.FILE_FILTER_CELLML && !n.endsWith(".xml")) {
                selectedFile = new File(selectedFileName + ".xml");
            } else if (fileFilter == FileFilters.FILE_FILTER_VCML && !n.endsWith(".vcml")) {
                selectedFile = new File(selectedFileName + ".vcml");
            } else if ((fileFilter == FileFilters.FILE_FILTER_SBML_23 || (fileFilter == FileFilters.FILE_FILTER_SBML_24)) && !n.endsWith(".xml")) {
                selectedFile = new File(selectedFileName + ".xml");
            } else if (fileFilter == FileFilters.FILE_FILTER_MATLABV6 && !n.endsWith(".m")) {
                selectedFile = new File(selectedFileName + ".m");
            } else if (fileFilter == FileFilters.FILE_FILTER_PDF && !n.endsWith(".pdf")) {
                selectedFile = new File(selectedFileName + ".pdf");
            } else if (fileFilter == FileFilters.FILE_FILTER_SMOLDYN_INPUT && !(n.endsWith(SMOLDYN_INPUT_FILE_EXTENSION) || (n.endsWith(".txt")))) {
                selectedFile = new File(selectedFileName + SMOLDYN_INPUT_FILE_EXTENSION);
            }
            checkForOverwrites(selectedFile, topLevelWindowManager.getComponent(), userPreferences);
            // put the filter in the hash so the export task knows what to do...
            hashTable.put("fileFilter", fileFilter);
            // only non-spatial math models can be exported to CellML.
            if (fileFilter == FileFilters.FILE_FILTER_CELLML && mathModel.getMathDescription().getGeometry().getDimension() != 0) {
                throw new Exception("No non-spatial applications, can only export to this format the math from a non-spatial application");
            } else // Select a spatial stochastic simulation to export
            if (fileFilter.getDescription().equals(FileFilters.FILE_FILTER_SMOLDYN_INPUT.getDescription())) {
                Simulation[] sims = mathModel.getSimulations();
                if (sims == null || sims.length == 0) {
                    DialogUtils.showWarningDialog(topLevelWindowManager.getComponent(), "MathModel '" + mathModel.getName() + "' has no simulations to export");
                    throw UserCancelException.CANCEL_GENERIC;
                }
                String[][] rowData = new String[sims.length][2];
                for (int i = 0; i < sims.length; i++) {
                    rowData[i][0] = sims[i].getName();
                    rowData[i][1] = sims[i].getSolverTaskDescription().getSolverDescription().getDisplayLabel();
                }
                int[] selectedRow = PopupGenerator.showComponentOKCancelTableList(topLevelWindowManager.getComponent(), "Select a simulation to export", new String[] { "Simulation Name", "Solver" }, rowData, ListSelectionModel.SINGLE_SELECTION);
                if (selectedRow == null) {
                    throw UserCancelException.CANCEL_GENERIC;
                }
                String chosenSimulationName = rowData[selectedRow[0]][0];
                Simulation chosenSimulation = mathModel.getSimulation(chosenSimulationName);
                if (chosenSimulation != null) {
                    hashTable.put("selectedSimulation", chosenSimulation);
                } else {
                    throw new Exception("Couldn't match selection '" + chosenSimulationName + "' with simulation");
                }
            }
            resetPreferredFilePath(selectedFile, userPreferences);
            return selectedFile;
        }
    }
}
Also used : UserPreferences(cbit.vcell.client.server.UserPreferences) MathModel(cbit.vcell.mathmodel.MathModel) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) UserCancelException(org.vcell.util.UserCancelException) Simulation(cbit.vcell.solver.Simulation) JFrame(javax.swing.JFrame) VCFileChooser(org.vcell.util.gui.VCFileChooser) File(java.io.File)

Example 59 with MathModel

use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.

the class DeleteOldDocument method run.

/**
 * Insert the method's description here.
 * Creation date: (5/31/2004 6:04:14 PM)
 * @param hashTable java.util.Hashtable
 * @param clientWorker cbit.vcell.desktop.controls.ClientWorker
 */
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    DocumentWindowManager dwm = (DocumentWindowManager) fetch(hashTable, DOCUMENT_WINDOW_MANAGER);
    VCDocument currentDocument = dwm.getVCDocument();
    DocumentManager documentManager = (DocumentManager) fetch(hashTable, DOCUMENT_MANAGER);
    switch(currentDocument.getDocumentType()) {
        case BIOMODEL_DOC:
            {
                // make the info
                BioModel oldBioModel = (BioModel) currentDocument;
                BioModelInfo oldBioModelInfo = documentManager.getBioModelInfo(oldBioModel.getVersion().getVersionKey());
                // delete document
                documentManager.delete(oldBioModelInfo);
                break;
            }
        case MATHMODEL_DOC:
            {
                // make the info
                MathModel oldMathModel = (MathModel) currentDocument;
                MathModelInfo oldMathModelInfo = documentManager.getMathModelInfo(oldMathModel.getVersion().getVersionKey());
                // delete document
                documentManager.delete(oldMathModelInfo);
                break;
            }
        case GEOMETRY_DOC:
            {
                // make the info
                Geometry oldGeometry = (Geometry) currentDocument;
                GeometryInfo oldGeometryInfo = documentManager.getGeometryInfo(oldGeometry.getVersion().getVersionKey());
                // delete document
                documentManager.delete(oldGeometryInfo);
                break;
            }
        default:
            break;
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) MathModel(cbit.vcell.mathmodel.MathModel) VCDocument(org.vcell.util.document.VCDocument) DocumentWindowManager(cbit.vcell.client.DocumentWindowManager) BioModel(cbit.vcell.biomodel.BioModel) DocumentManager(cbit.vcell.clientdb.DocumentManager) BioModelInfo(org.vcell.util.document.BioModelInfo) GeometryInfo(cbit.vcell.geometry.GeometryInfo) MathModelInfo(org.vcell.util.document.MathModelInfo)

Example 60 with MathModel

use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.

the class RunSims method run.

/**
 * Insert the method's description here.
 * Creation date: (5/31/2004 6:04:14 PM)
 * @param hashTable java.util.Hashtable
 * @param clientWorker cbit.vcell.desktop.controls.ClientWorker
 */
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    DocumentWindowManager documentWindowManager = (DocumentWindowManager) hashTable.get(CommonTask.DOCUMENT_WINDOW_MANAGER.name);
    ClientSimManager clientSimManager = (ClientSimManager) hashTable.get("clientSimManager");
    // DocumentManager documentManager = (DocumentManager)hashTable.get(CommonTask.DOCUMENT_MANAGER.name);
    JobManager jobManager = (JobManager) hashTable.get("jobManager");
    Simulation[] simulations = (Simulation[]) hashTable.get("simulations");
    Hashtable<Simulation, Throwable> failures = new Hashtable<Simulation, Throwable>();
    if (simulations != null && simulations.length > 0) {
        // we need to get the new ones if a save occurred...
        if (hashTable.containsKey(SaveDocument.DOC_KEY)) {
            VCDocument savedDocument = (VCDocument) hashTable.get(SaveDocument.DOC_KEY);
            Simulation[] allSims = null;
            if (savedDocument instanceof BioModel) {
                allSims = ((BioModel) savedDocument).getSimulations();
            } else if (savedDocument instanceof MathModel) {
                allSims = ((MathModel) savedDocument).getSimulations();
            }
            Vector<Simulation> v = new Vector<Simulation>();
            for (int i = 0; i < simulations.length; i++) {
                for (int j = 0; j < allSims.length; j++) {
                    if (simulations[i].getName().equals(allSims[j].getName())) {
                        v.add(allSims[j]);
                        break;
                    }
                }
            }
            simulations = (Simulation[]) BeanUtils.getArray(v, Simulation.class);
        }
        for (Simulation sim : simulations) {
            try {
                int dimension = sim.getMathDescription().getGeometry().getDimension();
                if (clientSimManager.getSimulationStatus(sim).isCompleted()) {
                    // completed
                    String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_1, sim.getName());
                    String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                    if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                        continue;
                    }
                }
                DataProcessingInstructions dataProcessingInstructions = sim.getDataProcessingInstructions();
                try {
                    if (dataProcessingInstructions != null) {
                        dataProcessingInstructions.getSampleImageFieldData(sim.getVersion().getOwner());
                    }
                } catch (Exception ex) {
                    DialogUtils.showErrorDialog(documentWindowManager.getComponent(), "Problem found in simulation '" + sim.getName() + "':\n" + ex.getMessage());
                    continue;
                }
                if (dimension > 0) {
                    MeshSpecification meshSpecification = sim.getMeshSpecification();
                    boolean bCellCentered = sim.hasCellCenteredMesh();
                    if (meshSpecification != null && !meshSpecification.isAspectRatioOK(bCellCentered)) {
                        String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_2, sim.getName(), "\u0394x=" + meshSpecification.getDx(bCellCentered) + "\n" + "\u0394y=" + meshSpecification.getDy(bCellCentered) + (dimension < 3 ? "" : "\n\u0394z=" + meshSpecification.getDz(bCellCentered)));
                        String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                        if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                            continue;
                        }
                    }
                    if (sim.getSolverTaskDescription().getSolverDescription().equals(SolverDescription.Smoldyn)) {
                        if (!isSmoldynTimeStepOK(sim)) {
                            double s = smoldynTimestepVars.getSpatialResolution();
                            double dMax = smoldynTimestepVars.getMaxDiffusion();
                            double condn = (s * s) / (2.0 * dMax);
                            String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_3, Double.toString(s), Double.toString(dMax), Double.toString(condn));
                            DialogUtils.showErrorDialog(documentWindowManager.getComponent(), warningMessage);
                            continue;
                        }
                    }
                    // check the number of regions if the simulation mesh is coarser.
                    Geometry mathGeometry = sim.getMathDescription().getGeometry();
                    ISize newSize = meshSpecification.getSamplingSize();
                    ISize defaultSize = mathGeometry.getGeometrySpec().getDefaultSampledImageSize();
                    if (!sim.getSolverTaskDescription().getSolverDescription().isChomboSolver()) {
                        int defaultTotalVolumeElements = mathGeometry.getGeometrySurfaceDescription().getVolumeSampleSize().getXYZ();
                        int newTotalVolumeElements = meshSpecification.getSamplingSize().getXYZ();
                        if (defaultTotalVolumeElements > newTotalVolumeElements) {
                            // coarser
                            Geometry resampledGeometry = (Geometry) BeanUtils.cloneSerializable(mathGeometry);
                            GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
                            geoSurfaceDesc.setVolumeSampleSize(newSize);
                            geoSurfaceDesc.updateAll();
                            if (mathGeometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
                                mathGeometry.getGeometrySurfaceDescription().updateAll();
                            }
                            int defaultNumGeometricRegions = mathGeometry.getGeometrySurfaceDescription().getGeometricRegions().length;
                            int numGeometricRegions = geoSurfaceDesc.getGeometricRegions().length;
                            if (numGeometricRegions != defaultNumGeometricRegions) {
                                String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_4, newSize.getX() + (dimension > 1 ? " x " + newSize.getY() : "") + (dimension > 2 ? " x " + newSize.getZ() : ""), sim.getName(), numGeometricRegions, defaultNumGeometricRegions);
                                String result = PopupGenerator.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                                if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                                    continue;
                                }
                            }
                        }
                        if (mathGeometry.getGeometrySpec().hasImage()) {
                            // if it's an image.
                            if (defaultSize.getX() + 1 < newSize.getX() || defaultSize.getY() + 1 < newSize.getY() || defaultSize.getZ() + 1 < newSize.getZ()) {
                                // finer
                                String defaultSizeString = (defaultSize.getX() + 1) + (dimension > 1 ? " x " + (defaultSize.getY() + 1) : "") + (dimension > 2 ? " x " + (defaultSize.getZ() + 1) : "");
                                String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_5, newSize.getX() + (dimension > 1 ? " x " + newSize.getY() : "") + (dimension > 2 ? " x " + newSize.getZ() : ""), sim.getName(), defaultSizeString, defaultSizeString);
                                String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                                if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                                    continue;
                                }
                            }
                        }
                    }
                    boolean bGiveWarning = false;
                    for (int i = 0; i < sim.getScanCount(); i++) {
                        if (sim.getSolverTaskDescription().getSolverDescription().equals(SolverDescription.SundialsPDE)) {
                            SimulationJob simJob = new SimulationJob(sim, i, null);
                            if (simJob.getSimulationSymbolTable().hasTimeVaryingDiffusionOrAdvection()) {
                                bGiveWarning = true;
                                break;
                            }
                        }
                    }
                    if (bGiveWarning) {
                        String warningMessage = VCellErrorMessages.RunSims_6;
                        String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                        if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                            continue;
                        }
                    }
                }
                SimulationInfo simInfo = sim.getSimulationInfo();
                if (simInfo != null) {
                    // 
                    // translate to common ancestral simulation (oldest mathematically equivalent simulation)
                    // 
                    SimulationStatus simulationStatus = jobManager.startSimulation(simInfo.getAuthoritativeVCSimulationIdentifier(), sim.getScanCount());
                    // updateStatus
                    clientSimManager.updateStatusFromStartRequest(sim, simulationStatus);
                } else {
                    // this should really not happen...
                    throw new RuntimeException(">>>>>>>>>> trying to run an unsaved simulation...");
                }
            } catch (Throwable exc) {
                exc.printStackTrace(System.out);
                failures.put(sim, exc);
            }
        }
    }
    // we deal with individual request failures here, passing down only other things (that break the whole thing down) to dispatcher
    if (!failures.isEmpty()) {
        Enumeration<Simulation> en = failures.keys();
        while (en.hasMoreElements()) {
            Simulation sim = en.nextElement();
            Throwable exc = (Throwable) failures.get(sim);
            // // updateStatus
            // SimulationStatus simulationStatus = clientSimManager.updateStatusFromStartRequest(sim, true, exc.getMessage());
            // notify user
            PopupGenerator.showErrorDialog(documentWindowManager, "Failed to start simulation'" + sim.getName() + "'\n" + exc.getMessage());
        }
    }
}
Also used : ClientSimManager(cbit.vcell.client.ClientSimManager) MathModel(cbit.vcell.mathmodel.MathModel) GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) ISize(org.vcell.util.ISize) JobManager(cbit.vcell.client.server.JobManager) DocumentWindowManager(cbit.vcell.client.DocumentWindowManager) DataProcessingInstructions(cbit.vcell.solver.DataProcessingInstructions) Vector(java.util.Vector) SimulationJob(cbit.vcell.solver.SimulationJob) VCDocument(org.vcell.util.document.VCDocument) Hashtable(java.util.Hashtable) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) MeshSpecification(cbit.vcell.solver.MeshSpecification) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) SimulationStatus(cbit.vcell.server.SimulationStatus) BioModel(cbit.vcell.biomodel.BioModel) SimulationInfo(cbit.vcell.solver.SimulationInfo)

Aggregations

MathModel (cbit.vcell.mathmodel.MathModel)70 BioModel (cbit.vcell.biomodel.BioModel)26 Simulation (cbit.vcell.solver.Simulation)24 DataAccessException (org.vcell.util.DataAccessException)21 Geometry (cbit.vcell.geometry.Geometry)20 MathDescription (cbit.vcell.math.MathDescription)20 SimulationContext (cbit.vcell.mapping.SimulationContext)19 XmlParseException (cbit.vcell.xml.XmlParseException)13 MathModelInfo (org.vcell.util.document.MathModelInfo)12 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)11 UserCancelException (org.vcell.util.UserCancelException)11 VCDocument (org.vcell.util.document.VCDocument)11 XMLSource (cbit.vcell.xml.XMLSource)10 ExpressionException (cbit.vcell.parser.ExpressionException)9 File (java.io.File)9 KeyValue (org.vcell.util.document.KeyValue)8 PropertyVetoException (java.beans.PropertyVetoException)7 IOException (java.io.IOException)7 BigString (org.vcell.util.BigString)7 BioModelInfo (org.vcell.util.document.BioModelInfo)7