本文整理汇总了C++中KineticLaw::setMath方法的典型用法代码示例。如果您正苦于以下问题:C++ KineticLaw::setMath方法的具体用法?C++ KineticLaw::setMath怎么用?C++ KineticLaw::setMath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KineticLaw
的用法示例。
在下文中一共展示了KineticLaw::setMath方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createKineticLawForReaction
void createKineticLawForReaction(Reaction* reaction)
{
if (reaction == NULL)
return;
reaction->unsetKineticLaw();
KineticLaw *law = reaction->getKineticLaw();
if (law == NULL)
{
law = reaction->createKineticLaw();
LocalParameter* fluxValue = law->createLocalParameter();
fluxValue->initDefaults();
fluxValue->setId("FLUX_VALUE");
fluxValue->setValue(0);
fluxValue->setUnits("dimensionless");
ASTNode* astn = SBML_parseFormula("FLUX_VALUE");
law->setMath(astn);
delete astn;
}
LocalParameter* LB = law->getLocalParameter("LOWER_BOUND");
if (LB == NULL)
{
LB = law->createLocalParameter();
LB->initDefaults();
LB->setId("LOWER_BOUND");
LB->setUnits("dimensionless");
LB->setValue(-std::numeric_limits<double>::infinity());
}
LocalParameter* UB = law->getLocalParameter("UPPER_BOUND");
if (UB == NULL)
{
UB = law->createLocalParameter();
UB->initDefaults();
UB->setId("UPPER_BOUND");
UB->setUnits("dimensionless");
LB->setValue(std::numeric_limits<double>::infinity());
}
LocalParameter* param = law->getLocalParameter("OBJECTIVE_COEFFICIENT");
if (param == NULL)
{
param = law->createLocalParameter();
param->initDefaults();
param->setId("OBJECTIVE_COEFFICIENT");
param->setUnits("dimensionless");
param->setValue(0);
}
}
示例2: KineticLaw
END_TEST
START_TEST ( test_KineticLaw )
{
KineticLaw* kl = new KineticLaw(2, 4);
fail_unless (!(kl->hasRequiredElements()));
kl->setMath(SBML_parseFormula("kl"));
fail_unless (kl->hasRequiredElements());
delete kl;
}
示例3: changePow
void
convertPow(SBMLDocument* doc,
bool shouldChangePow,
bool inlineCompartmentSizes)
{
Model* model = SBMLDocument_getModel(doc);
if (model == NULL)
{
return;
}
std::map<string, double> compartmentValueMap;
if (inlineCompartmentSizes)
{
for(unsigned int i = 0; i < model->getNumCompartments(); ++i)
{
Compartment* c = model->getCompartment(i);
compartmentValueMap[c->getId()] = c->getSize();
}
}
for(unsigned int i = 0; i < model->getNumReactions(); ++i)
{
Reaction* r = model->getReaction(i);
KineticLaw* kl = r->getKineticLaw();
const char* strKineticFormula;
if (kl == NULL)
{
strKineticFormula = "";
}
else
{
strKineticFormula = KineticLaw_getFormula(kl);
if (strKineticFormula == NULL)
{
continue;
}
}
ASTNode* ast_Node = SBML_parseFormula (strKineticFormula);
if (ast_Node != NULL)
{
changePow(ast_Node, compartmentValueMap, shouldChangePow);
kl->setMath (ast_Node);
}
delete ast_Node;
}
}
示例4: createExampleInvolvingUnits
//.........这里部分代码省略.........
ASTNode* astMath = new ASTNode(AST_TIMES);
astMath->addChild(new ASTNode(AST_DIVIDE));
ASTNode* astDivide = astMath->getLeftChild();
astDivide->addChild(new ASTNode(AST_TIMES));
ASTNode* astTimes = astDivide->getLeftChild();
astTimes->addChild(new ASTNode(AST_NAME));
astTimes->getLeftChild()->setName("vm");
astTimes->addChild(new ASTNode(AST_NAME));
astTimes->getRightChild()->setName("s1");
astDivide->addChild(new ASTNode(AST_PLUS));
ASTNode* astPlus = astDivide->getRightChild();
astPlus->addChild(new ASTNode(AST_NAME));
astPlus->getLeftChild()->setName("km");
astPlus->addChild(new ASTNode(AST_NAME));
astPlus->getRightChild()->setName("s1");
astMath->addChild(new ASTNode(AST_NAME));
astMath->getRightChild()->setName("cell");
//---------------------------------------------
//
// set the Math element
//
//------------------------------------------------
kl->setMath(astMath);
delete astMath;
//---------------------------------------------------------------------------
// (Reaction2) Creates a Reaction object ("v2").
//---------------------------------------------------------------------------
reaction = model->createReaction();
reaction->setId("v2");
//---------------------------------------------------------------------------
// Creates Reactant objects inside the Reaction object ("v2").
//---------------------------------------------------------------------------
// (Reactant2) Creates a Reactant object that references Species "s1"
// in the model.
spr = reaction->createReactant();
spr->setSpecies("s1");
//---------------------------------------------------------------------------
// Creates a Product object inside the Reaction object ("v2").
//---------------------------------------------------------------------------
// Creates a Product object that references Species "s2" in the model.
spr = reaction->createProduct();
spr->setSpecies("s2");
//---------------------------------------------------------------------------
// Creates a KineticLaw object inside the Reaction object ("v2").
//---------------------------------------------------------------------------
示例5: createExampleEnzymaticReaction
//.........这里部分代码省略.........
//
// create node representing
// <apply>
// <times/>
// <ci> cytosol </ci>
// <apply>
// <minus/>
// <apply>
// <times/>
// <ci> kon </ci>
// <ci> E </ci>
// <ci> S </ci>
// </apply>
// <apply>
// <times/>
// <ci> koff </ci>
// <ci> ES </ci>
// </apply>
// </apply>
// </apply>
//
//--------------------------------------------
ASTNode* astMath = new ASTNode(AST_TIMES);
astMath->addChild(astCytosol);
astMath->addChild(astMinus);
//---------------------------------------------
//
// set the Math element
//
//------------------------------------------------
kl->setMath(astMath);
// KineticLaw::setMath(const ASTNode*) sets the math of the KineticLaw object
// to a copy of the given ASTNode, and thus basically the caller should delete
// the original ASTNode object if the caller has the ownership of the object to
// avoid memory leak.
delete astMath;
//---------------------------------------------------------------------------
// Creates local Parameter objects inside the KineticLaw object.
//---------------------------------------------------------------------------
// Creates a Parameter ("kon")
Parameter* para = kl->createParameter();
para->setId("kon");
para->setValue(1000000);
para->setUnits("litre_per_mole_per_second");
// Creates a Parameter ("koff")
para = kl->createParameter();
para->setId("koff");
para->setValue(0.2);
para->setUnits("per_second");
//---------------------------------------------------------------------------
// (Reaction2) Creates a Reaction object ("vcat") .
//---------------------------------------------------------------------------
示例6: createExampleInvolvingFunctionDefinitions
/**
*
* Creates an SBML model represented in "7.8 Example involving function definitions"
* in the SBML Level 2 Version 4 Specification.
*
*/
SBMLDocument* createExampleInvolvingFunctionDefinitions()
{
const unsigned int level = Level;
const unsigned int version = Version;
//---------------------------------------------------------------------------
//
// Creates an SBMLDocument object
//
//---------------------------------------------------------------------------
SBMLDocument* sbmlDoc = new SBMLDocument(level,version);
//---------------------------------------------------------------------------
//
// Creates a Model object inside the SBMLDocument object.
//
//---------------------------------------------------------------------------
Model* model = sbmlDoc->createModel();
model->setId("functionExample");
//---------------------------------------------------------------------------
//
// Creates a FunctionDefinition object inside the Model object.
//
//---------------------------------------------------------------------------
FunctionDefinition* fdef = model->createFunctionDefinition();
fdef->setId("f");
// Sets a math (ASTNode object) to the FunctionDefinition object.
string mathXMLString = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
" <lambda>"
" <bvar>"
" <ci> x </ci>"
" </bvar>"
" <apply>"
" <times/>"
" <ci> x </ci>"
" <cn> 2 </cn>"
" </apply>"
" </lambda>"
"</math>";
ASTNode* astMath = readMathMLFromString(mathXMLString.c_str());
fdef->setMath(astMath);
delete astMath;
//---------------------------------------------------------------------------
//
// Creates a Compartment object inside the Model object.
//
//---------------------------------------------------------------------------
Compartment* comp;
const string compName = "compartmentOne";
// Creates a Compartment object ("compartmentOne")
comp = model->createCompartment();
comp->setId(compName);
// Sets the "size" attribute of the Compartment object.
//
// The units of this Compartment object is the default SBML
// units of volume (litre), and thus we don't have to explicitly invoke
// setUnits("litre") function to set the default units.
//
comp->setSize(1);
//---------------------------------------------------------------------------
//
// Creates Species objects inside the Model object.
//
//---------------------------------------------------------------------------
Species* sp;
//---------------------------------------------------------------------------
// (Species1) Creates a Species object ("S1")
//---------------------------------------------------------------------------
sp = model->createSpecies();
sp->setId("S1");
// Sets the "compartment" attribute of the Species object to identify the
// compartnet in which the Species object located.
sp->setCompartment(compName);
//.........这里部分代码省略.........
示例7: getSBMLDocument
/** @cond doxygenLibsbmlInternal */
int
Replacing::updateIDs(SBase* oldnames, SBase* newnames)
{
int ret = LIBSBML_OPERATION_SUCCESS;
SBMLDocument* doc = getSBMLDocument();
if (oldnames->isSetId() && !newnames->isSetId()) {
if (doc) {
string error = "Unable to transform IDs in Replacing::updateIDs during replacement: the '" + oldnames->getId() + "' element's replacement does not have an ID set.";
doc->getErrorLog()->logPackageError("comp", CompMustReplaceIDs, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return LIBSBML_INVALID_OBJECT;
}
if (oldnames->isSetMetaId() && !newnames->isSetMetaId()) {
if (doc) {
string error = "Unable to transform IDs in Replacing::updateIDs during replacement: the replacement of the element with metaid '" + oldnames->getMetaId() + "' does not have a metaid.";
doc->getErrorLog()->logPackageError("comp", CompMustReplaceMetaIDs, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return LIBSBML_INVALID_OBJECT;
}
//LS DEBUG Somehow we need to check identifiers from other packages here (like spatial id's). How, exactly, is anyone's guess.
Model* replacedmod = const_cast<Model*>(CompBase::getParentModel(oldnames));
KineticLaw* replacedkl;
ASTNode newkl;
if (replacedmod==NULL) {
if (doc) {
string error = "Unable to transform IDs in Replacing::updateIDs during replacement: the replacement of '" + oldnames->getId() + "' does not have a valid model.";
doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return LIBSBML_INVALID_OBJECT;
}
List* allElements = replacedmod->getAllElements();
string oldid = oldnames->getId();
string newid = newnames->getId();
if (!oldid.empty()) {
switch(oldnames->getTypeCode()) {
case SBML_UNIT_DEFINITION:
replacedmod->renameUnitSIdRefs(oldid, newid);
for (unsigned int e=0; e<allElements->getSize(); e++) {
SBase* element = static_cast<SBase*>(allElements->get(e));
element->renameUnitSIdRefs(oldid, newid);
}
break;
case SBML_LOCAL_PARAMETER:
replacedkl = static_cast<KineticLaw*>(oldnames->getAncestorOfType(SBML_KINETIC_LAW));
if (replacedkl->isSetMath()) {
newkl = *replacedkl->getMath();
newkl.renameSIdRefs(oldid, newid);
replacedkl->setMath(&newkl);
}
break;
case SBML_COMP_PORT:
break;
//LS DEBUG And here is where we would need some sort of way to check if the id wasn't an SId for some objects.
default:
replacedmod->renameSIdRefs(oldnames->getId(), newnames->getId());
for (unsigned int e=0; e<allElements->getSize(); e++) {
SBase* element = static_cast<SBase*>(allElements->get(e));
element->renameSIdRefs(oldid, newid);
}
}
}
string oldmetaid = oldnames->getMetaId();
string newmetaid = newnames->getMetaId();
if (oldnames->isSetMetaId()) {
replacedmod->renameMetaIdRefs(oldmetaid, newmetaid);
for (unsigned int e=0; e<allElements->getSize(); e++) {
SBase* element = static_cast<SBase*>(allElements->get(e));
element->renameMetaIdRefs(oldmetaid, newmetaid);
}
}
//LS DEBUG And here is where we would need some sort of way to check for ids that were not 'id' or 'metaid'.
delete allElements;
return ret;
}
示例8: convertTimeAndExtentWith
int Submodel::convertTimeAndExtentWith(const ASTNode* tcf, const ASTNode* xcf, const ASTNode* klmod)
{
if (tcf==NULL && xcf==NULL) return LIBSBML_OPERATION_SUCCESS;
Model* model = getInstantiation();
if (model==NULL) {
//getInstantiation sets its own error messages.
return LIBSBML_OPERATION_FAILED;
}
ASTNode tcftimes(AST_TIMES);
ASTNode tcfdiv(AST_DIVIDE);
if (tcf != NULL) {
tcftimes.addChild(tcf->deepCopy());
tcfdiv.addChild(tcf->deepCopy());
}
ASTNode rxndivide(AST_DIVIDE);
if (klmod != NULL) {
ASTNode rxnref(AST_NAME);
rxndivide.addChild(rxnref.deepCopy());
rxndivide.addChild(klmod->deepCopy());
}
List* allElements = model->getAllElements();
for (ListIterator iter = allElements->begin(); iter != allElements->end(); ++iter)
{
SBase* element = static_cast<SBase*>(*iter);
assert(element != NULL);
ASTNode* ast1 = NULL;
ASTNode* ast2 = NULL;
Constraint* constraint = NULL;
Delay* delay = NULL;
EventAssignment* ea = NULL;
InitialAssignment* ia = NULL;
KineticLaw* kl = NULL;
Priority* priority = NULL;
RateRule* rrule = NULL;
Rule* rule = NULL;
Submodel* submodel = NULL;
Trigger* trigger = NULL;
string cf = "";
//Reaction math will be converted below, in the bits with the kinetic law. But because of that, we need to handle references *to* the reaction: even if it has no kinetic law, the units have changed, and this needs to be reflected by the flattening routine.
if (rxndivide.getNumChildren() != 0 && element->getTypeCode()==SBML_REACTION && element->isSetId()) {
rxndivide.getChild(0)->setName(element->getId().c_str());
for (ListIterator iter = allElements->begin(); iter != allElements->end(); ++iter)
{
SBase* subelement = static_cast<SBase*>(*iter);
subelement->replaceSIDWithFunction(element->getId(), &rxndivide);
}
}
//Submodels need their timeConversionFactor and extentConversionFactor attributes converted. We're moving top-down, so all we need to do here is fix the conversion factor attributes themselves, pointing them to new parameters if need be.
if ((tcf !=NULL || xcf != NULL) && element->getTypeCode()==SBML_COMP_SUBMODEL) {
submodel = static_cast<Submodel*>(element);
if (tcf != NULL) {
if (submodel->isSetTimeConversionFactor()) {
createNewConversionFactor(cf, tcf, submodel->getTimeConversionFactor(), model);
submodel->setTimeConversionFactor(cf);
}
else {
submodel->setTimeConversionFactor(tcf->getName());
}
}
if (xcf != NULL) {
if (submodel->isSetExtentConversionFactor()) {
createNewConversionFactor(cf, xcf, submodel->getExtentConversionFactor(), model);
submodel->setExtentConversionFactor(cf);
}
else {
submodel->setExtentConversionFactor(xcf->getName());
}
}
}
if (tcf==NULL) {
if (klmod !=NULL && element->getTypeCode()==SBML_KINETIC_LAW) {
kl = static_cast<KineticLaw*>(element);
if (kl->isSetMath()) {
ast1 = new ASTNode(AST_TIMES);
ast1->addChild(klmod->deepCopy());
ast1->addChild(kl->getMath()->deepCopy());
kl->setMath(ast1);
delete ast1;
}
}
}
else {
// All math 'time' and 'delay' csymbols must still be converted.
// Also, several constructs are modified directly.
switch(element->getTypeCode()) {
//This would be a WHOLE LOT SIMPLER if there was a 'hasMath' class in libsbml. But even so, it would have to
// handle the kinetic laws, rate rules, and delays separately.
case SBML_KINETIC_LAW:
//Kinetic laws are multiplied by 'klmod'.
kl = static_cast<KineticLaw*>(element);
ast1 = kl->getMath()->deepCopy();
convertCSymbols(ast1, &tcfdiv, &tcftimes);
if (klmod !=NULL) {
kl = static_cast<KineticLaw*>(element);
if (kl->isSetMath()) {
ast2 = new ASTNode(AST_TIMES);
ast2->addChild(klmod->deepCopy());
ast2->addChild(ast1);
kl->setMath(ast2);
//.........这里部分代码省略.........
示例9: CreateSBMLModel
void Module::CreateSBMLModel()
{
Model* sbmlmod = m_sbml.createModel();
sbmlmod->setId(m_modulename);
sbmlmod->setName(m_modulename);
sbmlmod->setNotes("<body xmlns=\"http://www.w3.org/1999/xhtml\"><p> Originally created by libAntimony " VERSION_STRING " (using libSBML " LIBSBML_DOTTED_VERSION ") </p></body>");
char cc = g_registry.GetCC();
//User-defined functions
for (size_t uf=0; uf<g_registry.GetNumUserFunctions(); uf++) {
const UserFunction* userfunction = g_registry.GetNthUserFunction(uf);
assert(userfunction != NULL);
FunctionDefinition* fd = sbmlmod->createFunctionDefinition();
fd->setId(userfunction->GetModuleName());
ASTNode* math = parseStringToASTNode(userfunction->ToSBMLString());
fd->setMath(math);
delete math;
}
//Compartments
Compartment* defaultCompartment = sbmlmod->createCompartment();
defaultCompartment->setId(DEFAULTCOMP);
defaultCompartment->setConstant(true);
defaultCompartment->setSize(1);
defaultCompartment->setSBOTerm(410); //The 'implicit compartment'
size_t numcomps = GetNumVariablesOfType(allCompartments);
for (size_t comp=0; comp<numcomps; comp++) {
const Variable* compartment = GetNthVariableOfType(allCompartments, comp);
Compartment* sbmlcomp = sbmlmod->createCompartment();
sbmlcomp->setId(compartment->GetNameDelimitedBy(cc));
if (compartment->GetDisplayName() != "") {
sbmlcomp->setName(compartment->GetDisplayName());
}
sbmlcomp->setConstant(compartment->GetIsConst());
formula_type ftype = compartment->GetFormulaType();
assert (ftype == formulaINITIAL || ftype==formulaASSIGNMENT || ftype==formulaRATE);
if (ftype != formulaINITIAL) {
sbmlcomp->setConstant(false);
}
const Formula* formula = compartment->GetFormula();
if (formula->IsDouble()) {
sbmlcomp->setSize(atof(formula->ToSBMLString().c_str()));
}
SetAssignmentFor(sbmlmod, compartment);
}
//Species
size_t numspecies = GetNumVariablesOfType(allSpecies);
for (size_t spec=0; spec < numspecies; spec++) {
const Variable* species = GetNthVariableOfType(allSpecies, spec);
Species* sbmlspecies = sbmlmod->createSpecies();
sbmlspecies->setId(species->GetNameDelimitedBy(cc));
if (species->GetDisplayName() != "") {
sbmlspecies->setName(species->GetDisplayName());
}
sbmlspecies->setConstant(false); //There's no need to try to distinguish between const and var for species.
if (species->GetIsConst()) {
sbmlspecies->setBoundaryCondition(true);
}
else {
sbmlspecies->setBoundaryCondition(false);
}
const Variable* compartment = species->GetCompartment();
if (compartment == NULL) {
sbmlspecies->setCompartment(defaultCompartment->getId());
}
else {
sbmlspecies->setCompartment(compartment->GetNameDelimitedBy(cc));
}
const Formula* formula = species->GetFormula();
if (formula->IsDouble()) {
sbmlspecies->setInitialConcentration(atof(formula->ToSBMLString().c_str()));
}
else if (formula->IsAmountIn(species->GetCompartment())) {
sbmlspecies->setInitialAmount(formula->ToAmount());
}
SetAssignmentFor(sbmlmod, species);
}
//Formulas
size_t numforms = GetNumVariablesOfType(allFormulas);
for (size_t form=0; form < numforms; form++) {
const Variable* formvar = GetNthVariableOfType(allFormulas, form);
const Formula* formula = formvar->GetFormula();
Parameter* param = sbmlmod->createParameter();
param->setId(formvar->GetNameDelimitedBy(cc));
if (formvar->GetDisplayName() != "") {
param->setName(formvar->GetDisplayName());
}
param->setConstant(formvar->GetIsConst());
if (formula->IsDouble()) {
param->setValue(atof(formula->ToSBMLString().c_str()));
}
SetAssignmentFor(sbmlmod, formvar);
formula_type ftype = formvar->GetFormulaType();
assert (ftype == formulaINITIAL || ftype==formulaASSIGNMENT || ftype==formulaRATE);
if (ftype != formulaINITIAL) {
param->setConstant(false);
}
}
//Reactions
//.........这里部分代码省略.........