Search in sources :

Example 1 with NFsimSimulationOptions

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

the class NFSimFileWriter method write.

@Override
public void write(String[] parameterNames) throws Exception {
    WriterOutputStream wos = new WriterOutputStream(printWriter);
    NFsimSimulationOptions nfsimSimulationOptions = simTask.getSimulation().getSolverTaskDescription().getNFSimSimulationOptions();
    boolean bUseLocationMarks = true;
    Element root = NFsimXMLWriter.writeNFsimXML(simTask, randomSeed, nfsimSimulationOptions, bUseLocationMarks);
    if (bUseMessaging) {
        Element jms = super.xmlJMSParameters();
        root.addContent(jms);
    }
    // String resultString = XmlUtil.xmlToString(root);
    // resultString = XmlUtil.beautify(resultString);
    // resultString = resultString.replaceAll("DeleteMolecules=\"0\"", "DeleteMolecules=\"1\"");
    // 
    // System.out.println(resultString);
    // 
    // StringReader stringReader = new StringReader(resultString);	// transform back to element
    // SAXBuilder builder = new SAXBuilder();
    // Document doc1 = builder.build(stringReader);
    // Element root1 = doc1.getRootElement();
    // XmlUtil.writeXmlToStream(root1, false, wos);	// modified
    // original
    XmlUtil.writeXmlToStream(root, false, wos);
}
Also used : NFsimSimulationOptions(cbit.vcell.solver.NFsimSimulationOptions) Element(org.jdom.Element) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream)

Example 2 with NFsimSimulationOptions

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

the class Xmlproducer method getXML.

/**
 * This method returns a XML representation of a SolverTaskDescription object.
 * Creation date: (3/2/2001 10:59:55 PM)
 * @return Element
 * @param param cbit.vcell.solver.SolverTaskDescription
 */
