Search in sources :

Example 6 with AbstractTask

use of org.jlibsedml.AbstractTask in project vcell by virtualcell.

the class VCellSedMLSolver method doWork.

// everything is done here
public void doWork(ExternalDocInfo externalDocInfo, AbstractTask sedmlTask, SedML sedml) throws Exception {
    // create the VCDocument (bioModel + application + simulation), do sanity checks
    cbit.util.xml.VCLogger sedmlImportLogger = new LocalLogger();
    List<AbstractTask> tasks = new ArrayList<AbstractTask>();
    tasks.add(sedmlTask);
    List<VCDocument> docs = XmlHelper.sedmlToBioModel(sedmlImportLogger, externalDocInfo, sedml, tasks, null, false);
    VCDocument doc = docs.get(0);
    sanityCheck(doc);
    // create the work directory for this task, invoke the solver
    String docName = doc.getName();
    String outString = VCellSedMLSolver.OUT_ROOT_STRING + "/" + docName + "/" + sedmlTask.getId();
    File outDir = new File(outString);
    if (!outDir.exists()) {
        outDir.mkdirs();
    }
    BioModel bioModel = (BioModel) doc;
    SimulationContext simContext = bioModel.getSimulationContext(0);
    MathDescription mathDesc = simContext.getMathDescription();
    String vcml = mathDesc.getVCML();
    try (PrintWriter pw = new PrintWriter(outString + "/vcmlTrace.xml")) {
        pw.println(vcml);
    }
    Simulation sim = bioModel.getSimulation(0);
    SolverTaskDescription std = sim.getSolverTaskDescription();
    SolverDescription sd = std.getSolverDescription();
    String kisao = sd.getKisao();
    if (SolverDescription.CVODE.getKisao().contentEquals(kisao)) {
        ODESolverResultSet odeSolverResultSet = solveCvode(outDir, bioModel);
        System.out.println("Finished: " + docName + ": - task '" + sedmlTask.getId() + "'.");
    } else if (SolverDescription.StochGibson.getKisao().contentEquals(kisao)) {
        ODESolverResultSet odeSolverResultSet = solveGibson(outDir, bioModel);
        System.out.println("Finished: " + docName + ": - task '" + sedmlTask.getId() + "'.");
    } else if (SolverDescription.IDA.getKisao().contentEquals(kisao)) {
        ODESolverResultSet odeSolverResultSet = solveIDA(outDir, bioModel);
        System.out.println("Finished: " + docName + ": - task '" + sedmlTask.getId() + "'.");
    } else {
        System.out.println("Unsupported solver: " + kisao);
    }
    System.out.println("-------------------------------------------------------------------------");
}
Also used : AbstractTask(org.jlibsedml.AbstractTask) SolverDescription(cbit.vcell.solver.SolverDescription) VCDocument(org.vcell.util.document.VCDocument) MathDescription(cbit.vcell.math.MathDescription) VCLogger(cbit.util.xml.VCLogger) SimulationContext(cbit.vcell.mapping.SimulationContext) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription)

Example 7 with AbstractTask

use of org.jlibsedml.AbstractTask in project vcell by virtualcell.

the class SEDMLChooserPanel method initialize.

