Work on an SBW and JSim integration is in full progress. However the other day I came across a minor snag with the SBW Java bindings, for the life of me I couldn’t find out why we could not send a model from one application to another. On any other platform (OSX, Ubuntu, Windows), I would just have started the SBW Inspector, and called the methods from the UI, or I would have used PowerShell, or the CSharp interactive shell, or even IronPython to code against the SBW object model. However I was out of luck, I did not have the mono runtime available on that system. So it dawned to me that really there should be some sort of simple debugging tools available. Given that on the system the only thing I had available was Java, I went and wrote the simplest Java SBW modules to narrow down the process. I figured in case others have the same problem I might as well put them up here for grabs.
So how would you use those java classes:
- Download the SBWtest.tar.gz file
- Extract with: tar zxf SBWtest.tar.gz
- change to the directory: cd SBWtest
at this point you will find two jar files (SBWCore.jar and SBWCore-debug.jar). Those jar files are the SBW Java bindings. All the following commands will assume that you include them in your classpath. There are two jar files, the SBWCore.jar will silently do its work and SBWCore-debug.jar will work just the same but add tons of debugging information for when it is really needed. Usually you’d just use the SBWCore.jar, and only switch to the other one if something fishy is going on. Let us have a brief look at the java classes included in the archive:
ListModules | This all this simple class does, is to connect to SBW, and get a list of registered modules and print them to stdout. Use with: java –cp SBWCore.jar:. ListModules This will print a list of module names, you will have the ‘unique’ module name, followed by an equals sign and then the human readable name. |
ListRunningModules | This class connects to SBW and lists all currently running SBW modules. Use with: java –cp SBWCore.jar:. ListRunningModules |
StartModule | A simple java class, that will just start another SBW module, it expects one argument, the ‘unique’ name of an SBW module (the name before the equals sign in the ListModules output). Start with: java –cp SBWCore.jar:. StartModule <moduleName> for example: java –cp SBWCore.jar:. StartModule edu.caltech.NOM to start the SBML support module. |
Analyzer | The Analyzer class represents a simple SBW module by itself. It belongs to the ‘/Analysis’ category, and as such will when registered appear in the SBW module. It has one method, ‘void doAnalysis(string)’ which will take a string (usually an SBML model, when called through the SBW menu) and print it to the command line. As with all SBW modules, it takes one argument, either ‘-sbwmodule’ in which case it is launched as module, or ‘-sbwregister’ in which case it registers with the Broker (and it should be displayed with a call to ListModules as ‘testAnalyzer’). Use with: java –cp SBWCore.jar:. Analyzer –sbwregister to register, or with: java –cp SBWCore.jar:. Analyzer –sbwmodule to run it as module. |
CallAnalyzer | Finally there is CallAnalyzer, a simple class, that takes two arguments, the first is a ‘unique’ SBW module name (as given by ListModules) and the other is a fileName of a SBML file, which is read and passed to the SBW module. This basically mimics what will happen if an SBW analyzer is called from the SBW menu. Use with: java –cp SBWCore.jar:. CallAnalyzer <moduleName> <fileName> as in: java –cp SBWCore.jar:. Analzer ~/SBML\ Models/BorisEJB.xml |
I hope they will be useful for someone else … btw … turns out that the only thing that was not working as planned, was that the module in question was registered as SELF_MANAGED module instead of a UNIQUE one … so all is well with the bindings …
No comments:
Post a Comment