COPASI API  4.16.103
Macros | Functions
SBMLImporter.cpp File Reference
#include <iostream>
#include <vector>
#include <sstream>
#include <map>
#include <limits>
#include <cmath>
#include <sbml/SBMLReader.h>
#include <sbml/SBMLDocument.h>
#include <sbml/Compartment.h>
#include <sbml/Species.h>
#include <sbml/SpeciesReference.h>
#include <sbml/Reaction.h>
#include <sbml/LocalParameter.h>
#include <sbml/KineticLaw.h>
#include <sbml/math/FormulaFormatter.h>
#include <sbml/Model.h>
#include <sbml/UnitKind.h>
#include <sbml/Unit.h>
#include <sbml/Parameter.h>
#include <sbml/InitialAssignment.h>
#include <sbml/Rule.h>
#include <sbml/FunctionDefinition.h>
#include <sbml/UnitDefinition.h>
#include "copasi.h"
#include "report/CKeyFactory.h"
#include "model/CModel.h"
#include "model/CCompartment.h"
#include "model/CMetab.h"
#include "model/CReaction.h"
#include "model/CModelValue.h"
#include "model/CEvent.h"
#include "function/CNodeK.h"
#include "function/CFunctionDB.h"
#include "function/CEvaluationTree.h"
#include "function/CExpression.h"
#include "function/CFunctionParameters.h"
#include "report/CCopasiObjectReference.h"
#include "utilities/CCopasiTree.h"
#include "utilities/CNodeIterator.h"
#include "CopasiDataModel/CCopasiDataModel.h"
#include "report/CCopasiRootContainer.h"
#include "MIRIAM/CRDFGraphConverter.h"
#include "compareExpressions/CEvaluationNodeNormalizer.h"
#include "commandline/CLocaleString.h"
#include "commandline/COptions.h"
#include "SBMLImporter.h"
#include "SBMLUtils.h"
#include "ConverterASTNode.h"
#include "utilities/CProcessReport.h"
#include "copasi/commandline/CConfigurationFile.h"
#include "layout/SBMLDocumentLoader.h"
#include "layout/CListOfLayouts.h"
#include "utilities/CCopasiMessage.h"

Go to the source code of this file.

Macros

#define INIT_DEFAULTS(element)
 
#define USE_LAYOUT   1
 

Functions

bool addToKnownFunctionToMap (std::map< std::string, std::string > &map, const FunctionDefinition *sbmlFunction)
 
int AstStrCmp (const void *s1, const void *s2)
 
bool containsKey (const CCopasiVector< CChemEqElement > &list, const std::string &key)
 
void ensureAllArgsAreBeingUsedInFunctionDefinition (const FunctionDefinition *sbmlFunction)
 
CFunctionfindFunction (CCopasiVectorN< CFunction > &db, const CFunction *func)
 
CFunctiongetFunctionForKey (CCopasiVectorN< CFunction > &functionDb, const std::string &key)
 
std::string getInitialCNForSBase (SBase *sbase, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap)
 
std::string getOriginalSBMLId (Parameter *parameter)
 
std::string isKnownCustomFunctionDefinition (const FunctionDefinition *sbmlFunction, const std::string &sNamespace, const std::string &elementName, const std::string &definition)
 

Macro Definition Documentation

#define INIT_DEFAULTS (   element)
Value:
{\
}

Definition at line 49 of file SBMLImporter.cpp.

Referenced by SBMLImporter::createCModelFromSBMLDocument().

#define USE_LAYOUT   1

Definition at line 22 of file SBMLImporter.cpp.

Function Documentation

bool addToKnownFunctionToMap ( std::map< std::string, std::string > &  map,
const FunctionDefinition *  sbmlFunction 
)

Definition at line 1590 of file SBMLImporter.cpp.

References isKnownCustomFunctionDefinition().

Referenced by SBMLImporter::createCFunctionFromFunctionDefinition().