private void initialize() {
    Set<String> issues = new HashSet<>();
    setLayout(new GridBagLayout());
    int gridy = 0;
    // (incompatibility with vCell for example) and for them we create a list of problems which we show to the user
    for (AbstractTask at : sedml.getTasks()) {
        String text = "";
        String tooltip = "";
        boolean issueFound = false;
        if (at instanceof Task) {
            Task t = (Task) at;
            text = " Simple task '" + t.getId() + "' - " + sedml.getModelWithId(t.getModelReference()).getClass().getSimpleName() + // model class
            " '" + SEDMLUtil.getName(sedml.getModelWithId(t.getModelReference())) + "' : " + sedml.getSimulation(t.getSimulationReference()).getClass().getSimpleName() + // simulation class
            " '" + SEDMLUtil.getName(sedml.getSimulation(t.getSimulationReference())) + "' ";
            tooltip = "The model has " + sedml.getModelWithId(t.getModelReference()).getListOfChanges().size() + " changes.";
        } else if (at instanceof RepeatedTask) {
            RepeatedTask rt = (RepeatedTask) at;
            // TODO: we issue warning that importing repeated task is not implemented yet
            // but we have still can import it as simple task, so we don't set issueFound to true
            issues.add("Importing a RepeatedTask is not implemented yet, '" + SEDMLUtil.getName(rt) + "' may be imported as SimpleTask.");
            // add an error message to the list of errors and skip the task
            for (Change c : rt.getChanges()) {
                if (!c.getChangeKind().equals(SEDMLTags.SET_VALUE_KIND)) {
                    issues.add("The '" + c.getChangeKind() + "' change kind is not supported.");
                    issueFound = true;
                }
            }
            switch(rt.getSubTasks().size()) {
                case 0:
                    issues.add("At least one subtask is required within a repeated task: " + rt.getId());
                    issueFound = true;
                case 1:
                    // first (and only) element
                    SubTask st = rt.getSubTasks().entrySet().iterator().next().getValue();
                    String taskId = st.getTaskId();
                    AbstractTask t = sedml.getTaskWithId(taskId);
                    text = " Repeated task '" + rt.getId() + "' - " + sedml.getModelWithId(t.getModelReference()).getClass().getSimpleName() + // model class
                    " '" + SEDMLUtil.getName(sedml.getModelWithId(t.getModelReference())) + "' : " + sedml.getSimulation(t.getSimulationReference()).getClass().getSimpleName() + // simulation class
                    " '" + SEDMLUtil.getName(sedml.getSimulation(t.getSimulationReference())) + "' ";
                    tooltip = "The repeated task has " + rt.getChanges().size() + " changes and " + rt.getRanges().size() + " ranges.";
                    break;
                default:
                    issues.add("Multiple subtasks within a repeated task '" + rt.getId() + "' are not supported.");
                    issueFound = true;
            }
        } else {
            issues.add("The task class '" + SEDMLUtil.getName(at) + "' is not supported.");
            issueFound = true;
        }
        if (issueFound) {
            // we skip the tasks we don't know how to import in vCell
            continue;
        }
        JRadioButton rb = new JRadioButton(text);
        rb.setToolTipText(tooltip);
        SEDMLRadioButtonModel bm = new SEDMLRadioButtonModel(at);
        rb.setModel(bm);
        if (gridy == 0) {
            rb.setSelected(true);
        }
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(2, 4, 2, 4);
        group.add(rb);
        add(rb, gbc);
        gridy++;
    }
    // we display the issues (but no more than a certain number)
    final int MAX_ISSUES = 10;
    int issueIndex = 0;
    for (String issue : issues) {
        if (issueIndex >= MAX_ISSUES) {
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = gridy;
            gbc.anchor = GridBagConstraints.WEST;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.insets = new Insets(2, 4, 2, 4);
            add(new JLabel("<html><font color = \"#8B0000\">" + "...More" + "</font></html>"), gbc);
            gridy++;
            break;
        }
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(2, 4, 2, 4);
        add(new JLabel("<html><font color = \"#8B0000\">" + issue + "</font></html>"), gbc);
        gridy++;
        issueIndex++;
    }
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.gridwidth = 2;
    gbc.weightx = 1;
    // fake cell used for filling all the vertical empty space
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(4, 4, 4, 10);
    add(new JLabel(""), gbc);
}
Also used : RepeatedTask(org.jlibsedml.RepeatedTask) SubTask(org.jlibsedml.SubTask) AbstractTask(org.jlibsedml.AbstractTask) Task(org.jlibsedml.Task) GridBagConstraints(java.awt.GridBagConstraints) AbstractTask(org.jlibsedml.AbstractTask) JRadioButton(javax.swing.JRadioButton) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) Change(org.jlibsedml.Change) RepeatedTask(org.jlibsedml.RepeatedTask) SubTask(org.jlibsedml.SubTask) HashSet(java.util.HashSet)

Example 8 with AbstractTask

use of org.jlibsedml.AbstractTask in project vcell by virtualcell.

the class SEDMLChooserPanel method chooseTask.

public static AbstractTask chooseTask(SedML sedml, Component requester, String name) {
    SEDMLChooserPanel panel = new SEDMLChooserPanel(sedml);
    int oKCancel = DialogUtils.showComponentOKCancelDialog(requester, panel, "Import Sed-ML file: " + name);
    if (oKCancel == JOptionPane.CANCEL_OPTION || oKCancel == JOptionPane.DEFAULT_OPTION) {
        throw new UserCancelException("Canceling Import");
    }
    SEDMLRadioButtonModel bm = (SEDMLRadioButtonModel) panel.group.getSelection();
    AbstractTask tt = bm.getTask();
    return tt;
}
Also used : AbstractTask(org.jlibsedml.AbstractTask) UserCancelException(org.vcell.util.UserCancelException)

Example 9 with AbstractTask

use of org.jlibsedml.AbstractTask in project vcell by virtualcell.

the class AbstractSedmlExecutor method runSimulations.

/**
 * Main method for running simulations
 *
 * @return A non-null Map<AbstractTask, IRawSedmlSimulationResults>
 */
