Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove function definitions #102

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ project(libantimony)
# Set up version information.
#
SET(LIBANTIMONY_VERSION_MAJOR 2)
SET(LIBANTIMONY_VERSION_MINOR 14)
SET(LIBANTIMONY_VERSION_MINOR 15)
SET(LIBANTIMONY_VERSION_PATCH ".0")
SET(LIBANTIMONY_VERSION_RELEASE "")

Expand Down
16 changes: 14 additions & 2 deletions src/antimony_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sbml/SBMLTypes.h>
#include <sbml/xml/XMLOutputStream.h>
#include <sbml/Model.h>
#include <sbml/conversion/SBMLFunctionDefinitionConverter.h>
#endif

#ifndef NCELLML
Expand Down Expand Up @@ -306,6 +307,12 @@ LIB_EXTERN long loadAntimonyFile(const char* filename)
#ifndef NSBML
void LoadSBML(SBMLDocument* doc)
{
if (g_registry.GetRemoveFunctionDefinitions()) {
SBMLConverter* converter = new SBMLFunctionDefinitionConverter();
converter->setDocument(doc);
int cret = converter->convert();

}
#ifdef USE_COMP
string mainsbmlname = getNameFromSBMLObject(doc->getModel(), "doc");
CompSBMLDocumentPlugin* compdoc = static_cast<CompSBMLDocumentPlugin*>(doc->getPlugin("comp"));
Expand Down Expand Up @@ -556,16 +563,21 @@ LIB_EXTERN void clearPreviousLoads()
g_registry.ClearAll();
}

LIB_EXTERN void addDirectory(const char* directory)
LIB_EXTERN void addDirectory(const char* directory)
{
g_registry.AddDirectory(directory);
}

LIB_EXTERN void clearDirectories()
LIB_EXTERN void clearDirectories()
{
g_registry.ClearDirectories();
}

LIB_EXTERN void setRemoveFunctionDefinitions(bool removeFunctionDefinitions)
{
g_registry.SetRemoveFunctionDefinitions(removeFunctionDefinitions);
}

LIB_EXTERN char* getLastError()
{
return getCharStar((g_registry.GetError()).c_str());
Expand Down
12 changes: 12 additions & 0 deletions src/antimony_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ LIB_EXTERN long loadAntimonyString(const char* model);
* Loads a file and parses it (using libSBML) as an SBML file. On an error, the error is saved, -1 is returned, and no information is stored.
* @return a long integer indicating the index of the file read and stored. On an error, returns -1 and no information is stored.
* NOTE: This function is unavailable when libAntimony is compiled with the '-NSBML' flag.
* Also note that by default, function definitions are removed.
*
* @param filename The filename as a character string. May be either absolute or relative to the directory the executable is being run from.
*
* @see getLastError()
* @see setRemoveFunctionDefinitions()
*/
LIB_EXTERN long loadSBMLFile(const char* filename);

Expand All @@ -140,10 +142,12 @@ LIB_EXTERN long loadSBMLFile(const char* filename);
* Loads a string and parses it (using libSBML) as an SBML file. On an error, the error is saved, -1 is returned, and no information is stored.
* @return a long integer indicating the index of the string read and stored. On an error, returns -1 and no information is stored.
* NOTE: This function is unavailable when libAntimony is compiled with the '-NSBML' flag.
* Also note that by default, function definitions are removed.
*
* @param model The model, in SBML format.
*
* @see getLastError()
* @see setRemoveFunctionDefinitions()
*/
LIB_EXTERN long loadSBMLString(const char* model);

Expand All @@ -153,11 +157,13 @@ LIB_EXTERN long loadSBMLString(const char* model);
* Loads a string and parses it (using libSBML) as an SBML file. On an error, the error is saved, -1 is returned, and no information is stored. This function additionally allows you to set the location of the string, in case there are relative file references in the file (as there can be in some hierarchical models).
* @return a long integer indicating the index of the string read and stored. On an error, returns -1 and no information is stored.
* NOTE: This function is unavailable when libAntimony is compiled with the '-NSBML' flag.
* Also note that by default, function definitions are removed.
*
* @param model The model, in SBML format.
* @param location The location of the file (i.e. "file1.xml" or "/home/user/sbml/models/file.xml")
*
* @see getLastError()
* @see setRemoveFunctionDefinitions()
*/
LIB_EXTERN long loadSBMLStringWithLocation(const char* model, const char* location);
#endif
Expand Down Expand Up @@ -221,6 +227,12 @@ LIB_EXTERN void addDirectory(const char* directory);
*/
LIB_EXTERN void clearDirectories();

/**
* Sets whether to remove function definitions on import from SBML.
* By default, is set to 'true'.
*/
LIB_EXTERN void setRemoveFunctionDefinitions(bool removeFunctionDefinitions);


/** \} */

Expand Down
1 change: 1 addition & 0 deletions src/bindings/python/createAntimonyLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def parse_function(line, comment, functions):
args = []
for onearg in argvec:
onearg = onearg.strip()
onearg = onearg.replace(" = false", "")
if len(onearg)==0:
continue
lastspace = onearg.rfind(" ")
Expand Down
11 changes: 11 additions & 0 deletions src/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Registry::Registry()
m_writeTimestampToSBML(false),
m_bareNumbersAreDimensionless(false),
m_eof(false),
m_removeFunctionDefinitions(true),
input(NULL)
{
string main = MAINMODULE;
Expand Down Expand Up @@ -1450,6 +1451,16 @@ void Registry::FixTimeInFunctions()
}
}

