Search in sources :

Example 31 with Simulation

use of cbit.vcell.solver.Simulation in project vcell by virtualcell.

the class BioModel method propertyChange.

/**
 * This method gets called when a bound property is changed.
 * @param evt A PropertyChangeEvent object describing the event source
 *   	and the property that has changed.
 */
public void propertyChange(java.beans.PropertyChangeEvent evt) {
    // 
    if (evt.getSource() instanceof SimulationContext && evt.getPropertyName().equals("mathDescription") && evt.getNewValue() != null) {
        if (fieldSimulations != null) {
            for (int i = 0; i < fieldSimulations.length; i++) {
                if (fieldSimulations[i].getMathDescription() == evt.getOldValue()) {
                    try {
                        fieldSimulations[i].setMathDescription((MathDescription) evt.getNewValue());
                    } catch (PropertyVetoException e) {
                        System.out.println("error propagating math from SimulationContext '" + ((SimulationContext) evt.getSource()).getName() + "' to Simulation '" + fieldSimulations[i].getName());
                        e.printStackTrace(System.out);
                    }
                }
            }
        }
    }
    // 
    if (evt.getSource() == this && evt.getPropertyName().equals(PropertyConstants.PROPERTY_NAME_SIMULATIONS) && evt.getNewValue() != null) {
        // 
        if (evt.getOldValue() != null) {
            Simulation[] simulations = (Simulation[]) evt.getOldValue();
            for (int i = 0; i < simulations.length; i++) {
                simulations[i].removeVetoableChangeListener(this);
                simulations[i].removePropertyChangeListener(this);
            }
        }
        // 
        if (evt.getOldValue() != null) {
            Simulation[] simulations = (Simulation[]) evt.getNewValue();
            for (int i = 0; i < simulations.length; i++) {
                simulations[i].addVetoableChangeListener(this);
                simulations[i].addPropertyChangeListener(this);
            }
        }
    }
    if (evt.getSource() == this && evt.getPropertyName().equals(PROPERTY_NAME_SIMULATION_CONTEXTS) && evt.getNewValue() != null) {
        // 
        if (evt.getOldValue() != null) {
            SimulationContext[] simulationContexts = (SimulationContext[]) evt.getOldValue();
            for (int i = 0; i < simulationContexts.length; i++) {
                simulationContexts[i].removeVetoableChangeListener(this);
                simulationContexts[i].removePropertyChangeListener(this);
            }
        }
        // 
        if (evt.getOldValue() != null) {
            SimulationContext[] simulationContexts = (SimulationContext[]) evt.getNewValue();
            for (int i = 0; i < simulationContexts.length; i++) {
                simulationContexts[i].addVetoableChangeListener(this);
                simulationContexts[i].addPropertyChangeListener(this);
            }
        }
    }
    if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(Model.PROPERTY_NAME_SPECIES_CONTEXTS) || evt.getPropertyName().equals(Model.PROPERTY_NAME_REACTION_STEPS))) {
        // remove the relationship objects if the biomodelEntity objects were removed
        Set<BioModelEntityObject> removedObjects = relationshipModel.getBioModelEntityObjects();
        for (SpeciesContext sc : fieldModel.getSpeciesContexts()) {
            removedObjects.remove(sc);
        }
        for (ReactionStep rs : fieldModel.getReactionSteps()) {
            removedObjects.remove(rs);
        }
        for (MolecularType mt : fieldModel.getRbmModelContainer().getMolecularTypeList()) {
            removedObjects.remove(mt);
        }
        for (ReactionRule rr : fieldModel.getRbmModelContainer().getReactionRuleList()) {
            removedObjects.remove(rr);
        }
        relationshipModel.removeRelationshipObjects(removedObjects);
    }
    // adjust the relationship model when a molecule gets deleted
    if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_MOLECULAR_TYPE_LIST))) {
        @SuppressWarnings("unchecked") List<MolecularType> oldListCopy = new ArrayList<MolecularType>((List<MolecularType>) evt.getOldValue());
        @SuppressWarnings("unchecked") List<MolecularType> newList = (List<MolecularType>) evt.getNewValue();
        if (newList != null && oldListCopy != null && oldListCopy.size() > newList.size()) {
            // something got deleted
            oldListCopy.removeAll(newList);
            for (MolecularType removedMt : oldListCopy) {
                relationshipModel.removeRelationshipObject(removedMt);
            }
        }
    }
    if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_REACTION_RULE_LIST))) {
        @SuppressWarnings("unchecked") List<ReactionRule> oldListCopy = new ArrayList<ReactionRule>((List<ReactionRule>) evt.getOldValue());
        @SuppressWarnings("unchecked") List<ReactionRule> newList = (List<ReactionRule>) evt.getNewValue();
        if (newList != null && oldListCopy != null && oldListCopy.size() > newList.size()) {
            // something got deleted
            oldListCopy.removeAll(newList);
            for (ReactionRule removedRr : oldListCopy) {
                relationshipModel.removeRelationshipObject(removedRr);
            }
        }
    }
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) ArrayList(java.util.ArrayList) SpeciesContext(cbit.vcell.model.SpeciesContext) SimulationContext(cbit.vcell.mapping.SimulationContext) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject) PropertyVetoException(java.beans.PropertyVetoException) MolecularType(org.vcell.model.rbm.MolecularType) Simulation(cbit.vcell.solver.Simulation) ReactionStep(cbit.vcell.model.ReactionStep) List(java.util.List) ArrayList(java.util.ArrayList)