1591 {
1592  if (!sbmlFunction->isSetAnnotation())
1593  return false;
1594 
1595  std::string id = isKnownCustomFunctionDefinition(sbmlFunction,
1596  "http://sbml.org/annotations/symbols",
1597  "symbols",
1598  "http://en.wikipedia.org/wiki/Derivative");
1599 
1600  if (!id.empty())
1601  {
1602  map[id] = "RATE";
1603  return true;
1604  }
1605 
1606  id = isKnownCustomFunctionDefinition(sbmlFunction,
1607  "http://sbml.org/annotations/distribution",
1608  "distribution",
1609  "http://www.uncertml.org/distributions/normal");
1610 
1611  if (!id.empty())
1612  {
1613  map[id] = "RNORMAL";
1614  return true;
1615  }
1616 
1617  id = isKnownCustomFunctionDefinition(sbmlFunction,
1618  "http://sbml.org/annotations/distribution",
1619  "distribution",
1620  "http://www.uncertml.org/distributions/uniform");
1621 
1622  if (!id.empty())
1623  {
1624  map[id] = "RUNIFORM";
1625  return true;
1626  }
1627 
1628  id = isKnownCustomFunctionDefinition(sbmlFunction,
1629  "http://sbml.org/annotations/distribution",
1630  "distribution",
1631  "http://www.uncertml.org/distributions/gamma");
1632 
1633  if (!id.empty())
1634  {
1635  map[id] = "RGAMMA";
1636  return true;
1637  }
1638 
1639  id = isKnownCustomFunctionDefinition(sbmlFunction,
1640  "http://sbml.org/annotations/distribution",
1641  "distribution",
1642  "http://www.uncertml.org/distributions/poisson");
1643 
1644  if (!id.empty())
1645  {
1646  map[id] = "RPOISSON";
1647  return true;
1648  }
1649 
1650  return false;
1651 }
std::string isKnownCustomFunctionDefinition(const FunctionDefinition *sbmlFunction, const std::string &sNamespace, const std::string &elementName, const std::string &definition)
int AstStrCmp ( const void s1,
const void s2 
)

Definition at line 1654 of file SBMLImporter.cpp.

Referenced by ensureAllArgsAreBeingUsedInFunctionDefinition().

1655 {
1656  const char* a = static_cast<const ASTNode *>(s1)->getName();
1657  const char* b = static_cast<const ASTNode *>(s2)->getName();
1658 
1659  if (a == NULL && b == NULL) return 0;
1660 
1661  if (a == NULL && b != NULL) return -1;
1662 
1663  if (a != NULL && b == NULL) return 1;
1664 
1665  return strcmp(
1666  a,
1667  b);
1668 }
bool containsKey ( const CCopasiVector< CChemEqElement > &  list,
const std::string &  key 
)

Definition at line 5724 of file SBMLImporter.cpp.

References CCopasiVector< T >::begin(), and CCopasiVector< T >::end().

Referenced by SBMLImporter::doMapping().

5725 {
5728 
5729  for (; it != end; ++it)
5730  {
5731  if ((*it)->getMetaboliteKey() == key)
5732  {
5733  return true;
5734  }
5735  }
5736 
5737  return false;
5738 }
iterator begin()
iterator end()
void ensureAllArgsAreBeingUsedInFunctionDefinition ( const FunctionDefinition *  sbmlFunction)

This function checks the function definition for unused arguments (that would not be properly displayed in the CopasiUI). If found, the function body will be replaced with one including all arguments.

Definition at line 1675 of file SBMLImporter.cpp.

References AstStrCmp().

Referenced by SBMLImporter::createCFunctionFromFunctionDefinition().

1676 {
1677  if (sbmlFunction == NULL || sbmlFunction->getNumArguments() == 0 || sbmlFunction->getBody() == NULL) return;
1678 
1679  // get all variables
1680  List *variables = sbmlFunction->getBody()->getListOfNodes(ASTNode_isName);
1681 
1682  // find unused ones
1683  std::vector<std::string> unused;
1684 
1685  for (unsigned int i = 0; i < sbmlFunction->getNumArguments(); ++i)
1686  {
1687  const ASTNode *arg = sbmlFunction->getArgument(i);
1688 
1689  if (variables->find(arg, AstStrCmp) == NULL)
1690  {
1691  if (arg->getName() != NULL)
1692  unused.push_back(arg->getName());
1693  }
1694  }
1695 
1696  // get rid of the list
1697  delete variables;
1698 
1699  // let us hope this is empty
1700  if (unused.size() == 0)
1701  return;
1702 
1703  // it is not, so modify the function definition to include all of them
1704  std::stringstream str;
1705  str << "lambda(";
1706 
1707  for (unsigned int i = 0; i < sbmlFunction->getNumArguments(); ++i)
1708  str << sbmlFunction->getArgument(i)->getName() << ", ";
1709 
1710  char* formula = SBML_formulaToString(sbmlFunction->getBody());
1711  str << formula;
1712 
1713  std::vector<std::string>::iterator it;
1714 
1715  for (it = unused.begin(); it != unused.end(); ++it)
1716  str << " + 0*" << *it;
1717 
1718  str << ")";
1719 
1720  // update the function definition
1721  const_cast<FunctionDefinition*>(sbmlFunction)->setMath(SBML_parseFormula(str.str().c_str()));
1722 
1723  // free the formula
1724  free(formula);
1725 }
int AstStrCmp(const void *s1, const void *s2)
CFunction* findFunction ( CCopasiVectorN< CFunction > &  db,
const CFunction func 
)