public final Map<AbstractTask, IRawSedmlSimulationResults> runSimulations() {
    failureMessages.clear();
    log.debug("Running simulations");
    Map<AbstractTask, IRawSedmlSimulationResults> res = new HashMap<AbstractTask, IRawSedmlSimulationResults>();
    Set<AbstractTask> tasksToExecute = new HashSet<AbstractTask>();
    if (task != null) {
        tasksToExecute.add(task);
    } else {
        tasksToExecute = findTasks(output);
    }
    if (tasksToExecute.isEmpty()) {
        addStatus(new ExecutionStatusElement(null, NO_TASKS_ERROR, ExecutionStatusType.ERROR));
        return res;
    }
    log.debug("Got a task to execute");
    for (AbstractTask t : tasksToExecute) {
        if (!getSimulatableTasks().contains(t)) {
            addStatus(new ExecutionStatusElement(null, NO_SIMULATABLE_TASK_ERROR1 + t.getId() + NO_SIMULATABLE_TASK_ERROR2, ExecutionStatusType.ERROR));
            return res;
        }
    }
    for (AbstractTask task : tasksToExecute) {
        Model m = sedml.getModelWithId(task.getModelReference());
        if (!supportsLanguage(m.getLanguage())) {
            addStatus(new ExecutionStatusElement(null, LANGUAGE_NOT_SUPPORTED_ERROR + m.getLanguage(), ExecutionStatusType.ERROR));
            return res;
        }
        log.debug("language {} is OK", m.getLanguage());
        String changedModel = modelResolver.getModelString(m);
        log.debug("Changed modell is {}", changedModel);
        if (changedModel == null) {
            addStatus(new ExecutionStatusElement(null, modelResolver.getMessage(), ExecutionStatusType.ERROR));
        }
        log.debug("Ready to execute");
        IRawSedmlSimulationResults results = executeSimulation(changedModel, (UniformTimeCourse) sedml.getSimulation(task.getSimulationReference()));
        if (results == null) {
            addStatus(new ExecutionStatusElement(null, "Simulation failed during execution: " + task.getSimulationReference() + " with model: " + task.getModelReference(), ExecutionStatusType.ERROR));
        // return res;
        }
        log.debug("Results are {}", results);
        res.put(task, results);
    }
    return res;
}
Also used : AbstractTask(org.jlibsedml.AbstractTask) HashMap(java.util.HashMap) Model(org.jlibsedml.Model) HashSet(java.util.HashSet)

Example 10 with AbstractTask

use of org.jlibsedml.AbstractTask in project vcell by virtualcell.

the class AbstractSedmlExecutor method findTasks.

private Set<AbstractTask> findTasks(Output output) {
    Set<AbstractTask> tasksToExecute = new TreeSet<AbstractTask>();
    Set<DataGenerator> dgs = new TreeSet<DataGenerator>();
    for (String dgid : output.getAllDataGeneratorReferences()) {
        dgs.add(sedml.getDataGeneratorWithId(dgid));
    }
    for (DataGenerator dg : dgs) {
        for (Variable v : dg.getListOfVariables()) {
            tasksToExecute.add(sedml.getTaskWithId(v.getReference()));
        }
    }
    return tasksToExecute;
}
Also used : AbstractTask(org.jlibsedml.AbstractTask) Variable(org.jlibsedml.Variable) TreeSet(java.util.TreeSet) DataGenerator(org.jlibsedml.DataGenerator)

Aggregations

AbstractTask (org.jlibsedml.AbstractTask)11 DataGenerator (org.jlibsedml.DataGenerator)5 BioModel (cbit.vcell.biomodel.BioModel)4 SimulationContext (cbit.vcell.mapping.SimulationContext)4 ArrayList (java.util.ArrayList)4 Model (org.jlibsedml.Model)4 MathMappingCallbackTaskAdapter (cbit.vcell.mapping.MathMappingCallbackTaskAdapter)3 Application (cbit.vcell.mapping.SimulationContext.Application)3 MathMappingCallback (cbit.vcell.mapping.SimulationContext.MathMappingCallback)3 Simulation (cbit.vcell.solver.Simulation)3 SolverDescription (cbit.vcell.solver.SolverDescription)3 FileInputStream (java.io.FileInputStream)3 ArchiveComponents (org.jlibsedml.ArchiveComponents)3 OneStep (org.jlibsedml.OneStep)3 Output (org.jlibsedml.Output)3 SteadyState (org.jlibsedml.SteadyState)3 UniformTimeCourse (org.jlibsedml.UniformTimeCourse)3 ArchiveModelResolver (org.jlibsedml.execution.ArchiveModelResolver)3 ModelResolver (org.jlibsedml.execution.ModelResolver)3 MathModel (cbit.vcell.mathmodel.MathModel)2