void Registry::SetRemoveFunctionDefinitions(bool removeFunctionDefinitions)
{
m_removeFunctionDefinitions = removeFunctionDefinitions;
}

bool Registry::GetRemoveFunctionDefinitions()
{
return m_removeFunctionDefinitions;
}

bool Registry::ProcessGlobalCVTerm(const string* name, const string* qual, vector<string>* resources)
{
if (name && qual && resources) {
Expand Down
5 changes: 5 additions & 0 deletions src/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Registry
bool m_bareNumbersAreDimensionless;
bool m_eof;

bool m_removeFunctionDefinitions;

public:
Registry();
~Registry();
Expand Down Expand Up @@ -199,6 +201,9 @@ class Registry
UserFunction* GetUserFunction(std::string name);
void FixTimeInFunctions();

void SetRemoveFunctionDefinitions(bool removeFunctionDefinitions);
bool GetRemoveFunctionDefinitions();

// CV terms
bool ProcessGlobalCVTerm(const std::string* name, const std::string* qual, std::vector<std::string>* resources);

Expand Down
1 change: 1 addition & 0 deletions src/test/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ main (int argc, char* argv[])
{
int num_failed;
g_registry.SetWriteNameToSBML(false);
g_registry.SetRemoveFunctionDefinitions(false);

setTestDataDirectory();

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/BIOMD0000000118.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
function GAMMA(VV, theta, sigma)
1/(1 + exp(-(VV - theta)/sigma));
end
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/BIOMD0000000696.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model *Boada2016___Incoherent_type_1_feed_forward_loop__I1_FFL()

// Compartments and Species:
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/SBO_compartment_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Compartments and Species:
compartment a;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/SBO_event_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Events:
E0: at time > 3: b = 4;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/SBO_function_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
function foo()
3;
end
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/SBO_localvar_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model *foo()

// Variable initializations:
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/SBO_module_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model *foo()
end

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/SBO_param2_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Variable initializations:
a = 3;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/SBO_param_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Variable initializations:
a = ;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/SBO_reaction_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Compartments and Species:
species A;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/SBO_species_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Compartments and Species:
species a;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/SBO_submodel_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model foo()
end

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/SBO_submodel_shadowed_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model foo()

// Variable initializations:
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/algrule_id_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Algebraic Rules:
alg1: 0 = x - 2;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/algrule_idname_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Algebraic Rules:
alg1: 0 = x - 2;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/algrule_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Algebraic Rules:
_alg0: 0 = x - 2;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/autopromoted_units_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model foo(p)

// Variable initializations:
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/coefficientOfVariation_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Variable initializations:
a = ;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/confidenceInterval_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Variable initializations:
a = ;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/created_element_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Variable initializations:
a = 3;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/created_model_parts_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model *foo()

// Variable initializations:
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/created_model_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model *foo()

// Variable initializations:
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/creator_blank_model_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model *foo()

// Variable initializations:
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/creator_one_element_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Variable initializations:
a = 3;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/creator_one_model_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model *foo()

// Variable initializations:
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/creator_two_model_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model *foo()

// Variable initializations:
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/credibleInterval_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Variable initializations:
a = ;
x = ;
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/default_compartment.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model *def_comp()

// Compartments and Species:
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/distribution_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Variable initializations:
a = ;
x = ;
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/encodes_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Variable initializations:
a = 3;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/externalParameter1_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Variable initializations:
a = ;

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/externalParameter2_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Variable initializations:
a = ;
x = ;
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/externalParameter3_rt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
// Variable initializations:
a = ;
x = ;
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/from-libsbml/CompTest.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0

// Warnings from automatic translation:
// Unable to create port constraint__constraint0 in model CompModel because Constraint elements do not have IDs in SBML, and therefore cannot be made into ports in Antimony.
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/from-libsbml/QTPop.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
function get2DArrayElement(a, b, c)
a;
end
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/from-libsbml/comp.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model moddef1()

// Compartments and Species:
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-data/from-libsbml/exchangetest.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0
model *testmod()

// Compartments and Species:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created by libAntimony v2.14.0
// Created by libAntimony v2.15.0

// Warnings from automatic translation:
// Unable to create port rule__iBioSim7 in model CompModel because RateRule elements only exist as part of other Antimony elements, and do not function as their own separate entities which may be flagged as a port.
Expand Down
Loading
Loading