Definition at line 2126 of file SBMLImporter.cpp.

References CCopasiVector< T >::size().

Referenced by CModel::convert2NonReversible().

2127 {
2128  size_t i, iMax = db.size();
2129 
2130  for (i = 0; i < iMax; ++i)
2131  {
2132  CFunction* pFun = (db[i]);
2133 
2134  if (*pFun == *func)
2135  return pFun;
2136  }
2137 
2138  return NULL;
2139 }
virtual size_t size() const
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
CFunction* getFunctionForKey ( CCopasiVectorN< CFunction > &  functionDb,
const std::string &  key 
)

Definition at line 1926 of file SBMLImporter.cpp.

References CCopasiVector< T >::begin(), and CCopasiVector< T >::end().

1927 {
1928  CFunction* pFunc = NULL;
1929  CCopasiVectorN<CFunction>::iterator it = functionDb.begin(), endit = functionDb.end();
1930 
1931  while (it != endit)
1932  {
1933  if ((*it)->getKey() == key)
1934  {
1935  pFunc = dynamic_cast<CFunction*>(*it);
1936  break;
1937  }
1938 
1939  ++it;
1940  }
1941 
1942  return pFunc;
1943 }
iterator begin()
iterator end()
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
std::string getInitialCNForSBase ( SBase *  sbase,
std::map< CCopasiObject *, SBase * > &  copasi2sbmlmap 
)

Definition at line 212 of file SBMLImporter.cpp.

References CCopasiObject::getCN(), CMetab::getInitialConcentrationReference(), and CModelEntity::getInitialValueReference().

Referenced by SBMLImporter::createCModelFromSBMLDocument().

213 {
214  std::map<CCopasiObject*, SBase*>::const_iterator it;
215 
216  for (it = copasi2sbmlmap.begin(); it != copasi2sbmlmap.end(); ++it)
217  {
218  if (it->second != sbase)
219  continue;
220 
221  CMetab *metab = dynamic_cast<CMetab*>(it->first);
222 
223  if (metab != NULL)
224  return metab->getInitialConcentrationReference()->getCN();
225 
226  CCompartment *comp = dynamic_cast<CCompartment*>(it->first);
227 
228  if (comp != NULL)
229  return comp->getInitialValueReference()->getCN();
230 
231  CModelValue *param = dynamic_cast<CModelValue*>(it->first);
232 
233  if (param != NULL)
234  return param->getInitialValueReference()->getCN();
235  }
236 
237  return "";
238 }
virtual CCopasiObjectName getCN() const
CCopasiObject * getInitialValueReference() const
Definition: CMetab.h:178
CConcentrationReference * getInitialConcentrationReference() const
Definition: CMetab.cpp:861
std::string getOriginalSBMLId ( Parameter *  parameter)

Definition at line 189 of file SBMLImporter.cpp.

Referenced by SBMLImporter::createCModelFromSBMLDocument().

190 {
191  if (parameter == NULL) return "";
192 
193  if (!parameter->isSetAnnotation()) return "";
194 
195  XMLNode* node = parameter->getAnnotation();
196 
197  if (node->getNumChildren() < 1) return "";
198 
199  for (unsigned int i = 0; i < node->getNumChildren(); ++i)
200  {
201  const XMLNode& current = node->getChild(i);
202 
203  if (current.getNamespaces().containsUri("http://copasi.org/initialValue"))
204  {
205  return current.getAttrValue("parent");
206  }
207  }
208 
209  return "";
210 }
std::string isKnownCustomFunctionDefinition ( const FunctionDefinition *  sbmlFunction,
const std::string &  sNamespace,
const std::string &  elementName,
const std::string &  definition 
)

Definition at line 1560 of file SBMLImporter.cpp.

Referenced by addToKnownFunctionToMap().

1564 {
1565  FunctionDefinition* current = const_cast<FunctionDefinition*>(sbmlFunction);
1566 
1567  if (current == NULL) return "";
1568 
1569  if (!current->isSetAnnotation()) return "";
1570 
1571  const XMLNode* element = current->getAnnotation();
1572 
1573  if (element == NULL) return "";
1574 
1575  for (unsigned int i = 0 ; i < element->getNumChildren(); ++i)
1576  {
1577  const XMLNode& annot = element->getChild(i);
1578 
1579  if (annot.getURI() == sNamespace &&
1580  annot.getName() == elementName &&
1581  annot.getAttrValue("definition") == definition)
1582  {
1583  return current->getId();
1584  }
1585  }
1586 
1587  return "";
1588 }