24 #include "sbml/SBMLDocument.h"
25 #include "sbml/Compartment.h"
26 #if LIBSBML_VERSION >= 40100
27 #include "sbml/LocalParameter.h"
28 #endif // LIBSBML_VERSION
30 #if LIBSBML_VERSION >= 50400
32 #include <sbml/packages/layout/extension/LayoutModelPlugin.h>
33 #include <sbml/packages/layout/extension/LayoutExtension.h>
34 #include <sbml/conversion/ConversionProperties.h>
37 #include <sbml/packages/render/extension/RenderExtension.h>
38 #include <sbml/packages/render/extension/RenderListOfLayoutsPlugin.h>
39 #include <sbml/packages/render/sbml/GlobalRenderInformation.h>
41 #define INIT_DEFAULTS(element) \
43 element.initDefaults();\
48 #define INIT_DEFAULTS(element) \
52 #endif // LIBSBML VERSION
54 #include "sbml/Model.h"
55 #include "sbml/Species.h"
56 #include "sbml/Parameter.h"
57 #include "sbml/Reaction.h"
58 #include "sbml/KineticLaw.h"
59 #include "sbml/SBMLWriter.h"
60 #include "sbml/SpeciesReference.h"
61 #include "sbml/math/ASTNode.h"
62 #include "sbml/annotation/ModelHistory.h"
63 #include "sbml/annotation/CVTerm.h"
64 #include "sbml/SBMLErrorLog.h"
65 #include "sbml/SBMLError.h"
84 #include "sbml/Trigger.h"
85 #include "sbml/Event.h"
86 #include "sbml/EventAssignment.h"
87 #include <sbml/xml/XMLInputStream.h>
105 const std::string& sNamespace,
106 const std::string& elementName,
107 const std::string& definition)
109 if (pSBMLDocument == NULL || pSBMLDocument->getModel() == NULL)
return "";
111 for (
unsigned int i = 0; i < pSBMLDocument->getModel()->getNumFunctionDefinitions(); ++i)
113 FunctionDefinition* current = pSBMLDocument->getModel()->getFunctionDefinition(i);
115 if (current == NULL)
continue;
117 if (!current->isSetAnnotation())
continue;
119 const XMLNode* element = current->getAnnotation();
121 if (element == NULL)
continue;
123 for (
unsigned int i = 0 ; i < element->getNumChildren(); ++i)
125 const XMLNode& annot = element->getChild(i);
127 if (annot.getURI() == sNamespace &&
128 annot.getName() == elementName &&
129 annot.getAttrValue(
"definition") == definition)
131 return current->getId();
140 std::map<std::string, const SBase*>& idMap,
142 const std::string& sNamespace,
143 const std::string& elementName,
144 const std::string& definition,
145 const std::string& lambda)
147 if (pSBMLDocument == NULL || pSBMLDocument->getModel() == NULL)
return id;
151 FunctionDefinition *def = pSBMLDocument->getModel()->createFunctionDefinition();
153 def -> setMath(SBML_parseFormula(lambda.c_str()));
155 std::stringstream annotation;
156 std::string annotElement = pSBMLDocument->getLevel() == 1 ?
"annotations" :
"annotation";
157 annotation <<
"<" << annotElement <<
"> <" << elementName
158 <<
" xmlns='" << sNamespace
159 <<
"' definition='" << definition
160 <<
"' /> </" << annotElement <<
">";
162 def->setAnnotation(annotation.str());
168 std::map<std::string, const SBase*>& idMap,
172 "http://sbml.org/annotations/symbols",
174 "http://en.wikipedia.org/wiki/Derivative");
176 if (!newId.empty())
return newId;
182 "http://sbml.org/annotations/symbols",
184 "http://en.wikipedia.org/wiki/Derivative",
191 std::map<std::string, const SBase*>& idMap,
196 if (
id == std::string(
"RNORMAL"))
199 "http://sbml.org/annotations/distribution",
201 "http://www.uncertml.org/distributions/normal");
203 if (!newId.empty())
return newId;
209 "http://sbml.org/annotations/distribution",
211 "http://www.uncertml.org/distributions/normal",
216 else if (
id == std::string(
"RUNIFORM"))
219 "http://sbml.org/annotations/distribution",
221 "http://www.uncertml.org/distributions/uniform");
223 if (!newId.empty())
return newId;
229 "http://sbml.org/annotations/distribution",
231 "http://www.uncertml.org/distributions/uniform",
232 "lambda(a,b,(a+b)/2)"
236 else if (
id == std::string(
"RGAMMA"))
239 "http://sbml.org/annotations/distribution",
241 "http://www.uncertml.org/distributions/gamma");
243 if (!newId.empty())
return newId;
249 "http://sbml.org/annotations/distribution",
251 "http://www.uncertml.org/distributions/gamma",
256 else if (
id == std::string(
"RPOISSON"))
259 "http://sbml.org/annotations/distribution",
261 "http://www.uncertml.org/distributions/poisson");
263 if (!newId.empty())
return newId;
269 "http://sbml.org/annotations/distribution",
271 "http://www.uncertml.org/distributions/poisson",
276 else if (
id == std::string(
"MAX"))
279 "http://sbml.org/annotations/function",
281 "http://sbml.org/annotations/function/max");
283 if (!newId.empty())
return newId;
289 "http://sbml.org/annotations/function",
291 "http://sbml.org/annotations/function/max",
292 "lambda(a,b,piecewise(a,geq(a,b),b))"
296 else if (
id == std::string(
"MIN"))
299 "http://sbml.org/annotations/function",
301 "http://sbml.org/annotations/function/min");
303 if (!newId.empty())
return newId;
309 "http://sbml.org/annotations/function",
311 "http://sbml.org/annotations/function/min",
312 "lambda(a,b,piecewise(a,leq(a,b),b))"
316 else if (
id == std::string(
"rateOf"))
326 #endif // USE_SBMLUNIT
328 CSBMLExporter::CSBMLExporter(): mpSBMLDocument(NULL), mSBMLLevel(2), mSBMLVersion(1), mIncompleteExport(false), mVariableVolumes(false), mpAvogadro(NULL), mAvogadroCreated(false), mMIRIAMWarning(false), mDocumentDisowned(false), mExportCOPASIMIRIAM(false), mExportedFunctions(2, 1)
359 uDef.setName(
"time");
367 unit.setKind(UNIT_KIND_SECOND);
370 unit.setMultiplier(86400);
374 unit.setKind(UNIT_KIND_SECOND);
377 unit.setMultiplier(3600);
381 unit.setKind(UNIT_KIND_SECOND);
384 unit.setMultiplier(60);
388 unit.setKind(UNIT_KIND_SECOND);
391 unit.setMultiplier(1);
395 unit.setKind(UNIT_KIND_SECOND);
398 unit.setMultiplier(1);
402 unit.setKind(UNIT_KIND_SECOND);
405 unit.setMultiplier(1);
409 unit.setKind(UNIT_KIND_SECOND);
412 unit.setMultiplier(1);
416 unit.setKind(UNIT_KIND_SECOND);
419 unit.setMultiplier(1);
423 unit.setKind(UNIT_KIND_SECOND);
426 unit.setMultiplier(1);
430 unit.setKind(UNIT_KIND_DIMENSIONLESS);
433 unit.setMultiplier(1);
443 UnitDefinition* pUdef = pSBMLModel->getUnitDefinition(
"time");
459 if (this->
mSBMLLevel > 2 || unit.getKind() != UNIT_KIND_SECOND || unit.getScale() != 0 || unit.getExponent() != 1 || unit.getMultiplier() != 1.0)
462 pSBMLModel->addUnitDefinition(&uDef);
467 #if LIBSBML_VERSION >= 40100
471 pSBMLModel->setTimeUnits(uDef.getId());
474 #endif // LIBSBML_VERSION
485 uDef.setName(
"volume");
486 uDef.setId(
"volume");
493 unit.setKind(UNIT_KIND_LITRE);
499 unit.setKind(UNIT_KIND_LITRE);
505 unit.setKind(UNIT_KIND_LITRE);
511 unit.setKind(UNIT_KIND_LITRE);
517 unit.setKind(UNIT_KIND_LITRE);
523 unit.setKind(UNIT_KIND_LITRE);
529 unit.setKind(UNIT_KIND_METRE);
535 unit.setKind(UNIT_KIND_DIMENSIONLESS);
545 unit.setMultiplier(1.0);
548 UnitDefinition* pUdef = pSBMLModel->getUnitDefinition(
"volume");
562 if (this->
mSBMLLevel > 2 || unit.getKind() != UNIT_KIND_LITRE || unit.getScale() != 0 || unit.getExponent() != 1 || unit.getMultiplier() != 1.0)
565 pSBMLModel->addUnitDefinition(&uDef);
570 #if LIBSBML_VERSION >= 40100
574 pSBMLModel->setVolumeUnits(uDef.getId());
577 #endif // LIBSBML_VERSION
588 uDef.setName(
"substance");
589 uDef.setId(
"substance");
596 unit.setKind(UNIT_KIND_MOLE);
602 unit.setKind(UNIT_KIND_MOLE);
608 unit.setKind(UNIT_KIND_MOLE);
614 unit.setKind(UNIT_KIND_MOLE);
620 unit.setKind(UNIT_KIND_MOLE);
626 unit.setKind(UNIT_KIND_MOLE);
632 unit.setKind(UNIT_KIND_ITEM);
638 unit.setKind(UNIT_KIND_DIMENSIONLESS);
648 unit.setMultiplier(1);
651 UnitDefinition* pUdef = pSBMLModel->getUnitDefinition(
"substance");
665 if (this->
mSBMLLevel > 2 || unit.getKind() != UNIT_KIND_MOLE || unit.getScale() != 0 || unit.getExponent() != 1 || unit.getMultiplier() != 1.0)
668 pSBMLModel->addUnitDefinition(&uDef);
673 #if LIBSBML_VERSION >= 40100
677 pSBMLModel->setSubstanceUnits(uDef.getId());
680 pSBMLModel->setExtentUnits(uDef.getId());
683 #endif // LIBSBML_VERSION
694 uDef.setName(
"length");
695 uDef.setId(
"length");
702 unit.setKind(UNIT_KIND_METRE);
708 unit.setKind(UNIT_KIND_METRE);
714 unit.setKind(UNIT_KIND_METRE);
720 unit.setKind(UNIT_KIND_METRE);
726 unit.setKind(UNIT_KIND_METRE);
732 unit.setKind(UNIT_KIND_METRE);
738 unit.setKind(UNIT_KIND_METRE);
744 unit.setKind(UNIT_KIND_METRE);
750 unit.setKind(UNIT_KIND_DIMENSIONLESS);
760 unit.setMultiplier(1.0);
763 UnitDefinition* pUdef = pSBMLModel->getUnitDefinition(
"length");
777 if (this->
mSBMLLevel > 2 || unit.getKind() != UNIT_KIND_METRE || unit.getScale() != 0 || unit.getExponent() != 1 || unit.getMultiplier() != 1.0)
780 pSBMLModel->addUnitDefinition(&uDef);
785 #if LIBSBML_VERSION >= 40100
789 pSBMLModel->setLengthUnits(uDef.getId());
792 #endif // LIBSBML_VERSION
803 uDef.setName(
"area");
811 unit.setKind(UNIT_KIND_METRE);
817 unit.setKind(UNIT_KIND_METRE);
823 unit.setKind(UNIT_KIND_METRE);
829 unit.setKind(UNIT_KIND_METRE);
835 unit.setKind(UNIT_KIND_METRE);
841 unit.setKind(UNIT_KIND_METRE);
847 unit.setKind(UNIT_KIND_METRE);
853 unit.setKind(UNIT_KIND_METRE);
859 unit.setKind(UNIT_KIND_DIMENSIONLESS);
869 unit.setMultiplier(1.0);
872 UnitDefinition* pUdef = pSBMLModel->getUnitDefinition(
"area");
887 unit.getKind() != UNIT_KIND_METRE ||
888 unit.getScale() != 0 ||
889 unit.getExponent() != 2 ||
890 unit.getMultiplier() != 1.0)
893 pSBMLModel->addUnitDefinition(&uDef);
898 #if LIBSBML_VERSION >= 40100
902 pSBMLModel->setAreaUnits(uDef.getId());
905 #endif // LIBSBML_VERSION
930 Compartment* pSBMLCompartment = NULL;
931 std::string sbmlId = compartment.
getSBMLId();
935 pSBMLCompartment = this->
mpSBMLDocument->getModel()->getCompartment(sbmlId);
937 if (pSBMLCompartment == NULL)
939 pSBMLCompartment = this->
mpSBMLDocument->getModel()->createCompartment();
941 pSBMLCompartment->setId(sbmlId);
946 pSBMLCompartment = this->
mpSBMLDocument->getModel()->createCompartment();
950 pSBMLCompartment->setId(sbmlId);
955 this->
mIdMap.insert(std::pair<const std::string, const SBase*>(sbmlId, pSBMLCompartment));
962 pSBMLCompartment->setName(compartment.
getObjectName().c_str());
965 pSBMLCompartment->setSpatialDimensions((
unsigned int)compartment.
getDimensionality());
971 pSBMLCompartment->setVolume(value);
975 pSBMLCompartment->unsetVolume();
988 pSBMLCompartment->setConstant(
false);
1001 pSBMLCompartment->setConstant(
false);
1023 pSBMLCompartment->setConstant(
true);
1029 pSBMLCompartment->setConstant(
false);
1052 if (pSBMLCompartment != NULL)
1057 if (pSBMLCompartment != NULL &&
mSBMLLevel == 3)
1059 pSBMLCompartment->setUnits(
"volume");
1089 std::ostringstream os;
1092 while (sit != sendit)
1107 Species* pSBMLSpecies = NULL;
1110 if (!sbmlId.empty())
1112 pSBMLSpecies = this->
mpSBMLDocument->getModel()->getSpecies(sbmlId);
1114 if (pSBMLSpecies == NULL)
1116 pSBMLSpecies = this->
mpSBMLDocument->getModel()->createSpecies();
1118 pSBMLSpecies->setId(sbmlId);
1122 #if LIBSBML_VERSION >= 40100
1126 pSBMLSpecies->unsetConversionFactor();
1131 #endif // LIBSBML_VERSION
1136 if (pSBMLSpecies->isSetSpatialSizeUnits())
1138 pSBMLSpecies->unsetSpatialSizeUnits();
1146 pSBMLSpecies = this->
mpSBMLDocument->getModel()->createSpecies();
1150 pSBMLSpecies->setId(sbmlId);
1155 this->
mIdMap.insert(std::pair<const std::string, const SBase*>(sbmlId, pSBMLSpecies));
1167 assert(pSBMLCompartment);
1168 pSBMLSpecies->setCompartment(pSBMLCompartment->getId());
1172 pSBMLSpecies->setHasOnlySubstanceUnits(
true);
1190 if (pSBMLSpecies->isSetInitialAmount() || this->
mVariableVolumes ==
true || pSBMLSpecies->getLevel() == 1)
1196 pSBMLSpecies->setInitialConcentration(value);
1201 pSBMLSpecies->unsetInitialConcentration();
1202 pSBMLSpecies->unsetInitialAmount();
1212 pSBMLSpecies->setConstant(
false);
1213 pSBMLSpecies->setBoundaryCondition(
true);
1219 pSBMLSpecies->setConstant(
false);
1220 pSBMLSpecies->setBoundaryCondition(
true);
1237 pSBMLSpecies->setConstant(
true);
1243 pSBMLSpecies->setConstant(
false);
1246 pSBMLSpecies->setBoundaryCondition(
true);
1261 pSBMLSpecies->setConstant(
false);
1262 pSBMLSpecies->setBoundaryCondition(
false);
1270 if (pSBMLSpecies != NULL)
1278 pSBMLSpecies->setSubstanceUnits(
"substance");
1306 Parameter* pParameter = NULL;
1307 std::string sbmlId = modelValue.
getSBMLId();
1309 if (!sbmlId.empty())
1311 pParameter = this->
mpSBMLDocument->getModel()->getParameter(sbmlId);
1313 if (pParameter == NULL)
1315 pParameter = this->
mpSBMLDocument->getModel()->createParameter();
1317 pParameter->setId(sbmlId);
1322 pParameter = this->
mpSBMLDocument->getModel()->createParameter();
1326 pParameter->setId(sbmlId);
1331 this->
mIdMap.insert(std::pair<const std::string, const SBase*>(sbmlId, pParameter));
1346 pParameter->setValue(value);
1350 pParameter->unsetValue();
1361 pParameter->setConstant(
false);
1367 pParameter->setConstant(
false);
1384 pParameter->setConstant(
true);
1390 pParameter->setConstant(
false);
1406 if (pParameter != NULL)
1437 Reaction* pSBMLReaction = NULL;
1445 std::string sbmlId = reaction.
getSBMLId();
1447 if (!sbmlId.empty())
1449 pSBMLReaction = this->
mpSBMLDocument->getModel()->getReaction(sbmlId);
1451 if (pSBMLReaction == NULL)
1454 pSBMLReaction = this->
mpSBMLDocument->getModel()->createReaction();
1456 pSBMLReaction->setId(sbmlId);
1461 std::map<std::string, const SBase*>::const_iterator pos = this->
mIdMap.find(sbmlId);
1462 assert(pos != this->
mIdMap.end());
1464 if (pos->second == NULL)
1466 this->
mIdMap[sbmlId] = pSBMLReaction;
1471 pSBMLReaction = this->
mpSBMLDocument->getModel()->createReaction();
1475 pSBMLReaction->setId(sbmlId);
1480 this->
mIdMap.insert(std::pair<const std::string, const SBase*>(sbmlId, pSBMLReaction));
1493 unsigned int counter;
1494 std::set<std::string> usedReferences;
1500 assert(pMetabolite);
1501 SpeciesReference* sRef = NULL;
1503 if (!(sRef = pSBMLReaction->getReactant(pMetabolite->
getSBMLId())))
1505 sRef = pSBMLReaction->createReactant();
1506 sRef->setSpecies(pMetabolite->
getSBMLId().c_str());
1510 #if LIBSBML_VERSION > 40100
1513 sRef->setConstant(
true);
1517 sRef->setDenominator(1);
1518 usedReferences.insert(sRef->getSpecies());
1521 ListOf* l = pSBMLReaction->getListOfReactants();
1523 for (counter = l->size(); counter > 0; --counter)
1525 if (usedReferences.find(static_cast<SimpleSpeciesReference*>(l->get(counter - 1))->getSpecies()) == usedReferences.end())
1527 l->remove(counter - 1);
1532 usedReferences.clear();
1534 for (counter = 0; counter < chemicalEquation.
getProducts().
size(); counter++)
1538 assert(pMetabolite);
1539 SpeciesReference* sRef = NULL;
1541 if (!(sRef = pSBMLReaction->getProduct(pMetabolite->
getSBMLId())))
1543 sRef = pSBMLReaction->createProduct();
1544 sRef->setSpecies(pMetabolite->
getSBMLId().c_str());
1548 #if LIBSBML_VERSION > 40100
1551 sRef->setConstant(
true);
1556 sRef->setDenominator(1);
1557 usedReferences.insert(sRef->getSpecies());
1560 l = pSBMLReaction->getListOfProducts();
1562 for (counter = l->size(); counter > 0; --counter)
1564 if (usedReferences.find(static_cast<SimpleSpeciesReference*>(l->get(counter - 1))->getSpecies()) == usedReferences.end())
1566 l->remove(counter - 1);
1571 usedReferences.clear();
1573 for (counter = 0; counter < chemicalEquation.
getModifiers().
size(); counter++)
1577 ModifierSpeciesReference* sRef = NULL;
1579 if (!(sRef = pSBMLReaction->getModifier(pMetabolite->
getSBMLId())))
1581 if (pSBMLReaction->getLevel() > 1)
1583 sRef = pSBMLReaction->createModifier();
1584 assert(sRef != NULL);
1585 sRef->setSpecies(pMetabolite->
getSBMLId().c_str());
1589 if (pSBMLReaction->getLevel() > 1)
1591 usedReferences.insert(sRef->getSpecies());
1595 l = pSBMLReaction->getListOfModifiers();
1597 for (counter = l->size(); counter > 0; --counter)
1599 if (usedReferences.find(static_cast<SimpleSpeciesReference*>(l->get(counter - 1))->getSpecies()) == usedReferences.end())
1601 l->remove(counter - 1);
1613 KineticLaw* pKineticLaw = this->
createKineticLaw(reaction, dataModel, pSBMLReaction->getLevel(), pSBMLReaction->getVersion());
1615 if (pKineticLaw != NULL)
1617 pSBMLReaction->setKineticLaw(pKineticLaw);
1630 pSBMLReaction->unsetKineticLaw();
1636 pSBMLReaction->unsetKineticLaw();
1639 if (pSBMLReaction != NULL)
1658 for (i = 0; i < iMax; ++i)
1661 assert(pME != NULL);
1676 std::vector<SBMLIncompatibility> result;
1682 , std::string(
"initial expression for object named \"" + modelEntity.
getObjectName() +
"\"").c_str()
1689 std::set<std::string> directlyUsedFunctionNames;
1693 #if defined _MSC_VER && _MSC_VER < 1201 // 1200 Identifies Visual C++ 6.0
1695 std::set<CFunction*>::const_iterator it = usedFunctions.begin();
1696 std::set<CFunction*>::const_iterator end = usedFunctions.end();
1698 for (; it != end; ++it)
1702 this->
mUsedFunctions.insert(usedFunctions.begin(), usedFunctions.end());
1706 InitialAssignment* pInitialAssignment = this->
mpSBMLDocument->getModel()->getInitialAssignment(modelEntity.
getSBMLId());
1708 if (pInitialAssignment == NULL)
1710 pInitialAssignment = this->
mpSBMLDocument->getModel()->createInitialAssignment();
1711 pInitialAssignment->setSymbol(modelEntity.
getSBMLId());
1728 assert(pOrigNode != NULL);
1734 const CMetab* pMetab =
dynamic_cast<const CMetab*
>(&modelEntity);
1738 std::map<const CCopasiObject*, SBase*>::const_iterator pos = this->
mCOPASI2SBMLMap.find(&modelEntity);
1741 if (dynamic_cast<const Species*>(pos->second)->getHasOnlySubstanceUnits() ==
true)
1748 assert(pNode != NULL);
1767 pInitialAssignment->setMath(pNode);
1775 unsigned int i = 0, iMax = this->
mpSBMLDocument->getModel()->getNumInitialAssignments();
1781 this->
mpSBMLDocument->getModel()->getListOfInitialAssignments()->remove(i);
1810 std::string
convertExpression(
const std::string& expression,
const std::map<const std::string, Parameter*>& initialValueMap)
1812 if (initialValueMap.empty())
1815 std::string result = expression;
1816 std::map<const std::string, Parameter*>::const_iterator it;
1818 for (it = initialValueMap.begin(); it != initialValueMap.end(); ++it)
1820 size_t length = it->first.length();
1823 while ((start = result.find(it->first)) != std::string::npos)
1825 result.replace(start, length, it->second->getId());
1843 std::vector<CModelEntity*> orderedAssignmentRules =
orderRules(dataModel);
1848 std::map<std::string, Rule*> ruleMap;
1850 assert(pSBMLModel != NULL);
1852 while (pSBMLModel->getNumRules() != 0)
1854 Rule* pRule = pSBMLModel->getRule(0);
1855 assert(pRule != NULL);
1858 if (pRule->getTypeCode() == SBML_ASSIGNMENT_RULE)
1860 AssignmentRule* pARule =
dynamic_cast<AssignmentRule*
>(pRule);
1861 assert(pARule != NULL);
1862 ruleMap[pARule->getVariable()] = pARule;
1864 else if (pRule->getTypeCode() == SBML_RATE_RULE)
1866 RateRule* pRRule =
dynamic_cast<RateRule*
>(pRule);
1867 assert(pRRule != NULL);
1868 ruleMap[pRRule->getVariable()] = pRRule;
1871 pSBMLModel->getListOfRules()->remove(0);
1876 size_t i, iMax = orderedAssignmentRules.size();
1878 for (i = 0; i < iMax; ++i)
1880 pME = orderedAssignmentRules[i];
1881 assert(pME != NULL);
1885 std::map<std::string, Rule*>::const_iterator pos = ruleMap.find(pME->
getSBMLId());
1886 Rule* pOldRule = NULL;
1888 if (pos != ruleMap.end())
1890 pOldRule = pos->second;
1891 assert(pOldRule != NULL);
1892 ruleMap.erase(pos->first);
1901 for (i = 0; i < iMax; ++i)
1904 assert(pME != NULL);
1908 std::map<std::string, Rule*>::const_iterator pos = ruleMap.find(pME->
getSBMLId());
1909 Rule* pOldRule = NULL;
1911 if (pos != ruleMap.end())
1913 pOldRule = pos->second;
1914 assert(pOldRule != NULL);
1915 ruleMap.erase(pos->first);
1923 std::map<std::string, Rule*>::iterator mapIt = ruleMap.begin(), mapEndit = ruleMap.end();
1925 while (mapIt != mapEndit)
1927 delete mapIt->second;
1940 std::vector<SBMLIncompatibility> result;
1946 , std::string(
"rule for object named \"" + modelEntity.
getObjectName() +
"\"").c_str()
1953 std::set<std::string> directlyUsedFunctionNames;
1957 # if defined _MSC_VER && _MSC_VER < 1201 // 1200 Identifies Visual C++ 6.0
1959 std::set<CFunction*>::const_iterator it = usedFunctions.begin();
1960 std::set<CFunction*>::const_iterator end = usedFunctions.end();
1962 for (; it != end; ++it)
1966 this->
mUsedFunctions.insert(usedFunctions.begin(), usedFunctions.end());
1971 const CMetab* pMetab =
dynamic_cast<const CMetab*
>(&modelEntity);
1973 if (pOldRule == NULL)
1977 pOldRule = this->
mpSBMLDocument->getModel()->createAssignmentRule();
1993 pOldRule->setVariable(modelEntity.
getSBMLId());
1998 this->
mpSBMLDocument->getModel()->getListOfRules()->appendAndOwn(pOldRule);
2018 assert(pOrigNode != NULL);
2025 std::map<const CCopasiObject*, SBase*>::const_iterator pos = this->
mCOPASI2SBMLMap.find(&modelEntity);
2028 if (dynamic_cast<const Species*>(pos->second)->getHasOnlySubstanceUnits() ==
true)
2035 assert(pNode != NULL);
2052 pOldRule->setMath(pNode);
2079 std::map<std::string, const SBase*> idMap;
2080 unsigned int i, iMax;
2082 if (sbmlModel.isSetId())
2084 idMap.insert(std::pair<const std::string, const SBase*>(sbmlModel.getId(), &sbmlModel));
2087 if (sbmlModel.getListOfFunctionDefinitions()->isSetId())
2089 idMap.insert(std::pair<const std::string, const SBase*>(sbmlModel.getListOfFunctionDefinitions()->getId(), sbmlModel.getListOfFunctionDefinitions()));
2092 iMax = sbmlModel.getNumFunctionDefinitions();
2094 for (i = 0; i < iMax; ++i)
2096 idMap.insert(std::pair<const std::string, const SBase*>(sbmlModel.getFunctionDefinition(i)->getId(), sbmlModel.getFunctionDefinition(i)));
2099 if (sbmlModel.getListOfCompartments()->isSetId())
2101 idMap.insert(std::pair<const std::string, const SBase*>(sbmlModel.getListOfCompartments()->getId(), sbmlModel.getListOfCompartments()));
2104 iMax = sbmlModel.getNumCompartments();
2106 for (i = 0; i < iMax; ++i)
2108 idMap.insert(std::pair<const std::string, const SBase*>(sbmlModel.getCompartment(i)->getId(), sbmlModel.getCompartment(i)));
2111 if (sbmlModel.getListOfSpecies()->isSetId())
2113 idMap.insert(std::pair<const std::string, const SBase*>(sbmlModel.getListOfSpecies()->getId(), sbmlModel.getListOfSpecies()));
2116 iMax = sbmlModel.getNumSpecies();
2118 for (i = 0; i < iMax; ++i)
2120 idMap.insert(std::pair<const std::string, const SBase*>(sbmlModel.getSpecies(i)->getId(), sbmlModel.getSpecies(i)));
2123 if (sbmlModel.getListOfParameters()->isSetId())
2125 idMap.insert(std::pair<const std::string, const SBase*>(sbmlModel.getListOfParameters()->getId(), sbmlModel.getListOfParameters()));
2128 iMax = sbmlModel.getNumParameters();
2130 for (i = 0; i < iMax; ++i)
2132 idMap.insert(std::pair<const std::string, const SBase*>(sbmlModel.getParameter(i)->getId(), sbmlModel.getParameter(i)));
2135 if (sbmlModel.getListOfReactions()->isSetId())
2137 idMap.insert(std::pair<const std::string, const SBase*>(sbmlModel.getListOfReactions()->getId(), sbmlModel.getListOfReactions()));
2140 iMax = sbmlModel.getNumReactions();
2142 for (i = 0; i < iMax; ++i)
2144 const Reaction* pReaction = sbmlModel.getReaction(i);
2146 if (pReaction != NULL)
2148 idMap.insert(std::pair<const std::string, const SBase*>(pReaction->getId(), pReaction));
2150 if (pReaction->getListOfReactants()->isSetId())
2152 idMap.insert(std::pair<const std::string, const SBase*>(pReaction->getListOfReactants()->getId(), pReaction->getListOfReactants()));
2155 unsigned int j, jMax = pReaction->getNumReactants();
2156 const SpeciesReference* pSRef = NULL;
2158 for (j = 0; j < jMax; ++j)
2160 pSRef = pReaction->getReactant(j);
2162 if (pSRef->isSetId())
2164 idMap.insert(std::pair<const std::string, const SBase*>(pSRef->getId(), pSRef));
2168 if (pReaction->getListOfProducts()->isSetId())
2170 idMap.insert(std::pair<const std::string, const SBase*>(pReaction->getListOfProducts()->getId(), pReaction->getListOfProducts()));
2173 jMax = pReaction->getNumProducts();
2175 for (j = 0; j < jMax; ++j)
2177 pSRef = pReaction->getProduct(j);
2179 if (pSRef->isSetId())
2181 idMap.insert(std::pair<const std::string, const SBase*>(pSRef->getId(), pSRef));
2185 if (pReaction->getListOfModifiers()->isSetId())
2187 idMap.insert(std::pair<const std::string, const SBase*>(pReaction->getListOfModifiers()->getId(), pReaction->getListOfModifiers()));
2190 jMax = pReaction->getNumModifiers();
2191 const ModifierSpeciesReference* pModSRef;
2193 for (j = 0; j < jMax; ++j)
2195 pModSRef = pReaction->getModifier(j);
2197 if (pModSRef->isSetId())
2199 idMap.insert(std::pair<const std::string, const SBase*>(pModSRef->getId(), pModSRef));
2205 if (sbmlModel.getListOfEvents()->isSetId())
2207 idMap.insert(std::pair<const std::string, const SBase*>(sbmlModel.getListOfEvents()->getId(), sbmlModel.getListOfEvents()));
2210 iMax = sbmlModel.getNumEvents();
2212 for (i = 0; i < iMax; ++i)
2214 idMap.insert(std::pair<const std::string, const SBase*>(sbmlModel.getEvent(i)->getId(), sbmlModel.getEvent(i)));
2218 const LayoutModelPlugin* lmPlugin = (LayoutModelPlugin*)sbmlModel.getPlugin(
"layout");
2220 if (lmPlugin != NULL)
2222 if (lmPlugin->getListOfLayouts()->isSetId())
2224 idMap.insert(std::pair<const std::string, const SBase*>(lmPlugin->getListOfLayouts()->getId(), lmPlugin->getListOfLayouts()));
2227 iMax = lmPlugin->getListOfLayouts()->size();
2229 for (i = 0; i < iMax; ++i)
2231 const Layout* pLayout = lmPlugin->getLayout(i);
2233 if (pLayout != NULL)
2235 if (pLayout->isSetId())
2237 idMap.insert(std::pair<const std::string, const SBase*>(pLayout->getId(), pLayout));
2253 const std::string& prefix,
2254 bool addIndexForFirst,
2255 const std::string & separator)
2260 std::ostringstream Id;
2262 if (addIndexForFirst)
2264 Id << Prefix << separator << i++;
2271 while (idMap.find(Id.str()) != idMap.end())
2274 Id << Prefix << separator << i++;
2290 if (pModel == NULL)
return;
2295 for (i = 0; i < iMax; ++i)
2298 assert(pME != NULL);
2309 for (i = 0; i < iMax; ++i)
2312 assert(pME != NULL);
2323 for (i = 0; i < iMax; ++i)
2326 assert(pME != NULL);
2337 std::stringstream str;
2338 str <<
"<initialValue xmlns='http://copasi.org/initialValue' ";
2339 str <<
"parent='" << ((
CModelEntity*)pObjectParent)->getSBMLId() <<
"' />";
2353 if (initialMap == NULL || pObject == NULL || pObjectParent == NULL)
2356 const std::string& cn = pObject->
getCN();
2358 if ((*initialMap)[cn] != NULL)
2364 Parameter* initial =
new Parameter(sbmlLevel, sbmlVersion);
2366 initial->initDefaults();
2367 initial->setId(pObjectParent->
getKey());
2368 initial->setName(
"Initial for " + pObjectParent->
getObjectName());
2373 (*initialMap) [cn] = initial;
2379 ,
unsigned int sbmlLevel
2380 ,
unsigned int sbmlVersion
2381 , std::vector<SBMLIncompatibility>& result
2382 ,
bool initialExpression
2383 , std::map<const std::string, Parameter*>* initialMap )
2393 const std::vector<CEvaluationNode*>& objectNodes = expr.
getNodeList();
2394 size_t j, jMax = objectNodes.size();
2396 for (j = 0; j < jMax; ++j)
2401 assert(pObjectNode);
2403 if (pObjectNode == NULL)
continue;
2405 std::vector<CCopasiContainer*> containers;
2406 containers.push_back(const_cast<CModel*>(dataModel.
getModel()));
2414 assert(pObjectParent);
2417 if (typeString ==
"Compartment")
2420 if (initialExpression ==
true)
2430 && initialMap != NULL
2431 && (sbmlLevel > 2 || (sbmlLevel == 2 && sbmlVersion > 1)))
2443 else if (typeString ==
"Metabolite")
2446 if (initialExpression ==
true)
2456 && initialMap != NULL
2457 && (sbmlLevel > 2 || (sbmlLevel == 2 && sbmlVersion > 1)))
2471 else if (typeString ==
"ModelValue")
2474 if (initialExpression ==
true)
2484 && initialMap != NULL
2485 && (sbmlLevel > 2 || (sbmlLevel == 2 && sbmlVersion > 1)))
2497 else if (typeString ==
"Model")
2505 else if (typeString ==
"Parameter")
2515 if (sbmlLevel == 1 || (sbmlLevel == 2 && sbmlVersion == 1))
2521 if (typeString ==
"Reaction")
2537 if (pLocalParameter == NULL)
2599 const SBMLDocument* pSBMLDocument =
const_cast<const SBMLDocument*
>(
const_cast<CCopasiDataModel&
>(dataModel).getCurrentSBMLDocument());
2601 if (pSBMLDocument != NULL)
2610 std::set<std::string> badSpecies;
2611 const std::map<CCopasiObject*, SBase*>& copasi2sbmlmap =
const_cast<CCopasiDataModel&
>(dataModel).getCopasi2SBMLMap();
2612 std::map<CCopasiObject*, SBase*>::const_iterator pos;
2613 const Species* pSBMLSpecies = NULL;
2614 std::string spatialSizeUnits;
2618 pos = copasi2sbmlmap.find(*it);
2620 if (pos != copasi2sbmlmap.end())
2623 pSBMLSpecies =
dynamic_cast<const Species*
>(pos->second);
2624 assert(pSBMLSpecies != NULL);
2626 if (pSBMLSpecies == NULL)
continue;
2628 if (pSBMLSpecies->isSetSpatialSizeUnits())
2630 spatialSizeUnits = pSBMLSpecies->getSpatialSizeUnits();
2633 assert(pSBMLDocument->getModel() != NULL);
2634 const Compartment* pCompartment = pSBMLDocument->getModel()->getCompartment(pSBMLSpecies->getCompartment());
2635 assert(pCompartment != NULL);
2637 if (pCompartment != NULL)
2639 UnitDefinition* pUDef1 = NULL;
2640 UnitDefinition* pUDef2 = NULL;
2642 if (pCompartment->isSetUnits())
2644 assert(pSBMLDocument->getModel() != NULL);
2646 if (pSBMLDocument->getModel() != NULL)
2656 assert(pSBMLDocument->getModel() != NULL);
2658 if (pSBMLDocument->getModel() != NULL)
2660 switch (pCompartment->getSpatialDimensions())
2687 if (pUDef1 != NULL && pUDef2 != NULL)
2693 badSpecies.insert(pSBMLSpecies->getId());
2714 if (!badSpecies.empty())
2717 std::ostringstream os;
2718 std::set<std::string>::const_iterator sit = badSpecies.begin(), sendit = badSpecies.end();
2720 while (sit != sendit)
2726 result.push_back(
SBMLIncompatibility(2, os.str().substr(0, os.str().size() - 2).c_str()));
2748 const CCompartment* pCompartment = (*it)->getCompartment();
2749 assert(pCompartment != NULL);
2771 , std::vector<SBMLIncompatibility>& result
2772 ,
const std::string& objectDescription
2773 ,
bool initialExpression
2774 , std::map<const std::string, Parameter*>* initialMap )
2787 unsigned int sbmlLevel,
unsigned int , std::vector<SBMLIncompatibility>& result)
2798 for (i = 0; i < iMax; ++i)
2801 assert(pME != NULL);
2812 for (i = 0; i < iMax; ++i)
2815 assert(pME != NULL);
2826 for (i = 0; i < iMax; ++i)
2829 assert(pME != NULL);
2845 assert(*it != NULL);
2862 const std::set<CEvaluationNodeFunction::SubType>& unsupportedFunctions,
2863 std::vector<SBMLIncompatibility>& result,
const std::string& objectDescription)
2869 if (unsupportedFunctions.find(subtype) != unsupportedFunctions.end())
2877 while (pChild != NULL)
2897 while (compIt != compEndit)
2899 if ((*compIt)->getInitialExpression() !=
"")
2901 result.push_back(
SBMLIncompatibility(5,
"Compartment", (*compIt)->getObjectName().c_str()));
2911 while (metabIt != metabEndit)
2913 if ((*metabIt)->getInitialExpression() !=
"")
2915 result.push_back(
SBMLIncompatibility(5,
"Metabolite", (*metabIt)->getObjectName().c_str()));
2925 while (mvIt != mvEndit)
2927 if ((*mvIt)->getInitialExpression() !=
"")
2951 this->
mUsedFunctions.insert(usedFunctions.begin(), usedFunctions.end());
2960 std::map<SBase*, const CCopasiObject*> sbml2copasiMap;
2961 std::map<const CCopasiObject*, SBase*>::iterator mapIt = this->
mCOPASI2SBMLMap.begin();
2962 std::map<const CCopasiObject*, SBase*>::iterator mapEndit = this->
mCOPASI2SBMLMap.end();
2964 while (mapIt != mapEndit)
2966 sbml2copasiMap.insert(std::make_pair(mapIt->second, mapIt->first));
2970 std::set<CFunction*> unusedFunctions;
2971 unsigned int i = 0, iMax = pModel->getNumFunctionDefinitions();
2972 std::map<SBase*, const CCopasiObject*>::iterator mapPos;
2973 std::set<std::string> toRemove;
2977 FunctionDefinition* pFunDef = pModel->getFunctionDefinition(i);
2979 if (pFunDef != NULL)
2981 mapPos = sbml2copasiMap.find(pFunDef);
2983 if (mapPos != sbml2copasiMap.end())
2994 toRemove.insert(pFunDef->getId());
3000 unusedFunctions.insert(pFun);
3011 usedFunctions.insert(usedFunctions.end(), functionsVect.begin(), functionsVect.end());
3014 this->
mUsedFunctions.insert(usedFunctions.begin(), usedFunctions.end());
3017 std::set<std::string>::iterator toRemoveIt = toRemove.begin();
3018 std::set<std::string>::iterator toRemoveEndit = toRemove.end();
3020 while (toRemoveIt != toRemoveEndit)
3022 FunctionDefinition* pFunDef = pModel->getFunctionDefinition(*toRemoveIt);
3024 if (pFunDef != NULL)
3026 mapPos = sbml2copasiMap.find(pFunDef);
3028 if (mapPos != sbml2copasiMap.end() &&
3031 pModel->getListOfFunctionDefinitions()->remove(*toRemoveIt);
3040 std::vector<CFunction*>::reverse_iterator reverseIt = usedFunctions.rbegin(), reverseEndit = usedFunctions.rend();
3041 functionsVect.clear();
3043 while (reverseIt != reverseEndit)
3045 if (std::find(functionsVect.begin(), functionsVect.end(), *reverseIt) == functionsVect.end())
3047 functionsVect.insert(functionsVect.begin(), *reverseIt);
3055 iMax = pModel->getNumFunctionDefinitions();
3057 for (
unsigned int i = 0; i < iMax; ++i)
3062 while (mapIt != mapEndit)
3064 if (mapIt->second == pModel->getFunctionDefinition(i))
3076 for (
int i = ((
int)pModel->getNumFunctionDefinitions()) - 1; i >= 0; --i)
3078 FunctionDefinition* current = pModel->getFunctionDefinition(i);
3080 if (current != NULL &&
3081 current->isSetAnnotation() &&
3082 current->getAnnotation()->getNumChildren() == 1 &&
3083 current->getAnnotation()->getChild(0).getURI().find(
"http://sbml.org/annotations/") != std::string::npos)
3087 FunctionDefinition* toDelete = pModel->removeFunctionDefinition(i);
3091 std::vector<CFunction*>::iterator it = functionsVect.begin(), endit = functionsVect.end();
3110 std::map<const CCopasiObject*, SBase*>::iterator pos = this->
mCOPASI2SBMLMap.find(&
function);
3111 FunctionDefinition* pFunDef = NULL;
3118 pFunDef =
dynamic_cast<FunctionDefinition*
>(pos->second);
3120 this->
mpSBMLDocument->getModel()->getListOfFunctionDefinitions()->appendAndOwn(pFunDef);
3126 pFunDef =
new FunctionDefinition(2, 4);
3134 pFunDef->setName(
function.getObjectName());
3135 std::string
id =
function.getSBMLId();
3139 id =
function.getObjectName();
3154 this->
mIdMap.insert(std::pair<const std::string, const SBase*>(
id, pFunDef));
3156 function.setSBMLId(
id);
3160 if (
function.getRoot() == NULL)
3162 std::string errorMessage = std::string(
"Can not export function '");
3163 errorMessage +=
function.getObjectName();
3164 errorMessage += std::string(
"'. Function does not have a valid root node.");
3169 std::vector<SBMLIncompatibility> result;
3176 ASTNode* pLambda =
new ASTNode(AST_LAMBDA);
3179 size_t i, iMax = funParams.
size();
3180 ASTNode* pParamNode = NULL;
3182 for (i = 0; i < iMax; ++i)
3184 pParamNode =
new ASTNode(AST_NAME);
3185 pParamNode->setName(funParams[i]->getObjectName().c_str());
3186 pLambda->addChild(pParamNode);
3189 pLambda->addChild(pFunNode);
3191 if (pFunDef->setMath(pLambda) != LIBSBML_OPERATION_SUCCESS)
3194 "The function '%s' uses an invalid expression '%s' that cannot be exported to SBML, the function definition is not exported."
3195 ,
function.getObjectName().c_str()
3196 ,
function.getInfix().c_str());
3209 if (pFunDef != NULL)
3224 if (pSBMLDocument == NULL || pSBMLDocument->getModel() == NULL)
3228 for (
unsigned int i = 0; i < pSBMLDocument->getModel()->getNumParameters(); ++i)
3229 pSBMLDocument->getModel()->getParameter(i)->setUserData(NULL);
3232 for (
unsigned int i = 0; i < pSBMLDocument->getModel()->getNumInitialAssignments(); ++i)
3233 pSBMLDocument->getModel()->getInitialAssignment(i)->setUserData(NULL);
3250 LayoutModelPlugin* lmPlugin =
static_cast<LayoutModelPlugin*
>(this->
mpSBMLDocument->getModel()->getPlugin(
"layout"));
3252 if (lmPlugin != NULL && sbmlLevel > 1)
3258 #if LIBSBML_VERSION >= 50400
3263 RenderListOfLayoutsPlugin* plugin =
static_cast<RenderListOfLayoutsPlugin *
>(lmPlugin->getListOfLayouts()->getPlugin(
"render"));
3267 if (plugin->getNumGlobalRenderInformationObjects() == 0)
3269 GlobalRenderInformation* info = plugin->createGlobalRenderInformation();
3275 #endif // LIBSBML_VERSION >= 50400
3287 if (uif.getStatistics().all[5] == 0)
3290 if ((uif.getStatistics().local[0] != 0 || uif.getStatistics().global[0] != 0) && uif.getStatistics().numbers[0] != 0)
3295 uif2.determineUnits();
3298 if (uif2.getStatistics().all[5] == 0)
3302 uif2.writeBackToModel();
3303 std::cerr <<
"undetermined: " << uif2.getStatistics().global[0] + uif2.getStatistics().local[0] << std::endl;
3308 std::cerr <<
"Warning. " << uif2.getStatistics().all[5] <<
" conflicts found." << std::endl;
3314 uif.writeBackToModel();
3315 std::cerr <<
"undetermined: " << uif.getStatistics().global[0] + uif.getStatistics().local[0] << std::endl;
3321 std::cerr <<
"Warning. " << uif.getStatistics().all[5] <<
" conflicts found." << std::endl;
3325 #endif // USE_SBMLUNIT
3331 SBMLWriter* writer =
new SBMLWriter();
3333 writer->setProgramName(
"COPASI");
3337 std::string returnValue = d;
3349 #if LIBSBML_VERSION <= 51104
3354 if (sbmlLevel == 1 && sbmlVersion == 1)
3370 , std::map<const std::string, Parameter*>& initialValueMap
3373 if (doc == NULL || doc->getModel() == NULL || initialValueMap.size() == 0)
3376 std::map<const std::string, Parameter*>::const_iterator it;
3378 for (it = initialValueMap.begin(); it != initialValueMap.end(); ++it)
3380 Parameter* param = it->second;
3382 int result = doc->getModel()->addParameter(param);
3383 doc->getModel()->getParameter(param->getId())->setUserData((
void*)
"1");
3390 InitialAssignment* ia = doc->getModel()->createInitialAssignment();
3391 ia->setSymbol(it->second->getId());
3392 ia->setMath(SBML_parseFormula(sbmlId.c_str()));
3393 ia->setUserData((
void*)
"1");
3408 assert(pModel != NULL);
3410 if (pOldSBMLDocument == NULL)
3416 this->
mpSBMLDocument =
dynamic_cast<SBMLDocument*
>(pOldSBMLDocument->clone());
3421 #if LIBSBML_VERSION >= 50000
3422 const std::string uri = (this->
mSBMLLevel < 3 ? LayoutExtension::getXmlnsL2() : LayoutExtension::getXmlnsL3V1V1());
3428 const std::string renderuri = (this->
mSBMLLevel < 3 ? RenderExtension::getXmlnsL2() : RenderExtension::getXmlnsL3V1V1());
3446 this->
mIdMap.insert(std::pair<const std::string, const SBase*>(
id, this->
mpSBMLDocument->getModel()));
3469 #if LIBSBML_VERSION >= 40100
3478 #endif // LIBSBML_VERSION
3534 assert(pSBMLModel != NULL);
3535 int i = pSBMLModel->getListOfFunctionDefinitions()->size();
3546 if (it->second == pSBMLModel->getFunctionDefinition(i))
3555 delete pSBMLModel->getListOfFunctionDefinitions()->remove(i);
3562 assert(pSBMLModel != NULL);
3564 if (pSBMLModel != NULL)
3567 #if LIBSBML_VERSION >= 40100
3569 #endif // LIBSBML_VERSION >= 40100
3570 FunctionDefinition* pFunDef = NULL;
3571 std::map<const FunctionDefinition*, const CCopasiObject*>::const_iterator funPos;
3576 assert(pFunDef != NULL);
3578 pFunDef->setSBMLNamespaces(pSBMLModel->getSBMLNamespaces());
3580 #if LIBSBML_VERSION >= 40100
3581 result = pSBMLModel->addFunctionDefinition(pFunDef);
3582 assert(result == LIBSBML_OPERATION_SUCCESS);
3584 pSBMLModel->addFunctionDefinition(pFunDef);
3585 assert(pSBMLModel->getFunctionDefinition(pFunDef->getId()) != NULL);
3586 #endif // LIBSBML_VERSION >= 40100
3590 pFunDef = pSBMLModel->getFunctionDefinition(pFunDef->getId());
3591 assert(pFunDef != NULL);
3604 #if LIBSBML_VERSION >= 50400
3613 ConversionProperties prop(&targetNs);
3614 prop.addOption(
"convertToL1V1",
true,
3615 "convert the document to SBML Level 1 Version 1");
3616 prop.addOption(
"changePow",
true,
3617 "change pow expressions to the (^) hat notation");
3618 prop.addOption(
"inlineCompartmentSizes",
true,
3619 "if true, occurrances of compartment ids in expressions will be replaced with their initial size");
3626 ConversionProperties prop(&targetNs);
3627 prop.addOption(
"strict",
false);
3628 prop.addOption(
"setLevelAndVersion",
true);
3629 prop.addOption(
"ignorePackages",
true);
3642 std::string message(
"libSBML could not convert the model to the requested level and/or version. The reason(s) given were:");
3644 for (i = 0; i < iMax ; ++i)
3648 message += pSBMLError->getMessage();
3682 std::set<CEvaluationNodeFunction::SubType> unsupportedFunctionTypes;
3710 return unsupportedFunctionTypes;
3720 bool success =
true;
3731 if (testInfile && !overwrite)
3760 std::vector<SBMLIncompatibility> result;
3762 if (pModel == NULL)
return result;
3776 std::set<std::string> usedFunctionNames;
3780 while (compIt != compEndit)
3782 status = (*compIt)->getStatus();
3786 pExpression = (*compIt)->getExpressionPtr();
3787 assert(pExpression != NULL);
3789 if (pExpression != NULL)
3793 usedFunctionNames.clear();
3799 pExpression = (*compIt)->getInitialExpressionPtr();
3801 if (pExpression != NULL)
3805 CSBMLExporter::isExpressionSBMLCompatible(*pExpression, dataModel, sbmlLevel, sbmlVersion, result, std::string(
"initial expression for compartment named \"" + (*compIt)->getObjectName() +
"\"").c_str());
3806 usedFunctionNames.clear();
3816 while (metabIt != metabEndit)
3818 status = (*metabIt)->getStatus();
3822 pExpression = (*metabIt)->getExpressionPtr();
3823 assert(pExpression != NULL);
3825 if (pExpression != NULL)
3830 usedFunctionNames.clear();
3835 pExpression = (*metabIt)->getInitialExpressionPtr();
3837 if (pExpression != NULL)
3841 CSBMLExporter::isExpressionSBMLCompatible(*pExpression, dataModel, sbmlLevel, sbmlVersion, result, std::string(
"initial species for metabolite named \"" + (*metabIt)->getObjectName() +
"\"").c_str());
3842 usedFunctionNames.clear();
3852 while (mvIt != mvEndit)
3854 status = (*mvIt)->getStatus();
3858 pExpression = (*mvIt)->getExpressionPtr();
3859 assert(pExpression != NULL);
3861 if (pExpression != NULL)
3866 usedFunctionNames.clear();
3871 pExpression = (*mvIt)->getInitialExpressionPtr();
3873 if (pExpression != NULL)
3877 CSBMLExporter::isExpressionSBMLCompatible(*pExpression, dataModel, sbmlLevel, sbmlVersion, result, std::string(
"initial expression for global parameter named \"" + (*mvIt)->getObjectName() +
"\"").c_str());
3878 usedFunctionNames.clear();
3902 while (eventIt != eventEndit)
3908 switch (sbmlVersion)
3952 if (pSBMLModel == NULL)
3956 std::set<Event*> eventSet;
3958 while (pSBMLModel->getNumEvents() != 0)
3960 Event* pEvent = pSBMLModel->getListOfEvents()->remove(pSBMLModel->getNumEvents() - 1);
3961 assert(pEvent != NULL);
3962 eventSet.insert(pEvent);
3969 Event* pSBMLEvent = NULL;
3971 std::map<const CCopasiObject*, SBase*>::const_iterator pos;
3980 pSBMLEvent =
dynamic_cast<Event*
>(pos->second);
3988 if (pSBMLEvent) eventSet.erase(pSBMLEvent);
3996 std::set<Event*>::iterator it2 = eventSet.begin(), endit2 = eventSet.end();
3998 while (it2 != endit2)
4014 if (pSBMLEvent == NULL)
4021 if (this->
mpSBMLDocument->getModel()->getListOfEvents()->appendAndOwn(pSBMLEvent) != LIBSBML_OPERATION_SUCCESS)
4033 if (!pSBMLEvent->isSetId())
4036 this->
mIdMap.insert(std::pair<const std::string, const SBase*>(sbmlId, pSBMLEvent));
4037 pSBMLEvent->setId(sbmlId);
4038 event.setSBMLId(sbmlId);
4047 #if LIBSBML_VERSION >= 40200
4054 pSBMLEvent->setPriority(NULL);
4057 #endif // LIBSBML_VERSION >= 40200
4060 if (event.
getObjectName().find_first_not_of(
"\t\r\n ") != std::string::npos)
4066 const CExpression* pExpression =
event.getTriggerExpressionPtr();
4067 assert(pExpression != NULL);
4068 std::vector<SBMLIncompatibility> result;
4074 , std::string(
"event trigger for event with id\"+" + event.
getSBMLId() +
"\"")
4081 std::set<std::string> directlyUsedFunctionNames;
4085 # if defined _MSC_VER && _MSC_VER < 1201 // 1200 Identifies Visual C++ 6.0
4087 std::set<CFunction*>::const_iterator it = usedFunctions.begin();
4088 std::set<CFunction*>::const_iterator end = usedFunctions.end();
4090 for (; it != end; ++it)
4094 this->
mUsedFunctions.insert(usedFunctions.begin(), usedFunctions.end());
4128 assert(pOrigNode != NULL);
4137 Trigger* pTrigger = pSBMLEvent->createTrigger();
4138 pTrigger->setMath(pNode);
4139 #if LIBSBML_VERSION >= 40200
4147 pTrigger->setInitialValue(
true);
4148 pTrigger->setPersistent(
true);
4151 #endif // LIBSBML_VERSION >= 40200
4163 pExpression =
event.getDelayExpressionPtr();
4164 const std::string delayInfix = pExpression == NULL ?
"" : pExpression->
getInfix();
4166 if (!delayInfix.empty())
4174 , std::string(
"event delay for event with id\"+" + event.
getSBMLId() +
"\"").c_str()
4181 std::set<std::string> directlyUsedFunctionNames;
4185 # if defined _MSC_VER && _MSC_VER < 1201 // 1200 Identifies Visual C++ 6.0
4187 it = usedFunctions.begin();
4188 usedFunctions.end();
4190 for (; it != end; ++it)
4194 this->
mUsedFunctions.insert(usedFunctions.begin(), usedFunctions.end());
4224 assert(pOrigNode != NULL);
4234 pDelay->setMath(pNode);
4235 pSBMLEvent->setDelay(pDelay);
4266 if (pSBMLEvent->getNumEventAssignments() == 0 &&
mpSBMLDocument->getLevel() < 3)
4268 unsigned int i, iMax = this->
mpSBMLDocument->getModel()->getNumEvents();
4272 for (i = 0; i < iMax; ++i)
4287 if (pSBMLEvent != NULL)
4298 std::map<std::string, EventAssignment*> assignmentMap;
4300 while (pSBMLEvent->getNumEventAssignments() != 0)
4302 EventAssignment* pAssignment = pSBMLEvent->getEventAssignment(pSBMLEvent->getNumEventAssignments() - 1);
4303 assert(pAssignment != NULL);
4304 assignmentMap[pAssignment->getVariable()] = pAssignment;
4305 pSBMLEvent->getListOfEventAssignments()->remove(pSBMLEvent->getNumEventAssignments() - 1);
4311 for (; itAssignment != endAssignment; ++itAssignment)
4315 std::string key = (*itAssignment)->getTargetKey();
4322 if (objectType ==
"Reference")
4328 if (objectType !=
"Compartment" && objectType !=
"Metabolite" && objectType !=
"ModelValue")
4335 std::map<const CCopasiObject*, SBase*>::const_iterator pos = this->
mCOPASI2SBMLMap.find(pObject);
4346 SBase* pSBase = pos->second;
4347 assert(pSBase != NULL);
4359 Compartment* pSBMLCompartment = NULL;
4360 Species* pSBMLSpecies = NULL;
4361 Parameter* pSBMLParameter = NULL;
4363 switch (pSBase->getTypeCode())
4365 case SBML_COMPARTMENT:
4366 pSBMLCompartment =
dynamic_cast<Compartment*
>(pSBase);
4367 assert(pSBMLCompartment != NULL);
4369 if (pSBMLCompartment->getConstant() ==
true)
4371 pSBMLCompartment->setConstant(
false);
4377 pSBMLSpecies =
dynamic_cast<Species*
>(pSBase);
4378 assert(pSBMLSpecies != NULL);
4380 if (pSBMLSpecies->getConstant() ==
true)
4382 pSBMLSpecies->setConstant(
false);
4387 case SBML_PARAMETER:
4388 pSBMLParameter =
dynamic_cast<Parameter*
>(pSBase);
4389 assert(pSBMLParameter != NULL);
4391 if (pSBMLParameter->getConstant() ==
true)
4393 pSBMLParameter->setConstant(
false);
4403 std::string sbmlId = pSBase->getId();
4404 assert(sbmlId.find_first_not_of(
"\t\r\n ") != std::string::npos);
4405 std::map<std::string, EventAssignment*>::iterator pos2 = assignmentMap.find(sbmlId);
4406 EventAssignment* pAssignment = NULL;
4408 if (pos2 != assignmentMap.end())
4410 pAssignment =
dynamic_cast<EventAssignment*
>(pos2->second);
4411 assert(pAssignment != NULL);
4412 pSBMLEvent->getListOfEventAssignments()->appendAndOwn(pAssignment);
4414 assignmentMap.erase(pos2);
4417 if (pAssignment == NULL)
4419 pAssignment = pSBMLEvent->createEventAssignment();
4422 pAssignment->setVariable(sbmlId);
4424 const CExpression * pExpression = (*itAssignment)->getExpressionPtr();
4426 if (pExpression != NULL)
4428 std::vector<SBMLIncompatibility> result;
4435 , std::string(
"event assignment for variable \"" + sbmlId +
"\" in event with id\"+" + event.
getSBMLId() +
"\"")
4442 std::set<std::string> directlyUsedFunctionNames;
4446 # if defined _MSC_VER && _MSC_VER < 1201 // 1200 Identifies Visual C++ 6.0
4448 it = usedFunctions.begin();
4449 usedFunctions.end();
4451 for (; it != end; ++it)
4455 this->
mUsedFunctions.insert(usedFunctions.begin(), usedFunctions.end());
4485 assert(pOrigNode != NULL);
4489 const CMetab* pMetab =
dynamic_cast<const CMetab*
>(pObject);
4493 std::map<const CCopasiObject*, SBase*>::const_iterator pos = this->
mCOPASI2SBMLMap.find(pObject);
4496 if (dynamic_cast<const Species*>(pos->second)->getHasOnlySubstanceUnits() ==
true)
4503 assert(pNode != NULL);
4522 pAssignment->setMath(pNode);
4543 std::map<std::string, EventAssignment*>::iterator it = assignmentMap.begin(), endit = assignmentMap.end();
4567 std::map<CCopasiObject*, SBase*>& modelMap =
const_cast<CCopasiDataModel&
>(dataModel).getCopasi2SBMLMap();
4568 std::map<CCopasiObject*, SBase*>::const_iterator it = modelMap.begin();
4569 std::map<CCopasiObject*, SBase*>::const_iterator endit = modelMap.end();
4573 std::map<std::string, const SBase*>::iterator pos = it->second == NULL ?
mIdMap.end() : this->
mIdMap.find(it->second->getId());
4575 if (pos != this->
mIdMap.end())
4577 this->
mCOPASI2SBMLMap.insert(std::pair<const CCopasiObject * const, SBase*>(it->first, const_cast<SBase*>(pos->second)));
4586 KineticLaw* pKLaw = NULL;
4591 pKLaw =
new KineticLaw(level, version);
4597 for (i = 0; i < iMax; ++i)
4614 assert(v.size() == 1);
4616 assert(pTmpObject != NULL);
4618 assert(pLocalParameter != NULL);
4627 Parameter* pSBMLPara = NULL;
4628 #if LIBSBML_VERSION >= 40100
4632 pSBMLPara = pKLaw->createLocalParameter();
4636 #endif // LIBSBML_VERSION
4637 pSBMLPara = pKLaw->createParameter();
4638 #if LIBSBML_VERSION >= 40100
4642 #endif // LIBSBML_VERSION
4656 pSBMLPara->setValue(value);
4669 if (pExpression == NULL)
4683 assert(pOrigNode != NULL);
4690 assert(pNode != NULL);
4704 if (pTNode->getNumChildren() == 0)
4709 if (pTNode->getNumChildren() == 1)
4721 pTNode =
new ASTNode(AST_TIMES);
4722 ASTNode* pVNode =
new ASTNode(AST_NAME);
4723 pVNode->setName(compartment.
getSBMLId().c_str());
4724 pTNode->addChild(pVNode);
4725 pTNode->addChild(pNode);
4731 pKLaw->setMath(pNode);
4740 ASTNode* pResult = NULL;
4742 if (pRootNode->getType() == AST_DIVIDE || pRootNode->getType() == AST_TIMES)
4745 unsigned int i, iMax = pRootNode->getNumChildren();
4748 for (i = 0; i < iMax; ++i)
4750 const ASTNode* pChild = pRootNode->getChild(i);
4752 if (pRootNode->getType() == AST_DIVIDE && pChild->getType() == AST_NAME && pChild->getName() == compartmentId)
4756 else if ((!found) && (pChild->getType() == AST_DIVIDE || pChild->getType() == AST_TIMES))
4760 if (pSubResult != NULL)
4764 if (pSubResult->getNumChildren() > 1)
4766 pTmpResultNode->addChild(pSubResult);
4768 else if (pSubResult->getNumChildren() == 1)
4770 pTmpResultNode->addChild(static_cast<ASTNode*>(static_cast<ConverterASTNode*>(pSubResult)->removeChild(0)));
4791 pResult = pTmpResultNode;
4795 delete pTmpResultNode;
4816 size_t i, iMax = arguments.size();
4819 for (i = 0; i < iMax; ++i)
4827 if (dynamic_cast<const CModel*>(pObject) != NULL)
4829 cn =
"<" + pObject->
getCN() +
",Reference=Time>";
4831 else if (dynamic_cast<const CCompartment*>(pObject) != NULL)
4833 cn =
"<" + pObject->
getCN() +
",Reference=Volume>";
4835 else if (dynamic_cast<const CMetab*>(pObject) != NULL)
4837 cn =
"<" + pObject->
getCN() +
",Reference=Concentration>";
4839 else if (dynamic_cast<const CModelValue*>(pObject) != NULL)
4841 cn =
"<" + pObject->
getCN() +
",Reference=Value>";
4843 else if (dynamic_cast<const CReaction*>(pObject) != NULL)
4845 cn =
"<" + pObject->
getCN() +
",Reference=Flux>";
4847 else if (dynamic_cast<const CCopasiParameter*>(pObject) != NULL)
4851 cn =
"<" + pObject->
getCN() +
">";
4855 cn =
"<" + pObject->
getCN() +
">";
4861 pResult = pFunctionCall;
4874 ASTNode* pNode = NULL;
4875 double multiplicity = vect[pos]->getMultiplicity();
4877 if (pos == vect.
size() - 1)
4879 pNode =
new ASTNode(AST_NAME);
4880 const CMetab* pMetab = vect[pos]->getMetabolite();
4883 pNode->setName(pMetab->
getSBMLId().c_str());
4886 if (multiplicity != 1.0)
4888 ASTNode* pTmpNode1 =
new ASTNode(AST_POWER);
4889 ASTNode* pTmpNode2 =
new ASTNode(AST_REAL);
4890 pTmpNode2->setValue(multiplicity);
4891 pTmpNode1->addChild(pNode);
4892 pTmpNode1->addChild(pTmpNode2);
4898 pNode =
new ASTNode(AST_TIMES);
4899 ASTNode* pChild =
new ASTNode(AST_NAME);
4900 const CMetab* pMetab = vect[pos]->getMetabolite();
4903 pChild->setName(pMetab->
getSBMLId().c_str());
4906 if (multiplicity != 1.0)
4908 ASTNode* pTmpNode1 =
new ASTNode(AST_POWER);
4909 ASTNode* pTmpNode2 =
new ASTNode(AST_REAL);
4910 pTmpNode2->setValue(multiplicity);
4911 pTmpNode1->addChild(pChild);
4912 pTmpNode1->addChild(pTmpNode2);
4916 pNode->addChild(pChild);
4929 if (pRootNode == NULL)
return;
4933 result.insert(pRootNode->
getData());
4938 while (pChild != NULL)
4947 std::map<CFunction*, std::set<CFunction*> > functionDependencyMap;
4948 std::set<CFunction*>::iterator setit = functions.begin(), setendit = functions.end();
4951 while (setit != setendit)
4953 std::set<std::string> usedFunctionNames;
4956 functionDependencyMap[*setit] = usedFunctions;
4965 std::map<CFunction*, std::set<CFunction*> >::iterator mapIt = functionDependencyMap.begin(), mapEndit = functionDependencyMap.end();
4967 while (mapIt != mapEndit)
4969 setit = mapIt->second.begin(), setendit = mapIt->second.end();
4971 while (setit != setendit)
4974 if (functionDependencyMap.find(*setit) == functionDependencyMap.end())
4977 std::set<std::string> usedFunctionNames;
4980 functionDependencyMap[*setit] = usedFunctions;
4997 bool removed =
true;
4998 std::vector<CFunction*> functionVector;
5000 while (!functionDependencyMap.empty() && removed ==
true)
5002 std::map<CFunction*, std::set<CFunction*> >::iterator mapIt = functionDependencyMap.begin(), mapEndit = functionDependencyMap.end();
5006 while (mapIt != mapEndit)
5008 if (mapIt->second.empty())
5015 functionVector.push_back(mapIt->first);
5018 std::map<CFunction*, std::set<CFunction*> >::iterator mapIt2 = functionDependencyMap.begin(), mapEndit2 = functionDependencyMap.end();
5020 while (mapIt2 != mapEndit2)
5022 std::set<CFunction*>::iterator pos = mapIt2->second.find(mapIt->first);
5024 if (pos != mapIt2->second.end())
5026 mapIt2->second.erase(pos);
5033 std::map<CFunction*, std::set<CFunction*> >::iterator pos = mapIt;
5035 functionDependencyMap.erase(pos);
5046 if (!functionDependencyMap.empty())
5051 return functionVector;
5056 std::set<CFunction*> result;
5060 std::set<std::string>::const_iterator it = names.begin();
5061 std::set<std::string>::const_iterator endit = names.end();
5074 result.insert(pFun);
5087 std::map<CModelEntity*, std::set<const CModelEntity*> > dependencyMap;
5092 const CExpression* pExpr = (*it)->getExpressionPtr();
5093 assert(pExpr != NULL);
5094 std::set<const CModelEntity*> dependencies;
5108 dependencyMap[*it] = dependencies;
5114 std::vector<CModelEntity*> orderedRules;
5116 std::map<CModelEntity*, std::set<const CModelEntity*> > reducedDependencyMap;
5117 std::map<CModelEntity*, std::set<const CModelEntity*> >::iterator mapIt = dependencyMap.begin(), mapEndit = dependencyMap.end();
5119 while (mapIt != mapEndit)
5121 std::set<const CModelEntity*> dependencies;
5122 std::set<const CModelEntity*>::const_iterator setIt = mapIt->second.begin(), setEndit = mapIt->second.end();
5124 while (setIt != setEndit)
5126 if (dependencyMap.find(const_cast<CModelEntity*>(*setIt)) != dependencyMap.end())
5128 dependencies.insert(*setIt);
5134 reducedDependencyMap[mapIt->first] = dependencies;
5138 while (error ==
false && !reducedDependencyMap.empty())
5140 mapIt = reducedDependencyMap.begin(), mapEndit = reducedDependencyMap.end();
5145 while (mapIt != mapEndit)
5149 if (!mapIt->second.empty())
5151 std::vector<CModelEntity*>::iterator vIt = orderedRules.begin(), vEndit = orderedRules.end();
5153 while (vIt != vEndit)
5155 std::set<const CModelEntity*>::iterator pos = mapIt->second.find(*vIt);
5157 if (pos != mapIt->second.end())
5159 mapIt->second.erase(pos);
5166 if (mapIt->second.empty())
5170 orderedRules.push_back(mapIt->first);
5181 reducedDependencyMap.erase(mapIt);
5185 return orderedRules;
5190 if (pNode == NULL)
return;
5195 assert(pObjectNode != NULL);
5197 if (pObjectNode != NULL)
5209 assert(pObject != NULL);
5216 dependencies.insert(pME);
5223 while (pChild != NULL)
5243 Reaction* pReaction = NULL;
5244 KineticLaw* pLaw = NULL;
5245 unsigned int i, iMax = pModel->getNumRules();
5247 for (i = 0; i < iMax; ++i)
5249 pRule = pModel->getRule(i);
5250 assert(pRule != NULL);
5251 const ASTNode* pMath = pRule->getMath();
5252 assert(pMath != NULL);
5253 std::string message =
"rule for object with id \"";
5254 message += pRule->getVariable();
5257 assert(pNewMath != NULL);
5259 if (pNewMath != NULL)
5261 pRule->setMath(pNewMath);
5266 iMax = pModel->getNumReactions();
5268 for (i = 0; i < iMax; ++i)
5270 pReaction = pModel->getReaction(i);
5271 assert(pReaction != NULL);
5272 pLaw = pReaction->getKineticLaw();
5277 const ASTNode* pMath = pLaw->getMath();
5278 assert(pMath != NULL);
5279 std::string message =
"kinetic law in reaction with id \"";
5280 message += pReaction->getId();
5283 assert(pNewMath != NULL);
5285 if (pNewMath != NULL)
5287 pLaw->setMath(pNewMath);
5304 if (pNode == NULL)
return NULL;
5306 ASTNode* pResult = NULL;
5307 ASTNode* pChild = NULL;
5308 unsigned int i, iMax;
5310 switch (pNode->getType())
5312 case AST_FUNCTION_PIECEWISE:
5315 case AST_CONSTANT_E:
5317 pResult =
new ASTNode(AST_FUNCTION_EXP);
5318 pChild =
new ASTNode(AST_REAL);
5319 pChild->setValue(1.0);
5320 pResult->addChild(pChild);
5323 case AST_CONSTANT_PI:
5325 pResult =
new ASTNode(AST_TIMES);
5326 pChild =
new ASTNode(AST_REAL);
5327 pChild->setValue(2.0);
5328 pResult->addChild(pChild);
5329 pResult->addChild(
new ASTNode(AST_FUNCTION_ARCSIN));
5330 pChild =
new ASTNode(AST_REAL);
5331 pChild->setValue(1.0);
5332 pResult->getChild(1)->addChild(pChild);
5335 case AST_FUNCTION_SEC:
5343 case AST_FUNCTION_CSC:
5351 case AST_FUNCTION_COT:
5359 case AST_FUNCTION_SINH:
5367 case AST_FUNCTION_COSH:
5375 case AST_FUNCTION_TANH:
5383 case AST_FUNCTION_SECH:
5391 case AST_FUNCTION_CSCH:
5399 case AST_FUNCTION_COTH:
5407 case AST_FUNCTION_ARCSINH:
5415 case AST_FUNCTION_ARCCOSH:
5423 case AST_FUNCTION_ARCTANH:
5431 case AST_FUNCTION_ARCSECH:
5439 case AST_FUNCTION_ARCCSCH:
5447 case AST_FUNCTION_ARCCOTH:
5456 if (pNode->getReal() != pNode->getReal())
5459 pResult =
new ASTNode(AST_RATIONAL);
5460 pResult->setValue(0L, 0L);
5465 pResult =
new ASTNode(AST_RATIONAL);
5466 pResult->setValue(1L, 0L);
5471 pResult =
new ASTNode(AST_RATIONAL);
5472 pResult->setValue(-1L, 0L);
5476 pResult = pNode->deepCopy();
5484 iMax = pNode->getNumChildren();
5486 for (i = 0; i < iMax; ++i)
5492 pResult->addChild(pChild);
5511 if (pExpanded != NULL)
5516 if (pReplaced == NULL)
5521 pExpanded = pReplaced;
5533 std::set<std::string> usedFunctionNames;
5536 if (pModel == NULL)
return;
5543 size_t i, iMax = compartments.
size();
5545 for (i = 0; i < iMax; ++i)
5547 pME = compartments[i];
5559 iMax = metabolites.
size();
5561 for (i = 0; i < iMax; ++i)
5563 pME = metabolites[i];
5575 iMax = modelvalues.
size();
5577 for (i = 0; i < iMax; ++i)
5579 pME = modelvalues[i];
5593 iMax = reactions.
size();
5595 for (i = 0; i < iMax; ++i)
5597 pReaction = reactions[i];
5608 std::vector<CFunction*>::const_iterator it = functions.begin(), endit = functions.end();
5631 size_t size = result.size();
5634 while (pChild != NULL && result.size() == size)
5652 std::map<const SBase*, const CCopasiObject*> reverseCOPASI2SBMLMap;
5657 reverseCOPASI2SBMLMap.insert(std::pair<const SBase*, const CCopasiObject*>(it->second, it->first));
5662 std::list<SBase*> removedObjects;
5663 SBase* pSBase = NULL;
5664 ListOf* pList = pModel->getListOfCompartments();
5666 std::map<const SBase*, const CCopasiObject*>::const_iterator pos;
5667 std::map<const CCopasiObject*, SBase*>::iterator pos2;
5669 for (i = pList->size(); i != 0; --i)
5671 pSBase = pList->get(i - 1);
5675 removedObjects.push_back(pList->remove(i - 1));
5679 pList = pModel->getListOfSpecies();
5681 for (i = pList->size(); i != 0; --i)
5683 pSBase = pList->get(i - 1);
5687 removedObjects.push_back(pList->remove(i - 1));
5691 pList = pModel->getListOfParameters();
5693 for (i = pList->size(); i != 0; --i)
5695 pSBase = pList->get(i - 1);
5698 if (pSBase->getUserData() != NULL && strcmp((
const char*)pSBase->getUserData(),
"1") == 0)
5703 removedObjects.push_back(pList->remove(i - 1));
5707 pList = pModel->getListOfInitialAssignments();
5709 for (i = pList->size(); i != 0; --i)
5711 pSBase = pList->get(i - 1);
5714 if (pSBase->getUserData() != NULL && strcmp((
const char*)pSBase->getUserData(),
"1") == 0)
5720 pos = reverseCOPASI2SBMLMap.find(pSBase);
5722 if (pos != reverseCOPASI2SBMLMap.end() && pos->second != NULL)
5734 delete pList->remove(i - 1);
5738 pList = pModel->getListOfReactions();
5740 for (i = pList->size(); i != 0; --i)
5742 pSBase = pList->get(i - 1);
5747 pos = reverseCOPASI2SBMLMap.find(pSBase);
5749 if (pos != reverseCOPASI2SBMLMap.end() && pos->second != NULL)
5761 delete pList->remove(i - 1);
5767 std::list<SBase*>::iterator it2 = removedObjects.begin(), endit2 = removedObjects.end();
5768 pList = pModel->getListOfRules();
5769 ListOf* pEventList = pModel->getListOfEvents();
5770 ListOf* pInitialAssignmentList = pModel->getListOfInitialAssignments();
5772 Event* pEvent = NULL;
5773 InitialAssignment* pIA = NULL;
5776 while (it2 != endit2)
5778 iMax = pList->size();
5780 for (i = 0; i < iMax; ++i)
5782 pRule =
dynamic_cast<Rule*
>(pList->get(i));
5784 if (pRule != NULL && pRule->isSetVariable() && pRule->getVariable() == (*it2)->getId())
5787 pos = reverseCOPASI2SBMLMap.find(pRule);
5789 if (pos != reverseCOPASI2SBMLMap.end() && pos->second != NULL)
5799 delete pList->remove(i);
5804 iMax = pInitialAssignmentList->size();
5806 for (i = 0; i < iMax; ++i)
5808 pIA =
dynamic_cast<InitialAssignment*
>(pInitialAssignmentList->get(i));
5810 if (pIA->isSetSymbol() && pIA->getSymbol() == (*it2)->getId())
5813 pos = reverseCOPASI2SBMLMap.find(pIA);
5815 if (pos != reverseCOPASI2SBMLMap.end() && pos->second != NULL)
5825 delete pInitialAssignmentList->remove(i);
5830 iMax = pEventList->size();
5832 for (i = 0; i < iMax; ++i)
5834 pEvent =
dynamic_cast<Event*
>(pEventList->get(i));
5838 ListOfEventAssignments* pEAL = pEvent->getListOfEventAssignments();
5839 EventAssignment* pEA = NULL;
5840 unsigned int j, jMax = pEAL->size();
5842 for (j = 0; j < jMax; ++j)
5844 pEA = pEvent->getEventAssignment(j);
5846 if (pEA != NULL && pEA->getVariable() == (*it2)->getId())
5849 pos = reverseCOPASI2SBMLMap.find(pEA);
5851 if (pos != reverseCOPASI2SBMLMap.end() && pos->second != NULL)
5861 delete pEAL->remove(j);
5868 if (pEAL->size() == 0)
5871 pos = reverseCOPASI2SBMLMap.find(pEvent);
5873 if (pos != reverseCOPASI2SBMLMap.end() && pos->second != NULL)
5883 delete pEventList->remove(i);
5889 pos = reverseCOPASI2SBMLMap.find(*it2);
5891 if (pos != reverseCOPASI2SBMLMap.end() && pos->second != NULL)
5909 assert((isReversible && arguments.size() == 4) || arguments.size() == 2);
5910 assert(arguments[0].size() == 1 && arguments[1].size() > 0);
5913 std::set<std::string> finishedElements;
5914 std::vector<CEvaluationNode*> multiplicants;
5916 assert(pObject != NULL);
5918 std::vector<std::string>::const_iterator it = arguments[1].begin(), endit = arguments[1].end();
5922 if (finishedElements.find(*it) == finishedElements.end())
5927 unsigned int num = 0;
5928 std::count(arguments[1].begin(), arguments[1].end(), *it, num);
5930 size_t num = std::count(arguments[1].begin(), arguments[1].end(), *it);
5931 #endif // __SUNPRO_CC
5933 finishedElements.insert(*it);
5935 assert(pObject != NULL);
5943 std::ostringstream os;
5948 multiplicants.push_back(pOperator);
5955 std::vector<CEvaluationNode*>::reverse_iterator rIt = multiplicants.rbegin(), rEndit = multiplicants.rend();
5964 while (rIt != rEndit)
5981 std::vector<std::vector<std::string> > tmpV;
5982 tmpV.push_back(arguments[2]);
5983 tmpV.push_back(arguments[3]);
5997 if (
id.length() > 0)
6000 result = (c ==
'_' || (c > 64 && c < 91) || (c > 96 && c < 123));
6001 size_t i, iMax =
id.length();
6003 for (i = 1; (i < iMax) && result; ++i)
6006 result = (c ==
'_' || (c > 64 && c < 91) || (c > 96 && c < 123) || (c > 47 && c < 58));
6023 ListOfInitialAssignments* pList = this->
mpSBMLDocument->getModel()->getListOfInitialAssignments();
6024 unsigned int i, iMax = pList->size();
6026 for (i = 0; i < iMax; ++i)
6028 InitialAssignment* pIA =
dynamic_cast<InitialAssignment*
>(pList->get(i));
6030 if (pIA->getSymbol() == sbmlId)
6044 ListOfRules* pList = this->
mpSBMLDocument->getModel()->getListOfRules();
6045 unsigned int i, iMax = pList->size();
6047 for (i = 0; i < iMax; ++i)
6049 Rule* pR =
dynamic_cast<Rule*
>(pList->get(i));
6051 if (pR->getVariable() == sbmlId)
6073 std::vector<CCopasiContainer*> containers;
6074 containers.push_back(const_cast<CModel*>(dataModel.
getModel()));
6075 const CCopasiObject* pObject = dataModel.
ObjectFromName(containers, dynamic_cast<const CEvaluationNodeObject*>(pOrigNode)->getObjectCN());
6077 if (pObject == NULL)
6088 const CMetab* pMetab =
dynamic_cast<const CMetab*
>(pParent);
6108 assert(pCompartment != NULL);
6145 Parameter* pSBMLAvogadro = this->
mpSBMLDocument->getModel()->createParameter();
6146 pSBMLAvogadro->setName(
"quantity to number factor");
6148 pSBMLAvogadro->setId(sbmlId);
6150 this->
mIdMap.insert(std::pair<const std::string, const SBase*>(sbmlId, pSBMLAvogadro));
6154 pSBMLAvogadro->setConstant(
true);
6160 pSBMLAvogadro->setConstant(
true);
6219 assert(pLeft != NULL);
6220 assert(pRight != NULL);
6224 std::vector<CCopasiContainer*> containers;
6225 containers.push_back(const_cast<CModel*>(dataModel.
getModel()));
6226 const CCopasiObject* pObject = dataModel.
ObjectFromName(containers, dynamic_cast<const CEvaluationNodeObject*>(pLeft)->getObjectCN());
6232 const CMetab* pMetab =
dynamic_cast<const CMetab*
>(pParent);
6244 if (fabs((factor - value) / factor) <= 1e-3)
6253 const CCopasiObject* pObject2 = dataModel.
ObjectFromName(containers, dynamic_cast<const CEvaluationNodeObject*>(pRight)->getObjectCN());