Search in sources :

Example 1 with StoichiometryTableModel

use of cbit.vcell.mapping.gui.StoichiometryTableModel in project vcell by virtualcell.

the class ValidateConstraintsPanel method initialize.

private void initialize() {
    try {
        setName("ValidateConstraintsPanel");
        setLayout(new GridBagLayout());
        maxIterationTextField = new JLabel();
        maxMolTextField = new JLabel();
        speciesLimitTextField = new JLabel();
        reactionsLimitTextField = new JLabel();
        somethingInsufficientLabel = new JLabel();
        NetworkConstraints nc = owner.getSimulationContext().getNetworkConstraints();
        maxIterationTextField.setText(nc.getTestMaxIteration() + "");
        maxMolTextField.setText(nc.getTestMaxMoleculesPerSpecies() + "");
        speciesLimitTextField.setText(nc.getTestSpeciesLimit() + "");
        reactionsLimitTextField.setText(nc.getTestReactionsLimit() + "");
        int gridy = 0;
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        // gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        // top, left, bottom, right
        gbc.insets = new Insets(6, 8, 0, 0);
        add(new JLabel("Max. Iterations"), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(6, 0, 0, 10);
        add(maxIterationTextField, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        // gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(6, 8, 0, 0);
        add(new JLabel("Max. Molecules / Species"), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(6, 0, 0, 0);
        add(maxMolTextField, gbc);
        // ------------------------------------------------------
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        // gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(6, 8, 0, 0);
        add(new JLabel("Species Limit"), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(6, 0, 0, 0);
        add(speciesLimitTextField, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        // gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(6, 8, 4, 0);
        add(new JLabel("Reactions Limit"), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(6, 0, 4, 0);
        add(reactionsLimitTextField, gbc);
        // ------------------------------------------------------
        if (showStoichiometryTable) {
            stoichiometryTable = new EditorScrollTable();
            stoichiometryTableModel = new StoichiometryTableModel(stoichiometryTable);
            stoichiometryTable.setModel(stoichiometryTableModel);
            stoichiometryTableModel.setSimulationContext(owner.getSimulationContext());
            stoichiometryTableModel.displayTestMaxStoichiometry();
            // we disable editing for the Value column
            stoichiometryTableModel.setValueEditable(false);
            JScrollPane sp = new JScrollPane(stoichiometryTable);
            sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            gridy++;
            gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = gridy;
            gbc.weightx = gbc.weighty = 1.0;
            gbc.fill = GridBagConstraints.BOTH;
            gbc.anchor = GridBagConstraints.WEST;
            gbc.gridwidth = 4;
            gbc.insets = new Insets(5, 8, 4, 10);
            add(sp, gbc);
        }
        // -------------------------------------------------------
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.gridwidth = 4;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(2, 8, 4, 10);
        add(somethingInsufficientLabel, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 2, 8, 2);
        add(getApplyButton(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(6, 2, 8, 10);
        add(getCancelButton(), gbc);
        String s = "none";
        TaskCallbackProcessor tcbp = owner.getSimulationContext().getTaskCallbackProcessor();
        if (tcbp.getPreviousIterationSpecies() > 0 && tcbp.getCurrentIterationSpecies() > 0 && tcbp.getCurrentIterationSpecies() != tcbp.getPreviousIterationSpecies()) {
            s = "<font color=#8C001A>" + SimulationContext.IssueInsufficientIterations + "</font>";
        } else if (tcbp.getPreviousIterationSpecies() > 0 && tcbp.getCurrentIterationSpecies() > 0 && tcbp.getCurrentIterationSpecies() == tcbp.getPreviousIterationSpecies()) {
            if (tcbp.isNeedAdjustMaxMolecules()) {
                s = "<font color=#8C001A>" + SimulationContext.IssueInsufficientMolecules + "</font>";
            }
        }
        somethingInsufficientLabel.setText("<html>Warning:  " + s + "</html>");
    } catch (java.lang.Throwable ivjExc) {
        handleException(ivjExc);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) StoichiometryTableModel(cbit.vcell.mapping.gui.StoichiometryTableModel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) TaskCallbackProcessor(cbit.vcell.mapping.TaskCallbackProcessor) JLabel(javax.swing.JLabel) EditorScrollTable(org.vcell.util.gui.EditorScrollTable) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 2 with StoichiometryTableModel

use of cbit.vcell.mapping.gui.StoichiometryTableModel in project vcell by virtualcell.

the class EditConstraintsPanel method initialize.

private void initialize() {
    try {
        setName("EditConstraintsPanel");
        setLayout(new GridBagLayout());
        maxIterationTextField = new JTextField();
        maxMolTextField = new JTextField();
        speciesLimitTextField = new JTextField();
        reactionsLimitTextField = new JTextField();
        stoichiometryTable = new EditorScrollTable();
        stoichiometryTableModel = new StoichiometryTableModel(stoichiometryTable);
        stoichiometryTable.setModel(stoichiometryTableModel);
        stoichiometryTableModel.setSimulationContext(owner.getSimulationContext());
        maxIterationTextField.addActionListener(eventHandler);
        maxMolTextField.addActionListener(eventHandler);
        speciesLimitTextField.addActionListener(eventHandler);
        reactionsLimitTextField.addActionListener(eventHandler);
        maxIterationTextField.addFocusListener(eventHandler);
        maxMolTextField.addFocusListener(eventHandler);
        speciesLimitTextField.addFocusListener(eventHandler);
        reactionsLimitTextField.addFocusListener(eventHandler);
        stoichiometryTableModel.addTableModelListener(eventHandler);
        maxIterationTextField.getDocument().addDocumentListener(new DocumentListener() {

            public void changedUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public void removeUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public void insertUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public boolean isChanged() {
                NetworkConstraints nc = owner.getSimulationContext().getNetworkConstraints();
                String s1 = maxIterationTextField.getText();
                String s2 = nc.getMaxIteration() + "";
                if (!s1.equals(s2)) {
                    return true;
                }
                return false;
            }
        });
        maxMolTextField.getDocument().addDocumentListener(new DocumentListener() {

            public void changedUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public void removeUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public void insertUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public boolean isChanged() {
                NetworkConstraints nc = owner.getSimulationContext().getNetworkConstraints();
                String s1 = maxMolTextField.getText();
                String s2 = nc.getMaxMoleculesPerSpecies() + "";
                if (!s1.equals(s2)) {
                    return true;
                }
                return false;
            }
        });
        speciesLimitTextField.getDocument().addDocumentListener(new DocumentListener() {

            public void changedUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public void removeUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public void insertUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public boolean isChanged() {
                NetworkConstraints nc = owner.getSimulationContext().getNetworkConstraints();
                String s1 = speciesLimitTextField.getText();
                String s2 = nc.getSpeciesLimit() + "";
                if (!s1.equals(s2)) {
                    return true;
                }
                return false;
            }
        });
        reactionsLimitTextField.getDocument().addDocumentListener(new DocumentListener() {

            public void changedUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public void removeUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public void insertUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public boolean isChanged() {
                NetworkConstraints nc = owner.getSimulationContext().getNetworkConstraints();
                String s1 = reactionsLimitTextField.getText();
                String s2 = nc.getReactionsLimit() + "";
                if (!s1.equals(s2)) {
                    return true;
                }
                return false;
            }
        });
        JPanel p = new JPanel();
        p.setLayout(new GridBagLayout());
        int gridy = 0;
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        // top, left, bottom, right
        gbc.insets = new Insets(6, 8, 0, 0);
        p.add(new JLabel("Max. Iterations"), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(6, 0, 0, 10);
        p.add(maxIterationTextField, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(6, 8, 0, 0);
        p.add(new JLabel("Max. Molecules / Species"), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(6, 0, 0, 10);
        p.add(maxMolTextField, gbc);
        // ---------------------------------------------------------
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(6, 8, 0, 0);
        p.add(new JLabel("Species Limit"), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(6, 0, 0, 10);
        p.add(speciesLimitTextField, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(6, 8, 6, 0);
        p.add(new JLabel("Reactions Limit"), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(6, 0, 6, 10);
        p.add(reactionsLimitTextField, gbc);
        // ---------------------------------------------------------
        setLayout(new GridBagLayout());
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.gridwidth = 3;
        gbc.anchor = GridBagConstraints.NORTHWEST;
        add(p, gbc);
        JScrollPane sp = new JScrollPane(stoichiometryTable);
        sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.gridwidth = 3;
        gbc.insets = new Insets(5, 8, 4, 10);
        add(sp, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(6, 8, 8, 2);
        add(getRunButton(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(6, 2, 8, 2);
        add(getApplyButton(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(6, 2, 8, 10);
        add(getCancelButton(), gbc);
        maxIterationTextField.setText(owner.getSimulationContext().getNetworkConstraints().getMaxIteration() + "");
        maxMolTextField.setText(owner.getSimulationContext().getNetworkConstraints().getMaxMoleculesPerSpecies() + "");
        speciesLimitTextField.setText(owner.getSimulationContext().getNetworkConstraints().getSpeciesLimit() + "");
        reactionsLimitTextField.setText(owner.getSimulationContext().getNetworkConstraints().getReactionsLimit() + "");
        getApplyButton().setEnabled(false);
    } catch (java.lang.Throwable ivjExc) {
        handleException(ivjExc);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) StoichiometryTableModel(cbit.vcell.mapping.gui.StoichiometryTableModel) DocumentListener(javax.swing.event.DocumentListener) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) DocumentEvent(javax.swing.event.DocumentEvent) EditorScrollTable(org.vcell.util.gui.EditorScrollTable) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 3 with StoichiometryTableModel

use of cbit.vcell.mapping.gui.StoichiometryTableModel in project vcell by virtualcell.

the class NetworkConstraintsPanel method runBioNetGen.

private void runBioNetGen() {
    EditConstraintsPanel panel = new EditConstraintsPanel(this);
    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(this);
    ChildWindow childWindow = childWindowManager.addChildWindow(panel, panel, "Edit / Test Constraints");
    Dimension dim = new Dimension(320, 330);
    childWindow.pack();
    panel.setChildWindow(childWindow);
    childWindow.setPreferredSize(dim);
    childWindow.showModal();
    int maxIterations;
    int maxMolecules;
    int speciesLimit;
    int reactionsLimit;
    Map<MolecularType, Integer> testMaxStoichiometryMap = new LinkedHashMap<>();
    StoichiometryTableModel stoichiometryTableModel = panel.getStoichiometryTableModel();
    for (int row = 0; row < stoichiometryTableModel.getRowCount(); row++) {
        MaxStoichiometryEntity nce = stoichiometryTableModel.getValueAt(row);
        MolecularType key = nce.getMolecularType();
        Integer value = nce.getValue();
        testMaxStoichiometryMap.put(key, value);
    }
    if (panel.getButtonPushed() == ActionButtons.Run) {
        maxIterations = new Integer(panel.maxIterationTextField.getText());
        maxMolecules = new Integer(panel.maxMolTextField.getText());
        speciesLimit = new Integer(panel.speciesLimitTextField.getText());
        reactionsLimit = new Integer(panel.reactionsLimitTextField.getText());
        fieldSimulationContext.getNetworkConstraints().setTestConstraints(maxIterations, maxMolecules, speciesLimit, reactionsLimit, testMaxStoichiometryMap);
    } else if (panel.getButtonPushed() == ActionButtons.Apply) {
        activateConsole();
        maxIterations = new Integer(panel.maxIterationTextField.getText());
        maxMolecules = new Integer(panel.maxMolTextField.getText());
        speciesLimit = new Integer(panel.speciesLimitTextField.getText());
        reactionsLimit = new Integer(panel.reactionsLimitTextField.getText());
        fieldSimulationContext.getNetworkConstraints().setTestConstraints(maxIterations, maxMolecules, speciesLimit, reactionsLimit, testMaxStoichiometryMap);
        fieldSimulationContext.getNetworkConstraints().updateConstraintsFromTest();
        // apply will invalidate everything: generated species, reactions, console, cache, etc
        updateBioNetGenOutput(null);
        refreshInterface();
        TaskCallbackMessage tcm = new TaskCallbackMessage(TaskCallbackStatus.Clean, "");
        fieldSimulationContext.appendToConsole(tcm);
        String message = "Warning: The current Constraints are not tested / validated.";
        tcm = new TaskCallbackMessage(TaskCallbackStatus.Warning, message);
        fieldSimulationContext.appendToConsole(tcm);
        message = "The Network generation may take a very long time or the generated network may be incomplete. " + "We recommend testing this set of constraints.";
        tcm = new TaskCallbackMessage(TaskCallbackStatus.Notification, message);
        fieldSimulationContext.appendToConsole(tcm);
        return;
    } else {
        // when cancel we put back in sync the test values
        maxIterations = fieldSimulationContext.getNetworkConstraints().getMaxIteration();
        maxMolecules = fieldSimulationContext.getNetworkConstraints().getMaxMoleculesPerSpecies();
        speciesLimit = fieldSimulationContext.getNetworkConstraints().getSpeciesLimit();
        reactionsLimit = fieldSimulationContext.getNetworkConstraints().getReactionsLimit();
        fieldSimulationContext.getNetworkConstraints().setTestConstraints(maxIterations, maxMolecules, speciesLimit, reactionsLimit, testMaxStoichiometryMap);
        return;
    }
    // TODO: do not delete the commented code below
    // uncomment the next 6 lines to keep the data in the dialogs synchronized with the most recent reaction network
    // if(viewSpeciesDialog != null) {
    // viewSpeciesDialog.dispose();
    // }
    // if(viewReactionsDialog != null) {
    // viewReactionsDialog.dispose();
    // }
    activateConsole();
    // previousIterationSpecies = 0;
    synchronized (this) {
        fieldSimulationContext.setMd5hash(null);
        fieldSimulationContext.setMostRecentlyCreatedOutputSpec(null);
    }
    refreshInterface();
    if (!checkBnglRequirements()) {
        return;
    }
    NetworkTransformer transformer = new NetworkTransformer();
    MathMappingCallback dummyCallback = new MathMappingCallback() {

        public void setProgressFraction(float percentDone) {
        }

        public void setMessage(String message) {
        }

        public boolean isInterrupted() {
            return false;
        }
    };
    String input = transformer.convertToBngl(fieldSimulationContext, true, dummyCallback, NetworkGenerationRequirements.ComputeFullNoTimeout);
    // we alter the input string to use the test values for speciesLimit and reactionsLimit
    BufferedReader br = new BufferedReader(new StringReader(input));
    StringBuilder sb = new StringBuilder();
    int lineNumber = 0;
    while (true) {
        String line = null;
        try {
            line = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (line == null) {
            // end of document
            break;
        }
        if (line.isEmpty()) {
            sb.append("\n");
            lineNumber++;
            continue;
        }
        if (line.contains(NetworkConstraints.SPECIES_LIMIT_PARAMETER)) {
            sb.append(NetworkConstraints.SPECIES_LIMIT_PARAMETER + "\t\t" + speciesLimit + "\n");
        } else if (line.contains(NetworkConstraints.REACTIONS_LIMIT_PARAMETER)) {
            sb.append(NetworkConstraints.REACTIONS_LIMIT_PARAMETER + "\t\t" + reactionsLimit + "\n");
        } else {
            sb.append(line + "\n");
        }
    }
    input = sb.toString();
    // we alter the input string to use the test values for max iterations and max molecules per species
    // get rid of the default generate network command...
    input = input.substring(0, input.indexOf("generate_network({"));
    // ... and replace it with the "fake" one
    StringWriter bnglStringWriter = new StringWriter();
    PrintWriter pw = new PrintWriter(bnglStringWriter);
    // testMaxStoichiometryMap
    RbmNetworkGenerator.generateNetworkEx(maxIterations, maxMolecules, true, pw, fieldSimulationContext.getModel().getRbmModelContainer(), fieldSimulationContext, NetworkGenerationRequirements.ComputeFullNoTimeout);
    String genNetStr = bnglStringWriter.toString();
    pw.close();
    input += genNetStr;
    BNGInput bngInput = new BNGInput(input);
    final BNGExecutorService bngService = BNGExecutorService.getInstance(bngInput, NetworkGenerationRequirements.NoTimeoutMS);
    bngService.registerBngUpdaterCallback(this);
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    AsynchClientTask[] tasksArray = new AsynchClientTask[3];
    TaskCallbackMessage message = new TaskCallbackMessage(TaskCallbackStatus.Clean, "");
    fieldSimulationContext.appendToConsole(message);
    tasksArray[0] = new RunBioNetGen(bngService);
    tasksArray[1] = new CreateBNGOutputSpec(bngService);
    tasksArray[2] = new ReturnBNGOutput(bngService, fieldSimulationContext, this);
    ClientTaskDispatcher.dispatch(this, hash, tasksArray, false, true, new ProgressDialogListener() {

        @Override
        public void cancelButton_actionPerformed(EventObject newEvent) {
            try {
                bngService.stopBNG();
                String s = "...user cancelled.";
                TaskCallbackMessage tcm = new TaskCallbackMessage(TaskCallbackStatus.TaskStopped, s);
                // message will be processed in TaskCallbackProcessor::case TaskStopped
                setNewCallbackMessage(tcm);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : StoichiometryTableModel(cbit.vcell.mapping.gui.StoichiometryTableModel) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ReturnBNGOutput(cbit.vcell.client.task.ReturnBNGOutput) LinkedHashMap(java.util.LinkedHashMap) StringWriter(java.io.StringWriter) ProgressDialogListener(org.vcell.util.ProgressDialogListener) StringReader(java.io.StringReader) BNGInput(cbit.vcell.server.bionetgen.BNGInput) RunBioNetGen(cbit.vcell.client.task.RunBioNetGen) PrintWriter(java.io.PrintWriter) TaskCallbackMessage(cbit.vcell.mapping.TaskCallbackMessage) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) CreateBNGOutputSpec(cbit.vcell.client.task.CreateBNGOutputSpec) Hashtable(java.util.Hashtable) NetworkTransformer(cbit.vcell.mapping.NetworkTransformer) ChildWindowManager(cbit.vcell.client.ChildWindowManager) Dimension(java.awt.Dimension) IOException(java.io.IOException) BNGExecutorService(cbit.vcell.server.bionetgen.BNGExecutorService) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) EventObject(java.util.EventObject) IOException(java.io.IOException) MolecularType(org.vcell.model.rbm.MolecularType) MaxStoichiometryEntity(org.vcell.model.rbm.common.MaxStoichiometryEntity) BufferedReader(java.io.BufferedReader) EventObject(java.util.EventObject)

Aggregations

StoichiometryTableModel (cbit.vcell.mapping.gui.StoichiometryTableModel)3 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Insets (java.awt.Insets)2 JLabel (javax.swing.JLabel)2 JScrollPane (javax.swing.JScrollPane)2 NetworkConstraints (org.vcell.model.rbm.NetworkConstraints)2 EditorScrollTable (org.vcell.util.gui.EditorScrollTable)2 ChildWindowManager (cbit.vcell.client.ChildWindowManager)1 ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 CreateBNGOutputSpec (cbit.vcell.client.task.CreateBNGOutputSpec)1 ReturnBNGOutput (cbit.vcell.client.task.ReturnBNGOutput)1 RunBioNetGen (cbit.vcell.client.task.RunBioNetGen)1 NetworkTransformer (cbit.vcell.mapping.NetworkTransformer)1 MathMappingCallback (cbit.vcell.mapping.SimulationContext.MathMappingCallback)1 TaskCallbackMessage (cbit.vcell.mapping.TaskCallbackMessage)1 TaskCallbackProcessor (cbit.vcell.mapping.TaskCallbackProcessor)1 BNGExecutorService (cbit.vcell.server.bionetgen.BNGExecutorService)1 BNGInput (cbit.vcell.server.bionetgen.BNGInput)1