Example 32 with Simulation

use of cbit.vcell.solver.Simulation in project vcell by virtualcell.

the class NfsimExtensionFilter method writeBioModel.

@Override
public void writeBioModel(DocumentManager documentManager, BioModel bioModel, File exportFile, SimulationContext simulationContext) throws Exception {
    // TODO: get the first thing we find for now, in the future we'll need to modify ChooseFile
    // to only offer the applications / simulations with bngl content
    // This should be done by creating one or more additional Selector values and add the filtering logic to ChooseFile
    SimulationContext[] simContexts = bioModel.getSimulationContexts();
    Simulation selectedSim = simulationContext.getSimulations(0);
    // Simulation selectedSim = (Simulation)hashTable.get("selectedSimulation");
    SimulationTask simTask = new SimulationTask(new SimulationJob(selectedSim, 0, null), 0);
    // a fixed seed will allow us to run reproducible simulations
    long randomSeed = 0;
    // long randomSeed = System.currentTimeMillis();
    NFsimSimulationOptions nfsimSimulationOptions = new NFsimSimulationOptions();
    // we get the data we need from the math description
    boolean bUseLocationMarks = true;
    Element root = NFsimXMLWriter.writeNFsimXML(simTask, randomSeed, nfsimSimulationOptions, bUseLocationMarks);
    Document doc = new Document();
    doc.setRootElement(root);
    XMLOutputter xmlOut = new XMLOutputter();
    String resultString = xmlOut.outputString(doc);
    FileUtils.writeStringToFile(exportFile, resultString);
}
Also used : NFsimSimulationOptions(cbit.vcell.solver.NFsimSimulationOptions) XMLOutputter(org.jdom.output.XMLOutputter) SimulationTask(cbit.vcell.messaging.server.SimulationTask) Simulation(cbit.vcell.solver.Simulation) Element(org.jdom.Element) SimulationContext(cbit.vcell.mapping.SimulationContext) Document(org.jdom.Document) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 33 with Simulation

use of cbit.vcell.solver.Simulation in project vcell by virtualcell.

the class SbmlExtensionFilter method askUser.

