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);
}
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
}
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);
}
}
Aggregations