Search in sources :

Example 6 with BNGOutput

use of cbit.vcell.server.bionetgen.BNGOutput in project vcell by virtualcell.

the class NetworkTransformer method generateNetwork.

private BNGOutputSpec generateNetwork(SimulationContext simContext, MathMappingCallback mathMappingCallback, NetworkGenerationRequirements networkGenerationRequirements) throws ClassNotFoundException, IOException {
    TaskCallbackMessage tcm;
    BNGOutputSpec outputSpec;
    speciesEquivalenceMap.clear();
    kineticsParameterMap.clear();
    String input = convertToBngl(simContext, true, mathMappingCallback, networkGenerationRequirements);
    for (Map.Entry<FakeSeedSpeciesInitialConditionsParameter, Pair<SpeciesContext, Expression>> entry : speciesEquivalenceMap.entrySet()) {
        FakeSeedSpeciesInitialConditionsParameter key = entry.getKey();
        Pair<SpeciesContext, Expression> value = entry.getValue();
        SpeciesContext sc = value.one;
        Expression initial = value.two;
        System.out.println("key: " + key.fakeParameterName + ",   species: " + sc.getName() + ", initial: " + initial.infix());
    }
    String md5hash = MD5.md5(input);
    if (isBngHashValid(input, md5hash, simContext)) {
        String s = "Previously saved outputSpec is up-to-date, no need to generate network.";
        System.out.println(s);
        // not an error, we just want to show it in red
        tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, s);
        simContext.appendToConsole(tcm);
        if (simContext.isInsufficientIterations()) {
            s = NetworkTransformer.getInsufficientIterationsMessage();
            System.out.println(s);
            tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, s);
            simContext.appendToConsole(tcm);
        }
        if (simContext.isInsufficientMaxMolecules()) {
            s = NetworkTransformer.getInsufficientMaxMoleculesMessage();
            System.out.println(s);
            tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, s);
            simContext.appendToConsole(tcm);
        }
        outputSpec = simContext.getMostRecentlyCreatedOutputSpec();
        return (BNGOutputSpec) BeanUtils.cloneSerializable(outputSpec);
    }
    BNGInput bngInput = new BNGInput(input);
    BNGOutput bngOutput = null;
    try {
        final BNGExecutorService bngService = BNGExecutorService.getInstance(bngInput, networkGenerationRequirements.timeoutDurationMS);
        bngService.registerBngUpdaterCallback(simContext);
        bngOutput = bngService.executeBNG();
    } catch (BNGException ex) {
        ex.printStackTrace(System.out);
        System.out.println("bionetgen exception");
        if (ex.getMessage().contains("was asked to write the network, but no reactions were found")) {
            RuntimeException rex = new RuntimeException("Specified species and reaction rules are not sufficient to define reaction network.");
            throw rex;
        } else {
            // rethrow without losing context
            throw ex;
        }
    } catch (RuntimeException ex) {
        ex.printStackTrace(System.out);
        System.out.println("runtime exception");
        throw ex;
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
        System.out.println("other exception");
        throw new RuntimeException(ex.getMessage());
    }
    // simContext.setInsufficientIterations(false);
    // simContext.setInsufficientMaxMolecules(false);
    String bngConsoleString = bngOutput.getConsoleOutput();
    // TODO: this message we check if insufficient iterations / max molecules
    // DO IT OUTSIDE (in the bng service), we now can
    // tcm = new TaskCallbackMessage(TaskCallbackStatus.DetailBatch, bngConsoleString);
    // simContext.appendToConsole(tcm);
    tcm = new TaskCallbackMessage(TaskCallbackStatus.TaskEndNotificationOnly, "");
    simContext.setNewCallbackMessage(tcm);
    tcm = new TaskCallbackMessage(TaskCallbackStatus.TaskEndAdjustSimulationContextFlagsOnly, "");
    simContext.setNewCallbackMessage(tcm);
    String bngNetString = bngOutput.getNetFileContent();
    outputSpec = BNGOutputFileParser.createBngOutputSpec(bngNetString);
    // prints all output to console
    BNGOutputFileParser.printBNGNetOutput(outputSpec);
    if (mathMappingCallback.isInterrupted()) {
        String msg = "Canceled by user.";
        tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, msg);
        simContext.appendToConsole(tcm);
        // clean the cache if the user interrupts
        simContext.setMd5hash(null);
        throw new UserCancelException(msg);
    }
    if (outputSpec.getBNGSpecies().length > NetworkTransformer.speciesLimit) {
        String message = NetworkTransformer.getSpeciesLimitExceededMessage(outputSpec);
        tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, message);
        simContext.appendToConsole(tcm);
        simContext.setMd5hash(null);
        message = "Unable to generate Math for Application " + simContext.getName() + ".\n" + message;
        throw new RuntimeException(message);
    }
    if (outputSpec.getBNGReactions().length > NetworkTransformer.reactionsLimit) {
        String message = NetworkTransformer.getReactionsLimitExceededMessage(outputSpec);
        tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, message);
        simContext.appendToConsole(tcm);
        simContext.setMd5hash(null);
        message = "Unable to generate Math for Application " + simContext.getName() + ".\n" + message;
        throw new RuntimeException(message);
    }
    // System.out.println("old hash: " + simContext.getMd5hash());
    if (md5hash != null && md5hash.length() != 0 && outputSpec != null) {
        System.out.println("saving hash and output spec");
        synchronized (this) {
            simContext.setMd5hash(md5hash);
            simContext.setMostRecentlyCreatedOutputSpec(outputSpec);
        }
    } else {
        System.out.println("something is wrong with the hash and/or output spec");
    }
    return (BNGOutputSpec) BeanUtils.cloneSerializable(outputSpec);
}
Also used : UserCancelException(org.vcell.util.UserCancelException) SpeciesContext(cbit.vcell.model.SpeciesContext) BNGExecutorService(cbit.vcell.server.bionetgen.BNGExecutorService) BNGOutput(cbit.vcell.server.bionetgen.BNGOutput) FakeSeedSpeciesInitialConditionsParameter(org.vcell.model.rbm.FakeSeedSpeciesInitialConditionsParameter) BNGOutputSpec(cbit.vcell.bionetgen.BNGOutputSpec) PropertyVetoException(java.beans.PropertyVetoException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ParseException(org.vcell.model.bngl.ParseException) BNGException(cbit.vcell.server.bionetgen.BNGException) ModelException(cbit.vcell.model.ModelException) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) BNGException(cbit.vcell.server.bionetgen.BNGException) Expression(cbit.vcell.parser.Expression) BNGInput(cbit.vcell.server.bionetgen.BNGInput) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(org.vcell.util.Pair)