@Override
public void askUser(ChooseContext c) throws UserCancelException {
    BioModel bioModel = c.chosenContext.getBioModel();
    JFrame currentWindow = c.currentWindow;
    selectedSimWOSBE = null;
    selectedSimContext = c.chosenContext;
    // get user choice of structure and its size and computes absolute sizes of compartments using the StructureSizeSolver.
    Structure[] structures = bioModel.getModel().getStructures();
    // get the nonspatial simulationContexts corresponding to names in applicableAppNameList
    // This is needed in ApplnSelectionAndStructureSizeInputPanel
    String strucName = null;
    double structSize = 1.0;
    int structSelection = -1;
    int option = JOptionPane.CANCEL_OPTION;
    ApplnSelectionAndStructureSizeInputPanel applnStructInputPanel = null;
    while (structSelection < 0) {
        applnStructInputPanel = new ApplnSelectionAndStructureSizeInputPanel();
        applnStructInputPanel.setSimContext(c.chosenContext);
        applnStructInputPanel.setStructures(structures);
        if (applnStructInputPanel.isNeedStructureSizes()) {
            applnStructInputPanel.setPreferredSize(new java.awt.Dimension(350, 400));
            applnStructInputPanel.setMaximumSize(new java.awt.Dimension(350, 400));
            option = DialogUtils.showComponentOKCancelDialog(currentWindow, applnStructInputPanel, "Specify Structure Size to Export:");
            structSelection = applnStructInputPanel.getStructSelectionIndex();
            if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
                break;
            } else if (option == JOptionPane.OK_OPTION && structSelection < 0) {
                DialogUtils.showErrorDialog(currentWindow, "Please select a structure and set its size");
            }
        } else {
            // adapt to legacy logic ...
            structSelection = 0;
            option = JOptionPane.OK_OPTION;
        }
    }
    if (option == JOptionPane.OK_OPTION) {
        applnStructInputPanel.applyStructureNameAndSizeValues();
        strucName = applnStructInputPanel.getSelectedStructureName();
        selectedSimContext = applnStructInputPanel.getSelectedSimContext();
        GeometryContext geoContext = selectedSimContext.getGeometryContext();
        if (!isSpatial) {
            // calculate structure Sizes only if appln is not spatial
            structSize = applnStructInputPanel.getStructureSize();
            // Invoke StructureSizeEvaluator to compute absolute sizes of compartments if all sizes are not set
            if ((geoContext.isAllSizeSpecifiedNull() && geoContext.isAllVolFracAndSurfVolSpecifiedNull()) || ((strucName == null || structSize <= 0.0) && (geoContext.isAllSizeSpecifiedNull() && geoContext.isAllVolFracAndSurfVolSpecified())) || (!geoContext.isAllSizeSpecifiedPositive() && geoContext.isAllVolFracAndSurfVolSpecifiedNull()) || (!geoContext.isAllSizeSpecifiedPositive() && !geoContext.isAllVolFracAndSurfVolSpecified()) || (geoContext.isAllSizeSpecifiedNull() && !geoContext.isAllVolFracAndSurfVolSpecified())) {
                DialogUtils.showErrorDialog(currentWindow, "Cannot export to SBML without compartment sizes being set. This can be automatically " + " computed if the absolute size of at least one compartment and the relative sizes (Surface-to-volume-ratio/Volume-fraction) " + " of all compartments are known. Sufficient information is not available to perform this computation." + "\n\nThis can be fixed by going back to the application '" + selectedSimContext.getName() + "' and setting structure sizes in the 'StructureMapping' tab.");
                throw UserCancelException.CANCEL_XML_TRANSLATION;
            }
            if (!geoContext.isAllSizeSpecifiedPositive() && geoContext.isAllVolFracAndSurfVolSpecified()) {
                Structure chosenStructure = selectedSimContext.getModel().getStructure(strucName);
                StructureMapping chosenStructMapping = selectedSimContext.getGeometryContext().getStructureMapping(chosenStructure);
                try {
                    StructureSizeSolver.updateAbsoluteStructureSizes(selectedSimContext, chosenStructure, structSize, chosenStructMapping.getSizeParameter().getUnitDefinition());
                } catch (Exception e) {
                    throw new ProgrammingException("exception updating sizes", e);
                }
            }
        } else {
            if (!geoContext.isAllUnitSizeParameterSetForSpatial()) {
                DialogUtils.showErrorDialog(currentWindow, "Cannot export to SBML without compartment size ratios being set." + "\n\nThis can be fixed by going back to the application '" + selectedSimContext.getName() + "' and setting structure" + " size ratios in the 'StructureMapping' tab.");
                throw UserCancelException.CANCEL_XML_TRANSLATION;
            }
        }
        // Select simulation whose overrides need to be exported
        // If simContext doesn't have simulations, don't pop up simulationSelectionPanel
        Simulation[] sims = bioModel.getSimulations(selectedSimContext);
        // display only those simulations that have overrides in the simulationSelectionPanel.
        Vector<Simulation> orSims = new Vector<Simulation>();
        for (int s = 0; (sims != null) && (s < sims.length); s++) {
            if (sims[s].getMathOverrides().hasOverrides()) {
                orSims.addElement(sims[s]);
            }
        }
        Simulation[] overriddenSims = orSims.toArray(new Simulation[orSims.size()]);
        if (overriddenSims.length > 0) {
            SimulationSelectionPanel simSelectionPanel = new SimulationSelectionPanel();
            simSelectionPanel.setPreferredSize(new java.awt.Dimension(600, 400));
            simSelectionPanel.setMaximumSize(new java.awt.Dimension(600, 400));
            simSelectionPanel.setSimulations(overriddenSims);
            int simOption = DialogUtils.showComponentOKCancelDialog(currentWindow, simSelectionPanel, "Select Simulation whose overrides should be exported:");
            if (simOption == JOptionPane.OK_OPTION) {
                selectedSimWOSBE = simSelectionPanel.getSelectedSimulation();
            // if (chosenSimulation != null) {
            // CARRY						hashTable.put("selectedSimulation", chosenSimulation);
            // }
            } else if (simOption == JOptionPane.CANCEL_OPTION || simOption == JOptionPane.CLOSED_OPTION) {
                // Hence canceling the entire export to SBML operation.
                throw UserCancelException.CANCEL_XML_TRANSLATION;
            }
        }
    } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
        // Hence canceling the entire export to SBML operation.
        throw UserCancelException.CANCEL_XML_TRANSLATION;
    }
    if (selectedSimWOSBE != null) {
        String selectedFileName = c.filename;
        // rename file to contain exported simulation.
        String ext = FilenameUtils.getExtension(selectedFileName);
        String base = FilenameUtils.getBaseName(selectedFileName);
        String path = FilenameUtils.getPath(selectedFileName);
        base += "_" + TokenMangler.mangleToSName(selectedSimWOSBE.getName());
        selectedFileName = path + base + ext;
        c.selectedFile.renameTo(new File(selectedFileName));
    }
}
Also used : SimulationSelectionPanel(org.vcell.sbml.gui.SimulationSelectionPanel) StructureMapping(cbit.vcell.mapping.StructureMapping) ProgrammingException(org.vcell.util.ProgrammingException) UserCancelException(org.vcell.util.UserCancelException) Simulation(cbit.vcell.solver.Simulation) JFrame(javax.swing.JFrame) ApplnSelectionAndStructureSizeInputPanel(org.vcell.sbml.gui.ApplnSelectionAndStructureSizeInputPanel) BioModel(cbit.vcell.biomodel.BioModel) GeometryContext(cbit.vcell.mapping.GeometryContext) ProgrammingException(org.vcell.util.ProgrammingException) Structure(cbit.vcell.model.Structure) Vector(java.util.Vector) File(java.io.File)

