Search in sources :

Example 1 with MaxStoichiometryEntity

use of org.vcell.model.rbm.common.MaxStoichiometryEntity in project vcell by virtualcell.

the class StoichiometryTableModel method displayTestMaxStoichiometry.

public void displayTestMaxStoichiometry() {
    ArrayList<MaxStoichiometryEntity> nceList = new ArrayList<MaxStoichiometryEntity>();
    Model model = simContext.getModel();
    RbmModelContainer rbmModelContainer = model.getRbmModelContainer();
    if (rbmModelContainer == null) {
        setData(nceList);
        return;
    }
    NetworkConstraints networkConstraints = simContext.getNetworkConstraints();
    Map<MolecularType, Integer> smTest = networkConstraints.getTestMaxStoichiometry(simContext);
    Map<MolecularType, Integer> smOld = networkConstraints.getMaxStoichiometry(simContext);
    for (Map.Entry<MolecularType, Integer> entry : smTest.entrySet()) {
        MolecularType mt = entry.getKey();
        Integer valueTest = entry.getValue();
        Integer valueOld = smOld.get(mt);
        MaxStoichiometryEntity nce = new MaxStoichiometryEntity(mt, valueTest);
        if (valueTest != valueOld) {
            // not in use
            nce.setChanged(true);
        }
        nceList.add(nce);
    }
    setData(nceList);
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) MaxStoichiometryEntity(org.vcell.model.rbm.common.MaxStoichiometryEntity) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) ArrayList(java.util.ArrayList) BioModelEditorRightSideTableModel(cbit.vcell.client.desktop.biomodel.BioModelEditorRightSideTableModel) Model(cbit.vcell.model.Model) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 2 with MaxStoichiometryEntity

use of org.vcell.model.rbm.common.MaxStoichiometryEntity in project vcell by virtualcell.

the class StoichiometryTableModel method setValueAt.

@Override
public void setValueAt(Object value, int row, int column) {
    if (simContext == null || value == null) {
        return;
    }
    String text = value + "";
    if (text == null || text.trim().length() == 0) {
        return;
    }
    MaxStoichiometryEntity nce = getValueAt(row);
    if (text.equals(nce.getValue().toString())) {
        // unchanged
        return;
    }
    nce.setValue(new Integer(text));
    fireTableRowsUpdated(row, row);
    return;
}
Also used : MaxStoichiometryEntity(org.vcell.model.rbm.common.MaxStoichiometryEntity)

Example 3 with MaxStoichiometryEntity

use of org.vcell.model.rbm.common.MaxStoichiometryEntity in project vcell by virtualcell.

the class StoichiometryTableModel method computeData.

protected ArrayList<MaxStoichiometryEntity> computeData() {
    ArrayList<MaxStoichiometryEntity> nceList = new ArrayList<MaxStoichiometryEntity>();
    Model model = simContext.getModel();
    RbmModelContainer rbmModelContainer = model.getRbmModelContainer();
    if (rbmModelContainer == null) {
        return nceList;
    }
    NetworkConstraints networkConstraints = simContext.getNetworkConstraints();
    Map<MolecularType, Integer> stoichiometryMap = networkConstraints.getMaxStoichiometry(simContext);
    for (Map.Entry<MolecularType, Integer> entry : stoichiometryMap.entrySet()) {
        MolecularType mt = entry.getKey();
        Integer value = entry.getValue();
        MaxStoichiometryEntity nce = new MaxStoichiometryEntity(mt, value);
        nceList.add(nce);
    }
    return nceList;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) MaxStoichiometryEntity(org.vcell.model.rbm.common.MaxStoichiometryEntity) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) ArrayList(java.util.ArrayList) BioModelEditorRightSideTableModel(cbit.vcell.client.desktop.biomodel.BioModelEditorRightSideTableModel) Model(cbit.vcell.model.Model) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 4 with MaxStoichiometryEntity

use of org.vcell.model.rbm.common.MaxStoichiometryEntity in project vcell by virtualcell.

the class StoichiometryTableModel method isChanged.

public boolean isChanged() {
    NetworkConstraints nc = simContext.getNetworkConstraints();
    for (int row = 0; row < getRowCount(); row++) {
        Integer candidate = (Integer) getValueAt(row, 1);
        MaxStoichiometryEntity nce = getValueAt(row);
        MolecularType mt = nce.getMolecularType();
        Integer oldValue = simContext.getNetworkConstraints().getMaxStoichiometry(simContext).get(mt);
        if (oldValue.intValue() != candidate.intValue()) {
            // is changed
            return true;
        }
    }
    return false;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) MaxStoichiometryEntity(org.vcell.model.rbm.common.MaxStoichiometryEntity) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 5 with MaxStoichiometryEntity

use of org.vcell.model.rbm.common.MaxStoichiometryEntity 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

MaxStoichiometryEntity (org.vcell.model.rbm.common.MaxStoichiometryEntity)5 MolecularType (org.vcell.model.rbm.MolecularType)4 LinkedHashMap (java.util.LinkedHashMap)3 NetworkConstraints (org.vcell.model.rbm.NetworkConstraints)3 BioModelEditorRightSideTableModel (cbit.vcell.client.desktop.biomodel.BioModelEditorRightSideTableModel)2 Model (cbit.vcell.model.Model)2 RbmModelContainer (cbit.vcell.model.Model.RbmModelContainer)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)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 StoichiometryTableModel (cbit.vcell.mapping.gui.StoichiometryTableModel)1