diff --git a/src/writesbml.jl b/src/writesbml.jl index bd8dc5c9..c69fcbb3 100644 --- a/src/writesbml.jl +++ b/src/writesbml.jl @@ -1,9 +1,10 @@ -# Ideally we'd like to use level 3, version 2, but because of -# https://github.com/sbmlteam/libsbml/pull/235#issuecomment-1152491848 we have to match -# level/version of the fbc plugin. +# Level/Version for the document const WRITESBML_DEFAULT_LEVEL = 3 -const WRITESBML_DEFAULT_VERSION = 1 -const WRITESBML_DEFAULT_PKGVERSION = 2 +const WRITESBML_DEFAULT_VERSION = 2 +# Level/Version/Package version for the package +const WRITESBML_PKG_DEFAULT_LEVEL = 3 +const WRITESBML_PKG_DEFAULT_VERSION = 1 +const WRITESBML_PKG_DEFAULT_PKGVERSION = 2 function model_to_sbml!(doc::VPtr, mdl::Model)::VPtr # Create the model pointer @@ -151,9 +152,9 @@ function model_to_sbml!(doc::VPtr, mdl::Model)::VPtr sbml(:GeneProduct_create), VPtr, (Cuint, Cuint, Cuint), - WRITESBML_DEFAULT_LEVEL, - WRITESBML_DEFAULT_VERSION, - WRITESBML_DEFAULT_PKGVERSION, + WRITESBML_PKG_DEFAULT_LEVEL, + WRITESBML_PKG_DEFAULT_VERSION, + WRITESBML_PKG_DEFAULT_PKGVERSION, ) ccall(sbml(:GeneProduct_setId), Cint, (VPtr, Cstring), geneproduct_ptr, id) ccall( @@ -271,9 +272,6 @@ function model_to_sbml!(doc::VPtr, mdl::Model)::VPtr reaction_ptr, reaction.reversible, ) - # The fast attribute is mandatory in Level 3 Version 1, but it was removed in Level - # 3 Version 2. When missing, it is assumed to be false. - ccall(sbml(:Reaction_setFast), Cint, (VPtr, Cint), reaction_ptr, false) isnothing(reaction.name) || ccall( sbml(:Reaction_setName), Cint, @@ -363,9 +361,9 @@ function model_to_sbml!(doc::VPtr, mdl::Model)::VPtr sbml(:Objective_create), VPtr, (Cuint, Cuint, Cuint), - WRITESBML_DEFAULT_LEVEL, - WRITESBML_DEFAULT_VERSION, - WRITESBML_DEFAULT_PKGVERSION, + WRITESBML_PKG_DEFAULT_LEVEL, + WRITESBML_PKG_DEFAULT_VERSION, + WRITESBML_PKG_DEFAULT_PKGVERSION, ) ccall(sbml(:Objective_setId), Cint, (VPtr, Cstring), objective_ptr, id) ccall( @@ -380,9 +378,9 @@ function model_to_sbml!(doc::VPtr, mdl::Model)::VPtr sbml(:FluxObjective_create), VPtr, (Cuint, Cuint, Cuint), - WRITESBML_DEFAULT_LEVEL, - WRITESBML_DEFAULT_VERSION, - WRITESBML_DEFAULT_PKGVERSION, + WRITESBML_PKG_DEFAULT_LEVEL, + WRITESBML_PKG_DEFAULT_VERSION, + WRITESBML_PKG_DEFAULT_PKGVERSION, ) ccall( sbml(:FluxObjective_setReaction), @@ -723,8 +721,39 @@ function _create_doc(mdl::Model)::VPtr WRITESBML_DEFAULT_VERSION, ) else + # Get fbc registry entry + sbmlext = ccall( + sbml(:SBMLExtensionRegistry_getExtension), + VPtr, + (Cstring,), + "fbc", + ) + # create the sbml namespaces object with fbc + fbc = ccall( + sbml(:XMLNamespaces_create), + VPtr, + (), + ) + # create the sbml namespaces object with fbc + uri = ccall( + sbml(:SBMLExtension_getURI), + Cstring, + (VPtr, Cuint, Cuint, Cuint), + sbmlext, + WRITESBML_PKG_DEFAULT_LEVEL, + WRITESBML_PKG_DEFAULT_VERSION, + WRITESBML_PKG_DEFAULT_PKGVERSION, + ) + ccall( + sbml(:XMLNamespaces_add), + Cint, + (VPtr, Cstring, Cstring), + fbc, + uri, + "fbc", + ) # Create SBML namespace with fbc package - ns = ccall( + sbmlns = ccall( sbml(:SBMLNamespaces_create), VPtr, (Cuint, Cuint), @@ -732,16 +761,14 @@ function _create_doc(mdl::Model)::VPtr WRITESBML_DEFAULT_VERSION, ) ccall( - sbml(:SBMLNamespaces_addPackageNamespace), + sbml(:SBMLNamespaces_addPackageNamespaces), Cint, - (VPtr, Cstring, Cuint, Cstring), - ns, - "fbc", - WRITESBML_DEFAULT_PKGVERSION, - "", + (VPtr, VPtr), + sbmlns, + fbc, ) # Create document from SBML namespace - d = ccall(sbml(:SBMLDocument_createWithSBMLNamespaces), VPtr, (VPtr,), ns) + d = ccall(sbml(:SBMLDocument_createWithSBMLNamespaces), VPtr, (VPtr,), sbmlns) # Do not require fbc package ccall( sbml(:SBMLDocument_setPackageRequired), diff --git a/test/data/Dasgupta2020-written.xml b/test/data/Dasgupta2020-written.xml index 9b1f1114..682636c1 100644 --- a/test/data/Dasgupta2020-written.xml +++ b/test/data/Dasgupta2020-written.xml @@ -1,5 +1,5 @@ - + @@ -50,14 +50,12 @@ response to activation both in 2D and in 3D

- - Tiwari - Krishna - - tiwarik@babraham.ac.uk - - Babraham Institute - + + Tiwari + Krishna + + tiwarik@babraham.ac.uk + Babraham Institute @@ -412,32 +410,32 @@ response to activation both in 2D and in 3D

- + - + - + - + - + - +