GithubHelp home page GithubHelp logo

copasi / copasi.js Goto Github PK

View Code? Open in Web Editor NEW
1.0 5.0 0.0 812 KB

Emscripten COPASI Javascript Bindings

Home Page: https://copasijs.readthedocs.io/en/latest/

License: BSD 2-Clause "Simplified" License

CMake 1.34% C++ 96.82% JavaScript 1.20% Shell 0.64%
copasi nodejs

copasi.js's Introduction

COPASI.js

This project hosts a wrapper for the COPASI API used primarily for running simulations and steady state analysis of SBML/COPASI models.

Main use of this project is as JavaScript wrapper of the simulation API. For that we use Emscripten.

Using from node.js

The API is wrapped in the copasi.js file. So after loading the wasm module, you pass the module to the constructor of the COPASI class:

var createApi = require('./copasijs.js');
var COPASI = require('./copasi.js');
var fs = require("fs");

createApi().then((Module) => {

    // instantiate COPASI simulator
    var instance = new COPASI(Module);

    // check version
    console.log('Using COPASI: ', instance.version);

    // load a local file using the filesystem 
    var data = fs.readFileSync(process.argv[2], 'utf8');

    // print model structure
    console.log(instance.loadModel(data));
    
    // simulate the model
    console.log(instance.simulateEx(0, 10, 11));
  
});

Download Release

You could just take one of the release archives directly from the releases page. There are three different kind of archives:

  • copasijs-node.zip for use with nodejs
  • copasijs-web-single.zip that is compiled only to javascript for the WEB environment
  • copasijs-web.zip containing js + wasm file

Alternatively, you can build using the instructions below.

Emscripten build

To build from a clone we use the following (ensuring that you first have initialized the Emscripten sdk):

dependencies

curl -L -O http://downloads.sourceforge.net/libuuid/libuuid-1.0.3.tar.gz 
tar -zxf libuuid-1.0.3.tar.gz
cd libuuid-1.0.3
emconfigure ./configure --prefix=$PWD/../em-dependencies --disable-dependency-tracking --with-pic --enable-static=yes --enable-shared=no CFLAGS='-fPIC'
emmake make
emmake make install
cd ..
rm em-dependencies/lib/libuuid.la*

git clone https://github.com/copasi/copasi-dependencies
emcmake cmake -G Ninja -B em-build-dependencies -S copasi-dependencies \
  -DCMAKE_INSTALL_PREFIX=em-dependencies \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_UI_DEPS=OFF \
  -DBUILD_zlib=ON \
  -DBUILD_archive=OFF \
  -DBUILD_NativeJIT=OFF \
  -DBUILD_clapack=ON \
  -DCMAKE_PREFIX_PATH=em-dependencies
cmake --build em-build-dependencies --config=Release

git clone https://github.com/copasi/COPASI
cd COPASI && gitTools/UpdateCopasiVersion --force && cd ..
cd COPASI && git checkout release/Version-4.43 && cd ..

cp COPASI/copasi/lapack/f2c.h em-dependencies/include 
cp COPASI/copasi/lapack/blaswrap.h em-dependencies/include

emcmake cmake -G Ninja -B em-build-copasi -S COPASI \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_GUI=OFF \
  -DENABLE_JIT:BOOL=OFF \
  -DDATAVALUE_NEEDS_SIZE_T_MEMBERS=1 \
  -DCOPASI_INSTALL_C_API=ON \
  -DCMAKE_INSTALL_PREFIX=em-dependencies \
  -DCOPASI_DEPENDENCY_DIR=em-dependencies \
  -DCMAKE_PREFIX_PATH=em-dependencies \
  -DDISABLE_STACK_PROTECTOR=ON \
  -DF2C_INTEGER=int \
  -DF2C_LOGICAL=int

cmake --build em-build-copasi --config=Release
cmake --install em-build-copasi --config=Release

JavaScript Library

git clone https://github.com/copasi/COPASI.js.git
emcmake cmake -DCOPASIJS_DEPENDENCY_DIR=em-dependencies -S COPASI.js -B em-build-copasijs -DCMAKE_INSTALL_PREFIX=bin-js
cmake --build em-build-copasijs --config=Release
cmake --install em-build-copasijs --config=Release

Now that the files are in bin-js, we can run test programs with for example nodejs:

cp COPASI.js/test/load_and_simulate.js bin-js
cd bin-js
node load_and_simulate.js COPASI.js/example_files/oscli.xml

Dependencies

This project requires:

Building the standalone library

The best way to set this up, is to just install the COPASI dependencies first into a dependency directory, then compile the COPASISE library, and install it also into that directory. The code below can be used to test the library standalone on any system:

git clone https://github.com/copasi/copasi-dependencies
cmake -G Ninja -B build-dependencies -S copasi-dependencies \
  -DCMAKE_INSTALL_PREFIX=dependencies \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_UI_DEPS=OFF \
  -DBUILD_zlib=ON \
  -DBUILD_archive=OFF \
  -DBUILD_NativeJIT=OFF \
  -DBUILD_clapack=ON
cmake --build build-dependencies --config=Release


git clone https://github.com/copasi/COPASI
cd COPASI && gitTools/UpdateCopasiVersion --force && cd ..
cd COPASI && git checkout release/Version-4.43 && cd ..

cp COPASI/copasi/lapack/f2c.h dependencies/include 
cp COPASI/copasi/lapack/blaswrap.h dependencies/include

cmake -G Ninja -B build-copasi -S COPASI \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_GUI=OFF \
  -DENABLE_JIT:BOOL=OFF \
  -DDATAVALUE_NEEDS_SIZE_T_MEMBERS=0 \
  -DCOPASI_INSTALL_C_API=ON \
  -DCMAKE_INSTALL_PREFIX=dependencies \
  -DCOPASI_DEPENDENCY_DIR=dependencies \
  -DCMAKE_PREFIX_PATH=dependencies \
  -DF2C_INTEGER=int \
  -DF2C_LOGICAL=int

cmake --build build-copasi --config=Release
cmake --install build-copasi --config=Release

Testing

Once the dependencies are compiled as above and installed into dependencies, you can run the standalone test runner like so:

git clone https://github.com/copasi/COPASI.js.git
cmake -DCOPASIJS_DEPENDENCY_DIR=dependencies -S COPASI.js -B build-copasijs
cmake --build build-copasijs --config=Release
cd build-copasijs && ctest -V

copasi.js's People

Contributors

fbergmann avatar

Stargazers

Tung Nguyen avatar

Watchers

Brian Klahn avatar  avatar Stefan Hoops avatar Pedro Mendes avatar  avatar

copasi.js's Issues

Don't understand what reset() is doing

We don't understand what reset is doing. Does it reset just the initial conditions or does it reset parameters and initial conditions?

The reset in the original simapi only resets the initial conditions and doesn't touch the parameter values.

We have three reset calls:

reset() - only resets initial conditons
resetAll() - resent initial conditons and parameters
resetToOrigin() - resets everything back to the original loaded model

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.