private Element getXML(SolverTaskDescription param) {
    Element solvertask = new Element(XMLTags.SolverTaskDescriptionTag);
    // Add Attributes
    if (param.getTaskType() == SolverTaskDescription.TASK_UNSTEADY) {
        solvertask.setAttribute(XMLTags.TaskTypeTag, XMLTags.UnsteadyTag);
    } else if (param.getTaskType() == SolverTaskDescription.TASK_STEADY) {
        solvertask.setAttribute(XMLTags.TaskTypeTag, XMLTags.SteadyTag);
    } else {
        throw new IllegalArgumentException("Unexpected task type:" + param.getTaskType());
    }
    // solvertask.setAttribute(XMLTags.KeepEveryTag, String.valueOf(param.getKeepEvery()));
    // solvertask.setAttribute(XMLTags.KeepAtMostTag, String.valueOf(param.getKeepAtMost()));
    solvertask.setAttribute(XMLTags.UseSymbolicJacobianAttrTag, String.valueOf(param.getUseSymbolicJacobian()));
    // Add timeBounds
    solvertask.addContent(getXML(param.getTimeBounds()));
    // Add timeStep
    solvertask.addContent(getXML(param.getTimeStep()));
    // Add ErrorTolerence
    solvertask.addContent(getXML(param.getErrorTolerance()));
    // Jan 8, 2016 (jim) let getXML(stochOpt) write out the correct stochastic options
    if (param.getStochOpt() != null) {
        solvertask.addContent(getXML(param.getStochOpt(), param.getStochHybridOpt()));
    }
    // Add OutputOptions
    solvertask.addContent(getXML(param.getOutputTimeSpec()));
    // Add sensitivityParameter
    if (param.getSensitivityParameter() != null) {
        solvertask.addContent(getXML(param.getSensitivityParameter()));
    }
    // Add solver name
    solvertask.setAttribute(XMLTags.SolverNameTag, param.getSolverDescription().getDatabaseName());
    // Stop At Spatially Uniform
    ErrorTolerance stopAtSpatiallyUniformErrorTolerance = param.getStopAtSpatiallyUniformErrorTolerance();
    if (stopAtSpatiallyUniformErrorTolerance != null) {
        Element element = new Element(XMLTags.StopAtSpatiallyUniform);
        element.addContent(getXML(stopAtSpatiallyUniformErrorTolerance));
        solvertask.addContent(element);
    }
    boolean bRunParameterScanSerially = param.isSerialParameterScan();
    if (bRunParameterScanSerially) {
        solvertask.setAttribute(XMLTags.RunParameterScanSerially, String.valueOf(bRunParameterScanSerially));
    }
    SmoldynSimulationOptions smoldynSimulationOptions = param.getSmoldynSimulationOptions();
    if (smoldynSimulationOptions != null) {
        solvertask.addContent(getXML(smoldynSimulationOptions));
    }
    NFsimSimulationOptions nfsimSimulationOptions = param.getNFSimSimulationOptions();
    if (nfsimSimulationOptions != null) {
        solvertask.addContent(getXML(nfsimSimulationOptions));
    }
    SundialsPdeSolverOptions sundialsPdeSolverOptions = param.getSundialsPdeSolverOptions();
    if (sundialsPdeSolverOptions != null) {
        solvertask.addContent(getXML(sundialsPdeSolverOptions));
    }
    ChomboSolverSpec chomboSolverSpec = param.getChomboSolverSpec();
    if (chomboSolverSpec != null) {
        Element chomboElement = getXML(chomboSolverSpec);
        solvertask.addContent(chomboElement);
    }
    MovingBoundarySolverOptions mb = param.getMovingBoundarySolverOptions();
    if (mb != null) {
        Element e = getXML(mb);
        solvertask.addContent(e);
    }
    Element numProcessors = new Element(XMLTags.NUM_PROCESSORS);
    numProcessors.setText(Integer.toString(param.getNumProcessors()));
    solvertask.addContent(numProcessors);
    return solvertask;
}
Also used : SmoldynSimulationOptions(cbit.vcell.solver.SmoldynSimulationOptions) NFsimSimulationOptions(cbit.vcell.solver.NFsimSimulationOptions) MovingBoundarySolverOptions(cbit.vcell.solvers.mb.MovingBoundarySolverOptions) SundialsPdeSolverOptions(cbit.vcell.solver.SundialsPdeSolverOptions) Element(org.jdom.Element) ErrorTolerance(cbit.vcell.solver.ErrorTolerance) ChomboSolverSpec(org.vcell.chombo.ChomboSolverSpec)

Example 3 with NFsimSimulationOptions

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

the class SimulationSummaryPanel method displayTask.

/**
 * Comment
 */
