Skip to content

Commit

Permalink
Update Fbc V3 package
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Sep 15, 2023
1 parent bee0af7 commit b3eb9c3
Show file tree
Hide file tree
Showing 8 changed files with 614 additions and 57 deletions.
10 changes: 10 additions & 0 deletions NEWS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ and converting models.
- Attributes of the ModelHistory can now be accessed from
const objects.

- The FBC V3 package has been updated to reflect the latest
specification. There are now optional attributes `fbc:reaction2`
on the FluxObjective and `fbc:variable2` on the
UserDefinedConstraintComponent.

* Bug fixes

- A bug converting / validating models with the 'comp' package
Expand All @@ -23,6 +28,11 @@ and converting models.

- A fix to the CMake Build system ensures that check for dependencies
is more robust. Thanks to first time contributor @adelhpour

- The type of the FBC V3 `coefficient` attribute on the
UserDefinedConstraintComponent has been corrected, it was mistakenly
a double before, now it has been corrected to be a SIdRef as
described in the specification.


====================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,17 +415,19 @@ START_TEST(test_FbcExtension_create_and_write_L3V1V3)
FluxObjective* fluxObjective = objective->createFluxObjective();
fluxObjective->setReaction("J0");
fluxObjective->setCoefficient(1);
fluxObjective->setVariableType("linear");
fluxObjective->setReaction2("J0");
fluxObjective->setVariableType("quadratic");

UserDefinedConstraint* userconstraint = mplugin->createUserDefinedConstraint();
userconstraint->setId("uc2");
userconstraint->setLowerBound("uc2lb");
userconstraint->setUpperBound("uc2ub");

UserDefinedConstraintComponent * udcc = userconstraint->createUserDefinedConstraintComponent();
udcc->setCoefficient(2);
udcc->setCoefficient("ucc1");
udcc->setVariable("Avar");
udcc->setVariableType("linear");
udcc->setVariableType("quadratic");
udcc->setVariable2("Avar2");

