use of org.jdom.Document in project vcell by virtualcell.
the class NfsimExtensionFilter method writeBioModel.
@Override
public void writeBioModel(DocumentManager documentManager, BioModel bioModel, File exportFile, SimulationContext simulationContext) throws Exception {
// TODO: get the first thing we find for now, in the future we'll need to modify ChooseFile
// to only offer the applications / simulations with bngl content
// This should be done by creating one or more additional Selector values and add the filtering logic to ChooseFile
SimulationContext[] simContexts = bioModel.getSimulationContexts();
Simulation selectedSim = simulationContext.getSimulations(0);
// Simulation selectedSim = (Simulation)hashTable.get("selectedSimulation");
SimulationTask simTask = new SimulationTask(new SimulationJob(selectedSim, 0, null), 0);
// a fixed seed will allow us to run reproducible simulations
long randomSeed = 0;
// long randomSeed = System.currentTimeMillis();
NFsimSimulationOptions nfsimSimulationOptions = new NFsimSimulationOptions();
// we get the data we need from the math description
boolean bUseLocationMarks = true;
Element root = NFsimXMLWriter.writeNFsimXML(simTask, randomSeed, nfsimSimulationOptions, bUseLocationMarks);
Document doc = new Document();
doc.setRootElement(root);
XMLOutputter xmlOut = new XMLOutputter();
String resultString = xmlOut.outputString(doc);
FileUtils.writeStringToFile(exportFile, resultString);
}
use of org.jdom.Document in project vcell by virtualcell.
the class RulebasedTransformer method parseObservablesBngOutput.
private void parseObservablesBngOutput(SimulationContext simContext, BNGOutput bngOutput) {
Model model = simContext.getModel();
Document bngNFSimXMLDocument = bngOutput.getNFSimXMLDocument();
bngRootElement = bngNFSimXMLDocument.getRootElement();
Element modelElement = bngRootElement.getChild("model", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
Element listOfObservablesElement = modelElement.getChild("ListOfObservables", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
XMLOutputter outp = new XMLOutputter();
String sTheirs = outp.outputString(listOfObservablesElement);
sTheirs = sTheirs.replace("xmlns=\"http://www.sbml.org/sbml/level3\"", "");
// System.out.println("==================== Their Observables ===================================================================");
// System.out.println(sTheirs);
// System.out.println("=======================================================================================");
saveAsText("c:\\TEMP\\ddd\\theirObservables.txt", sTheirs);
// sTheirs = sTheirs.replaceAll("\\s+","");
}
use of org.jdom.Document in project vcell by virtualcell.
the class RulebasedTransformer method parseBngOutput.
private void parseBngOutput(SimulationContext simContext, Set<ReactionRule> fromReactions, BNGOutput bngOutput) {
Model model = simContext.getModel();
Document bngNFSimXMLDocument = bngOutput.getNFSimXMLDocument();
bngRootElement = bngNFSimXMLDocument.getRootElement();
Element modelElement = bngRootElement.getChild("model", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
Element listOfReactionRulesElement = modelElement.getChild("ListOfReactionRules", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
List<Element> reactionRuleChildren = new ArrayList<Element>();
reactionRuleChildren = listOfReactionRulesElement.getChildren("ReactionRule", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
for (Element reactionRuleElement : reactionRuleChildren) {
ReactionRuleAnalysisReport rar = new ReactionRuleAnalysisReport();
boolean bForward = true;
String rule_id_str = reactionRuleElement.getAttributeValue("id");
ruleElementMap.put(rule_id_str, reactionRuleElement);
String rule_name_str = reactionRuleElement.getAttributeValue("name");
String symmetry_factor_str = reactionRuleElement.getAttributeValue("symmetry_factor");
Double symmetry_factor_double = Double.parseDouble(symmetry_factor_str);
ReactionRule rr = null;
if (rule_name_str.startsWith("_reverse_")) {
bForward = false;
rule_name_str = rule_name_str.substring("_reverse_".length());
rr = model.getRbmModelContainer().getReactionRule(rule_name_str);
RbmKineticLaw rkl = rr.getKineticLaw();
try {
if (symmetry_factor_double != 1.0 && fromReactions.contains(rr)) {
Expression expression = rkl.getLocalParameterValue(RbmKineticLawParameterType.MassActionReverseRate);
expression = Expression.div(expression, new Expression(symmetry_factor_double));
rkl.setLocalParameterValue(RbmKineticLawParameterType.MassActionReverseRate, expression);
}
} catch (ExpressionException | PropertyVetoException exc) {
exc.printStackTrace();
throw new RuntimeException("Unexpected transform exception: " + exc.getMessage());
}
rulesReverseMap.put(rr, rar);
} else {
rr = model.getRbmModelContainer().getReactionRule(rule_name_str);
RbmKineticLaw rkl = rr.getKineticLaw();
try {
if (symmetry_factor_double != 1.0 && fromReactions.contains(rr)) {
Expression expression = rkl.getLocalParameterValue(RbmKineticLawParameterType.MassActionForwardRate);
expression = Expression.div(expression, new Expression(symmetry_factor_double));
rkl.setLocalParameterValue(RbmKineticLawParameterType.MassActionForwardRate, expression);
}
} catch (ExpressionException | PropertyVetoException exc) {
exc.printStackTrace();
throw new RuntimeException("Unexpected transform exception: " + exc.getMessage());
}
rulesForwardMap.put(rr, rar);
}
rar.symmetryFactor = symmetry_factor_double;
System.out.println("rule id=" + rule_id_str + ", name=" + rule_name_str + ", symmetry factor=" + symmetry_factor_str);
keyMap.put(rule_id_str, rr);
Element listOfReactantPatternsElement = reactionRuleElement.getChild("ListOfReactantPatterns", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
List<Element> reactantPatternChildren = new ArrayList<Element>();
reactantPatternChildren = listOfReactantPatternsElement.getChildren("ReactantPattern", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
for (int i = 0; i < reactantPatternChildren.size(); i++) {
Element reactantPatternElement = reactantPatternChildren.get(i);
String pattern_id_str = reactantPatternElement.getAttributeValue("id");
ReactionRuleParticipant p = bForward ? rr.getReactantPattern(i) : rr.getProductPattern(i);
SpeciesPattern sp = p.getSpeciesPattern();
System.out.println(" reactant id=" + pattern_id_str + ", name=" + sp.toString());
keyMap.put(pattern_id_str, sp);
// list of molecules
extractMolecules(sp, model, reactantPatternElement);
// list of bonds (not implemented)
extractBonds(reactantPatternElement);
}
Element listOfProductPatternsElement = reactionRuleElement.getChild("ListOfProductPatterns", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
List<Element> productPatternChildren = new ArrayList<Element>();
productPatternChildren = listOfProductPatternsElement.getChildren("ProductPattern", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
for (int i = 0; i < productPatternChildren.size(); i++) {
Element productPatternElement = productPatternChildren.get(i);
String pattern_id_str = productPatternElement.getAttributeValue("id");
ReactionRuleParticipant p = bForward ? rr.getProductPattern(i) : rr.getReactantPattern(i);
SpeciesPattern sp = p.getSpeciesPattern();
System.out.println(" product id=" + pattern_id_str + ", name=" + sp.toString());
keyMap.put(pattern_id_str, sp);
extractMolecules(sp, model, productPatternElement);
extractBonds(productPatternElement);
}
// extract the Map for this rule
Element listOfMapElement = reactionRuleElement.getChild("Map", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
List<Element> mapChildren = new ArrayList<Element>();
mapChildren = listOfMapElement.getChildren("MapItem", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
for (Element mapElement : mapChildren) {
String target_id_str = mapElement.getAttributeValue("targetID");
String source_id_str = mapElement.getAttributeValue("sourceID");
System.out.println("Map: target=" + target_id_str + " source=" + source_id_str);
RbmObject target_object = keyMap.get(target_id_str);
RbmObject source_object = keyMap.get(source_id_str);
if (target_object == null)
System.out.println("!!! Missing map target " + target_id_str);
if (source_object == null)
System.out.println("!!! Missing map source " + source_id_str);
if (source_object != null) {
// target_object may be null
System.out.println(" target=" + target_object + " source=" + source_object);
Pair<RbmObject, RbmObject> mapEntry = new Pair<RbmObject, RbmObject>(target_object, source_object);
rar.objmappingList.add(mapEntry);
}
Pair<String, String> idmapEntry = new Pair<String, String>(target_id_str, source_id_str);
rar.idmappingList.add(idmapEntry);
}
// ListOfOperations
Element listOfOperationsElement = reactionRuleElement.getChild("ListOfOperations", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
List<Element> operationsChildren = new ArrayList<Element>();
operationsChildren = listOfOperationsElement.getChildren("StateChange", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
System.out.println("ListOfOperations");
for (Element operationsElement : operationsChildren) {
String finalState_str = operationsElement.getAttributeValue("finalState");
String site_str = operationsElement.getAttributeValue("site");
RbmObject site_object = keyMap.get(site_str);
if (site_object == null)
System.out.println("!!! Missing map object " + site_str);
if (site_object != null) {
System.out.println(" finalState=" + finalState_str + " site=" + site_object);
StateChangeOperation sco = new StateChangeOperation(finalState_str, site_str, site_object);
rar.operationsList.add(sco);
}
}
operationsChildren = listOfOperationsElement.getChildren("AddBond", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
for (Element operationsElement : operationsChildren) {
String site1_str = operationsElement.getAttributeValue("site1");
String site2_str = operationsElement.getAttributeValue("site2");
RbmObject site1_object = keyMap.get(site1_str);
RbmObject site2_object = keyMap.get(site2_str);
if (site1_object == null)
System.out.println("!!! Missing map object " + site1_str);
if (site2_object == null)
System.out.println("!!! Missing map object " + site2_str);
if (site1_object != null && site2_object != null) {
System.out.println(" site1=" + site1_object + " site2=" + site2_object);
AddBondOperation abo = new AddBondOperation(site1_str, site2_str, site1_object, site2_object);
rar.operationsList.add(abo);
}
}
operationsChildren = listOfOperationsElement.getChildren("DeleteBond", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
for (Element operationsElement : operationsChildren) {
String site1_str = operationsElement.getAttributeValue("site1");
String site2_str = operationsElement.getAttributeValue("site2");
RbmObject site1_object = keyMap.get(site1_str);
RbmObject site2_object = keyMap.get(site2_str);
if (site1_object == null)
System.out.println("!!! Missing map object " + site1_str);
if (site2_object == null)
System.out.println("!!! Missing map object " + site2_str);
if (site1_object != null && site2_object != null) {
System.out.println(" site1=" + site1_object + " site2=" + site2_object);
DeleteBondOperation dbo = new DeleteBondOperation(site1_str, site2_str, site1_object, site2_object);
rar.operationsList.add(dbo);
}
}
operationsChildren = listOfOperationsElement.getChildren("Add", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
for (Element operationsElement : operationsChildren) {
String id_str = operationsElement.getAttributeValue("id");
RbmObject id_object = keyMap.get(id_str);
if (id_object == null)
System.out.println("!!! Missing map object " + id_str);
if (id_object != null) {
System.out.println(" id=" + id_str);
AddOperation ao = new AddOperation(id_str, id_object);
rar.operationsList.add(ao);
}
}
operationsChildren = listOfOperationsElement.getChildren("Delete", Namespace.getNamespace("http://www.sbml.org/sbml/level3"));
for (Element operationsElement : operationsChildren) {
String id_str = operationsElement.getAttributeValue("id");
String delete_molecules_str = operationsElement.getAttributeValue("DeleteMolecules");
RbmObject id_object = keyMap.get(id_str);
if (id_object == null)
System.out.println("!!! Missing map object " + id_str);
int delete_molecules_int = 0;
if (delete_molecules_str != null) {
delete_molecules_int = Integer.parseInt(delete_molecules_str);
}
if (id_object != null) {
System.out.println(" id=" + id_str + ", DeleteMolecules=" + delete_molecules_str);
DeleteOperation dop = new DeleteOperation(id_str, id_object, delete_molecules_int);
rar.operationsList.add(dop);
}
}
}
System.out.println("done parsing xml file");
}
use of org.jdom.Document in project vcell by virtualcell.
the class AmplistorUtils method getHeaderFields.
private static HashMap<String, List<String>> getHeaderFields(String urlStr, AmplistorCredential amplistorCredential) throws Exception {
HashMap<String, List<String>> results = new HashMap<>();
CheckOPHelper checkOPHelper = null;
try {
checkOPHelper = ampliCheckOP(new URL(urlStr + "?meta=xml"), amplistorCredential, AMPLI_OP_METHOD.GET, null, AMPLI_OP_KIND.FILE, null);
Document doc = getResponseXML(checkOPHelper.httpURLConnection);
List<Element> dirEntryElements = doc.getRootElement().getChildren();
for (Element dirEntry : dirEntryElements) {
ArrayList<String> values = new ArrayList<>();
values.add(dirEntry.getText());
results.put(dirEntry.getName(), values);
}
} finally {
if (checkOPHelper != null && checkOPHelper.httpURLConnection != null) {
checkOPHelper.httpURLConnection.disconnect();
}
}
return results;
}
use of org.jdom.Document in project vcell by virtualcell.
the class XmlHelper method importMathCellML.
public static VCDocument importMathCellML(VCLogger vcLogger, XMLSource xmlSource) throws Exception {
// checks that the string is not empty
if (xmlSource == null) {
throw new XmlParseException("Invalid params for importing cellml model to Mathmodel.");
}
Document xmlDoc = xmlSource.getXmlDoc();
String xmlString = XmlUtil.xmlToString(xmlDoc, false);
CellQuanVCTranslator cellmlTranslator = new CellQuanVCTranslator();
VCDocument vcDoc = cellmlTranslator.translate(new StringReader(xmlString), false);
vcDoc.refreshDependencies();
return vcDoc;
}
Aggregations