private void displayTask() {
    SolverTaskDescription solverTaskDescription = getSimulation().getSolverTaskDescription();
    try {
        NonspatialStochSimOptions stochOpt = solverTaskDescription.getStochOpt();
        if (stochOpt != null && stochOpt.getNumOfTrials() > 1) {
            getJLabelOutput().setText("Histogram with " + stochOpt.getNumOfTrials() + " Trials(@last time point)");
        } else {
            // gcwtodo
            String text = solverTaskDescription.getOutputTimeSpec().getShortDescription();
            if (solverTaskDescription.getSolverDescription().isChomboSolver()) {
                text = "Variable";
                if (solverTaskDescription.getChomboSolverSpec().getTimeIntervalList().size() == 1) {
                    text = "Every " + solverTaskDescription.getChomboSolverSpec().getLastTimeInterval().getOutputTimeStep() + "s";
                }
            } else if (solverTaskDescription.getOutputTimeSpec().isDefault() && !solverTaskDescription.getSolverDescription().isSemiImplicitPdeSolver() && !solverTaskDescription.getSolverDescription().equals(SolverDescription.StochGibson)) {
                text += ", at most " + ((DefaultOutputTimeSpec) solverTaskDescription.getOutputTimeSpec()).getKeepAtMost();
            }
            getJLabelOutput().setText(text);
        }
    } catch (Exception exc) {
        exc.printStackTrace(System.out);
        getJLabelOutput().setText("");
    }
    SolverDescription solverDescription = solverTaskDescription.getSolverDescription();
    try {
        ErrorTolerance errorTolerance = solverTaskDescription.getErrorTolerance();
        TimeStep timeStep = solverTaskDescription.getTimeStep();
        getJLabelRelTol().setText("Rel tol");
        getJLabelAbsTol().setText("Abs tol");
        getJLabel12().setText("Timestep");
        getJLabelRelTol().setEnabled(false);
        getJLabelAbsTol().setEnabled(false);
        getJLabel12().setEnabled(false);
        getJLabel10().setText("Sensitivity Analysis");
        getJLabel10().setEnabled(true);
        if (solverDescription.equals(SolverDescription.StochGibson)) {
            getJLabel12().setEnabled(false);
            getJLabelTimestep().setText("");
        } else if (solverDescription.equals(SolverDescription.NFSim)) {
            TimeBounds tb = solverTaskDescription.getTimeBounds();
            double dtime = tb.getEndingTime() - tb.getStartingTime();
            if (solverTaskDescription.getOutputTimeSpec() instanceof UniformOutputTimeSpec) {
                UniformOutputTimeSpec uots = (UniformOutputTimeSpec) solverTaskDescription.getOutputTimeSpec();
                double interval = uots.getOutputTimeStep();
                int steps = (int) Math.round(dtime / interval);
                getJLabel12().setEnabled(true);
                getJLabel12().setText("Timepoints");
                getJLabelTimestep().setText(steps + "");
            } else if (solverTaskDescription.getOutputTimeSpec() instanceof DefaultOutputTimeSpec) {
                DefaultOutputTimeSpec uots = (DefaultOutputTimeSpec) solverTaskDescription.getOutputTimeSpec();
                getJLabel12().setEnabled(true);
                getJLabel12().setText("End Time");
                getJLabelTimestep().setText(solverTaskDescription.getTimeBounds().getEndingTime() + "");
            } else {
                getJLabel12().setEnabled(false);
                getJLabel12().setText("End Time");
                getJLabelTimestep().setText("na");
            }
            NFsimSimulationOptions nfsso = solverTaskDescription.getNFSimSimulationOptions();
            String utl = "default";
            Integer moleculeDistance = nfsso.getMoleculeDistance();
            if (moleculeDistance != null) {
                utl = moleculeDistance + "";
            }
            getJLabelRelTol().setEnabled(true);
            getJLabelRelTol().setText("Universal Transversal Limit");
            getJLabelRelTolValue().setText(utl);
            String gml = "default";
            Integer maxMoleculesPerType = nfsso.getMaxMoleculesPerType();
            if (maxMoleculesPerType != null) {
                gml = maxMoleculesPerType + "";
            }
            getJLabelAbsTol().setEnabled(true);
            getJLabelAbsTol().setText("Max # of each " + MolecularType.typeName);
            getJLabelAbsTolValue().setText(gml);
        } else if (solverDescription.isNonSpatialStochasticSolver()) {
            getJLabel12().setEnabled(true);
            getJLabel12().setText("Timestep");
            getJLabelTimestep().setText(timeStep.getDefaultTimeStep() + "s");
        } else if (solverDescription.hasVariableTimestep()) {
            getJLabel12().setEnabled(true);
            getJLabel12().setText("Max timestep");
            getJLabelTimestep().setText(timeStep.getMaximumTimeStep() + "s");
            getJLabelRelTol().setEnabled(true);
            getJLabelRelTolValue().setText("" + errorTolerance.getRelativeErrorTolerance());
            getJLabelAbsTol().setEnabled(true);
            getJLabelAbsTolValue().setText("" + errorTolerance.getAbsoluteErrorTolerance());
        } else {
            getJLabel12().setEnabled(true);
            getJLabel12().setText("Timestep");
            if (solverDescription.isChomboSolver()) {
                String text = "Variable";
                if (solverTaskDescription.getChomboSolverSpec().getTimeIntervalList().size() == 1) {
                    text = solverTaskDescription.getChomboSolverSpec().getLastTimeInterval().getTimeStep() + "s";
                }
                getJLabelTimestep().setText(text);
            } else {
                getJLabelTimestep().setText(timeStep.getDefaultTimeStep() + "s");
            }
            if (solverDescription.isSemiImplicitPdeSolver()) {
                getJLabelRelTol().setEnabled(true);
                getJLabelRelTolValue().setText("" + errorTolerance.getRelativeErrorTolerance());
            } else {
                getJLabelRelTol().setEnabled(false);
                getJLabelRelTolValue().setText("");
            }
            getJLabelAbsTol().setEnabled(false);
            getJLabelAbsTolValue().setText("");
        }
    } catch (Exception exc) {
        exc.printStackTrace(System.out);
        getJLabelTimestep().setText("");
        getJLabelRelTolValue().setText("");
        getJLabelAbsTolValue().setText("");
    }
    try {
        boolean bChomboSolver = solverDescription.isChomboSolver();
        getJLabelTitleNumProcessors().setVisible(bChomboSolver);
        getJLabelNumProcessors().setVisible(bChomboSolver);
        if (bChomboSolver) {
            getJLabelNumProcessors().setText(String.valueOf(solverTaskDescription.getNumProcessors()));
        }
        if (getSimulation().isSpatial() || solverDescription.isNonSpatialStochasticSolver()) {
            getJLabelSensitivity().setVisible(false);
            getJLabel10().setVisible(false);
        } else if (solverDescription.equals(SolverDescription.NFSim)) {
            getJLabel10().setText("On-the-fly observ comp.");
            NFsimSimulationOptions nfsso = solverTaskDescription.getNFSimSimulationOptions();
            boolean goc = nfsso.getObservableComputationOff();
            getJLabelSensitivity().setText(goc + "");
        } else {
            getJLabelSensitivity().setVisible(true);
            getJLabel10().setVisible(true);
            Constant param = solverTaskDescription.getSensitivityParameter();
            if (param == null) {
                getJLabelSensitivity().setText("no");
            } else {
                getJLabelSensitivity().setText(param.getName());
            }
        }
    } catch (Exception exc) {
        exc.printStackTrace(System.out);
        getJLabelSensitivity().setText("");
    }
    if (solverDescription.isNonSpatialStochasticSolver()) {
        getJLabelRelTol().setVisible(false);
        getJLabelAbsTol().setVisible(false);
        getJLabelRelTolValue().setVisible(false);
        getJLabelAbsTolValue().setVisible(false);
    } else {
        getJLabelRelTol().setVisible(true);
        getJLabelAbsTol().setVisible(true);
    }
}
Also used : NFsimSimulationOptions(cbit.vcell.solver.NFsimSimulationOptions) SolverDescription(cbit.vcell.solver.SolverDescription) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) Constant(cbit.vcell.math.Constant) NonspatialStochSimOptions(cbit.vcell.solver.NonspatialStochSimOptions) PropertyVetoException(java.beans.PropertyVetoException) TimeStep(cbit.vcell.solver.TimeStep) TimeBounds(cbit.vcell.solver.TimeBounds) ErrorTolerance(cbit.vcell.solver.ErrorTolerance) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec)

