Download Links

Simulate 3D | SBW (Win32) | Bifurcation Discovery | FluxBalance
Showing posts with label roadRunner. Show all posts
Showing posts with label roadRunner. Show all posts

Sunday, March 2, 2014

Release of the Systems Biology Workbench 2.10.0

We are proud to finally announce a new release of the Systems Biology Workbench 2.10.0. You can download this release directly from SourceForge. This version provides updates to all components:

  • Jarnac comes up with an altered front-end, that will make it easier to work with it. It features also additional script commands .
  • JDesigner has been updated to work on newer Windows versions (7-8.1). It also can now load and save model parameters from / to external files. And it features a new plugin system.

Since our last official release, the SBML Level 3 Layout Package has finally been officially accepted, this release supports that final version as well. Similarly, SED-ML Level 1 Version 2 has been released, and with the Simulation Tool those files can be executed. Broken down into individual applications we have:

  • Layout Viewer / SBW Auto Layout: Support for SBML Level 3 Layout Package.
  • SBW Simulation Tool: Support for all SBML levels, and SED-ML Level 1 Version 2. First experiments such as Parameter Scans can also be exported. It also automatically displays targets of SBML Events / Rules in the list of selected elements, when loading models. The Simulation Tool also supports loading files from the COMBINE archive.
  • SBML Support Library: SBML models using the Hierarchical Model Composition package will be automatically flattened, when possible (The file has to be valid, and all submodels have to be reachable.).
  • JarnacLite / RoadRunner / SBML Support Library / JDesigner: A number of custom annotations have been added to allow the specification / simulation of distribution functions, or referencing the rate of change of a species. I've written about that before: distribution and rateOf.

As some of you know, Frank has joined the COPASI team. This made it possible to write a translator for COPASI, and now there is a new SBW import category that enables calling modules, to have a specific format converted into SBML, which can then be consumed. Current bidirectional translators are available for COPASI and JARNAC format. Practically that means that COPASI and JARNAC files can now be directly imported into: Simulation Tool, Auto Layout and others.

Of course there have been many more changes, bug fixes and improvements, so have a look at our full changelog.

Sunday, September 1, 2013

Systems Biology Workbench 2.10 (RC1)

As hinted at, a couple of days ago, we are shortly before the release of the next version of SBW with enhancements for all associated programs. Today I want to announce a new release candidate. On SourceForge you will find installers for Windows, OSX as well as Linux (x86 & x64). You can download them from:

http://sourceforge.net/projects/sbw/files/sbw/2.10.0/rc1/

I’ve also created virtual machines & live images with SUSE studio, that are available online:

32bit OpenSUSE 12.3,
64bit OpenSUSE 12.3

Any feedback is appreciated.

SBW-Logo

Sunday, February 10, 2013

New SBML Test Suite Database!

As you might have noticed there is a new online service available on sbml.org, the SBML Test Suite Database. We of course had the SBML Test Suite for quite some time, with an amazing number of 1196 tests (to date), that now also include tests for the Flux Balance Package and even Hierarchical Modeling. This new application lets you browse all these tests, filter for tests (for example: Show me all tests, that test ‘RandomEventExecution’) and  download a selection of tests right there.

2013-01-30_-_TestSuiteDB

At the heart of course is the capability to *upload* a zipped set of test results, and analyze them for yourself in a private area, and once you are happy with them have them published publicly for the world to see. I’ve am working on a new version of SBW, that uses the 5.7.0 version of libSBML. And here is what a result for RoadRunner would look like:

2013-01-30_-_TestSuiteDB_RR_Result

As you can see in yellow, RoadRunner will still not support AlgebraicRules, FastReactions or CSymbolDelay. However, libSBML will flatten comp models for RoadRunner, and so all comp tests that do not use the above mentioned elements will work just fine.

Thursday, September 6, 2012

Custom Annotation for using Distribution Functions in SBML Models

Drawing random numbers is a task occasionally encountered. However, there is no standard way to do that in SBML. Of course that is precisely what the SBML Level 3 package for Distributions and Ranges is for. But what to do in the meantime, or what to do when you want it working for SBML Level 2? This is precisely what I encountered a couple of weeks back, and that is why below you will find a specification for a very short custom annotation, that allows to tag an SBML function definition as distribution function. Here an example:

<functionDefinition id="normal" name="Normal distribution">
  <annotation>
    <distribution xmlns="
http://sbml.org/annotations/distribution" definition="http://en.wikipedia.org/wiki/Normal_distribution" />
  </annotation>
  <math xmlns="
http://www.w3.org/1998/Math/MathML">
    <lambda>
      <bvar>
        <ci> m </ci>
      </bvar>
      <bvar>
        <ci> s </ci>
      </bvar>
      <ci> m </ci>
    </lambda>
  </math>
</functionDefinition>

The annotation (in the namespace http://sbml.org/annotations/distribution) contains one attribute definition, whose value tells us precisely which distribution we would like to draw numbers from. All software that supports it will know that we are dealing with a distribution and know what to do with it. Other software at least get the mean whenever they invoke the function.

2012-09-06_-_Result

Here the full specification of the Custom Distribution Annotation. (and here the SBML model). The annotation is so far supported by JarnacLite and RoadRunner (Windows Installer). As the same functionality is available in other software packages it would be great if they could be tagged with the annotation as well.

Sunday, February 12, 2012

Systems Biology Workbench - 2.9.0

I’m pleased to announce the release of SBW 2.9.0. This release is available for the following platforms:

  • Windows
  • Linux x86 / x64
  • OS X
  • portable Apps

This release improves support for the exchange standards: SBGN-ML, SED-ML (including the nested proposal v2), and of course SBML. RoadRunner simulates a wider range of SBML models. You can get the new release from Sourceforge:

And the portable installer from:

Screenshots

image

image

image

Linux

Thanks to bitrock, we are finally able to provide a new range of linux installers (as well as 32bit and 64bit RPMs and DEB packages). When installing as root, SBW will be installed into /opt/sbw-2.9.0. Otherwise it will be available in the users home directory. In these directories you will find shortcuts to all available programs.

Dependencies: most SBW applications require Mono 2.10 to be installed (we recommend to install mono-complete). If you try to run SBW on an older linux distribution that does not include mono 2.10 in its repository here are some installation scripts for fedora and ubuntu that will help you to get it running, it should be easy enough to adapt them to centos when needed. Here the example for ubuntu:

mkdir mono-2.10
cd mono-2.10
wget --no-check-certificate https://github.com/nathanb/iws-snippets/raw/master/mono-install-scripts/ubuntu/install_mono-2.10.sh
chmod 755 install_mono-2.10.sh
./install_mono-2.10.sh

If this still seems to adventurous for you, I’ve created a 32bit and a 64bit virtual machine that runs SBW 2.9.0. It includes Live CDs, Virtual Machines and hard drive images. Simply start the machine and find the SBW shortcuts in the start menu. (They simply use the SBW rpm installer!).

OS X

We’ve listened to all your feedback about SBW being difficult to install. So this time around we don’t use any installation. Simply drag the SBW folder into your Applications folder and you are good to go.

As always, we recommend installing XQuartz and Mono prior to running SBW. The current Mono release 2.10.8 (and the 2.10.9 beta) unfortunately have a regression that causes the some application to stop working. The last known working release is 2.10.5 as available from:  http://download.mono-project.com/archive/2.10.5/download/

As for XQuartz, I’m using: http://xquartz.macosforge.org/trac/wiki/X112.7.0

Full Change Log

Feb 2012
Changes in Version 2.9.0
===========================

SBML Layout:
  - Reading Support for SBML Layout Extension (for SBML L3)
  - (at the moment the library only writes annotations though)
  - Stability and performance improvements for Layout Viewer.
  - SBGN upgrade
  - Bug Fix: Global Render Information were not correctly read
  - Stability: Now works even independently of SBW
   
SED-ML:
  - Support for Kisao Terms (full lookup and browsing of the
    hierarchy).
  - Bug Fixes for error correction facility

RoadRunner:
  - BugFix: non integral stoichiometry for L1 models
  - BugFix: model refused to load when non-L3 model used ids in speciesreferences
  - BugFix: L1 model with local parameters refused to load
  - BugFix: L1 model with non-integral stoichiometry was incorrect
  - BugFix: hasOnlySubstanceUnits was ignored in some places

NOM:
  - added methods:
    reorderRules : string reorderRules(string)
    inlineFunctionDefinitions : string inlineFunctionDefinitions(string)
  - (rules are automatically reordered by loadSBML, this will allow other modules
    to work correctly without code change)
  - fix: promote local to global parameters works for L1 models
   
Translators:
  - sort assignment rules
  - added command line option -f <sbmlfile> to translate the SBML file
    and write the file to stdout, so they can be used from the command line.
 
Portable:
  - we also have a version of SBW that you can install on a flash drive
    using portable apps.
 
All modules:
  - updated to use libSBML 5.4.0

JDesigner:
  - Fixed Chinese characters appearing when assignment rule was selected for editing.

Sunday, December 11, 2011

SBW goes Portable

Portable Applications, are applications that you can easily take with you on your USB stick. This allows to use your applications on all Windows machines by simply plugging in the stick. I’m pleased to announce a first prototype that will make the Systems Biology Workbench available for the portableapps.com framework. Here the download:

http://sourceforge.net/projects/sbw/files/sbw/portable/

To install, simply launch portable apps, and then click on “Install a new App”:

image

It will install the following applications:

image

While the launcher only exposes: JDesigner,Jarnac, JarnacLite, the Simulation Tool,  SBML Translator, SBML Layout Viewer, AutoLayout and the C# Inspector, the full SBW installation is available.

If you need custom launchers for more applications, let me know (Possible candidates: BioModels Importer, Jacobian Viewer, Convert SBML, Shutdown SBW).

Please let me know whether this is working for you.

BAD NEWS:

Unfortunately we won’t be able to have SBW be part of the Portable Apps dictionary since some SBW components use .NET and portable apps do not consider .NET widely enough spread. (Even though it appears that it was on 90% of  Windows machines in 2010, and is now part of windows update, and thus *everyone* updating their machine is likely to have it installed.) But there goes me rambling …

Saturday, July 23, 2011

Updated SED-ML Web Tools (now with editing of SED-ML descriptions)

I’ve just released a new version of the SED-ML Web Tools they as always available from:

http://sysbioapps.dyndns.org/SED-ML Web Tools/Home/

The new version allows to edit the loaded model either by directly manipulating the XML, or by altering the model using the SED-ML Script Language.

Here a simple tutorial of creating a new SED-ML description from an SBML model and then modifying it using SED-ML Script.

Unable to display content. Adobe Flash is required.

As always I look forward to your feedback. To make it easier to collect I’ve signed up with idea informer, so there is now an orange feedback button right there on the page. That makes it easy to request your feature requests:

image

Sunday, July 3, 2011

Creating SED-ML for SBML models

I have just released a new version of the SED-ML Web Tools. This version creates SED-ML models for SBML files. Have a look here:

http://sysbioapps.dyndns.org/SED-ML%20Web%20Tools/Home/Create

All that is needed is to fill out this form:

image

After that the SED-ML description can be executed, or downloaded. More advanced options (such as creating SED-ML descriptions for CellML models) is available in the SED-ML Script Editor:

sf.net/projects/libsedml/files/

Friday, March 18, 2011

Systems Biology Workbench (SBW) 2.8.2 Released

We are pleased to announce the a release of the Systems Biology Workbench 2.8.2, available from:

http://sys-bio.org

The Systems Biology Workbench (SBW), is a software framework that allows heterogeneous application components-written in diverse programming languages and running on different platforms - to communicate and use each other's capabilities via a fast binary encoded-message system. Our goal was to create a simple, high performance, open-source software infrastructure which is easy to implement and understand. SBW enables applications (potentially running on separate, distributed computers) to communicate via a simple network protocol.

The interfaces to the system are encapsulated in client-side libraries that we provide for different programming languages.

Major changes in this release:

  • Updated JDesigner
  • Improved event support in RoadRunner,
  • Support of SBGN-ML (from SBML Layout)
  • Support of SED-ML L1V1 (from the Simulation Tool)

For a full list of changes see:

http://sys-bio.org/changelog.

As always we appreciate any feedback from users send to:

sbwteam@gmail.com

Enjoy

- Frank

Monday, August 9, 2010

Writing Plug-ins for the Simulation Tool – Part 2 – Setup - MonoDevelop

MonoDevelop

MonoDevelop is a free IDE by Novell, that is available on all operating systems. IT does not feature a visual designer and has no advanced debugging facilities as we see them in Visual Studio but it still is quite good. So let us try and create a project by hand that would create the above plug-in.  To make this authentic I add screenshots from doing it on OS X 10.6.

First let us start MonoDevelop and create a new Project:

Screen shot 2010-08-05 at 11.59.56 AM 

Next let us load all the required libraries (I’ve copied the files from the SBW Installation, which is either in /Application/SBW/lib or ~/SBW/lib on Linux):

Screen shot 2010-08-05 at 12.00.20 PM 

don’t forget to add System.Drawing and System.Windows.Forms from the GAC. The result should look like this:

Screen shot 2010-08-05 at 12.18.47 PM

(I went ahead and already copied some code for a plug-in into my project) 

When this is loaded let us modify the project settings:

Screen shot 2010-08-05 at 12.23.05 PM

Here we can change the default namespace:

Screen shot 2010-08-05 at 12.23.21 PM

and the target machine (x86):

Screen shot 2010-08-05 at 12.23.49 PM

And the output directory:

Screen shot 2010-08-05 at 12.24.12 PM

The output directory should *for now* be the SBW lib directory (that is where all the C# assemblies are). Under Linux that would be:

~/SBW/lib

and on OSX it is /Applications/SBW/lib.

for now this should be the same as the SBW one.  

All this has been saved in this project:

https://sourceforge.net/downloads/sbwsimtool/mono-sample-project/v1/

(It already uses the output directory /Application/SBW/lib as needed for OS X 10.6)

Unfortunately, similarly to Visual Studio Express there is no debugging support for Libraries … thus after a build you will need to start the simulation tool manually. (for example by double clicking on the Simulation Tool in /Applications/SBW (on OS X), or by launching ~/SBW/Simulation Tool … or if the SBW/bin is in the path by starting sbw_simultool.

Screen shot 2010-08-05 at 2.48.26 PM 

if you test it with ‘oscli.xml’ you see this:

Screen shot 2010-08-05 at 2.49.05 PM

Thursday, August 5, 2010

Writing Plug-ins for the Simulation Tool – Part 3 – Setup – Command Line

Command Line

for the command line compilation 1st ensure that you have mono installed (http://mono-project.com/Downloads) (or on windows .NET 3.5 has to be installed). Next download the project we created above:

https://sourceforge.net/downloads/sbwsimtool/mono-sample-project/v1/

once extracted you can compile those files from the command line using:

gmcs *.cs -r:3rdParty/Microsoft.ComponentModel.Composition.Diagnostics.dll -r:3rdParty/SimulationToolAPI.dll -r:3rdParty/System.ComponentModel.Composition.dll  -r:3rdParty/ZedGraph.dll  -r:System.Windows.Forms -r:System.Drawing -target:library -platform:x86 -out:SimulationToolPlugin1.dll

on mono or:

\Windows\Microsoft.NET\Framework\v3.5\csc.exe  -r:3rdParty/Microsoft.ComponentModel.Composition.Diagnostics.dll -r:3rdParty/SimulationToolAPI.dll -r:3rdParty/System.ComponentModel.Composition.dll  -r:3rdParty/ZedGraph.dll  -target:library -platform:x86 -out:SimulationToolPlugin1.dll *.cs

using microsofts compiler.

next you copy the resulting SimulationToolPlugin1.dll into the SBW directory:

~/SBW/lib on linux

/Applications/SBW/lib on OS X

c:\program files\KGI\SBW\roadrunner on win32 and

C:\Program Files (x86)\KGI\SBW\roadrunner on win64.

Now if you start the simulation tool you again should see the newly build plug-in in an unnamed category.

Writing Plug-ins for the Simulation Tool – Part 1 – Setup - Visual Studio

With the release 2.8.1 of the Systems Biology Workbench the Simulation Tool now has a plug-in system based on MEF. This enabled me to enhance the simulation tool by both new layouts (changing the look and feel) as well as include new Simulation Experiments (like the Signal Injection plug-in). But now that we have this new plug-in API it also allows Y O U to write for it. And I’m excited to see  Y O U R contributions. (I’m preparing a online repository for plug-ins). So how do you write these plug-ins? In this series I show you how to set up the IDE, so that you can start writing plug-ins, and then give a couple of examples of simple plug-ins one could write.

There are three ways that I envision people would write plug-ins:

  • using Visual Studio (2010 / 2008 / Express (free))
  • using MonoDevelop (http://monodevelop.com/)
  • using the command line (either on windows / posix)

Visual Studio

Visual Studio is my tool of choice when it comes to programming. Luckily most universities have contracts with microsoft, so ask your IT department for a copy (ours had 2010 Ultimate!). If they don’t you still have the option of getting a full version at dreamspark:

 https://www.dreamspark.com/

Or of course the express editions will work:

http://www.microsoft.com/express/Default.aspx.

In the following I use screenshots from Visual Studio 2010, but the same will apply to Visual Studio 2008 and Express editions.

In order to ease the process of writing plug-ins I have created Visual Studio Templates. You can download them from:

http://sourceforge.net/downloads/sbwsimtool/visual-studio-templates/v1

simply download the Zip files and place them into:

C:\Users\fbergmann\Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual C#

(just replace fbergmann with whatever your user name is). The same templates also work for Visual Studio 2008 where you place them into:

C:\Users\fbergmann\Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual C#

Once this is done start Visual Studio and create a new project. Now in the template wizard you can simply select the SimulationToolPlugin template:

Screen shot 2010-08-05 at 10.59.59 AM

Once you confirm the new project will be created and loaded. The code already implements a simple plug-in. So let us set up the properties, so that we can run it. For this go to

Project\SimulationTool1Plugin Properties

Screen shot 2010-08-05 at 11.05.23 AM

Here you want to change the ‘Assembly Information’ to provide a short description of your plug-in an set your Copyright information. Next you might want to change the Default Namespace and the Assembly Name. My recommendation is to use the same name for both. The Assembly Name controls what the name of the resulting .DLL will be.

Next let us flip to the Build tab:

Screen shot 2010-08-05 at 11.08.40 AM

The key  elements here are: The platform target: make sure to select x86 (as the simulation tool uses native libraries that are compiled for 32bit only). The output path:

you want to set this one *for now* to the directory of the Simulation Tool:

C:\Program Files (x86)\KGI\SBW\roadrunner

on 64-bit systems and:

C:\Program Files\KGI\SBW\roadrunner

on 32 bit systems.

Finally, let us set up how to start the debug session:

Screen shot 2010-08-05 at 11.15.02 AM

we want to start an external program:

C:\Program Files (x86)\KGI\SBW\roadrunner\SimDriverNET.exe or

C:\Program Files\KGI\SBW\roadrunner\SimDriverNET.exe

and we want to set the working directory to:

C:\Program Files (x86)\KGI\SBW\roadrunner or

C:\Program Files\KGI\SBW\roadrunner

(One note for express users: you won’t be able to start an external program in the express edition … I suggest you choose a Post Build Event to start the SimDriverNET executable by adding:

cd C:\Program Files\KGI\SBW\roadrunner && SimDriverNET.exe

as post build event now after every build you see the simdriver loaded with the new plugin, alas no debugging support.)

THAT IS IT … now we are ready to test our plug-in! close the property tab and press RUN. Our new plug-in is in an unnamed category so you can easily find it:

Screen shot 2010-08-05 at 11.19.33 AM

And when you load a model you can perform time course scans by entering values into it. Here a screenshot for the ‘oscli.xml’ file:

Screen shot 2010-08-05 at 11.25.20 AM

This is it you are all set up and ready to play with the plug-in. 

Saturday, July 31, 2010

Systems Biology Workbench (SBW) 2.8.1 Released

We are pleased to announce the a release of the Systems Biology Workbench 2.8.1, available from:

http://sys-bio.org

The Systems Biology Workbench (SBW), is a software framework that allows heterogeneous application components-written in diverse programming languages and running on different platforms – to communicate and use each others' capabilities via a fast binary encoded-message system. Our goal was to create a simple, high performance, open-source software infrastructure which is easy to implement and understand. SBW enables applications (potentially running on separate, distributed computers) to communicate via a simple network protocol.

The interfaces to the system are encapsulated in client-side libraries that we provide for different programming languages.

There are a number of significant changes in this release:

  1. The SBW Simulation Tool has been largely rewritten to allow for a variety of interactive simulation experiments. Thanks to a new plug-in mechanism it is easy to extend the Simulation Tool.
  2. The script based modeling tool JarnacLite has been enhanced to make it easier to select Kinetic Laws to use.
  3. RoadRunner now supports SBML Level 3 (with the same restrictions that applied to Level 2, i.e.: no algebraic rules, no delays, no fast flag).
  4. Numerous bug fixes and usability improvements (such as a favorites menu bar, that allows to quickly edit / simulate SBML models in most applications).

For a full list of changes see: http://sys-bio.org/changelog.

With SBW 2.8.1 we have a new full release, with binaries for Windows, OSX (10.6) and Linux (tested with openSUSE 10.2 and Ubuntu Lucid). We are well aware that there are many more platforms available out there and regret not having the manpower to provide binaries for additional platforms. For this reason we have created a set of Virtual Machine (VMware/VirtualBox & Xen), hard drive image,  and Live CD image (running openSUSE 11.2). For all of these the username is ‘sbw’ and password is ‘linux’.

For a list of modules included with the Systems Biology Workbench and a description of what they do please have a look at

http://jdesigner.sourceforge.net/

More details can also be found on my blog at:

http://frank-fbergmann.blogspot.com/

In case you are interested in instruction in how to use the Systems Biology Workbench join our tutorial at this year's ICSB.

As always we appreciate any feedback from users send to:

sbwteam@gmail.com

Friday, July 30, 2010

The SBW Simulation Tool – Part 4 – Parameter Scanning

It was always a bit cumbersome to perform parameter scans with our tools. Thus, with the new release of SBW a new plug-in was written that makes performing 1 or 2d parameter scans a snap. Be it steady state, or time course scans it should be easy to do. We support ranges (varying a parameter from a min to a max value in a number of steps), logarithmic ranges, or even just entering of specific parameter values to be used.

In order to be able to plot the scan results we interface with Gnuplot and allow users to tweak the gnuplot scripts. Resulting figures can then be exported as PDF or image.

Below a demonstration of the feature:

As you can see towards the end instead of just the floating species a wealth of output options is available.

The SBW Simulation Tool – Part 2 – Signal Injection

The new simulation tool also comes with a couple of new interactive simulation experiments. The first one to be described here is the Signal injection plug-in as seen below.

It couldn’t be simpler to use. Simply load the model you want to experiment with, click the ‘add signal’ button, and choose parameter and signal type. Immediately the signal will be displayed in the graphing window and can be moved about with the mouse allowing you to directly see the influence this has.

For the sine  (or square wave) signal type it is possible to change the angular frequency by holding down the CTRL key and moving the mouse.

Here a video demonstrating this feature:

Thursday, April 29, 2010

RoadRunner & Java (!?)

Darren Wilkinson is here this week early for the Hackathon this weekend. One of his projects is CaliBayes, which addresses the issue of estimating  parameters of kinetic laws. CaliBayes uses Java, and until now using RoadRunner required to go through the SBW Java bindings, to the SBW Broker to RoadRunner. It seems apparent, that this won’t deliver the best possible performance.

A couple of weeks ago I first dabbled in embedding the mono runtime for use of RoadRunner in C++. So it seemed clear, that this could be extended to the JNI world.

A prototype was quickly written and tested on OSX (10.6, using a 32bit JVM) and verified to work on Ubuntu 9.10 (32 bit). So far the version is not working in 64bit Linux. Mainly because all our libraries are not yet available for 64bit. Oh well … but it is a start …

The Ubuntu version is now online on the source forge project, source code an all:

http://sourceforge.net/projects/roadrunner/files/

Saturday, February 13, 2010

RoadRunner & C++/CLI vs. Embedding the MONO Runtime

RoadRunner, our simulation main simulation engine in the Systems Biology Workbench, has been written in C#. This allows RoadRunner to be used in scripting scenarios with languages like IronPython, or even from the csharp-shell or Windows PowerShell. But what if you wanted to use RoadRunner from plain old C / C++?

C++ / CLI

On Windows operating systems the obvious choice would probably be C++/CLI.  And really, the task could not be easier. Just add the RoadRunner reference to the application include the RoadRunner namespace and you are good to go:

   1: // RoadRunnerCLI.cpp : main project file.



   2:  



   3: #include "stdafx.h"



   4:  



   5: using namespace System;



   6: using namespace CSharpSimulator;



   7:  



   8: static void PrintResult(cli::array<double, 2>^ data)



   9:     {



  10:         for (int i = 0; i < data->GetLength(0); i++)



  11:         {



  12:             for (int j = 0; j < data->GetLength(1); j++)



  13:             {



  14:                 Console::Write(data[i,j]);



  15:                 Console::Write("\t");



  16:             }



  17:             Console::WriteLine();



  18:         }



  19:     }



  20:  



  21: int main(array<System::String ^> ^args)



  22: {



  23:  



  24:     sbwInterface roadRunnerInstance;



  25:  



  26:     roadRunnerInstance.loadSBMLFromFile



  27:         (L"C:\\Users\\fbergmann\\Documents\\SBML Models\\BorisEJB.xml");



  28:     roadRunnerInstance.setTimeStart(0.0);



  29:     roadRunnerInstance.setTimeEnd(100.0);



  30:     roadRunnerInstance.setNumPoints(11);



  31:     



  32:     cli::array<double, 2>^ result = roadRunnerInstance.simulate();



  33:  



  34:     PrintResult(result);



  35:  



  36:     return 0;



  37: }




The only drawback would be that this will not work on Linux or OS X.



MONO Embedding



So what about MONO Embedding? Or in other words, writing a C++ application, that would embed the MONO Runtime. This enables the C++ application to directly reference RoadRunner. The idea is basically the same as when using any SBW Module. First we get a hold of the RoadRunner module, or in this case an instance of the RoadRunner class:





   1: mono_set_dirs(NULL, NULL);



   2: domain = mono_jit_init ("LibRoadRunner.dll");



   3: mono_set_dirs(NULL, NULL);



   4: mono_config_parse(NULL);



   5: assembly = mono_domain_assembly_open (domain, "LibRoadRunner.dll");



   6: if (assembly == NULL)



   7:     cout << "Couldn't load RR assembly" << endl;



   8: image = mono_assembly_get_image (assembly);



   9: rr_class = mono_class_from_name (image, "CSharpSimulator", "sbwInterface");



  10: if (rr_class == NULL)



  11:     cout << "Couldn't get hold of the RoadRunner class" << endl;



  12:  



  13: // create new roadRunner instance



  14: rr_instance = mono_object_new (domain, rr_class);   



  15: // call constructor



  16: mono_runtime_object_init (rr_instance);




Next one would get hold of all the method one would like to call, as in:





   1: // get the loadSBML 



   2: methodLoadSBML = mono_class_get_method_from_name(rr_class, "loadSBML", -1);



   3: if (methodLoadSBML == NULL) 



   4:     cout << "Couldn't get loadSBML" << endl;



   5:     






finally for calling the method all that’s needed is to wrap the arguments into arguments that MONO would understand:





   1: void HostRR::LoadSBML(const char* model)



   2: {



   3:     MonoString *str = mono_string_new (domain, model);



   4:     void *args[1]; args[0] = str; 



   5:     MonoObject *exception = NULL;



   6:     mono_runtime_invoke(methodLoadSBML, rr_instance, args, &exception);



   7:     if (exception != NULL)



   8:     {



   9:         PrintException("Error while loading SBML", exception);



  10:     }



  11: }






continuing like that for the remaining methods that have to be available for C++. For a client calling into RoadRunner the result would look like this:





   1: #include "HostRR.h"



   2: #include <iostream>



   3: #include <iomanip>



   4:  



   5: using namespace std;



   6:  



   7: void PrintResult(double** data, int numRows, int numCols)



   8: {



   9:     if (data == NULL) return;



  10:  



  11:     for (int y = 0; y < numRows; y++) 



  12:     {



  13:         for (int x = 0; x < numCols; x++) 



  14:         {



  15:             cout << setiosflags(ios::fixed) 



  16:                  << setw(7) << setprecision(2) << setfill(' ') 



  17:                  <<  data[y][x] << "\t";



  18:         }



  19:         cout << endl;



  20:     }



  21:     cout << endl;



  22: }



  23:  



  24: int main(int argc, char* argv[])



  25: {



  26:     HostRR instance;



  27:     



  28:     instance.LoadSBMLFromFile("BorisEJB.xml");



  29:  



  30:     instance.SetTimeStart(0.0);



  31:     instance.SetTimeEnd(1100.0);



  32:     instance.SetNumPoints(100);



  33:     



  34:     int numRows; int numCols;



  35:     double** result = instance.Simulate(&numRows,&numCols);



  36:     



  37:     PrintResult(result, numRows, numCols);



  38:     



  39:     return 0;



  40: }






And the advantage? It runs like a charm on Linux and OS X. However I did struggle a bit with getting it compiled. After all one draws several dependencies when embedding mono, the most troublesome for me proved to be glib2 and OS X. At the end the problem turned out to be that Snow Leopard liked the executable to be 64bit by default, but the glib libraries were only available for 32bit and ppc. Since I have Qt installed on all my systems, I used a qmake project, to generate the make files (or Xcode projects as the case may be). So here is what worked for me:





   1:  



   2: TEMPLATE = app



   3: CONFIG = console



   4: TARGET = HostRR



   5: DEPENDPATH += .



   6: INCLUDEPATH += . 



   7:  



   8: mac { 



   9: CONFIG += x86 



  10: CFLAGS += -arch i386



  11: INCLUDEPATH += /Library/Frameworks/Mono.framework/Versions/2.6.1/include/mono-1.0 /sw/include/glib-2.0 /sw/lib/glib-2.0/include



  12: LIBS += -L/Library/Frameworks/Mono.framework/Versions/2.6.1/lib -L/sw/lib -pthread -lmono -lpthread -lm -lgthread-2.0 -lglib-2.0 -lintl



  13: }



  14:  



  15: unix { 



  16: DEFINES +=_REENTRANT -pthread 



  17: INCLUDEPATH += /usr/include/mono-1.0 /usr/include/glib-2.0 /usr/lib/glib-2.0/include



  18: LIBS += -Wl,--export-dynamic -pthread -lmono -ldl -lpthread -lm -lgthread-2.0 -lrt -lglib-2.0 



  19: }



  20:  



  21: win32 {



  22: INCLUDEPATH += "C:\Program Files (x86)\Mono-2.6\include\glib-2.0"  "C:\Program Files (x86)\Mono-2.6\lib\glib-2.0\include" "C:\Program Files (x86)\Mono-2.6\include\mono-1.0"



  23: LIBS +=  -L"." -lmono



  24: }



  25:  



  26: # Input



  27: HEADERS += HostRR.h



  28: SOURCES += HostRR.cpp main.cpp



  29:  




If you’d like to give it a try, I’ve posted all the source to sourceforge. The results are right here:



http://jdesigner.svn.sourceforge.net/viewvc/jdesigner/trunk/csharp/HostRR/



Conclusions



We’ve seen, that accessing a .NET assembly from C/C++ is really no issue at all. C++/CLI is a great language it provides access to all of the .NET framework in a snap, however it will lock you in to the Windows world. With MONO Embedding, it is easy to break out! Given the reflection capabilities of .NET I believe the way to go forward would be to have a wrapper generator, that would just write the wrapper code.



Going forward if I were to use C++ to interact with RoadRunner, I’d probably combine the best of two worlds by falling back to C++/CLI on Windows systems and Mono embedding on Linux / OS X. But this might be a personal preference.