Search in sources :

Example 1 with NetworkTransformer

use of cbit.vcell.mapping.NetworkTransformer 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(360, 160);
    childWindow.pack();
    panel.setChildWindow(childWindow);
    childWindow.setPreferredSize(dim);
    childWindow.showModal();
    int maxIterations;
    int maxMolecules;
    if (panel.getButtonPushed() == ActionButtons.Run) {
        maxIterations = new Integer(panel.maxIterationTextField.getText());
        maxMolecules = new Integer(panel.maxMolTextField.getText());
        fieldSimulationContext.getNetworkConstraints().setTestConstraints(maxIterations, maxMolecules);
    } else if (panel.getButtonPushed() == ActionButtons.Apply) {
        activateConsole();
        maxIterations = new Integer(panel.maxIterationTextField.getText());
        maxMolecules = new Integer(panel.maxMolTextField.getText());
        fieldSimulationContext.getNetworkConstraints().setTestConstraints(maxIterations, maxMolecules);
        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 {
        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;
        }
    };
    // we alter the input string to use the test values for max iterations and max molecules per species
    String input = transformer.convertToBngl(fieldSimulationContext, true, dummyCallback, NetworkGenerationRequirements.ComputeFullNoTimeout);
    // 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);
    RbmNetworkGenerator.generateNetworkEx(maxIterations, maxMolecules, 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 : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ReturnBNGOutput(cbit.vcell.client.task.ReturnBNGOutput) StringWriter(java.io.StringWriter) ProgressDialogListener(org.vcell.util.ProgressDialogListener) 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) BNGExecutorService(cbit.vcell.server.bionetgen.BNGExecutorService) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) EventObject(java.util.EventObject) EventObject(java.util.EventObject)

Aggregations

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 BNGExecutorService (cbit.vcell.server.bionetgen.BNGExecutorService)1 BNGInput (cbit.vcell.server.bionetgen.BNGInput)1 Dimension (java.awt.Dimension)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 EventObject (java.util.EventObject)1 Hashtable (java.util.Hashtable)1 ProgressDialogListener (org.vcell.util.ProgressDialogListener)1