Example 7 with BNGOutput

use of cbit.vcell.server.bionetgen.BNGOutput in project vcell by virtualcell.

the class BNGOutputPanel method setbngOutput1.

/**
 * Set the bngOutput1 to a new value.
 * @param newValue bngclientserverapi.BNGOutput
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void setbngOutput1(BNGOutput newValue) {
    if (ivjbngOutput1 != newValue) {
        try {
            BNGOutput oldValue = getbngOutput1();
            ivjbngOutput1 = newValue;
            connPtoP1SetSource();
            connEtoC1(ivjbngOutput1);
            connPtoP2SetTarget();
            firePropertyChange("bngOutput", oldValue, newValue);
        // user code begin {1}
        // user code end
        } catch (java.lang.Throwable ivjExc) {
            // user code begin {2}
            // user code end
            handleException(ivjExc);
        }
    }
    ;
// user code begin {3}
// user code end
}
Also used : BNGOutput(cbit.vcell.server.bionetgen.BNGOutput)

Example 8 with BNGOutput

use of cbit.vcell.server.bionetgen.BNGOutput in project vcell by virtualcell.

the class RunBioNetGen method run.

public void run(Hashtable<String, Object> hashTable) throws Exception {
    broadcastRun();
    BNGOutput bngOutput = bngService.executeBNG();
    if (bngOutput != null) {
        hashTable.put("bngOutput", bngOutput);
    }
}
Also used : BNGOutput(cbit.vcell.server.bionetgen.BNGOutput)

Aggregations

BNGOutput (cbit.vcell.server.bionetgen.BNGOutput)8 BNGOutputSpec (cbit.vcell.bionetgen.BNGOutputSpec)3 ModelException (cbit.vcell.model.ModelException)2 SpeciesContext (cbit.vcell.model.SpeciesContext)2 Expression (cbit.vcell.parser.Expression)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 BNGExecutorService (cbit.vcell.server.bionetgen.BNGExecutorService)2 BNGInput (cbit.vcell.server.bionetgen.BNGInput)2 PropertyVetoException (java.beans.PropertyVetoException)2 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 FakeSeedSpeciesInitialConditionsParameter (org.vcell.model.rbm.FakeSeedSpeciesInitialConditionsParameter)2 Pair (org.vcell.util.Pair)2 BNGOutputPanel (cbit.vcell.client.bionetgen.BNGOutputPanel)1 NetworkGenerationRequirements (cbit.vcell.mapping.SimulationContext.NetworkGenerationRequirements)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 BNGException (cbit.vcell.server.bionetgen.BNGException)1 HashMap (java.util.HashMap)1 ParseException (org.vcell.model.bngl.ParseException)1