use of org.vcell.model.rbm.NetworkConstraints in project vcell by virtualcell.
the class IssuePanel method invokeHyperlink.
private void invokeHyperlink(Issue issue) {
if (selectionManager != null) {
// followHyperlink is no-op if selectionManger null, so no point in proceeding if it is
IssueContext issueContext = issue.getIssueContext();
IssueSource object = issue.getSource();
if (object instanceof DecoratedIssueSource) {
DecoratedIssueSource dis = (DecoratedIssueSource) object;
dis.activateView(selectionManager);
} else if (object instanceof Parameter) {
followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.BIOMODEL_PARAMETERS_NODE, ActiveViewID.parameters_functions), new Object[] { object });
} else if (object instanceof StructureMapping) {
StructureMapping structureMapping = (StructureMapping) object;
StructureMappingNameScope structureMappingNameScope = (StructureMappingNameScope) structureMapping.getNameScope();
SimulationContext simulationContext = ((SimulationContextNameScope) (structureMappingNameScope.getParent())).getSimulationContext();
followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.structure_mapping), new Object[] { object });
} else if (object instanceof SpatialObject) {
SpatialObject spatialObject = (SpatialObject) object;
SimulationContext simulationContext = spatialObject.getSimulationContext();
followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.spatial_objects), new Object[] { object });
} else if (object instanceof SpatialProcess) {
SpatialProcess spatialProcess = (SpatialProcess) object;
SimulationContext simulationContext = spatialProcess.getSimulationContext();
followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.spatial_processes), new Object[] { object });
} else if (object instanceof GeometryContext.UnmappedGeometryClass) {
UnmappedGeometryClass unmappedGeometryClass = (UnmappedGeometryClass) object;
SimulationContext simulationContext = unmappedGeometryClass.getSimulationContext();
followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.structure_mapping), new Object[] { object });
} else if (object instanceof MicroscopeMeasurement) {
SimulationContext simulationContext = ((MicroscopeMeasurement) object).getSimulationContext();
followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.PROTOCOLS_NODE, ActiveViewID.microscope_measuremments), new Object[] { object });
} else if (object instanceof BioEvent) {
BioEvent be = (BioEvent) object;
SimulationContext simulationContext = be.getSimulationContext();
followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.PROTOCOLS_NODE, ActiveViewID.events), new Object[] { object });
} else if (object instanceof OutputFunctionIssueSource) {
SimulationOwner simulationOwner = ((OutputFunctionIssueSource) object).getOutputFunctionContext().getSimulationOwner();
if (simulationOwner instanceof SimulationContext) {
SimulationContext simulationContext = (SimulationContext) simulationOwner;
followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.SIMULATIONS_NODE, ActiveViewID.output_functions), new Object[] { ((OutputFunctionIssueSource) object).getAnnotatedFunction() });
} else if (simulationOwner instanceof MathModel) {
followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MATH_OUTPUT_FUNCTIONS_NODE, ActiveViewID.math_output_functions), new Object[] { ((OutputFunctionIssueSource) object).getAnnotatedFunction() });
}
} else if (object instanceof Simulation) {
Simulation simulation = (Simulation) object;
SimulationOwner simulationOwner = simulation.getSimulationOwner();
if (simulationOwner instanceof SimulationContext) {
SimulationContext simulationContext = (SimulationContext) simulationOwner;
followHyperlink(new ActiveView(simulationContext, DocumentEditorTreeFolderClass.SIMULATIONS_NODE, ActiveViewID.simulations), new Object[] { simulation });
} else if (simulationOwner instanceof MathModel) {
followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MATH_SIMULATIONS_NODE, ActiveViewID.math_simulations), new Object[] { simulation });
}
} else if (object instanceof GeometryContext) {
setActiveView(new ActiveView(((GeometryContext) object).getSimulationContext(), DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.geometry_definition));
} else if (object instanceof Structure) {
followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.STRUCTURES_NODE, ActiveViewID.structures), new Object[] { object });
} else if (object instanceof MolecularType) {
followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MOLECULAR_TYPES_NODE, ActiveViewID.structures), new Object[] { object });
} else if (object instanceof ReactionStep) {
followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.REACTIONS_NODE, ActiveViewID.reactions), new Object[] { object });
} else if (object instanceof ReactionRule) {
followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.REACTIONS_NODE, ActiveViewID.reactions), new Object[] { object });
} else if (object instanceof SpeciesContextSpec) {
SpeciesContextSpec scs = (SpeciesContextSpec) object;
ActiveView av = new ActiveView(scs.getSimulationContext(), DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.species_settings);
followHyperlink(av, new Object[] { object });
} else if (object instanceof ReactionCombo) {
ReactionCombo rc = (ReactionCombo) object;
followHyperlink(new ActiveView(rc.getReactionContext().getSimulationContext(), DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.reaction_setting), new Object[] { ((ReactionCombo) object).getReactionSpec() });
} else if (object instanceof SpeciesContext) {
followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.SPECIES_NODE, ActiveViewID.species), new Object[] { object });
} else if (object instanceof RbmObservable) {
followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.OBSERVABLES_NODE, ActiveViewID.observables), new Object[] { object });
} else if (object instanceof MathDescription) {
// followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MATH_SIMULATIONS_NODE, ActiveViewID.generated_math), new Object[] {object});
followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.structure_mapping), new Object[] { object });
} else if (object instanceof SpeciesPattern) {
// if (issue.getIssueContext().hasContextType(ContextType.SpeciesContext)){
// SpeciesContext thing = (SpeciesContext)issue.getIssueContext().getContextObject(ContextType.SpeciesContext);
// followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.SPECIES_NODE, ActiveViewID.species), new Object[] {thing});
// }else if(issue.getIssueContext().hasContextType(ContextType.ReactionRule)) {
// ReactionRule thing = (ReactionRule)issue.getIssueContext().getContextObject(ContextType.ReactionRule);
// followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.REACTIONS_NODE, ActiveViewID.reactions), new Object[] {thing});
// }else if(issue.getIssueContext().hasContextType(ContextType.RbmObservable)) {
// RbmObservable thing = (RbmObservable)issue.getIssueContext().getContextObject(ContextType.RbmObservable);
// followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.OBSERVABLES_NODE, ActiveViewID.observables), new Object[] {thing});
// } else {
System.err.println("SpeciesPattern object missing a proper issue context.");
// }
} else if (object instanceof SimulationContext) {
SimulationContext sc = (SimulationContext) object;
IssueCategory ic = issue.getCategory();
switch(ic) {
case RbmNetworkConstraintsBad:
NetworkConstraints nc = sc.getNetworkConstraints();
if (issue.getMessage() == SimulationContext.IssueInsufficientMolecules) {
NetworkConstraintsEntity nce = new NetworkConstraintsEntity(NetworkConstraintsTableModel.sMaxMoleculesName, NetworkConstraintsTableModel.sValueType, nc.getMaxMoleculesPerSpecies() + "");
followHyperlink(new ActiveView(sc, DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.network_setting), new Object[] { nce });
} else {
NetworkConstraintsEntity nce = new NetworkConstraintsEntity(NetworkConstraintsTableModel.sMaxIterationName, NetworkConstraintsTableModel.sValueType, nc.getMaxIteration() + "");
followHyperlink(new ActiveView(sc, DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.network_setting), new Object[] { nce });
}
break;
default:
followHyperlink(new ActiveView(sc, DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, ActiveViewID.network_setting), new Object[] { object });
break;
}
} else if (object instanceof Geometry) {
if (issueContext.hasContextType(ContextType.SimContext)) {
SimulationContext simContext = (SimulationContext) issueContext.getContextObject(ContextType.SimContext);
followHyperlink(new ActiveView(simContext, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.geometry_definition), new Object[] { object });
} else if (issueContext.hasContextType(ContextType.MathModel)) {
followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.MATH_GEOMETRY_NODE, ActiveViewID.math_geometry), new Object[] { object });
} else if (issueContext.hasContextType(ContextType.MathDescription)) {
followHyperlink(new ActiveView(null, DocumentEditorTreeFolderClass.GEOMETRY_NODE, ActiveViewID.geometry_definition), new Object[] { object });
}
} else {
System.err.println("unknown object type in IssuePanel.invokeHyperlink(): " + object.getClass() + ", context type: " + issueContext.getContextType());
}
}
}
use of org.vcell.model.rbm.NetworkConstraints in project vcell by virtualcell.
the class BNGExecutorServiceMultipass method executeBNG.
@Override
public BNGOutput executeBNG() throws BNGException, ParseException, PropertyVetoException, ExpressionBindingException {
this.startTime = System.currentTimeMillis();
// elapsed time in doWork
long eltDoWork = 0;
// elapsed time executing bngl
long eltExecBng = 0;
// elapsed time executing isomorphism
eltIsomorph = 0;
// elapsed time on final Observable run
long eltObserv = 0;
String cBngInputString = cBngInput.getInputString();
String anchorsString = extractAnchors(cBngInputString);
anchorsMap = parseAnchors(anchorsString);
// the "trick" - the modified molecules, species, etc
// everything has an extra Site with the compartments as possible States
// and yet another site that we use to certify the compartment validity
String sBngInputString = preprocessInput(cBngInputString);
BNGInput sBngInput = new BNGInput(sBngInputString);
// output after each iteration
BNGOutput sBngOutput = null;
String sBngOutputString = null;
// the seedSpecies which were given as input for the current iteration
String oldSeedSpeciesString;
// the BNGReactions as they are at the end of the current iteration, after corrections of the species
String correctedReactionsString = null;
// before the first iteration we show the original seed species
oldSeedSpeciesString = extractOriginalSeedSpecies(sBngInputString);
// consoleNotification("======= Original Seed Species ===========================\n" + oldSeedSpeciesString);
// initial number of seed species
int speciesCount = org.apache.commons.lang3.StringUtils.countMatches(oldSeedSpeciesString, "\n");
displayIterationMessage(0, speciesCount);
List<BNGSpecies> initialSpeciesList = BNGOutputFileParser.createBngSpeciesOutputSpec(oldSeedSpeciesString);
for (BNGSpecies s : initialSpeciesList) {
// populate the isomorphism signature map with the initial seed species
isomorphismSignaturesMap.put(s.getName(), s.getName());
shortSignaturesSet.add(BNGSpecies.getShortSignature(s, sigDetailLevel));
}
NetworkConstraints nc = simContext.getNetworkConstraints();
// iterations counter
int i;
for (i = 0; i < nc.getMaxIteration(); i++) {
correctedReactionsString = null;
this.onepassBngService = new BNGExecutorServiceNative(sBngInput, timeoutDurationMS);
// we are the only callback for the native service, acting as middleman
this.onepassBngService.registerBngUpdaterCallback(this);
long st1 = System.currentTimeMillis();
sBngOutput = this.onepassBngService.executeBNG();
long et1 = System.currentTimeMillis();
eltExecBng += (et1 - st1);
this.onepassBngService = null;
// .net file
sBngOutputString = sBngOutput.getNetFileContent();
// String delta = "";
String rawSeedSpeciesString = "";
// this bloc is dealing with the strings, used for console display only
rawSeedSpeciesString = extractSeedSpecies(sBngOutputString);
dump("dumpIteration" + (i + 1) + ".txt", rawSeedSpeciesString);
// delta = rawSeedSpeciesString.substring(oldSeedSpeciesString.length());
String rs = extractReactions(sBngOutputString);
// String s = " --- Iteration " + (i+1) + " ---------------------------";
// s += "\n" + delta;
// s += "---------------------------------------\n" + rs;
// consoleNotification(s);
long st2 = System.currentTimeMillis();
CorrectedSR correctedSR = doWork(oldSeedSpeciesString, sBngOutputString);
long et2 = System.currentTimeMillis();
eltDoWork += (et2 - st2);
String correctedSeedSpeciesString = extractCorrectedSeedSpeciesAsString(correctedSR);
correctedReactionsString = extractCorrectedReactionsAsString(correctedSR);
oldSeedSpeciesString += correctedSeedSpeciesString;
speciesCount += correctedSR.speciesList.size();
int reactionsCount = correctedSR.reactionsList.size();
displayIterationMessage(i + 1, speciesCount);
if (speciesCount >= NetworkTransformer.speciesLimit) {
// don't continue iterations if we reach species limit
break;
}
if (reactionsCount >= NetworkTransformer.reactionsLimit) {
break;
}
if (correctedSR.speciesList.isEmpty()) {
// if the current iteration didn't provide any VALID NEW species (after correction) then we are done
break;
}
sBngInputString = prepareNewBnglString(sBngInputString, oldSeedSpeciesString);
// the new input for next iteration
sBngInput = new BNGInput(sBngInputString);
}
// run one more iteration with all the seed species calculated above and with one single fake
// rule (so that no new seed species will be created), to properly compute the observables
long st3 = System.currentTimeMillis();
// the ObservableGroups
String obsInputString = prepareObservableRun(sBngInputString);
BNGInput obsBngInput = new BNGInput(obsInputString);
this.onepassBngService = new BNGExecutorServiceNative(obsBngInput, timeoutDurationMS);
this.onepassBngService.registerBngUpdaterCallback(this);
BNGOutput obsBngOutput = this.onepassBngService.executeBNG();
String correctedObservablesString = extractCorrectedObservablesAsString(obsBngOutput);
correctedObservablesString = extractPolymerObservablesAsString(correctedObservablesString, oldSeedSpeciesString);
long et3 = System.currentTimeMillis();
eltObserv += (et3 - st3);
// oldSeedSpeciesString contains the final list of seed species
sBngOutput.insertEntitiesInNetFile(oldSeedSpeciesString, "species");
sBngOutput.insertEntitiesInNetFile(correctedReactionsString, "reactions");
sBngOutput.insertEntitiesInNetFile(correctedObservablesString, "groups");
// analyze the sBnglOutput, strip the fake "compartment" site and produce the proper cBnglOutput
if (model.getStructures().length > 1) {
// converts the net file inside sBngOutput
sBngOutput.extractCompartmentsFromNetFile();
}
BNGOutput cBngOutput = sBngOutput;
// String cBngOutputString = cBngOutput.getNetFileContent();
// System.out.println(cBngOutputString);
long endTime = System.currentTimeMillis();
long elapsedTime = endTime - startTime;
System.out.println("Done " + i + " Iterations in " + (int) (elapsedTime / 1000.0) + " s.");
// System.out.println("out of which " + (int)(eltDoWork/1000.0) + " s was spent in 'doWork'.");
System.out.println("- in BioNetGen: " + (int) (eltExecBng / 1000.0));
// doWork except isomorphism
System.out.println("- in DoWork : " + (int) ((eltDoWork - eltIsomorph) / 1000.0));
System.out.println("- in Isomorph : " + (int) (eltIsomorph / 1000.0));
System.out.println("- in Observ : " + (int) (eltObserv / 1000.0));
// algorithms outside doWork
System.out.println("- in rest : " + (int) ((elapsedTime - eltExecBng - eltDoWork - eltObserv) / 1000.0));
// we basically return the "corrected" bng output from the last iteration run
return cBngOutput;
}
use of org.vcell.model.rbm.NetworkConstraints in project vcell by virtualcell.
the class BNGExecutorServiceMultipass method extractNetworkConstraints.
private static NetworkConstraints extractNetworkConstraints(String cBngInputString) {
NetworkConstraints nc = new NetworkConstraints();
String s1 = cBngInputString.substring(cBngInputString.indexOf("max_iter=>") + "max_iter=>".length());
s1 = s1.substring(0, s1.indexOf(","));
int maxi = Integer.parseInt(s1);
nc.setMaxIteration(maxi);
String s2 = cBngInputString.substring(cBngInputString.indexOf("max_agg=>") + "max_agg=>".length());
s2 = s2.substring(0, s2.indexOf(","));
int maxa = Integer.parseInt(s2);
nc.setMaxMoleculesPerSpecies(maxa);
return nc;
}
use of org.vcell.model.rbm.NetworkConstraints in project vcell by virtualcell.
the class SimContextTable method getAppComponentsForDatabase.
/**
* getXMLStringForDatabase : this returns the XML string for the container element <AppComponents> for application-related protocols
* and other extra specifications. For now, BioEvents falls under this category, so the BioEvents element (list of bioevents)
* is obtained from the simContext (via the XMLProducer) and added as content to <AppComponents> element. The <AppComponents>
* element is converted to XML string which is the return value of this method. This string is stored in the database in the
* SimContextTable. Instead of creating new fields for each possible application component, it is convenient to store them
* all under a blanket XML element <AppComponents>.
* @param simContext
* @return
*/
public static String getAppComponentsForDatabase(SimulationContext simContext) {
Element appComponentsElement = new Element(XMLTags.ApplicationComponents);
// for now, create the element only if application is stochastic. Can change it later.
if (simContext.isStoch()) {
// add 'randomizeInitCondition' flag only if simContext is non-spatial
if (simContext.getGeometry().getDimension() == 0) {
Element appRelatedFlagsElement = new Element(XMLTags.ApplicationSpecificFlagsTag);
if (simContext.isRandomizeInitCondition()) {
appRelatedFlagsElement.setAttribute(XMLTags.RandomizeInitConditionTag, "true");
} else {
appRelatedFlagsElement.setAttribute(XMLTags.RandomizeInitConditionTag, "false");
}
appComponentsElement.addContent(appRelatedFlagsElement);
}
}
if (simContext.isInsufficientIterations()) {
appComponentsElement.setAttribute(XMLTags.InsufficientIterationsTag, "true");
} else {
appComponentsElement.setAttribute(XMLTags.InsufficientIterationsTag, "false");
}
if (simContext.isInsufficientMaxMolecules()) {
appComponentsElement.setAttribute(XMLTags.InsufficientMaxMoleculesTag, "true");
} else {
appComponentsElement.setAttribute(XMLTags.InsufficientMaxMoleculesTag, "false");
}
Xmlproducer xmlProducer = new Xmlproducer(false);
NetworkConstraints constraints = simContext.getNetworkConstraints();
if (constraints != null) {
appComponentsElement.addContent(xmlProducer.getXML(constraints));
}
// first fill in bioevents from simContext
BioEvent[] bioEvents = simContext.getBioEvents();
if (bioEvents != null && bioEvents.length > 0) {
try {
Element bioEventsElement = xmlProducer.getXML(bioEvents);
appComponentsElement.addContent(bioEventsElement);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error generating XML for bioevents : " + e.getMessage());
}
}
SimulationContextParameter[] appParams = simContext.getSimulationContextParameters();
if (appParams != null && appParams.length > 0) {
try {
Element appParamsElement = xmlProducer.getXML(appParams);
appComponentsElement.addContent(appParamsElement);
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error generating XML for application parameters : " + e.getMessage());
}
}
SpatialObject[] spatialObjects = simContext.getSpatialObjects();
if (spatialObjects != null && spatialObjects.length > 0) {
try {
Element spatialObjectsElement = xmlProducer.getXML(spatialObjects);
appComponentsElement.addContent(spatialObjectsElement);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error generating XML for spatialObjects : " + e.getMessage());
}
}
SpatialProcess[] spatialProcesses = simContext.getSpatialProcesses();
if (spatialProcesses != null && spatialProcesses.length > 0) {
try {
Element spatialProcessesElement = xmlProducer.getXML(spatialProcesses);
appComponentsElement.addContent(spatialProcessesElement);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error generating XML for spatialProcesses : " + e.getMessage());
}
}
// microscope measurements
Element element = xmlProducer.getXML(simContext.getMicroscopeMeasurement());
appComponentsElement.addContent(element);
// rate rules
RateRule[] rateRules = simContext.getRateRules();
if (rateRules != null && rateRules.length > 0) {
try {
Element rateRulesElement = xmlProducer.getXML(rateRules);
appComponentsElement.addContent(rateRulesElement);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error generating XML for bioevents : " + e.getMessage());
}
}
// ReactionRuleSpecs
ReactionRuleSpec[] reactionRuleSpecs = simContext.getReactionContext().getReactionRuleSpecs();
if (reactionRuleSpecs != null && reactionRuleSpecs.length > 0) {
Element reactionRuleSpecsElement = xmlProducer.getXML(reactionRuleSpecs);
appComponentsElement.addContent(reactionRuleSpecsElement);
}
String appComponentsXMLStr = null;
if (appComponentsElement.getContent() != null) {
appComponentsXMLStr = XmlUtil.xmlToString(appComponentsElement);
}
return appComponentsXMLStr;
}
Aggregations