16 # pragma warning (disable: 4786)
17 # pragma warning (disable: 4243)
19 # pragma warning (disable: 4355)
31 #include <sbml/SBMLReader.h>
32 #include <sbml/SBMLDocument.h>
33 #include <sbml/Compartment.h>
34 #include <sbml/Species.h>
35 #include <sbml/SpeciesReference.h>
36 #include <sbml/Reaction.h>
37 #include <sbml/LocalParameter.h>
39 #if LIBSBML_VERSION >= 50400
40 #include <sbml/SBMLTransforms.h>
42 #include <sbml/conversion/ConversionProperties.h>
43 #include <sbml/packages/layout/extension/LayoutModelPlugin.h>
44 #define INIT_DEFAULTS(element) \
46 element.initDefaults();\
49 #define INIT_DEFAULTS(element) \
52 #endif // LIBSBML_VERSION
54 #include <sbml/KineticLaw.h>
55 #include <sbml/math/FormulaFormatter.h>
56 #include <sbml/Model.h>
57 #include <sbml/UnitKind.h>
58 #include <sbml/Unit.h>
59 #include <sbml/Parameter.h>
60 #include <sbml/InitialAssignment.h>
61 #include <sbml/Rule.h>
62 #include <sbml/FunctionDefinition.h>
63 #include <sbml/UnitDefinition.h>
100 #if LIBSBML_VERSION >= 50903 && LIBSBML_HAS_PACKAGE_COMP
102 #include <sbml/util/PrefixTransformer.h>
103 #include <sbml/packages/comp/extension/CompModelPlugin.h>
105 class CPrefixNameTransformer :
public PrefixTransformer
108 CPrefixNameTransformer() {}
110 static void replaceStringInPlace(std::string& subject,
const std::string& search,
111 const std::string& replace)
115 while ((pos = subject.find(search, pos)) != std::string::npos)
117 subject.replace(pos, search.length(), replace);
118 pos += replace.length();
122 static inline std::string &rtrim(std::string &str)
124 size_t endpos = str.find_last_not_of(
" \t");
126 if (std::string::npos != endpos)
128 str = str.substr(0, endpos + 1);
134 const std::string& cleanName(std::string& prefix)
136 std::replace(prefix.begin(), prefix.end(),
'_',
' ');
137 replaceStringInPlace(prefix,
" ",
" ");
144 if (element == NULL || getPrefix().empty())
145 return LIBSBML_OPERATION_SUCCESS;
151 if (element->getTypeCode() == SBML_LOCAL_PARAMETER)
152 return LIBSBML_OPERATION_SUCCESS;
155 if (element->isSetName())
157 std::stringstream newName;
158 std::string prefix = getPrefix();
159 newName << element->getName() <<
" (" << cleanName(prefix) <<
")";
160 element->setName(newName.str());
163 return LIBSBML_OPERATION_SUCCESS;
173 x < 0.0 ? -floor(-x + 0.5) : floor(x + 0.5);
180 (fabs(x) + fabs(y)) * t;
186 return 2 * fabs(x - y) < Scale;
191 if (parameter == NULL)
return "";
193 if (!parameter->isSetAnnotation())
return "";
195 XMLNode* node = parameter->getAnnotation();
197 if (node->getNumChildren() < 1)
return "";
199 for (
unsigned int i = 0; i < node->getNumChildren(); ++i)
201 const XMLNode& current = node->getChild(i);
203 if (current.getNamespaces().containsUri(
"http://copasi.org/initialValue"))
205 return current.getAttrValue(
"parent");
214 std::map<CCopasiObject*, SBase*>::const_iterator it;
216 for (it = copasi2sbmlmap.begin(); it != copasi2sbmlmap.end(); ++it)
218 if (it->second != sbase)
245 Model* sbmlModel = sbmlDocument->getModel();
257 unsigned C_INT32 step = 0, totalSteps = 0;
265 UnitDefinition *pSubstanceUnits = NULL;
266 UnitDefinition *pTimeUnits = NULL;
267 UnitDefinition *pVolumeUnits = NULL;
268 UnitDefinition *pAreaUnits = NULL;
269 UnitDefinition *pLengthUnits = NULL;
281 UnitDefinition* pUDef = NULL;
282 Unit unit(sbmlModel->getLevel(), sbmlModel->getVersion());
285 if (sbmlModel->isSetSubstanceUnits())
287 units = sbmlModel->getSubstanceUnits();
289 pUDef = sbmlModel->getUnitDefinition(units);
293 pSubstanceUnits =
new UnitDefinition(*pUDef);
299 unit.setKind(UNIT_KIND_MOLE);
301 unit.setMultiplier(1.0);
303 pSubstanceUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
304 pSubstanceUnits->addUnit(&unit);
306 else if (units ==
"item")
308 unit.setKind(UNIT_KIND_ITEM);
310 unit.setMultiplier(1.0);
312 pSubstanceUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
313 pSubstanceUnits->addUnit(&unit);
315 else if (units ==
"dimensionless")
317 unit.setKind(UNIT_KIND_DIMENSIONLESS);
319 unit.setMultiplier(1.0);
321 pSubstanceUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
322 pSubstanceUnits->addUnit(&unit);
326 std::string message =
"COPASI can't handle substance unit \"" + units +
"\". Setting unit for substances to dimensionless.";
328 unit.setKind(UNIT_KIND_DIMENSIONLESS);
330 unit.setMultiplier(1.0);
332 pSubstanceUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
333 pSubstanceUnits->addUnit(&unit);
338 if (sbmlModel->isSetTimeUnits())
340 units = sbmlModel->getTimeUnits();
342 pUDef = sbmlModel->getUnitDefinition(units);
346 pTimeUnits =
new UnitDefinition(*pUDef);
350 if (units ==
"second")
352 unit.setKind(UNIT_KIND_SECOND);
354 unit.setMultiplier(1.0);
356 pTimeUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
357 pTimeUnits->addUnit(&unit);
359 else if (units ==
"dimensionless")
361 unit.setKind(UNIT_KIND_DIMENSIONLESS);
363 unit.setMultiplier(1.0);
365 pTimeUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
366 pTimeUnits->addUnit(&unit);
370 std::string message =
"COPASI can't handle time unit \"" + units +
"\". Setting unit for time to dimensionless.";
372 unit.setKind(UNIT_KIND_DIMENSIONLESS);
374 unit.setMultiplier(1.0);
376 pTimeUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
377 pTimeUnits->addUnit(&unit);
382 if (sbmlModel->isSetVolumeUnits())
384 units = sbmlModel->getVolumeUnits();
386 pUDef = sbmlModel->getUnitDefinition(units);
390 pVolumeUnits =
new UnitDefinition(*pUDef);
394 if (units ==
"litre")
396 unit.setKind(UNIT_KIND_LITRE);
398 unit.setMultiplier(1.0);
400 pVolumeUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
401 pVolumeUnits->addUnit(&unit);
403 else if (units ==
"dimensionless")
405 unit.setKind(UNIT_KIND_DIMENSIONLESS);
407 unit.setMultiplier(1.0);
409 pVolumeUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
410 pVolumeUnits->addUnit(&unit);
414 std::string message =
"COPASI can't handle volume unit \"" + units +
"\". Setting unit for volume to dimensionless.";
416 unit.setKind(UNIT_KIND_DIMENSIONLESS);
418 unit.setMultiplier(1.0);
420 pVolumeUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
421 pVolumeUnits->addUnit(&unit);
426 if (sbmlModel->isSetAreaUnits())
428 units = sbmlModel->getAreaUnits();
430 pUDef = sbmlModel->getUnitDefinition(units);
434 pAreaUnits =
new UnitDefinition(*pUDef);
438 if (units ==
"dimensionless")
440 unit.setKind(UNIT_KIND_DIMENSIONLESS);
442 unit.setMultiplier(1.0);
444 pAreaUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
445 pAreaUnits->addUnit(&unit);
449 std::string message =
"COPASI can't handle area unit \"" + units +
"\". Setting unit for area to dimensionless.";
451 unit.setKind(UNIT_KIND_DIMENSIONLESS);
453 unit.setMultiplier(1.0);
455 pAreaUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
456 pAreaUnits->addUnit(&unit);
461 if (sbmlModel->isSetLengthUnits())
463 units = sbmlModel->getLengthUnits();
465 pUDef = sbmlModel->getUnitDefinition(units);
469 pLengthUnits =
new UnitDefinition(*pUDef);
473 if (units ==
"litre")
475 unit.setKind(UNIT_KIND_LITRE);
477 unit.setMultiplier(1.0);
479 pLengthUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
480 pLengthUnits->addUnit(&unit);
482 else if (units ==
"metre")
484 unit.setKind(UNIT_KIND_METRE);
486 unit.setMultiplier(1.0);
488 pLengthUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
489 pLengthUnits->addUnit(&unit);
491 else if (units ==
"dimensionless")
493 unit.setKind(UNIT_KIND_DIMENSIONLESS);
495 unit.setMultiplier(1.0);
497 pLengthUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
498 pLengthUnits->addUnit(&unit);
502 std::string message =
"COPASI can't handle length unit \"" + units +
"\". Setting unit for length to dimensionless.";
504 unit.setKind(UNIT_KIND_DIMENSIONLESS);
506 unit.setMultiplier(1.0);
508 pLengthUnits =
new UnitDefinition(sbmlModel->getLevel(), sbmlModel->getVersion());
509 pLengthUnits->addUnit(&unit);
516 if (sbmlModel->getNumUnitDefinitions() != 0)
518 unsigned int counter;
522 for (counter = 0; counter < sbmlModel->getNumUnitDefinitions(); counter++)
524 UnitDefinition* uDef = sbmlModel->getUnitDefinition(counter);
525 std::string unitId = uDef->getId();
527 if (unitId ==
"substance")
529 pSubstanceUnits =
new UnitDefinition(*uDef);
531 else if (unitId ==
"time")
533 pTimeUnits =
new UnitDefinition(*uDef);
535 else if (unitId ==
"volume")
537 pVolumeUnits =
new UnitDefinition(*uDef);
539 else if ((unitId ==
"area"))
541 pAreaUnits =
new UnitDefinition(*uDef);
543 else if ((unitId ==
"length"))
545 pLengthUnits =
new UnitDefinition(*uDef);
552 if (pSubstanceUnits == NULL)
561 pSubstanceUnits =
new UnitDefinition(this->
mLevel, this->
mVersion);
562 pSubstanceUnits->setId(
"dummy_substance");
563 pSubstanceUnits->setName(
"dummy_substance");
564 Unit* pUnit = pSubstanceUnits->createUnit();
565 pUnit->setKind(UNIT_KIND_MOLE);
566 pUnit->setExponent(1);
567 pUnit->setMultiplier(1.0);
571 if (pTimeUnits == NULL)
581 pTimeUnits->setId(
"dummy_time");
582 pTimeUnits->setName(
"dummy_time");
583 Unit* pUnit = pTimeUnits->createUnit();
584 pUnit->setKind(UNIT_KIND_SECOND);
585 pUnit->setExponent(1);
586 pUnit->setMultiplier(1.0);
590 if (pVolumeUnits == NULL)
600 pVolumeUnits->setId(
"dummy_volume");
601 pVolumeUnits->setName(
"dummy_volume");
602 Unit* pUnit = pVolumeUnits->createUnit();
603 pUnit->setKind(UNIT_KIND_LITRE);
604 pUnit->setExponent(1);
605 pUnit->setMultiplier(1.0);
609 if (pAreaUnits == NULL)
619 pAreaUnits->setId(
"dummy_area");
620 pAreaUnits->setName(
"dummy_area");
621 Unit* pUnit = pAreaUnits->createUnit();
622 pUnit->setKind(UNIT_KIND_METRE);
623 pUnit->setExponent(2);
624 pUnit->setMultiplier(1.0);
628 if (pLengthUnits == NULL)
638 pLengthUnits->setId(
"dummy_length");
639 pLengthUnits->setName(
"dummy_length");
640 Unit* pUnit = pLengthUnits->createUnit();
641 pUnit->setKind(UNIT_KIND_METRE);
642 pUnit->setExponent(1);
643 pUnit->setMultiplier(1.0);
650 assert(pSubstanceUnits != NULL);
652 if (pSubstanceUnits != NULL)
654 std::pair<CModel::QuantityUnit, bool> qUnit;
662 std::ostringstream os;
663 os <<
"Error while importing substance units.";
671 os << text.substr(text.find(
"\n"));
677 if (qUnit.second ==
false)
693 if (!sbmlModel->isSetExtentUnits())
699 const UnitDefinition* pExtendsUnits = sbmlModel->getUnitDefinition(sbmlModel->getExtentUnits());
701 if (pExtendsUnits != NULL)
715 delete pSubstanceUnits;
716 pSubstanceUnits = NULL;
720 assert(pTimeUnits != NULL);
722 if (pTimeUnits != NULL)
724 std::pair<CModel::TimeUnit, bool> tUnit;
732 std::ostringstream os;
733 os <<
"Error while importing time units.";
741 os << text.substr(text.find(
"\n"));
747 if (tUnit.second ==
false)
764 assert(pVolumeUnits != NULL);
766 if (pVolumeUnits != NULL)
768 std::pair<CModel::VolumeUnit, bool> vUnit;
776 std::ostringstream os;
777 os <<
"Error while importing volume units.";
785 os << text.substr(text.find(
"\n"));
791 if (vUnit.second ==
false)
808 assert(pAreaUnits != NULL);
810 if (pAreaUnits != NULL)
812 std::pair<CModel::AreaUnit, bool> vUnit;
820 std::ostringstream os;
821 os <<
"Error while importing area units.";
829 os << text.substr(text.find(
"\n"));
835 if (vUnit.second ==
false)
852 assert(pLengthUnits != NULL);
854 if (pLengthUnits != NULL)
856 std::pair<CModel::LengthUnit, bool> vUnit;
864 std::ostringstream os;
865 os <<
"Error while importing length units.";
873 os << text.substr(text.find(
"\n"));
879 if (vUnit.second ==
false)
911 title = sbmlModel->getName();
922 std::stringstream str; str << sbmlModel->getName() <<
"_" << ++idCount;
930 SBMLImporter::updateSBMLSpeciesReferenceIds(sbmlModel, this->mSBMLSpeciesReferenceIds);
933 unsigned int counter;
936 size_t num = (*functions).
size();
944 totalSteps = (
unsigned C_INT32) num;
952 for (counter = 0; counter < num; ++counter)
967 std::map<std::string, CCompartment*> compartmentMap;
970 num = sbmlModel->getNumCompartments();
980 totalSteps = (
unsigned C_INT32) num;
986 for (counter = 0; counter < num; counter++)
988 Compartment* sbmlCompartment = sbmlModel->getCompartment(counter);
990 if (sbmlCompartment == NULL)
1003 std::ostringstream os;
1004 os <<
"Error while importing compartment \"";
1005 os << sbmlCompartment->getId() <<
"\".";
1013 os << text.substr(text.find(
"\n"));
1019 std::string key = sbmlCompartment->getId();
1023 key = sbmlCompartment->getName();
1026 compartmentMap[key] = pCopasiCompartment;
1033 num = sbmlModel->getNumSpecies();
1043 totalSteps = (
unsigned C_INT32) num;
1049 for (counter = 0; counter < num; ++counter)
1051 Species* sbmlSpecies = sbmlModel->getSpecies(counter);
1053 if (sbmlSpecies == NULL)
1058 CCompartment* pCopasiCompartment = compartmentMap[sbmlSpecies->getCompartment()];
1060 if (pCopasiCompartment != NULL)
1062 CMetab* pCopasiMetabolite = NULL;
1070 std::ostringstream os;
1071 os <<
"Error while importing species \"";
1072 os << sbmlSpecies->getId() <<
"\".";
1080 os << text.substr(text.find(
"\n"));
1090 key = sbmlSpecies->getName();
1094 key = sbmlSpecies->getId();
1110 num = sbmlModel->getNumParameters();
1120 totalSteps = (
unsigned C_INT32) num;
1126 for (counter = 0; counter < num; ++counter)
1128 Parameter* sbmlParameter = sbmlModel->getParameter(counter);
1130 if (sbmlParameter == NULL)
1140 if (!sbmlId.empty())
1142 Species* species = sbmlModel->getSpecies(sbmlId);
1144 if (species != NULL)
1150 Compartment *comp = sbmlModel->getCompartment(sbmlId);
1158 Parameter* param = sbmlModel->getParameter(sbmlId);
1171 std::ostringstream os;
1172 os <<
"Error while importing parameter \"";
1173 os << sbmlParameter->getId() <<
"\".";
1181 os << text.substr(text.find(
"\n"));
1198 if (this->
mLevel > 2 && sbmlModel->isSetConversionFactor())
1200 this->mConversionFactorFound =
true;
1201 std::string
id = sbmlModel->getConversionFactor();
1203 std::map<std::string, const CModelValue*>::const_iterator pos = this->mSBMLIdModelValueMap.find(
id);
1204 assert(pos != this->mSBMLIdModelValueMap.end());
1206 if (pos != this->mSBMLIdModelValueMap.end())
1208 this->mpModelConversionFactor = pos->second;
1221 num = sbmlModel->getNumSpecies();
1223 for (counter = 0; counter < num; ++counter)
1225 Species* sbmlSpecies = sbmlModel->getSpecies(counter);
1227 if (sbmlSpecies->isSetConversionFactor())
1229 this->mConversionFactorFound =
true;
1230 std::map<std::string, const CModelValue*>::const_iterator pos = this->mSBMLIdModelValueMap.find(sbmlSpecies->getConversionFactor());
1232 if (pos != this->mSBMLIdModelValueMap.end())
1234 this->mSpeciesConversionParameterMap[sbmlSpecies->getId()] = pos->second;
1242 std::ostringstream os;
1247 os << *errorIt <<
", ";
1251 std::string s = os.str();
1256 num = sbmlModel->getNumReactions();
1266 totalSteps = (
unsigned C_INT32) num;
1276 for (counter = 0; counter < num; counter++)
1284 std::ostringstream os;
1285 os <<
"Error while importing reaction \"";
1286 os << sbmlModel->getReaction(counter)->getId() <<
"\".";
1294 os << text.substr(text.find(
"\n"));
1319 idList = idList.substr(0, idList.length() - 2);
1327 std::set<std::string>::const_iterator it = this->
mFastReactions.begin();
1328 std::set<std::string>::const_iterator endit = this->
mFastReactions.end();
1337 idList = idList.substr(0, idList.length() - 2);
1355 idList = idList.substr(0, idList.length() - 2);
1380 num = sbmlModel->getNumRules();
1390 totalSteps = (
unsigned C_INT32) num;
1396 for (counter = 0; counter < num; ++counter)
1398 Rule* sbmlRule = sbmlModel->getRule(counter);
1400 if (sbmlRule == NULL)
1412 std::ostringstream os;
1413 os <<
"Error while importing rule for variable \"";
1414 os << sbmlRule->getVariable() <<
"\".";
1422 os << text.substr(text.find(
"\n"));
1433 if (sbmlModel->getNumConstraints() > 0)
1464 if (this->mRateRuleForSpeciesReferenceIgnored ==
true)
1469 if (this->mEventAssignmentForSpeciesReferenceIgnored ==
true)
1474 if (this->mConversionFactorFound ==
true)
1479 if (this->mEventPrioritiesIgnored ==
true)
1484 if (this->mInitialTriggerValues ==
true)
1489 if (this->mNonPersistentTriggerFound ==
true)
1508 it->first->setHasOnlySubstanceUnits(
false);
1519 this->applyConversionFactors();
1528 ListOf* pList = sbmlModel->getListOfParameters();
1529 unsigned i, iMax = pList->size();
1531 for (i = 0; i < iMax; ++i)
1533 if (pList->get(i)->getId() == pParameter->getId())
1541 delete pTmpFunctionDB;
1561 const std::string& sNamespace,
1562 const std::string& elementName,
1563 const std::string& definition)
1565 FunctionDefinition* current =
const_cast<FunctionDefinition*
>(sbmlFunction);
1567 if (current == NULL)
return "";
1569 if (!current->isSetAnnotation())
return "";
1571 const XMLNode* element = current->getAnnotation();
1573 if (element == NULL)
return "";
1575 for (
unsigned int i = 0 ; i < element->getNumChildren(); ++i)
1577 const XMLNode& annot = element->getChild(i);
1579 if (annot.getURI() == sNamespace &&
1580 annot.getName() == elementName &&
1581 annot.getAttrValue(
"definition") == definition)
1583 return current->getId();
1592 if (!sbmlFunction->isSetAnnotation())
1596 "http://sbml.org/annotations/symbols",
1598 "http://en.wikipedia.org/wiki/Derivative");
1607 "http://sbml.org/annotations/distribution",
1609 "http://www.uncertml.org/distributions/normal");
1613 map[id] =
"RNORMAL";
1618 "http://sbml.org/annotations/distribution",
1620 "http://www.uncertml.org/distributions/uniform");
1624 map[id] =
"RUNIFORM";
1629 "http://sbml.org/annotations/distribution",
1631 "http://www.uncertml.org/distributions/gamma");
1640 "http://sbml.org/annotations/distribution",
1642 "http://www.uncertml.org/distributions/poisson");
1646 map[id] =
"RPOISSON";
1656 const char* a =
static_cast<const ASTNode *
>(s1)->getName();
1657 const char* b =
static_cast<const ASTNode *
>(s2)->getName();
1659 if (a == NULL && b == NULL)
return 0;
1661 if (a == NULL && b != NULL)
return -1;
1663 if (a != NULL && b == NULL)
return 1;
1677 if (sbmlFunction == NULL || sbmlFunction->getNumArguments() == 0 || sbmlFunction->getBody() == NULL)
return;
1680 List *variables = sbmlFunction->getBody()->getListOfNodes(ASTNode_isName);
1683 std::vector<std::string> unused;
1685 for (
unsigned int i = 0; i < sbmlFunction->getNumArguments(); ++i)
1687 const ASTNode *arg = sbmlFunction->getArgument(i);
1689 if (variables->find(arg,
AstStrCmp) == NULL)
1691 if (arg->getName() != NULL)
1692 unused.push_back(arg->getName());
1700 if (unused.size() == 0)
1704 std::stringstream str;
1707 for (
unsigned int i = 0; i < sbmlFunction->getNumArguments(); ++i)
1708 str << sbmlFunction->getArgument(i)->getName() <<
", ";
1710 char* formula = SBML_formulaToString(sbmlFunction->getBody());
1713 std::vector<std::string>::iterator it;
1715 for (it = unused.begin(); it != unused.end(); ++it)
1716 str <<
" + 0*" << *it;
1721 const_cast<FunctionDefinition*
>(sbmlFunction)->setMath(SBML_parseFormula(str.str().c_str()));
1736 if (pTmpFunction == NULL)
1742 std::string sbmlId = sbmlFunction->getId();
1751 for (i = 0; i < iMax; ++i)
1761 std::string functionName = sbmlFunction->getName();
1763 if (functionName ==
"")
1765 functionName = sbmlFunction->getId();
1768 unsigned int counter = 1;
1769 std::ostringstream numberStream;
1770 std::string appendix =
"";
1778 pTmpFunction = pExistingFunction;
1784 numberStream.str(
"");
1785 numberStream <<
"_" << counter;
1787 appendix = numberStream.str();
1790 if (pTmpFunction != pExistingFunction)
1794 pTmpFunctionDB->
add(pTmpFunction,
false);
1803 return pTmpFunction;
1810 if (!pSBMLFunction->isSetMath())
1822 if (root.getType() != AST_LAMBDA)
1832 unsigned int i, iMax = root.getNumChildren() - 1;
1833 std::set<std::string> variableNames;
1835 for (i = 0; i < iMax; ++i)
1837 ASTNode* pVarNode = root.getChild(i);
1839 if (pVarNode->getType() != AST_NAME)
1846 variableNames.insert(pVarNode->getName());
1852 std::ostringstream sstream;
1853 std::string timeVariableName =
"time";
1854 unsigned int postfix = 1;
1856 while (variableNames.find(timeVariableName) != variableNames.end())
1859 sstream <<
"time_" << postfix;
1860 timeVariableName = sstream.str();
1867 ASTNode* pVarNode =
new ASTNode(AST_NAME);
1868 pVarNode->setName(timeVariableName.c_str());
1869 ASTNode* pTmpNode = root.removeChild(iMax);
1870 root.addChild(pVarNode);
1871 root.addChild(pTmpNode);
1878 pFun->
setTree(*root.getChild(iMax));
1882 if (dynamic_cast<CEvaluationNodeObject*>(&(*treeIt)))
1889 while (treeIt != NULL)
1891 if (dynamic_cast<CEvaluationNodeObject*>(&(*treeIt)))
1895 if ((*treeIt).getParent())
1897 (*treeIt).getParent()->addChild(pVariableNode, &(*treeIt));
1898 (*treeIt).getParent()->removeChild(&(*treeIt));
1902 treeIt = pVariableNode;
1933 if ((*it)->getKey() == key)
1952 if (sbmlCompartment->isSetUnits())
1954 std::string cU = sbmlCompartment->
getUnits();
1957 unsigned int dimensionality = 3;
1959 if (sbmlCompartment->isSetSpatialDimensions())
1961 dimensionality = sbmlCompartment->getSpatialDimensions();
1965 double dDimensionality = sbmlCompartment->getSpatialDimensions();
1969 dDimensionality = sbmlCompartment->getSpatialDimensionsAsDouble();
1976 dDimensionality -= dimensionality;
1978 if (fabs(dDimensionality) > 1e-9)
1990 if (dimensionality > 3)
1993 "Reaction with id \"%s\" has dimensions of %d, this is not supported by COPASI. COPASI will assume that the compartment is three dimensional."
1994 , sbmlCompartment->getId().c_str(), dimensionality);
1999 std::string name = sbmlCompartment->getName();
2003 name = sbmlCompartment->getId();
2006 std::string appendix =
"";
2007 unsigned int counter = 2;
2008 std::ostringstream numberStream;
2012 numberStream.str(
"");
2013 numberStream <<
"_" << counter;
2015 appendix = numberStream.str();
2023 copasiCompartment->
setSBMLId(sbmlCompartment->getName());
2027 copasiCompartment->
setSBMLId(sbmlCompartment->getId());
2036 copasi2sbmlmap[copasiCompartment] =
const_cast<Compartment*
>(sbmlCompartment);
2037 return copasiCompartment;
2046 if (sbmlSpecies->isSetSubstanceUnits())
2048 std::string cU = sbmlSpecies->getSubstanceUnits();
2051 std::map<CCopasiObject*, SBase*>::iterator it = copasi2sbmlmap.find(copasiCompartment);
2053 if (it == copasi2sbmlmap.end())
2058 Compartment* pSBMLCompartment = (Compartment*)it->second;
2060 if (sbmlSpecies->getHasOnlySubstanceUnits() ==
true)
2062 this->
mSubstanceOnlySpecies.insert(std::make_pair(const_cast<Species*>(sbmlSpecies), pSBMLCompartment));
2065 std::string name = sbmlSpecies->getName();
2069 name = sbmlSpecies->getId();
2072 std::string appendix =
"";
2073 unsigned int counter = 2;
2074 std::ostringstream numberStream;
2078 numberStream.str(
"");
2079 numberStream <<
"_" << counter;
2081 appendix = numberStream.str();
2086 if (copasiMetabolite == NULL)
2092 if (sbmlSpecies->getConstant() || sbmlSpecies->getBoundaryCondition())
2104 if (pSBMLCompartment->isSetSpatialDimensions() && pSBMLCompartment->getSpatialDimensions() == 0 && this->
mLevel < 3)
2106 this->
mSubstanceOnlySpecies.insert(std::make_pair(const_cast<Species*>(sbmlSpecies), pSBMLCompartment));
2110 copasi2sbmlmap[copasiMetabolite] =
const_cast<Species*
>(sbmlSpecies);
2114 copasiMetabolite->
setSBMLId(sbmlSpecies->getName());
2118 copasiMetabolite->
setSBMLId(sbmlSpecies->getId());
2123 return copasiMetabolite;
2128 size_t i, iMax = db.
size();
2130 for (i = 0; i < iMax; ++i)
2148 if (sbmlReaction == NULL)
2153 std::string name = sbmlReaction->getName();
2157 name = sbmlReaction->getId();
2161 std::string appendix =
"";
2162 unsigned int counter = 2;
2163 std::ostringstream numberStream;
2167 numberStream.str(
"");
2168 numberStream <<
"_" << counter;
2170 appendix = numberStream.str();
2176 if (copasiReaction == NULL)
2181 copasiReaction->
setReversible(sbmlReaction->getReversible());
2185 copasiReaction->
setSBMLId(sbmlReaction->getName());
2189 copasiReaction->
setSBMLId(sbmlReaction->getId());
2192 copasi2sbmlmap[copasiReaction] =
const_cast<Reaction*
>(sbmlReaction);
2194 if (sbmlReaction->isSetFast() && sbmlReaction->getFast() ==
true)
2196 const_cast<Reaction*
>(sbmlReaction)->setFast(
false);
2201 bool mConversionFactorNeeded =
false;
2204 unsigned int num = sbmlReaction->getNumReactants();
2205 bool singleCompartment =
true;
2207 bool hasOnlySubstanceUnitPresent =
false;
2208 bool ignoreMassAction =
false;
2210 for (counter = 0; counter < num; counter++)
2212 const SpeciesReference* sr = sbmlReaction->getReactant(counter);
2216 delete copasiReaction;
2225 if (sr->isSetStoichiometryMath())
2227 ignoreMassAction =
true;
2231 stoi = sr->getStoichiometry() / sr->getDenominator();
2237 if (sr->isSetId() &&
2238 (pSBMLModel->getInitialAssignment(sr->getId()) ||
2239 pSBMLModel->getRule(sr->getId())))
2241 ignoreMassAction =
true;
2244 if (sr->isSetStoichiometry())
2246 stoi = sr->getStoichiometry();
2250 std::map<std::string, CMetab*>::iterator pos;
2251 pos = this->
speciesMap.find(sr->getSpecies());
2256 delete copasiReaction;
2262 if (this->mpModelConversionFactor != NULL || this->mSpeciesConversionParameterMap.find(pos->second->getSBMLId()) != this->mSpeciesConversionParameterMap.end())
2264 mConversionFactorNeeded =
true;
2268 std::map<CCopasiObject*, SBase*>::const_iterator spos = copasi2sbmlmap.find(pos->second);
2269 assert(spos != copasi2sbmlmap.end());
2270 Species* pSBMLSpecies =
dynamic_cast<Species*
>(spos->second);
2271 assert(pSBMLSpecies != NULL);
2272 hasOnlySubstanceUnitPresent = (hasOnlySubstanceUnitPresent | (pSBMLSpecies->getHasOnlySubstanceUnits() ==
true));
2274 if (compartment == NULL)
2276 compartment = pos->second->getCompartment();
2280 if (singleCompartment && compartment != pos->second->getCompartment())
2282 singleCompartment =
false;
2286 copasiReaction->
addSubstrate(pos->second->getKey(), stoi);
2298 if ((*it)->getMetaboliteKey() == pos->second->getKey())
2307 assert(pElement != NULL);
2309 if (pElement != NULL)
2311 copasi2sbmlmap[pElement] =
const_cast<SpeciesReference*
>(sr);
2313 this->mChemEqElementSpeciesIdMap[pElement] = std::pair<std::string, CChemEq::MetaboliteRole>(sr->getSpecies(),
CChemEq::SUBSTRATE);
2318 if (this->mLevel < 3 && sr->isSetStoichiometryMath())
2327 if ((*it)->getMetabolite() == pos->second)
2329 pChemEqElement = (*it);
2336 assert(pChemEqElement != NULL);
2342 num = sbmlReaction->getNumProducts();
2344 for (counter = 0; counter < num; counter++)
2346 const SpeciesReference* sr = sbmlReaction->getProduct(counter);
2350 delete copasiReaction;
2358 if (sr->isSetStoichiometryMath())
2360 ignoreMassAction =
true;
2364 stoi = sr->getStoichiometry() / sr->getDenominator();
2370 if (sr->isSetId() &&
2371 (pSBMLModel->getInitialAssignment(sr->getId()) ||
2372 pSBMLModel->getRule(sr->getId())))
2374 ignoreMassAction =
true;
2377 if (sr->isSetStoichiometry())
2379 stoi = sr->getStoichiometry();
2383 std::map<std::string, CMetab*>::iterator pos;
2384 pos = this->
speciesMap.find(sr->getSpecies());
2388 delete copasiReaction;
2394 if (this->mpModelConversionFactor != NULL || this->mSpeciesConversionParameterMap.find(pos->second->getSBMLId()) != this->mSpeciesConversionParameterMap.end())
2396 mConversionFactorNeeded =
true;
2400 std::map<CCopasiObject*, SBase*>::const_iterator spos = copasi2sbmlmap.find(pos->second);
2401 assert(spos != copasi2sbmlmap.end());
2402 Species* pSBMLSpecies =
dynamic_cast<Species*
>(spos->second);
2403 assert(pSBMLSpecies != NULL);
2404 hasOnlySubstanceUnitPresent = (hasOnlySubstanceUnitPresent | (pSBMLSpecies->getHasOnlySubstanceUnits() ==
true));
2406 if (compartment == NULL)
2408 compartment = pos->second->getCompartment();
2412 if (singleCompartment && compartment != pos->second->getCompartment())
2414 singleCompartment =
false;
2418 copasiReaction->
addProduct(pos->second->getKey(), stoi);
2430 if ((*it)->getMetaboliteKey() == pos->second->getKey())
2439 assert(pElement != NULL);
2441 if (pElement != NULL)
2443 copasi2sbmlmap[pElement] =
const_cast<SpeciesReference*
>(sr);
2444 this->mChemEqElementSpeciesIdMap[pElement] = std::pair<std::string, CChemEq::MetaboliteRole>(sr->getSpecies(),
CChemEq::PRODUCT);
2448 if (sr->isSetStoichiometryMath())
2457 if ((*it)->getMetabolite() == pos->second)
2459 pChemEqElement = (*it);
2466 assert(pChemEqElement != NULL);
2472 num = sbmlReaction->getNumModifiers();
2474 for (counter = 0; counter < num; counter++)
2476 const ModifierSpeciesReference* sr = sbmlReaction->getModifier(counter);
2480 delete copasiReaction;
2484 std::map<std::string, CMetab*>::iterator pos;
2485 pos = this->
speciesMap.find(sr->getSpecies());
2489 delete copasiReaction;
2493 std::map<CCopasiObject*, SBase*>::const_iterator spos = copasi2sbmlmap.find(pos->second);
2494 assert(spos != copasi2sbmlmap.end());
2495 Species* pSBMLSpecies =
dynamic_cast<Species*
>(spos->second);
2496 assert(pSBMLSpecies != NULL);
2497 hasOnlySubstanceUnitPresent = (hasOnlySubstanceUnitPresent | (pSBMLSpecies->getHasOnlySubstanceUnits() ==
true));
2498 copasiReaction->
addModifier(pos->second->getKey());
2511 if ((*it)->getMetaboliteKey() == pos->second->getKey())
2520 assert(pElement != NULL);
2522 if (pElement != NULL)
2524 copasi2sbmlmap[pElement] =
const_cast<ModifierSpeciesReference*
>(sr);
2532 const KineticLaw* kLaw = sbmlReaction->getKineticLaw();
2536 const ListOfParameters* pParamList = NULL;
2540 pParamList = kLaw->getListOfLocalParameters();
2544 pParamList = kLaw->getListOfParameters();
2547 for (counter = 0; counter < pParamList->size(); ++counter)
2549 const Parameter* pSBMLParameter = pParamList->get(counter);
2554 id = pSBMLParameter->getName();
2558 id = pSBMLParameter->getId();
2563 if (pSBMLParameter->isSetValue() && pSBMLParameter->getValue() == pSBMLParameter->getValue())
2565 value = pSBMLParameter->getValue();
2571 value = std::numeric_limits<C_FLOAT64>::quiet_NaN();
2583 const ASTNode* kLawMath = kLaw->getMath();
2585 if (kLawMath == NULL || kLawMath->getType() == AST_UNKNOWN)
2599 this->
preprocessNode(node, pSBMLModel, copasi2sbmlmap, sbmlReaction);
2603 delete copasiReaction;
2612 if (singleCompartment)
2615 if (compartment != NULL)
2630 if (node->getType() == AST_DIVIDE && node->getNumChildren() != 2)
2639 tmpNode1->setType(AST_DIVIDE);
2640 tmpNode1->addChild(node);
2642 tmpNode2->setType(AST_NAME);
2643 tmpNode2->setName(compartment->
getSBMLId().c_str());
2644 tmpNode1->addChild(tmpNode2);
2646 std::map<CCopasiObject*, SBase*>::const_iterator pos = copasi2sbmlmap.find(const_cast<CCompartment*>(compartment));
2647 assert(pos != copasi2sbmlmap.end());
2648 Compartment* pSBMLCompartment =
dynamic_cast<Compartment*
>(pos->second);
2649 assert(pSBMLCompartment != NULL);
2651 if (!hasOnlySubstanceUnitPresent && ((this->
mLevel == 1 && pSBMLCompartment->isSetVolume()) || (this->
mLevel >= 2 && pSBMLCompartment->isSetSize())) && pSBMLCompartment->getSize() == 1.0)
2656 if (node->getChild(0)->getType() == AST_FUNCTION && (!this->
containsVolume(node->getChild(0), compartment->
getSBMLId())))
2668 delete copasiReaction;
2683 if (pExpressionTreeRoot)
2686 KineticLawExpression.
setRoot(pExpressionTreeRoot);
2691 if (pParamObject != NULL)
2695 assert(dynamic_cast<const CCopasiParameter*>(pParamObject) || dynamic_cast<const CModelValue*>(pParamObject));
2696 std::string functionName;
2701 functionName =
"Constant flux (reversible)";
2706 functionName =
"Constant flux (irreversible)";
2710 assert(pCFFun != NULL);
2722 assert(pCallNode != NULL);
2733 this->
doMapping(copasiReaction, pCallNode);
2742 std::string functionName = pExpressionTreeRoot->
getData();
2744 assert(pImportedFunction);
2745 std::vector<CEvaluationNodeObject*>* v = NULL;
2749 if (!mConversionFactorNeeded && !ignoreMassAction)
2759 if (v && !v->empty())
2779 size_t i, iMax = v->size();
2781 for (i = 0; i < iMax; ++i)
2788 this->
doMapping(copasiReaction, pCallNode);
2798 if (pExistingFunction)
2802 doMapping(copasiReaction, dynamic_cast<const CEvaluationNodeCall*>(pExpressionTreeRoot));
2808 std::map<std::string, std::string > arguments;
2811 size_t i, iMax = funParams.
size();
2813 for (i = 0; (i < iMax) && pTmpNode; ++i)
2821 assert((i == iMax) && pTmpNode == NULL);
2826 TmpTree2.
setRoot(pTmpExpression);
2832 TmpTree2.setObjectName(functionName);
2836 if (pNewFunction != NULL &&
2847 pTmpFunctionDB->
add(pNewFunction,
false);
2857 std::vector<CEvaluationNodeObject*>* v = NULL;
2861 if (!mConversionFactorNeeded && !ignoreMassAction)
2871 if (v && !v->empty())
2891 size_t i, iMax = v->size();
2893 for (i = 0; i < iMax; ++i)
2901 this->
doMapping(copasiReaction, pCallNode);
2908 if (pNonconstFun != NULL &&
2919 pTmpFunctionDB->
add(pNonconstFun,
false);
2945 return copasiReaction;
2952 std::map<std::string, ASTNode*>
2959 if (uDefFunction->getNumChildren() !=
function->getNumChildren() + 1)
2961 std::string functionName = uDefFunction->getName();
2965 std::map<std::string, ASTNode*> varMap;
2966 unsigned int counter;
2968 for (counter = 0; counter < uDefFunction->getNumChildren() - 1; counter++)
2970 varMap[uDefFunction->getChild(counter)->getName()] =
function->getChild(counter);
2980 const FunctionDefinition*
2983 const FunctionDefinition* fDef = NULL;
2984 unsigned int counter;
2986 for (counter = 0; counter < sbmlModel->getNumFunctionDefinitions(); counter++)
2988 std::string functionName = sbmlModel->getFunctionDefinition(counter)->getName();
2990 if (sbmlModel->getFunctionDefinition(counter)->isSetId())
2992 functionName = sbmlModel->getFunctionDefinition(counter)->getId();
2995 if (functionName == name)
2997 fDef = sbmlModel->getFunctionDefinition(counter);
3012 SBMLImporter::replaceBvars(
const ASTNode* node, std::map<std::string, ASTNode*> bvarMap)
3021 if (bvarMap.find(node->getName()) != bvarMap.end())
3030 unsigned int counter;
3032 for (counter = 0; counter < node->getNumChildren(); counter++)
3034 newNode->addChild(this->replaceBvars(node->getChild(counter), bvarMap));
3046 mIgnoredSBMLMessages(),
3049 mIncompleteModel(false),
3050 mUnsupportedRuleFound(false),
3051 mUnsupportedRateRuleFound(false),
3052 mUnsupportedAssignmentRuleFound(false),
3053 mUnitOnNumberFound(false),
3054 mAssignmentToSpeciesReferenceFound(false),
3061 mpCopasiModel(NULL),
3062 mFunctionNameMapping(),
3063 mDivisionByCompartmentReactions(),
3064 mpImportHandler(NULL),
3068 mSubstanceOnlySpecies(),
3070 mReactionsWithReplacedLocalParameters(),
3071 mExplicitelyTimeDependentFunctionDefinitions(),
3072 mIgnoredParameterUnits(),
3073 mStoichiometricExpressionMap(),
3075 mPotentialAvogadroNumbers(),
3076 mAvogadroCreated(false),
3077 mImportCOPASIMIRIAM(true),
3080 mUsedSBMLIdsPopulated(false),
3081 mAvogadroSet(false),
3082 mKnownCustomUserDefinedFunctions(),
3083 #
if LIBSBML_VERSION >= 40100
3084 mpModelConversionFactor(NULL),
3085 mChemEqElementSpeciesIdMap(),
3086 mSpeciesConversionParameterMap(),
3087 mSBMLIdModelValueMap(),
3088 mSBMLSpeciesReferenceIds(),
3089 mRateRuleForSpeciesReferenceIgnored(false),
3090 mEventAssignmentForSpeciesReferenceIgnored(false),
3091 mConversionFactorFound(false),
3092 #
if LIBSBML_VERSION >= 40200
3093 mEventPrioritiesIgnored(false),
3094 mInitialTriggerValues(false),
3095 mNonPersistentTriggerFound(false)
3099 this->
speciesMap = std::map<std::string, CMetab*>();
3112 this->mpModelConversionFactor = NULL;
3113 this->mChemEqElementSpeciesIdMap.clear();
3114 this->mSpeciesConversionParameterMap.clear();
3115 this->mSBMLIdModelValueMap.clear();
3116 this->mRateRuleForSpeciesReferenceIgnored =
false;
3117 this->mEventAssignmentForSpeciesReferenceIgnored =
false;
3118 this->mConversionFactorFound =
false;
3119 this->mEventPrioritiesIgnored =
false;
3120 this->mInitialTriggerValues =
false;
3121 this->mNonPersistentTriggerFound =
false;
3188 SBMLDocument*& pSBMLDocument,
3189 std::map<CCopasiObject*, SBase*>& copasi2sbmlmap,
3201 std::ostringstream stringStream;
3211 return this->
parseSBML(stringStream.str(), funDB,
3212 pSBMLDocument, copasi2sbmlmap, prLol, pDataModel);
3223 SBMLDocument *& pSBMLDocument,
3224 std::map<CCopasiObject*, SBase*>& copasi2sbmlmap,
3238 SBMLReader* reader =
new SBMLReader();
3251 unsigned C_INT32 step = 0, totalSteps = 0;
3263 SBMLDocument* sbmlDoc = reader->readSBMLFromString(sbmlDocumentText);
3277 sbmlDoc->setApplicableValidators(AllChecksON);
3279 sbmlDoc->setApplicableValidators(AllChecksON & UnitsCheckOFF);
3281 #if LIBSBML_VERSION > 50800
3287 bool checkResult = sbmlDoc->checkConsistency();
3289 #if LIBSBML_VERSION > 50800
3297 sbmlDoc->getErrorLog()->changeErrorSeverity(LIBSBML_SEV_ERROR, LIBSBML_SEV_WARNING,
"layout");
3302 if (checkResult != 0)
3305 unsigned int i, iMax = sbmlDoc->getNumErrors();
3307 for (i = 0; (i < iMax) && (fatal == -1); ++i)
3309 const XMLError* pSBMLError = sbmlDoc->getError(i);
3312 if (sbmlDoc->getLevel() > 2 && pSBMLError->getErrorId() == 99107)
3319 switch (pSBMLError->getSeverity())
3321 case LIBSBML_SEV_INFO:
3332 CCopasiMessage(messageType,
MCSBML + 40,
"INFO", pSBMLError->getErrorId(), pSBMLError->getLine(), pSBMLError->getColumn(), pSBMLError->getMessage().c_str());
3335 case LIBSBML_SEV_WARNING:
3337 #if LIBSBML_VERSION > 50800
3340 if (pSBMLError->getPackage() ==
"layout")
3353 CCopasiMessage(messageType,
MCSBML + 40,
"WARNING", pSBMLError->getErrorId(), pSBMLError->getLine(), pSBMLError->getColumn(), pSBMLError->getMessage().c_str());
3356 case LIBSBML_SEV_ERROR:
3363 CCopasiMessage(messageType,
MCSBML + 40,
"ERROR", pSBMLError->getErrorId(), pSBMLError->getLine(), pSBMLError->getColumn(), pSBMLError->getMessage().c_str());
3366 case LIBSBML_SEV_FATAL:
3372 if (pSBMLError->getErrorId() == 10804)
3377 CCopasiMessage(messageType,
MCSBML + 40,
"ERROR", pSBMLError->getErrorId(), pSBMLError->getLine(), pSBMLError->getColumn(), pSBMLError->getMessage().c_str());
3392 const XMLError* pSBMLError = sbmlDoc->getError(fatal);
3394 pSBMLError->getLine(),
3395 pSBMLError->getColumn(),
3396 pSBMLError->getMessage().c_str());
3405 if (sbmlDoc->getLevel() > 2)
3408 unsigned int i, iMax = sbmlDoc->getNumErrors();
3410 for (i = 0; i < iMax ; ++i)
3412 const XMLError* pSBMLError = sbmlDoc->getError(i);
3414 if (pSBMLError->getErrorId() == 99107)
3416 if (pSBMLError->getMessage().find(
"'spatial'") != std::string::npos)
3419 "The model you tried to open requires the SBML spatial package. "
3420 "This version of COPASI does not support spatial models.");
3431 #if LIBSBML_VERSION >= 50700
3433 if (sbmlDoc->getPlugin(
"comp") != NULL && sbmlDoc->isSetPackageRequired(
"comp"))
3436 if (sbmlDoc->getNumErrors(LIBSBML_SEV_ERROR) > 0)
3438 std::string message =
3439 "The SBML model you are trying to import uses the Hierarchical Modeling extension. "
3440 "In order to import this model in COPASI, it has to be flattened, however flattening is "
3441 "not possible because of the following errors:\n" + sbmlDoc->getErrorLog()->toString();
3444 CPrefixNameTransformer::replaceStringInPlace(message,
"%",
"%%");
3449 #if LIBSBML_VERSION >= 50903 && LIBSBML_HAS_PACKAGE_COMP
3451 CompModelPlugin* mPlug =
dynamic_cast<CompModelPlugin*
>(sbmlDoc->getModel()->getPlugin(
"comp"));
3452 CPrefixNameTransformer trans;
3456 mPlug->setTransformer(&trans);
3459 #endif //LIBSBML_VERSION >= 50903 && LIBSBML_HAS_PACKAGE_COMP
3463 sbmlDoc->getErrorLog()->clearLog();
3465 ConversionProperties props;
3466 props.addOption(
"flatten comp");
3467 props.addOption(
"leavePorts",
false);
3470 if (sbmlDoc->convert(props) != LIBSBML_OPERATION_SUCCESS)
3472 std::string message =
3473 "The SBML model you are trying to import uses the Hierarchical Modeling extension. "
3474 "In order to import this model in COPASI, it has to be flattened, however flattening failed";
3476 if (sbmlDoc->getNumErrors() == 0)
3479 message +=
" with the following errors:\n" + sbmlDoc->getErrorLog()->toString();
3487 if (sbmlDoc->getModel() == NULL)
3497 pSBMLDocument = sbmlDoc;
3498 this->
mLevel = pSBMLDocument->getLevel();
3504 this->
mVersion = pSBMLDocument->getVersion();
3508 unsigned int i, iMax = pSBMLDocument->getModel()->getNumCompartments();
3510 for (i = 0; i < iMax; ++i)
3512 Compartment* pCompartment = pSBMLDocument->getModel()->getCompartment(i);
3513 pCompartment->setSize(pCompartment->getVolume());
3516 pSBMLDocument->setLevelAndVersion(2, 1);
3517 mLevel = pSBMLDocument->getLevel();
3523 Model* sbmlmodel = pSBMLDocument->getModel();
3525 if (sbmlmodel && prLol)
3527 LayoutModelPlugin *lmPlugin = (LayoutModelPlugin*)sbmlmodel->getPlugin(
"layout");
3529 if (lmPlugin != NULL)
3531 *lmPlugin->getListOfLayouts(),
3551 std::pair<CModel::QuantityUnit, bool>
3554 bool result =
false;
3563 if (uDef->getNumUnits() == 1)
3565 const Unit* u = uDef->getUnit(0);
3573 if ((u->getKind() == UNIT_KIND_MOLE)
3574 || u->getKind() == UNIT_KIND_AVOGADRO
3577 double multiplier = u->getMultiplier();
3578 int scale = u->getScale();
3580 if (multiplier != 1)
3585 double tmp = log10(multiplier);
3589 scale += (int)
round(tmp);
3594 if ((u->getExponent() == 1) &&
3596 ((scale % 3) == 0) &&
3643 else if ((u->getKind() == UNIT_KIND_ITEM))
3645 double multiplier = u->getMultiplier();
3646 int scale = u->getScale();
3648 if (multiplier != 1)
3653 double tmp = log10(multiplier);
3657 scale += (int)
round(tmp);
3662 if ((u->getExponent() == 1) &&
3664 (scale == 0 || scale == 1))
3666 if (u->getScale() == 1)
3681 else if ((u->getKind() == UNIT_KIND_DIMENSIONLESS))
3683 double multiplier = u->getMultiplier();
3684 int scale = u->getScale();
3686 if (multiplier != 1)
3691 double tmp = log10(multiplier);
3695 scale += (int)
round(tmp);
3700 if ((u->getExponent() == 1) &&
3722 return std::make_pair(qUnit, result);
3729 std::pair<CModel::TimeUnit, bool>
3732 bool result =
false;
3741 if (uDef->getNumUnits() == 1)
3743 const Unit* u = uDef->getUnit(0);
3751 if ((u->getKind() == UNIT_KIND_SECOND))
3753 double multiplier = u->getMultiplier();
3754 int scale = u->getScale();
3769 double tmp = log10(multiplier);
3778 scale += (int)
round(tmp);
3790 double tmp = log10(multiplier);
3795 multiplier *= pow(10.0, (
double)scale);
3802 scale += (int)
round(tmp);
3807 if ((u->getExponent() == 1) && ((scale % 3) == 0) && (scale < 1) && (scale > -16))
3849 else if ((scale == 0) &&
3855 else if ((scale == 0) &&
3861 else if ((scale == 0) &&
3877 else if ((u->getKind() == UNIT_KIND_DIMENSIONLESS))
3879 double multiplier = u->getMultiplier();
3880 int scale = u->getScale();
3882 if (multiplier != 1)
3887 double tmp = log10(multiplier);
3891 scale += (int)
round(tmp);
3896 if ((u->getExponent() == 1) &&
3918 return std::make_pair(tUnit, result);
3925 std::pair<CModel::LengthUnit, bool>
3928 bool result =
false;
3937 if (uDef->getNumUnits() == 1)
3939 const Unit* u = uDef->getUnit(0);
3947 if ((u->getKind() == UNIT_KIND_METRE || u->getKind() == UNIT_KIND_METER) && u->getExponent() == 1)
3949 double multiplier = u->getMultiplier();
3950 int scale = u->getScale();
3952 if (multiplier != 1)
3957 double tmp = log10(multiplier);
3961 scale += (int)
round(tmp);
3967 ((scale % 3) == 0 || scale == -1 || scale == -2) &&
4024 else if ((u->getKind() == UNIT_KIND_DIMENSIONLESS))
4026 double multiplier = u->getMultiplier();
4027 int scale = u->getScale();
4029 if (multiplier != 1)
4034 double tmp = log10(multiplier);
4038 scale += (int)
round(tmp);
4043 if ((u->getExponent() == 1) &&
4065 return std::make_pair(lUnit, result);
4072 std::pair<CModel::AreaUnit, bool>
4075 bool result =
false;
4084 if (uDef->getNumUnits() == 1)
4086 const Unit* u = uDef->getUnit(0);
4094 if ((u->getKind() == UNIT_KIND_METRE || u->getKind() == UNIT_KIND_METER) && u->getExponent() == 2)
4096 double multiplier = u->getMultiplier();
4097 int scale = u->getScale();
4099 if (multiplier != 1)
4104 double tmp = log10(multiplier);
4108 scale += (int)
round(tmp);
4114 ((scale % 3) == 0 || scale == -1 || scale == -2) &&
4171 else if ((u->getKind() == UNIT_KIND_DIMENSIONLESS))
4173 double multiplier = u->getMultiplier();
4174 int scale = u->getScale();
4176 if (multiplier != 1)
4181 double tmp = log10(multiplier);
4185 scale += (int)
round(tmp);
4190 if ((u->getExponent() == 1) &&
4212 return std::make_pair(aUnit, result);
4219 std::pair<CModel::VolumeUnit, bool>
4224 bool result =
false;
4233 if (uDef->getNumUnits() == 1)
4235 const Unit* u = uDef->getUnit(0);
4243 if (((u->getKind() == UNIT_KIND_LITER) || (u->getKind() == UNIT_KIND_LITRE)) && u->getExponent() == 1)
4245 double multiplier = u->getMultiplier();
4246 int scale = u->getScale();
4248 if (multiplier != 1)
4253 double tmp = log10(multiplier);
4257 scale += (int)
round(tmp);
4263 ((scale % 3) == 0) &&
4310 else if (((u->getKind() == UNIT_KIND_METER) || (u->getKind() == UNIT_KIND_METRE)) && u->getExponent() == 3)
4312 double multiplier = u->getMultiplier();
4313 int scale = u->getScale();
4315 if (multiplier != 1)
4320 double tmp = log10(multiplier);
4324 scale += (int)
round(tmp);
4340 if (pLitreUnit != NULL &&
4341 pLitreUnit->getExponent() == 1 &&
4342 (pLitreUnit->getScale() % 3 == 0) &&
4343 (pLitreUnit->getScale() < 1) &&
4344 (pLitreUnit->getScale() > -16) &&
4347 switch (pLitreUnit->getScale())
4392 else if ((u->getKind() == UNIT_KIND_DIMENSIONLESS))
4394 double multiplier = u->getMultiplier();
4395 int scale = u->getScale();
4397 if (multiplier != 1)
4402 double tmp = log10(multiplier);
4406 scale += (int)
round(tmp);
4411 if ((u->getExponent() == 1) &&
4433 return std::make_pair(vUnit, result);
4438 if (sbmlParameter->isSetUnits())
4443 const_cast<Parameter*
>(sbmlParameter)->unsetUnits();
4446 std::string name = sbmlParameter->getName();
4448 if (!sbmlParameter->isSetName())
4450 name = sbmlParameter->getId();
4453 std::string appendix =
"";
4454 unsigned int counter = 2;
4455 std::ostringstream numberStream;
4459 numberStream.str(
"");
4460 numberStream <<
"_" << counter;
4462 appendix = numberStream.str();
4469 sbmlId = sbmlParameter->getName();
4473 sbmlId = sbmlParameter->getId();
4477 copasi2sbmlmap[pMV] =
const_cast<Parameter*
>(sbmlParameter);
4484 this->mSBMLIdModelValueMap[sbmlId] = pMV;
4494 bool success =
true;
4495 unsigned int i, iMax = pNode->getNumChildren();
4497 if (pNode->getType() == AST_NAME)
4499 Compartment* pSBMLCompartment = NULL;
4500 Species* pSBMLSpecies = NULL;
4501 Reaction* pSBMLReaction = NULL;
4502 Parameter* pSBMLParameter = NULL;
4504 std::string name = pNode->getName();
4507 std::map<std::string, double>::const_iterator speciesReference = mSBMLSpeciesReferenceIds.find(name);
4509 if (speciesReference != mSBMLSpeciesReferenceIds.end())
4512 pNode->setType(AST_REAL);
4513 pNode->
setValue(mSBMLSpeciesReferenceIds[name]);
4517 pNode->setName(pParam->
getCN().c_str());
4521 std::map<CCopasiObject*, SBase*>::iterator it = copasi2sbmlmap.begin();
4522 std::map<CCopasiObject*, SBase*>::iterator endIt = copasi2sbmlmap.end();
4527 int type = it->second->getTypeCode();
4531 case SBML_COMPARTMENT:
4532 pSBMLCompartment =
dynamic_cast<Compartment*
>(it->second);
4536 sbmlId = pSBMLCompartment->getName();
4540 sbmlId = pSBMLCompartment->getId();
4543 if (sbmlId == pNode->getName())
4545 pNode->setName(dynamic_cast<CCompartment*>(it->first)->getObject(
CCopasiObjectName(
"Reference=InitialVolume"))->getCN().c_str());
4552 pSBMLSpecies =
dynamic_cast<Species*
>(it->second);
4556 sbmlId = pSBMLSpecies->getName();
4560 sbmlId = pSBMLSpecies->getId();
4563 if (sbmlId == pNode->getName())
4565 pNode->setName(dynamic_cast<CMetab*>(it->first)->getObject(
CCopasiObjectName(
"Reference=InitialConcentration"))->getCN().c_str());
4572 pSBMLReaction =
dynamic_cast<Reaction*
>(it->second);
4576 sbmlId = pSBMLReaction->getName();
4580 sbmlId = pSBMLReaction->getId();
4583 if (sbmlId == pNode->getName())
4585 pNode->setName(dynamic_cast<CReaction*>(it->first)->getObject(
CCopasiObjectName(
"Reference=ParticleFlux"))->getCN().c_str());
4591 case SBML_PARAMETER:
4592 pSBMLParameter =
dynamic_cast<Parameter*
>(it->second);
4596 sbmlId = pSBMLParameter->getName();
4600 sbmlId = pSBMLParameter->getId();
4603 if (sbmlId == pNode->getName())
4605 pNode->setName(dynamic_cast<CModelValue*>(it->first)->getValueReference()->getCN().c_str());
4618 if (!found) success =
false;
4622 for (i = 0; i < iMax; ++i)
4624 if (!this->
sbmlId2CopasiCN(pNode->getChild(i), copasi2sbmlmap, pParamGroup))
4635 void SBMLImporter::printMap(
const std::map<CCopasiObject*, SBase*> & copasi2sbml)
4637 std::map<CCopasiObject*, SBase*>::const_iterator it = copasi2sbml.begin();
4638 std::map<CCopasiObject*, SBase*>::const_iterator end = copasi2sbml.end();
4639 std::cout <<
"Number of elements: " << copasi2sbml.size() << std::endl;
4643 std::cout <<
"(@" << it->first <<
")" << it->first->getObjectName() <<
" : " <<
"(@" << it->second <<
")" << it->second->getTypeCode() << std::endl;
4647 std::cout << std::endl;
4649 #endif // COPASI_DEBUG
4654 std::map<CFunction*, std::string>::iterator it = this->
sbmlIdMap.begin();
4655 std::map<CFunction*, std::string>::iterator endIt = this->
sbmlIdMap.end();
4659 it->first->setSBMLId(it->second);
4664 std::set<std::string>::iterator it2 = this->
mUsedFunctions.begin();
4665 std::set<std::string>::iterator endIt2 = this->
mUsedFunctions.end();
4667 while (it2 != endIt2)
4702 if (pSBMLReaction != NULL && result)
4708 std::map<std::string, const SBase*> idMap;
4709 std::map<std::string, const SBase*> metaIdMap;
4713 std::map<std::string, const SBase*>::iterator it = idMap.begin(), endit = idMap.end();
4727 std::map<std::string, std::string> replacementMap;
4728 this->
replace_delay_nodes(pNode, pSBMLModel, copasi2sbmlmap, pSBMLReaction, replacementMap);
4730 if (!replacementMap.empty())
4737 std::map<std::string, std::string>::const_iterator it = replacementMap.begin(), endit = replacementMap.end();
4743 ListOfParameters* pList = NULL;
4747 pList = pSBMLReaction->getKineticLaw()->getListOfLocalParameters();
4751 pList = pSBMLReaction->getKineticLaw()->getListOfParameters();
4754 Parameter* pParam = NULL;
4758 pParam = pList->remove(it->first);
4759 assert(pParam != NULL);
4795 while (itNode.
next() != itNode.
end())
4797 if (*itNode == NULL)
4807 if (itNode->getType() == AST_TIMES && itNode->getNumChildren() == 2)
4812 ASTNode* pChild1 = itNode->getChild(0);
4813 ASTNode* pChild2 = itNode->getChild(1);
4814 assert(pChild1 != NULL);
4815 assert(pChild2 != NULL);
4817 if (pChild1->getType() == AST_NAME && pChild2->getType() == AST_NAME)
4819 std::string id1 = pChild1->getName();
4820 std::string id2 = pChild2->getName();
4821 ASTNode *pAvogadro = NULL, *pSpecies = NULL;
4823 if (pChild1 != NULL && pChild2 != NULL)
4825 while (avoIt != avoEndit)
4827 if (id1 == (*avoIt)->getId())
4829 pAvogadro = pChild1;
4835 else if (id2 == (*avoIt)->getId())
4837 pAvogadro = pChild2;
4845 if (pAvogadro != NULL)
4854 if (it->first->getId() == id1)
4863 itNode->setType(AST_NAME);
4864 itNode->setName(id1.c_str());
4874 else if ((pChild1->getType() == AST_NAME && (pChild2->getType() == AST_REAL || pChild2->getType() == AST_REAL_E)) ||
4875 (pChild2->getType() == AST_NAME && (pChild1->getType() == AST_REAL || pChild1->getType() == AST_REAL_E)))
4880 if (pChild1->getType() == AST_NAME)
4882 value = pChild2->getMantissa() * pow(10.0, (
double)pChild2->getExponent());
4883 id = pChild1->getName();
4887 value = pChild1->getMantissa() * pow(10.0, (
double)pChild1->getExponent());
4888 id = pChild2->getName();
4898 if (it->first->getId() == id)
4907 itNode->setType(AST_NAME);
4908 itNode->setName(
id.c_str());
4918 else if (itNode->getType() == AST_NAME)
4921 std::string
id = itNode->getName();
4927 if (it->first->getId() == id)
4944 itNode->setType(AST_DIVIDE);
4945 itNode->setCharacter(
'/');
4947 pChild->setName(
id.c_str());
4948 itNode->addChild(pChild);
4951 pChild->setName(
id.c_str());
4952 itNode->addChild(pChild);
4960 bool result =
false;
4963 while (itNode.
next() != itNode.
end())
4965 if (*itNode == NULL)
4970 if (itNode->getType() == AST_FUNCTION_DELAY)
4984 while (itNode.
next() != itNode.
end())
4986 if (*itNode == NULL)
4991 if (itNode->getType() == AST_NAME_TIME)
4995 else if (itNode->getType() == AST_NAME_AVOGADRO)
5006 while (itNode.
next() != itNode.
end())
5008 if (*itNode == NULL)
5013 if (itNode->getType() == AST_FUNCTION)
5015 std::map<std::string, std::string>::const_iterator pos = this->
mFunctionNameMapping.find(itNode->getName());
5025 (knownPos->second ==
"RATE" && itNode->getNumChildren() == 1))
5029 std::string symbol = itNode->getChild(0)->getName();
5030 itNode->removeChild(0);
5031 itNode->setType(AST_NAME);
5032 itNode->setName(symbol.c_str());
5033 itNode->setUserData(strdup(
"RATE"));
5037 std::string newName = pos->second;
5038 itNode->setName(newName.c_str());
5057 CFunction* pCorrespondingFunction = NULL;
5062 if (pCorrespondingFunction != NULL)
5066 for (
size_t i = 0; i < Variables.
size(); ++i)
5071 pCorrespondingFunction = NULL;
5077 if (pCorrespondingFunction != NULL)
5079 return pCorrespondingFunction;
5088 size_t i, iMax = functions.size();
5090 for (i = 0; i < iMax; ++i)
5092 pCorrespondingFunction = (functions[i]);
5097 if ((pCorrespondingFunction != tree) && (!
dynamic_cast<CMassAction*
>(pCorrespondingFunction)) &&
areEqualFunctions(pCorrespondingFunction, tree))
5101 for (
size_t i = 0; i < Variables.
size(); ++i)
5105 pCorrespondingFunction = NULL;
5110 pCorrespondingFunction = pFun;
5117 return pCorrespondingFunction;
5127 if (funParams1.
size() == funParams2.
size())
5129 size_t i, iMax = funParams1.
size();
5131 for (i = 0; i < iMax; ++i)
5166 while (result && pChild1 && pChild2)
5173 result = (result && !pChild1 && !pChild2);
5181 std::vector< std::vector< std::string > > functionArgumentCNs;
5184 std::vector<CEvaluationNodeObject*>* result = NULL;
5197 str = pChildNode->
getData().substr(1, pChildNode->
getData().length() - 2);
5198 functionArgumentCNs.push_back(std::vector<std::string>());
5199 functionArgumentCNs[functionArgumentCNs.size() - 1].push_back(str);
5208 result = this->
isMassActionFunction(dynamic_cast<const CFunction*>(pTree), chemicalEquation, functionArgumentCNs);
5226 std::vector<CEvaluationNodeObject*>* v = NULL;
5236 assert(pTmpNode != NULL);
5244 result = (pChildNode != NULL);
5250 size_t i, iMax = metabolites->
size();
5251 result = (iMax > 0);
5255 for (i = 0; i < iMax; ++i)
5268 result = !v->empty();
5273 result = (pChildNode != NULL);
5279 iMax = metabolites->
size();
5280 result = (iMax > 0);
5282 for (i = 0; i < iMax; ++i)
5295 result = !v2->empty();
5299 v->push_back((*v2)[0]);
5312 v =
new std::vector<CEvaluationNodeObject*>;
5318 v =
new std::vector<CEvaluationNodeObject*>;
5327 std::vector<const CEvaluationNode*> arguments;
5328 std::map<const CMetab*, C_FLOAT64> multiplicityMap;
5330 size_t numParameters = 0, i, iMax = arguments.size();
5331 v =
new std::vector<CEvaluationNodeObject*>;
5335 std::vector<CCopasiContainer*> listOfContainers;
5338 for (i = 0; (i < iMax) && (numParameters < 2); ++i)
5347 std::string objectCN = pNode->
getData().substr(1, pNode->
getData().length() - 2);
5359 if (dynamic_cast<const CMetab*>(pObject))
5361 const CMetab* pMetab =
static_cast<const CMetab*
>(pObject);
5363 if (multiplicityMap.find(pMetab) != multiplicityMap.end())
5365 multiplicityMap[pMetab] = multiplicityMap[pMetab] + 1.0;
5369 multiplicityMap[pMetab] = 1.0;
5372 else if (dynamic_cast<const CModelValue*>(pObject))
5383 else if (dynamic_cast<const CCopasiParameter*>(pObject))
5401 std::string objectCN = pChildNode->
getData().substr(1, pChildNode->
getData().length() - 2);
5409 if (dynamic_cast<const CMetab*>(pObject))
5418 const CMetab* pMetab =
static_cast<const CMetab*
>(pObject);
5420 if (multiplicityMap.find(pMetab) != multiplicityMap.end())
5422 multiplicityMap[pMetab] = multiplicityMap[pMetab] + pChildNode->
getValue();
5426 multiplicityMap[pMetab] = pChildNode->
getValue();
5433 const CMetab* pMetab =
static_cast<const CMetab*
>(pObject);
5462 if (numParameters != 1)
5470 size_t i, iMax = metabolites.
size();
5474 if (iMax == 0 || iMax != multiplicityMap.size()) result =
false;
5476 for (i = 0; i < iMax && result; ++i)
5480 std::map<const CMetab*, C_FLOAT64>::iterator pos = multiplicityMap.find(metabolites[i]->getMetabolite());
5482 if (pos == multiplicityMap.end() ||
5505 if (!pExpressionTree)
5512 delete pExpressionTree;
5522 if (pFunParams.
size() == functionArgumentCNs.size())
5524 std::map<std::string , std::string> variable2CNMap;
5525 size_t i, iMax = pFunParams.
size();
5527 for (i = 0; i < iMax; ++i)
5530 assert(functionArgumentCNs[i].size() == 1);
5531 variable2CNMap[pFunParams[i]->
getObjectName()] = functionArgumentCNs[i][0];
5562 arguments.push_back(pObjectNode);
5566 arguments.push_back(pOperatorNode);
5572 if (arguments.empty())
5600 std::vector<CCopasiContainer*> listOfContainers = std::vector<CCopasiContainer*>();
5606 std::map<const CChemEqElement*, CChemEq::MetaboliteRole> v;
5610 size_t i, iMax = pV->
size();
5612 for (i = 0; i < iMax; ++i)
5620 for (i = 0; i < iMax; ++i)
5628 for (i = 0; i < iMax; ++i)
5633 size_t parameterIndex = 0;
5657 if (dynamic_cast<const CMetab*>(
object))
5659 std::map<const CChemEqElement*, CChemEq::MetaboliteRole>::iterator it = v.begin();
5660 std::map<const CChemEqElement*, CChemEq::MetaboliteRole>::iterator endIt = v.end();
5664 if (it->first ==
object)
5698 else if (dynamic_cast<const CModelValue*>(
object))
5703 else if (dynamic_cast<const CCompartment*>(
object))
5729 for (; it != end; ++it)
5731 if ((*it)->getMetaboliteKey() == key)
5749 std::vector<CCopasiContainer*> listOfContainers;
5752 if (dynamic_cast<const CMassAction*>(pCopasiReaction->
getFunction()))
5755 std::string objectCN = pChild->
getData();
5756 objectCN = objectCN.substr(1, objectCN.length() - 2);
5769 const std::string& objectKey = pObject->
getKey();
5775 size_t i, iMax = metabolites->
size();
5779 for (i = 0; i < iMax; ++i)
5780 for (j = 0, jMax = static_cast<int>(fabs((*metabolites)[i]->getMultiplicity())); j < jMax; j++)
5786 std::string objectCN = pChild->
getData();
5787 objectCN = objectCN.substr(1, objectCN.length() - 2);
5800 const std::string& objectKey = pObject->
getKey();
5806 iMax = metabolites->
size();
5808 for (i = 0; i < iMax; ++i)
5809 for (j = 0, jMax = static_cast<int>(fabs((*metabolites)[i]->getMultiplicity())); j < jMax; j++)
5816 size_t i, iMax = Variables.
size();
5819 for (i = 0; i < iMax; ++i)
5826 std::string objectCN = pChild->
getData();
5827 objectCN = objectCN.substr(1, objectCN.length() - 2);
5840 const std::string& objectKey = pObject->
getKey();
5898 if (dynamic_cast<const CEvaluationNodeCall*>(pRootNode))
5910 if (!dynamic_cast<const CEvaluationNodeObject*>(pChildNode))
5931 if (node->getType() == AST_TIMES || node->getType() == AST_DIVIDE)
5934 unsigned int i, iMax = node->getNumChildren();
5937 for (i = 0; i < iMax; ++i)
5939 const ASTNode* child = node->getChild(i);
5941 if (node->getType() == AST_TIMES && child->getType() == AST_NAME && child->getName() == compartmentSBMLId)
5945 else if ((!found) && (child->getType() == AST_TIMES || child->getType() == AST_DIVIDE))
5953 if (pSubResult->getNumChildren() > 1)
5955 pTmpResultNode->addChild(pSubResult);
5957 else if (pSubResult->getNumChildren() == 1)
5959 pTmpResultNode->addChild(static_cast<ASTNode*>(static_cast<ConverterASTNode*>(pSubResult)->removeChild(0)));
5982 if (it->first->getId() == child->getName())
return NULL;
5994 result = pTmpResultNode;
5998 delete pTmpResultNode;
6010 if (dynamic_cast<const CEvaluationNodeVariable*>(pOrigNode))
6012 std::map<std::string , std::string>::const_iterator pos = replacementMap.find(pOrigNode->
getData());
6014 if (pos == replacementMap.end())
fatalError();
6026 pChildNode =
static_cast<const CEvaluationNode*
>(pChildNode->getSibling());
6035 std::vector<CCopasiContainer*> v;
6038 assert(pObjectNode);
6043 if (dynamic_cast<CCopasiParameter*>(pObject))
6057 if (dynamic_cast<CCopasiParameter*>(pObject))
6067 bool result =
false;
6068 unsigned int i, iMax = pNode->getNumChildren();
6070 for (i = 0; i < iMax; ++i)
6072 if (pNode->getChild(i)->getType() == AST_NAME &&
6073 pNode->getChild(i)->getName() == compartmentSBMLId)
6093 unsigned C_INT32 step = 0, totalSteps = 0;
6107 std::set<std::string> functionNameSet;
6109 for (i = 0; i < iMax; ++i)
6119 if (this->mConversionFactorFound)
6128 if (functionNameSet.find(pTree->
getObjectName()) == functionNameSet.end())
6141 for (i = 0; i < iMax; ++i)
6170 for (i = 0; i < iMax; ++i)
6199 for (i = 0; i < iMax; ++i)
6229 for (i = 0; i < iMax; ++i)
6232 assert(pEvent != NULL);
6235 assert(pTree != NULL);
6253 for (j = 0; j < jMax; ++j)
6256 assert(pEventAssignment != NULL);
6258 if (pEventAssignment != NULL)
6262 assert(pTree != NULL);
6290 for (; it != end; ++it)
6294 if (functionNameSet.find(pTree->
getObjectName()) == functionNameSet.end())
6299 std::map<CCopasiObject*, SBase*>::iterator pos = copasi2sbmlmap.find(pTree);
6300 assert(pos != copasi2sbmlmap.end());
6301 copasi2sbmlmap.erase(pos);
6325 while (treeIt != NULL)
6332 if (functionNameSet.find(pTree->
getObjectName()) == functionNameSet.end())
6346 bool stochastic =
false;
6348 const UnitDefinition* pUD = pSBMLModel->getUnitDefinition(
"substance");
6352 stochastic = (pUD->getNumUnits() == 1 &&
6353 pUD->getUnit(0)->getKind() == UNIT_KIND_ITEM);
6355 for (i = 0; (stochastic ==
true) && (i < pSBMLModel->getNumReactions()); ++i)
6357 stochastic = !pSBMLModel->getReaction(i)->getReversible();
6367 int type = sbmlRule->getTypeCode();
6369 if (type == SBML_ASSIGNMENT_RULE)
6371 const AssignmentRule* pAssignmentRule =
dynamic_cast<const AssignmentRule*
>(sbmlRule);
6373 if (pAssignmentRule && pAssignmentRule->isSetVariable())
6382 else if (type == SBML_RATE_RULE)
6384 const RateRule* pRateRule =
dynamic_cast<const RateRule*