Skip to content

Commit

Permalink
- added basic Java API and example for it
Browse files Browse the repository at this point in the history
- reconsidered on what functions to expose
  • Loading branch information
fbergmann committed Mar 11, 2013
1 parent f78baba commit e77fb44
Show file tree
Hide file tree
Showing 17 changed files with 952 additions and 9 deletions.
59 changes: 57 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,53 @@ find_path(LIBSBML_INCLUDE_DIR
)


###############################################################################
#
# Need some variables set up, such as the name for the libSBML
# library and the Path and file separator characters. The
# MISC_PREFIX variable will cause libsbml bindings, examples and
# documentation to be installed in PREFIX/${MISC_PREFIX}.
#

if(UNIX OR CYGWIN)
set(PATH_SEP "/")
set(FILE_SEP ":")
else()
set(PATH_SEP "\\")
set(FILE_SEP ";")
endif()

set(EXTRA_LIBS "" CACHE STRING "List of additional libraries to link against." )

option(WITH_CSHARP "Generate C# language bindings." OFF)
option(WITH_JAVA "Generate Java language bindings." OFF)


###############################################################################
#
# Find the C# compiler to use and set name for resulting library
#

if(WITH_CSHARP)
find_program(CSHARP_COMPILER
NAMES gmcs csc
PATHS C:/Windows/Microsoft.NET/Framework/v2.0.50727/ /usr/bin /usr/local/bin
DOC "The file name of the C# compiler."
)
if(UNIX)
else()
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
# mark libsbml library as x86
set(CSHARP_EXTRA_ARGS -platform:x86 )
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
# mark libsbml library as x64
set(CSHARP_EXTRA_ARGS -platform:x64 )
endif()
endif()

endif(WITH_CSHARP)