Example 4 with NFsimSimulationOptions

use of cbit.vcell.solver.NFsimSimulationOptions 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 5 with NFsimSimulationOptions

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

the class NFSimSimulationOptionsPanel method refresh.

private void refresh() {
    if (solverTaskDescription != null) {
        MathDescription mathDescription = solverTaskDescription.getSimulation().getMathDescription();
        if (!(mathDescription.isRuleBased())) {
            setVisible(false);
            return;
        }
    }
    setVisible(true);
    NFsimSimulationOptions nfsimSimulationOptions = solverTaskDescription.getNFSimSimulationOptions();
    boolean notf = nfsimSimulationOptions.getObservableComputationOff();
    if (notf == false) {
        observableComputationCheckBox.setSelected(false);
    } else {
        observableComputationCheckBox.setSelected(true);
    }
    Integer utl = nfsimSimulationOptions.getMoleculeDistance();
    if (utl == null) {
        // we always force this parameter, even for legacy simulations where it was optional
        // the default value is DefaultDistanceToMolecules but the user may still choose something else
        moleculeDistanceTextField.setEditable(true);
        moleculeDistanceTextField.setText(NFsimSimulationOptions.DefaultDistanceToMolecules + "");
        moleculeDistanceCheckBox.setSelected(true);
        moleculeDistanceCheckBox.setEnabled(false);
    } else {
        moleculeDistanceTextField.setEditable(true);
        moleculeDistanceTextField.setText("" + utl);
        moleculeDistanceCheckBox.setSelected(true);
        moleculeDistanceCheckBox.setEnabled(false);
    }
    boolean cb = nfsimSimulationOptions.getAggregateBookkeeping();
    if (cb == false) {
        // put it back here to false
        aggregateBookkeepingCheckBox.setSelected(true);
    } else {
        aggregateBookkeepingCheckBox.setSelected(true);
    }
    Integer gml = nfsimSimulationOptions.getMaxMoleculesPerType();
    if (gml == null) {
        maxMoleculesPerTypeTextField.setEditable(false);
        maxMoleculesPerTypeCheckBox.setSelected(false);
    } else {
        maxMoleculesPerTypeTextField.setEditable(true);
        maxMoleculesPerTypeCheckBox.setSelected(true);
        maxMoleculesPerTypeTextField.setText("" + gml);
    }
    Integer eq = nfsimSimulationOptions.getEquilibrateTime();
    if (eq == null) {
        equilibrateTimeTextField.setEditable(false);
        equilibrateTimeCheckBox.setSelected(false);
    } else {
        equilibrateTimeTextField.setEditable(true);
        equilibrateTimeCheckBox.setSelected(true);
        equilibrateTimeTextField.setText("" + eq);
    }
    Integer randomSeed = nfsimSimulationOptions.getRandomSeed();
    if (randomSeed == null) {
        randomSeedTextField.setEditable(false);
        randomSeedCheckBox.setSelected(false);
    } else {
        randomSeedTextField.setEditable(true);
        randomSeedCheckBox.setSelected(true);
        randomSeedTextField.setText(randomSeed.toString());
    }
    boolean bscb = nfsimSimulationOptions.getPreventIntraBonds();
    if (bscb == false) {
        preventIntraBondsCheckBox.setSelected(false);
    } else {
        preventIntraBondsCheckBox.setSelected(true);
    }
}
Also used : NFsimSimulationOptions(cbit.vcell.solver.NFsimSimulationOptions) MathDescription(cbit.vcell.math.MathDescription)