// check annotations on several types
FbcSBasePlugin* sbaseplugin = dynamic_cast<FbcSBasePlugin*>(compartment->getPlugin("fbc"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
</listOfKeyValuePairs>
</annotation>
<fbc:listOfFluxObjectives>
<fbc:fluxObjective fbc:reaction="J0" fbc:coefficient="1" fbc:variableType="linear"/>
<fbc:fluxObjective fbc:reaction="J0" fbc:coefficient="1" fbc:variableType="quadratic" fbc:reaction2="J0"/>
</fbc:listOfFluxObjectives>
</fbc:objective>
</fbc:listOfObjectives>
<fbc:listOfUserDefinedConstraints>
<fbc:userDefinedConstraint fbc:id="uc2" fbc:lowerBound="uc2lb" fbc:upperBound="uc2ub">
<fbc:listOfUserDefinedConstraintComponents>
<fbc:userDefinedConstraintComponent fbc:coefficient="2" fbc:variable="Avar" fbc:variableType="linear"/>
<fbc:userDefinedConstraintComponent fbc:coefficient="ucc1" fbc:variable="Avar" fbc:variableType="quadratic" fbc:variable2="Avar2"/>
</fbc:listOfUserDefinedConstraintComponents>
</fbc:userDefinedConstraint>
</fbc:listOfUserDefinedConstraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<fbc:listOfObjectives fbc:activeObjective="obj1">
<fbc:objective fbc:id="obj1" fbc:type="maximize">
<fbc:listOfFluxes>
<fbc:fluxObjective fbc:reaction="J8" fbc:coefficient="1" fbc:variableType="linear"/>
<fbc:fluxObjective fbc:reaction="J8" fbc:coefficient="1" fbc:variableType="quadratic" fbc:reaction2="J8"/>
</fbc:listOfFluxes>
</fbc:objective>
</fbc:listOfObjectives>
Expand Down
128 changes: 126 additions & 2 deletions src/sbml/packages/fbc/sbml/FluxObjective.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ FluxObjective::FluxObjective (unsigned int level, unsigned int version, unsigned
, mCoefficient (numeric_limits<double>::quiet_NaN())
, mIsSetCoefficient (false)
, mVariableType (FBC_VARIABLE_TYPE_INVALID)
, mReaction2 ("")
{
// set an SBMLNamespaces derived object of this package
setSBMLNamespacesAndOwn(new FbcPkgNamespaces(level, version, pkgVersion));
Expand All @@ -86,6 +87,7 @@ FluxObjective::FluxObjective (FbcPkgNamespaces* fbcns)
, mCoefficient (numeric_limits<double>::quiet_NaN())
, mIsSetCoefficient (false)
, mVariableType (FBC_VARIABLE_TYPE_INVALID)
, mReaction2 ("")
{
// set the element namespace of this object
setElementNamespace(fbcns->getURI());
Expand All @@ -104,6 +106,7 @@ FluxObjective::FluxObjective(const FluxObjective& orig)
, mCoefficient ( orig.mCoefficient )
, mIsSetCoefficient ( orig.mIsSetCoefficient )
, mVariableType ( orig.mVariableType )
, mReaction2 (orig.mReaction2)
{
}

Expand All @@ -123,6 +126,7 @@ FluxObjective::operator=(const FluxObjective& rhs)
mCoefficient = rhs.mCoefficient;
mIsSetCoefficient = rhs.mIsSetCoefficient;
mVariableType = rhs.mVariableType;
mReaction2 = rhs.mReaction2;
}
return *this;
}
Expand Down Expand Up @@ -176,6 +180,16 @@ FluxObjective::getReaction() const
}


/*
* Returns the value of the "reaction2" attribute of this FluxObjective.
*/
const std::string&
FluxObjective::getReaction2() const
{
return mReaction2;
}


/*
* Returns the value of the "coefficient" attribute of this FluxObjective.
*/
Expand Down Expand Up @@ -238,6 +252,16 @@ FluxObjective::isSetReaction() const
}


/*
* Predicate returning @c true if this FluxObjective's "reaction2" attribute is
* set.
*/
bool
FluxObjective::isSetReaction2() const
{
return (mReaction2.empty() == false);
}

/*
* Predicate returning @c true if this FluxObjective's "coefficient" attribute
* is set.
Expand Down Expand Up @@ -287,7 +311,17 @@ FluxObjective::setName(const std::string& name)
int
FluxObjective::setReaction(const std::string& reaction)
{
return SyntaxChecker::checkAndSetSId(reaction ,mReaction);
return SyntaxChecker::checkAndSetSId(reaction, mReaction);
}


/*
* Sets reaction2 and returns value indicating success.
*/
int
FluxObjective::setReaction2(const std::string& reaction)
{
return SyntaxChecker::checkAndSetSId(reaction, mReaction2);
}


Expand Down Expand Up @@ -418,6 +452,25 @@ FluxObjective::unsetReaction()
}


/*
* Unsets reaction and returns value indicating success.
*/
int
FluxObjective::unsetReaction2()
{
mReaction2.erase();

if (mReaction2.empty() == true)
{
return LIBSBML_OPERATION_SUCCESS;
}
else
{
return LIBSBML_OPERATION_FAILED;
}
}


/*
* Unsets coefficient and returns value indicating success.
*/
Expand Down Expand Up @@ -460,6 +513,10 @@ FluxObjective::renameSIdRefs(const std::string& oldid, const std::string& newid)
{
setReaction(newid);
}
if (isSetReaction2() == true && mReaction2 == oldid)
{
setReaction2(newid);
}

}

Expand Down Expand Up @@ -697,7 +754,12 @@ FluxObjective::getAttribute(const std::string& attributeName,
value = getVariableTypeAsString();
return_value = LIBSBML_OPERATION_SUCCESS;
}

else if (attributeName == "reaction2")
{
value = getReaction2();
return_value = LIBSBML_OPERATION_SUCCESS;
}

return return_value;
}

Expand Down Expand Up @@ -736,6 +798,10 @@ FluxObjective::isSetAttribute(const std::string& attributeName) const
{
value = isSetVariableType();
}
else if (attributeName == "reaction2")
{
value = isSetReaction2();
}

