use of org.vcell.sbml.vcell.SBMLImporter in project vcell by virtualcell.
the class SimulationServiceImpl method computeModel.
public SimulationInfo computeModel(SBMLModel model, SimulationSpec simSpec) throws ThriftDataAccessException, TException {
try {
SBMLImporter importer = new SBMLImporter(model.getFilepath(), vcLogger(), true);
BioModel bioModel = importer.getBioModel();
return computeModel(bioModel, simSpec, null);
} catch (Exception exc) {
exc.printStackTrace(System.out);
return null;
}
}
use of org.vcell.sbml.vcell.SBMLImporter in project vcell by virtualcell.
the class BNGWindowManager method importSbml.
/**
* Comment
*/
public void importSbml(String bngSbmlStr) {
if (bngSbmlStr == null || bngSbmlStr.length() == 0) {
throw new RuntimeException("SBMl string is empty, cannot import into VCell.");
}
//
// 1. Convert SBML string from BNG to SBML model, add unitDefintions to SBML model using VCell sbml compatible unit system
// 2. Import unit modified SBML model into VCell as biomodel
// 3. Enforce "cleaner" (looking) units on this imported biomodel (can use the units added to the sbml model above)
// 4. Convert all LumpedKinetics reactions into DistributedKinetics.
// 4. Convert this biomodel into vcml string and pass it into XMLInfo and then to RequestManager to open document.
//
ModelUnitSystem mus = ModelUnitSystem.createDefaultVCModelUnitSystem();
ModelUnitSystem sbmlCompatibleVCModelUnitSystem = ModelUnitSystem.createSBMLUnitSystem(mus.getVolumeSubstanceUnit(), mus.getVolumeUnit(), mus.getAreaUnit(), mus.getLengthUnit(), mus.getTimeUnit());
// display to user to change units if desired.
UnitSystemSelectionPanel unitSystemSelectionPanel = new UnitSystemSelectionPanel(true);
unitSystemSelectionPanel.initialize(sbmlCompatibleVCModelUnitSystem);
int retcode = DialogUtils.showComponentOKCancelDialog(getBngOutputPanel(), unitSystemSelectionPanel, "Select new unit system to import into VCell");
ModelUnitSystem forcedModelUnitSystem = null;
while (retcode == JOptionPane.OK_OPTION) {
try {
forcedModelUnitSystem = unitSystemSelectionPanel.createModelUnitSystem();
break;
} catch (Exception e) {
e.printStackTrace(System.out);
DialogUtils.showErrorDialog(getBngOutputPanel(), e.getMessage(), e);
retcode = DialogUtils.showComponentOKCancelDialog(getBngOutputPanel(), unitSystemSelectionPanel, "Select new unit system to import into VCell");
}
}
if (forcedModelUnitSystem == null) {
DialogUtils.showErrorDialog(getBngOutputPanel(), "Units are required for import into Virtual Cell.");
}
try {
// SBMLUnitTranslator.addUnitDefinitionsToSbmlModel(bngSbmlStr, forcedModelUnitSystem);
String modifiedSbmlStr = bngSbmlStr;
// Create a default VCLogger - SBMLImporter needs it
cbit.util.xml.VCLogger logger = new cbit.util.xml.VCLogger() {
@Override
public void sendMessage(Priority p, ErrorType et, String message) throws Exception {
System.err.println("LOGGER: msgLevel=" + p + ", msgType=" + et + ", " + message);
if (p == VCLogger.Priority.HighPriority) {
throw new RuntimeException("Import failed : " + message);
}
}
public void sendAllMessages() {
}
public boolean hasMessages() {
return false;
}
};
// import sbml String into VCell biomodel
File sbmlFile = File.createTempFile("temp", ".xml");
sbmlFile.deleteOnExit();
XmlUtil.writeXMLStringToFile(modifiedSbmlStr, sbmlFile.getAbsolutePath(), true);
org.vcell.sbml.vcell.SBMLImporter sbmlImporter = new SBMLImporter(sbmlFile.getAbsolutePath(), logger, false);
BioModel bioModel = sbmlImporter.getBioModel();
// enforce 'cleaner looking' units on vc biomodel (the process of adding unit defintion to sbml model messes up the units, though they are correct units (eg., 1e-6m for um).
BioModel modifiedBiomodel = ModelUnitConverter.createBioModelWithNewUnitSystem(bioModel, forcedModelUnitSystem);
// convert any reaction that has GeneralLumpedKinetics to GeneralKinetics
for (ReactionStep rs : modifiedBiomodel.getModel().getReactionSteps()) {
Kinetics kinetics = rs.getKinetics();
if (kinetics instanceof LumpedKinetics) {
rs.setKinetics(DistributedKinetics.toDistributedKinetics((LumpedKinetics) kinetics));
}
}
// convert biomodel to vcml string
String vcmlString = XmlHelper.bioModelToXML(modifiedBiomodel);
ExternalDocInfo externalDocInfo = new ExternalDocInfo(vcmlString);
if (externalDocInfo != null) {
getRequestManager().openDocument(externalDocInfo, this, true);
}
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException("Cound not convert BNG sbml string to VCell biomodel : ", e);
}
}
use of org.vcell.sbml.vcell.SBMLImporter in project vcell by virtualcell.
the class VCellSBMLSolver method importSBML.
private BioModel importSBML(String filename, VCLogger logger, boolean isSpatial) throws ClassNotFoundException, IOException, ExecutableException, XmlParseException, XMLStreamException {
org.vcell.sbml.vcell.SBMLImporter sbmlImporter = new org.vcell.sbml.vcell.SBMLImporter(filename, logger, false);
BioModel bioModel = sbmlImporter.getBioModel();
return bioModel;
}
use of org.vcell.sbml.vcell.SBMLImporter in project vcell by virtualcell.
the class XmlHelper method importSBML.
/**
* Allows the translation process to interact with the user via TranslationMessager
*/
public static VCDocument importSBML(VCLogger vcLogger, XMLSource xmlSource, boolean bSpatial) throws Exception {
// checks that the source is not empty
if (xmlSource == null) {
throw new XmlParseException("Invalid params for importing sbml model.");
}
// First try getting xmlfile from xmlSource. If not file, get xmlStr and save it in file
// (since we send only file name to SBMLImporter). If xmlString is also not present in xmlSource, throw exception.
File sbmlFile = xmlSource.getXmlFile();
if (sbmlFile == null) {
String sbmlStr = xmlSource.getXmlString();
if (sbmlStr != null) {
sbmlFile = File.createTempFile("temp", ".xml");
sbmlFile.deleteOnExit();
XmlUtil.writeXMLStringToFile(sbmlStr, sbmlFile.getAbsolutePath(), true);
} else {
throw new RuntimeException("Error importing from SBML : no SBML source.");
}
}
VCDocument vcDoc = null;
// if (!bSpatial) {
SBMLImporter sbmlImporter = new SBMLImporter(sbmlFile.getAbsolutePath(), vcLogger, bSpatial);
vcDoc = sbmlImporter.getBioModel();
// } else {
// SBMLSpatialImporter sbmlSpatialImporter = new SBMLSpatialImporter(sbmlFile.getAbsolutePath(), vcLogger);
// vcDoc = sbmlSpatialImporter.getBioModel();
// }
vcDoc.refreshDependencies();
System.out.println("Succesful model import: SBML file " + sbmlFile);
return vcDoc;
}
use of org.vcell.sbml.vcell.SBMLImporter in project vcell by virtualcell.
the class SBMLImporterTest method testImport.
@Test
public void testImport() throws XMLStreamException, IOException {
HashMap<Integer, FAULT> faults = new HashMap();
faults.put(6, FAULT.RESERVED_WORD);
faults.put(15, FAULT.RESERVED_WORD);
faults.put(92, FAULT.RESERVED_WORD);
faults.put(114, FAULT.RESERVED_WORD);
faults.put(115, FAULT.RESERVED_WORD);
faults.put(117, FAULT.RESERVED_WORD);
faults.put(148, FAULT.RESERVED_WORD);
faults.put(154, FAULT.RESERVED_WORD);
faults.put(155, FAULT.RESERVED_WORD);
faults.put(154, FAULT.RESERVED_WORD);
faults.put(155, FAULT.RESERVED_WORD);
faults.put(156, FAULT.RESERVED_WORD);
faults.put(157, FAULT.RESERVED_WORD);
faults.put(158, FAULT.RESERVED_WORD);
faults.put(159, FAULT.RESERVED_WORD);
faults.put(274, FAULT.RESERVED_WORD);
faults.put(279, FAULT.RESERVED_WORD);
faults.put(282, FAULT.RESERVED_WORD);
faults.put(288, FAULT.RESERVED_WORD);
faults.put(346, FAULT.RESERVED_WORD);
faults.put(24, FAULT.DELAY);
faults.put(25, FAULT.DELAY);
faults.put(34, FAULT.DELAY);
faults.put(196, FAULT.DELAY);
faults.put(39, FAULT.NONINTEGER_STOICH);
faults.put(59, FAULT.NONINTEGER_STOICH);
faults.put(63, FAULT.NONINTEGER_STOICH);
faults.put(81, FAULT.NONINTEGER_STOICH);
faults.put(145, FAULT.NONINTEGER_STOICH);
faults.put(151, FAULT.NONINTEGER_STOICH);
faults.put(199, FAULT.NONINTEGER_STOICH);
faults.put(206, FAULT.NONINTEGER_STOICH);
faults.put(232, FAULT.NONINTEGER_STOICH);
faults.put(244, FAULT.NONINTEGER_STOICH);
faults.put(246, FAULT.NONINTEGER_STOICH);
faults.put(110, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(178, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(228, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(245, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(252, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(262, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(263, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(264, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(267, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(283, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(300, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(316, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(317, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(319, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(322, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(323, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(337, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(327, FAULT.EXPRESSION_BINDING_EXCEPTION);
faults.put(340, FAULT.XOR_MISSING);
faults.put(248, FAULT.EXPRESSION_BINDING_EXCEPTION);
faults.put(305, FAULT.EXPRESSION_BINDING_EXCEPTION);
faults.put(353, FAULT.NONINTEGER_STOICH);
faults.put(367, FAULT.RESERVED_WORD);
faults.put(382, FAULT.RESERVED_WORD);
faults.put(383, FAULT.NONINTEGER_STOICH);
faults.put(384, FAULT.NONINTEGER_STOICH);
faults.put(385, FAULT.NONINTEGER_STOICH);
faults.put(386, FAULT.NONINTEGER_STOICH);
faults.put(387, FAULT.NONINTEGER_STOICH);
faults.put(388, FAULT.NONINTEGER_STOICH);
faults.put(392, FAULT.NONINTEGER_STOICH);
faults.put(401, FAULT.NONINTEGER_STOICH);
faults.put(402, FAULT.RESERVED_WORD);
faults.put(403, FAULT.RESERVED_WORD);
faults.put(405, FAULT.INCONSISTENT_UNIT_SYSTEM);
faults.put(539, FAULT.JSBML_ERROR);
File[] sbmlFiles = SBMLUnitTranslatorTest.getBiomodelsCuratedSBMLFiles();
// File[] sbmlFiles = new File[] {
// new File("/Users/schaff/Documents/workspace-maven/BioModels_Database-r30_pub-sbml_files/curated/BIOMD0000000001.xml"),
// new File("/Users/schaff/Documents/workspace-maven/BioModels_Database-r30_pub-sbml_files/curated/BIOMD0000000101.xml"),
// new File("/Users/schaff/Documents/workspace-maven/sbml-test-suite/cases/semantic/00001/00001-sbml-l3v1.xml")
// };
VCLogger vcl = new TLogger();
int start = 401;
for (int index = start; index < sbmlFiles.length; index++) {
File sbmlFile = sbmlFiles[index];
int sbmlNumber = Integer.parseInt(sbmlFile.getName().substring(6).replace(".xml", ""));
if (faults.containsKey(sbmlNumber)) {
System.err.println("skipping this model, " + faults.get(sbmlNumber).name());
continue;
}
System.out.println("testing " + sbmlFile);
SBMLImporter importer = new SBMLImporter(sbmlFile.getAbsolutePath(), vcl, false);
BioModel bioModel = importer.getBioModel();
}
}
Aggregations