Aggregations

NFsimSimulationOptions (cbit.vcell.solver.NFsimSimulationOptions)8 Element (org.jdom.Element)4 DefaultOutputTimeSpec (cbit.vcell.solver.DefaultOutputTimeSpec)3 UniformOutputTimeSpec (cbit.vcell.solver.UniformOutputTimeSpec)3 Constant (cbit.vcell.math.Constant)2 ErrorTolerance (cbit.vcell.solver.ErrorTolerance)2 OutputTimeSpec (cbit.vcell.solver.OutputTimeSpec)2 SmoldynSimulationOptions (cbit.vcell.solver.SmoldynSimulationOptions)2 SolverDescription (cbit.vcell.solver.SolverDescription)2 SolverTaskDescription (cbit.vcell.solver.SolverTaskDescription)2 SundialsPdeSolverOptions (cbit.vcell.solver.SundialsPdeSolverOptions)2 TimeBounds (cbit.vcell.solver.TimeBounds)2 MovingBoundarySolverOptions (cbit.vcell.solvers.mb.MovingBoundarySolverOptions)2 PropertyVetoException (java.beans.PropertyVetoException)2 ChomboSolverSpec (org.vcell.chombo.ChomboSolverSpec)2 SimulationContext (cbit.vcell.mapping.SimulationContext)1 MacroscopicRateConstant (cbit.vcell.math.MacroscopicRateConstant)1 MathDescription (cbit.vcell.math.MathDescription)1 SimulationTask (cbit.vcell.messaging.server.SimulationTask)1 ExplicitOutputTimeSpec (cbit.vcell.solver.ExplicitOutputTimeSpec)1