return value;
}
Expand Down Expand Up @@ -845,6 +911,10 @@ FluxObjective::setAttribute(const std::string& attributeName,
{
return_value = setVariableType(value);
}
else if (attributeName == "reaction2")
{
return_value = setReaction2(value);
}

return return_value;
}
Expand Down Expand Up @@ -883,6 +953,10 @@ FluxObjective::unsetAttribute(const std::string& attributeName)
{
value = unsetVariableType();
}
else if (attributeName == "reaction2")
{
value = unsetReaction2();
}

return value;
}
Expand Down Expand Up @@ -912,6 +986,7 @@ FluxObjective::addExpectedAttributes(ExpectedAttributes& attributes)
if (level == 3 && coreVersion == 1 && pkgVersion == 3)
{
attributes.add("variableType");
attributes.add("reaction2");
}
}

Expand Down Expand Up @@ -1052,6 +1127,17 @@ FluxObjective::readAttributes (const XMLAttributes& attributes,
}


assigned = attributes.readInto("reaction2", mReaction2);
if (assigned && !SyntaxChecker::isValidSBMLSId(mReaction2))
{
//
// Logs an error if the "id" attribute doesn't
// conform to the SBML type SId.
//
log->logPackageError("fbc", FbcFluxObjectReactionMustBeSIdRef,
getPackageVersion(), sbmlLevel, sbmlVersion, "", getLine(), getColumn());
}

unsigned int numErrs = log->getNumErrors();
mIsSetCoefficient = attributes.readInto("coefficient", mCoefficient, log);

Expand Down Expand Up @@ -1153,6 +1239,9 @@ FluxObjective::writeAttributes (XMLOutputStream& stream) const
FbcVariableType_toString(mVariableType));
}

if (isSetReaction2() == true)
stream.writeAttribute("reaction2", getPrefix(), mReaction2);

//
// (EXTENSION)
//
Expand Down Expand Up @@ -1542,6 +1631,13 @@ FluxObjective_getVariableTypeAsString(const FluxObjective_t * fo)
return (char*)(FbcVariableType_toString(fo->getVariableType()));
}

LIBSBML_EXTERN
const char *
FluxObjective_getReaction2(const FluxObjective_t * fo)
{
return (fo != NULL && fo->isSetReaction2()) ? fo->getReaction2().c_str() : NULL;
}


LIBSBML_EXTERN
int
Expand Down Expand Up @@ -1583,6 +1679,14 @@ FluxObjective_isSetVariableType(const FluxObjective_t * fo)
}


LIBSBML_EXTERN
int
FluxObjective_isSetReaction2(const FluxObjective_t * fo)
{
return (fo != NULL) ? static_cast<int>(fo->isSetReaction2()) : 0;
}


/*
* Sets the value of the "id" attribute of this FluxObjective_t.
*/
Expand Down Expand Up @@ -1652,6 +1756,18 @@ FluxObjective_setVariableTypeAsString(FluxObjective_t * fo,
LIBSBML_INVALID_OBJECT;
}


LIBSBML_EXTERN
int
FluxObjective_setReaction2(FluxObjective_t * fo, const char * reaction)
{
if (fo != NULL)
return (reaction == NULL) ? fo->setReaction2("") : fo->setReaction2(reaction);
else
return LIBSBML_INVALID_OBJECT;
}


LIBSBML_EXTERN
int
FluxObjective_unsetId(FluxObjective_t * fo)
Expand Down Expand Up @@ -1695,6 +1811,14 @@ FluxObjective_unsetVariableType(FluxObjective_t * fo)
}


LIBSBML_EXTERN
int
FluxObjective_unsetReaction2(FluxObjective_t * fo)
{
return (fo != NULL) ? fo->unsetReaction2() : LIBSBML_INVALID_OBJECT;
}


LIBSBML_EXTERN
int
FluxObjective_hasRequiredAttributes(const FluxObjective_t * fo)
Expand Down
Loading

0 comments on commit b3eb9c3

Please sign in to comment.