Example 34 with Simulation

use of cbit.vcell.solver.Simulation in project vcell by virtualcell.

the class SmoldynExtensionFilter method askUser.

@Override
public void askUser(ChooseContext ctx) throws UserCancelException {
    SimulationContext chosenSimContext = ctx.chosenContext;
    String[] simNames = new String[chosenSimContext.getSimulations().length];
    Simulation[] sims = chosenSimContext.getSimulations();
    for (int i = 0; i < sims.length; i++) {
        simNames[i] = sims[i].getName();
    }
    Object choice = PopupGenerator.showListDialog(ctx.topLevelWindowManager, simNames, "Please select " + chosenSimContext.getName() + " simulation to export");
    if (choice == null) {
        throw UserCancelException.CANCEL_FILE_SELECTION;
    }
    String chosenSimulationName = (String) choice;
    Simulation chosenSimulation = chosenSimContext.getSimulation(chosenSimulationName);
    Objects.requireNonNull(chosenSimulation);
    // PENDING delete
    ctx.hashTable.put(SIM_KEY, chosenSimulation);
    selectedSim = chosenSimulation;
}
Also used : Simulation(cbit.vcell.solver.Simulation) SimulationContext(cbit.vcell.mapping.SimulationContext)

Example 35 with Simulation

use of cbit.vcell.solver.Simulation in project vcell by virtualcell.

the class ClientDocumentManager method getMathModel.

/**
 * 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 MathModel getMathModel(KeyValue mathModelKey) throws DataAccessException {
    XMLHolder<MathModel> mathModelXML = getMathModelXML(mathModelKey);
    MathModel mathModel = getMathModelFromDatabaseXML(mathModelXML);
    // 
    // preload SimulationJobStatus for all simulations if any missing from hash.
    // 
    Simulation[] simulations = mathModel.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 mathModel;
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) Simulation(cbit.vcell.solver.Simulation)

Aggregations

Simulation (cbit.vcell.solver.Simulation)195 SimulationContext (cbit.vcell.mapping.SimulationContext)57 BioModel (cbit.vcell.biomodel.BioModel)53 MathDescription (cbit.vcell.math.MathDescription)48 KeyValue (org.vcell.util.document.KeyValue)33 Geometry (cbit.vcell.geometry.Geometry)29 MathModel (cbit.vcell.mathmodel.MathModel)27 Expression (cbit.vcell.parser.Expression)26 DataAccessException (org.vcell.util.DataAccessException)26 File (java.io.File)25 ExpressionException (cbit.vcell.parser.ExpressionException)24 IOException (java.io.IOException)24 SimulationJob (cbit.vcell.solver.SimulationJob)23 ArrayList (java.util.ArrayList)23 PropertyVetoException (java.beans.PropertyVetoException)20 UniformOutputTimeSpec (cbit.vcell.solver.UniformOutputTimeSpec)18 XMLSource (cbit.vcell.xml.XMLSource)18 SimulationTask (cbit.vcell.messaging.server.SimulationTask)17 TimeBounds (cbit.vcell.solver.TimeBounds)16 BigString (org.vcell.util.BigString)16