if(WIN32 AND NOT CYGWIN)
add_definitions(-DLIBSBML_EXPORTS -DWIN32)
if(MSVC)
Expand Down Expand Up @@ -107,9 +152,19 @@ message(STATUS
C FLAGS : ${CMAKE_C_FLAGS}
CXX FLAGS : ${CMAKE_CXX_FLAGS}
Extra Libs : ${EXTRA_LIBS}
Extra Libs : ${EXTRA_LIBS}
"""
)

if(WITH_CSHARP)
message(STATUS " Using C# = ${CSHARP_COMPILER}")
endif()

if(WITH_JAVA)
message(STATUS " Using Java = ${Java_JAVA_EXECUTABLE}")
endif()

add_subdirectory(bindings)


49 changes: 49 additions & 0 deletions SpatialSBML/spatialsimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,11 @@ void freeRInfo(vector<reactionInfo*> &rInfoList)
}
}

int SpatialSimulator::getVariableLength() const
{
return (Zindex -1) * Yindex * Xindex + (Yindex-1) * Xindex + Xindex-1;
}

void reversePolishRK(reactionInfo *&rInfo, variableInfo *&sInfo, int Xindex, int Yindex, int Zindex, double dt, int m, materialType mType, bool inVol, diffCInfo **dci)
{
int X, Y, Z, i;
Expand Down Expand Up @@ -1114,13 +1119,37 @@ Parameter* SpatialSimulator::getDiffusionCoefficientForSpecies(const std::string
return NULL;
}

SpatialSimulator::SpatialSimulator():
Xdiv(100), Ydiv(100), Zdiv(1), model(NULL), volDimension(0), memDimension(0)
{
}
void SpatialSimulator::initFromFile(const std::string &fileName, int xdim, int ydim, int zdim/*=1*/)
{
SBMLDocument*doc = readSBMLFromFile(fileName.c_str());
initFromModel(doc, xdim, ydim, zdim);
}
void SpatialSimulator::initFromString(const std::string &sbml, int xdim, int ydim, int zdim/*=1*/)
{
SBMLDocument*doc = readSBMLFromString(sbml.c_str());
initFromModel(doc, xdim, ydim, zdim);
}


SpatialSimulator::SpatialSimulator(SBMLDocument* doc, int xdim, int ydim, int zdim /*=1*/) :
Xdiv(xdim), Ydiv(ydim), Zdiv(zdim), model(NULL), volDimension(0), memDimension(0)
{
initFromModel(doc, xdim, ydim, zdim);
}

void SpatialSimulator::initFromModel(SBMLDocument* doc, int xdim, int ydim, int zdim/*=1*/)
{
unsigned int i, j, k;
int X = 0, Y = 0, Z = 0, index = 0;
int numOfASTNodes = 0;

Xdiv = xdim;
Ydiv = ydim;
Zdiv = zdim;

//sbml core
ASTNode *ast;
Expand Down Expand Up @@ -2627,6 +2656,11 @@ double* SpatialSimulator::getGeometry(const std::string &compartmentId, int &len
return info->isDomain;
}

int SpatialSimulator::getGeometryLength() const
{
return numOfVolIndexes;
}

boundaryType* SpatialSimulator::getBoundaryType(const std::string &compartmentId, int &length)
{
analyticVolInfo* info = searchAvolInfoByCompartment(avolInfoList, compartmentId.c_str());
Expand All @@ -2641,6 +2675,21 @@ int* SpatialSimulator::getBoundary(const std::string &compartmentId, int &length
return info->isBoundary;
}

double SpatialSimulator::getVariableAt(const std::string& variable, int x, int y, int z)
{
variableInfo *sInfo = searchInfoById(varInfoList, variable.c_str());
if (sInfo == NULL)
{
return 0.0;
}

int index = getIndexForPosition(x, y);
if (index == -1)
return 0.0;

return sInfo->value[index];
}

double* SpatialSimulator::getVariable(const std::string &speciesId, int &length)
{
variableInfo *sInfo = searchInfoById(varInfoList, speciesId.c_str());
Expand Down
39 changes: 33 additions & 6 deletions SpatialSBML/spatialsimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include <string>
#include <vector>

LIBSBML_CPP_NAMESPACE_BEGIN
#ifndef SWIG

LIBSBML_CPP_NAMESPACE_BEGIN
# endif
class SBMLDocument;
class Model;
class Species;
Expand All @@ -22,20 +24,28 @@ class ListOfCompartments;
class ListOfReactions;
class ListOfParameters;
class ListOfRules;

#ifndef SWIG
LIBSBML_CPP_NAMESPACE_END


typedef enum _boundaryType {
Xp = 0, Xm, Yp, Ym, Zp, Zm
} boundaryType;

# endif
#include "spatialstructs.h"


class SpatialSimulator
{
public:
SpatialSimulator(SBMLDocument* doc, int xdim, int ydim, int zdim=1);
SpatialSimulator();
void initFromFile(const std::string &fileName, int xdim, int ydim, int zdim=1);
void initFromString(const std::string &sbml, int xdim, int ydim, int zdim=1);
#ifndef SWIG
void initFromModel(SBMLDocument* doc, int xdim, int ydim, int zdim=1);
SpatialSimulator(SBMLDocument* doc, int xdim, int ydim, int zdim=1);
#endif
virtual ~SpatialSimulator();

void setGnuplotExecutable(const std::string &location);
Expand All @@ -49,31 +59,48 @@ class SpatialSimulator

void setParameterUniformly(const std::string &id, double value);
void setParameter(const std::string &id, double value);
void setParameterUniformly(variableInfo *species, double value);
int getIndexForPosition(double x, double y);
#ifndef SWIG
void setParameterUniformly(variableInfo *species, double value);
#endif
#ifndef SWIG
// return the values for the given variable (as 1d) flat array
double* getVariable(const std::string &speciesId, int &length);
double* getGeometry(const std::string &compartmentId, int &length);

boundaryType* getBoundaryType(const std::string &compartmentId, int &length);

int* getBoundary(const std::string &compartmentId, int &length);
double* getX(int &length);
double* getY(int &length);
double* getZ(int &length);
#endif

int getVariableLength() const;
int getGeometryLength() const;
int getXDim() const { return Xdiv;}
int getYDim() const { return Ydiv;}
int getZDim() const { return Zdiv;}

double getVariableAt(const std::string& variable, int x, int y, int z=0);

#ifndef SWIG


// for comparison allow the old stuff to run too
static int runOldMain(int argc, const char* argv[]);

const Model* getModel() const;

const Model* getModel() const;
void deleteValuesOutsideDomain(variableInfo *info );

#endif

void deleteValuesOutsideDomain(const std::string& id);

private:

#ifndef SWIG
Parameter* getDiffusionCoefficientForSpecies(const std::string& id, int index=0);

// prints all values from the current point;
Expand Down Expand Up @@ -125,7 +152,7 @@ class SpatialSimulator
ListOfReactions *lor ;
ListOfParameters *lop ;
ListOfRules *lorules ;

#endif
};

#endif //SPATIAL_SIMULATOR_H
1 change: 0 additions & 1 deletion SpatialSBML/spatialstructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using namespace std;
LIBSBML_CPP_NAMESPACE_USE;


typedef enum _materialTYpe {
reactants = 0, products
}materialType;
Expand Down
36 changes: 36 additions & 0 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
###############################################################################
#
# Description : CMake build script for spatialSBML language bindings
# Original author(s): Frank Bergmann <[email protected]>
# Organization : California Institute of Technology
#
###############################################################################

find_program(SWIG_EXECUTABLE
NAMES swig
PATHS
c:/swigwin-2.0.8
c:/swigwin-2.0.7
c:/swigwin-2.0.4
c:/swigwin-2.0.2
c:/swigwin-2.0.1
c:/swigwin-2.0.0
/usr/local/bin
/opt/local/bin
/usr/bin
DOC "The file name of the swig executable."
)
set(SWIG_EXTRA_ARGS)


#
# and build selected language bindings
#

if(WITH_CSHARP)
add_subdirectory(csharp)
endif()

if(WITH_JAVA)
add_subdirectory(java)
endif()
Loading

0 comments on commit e77fb44

Please sign in to comment.