Skip to content

Commit

Permalink
current version
Browse files Browse the repository at this point in the history
  • Loading branch information
skeating committed Sep 17, 2024
1 parent c19d5b0 commit 9370f2b
Show file tree
Hide file tree
Showing 11 changed files with 1,112 additions and 998 deletions.
1,596 changes: 808 additions & 788 deletions src/sbml/conversion/ExpressionAnalyser.cpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/sbml/conversion/ExpressionAnalyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ typedef enum
|*/
struct SubstitutionValues_t {
std::string k_value;
double k_real_value;
std::string x_value;
std::string y_value;
ASTNode * dxdt_expression;
Expand Down Expand Up @@ -223,7 +224,7 @@ class LIBSBML_EXTERN ExpressionAnalyser
* @param node the node to check
* @return true if the node is a constant number/parameter
*/
bool isNumericalConstantOrConstantParameter(ASTNode* node);
bool isNumericalConstantOrConstantParameter(ASTNode* node, bool& isNumber);

/*
* Have we already created a parameter for this expression
Expand Down
5 changes: 3 additions & 2 deletions src/sbml/conversion/SBMLRateRuleConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,8 @@ SBMLRateRuleConverter::determineDerivativeSign(std::string variable, ASTNode* te
}
else
{
ASTNode *deriv = term->derivative(variable);
ASTNode* deriv = term->derivative(variable);

signDetermined = isPositive(deriv, posDeriv);
if (!signDetermined)
{
Expand Down Expand Up @@ -617,7 +618,7 @@ SBMLRateRuleConverter::isPositive(const ASTNode* node, bool& posDeriv)
}
else
{
if (mDerivSign == NEGATIVE_DERIVATIVE) posDeriv = true;
if (mDerivSign == NEGATIVE_DERIVATIVE) posDeriv = false;
}
signDetermined = true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/sbml/conversion/SBMLRateRuleConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#include <sbml/conversion/SBMLConverter.h>
#include <sbml/conversion/SBMLConverterRegister.h>
#include <sbml/math/ASTNode.h>
#include <iostream>

typedef enum
{
Expand All @@ -74,6 +75,7 @@ typedef enum


LIBSBML_CPP_NAMESPACE_BEGIN

typedef std::vector< std::pair< std::string, ASTNode*> > pairODEs;

class LIBSBML_EXTERN SBMLRateRuleConverter : public SBMLConverter
Expand Down
105 changes: 99 additions & 6 deletions src/sbml/conversion/test/TestSBMLRateRuleConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,98 @@ START_TEST(test_model_valid_52)
}
END_TEST

START_TEST(test_model_valid_53)
{
ConversionProperties props;
props.addOption("inferReactions", true);

SBMLConverter* converter = new SBMLRateRuleConverter();
converter->setProperties(&props);

std::string filename(TestDataDirectory);
filename += "valid_53_rr.xml";
std::string filename1(TestDataDirectory);
filename1 += "valid_53_bio.xml";

SBMLDocument* d = readSBMLFromFile(filename.c_str());

converter->setDocument(d);
fail_unless(converter->convert() == LIBSBML_OPERATION_SUCCESS);

SBMLDocument* d1 = readSBMLFromFile(filename1.c_str());
std::string out = writeSBMLToStdString(d);
std::string expected = writeSBMLToStdString(d1);

fail_unless(equals(expected.c_str(), out.c_str()));

delete converter;
delete d;
delete d1;
}
END_TEST

START_TEST(test_model_valid_54)
{
ConversionProperties props;
props.addOption("inferReactions", true);

SBMLConverter* converter = new SBMLRateRuleConverter();
converter->setProperties(&props);

std::string filename(TestDataDirectory);
filename += "valid_54_rr.xml";
std::string filename1(TestDataDirectory);
filename1 += "valid_54_bio.xml";

SBMLDocument* d = readSBMLFromFile(filename.c_str());

converter->setDocument(d);
fail_unless(converter->convert() == LIBSBML_OPERATION_SUCCESS);

SBMLDocument* d1 = readSBMLFromFile(filename1.c_str());
std::string out = writeSBMLToStdString(d);
std::string expected = writeSBMLToStdString(d1);

fail_unless(equals(expected.c_str(), out.c_str()));

delete converter;
delete d;
delete d1;
}
END_TEST


START_TEST(test_model_valid_55)
{
ConversionProperties props;
props.addOption("inferReactions", true);

SBMLConverter* converter = new SBMLRateRuleConverter();
converter->setProperties(&props);

std::string filename(TestDataDirectory);
filename += "valid_55_rr.xml";
std::string filename1(TestDataDirectory);
filename1 += "valid_55_bio.xml";

SBMLDocument* d = readSBMLFromFile(filename.c_str());

converter->setDocument(d);
fail_unless(converter->convert() == LIBSBML_OPERATION_SUCCESS);

SBMLDocument* d1 = readSBMLFromFile(filename1.c_str());
std::string out = writeSBMLToStdString(d);
std::string expected = writeSBMLToStdString(d1);

fail_unless(equals(expected.c_str(), out.c_str()));

delete converter;
delete d;
delete d1;
}
END_TEST


Suite *
create_suite_TestSBMLRateRuleConverter (void)
{
Expand All @@ -955,15 +1047,16 @@ create_suite_TestSBMLRateRuleConverter (void)
// tcase_add_test(tcase, test_model4);
// tcase_add_test(tcase, test_model5);
// tcase_add_test(tcase, test_model6);
// tcase_add_test(tcase, test_model_valid_01); // this one works
// tcase_add_test(tcase, test_model_valid_01); // this one works
// tcase_add_test(tcase, test_model_valid_02); // this one works
// tcase_add_test(tcase, test_model_valid_03); // this one replaces the kinetic law'b' with the assignment rule for b
// tcase_add_test(tcase, test_model_valid_03); // this one replaces the kinetic law'b' with the assignment rule for b
// tcase_add_test(tcase, test_model_valid_04); // this one works
tcase_add_test(tcase, test_model_valid_05); // this one works
//tcase_add_test(tcase, test_model_valid_51); // this one works although puts the kinetic law in a different order
// tcase_add_test(tcase, test_model_valid_05); // this one works
// tcase_add_test(tcase, test_model_valid_51); // this one works
// tcase_add_test(tcase, test_model_valid_52); // this one works although puts the kinetic law in a different order


// tcase_add_test(tcase, test_model_valid_53); // this one has hidden species that I'm not picked up
//tcase_add_test(tcase, test_model_valid_54); //
tcase_add_test(tcase, test_model_valid_55); //

suite_add_tcase(suite, tcase);

Expand Down
Loading

0 comments on commit 9370f2b

Please sign in to comment.