COPASI API  4.16.103
Classes | Public Member Functions | Protected Attributes | List of all members
CModelExpansion Class Reference

#include <CModelExpansion.h>

Collaboration diagram for CModelExpansion:
Collaboration graph
[legend]

Classes

class  ElementsMap
 
class  SetOfModelElements
 

Public Member Functions

 CModelExpansion (CModel *pModel)
 
std::set< CCopasiObject * > copyCompleteModel (const CModel *pSourceModel)
 
void createDiffusionReaction (const std::string &name, const std::string &metabkey1, const std::string &metabkey2, const std::string &parameterkey)
 
void createLinearArray (const SetOfModelElements &source, size_t n, const std::set< std::string > &setOfMetabolites)
 
void createRectangularArray (const SetOfModelElements &source, size_t nx, size_t ny, const std::set< std::string > &setOfMetabolites)
 
bool duplicate (const SetOfModelElements &source, const std::string &index, ElementsMap &emap)
 
void duplicateCompartment (const CCompartment *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
 
void duplicateEvent (CEvent *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
 
void duplicateGlobalQuantity (const CModelValue *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
 
void duplicateMetab (const CMetab *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
 
void duplicateReaction (const CReaction *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
 
bool existDependentEntities (const CCopasiObject *pObj)
 
bool expressionContainsObject (const CExpression *exp, const SetOfModelElements &sourceSet)
 
void replaceInCompartment (CCompartment *pX, const ElementsMap &emap)
 
void replaceInEvent (CEvent *pX, const ElementsMap &emap)
 
void replaceInExpression (CExpression *exp, const ElementsMap &emap)
 
void replaceInMetab (CMetab *pX, const ElementsMap &emap)
 
void replaceInModel (const ElementsMap &emap, bool remove)
 
void replaceInModelEntity (CModelEntity *pX, const ElementsMap &emap)
 
void replaceInReaction (CReaction *pX, const ElementsMap &emap)
 
void setModel (CModel *pModel)
 
void simpleCall (const CCompartment *source, std::vector< std::string > listOfMetabolites, int mult, bool diff)
 
void updateExpression (CExpression *exp, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
 

Protected Attributes

CModelmpModel
 
const CModelmpSourceModel
 

Detailed Description

Definition at line 41 of file CModelExpansion.h.

Constructor & Destructor Documentation

CModelExpansion::CModelExpansion ( CModel pModel)

Definition at line 262 of file CModelExpansion.cpp.

263  : mpModel(pModel),
264  mpSourceModel(NULL)
265 {
266 }
const CModel * mpSourceModel

Member Function Documentation

std::set< CCopasiObject * > CModelExpansion::copyCompleteModel ( const CModel pSourceModel)

adds the contents of the source model to the current model. A list of created model elements is returned

Definition at line 478 of file CModelExpansion.cpp.

References CModel::compileIfNecessary(), duplicate(), CModelExpansion::SetOfModelElements::fillComplete(), CModelExpansion::ElementsMap::getMap(), mpModel, and mpSourceModel.

479 {
480  mpSourceModel = pSourceModel;
481 
482  SetOfModelElements sourceElements;
483  sourceElements.fillComplete(pSourceModel);
484  ElementsMap map;
485  duplicate(sourceElements, "[merge]", map);
487 
488  std::set<CCopasiObject*> ret;
489  std::map<const CCopasiObject*, CCopasiObject*>::const_iterator it;
490 
491  for (it = map.getMap().begin(); it != map.getMap().end(); ++it)
492  {
493  ret.insert(it->second);
494  //std::cout << it->second->getObjectDisplayName() << std::endl;
495  }
496 
497  return ret;
498 }
bool duplicate(const SetOfModelElements &source, const std::string &index, ElementsMap &emap)
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
const CModel * mpSourceModel
void CModelExpansion::createDiffusionReaction ( const std::string &  name,
const std::string &  metabkey1,
const std::string &  metabkey2,
const std::string &  parameterkey 
)

Create a first order reversible mass action reaction. This is intended for diffusion between copies of model parts. The method takes a reaction name, and keys of two metabolites and a global quantity that is used as a rate constant.

Definition at line 1066 of file CModelExpansion.cpp.

References CReaction::addParameterMapping(), CReaction::addProduct(), CReaction::addSubstrate(), CModel::createReaction(), mpModel, CReaction::setFunction(), CReaction::setParameterMapping(), and CReaction::setReversible().

Referenced by createLinearArray(), createRectangularArray(), and simpleCall().

1069 {
1070  //try creating the object until we find a name that is not yet used
1071  CReaction* newObj;
1072  std::ostringstream name_;
1073  name_ << name;
1074 
1075  do
1076  {
1077  newObj = mpModel->createReaction(name_.str());
1078  name_ << "_";
1079  }
1080  while (!newObj);
1081 
1082  newObj->setReversible(true);
1083  newObj->addSubstrate(metabkey1, 1);
1084  newObj->addProduct(metabkey2, 1);
1085  newObj->setFunction("Mass action (reversible)");
1086  newObj->addParameterMapping("substrate", metabkey1);
1087  newObj->addParameterMapping("product", metabkey2);
1088  newObj->setParameterMapping(0, parameterkey);
1089  newObj->setParameterMapping(2, parameterkey);
1090 }
void setReversible(bool reversible)
Definition: CReaction.cpp:247
bool addSubstrate(const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
Definition: CReaction.cpp:232
bool addProduct(const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
Definition: CReaction.cpp:236
bool setFunction(const std::string &functionName)
Definition: CReaction.cpp:255
CReaction * createReaction(const std::string &name)
Definition: CModel.cpp:2760
void setParameterMapping(const size_t &index, const std::string &key)
Definition: CReaction.cpp:339
void addParameterMapping(const size_t &index, const std::string &key)
Definition: CReaction.cpp:348
void CModelExpansion::createLinearArray ( const SetOfModelElements source,
size_t  n,
const std::set< std::string > &  setOfMetabolites 
)

creates n copies of the objects in souce. Diffusion reactions are created for each of the metabs in listOfMetabolites, so that a linear chain is formed.

Definition at line 336 of file CModelExpansion.cpp.

References CModel::compileIfNecessary(), createDiffusionReaction(), CModel::createModelValue(), duplicate(), CKeyFactory::get(), CMetab::getCompartment(), CCopasiRootContainer::getKeyFactory(), CCopasiObject::getObjectName(), and mpModel.

Referenced by CQExpandModelData::slotOK().

337 {
338  if (!mpModel) return;
339 
340  //create global quantities for the diffusion constants
341  std::vector<CModelValue*> diffusionConstants;
342  std::set<std::string>::const_iterator itMetab;
343 
344  for (itMetab = setOfMetabolites.begin(); itMetab != setOfMetabolites.end(); ++itMetab)
345  {
346  //try creating the object until we find a name that is not yet used
347  CModelValue* newObj;
348  const CMetab* pMetab = dynamic_cast<const CMetab*>(CCopasiRootContainer::getKeyFactory()->get(*itMetab));
349 
350  if (!pMetab)
351  continue;
352 
353  std::string name = "diff_" + pMetab->getCompartment()->getObjectName() + "_" + pMetab->getObjectName();
354 
355  do
356  {
357  newObj = mpModel->createModelValue(name, 1.0);
358  name += "_";
359  }
360  while (!newObj);
361 
362  diffusionConstants.push_back(newObj);
363  }
364 
365  //now create the copies
366  size_t i;
367  std::vector<ElementsMap> maps;
368  maps.resize(n);
369 
370  for (i = 0; i < n; ++i)
371  {
372  std::ostringstream indexstr;
373  indexstr << "[" << i << "]";
374  duplicate(source, indexstr.str(), maps[i]);
375 
376  //Diffusion
377  if (i)
378  {
379  std::vector<CModelValue*>::const_iterator itDiff;
380 
381  for (itMetab = setOfMetabolites.begin(), itDiff = diffusionConstants.begin();
382  itMetab != setOfMetabolites.end();
383  ++itMetab, ++itDiff)
384  {
385  std::ostringstream diffname;
386  diffname << (*itDiff)->getObjectName() << "[" << i - 1 << "-" << i << "]";
387  createDiffusionReaction(diffname.str(),
388  maps[i - 1].getDuplicateKey(*itMetab),
389  maps[i].getDuplicateKey(*itMetab), (*itDiff)->getKey());
390  }
391  }
392  }
393 
395 }
const std::string & getObjectName() const
CCopasiObject * get(const std::string &key)
CModelValue * createModelValue(const std::string &name, const C_FLOAT64 &value=0.0)
Definition: CModel.cpp:2838
Definition: CMetab.h:178
bool duplicate(const SetOfModelElements &source, const std::string &index, ElementsMap &emap)
void createDiffusionReaction(const std::string &name, const std::string &metabkey1, const std::string &metabkey2, const std::string &parameterkey)
static CKeyFactory * getKeyFactory()
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
void CModelExpansion::createRectangularArray ( const SetOfModelElements source,
size_t  nx,
size_t  ny,
const std::set< std::string > &  setOfMetabolites 
)

creates nx*ny copies of the objects in souce. Diffusion reactions are created for each of the metabs in listOfMetabolites, so that a rectangular array is formed.

Definition at line 397 of file CModelExpansion.cpp.

References CModel::compileIfNecessary(), createDiffusionReaction(), CModel::createModelValue(), duplicate(), CKeyFactory::get(), CMetab::getCompartment(), CCopasiRootContainer::getKeyFactory(), CCopasiObject::getObjectName(), and mpModel.

Referenced by CQExpandModelData::slotOK().

398 {
399  if (!mpModel) return;
400 
401  //create global quantities for the diffusion constants
402  std::vector<CModelValue*> diffusionConstants;
403  std::set<std::string>::const_iterator itMetab;
404 
405  for (itMetab = setOfMetabolites.begin(); itMetab != setOfMetabolites.end(); ++itMetab)
406  {
407  //try creating the object until we find a name that is not yet used
408  CModelValue* newObj;
409  const CMetab* pMetab = dynamic_cast<const CMetab*>(CCopasiRootContainer::getKeyFactory()->get(*itMetab));
410 
411  if (!pMetab)
412  continue;
413 
414  std::string name = "diff_" + pMetab->getCompartment()->getObjectName() + "_" + pMetab->getObjectName();
415 
416  do
417  {
418  newObj = mpModel->createModelValue(name, 1.0);
419  name += "_";
420  }
421  while (!newObj);
422 
423  diffusionConstants.push_back(newObj);
424  }
425 
426  //now create the copies
427  size_t i, j;
428  std::vector<std::vector<ElementsMap> > maps;
429  maps.resize(nx);
430 
431  for (i = 0; i < nx; ++i)
432  maps[i].resize(ny);
433 
434  for (i = 0; i < nx; ++i)
435  for (j = 0; j < ny; ++j)
436  {
437  std::ostringstream indexstr;
438  indexstr << "[" << i << "," << j << "]";
439  duplicate(source, indexstr.str(), maps[i][j]);
440 
441  //Diffusion
442  if (i)
443  {
444  std::vector<CModelValue*>::const_iterator itDiff;
445 
446  for (itMetab = setOfMetabolites.begin(), itDiff = diffusionConstants.begin();
447  itMetab != setOfMetabolites.end();
448  ++itMetab, ++itDiff)
449  {
450  std::ostringstream diffname;
451  diffname << (*itDiff)->getObjectName() << "[" << i - 1 << "-" << i << "," << j << "]";
452  createDiffusionReaction(diffname.str(),
453  maps[i - 1][j].getDuplicateKey(*itMetab),
454  maps[i][j].getDuplicateKey(*itMetab), (*itDiff)->getKey());
455  }
456  }
457 
458  if (j)
459  {
460  std::vector<CModelValue*>::const_iterator itDiff;
461 
462  for (itMetab = setOfMetabolites.begin(), itDiff = diffusionConstants.begin();
463  itMetab != setOfMetabolites.end();
464  ++itMetab, ++itDiff)
465  {
466  std::ostringstream diffname;
467  diffname << (*itDiff)->getObjectName() << "[" << i << "," << j - 1 << "-" << j << "]";
468  createDiffusionReaction(diffname.str(),
469  maps[i][j - 1].getDuplicateKey(*itMetab),
470  maps[i][j].getDuplicateKey(*itMetab), (*itDiff)->getKey());
471  }
472  }
473  }
474 
476 }
const std::string & getObjectName() const
CCopasiObject * get(const std::string &key)
CModelValue * createModelValue(const std::string &name, const C_FLOAT64 &value=0.0)
Definition: CModel.cpp:2838
Definition: CMetab.h:178
bool duplicate(const SetOfModelElements &source, const std::string &index, ElementsMap &emap)
void createDiffusionReaction(const std::string &name, const std::string &metabkey1, const std::string &metabkey2, const std::string &parameterkey)
static CKeyFactory * getKeyFactory()
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
bool CModelExpansion::duplicate ( const SetOfModelElements source,
const std::string &  index,
ElementsMap emap 
)

creates one duplicate of the set of elements specified by source. the string index is added to the object names

Definition at line 500 of file CModelExpansion.cpp.

References duplicateCompartment(), duplicateEvent(), duplicateGlobalQuantity(), duplicateMetab(), duplicateReaction(), CModelExpansion::SetOfModelElements::mCompartments, CModelExpansion::SetOfModelElements::mEvents, CModelExpansion::SetOfModelElements::mGlobalQuantities, CModelExpansion::SetOfModelElements::mMetabs, and CModelExpansion::SetOfModelElements::mReactions.

Referenced by CQCompartment::copy(), copyCompleteModel(), createLinearArray(), createRectangularArray(), replaceInExpression(), simpleCall(), and updateExpression().

501 {
502  std::set<const CCompartment*>::const_iterator itComp;
503 
504  for (itComp = source.mCompartments.begin(); itComp != source.mCompartments.end(); ++itComp)
505  {
506  duplicateCompartment(*itComp, index, source, emap);
507  }
508 
509  std::set<const CMetab*>::const_iterator itMetab;
510 
511  for (itMetab = source.mMetabs.begin(); itMetab != source.mMetabs.end(); ++itMetab)
512  {
513  duplicateMetab(*itMetab, index, source, emap);
514  }
515 
516  std::set<const CReaction*>::const_iterator itReac;
517 
518  for (itReac = source.mReactions.begin(); itReac != source.mReactions.end(); ++itReac)
519  {
520  duplicateReaction(*itReac, index, source, emap);
521  }
522 
523  std::set<const CModelValue*>::const_iterator itME;
524 
525  for (itME = source.mGlobalQuantities.begin(); itME != source.mGlobalQuantities.end(); ++itME)
526  {
527  duplicateGlobalQuantity(*itME, index, source, emap);
528  }
529 
530  std::set<const CEvent*>::const_iterator itEvent;
531 
532  for (itEvent = source.mEvents.begin(); itEvent != source.mEvents.end(); ++itEvent)
533  {
534  duplicateEvent(const_cast<CEvent*>(*itEvent), index, source, emap);
535  //the event can be changed. Potentially it is not duplicated in its entirety but only some event assignments are duplicated.
536  }
537 
538  // compilation failed on Win32, need return value for boolean
539  return false;
540 }
void duplicateMetab(const CMetab *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
void duplicateEvent(CEvent *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
void duplicateReaction(const CReaction *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
void duplicateGlobalQuantity(const CModelValue *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
void duplicateCompartment(const CCompartment *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
void CModelExpansion::duplicateCompartment ( const CCompartment source,
const std::string &  index,
const SetOfModelElements sourceSet,
ElementsMap emap 
)

Definition at line 542 of file CModelExpansion.cpp.

References CModelExpansion::ElementsMap::add(), CModel::createCompartment(), CModelExpansion::ElementsMap::exists(), CCompartment::getDimensionality(), CModelEntity::getExpression(), CModelEntity::getExpressionPtr(), CModelEntity::getInitialExpression(), CModelEntity::getInitialExpressionPtr(), CModelEntity::getInitialValue(), CModelEntity::getKey(), CAnnotation::getMiriamAnnotation(), CAnnotation::getNotes(), CCopasiObject::getObjectName(), CModelEntity::getStatus(), mpModel, CCompartment::setDimensionality(), CModelEntity::setExpression(), CModelEntity::setInitialExpression(), CAnnotation::setMiriamAnnotation(), CAnnotation::setNotes(), CModelEntity::setStatus(), and updateExpression().

Referenced by duplicate(), duplicateMetab(), duplicateReaction(), and updateExpression().

543 {
544  //if the source object has already been duplicated: do nothing
545  if (emap.exists(source))
546  return;
547 
548  //try creating the object until we find a name that is not yet used
549  CCompartment* newObj;
550  std::ostringstream infix;
551 
552  do
553  {
554  std::ostringstream name;
555  name << source->getObjectName() << infix.str() << index;
556  newObj = mpModel->createCompartment(name.str(), source->getInitialValue());
557  infix << "_";
558  }
559  while (!newObj);
560 
561  //add duplicated object to the map
562  emap.add(source, newObj);
563 
564  //now copy the contents of the object
565  newObj->setDimensionality(source->getDimensionality());
566 
567  //status
568  newObj->setStatus(source->getStatus());
569 
570  //expression (for assignment or ODE)
571  newObj->setExpression(source->getExpression());
572  updateExpression(newObj->getExpressionPtr(), index, sourceSet, emap);
573 
574  //initial expression
575  newObj->setInitialExpression(source->getInitialExpression());
576  updateExpression(newObj->getInitialExpressionPtr(), index, sourceSet, emap);
577 
578  newObj->setNotes(source->getNotes());
579  newObj->setMiriamAnnotation(source->getMiriamAnnotation(), newObj->getKey(), source->getKey());
580 }
const CExpression * getExpressionPtr() const
const std::string & getObjectName() const
bool setDimensionality(unsigned C_INT32 dim)
unsigned C_INT32 getDimensionality() const
void setNotes(const std::string &notes)
bool setInitialExpression(const std::string &expression)
std::string getExpression() const
void setMiriamAnnotation(const std::string &miriamAnnotation, const std::string &newId, const std::string &oldId)
const std::string & getMiriamAnnotation() const
const C_FLOAT64 & getInitialValue() const
const std::string & getNotes() const
virtual const std::string & getKey() const
virtual void setStatus(const CModelEntity::Status &status)
std::string getInitialExpression() const
virtual bool add(CCopasiObject *pObject, const bool &adopt=true)
const CModelEntity::Status & getStatus() const
bool setExpression(const std::string &expression)
void updateExpression(CExpression *exp, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
const CExpression * getInitialExpressionPtr() const
CCompartment * createCompartment(const std::string &name, const C_FLOAT64 &volume=1.0)
Definition: CModel.cpp:2698
void CModelExpansion::duplicateEvent ( CEvent source,
const std::string &  index,
const SetOfModelElements sourceSet,
ElementsMap emap 
)

Definition at line 869 of file CModelExpansion.cpp.

References CModelExpansion::ElementsMap::add(), CCopasiVectorN< CType >::add(), CExpression::compile(), CModelExpansion::SetOfModelElements::contains(), CModel::createEvent(), CModelExpansion::ElementsMap::exists(), expressionContainsObject(), CEvent::getAssignments(), CEvent::getDelayAssignment(), CEvent::getDelayExpression(), CEvent::getDelayExpressionPtr(), CModelExpansion::ElementsMap::getDuplicateKey(), CEventAssignment::getExpression(), CEventAssignment::getExpressionPtr(), CEvent::getKey(), CAnnotation::getMiriamAnnotation(), CAnnotation::getNotes(), CCopasiObject::getObjectName(), CEventAssignment::getTargetKey(), CEvent::getTriggerExpression(), CEvent::getTriggerExpressionPtr(), mpModel, CEvent::setDelayAssignment(), CEvent::setDelayExpression(), CEventAssignment::setExpression(), CAnnotation::setMiriamAnnotation(), CAnnotation::setNotes(), CEvent::setTriggerExpression(), CCopasiVector< T >::size(), and updateExpression().

Referenced by duplicate().

870 {
871  //if the source object has already been duplicated: do nothing
872  if (emap.exists(source))
873  return;
874 
875  CEvent* newObj = NULL;
876 
877  if (expressionContainsObject(source->getTriggerExpressionPtr(), sourceSet)
878  || expressionContainsObject(source->getDelayExpressionPtr(), sourceSet))
879  {
880  //we need to duplicate the event itself (because the trigger refers to a duplicated object)
881 
882  //try creating the object until we find a name that is not yet used
883  std::ostringstream infix;
884 
885  do
886  {
887  std::ostringstream name;
888  name << source->getObjectName() << infix.str() << index;
889  newObj = mpModel->createEvent(name.str());
890  infix << "_";
891  }
892  while (!newObj);
893 
894  //add duplicated object to the map
895  emap.add(source, newObj);
896 
897  //now do the trigger
898  newObj->setTriggerExpression(source->getTriggerExpression());
899  newObj->getTriggerExpressionPtr()->compile(); //I don't know why this is necessary
900  updateExpression(newObj->getTriggerExpressionPtr(), index, sourceSet, emap);
901 
902  //delay
903  newObj->setDelayExpression(source->getDelayExpression());
904  newObj->getDelayExpressionPtr()->compile(); //I don't know why this is necessary
905  updateExpression(newObj->getDelayExpressionPtr(), index, sourceSet, emap);
906 
907  newObj->setDelayAssignment(source->getDelayAssignment());
908  }
909  else
910  {
911  newObj = source; //no copying necessary
912 
913  //add duplicated object to the map
914  emap.add(source, newObj);
915  }
916 
917  //now the event assignments...
918  size_t i;
919 
920  for (i = 0; i < source->getAssignments().size(); ++i)
921  {
922  const CEventAssignment* pSourceAssignment = source->getAssignments()[i];
923 
924  //const CModelEntity * pSourceTarget = dynamic_cast<const CModelEntity * >(CCopasiRootContainer::getKeyFactory()->get(pSourceAssignment->getTargetKey()));
925  if (sourceSet.contains(pSourceAssignment->getTargetKey()))
926  {
927  //we assume that the duplicate of the target object already exists.
928  //this should be true since events are duplicated last.
929  if (!emap.exists(pSourceAssignment->getTargetKey()))
930  continue;
931 
932  //create duplicate of assignment (this can be either in the original event or in the
933  //duplicate of an event)
934  CEventAssignment * pNewAssignment = new CEventAssignment(emap.getDuplicateKey(pSourceAssignment->getTargetKey()));
935  newObj->getAssignments().add(pNewAssignment, true);
936 
937  //we do an assumption:
938  //It should not happen that the assignment expression contains a reference to an object that is duplicated,
939  //but the assignment target is not duplicated.
940 
941  //now copy the expression
942  pNewAssignment->setExpression(pSourceAssignment->getExpression());
943  pNewAssignment->getExpressionPtr()->compile();
944  updateExpression(pNewAssignment->getExpressionPtr(), index, sourceSet, emap);
945  }
946  }
947 
948  newObj->setNotes(source->getNotes());
949  newObj->setMiriamAnnotation(source->getMiriamAnnotation(), newObj->getKey(), source->getKey());
950 }
Definition: CEvent.h:152
const CCopasiVectorN< CEventAssignment > & getAssignments() const
Definition: CEvent.cpp:678
const bool & getDelayAssignment() const
Definition: CEvent.cpp:419
CEvent * createEvent(const std::string &name)
Definition: CModel.cpp:2928
const std::string & getObjectName() const
virtual size_t size() const
const std::string & getTargetKey() const
Definition: CEvent.cpp:162
void setNotes(const std::string &notes)
const CExpression * getExpressionPtr() const
Definition: CEvent.cpp:226
bool setExpression(const std::string &expression)
Definition: CEvent.cpp:167
std::string getTriggerExpression() const
Definition: CEvent.cpp:524
virtual bool compile(std::vector< CCopasiContainer * > listOfContainer=CCopasiContainer::EmptyList)
Definition: CExpression.cpp:97
void setMiriamAnnotation(const std::string &miriamAnnotation, const std::string &newId, const std::string &oldId)
bool expressionContainsObject(const CExpression *exp, const SetOfModelElements &sourceSet)
const std::string & getMiriamAnnotation() const
CExpression * getDelayExpressionPtr()
Definition: CEvent.cpp:606
virtual bool add(const CType &src)
const std::string & getNotes() const
bool setTriggerExpression(const std::string &expression)
Definition: CEvent.cpp:474
void setDelayAssignment(const bool &delayCalculation)
Definition: CEvent.cpp:408
std::string getDelayExpression() const
Definition: CEvent.cpp:591
const CExpression * getTriggerExpressionPtr() const
Definition: CEvent.cpp:534
bool setDelayExpression(const std::string &expression)
Definition: CEvent.cpp:544
virtual bool add(CCopasiObject *pObject, const bool &adopt=true)
void updateExpression(CExpression *exp, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
virtual const std::string & getKey() const
Definition: CEvent.cpp:287
std::string getExpression() const
Definition: CEvent.cpp:216
void CModelExpansion::duplicateGlobalQuantity ( const CModelValue source,
const std::string &  index,
const SetOfModelElements sourceSet,
ElementsMap emap 
)

Definition at line 832 of file CModelExpansion.cpp.

References CModelExpansion::ElementsMap::add(), CModel::createModelValue(), CModelExpansion::ElementsMap::exists(), CModelEntity::getExpression(), CModelEntity::getExpressionPtr(), CModelEntity::getInitialExpression(), CModelEntity::getInitialExpressionPtr(), CModelEntity::getInitialValue(), CModelEntity::getKey(), CAnnotation::getMiriamAnnotation(), CAnnotation::getNotes(), CCopasiObject::getObjectName(), CModelEntity::getStatus(), mpModel, CModelEntity::setExpression(), CModelEntity::setInitialExpression(), CAnnotation::setMiriamAnnotation(), CAnnotation::setNotes(), CModelEntity::setStatus(), and updateExpression().

Referenced by duplicate(), duplicateReaction(), and updateExpression().

833 {
834  //if the source object has already been duplicated: do nothing
835  if (emap.exists(source))
836  return;
837 
838  //try creating the object until we find a name that is not yet used
839  CModelEntity* newObj;
840  std::ostringstream infix;
841 
842  do
843  {
844  std::ostringstream name;
845  name << source->getObjectName() << infix.str() << index;
846  newObj = mpModel->createModelValue(name.str(), source->getInitialValue());
847  infix << "_";
848  }
849  while (!newObj);
850 
851  //add duplicated object to the map
852  emap.add(source, newObj);
853 
854  //status
855  newObj->setStatus(source->getStatus());
856 
857  //expression (for assignment or ODE)
858  newObj->setExpression(source->getExpression());
859  updateExpression(newObj->getExpressionPtr(), index, sourceSet, emap);
860 
861  //initial expression
862  newObj->setInitialExpression(source->getInitialExpression());
863  updateExpression(newObj->getInitialExpressionPtr(), index, sourceSet, emap);
864 
865  newObj->setNotes(source->getNotes());
866  newObj->setMiriamAnnotation(source->getMiriamAnnotation(), newObj->getKey(), source->getKey());
867 }
const CExpression * getExpressionPtr() const
const std::string & getObjectName() const
void setNotes(const std::string &notes)
bool setInitialExpression(const std::string &expression)
std::string getExpression() const
CModelValue * createModelValue(const std::string &name, const C_FLOAT64 &value=0.0)
Definition: CModel.cpp:2838
void setMiriamAnnotation(const std::string &miriamAnnotation, const std::string &newId, const std::string &oldId)
const std::string & getMiriamAnnotation() const
const C_FLOAT64 & getInitialValue() const
const std::string & getNotes() const
virtual const std::string & getKey() const
virtual void setStatus(const CModelEntity::Status &status)
std::string getInitialExpression() const
virtual bool add(CCopasiObject *pObject, const bool &adopt=true)
const CModelEntity::Status & getStatus() const
bool setExpression(const std::string &expression)
void updateExpression(CExpression *exp, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
const CExpression * getInitialExpressionPtr() const
void CModelExpansion::duplicateMetab ( const CMetab source,
const std::string &  index,
const SetOfModelElements sourceSet,
ElementsMap emap 
)

Definition at line 582 of file CModelExpansion.cpp.

References CModelExpansion::ElementsMap::add(), CModelExpansion::SetOfModelElements::contains(), CModel::createMetabolite(), duplicateCompartment(), CModelExpansion::ElementsMap::exists(), CMetab::getCompartment(), CModelExpansion::ElementsMap::getDuplicatePtr(), CModelEntity::getExpression(), CModelEntity::getExpressionPtr(), CMetab::getInitialConcentration(), CModelEntity::getInitialExpression(), CModelEntity::getInitialExpressionPtr(), CModelEntity::getKey(), CAnnotation::getMiriamAnnotation(), CAnnotation::getNotes(), CCopasiObject::getObjectName(), CModelEntity::getStatus(), mpModel, CModelEntity::setExpression(), CModelEntity::setInitialExpression(), CAnnotation::setMiriamAnnotation(), CAnnotation::setNotes(), and updateExpression().

Referenced by CQSpeciesDetail::copy(), ReactionsWidget1::copy(), duplicate(), duplicateReaction(), and updateExpression().

583 {
584  //if the source object has already been duplicated: do nothing
585  if (emap.exists(source))
586  return;
587 
588  //is the containing compartment also duplicated?
589  const CCompartment* sourceParent = source->getCompartment();
590  const CCompartment * parent = NULL;
591  bool nameflag;
592 
593  if (!sourceSet.contains(sourceParent))
594  {
595  parent = sourceParent; //use the original parent compartment
596  nameflag = true; //metab needs renaming
597  }
598  else //use a copy of the parent compartment
599  {
600  nameflag = false; //no renaming necessary (since the copy is in a different compartment)
601 
602  //create copy if it does not exist
603  if (!emap.exists(sourceParent))
604  {
605  duplicateCompartment(sourceParent, index, sourceSet, emap);
606  }
607 
608  parent = dynamic_cast<CCompartment *>(emap.getDuplicatePtr(sourceParent));
609  }
610 
611  //try creating the object until we find a name that is not yet used
612  CMetab* newObj;
613  std::ostringstream infix;
614 
615  do
616  {
617  std::ostringstream name;
618  name << source->getObjectName() << infix.str();
619 
620  if (nameflag)
621  name << index;
622 
623  newObj = mpModel->createMetabolite(name.str(), parent->getObjectName(), source->getInitialConcentration(), source->getStatus());
624 
625  infix << "_";
626  }
627  while (!newObj);
628 
629  //add duplicated object to the map
630  emap.add(source, newObj);
631 
632  //expression (for assignment or ODE)
633  newObj->setExpression(source->getExpression());
634  updateExpression(newObj->getExpressionPtr(), index, sourceSet, emap);
635 
636  //initial expression
637  newObj->setInitialExpression(source->getInitialExpression());
638  updateExpression(newObj->getInitialExpressionPtr(), index, sourceSet, emap);
639 
640  newObj->setNotes(source->getNotes());
641  newObj->setMiriamAnnotation(source->getMiriamAnnotation(), newObj->getKey(), source->getKey());
642 }
const CExpression * getExpressionPtr() const
const std::string & getObjectName() const
const C_FLOAT64 & getInitialConcentration() const
Definition: CMetab.cpp:220
void setNotes(const std::string &notes)
bool setInitialExpression(const std::string &expression)
std::string getExpression() const
void setMiriamAnnotation(const std::string &miriamAnnotation, const std::string &newId, const std::string &oldId)
Definition: CMetab.h:178
const std::string & getMiriamAnnotation() const
const std::string & getNotes() const
virtual const std::string & getKey() const
std::string getInitialExpression() const
virtual bool add(CCopasiObject *pObject, const bool &adopt=true)
void duplicateCompartment(const CCompartment *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
const CModelEntity::Status & getStatus() const
bool setExpression(const std::string &expression)
void updateExpression(CExpression *exp, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
const CExpression * getInitialExpressionPtr() const
CMetab * createMetabolite(const std::string &name, const std::string &compartment, const C_FLOAT64 &iconc=1.0, const CModelEntity::Status &status=CModelEntity::REACTIONS)
Definition: CModel.cpp:2622
void CModelExpansion::duplicateReaction ( const CReaction source,
const std::string &  index,
const SetOfModelElements sourceSet,
ElementsMap emap 
)

Definition at line 644 of file CModelExpansion.cpp.

References CModelExpansion::ElementsMap::add(), CReaction::addModifier(), CReaction::addParameterMapping(), CReaction::addProduct(), CReaction::addSubstrate(), CReaction::clearParameterMapping(), CModelExpansion::SetOfModelElements::contains(), CModel::createReaction(), duplicateCompartment(), duplicateGlobalQuantity(), duplicateMetab(), CModelExpansion::ElementsMap::exists(), CKeyFactory::get(), CReaction::getChemEq(), CModelExpansion::ElementsMap::getDuplicateKey(), CModelExpansion::ElementsMap::getDuplicatePtr(), CReaction::getFunction(), CReaction::getFunctionParameters(), CModelEntity::getKey(), CReaction::getKey(), CCopasiRootContainer::getKeyFactory(), CChemEqElement::getMetabolite(), CAnnotation::getMiriamAnnotation(), CChemEq::getModifiers(), CChemEqElement::getMultiplicity(), CAnnotation::getNotes(), CCopasiObject::getObjectName(), CReaction::getParameterMappings(), CReaction::getParameterValue(), CChemEq::getProducts(), CChemEq::getSubstrates(), CReaction::isLocalParameter(), CReaction::isReversible(), CFunctionParameter::MODIFIER, mpModel, CFunctionParameter::PARAMETER, CFunctionParameter::PRODUCT, CReaction::setFunction(), CAnnotation::setMiriamAnnotation(), CAnnotation::setNotes(), CReaction::setParameterMapping(), CReaction::setParameterValue(), CReaction::setReversible(), CFunctionParameters::size(), CCopasiVector< T >::size(), CFunctionParameter::SUBSTRATE, CFunctionParameter::TIME, CFunctionParameter::VFLOAT64, and CFunctionParameter::VOLUME.

Referenced by ReactionsWidget1::copy(), duplicate(), and updateExpression().

645 {
646  //if the source object has already been duplicated: do nothing
647  if (emap.exists(source))
648  return;
649 
650  //try creating the object until we find a name that is not yet used
651  CReaction* newObj;
652  std::ostringstream infix;
653 
654  do
655  {
656  std::ostringstream name;
657  name << source->getObjectName() << infix.str() << index;
658  newObj = mpModel->createReaction(name.str());
659  infix << "_";
660  }
661  while (!newObj);
662 
663  //add duplicated object to the map
664  emap.add(source, newObj);
665 
666  //now copy the chemical equation
667  size_t i;
668 
669  for (i = 0; i < source->getChemEq().getSubstrates().size(); ++i)
670  {
671  const CChemEqElement * sourceElement = source->getChemEq().getSubstrates()[i];
672  const CMetab* pMetab = NULL;
673 
674  if (sourceSet.contains(sourceElement->getMetabolite()))
675  {
676  if (!emap.exists(sourceElement->getMetabolite()))
677  duplicateMetab(sourceElement->getMetabolite(), index, sourceSet, emap);
678 
679  pMetab = dynamic_cast<const CMetab*>(emap.getDuplicatePtr(sourceElement->getMetabolite()));
680  }
681  else //add the original metab
682  {
683  pMetab = sourceElement->getMetabolite();
684  }
685 
686  if (pMetab)
687  newObj->addSubstrate(pMetab->getKey(), sourceElement->getMultiplicity());
688  }
689 
690  for (i = 0; i < source->getChemEq().getProducts().size(); ++i)
691  {
692  const CChemEqElement * sourceElement = source->getChemEq().getProducts()[i];
693  const CMetab* pMetab = NULL;
694 
695  if (sourceSet.contains(sourceElement->getMetabolite()))
696  {
697  if (!emap.exists(sourceElement->getMetabolite()))
698  duplicateMetab(sourceElement->getMetabolite(), index, sourceSet, emap);
699 
700  pMetab = dynamic_cast<const CMetab*>(emap.getDuplicatePtr(sourceElement->getMetabolite()));
701  }
702  else //add the original metab
703  {
704  pMetab = sourceElement->getMetabolite();
705  }
706 
707  if (pMetab)
708  newObj->addProduct(pMetab->getKey(), sourceElement->getMultiplicity());
709  }
710 
711  for (i = 0; i < source->getChemEq().getModifiers().size(); ++i)
712  {
713  const CChemEqElement * sourceElement = source->getChemEq().getModifiers()[i];
714  const CMetab* pMetab = NULL;
715 
716  if (sourceSet.contains(sourceElement->getMetabolite()))
717  {
718  if (!emap.exists(sourceElement->getMetabolite()))
719  duplicateMetab(sourceElement->getMetabolite(), index, sourceSet, emap);
720 
721  pMetab = dynamic_cast<const CMetab*>(emap.getDuplicatePtr(sourceElement->getMetabolite()));
722  }
723  else //add the original metab
724  {
725  pMetab = sourceElement->getMetabolite();
726  }
727 
728  if (pMetab)
729  newObj->addModifier(pMetab->getKey());
730  }
731 
732  newObj->setReversible(source->isReversible());
733 
734  //set the kinetic function
735  newObj->setFunction(const_cast<CFunction*>(source->getFunction()));
736 
737  //mapping and local parameters
738  for (i = 0; i < newObj->getFunctionParameters().size(); ++i)
739  {
740  switch (newObj->getFunctionParameters()[i]->getUsage())
741  {
745  {
746  bool isVector = (newObj->getFunctionParameters()[i]->getType() == CFunctionParameter::VFLOAT64);
747 
748  if (isVector)
749  newObj->clearParameterMapping(i);
750 
751  size_t k;
752 
753  for (k = 0; k < source->getParameterMappings()[i].size(); ++k)
754  {
755  //we assume that by now the metab was copied if necessary.
756  //therefore we only need to check the map.
757  std::string targetKey;
758 
759  if (emap.exists(source->getParameterMappings()[i][k]))
760  targetKey = emap.getDuplicateKey(source->getParameterMappings()[i][k]);
761  else
762  targetKey = source->getParameterMappings()[i][k];
763 
764  if (isVector)
765  newObj->addParameterMapping(i, targetKey);
766  else
767  newObj->setParameterMapping(i, targetKey);
768  }
769  }
770  break;
771 
773  newObj->setParameterMapping(i, source->getParameterMappings()[i][0]);
774  break;
775 
777  if (sourceSet.contains(source->getParameterMappings()[i][0]))
778  {
779  if (!emap.exists(source->getParameterMappings()[i][0]))
780  {
781  const CCompartment* pSource = dynamic_cast<const CCompartment*>(
783  duplicateCompartment(pSource, index, sourceSet, emap);
784  }
785 
786  newObj->setParameterMapping(i, emap.getDuplicateKey(source->getParameterMappings()[i][0]));
787  }
788  else //add the original metab
789  {
790  newObj->setParameterMapping(i, source->getParameterMappings()[i][0]);
791  }
792 
793  break;
794 
796  if (newObj->isLocalParameter(i))
797  {
798  //just copy the value
799  newObj->setParameterValue(newObj->getFunctionParameters()[i]->getObjectName(),
800  source->getParameterValue(newObj->getFunctionParameters()[i]->getObjectName()));
801  }
802  else
803  {
804  if (sourceSet.contains(source->getParameterMappings()[i][0]))
805  {
806  if (!emap.exists(source->getParameterMappings()[i][0]))
807  {
808  const CModelValue* pSource = dynamic_cast<const CModelValue*>(
810  duplicateGlobalQuantity(pSource, index, sourceSet, emap);
811  }
812 
813  newObj->setParameterMapping(i, emap.getDuplicateKey(source->getParameterMappings()[i][0]));
814  }
815  else //add the original global quantity
816  {
817  newObj->setParameterMapping(i, source->getParameterMappings()[i][0]);
818  }
819  }
820 
821  break;
822 
823  default:
824  break;
825  }
826  }
827 
828  newObj->setNotes(source->getNotes());
829  newObj->setMiriamAnnotation(source->getMiriamAnnotation(), newObj->getKey(), source->getKey());
830 }
void setReversible(bool reversible)
Definition: CReaction.cpp:247
bool addSubstrate(const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
Definition: CReaction.cpp:232
const std::string & getObjectName() const
virtual size_t size() const
CCopasiObject * get(const std::string &key)
virtual const std::string & getKey() const
Definition: CReaction.cpp:190
void setParameterValue(const std::string &parameterName, const C_FLOAT64 &value, const bool &updateStatus=true)
Definition: CReaction.cpp:303
const CMetab * getMetabolite() const
void setNotes(const std::string &notes)
bool addProduct(const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
Definition: CReaction.cpp:236
bool isLocalParameter(const size_t &index) const
Definition: CReaction.cpp:449
void clearParameterMapping(const std::string &parameterName)
Definition: CReaction.cpp:407
void setMiriamAnnotation(const std::string &miriamAnnotation, const std::string &newId, const std::string &oldId)
void duplicateMetab(const CMetab *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
Definition: CMetab.h:178
const std::string & getMiriamAnnotation() const
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
const CFunction * getFunction() const
Definition: CReaction.cpp:252
const CFunctionParameters & getFunctionParameters() const
Definition: CReaction.cpp:576
bool addModifier(const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
Definition: CReaction.cpp:240
const std::string & getNotes() const
bool setFunction(const std::string &functionName)
Definition: CReaction.cpp:255
CReaction * createReaction(const std::string &name)
Definition: CModel.cpp:2760
const C_FLOAT64 & getMultiplicity() const
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
bool isReversible() const
Definition: CReaction.cpp:229
static CKeyFactory * getKeyFactory()
void duplicateGlobalQuantity(const CModelValue *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
const CCopasiVector< CChemEqElement > & getModifiers() const
Definition: CChemEq.cpp:66
void setParameterMapping(const size_t &index, const std::string &key)
Definition: CReaction.cpp:339
virtual bool add(CCopasiObject *pObject, const bool &adopt=true)
void duplicateCompartment(const CCompartment *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
const std::vector< std::vector< std::string > > & getParameterMappings() const
Definition: CReaction.h:285
const CChemEq & getChemEq() const
Definition: CReaction.cpp:223
const C_FLOAT64 & getParameterValue(const std::string &parameterName) const
Definition: CReaction.cpp:326
void addParameterMapping(const size_t &index, const std::string &key)
Definition: CReaction.cpp:348
bool CModelExpansion::existDependentEntities ( const CCopasiObject pObj)

Tests if there are model elements that refer to the given model entity

Definition at line 1339 of file CModelExpansion.cpp.

References CModelExpansion::SetOfModelElements::addObject(), CModelExpansion::SetOfModelElements::fillDependencies(), CModelExpansion::SetOfModelElements::mCompartments, CModelExpansion::SetOfModelElements::mEvents, CModelExpansion::SetOfModelElements::mGlobalQuantities, CModelExpansion::SetOfModelElements::mMetabs, mpModel, and CModelExpansion::SetOfModelElements::mReactions.

Referenced by CQMergingData::fillTree().

1340 {
1341  SetOfModelElements sme;
1342 
1343  if (!sme.addObject(pObj))
1344  return false;
1345 
1346  /*std::cout << sme.mCompartments.size() << " "
1347  << sme.mMetabs.size() << " "
1348  << sme.mReactions.size() << " "
1349  << sme.mGlobalQuantities.size() << " "
1350  << sme.mEvents.size() << " " << std::endl;*/
1351 
1352  size_t s1 = sme.mCompartments.size();
1353  size_t s2 = sme.mMetabs.size();
1354  size_t s3 = sme.mReactions.size();
1355  size_t s4 = sme.mGlobalQuantities.size();
1356  size_t s5 = sme.mEvents.size();
1357 
1358  sme.fillDependencies(mpModel);
1359 
1360  if (s1 < sme.mCompartments.size())
1361  return true;
1362 
1363  if (s2 < sme.mMetabs.size())
1364  return true;
1365 
1366  if (s3 < sme.mReactions.size())
1367  return true;
1368 
1369  if (s4 < sme.mGlobalQuantities.size())
1370  return true;
1371 
1372  if (s5 < sme.mEvents.size())
1373  return true;
1374 
1375  return false;
1376 }
bool CModelExpansion::expressionContainsObject ( const CExpression exp,
const SetOfModelElements sourceSet 
)

Check if a given expression contains any of the objects in the sourceSet

Definition at line 1034 of file CModelExpansion.cpp.

References CModelExpansion::SetOfModelElements::contains(), CEvaluationTree::getNodeList(), CEvaluationNodeObject::getObjectInterfacePtr(), and CCopasiObject::getObjectParent().

Referenced by duplicateEvent().

1035 {
1036  if (!exp)
1037  return false;
1038 
1039  //we loop through the complete expression
1040  std::vector< CEvaluationNode * >::const_iterator it = exp->getNodeList().begin();
1041  std::vector< CEvaluationNode * >::const_iterator end = exp->getNodeList().end();
1042 
1043  for (; it != end; ++it)
1044  {
1045  CEvaluationNodeObject * node = dynamic_cast<CEvaluationNodeObject*>(*it);
1046 
1047  if (!node)
1048  continue;
1049 
1050  //std::cout << node->getData() << std::endl;
1051  const CCopasiObject * pObj = dynamic_cast<const CCopasiObject*>(node->getObjectInterfacePtr());
1052 
1053  if (pObj)
1054  {
1055  pObj = pObj->getObjectParent();
1056  }
1057 
1058  //is the object one that should be copied?
1059  if (sourceSet.contains(pObj))
1060  return true;
1061  }
1062 
1063  return false;
1064 }
const CObjectInterface * getObjectInterfacePtr() const
const std::vector< CEvaluationNode * > & getNodeList() const
CCopasiContainer * getObjectParent() const
void CModelExpansion::replaceInCompartment ( CCompartment pX,
const ElementsMap emap 
)

Definition at line 1160 of file CModelExpansion.cpp.

References replaceInModelEntity().

Referenced by replaceInModel().

1161 {
1162  replaceInModelEntity(pX, emap);
1163 }
void replaceInModelEntity(CModelEntity *pX, const ElementsMap &emap)
void CModelExpansion::replaceInEvent ( CEvent pX,
const ElementsMap emap 
)

Definition at line 1275 of file CModelExpansion.cpp.

References CEvent::getAssignments(), CEvent::getDelayExpressionPtr(), CModelExpansion::ElementsMap::getDuplicateKey(), CEventAssignment::getExpressionPtr(), CEventAssignment::getTargetKey(), CEvent::getTriggerExpressionPtr(), replaceInExpression(), CEventAssignment::setTargetKey(), and CCopasiVector< T >::size().

Referenced by replaceInModel().

1276 {
1279 
1280  //now the event assignments...
1281  size_t i;
1282 
1283  for (i = 0; i < pX->getAssignments().size(); ++i)
1284  {
1285  CEventAssignment* pAssignment = pX->getAssignments()[i];
1286  replaceInExpression(pAssignment->getExpressionPtr(), emap);
1287 
1288  std::string replacekey = emap.getDuplicateKey(pAssignment->getTargetKey());
1289 
1290  if (replacekey != "")
1291  pAssignment->setTargetKey(replacekey);
1292  }
1293 }
void replaceInExpression(CExpression *exp, const ElementsMap &emap)
const CCopasiVectorN< CEventAssignment > & getAssignments() const
Definition: CEvent.cpp:678
virtual size_t size() const
const std::string & getTargetKey() const
Definition: CEvent.cpp:162
const CExpression * getExpressionPtr() const
Definition: CEvent.cpp:226
bool setTargetKey(const std::string &targetKey)
Definition: CEvent.cpp:151
CExpression * getDelayExpressionPtr()
Definition: CEvent.cpp:606
const CExpression * getTriggerExpressionPtr() const
Definition: CEvent.cpp:534
void CModelExpansion::replaceInExpression ( CExpression exp,
const ElementsMap emap 
)

Definition at line 1295 of file CModelExpansion.cpp.

References duplicate(), CCopasiObject::getCN(), CModelExpansion::ElementsMap::getDuplicatePtr(), CEvaluationTree::getNodeList(), CCopasiObject::getObject(), CEvaluationNodeObject::getObjectInterfacePtr(), CCopasiObject::getObjectName(), CCopasiObject::getObjectParent(), CCopasiObject::getObjectType(), and CEvaluationNodeObject::setData().

Referenced by replaceInEvent(), and replaceInModelEntity().

1296 {
1297  if (!exp)
1298  return;
1299 
1300  //we loop through the complete expression
1301  std::vector< CEvaluationNode * >::const_iterator it = exp->getNodeList().begin();
1302  std::vector< CEvaluationNode * >::const_iterator end = exp->getNodeList().end();
1303 
1304  for (; it != end; ++it)
1305  {
1306  CEvaluationNodeObject * node = dynamic_cast<CEvaluationNodeObject*>(*it);
1307 
1308  if (!node)
1309  continue;
1310 
1311  //std::cout << node->getData() << std::endl;
1312  const CCopasiObject * pObj = dynamic_cast<const CCopasiObject*>(node->getObjectInterfacePtr());
1313  std::string refname = "";
1314  std::string reftype = "";
1315 
1316  if (pObj)
1317  {
1318  refname = pObj->getObjectName();
1319  reftype = pObj->getObjectType();
1320  pObj = pObj->getObjectParent();
1321  }
1322 
1323  const CCopasiObject* duplicate = emap.getDuplicatePtr(pObj);
1324 
1325  if (duplicate)
1326  {
1327  //get the reference object
1328  const CCopasiObject* pRef = dynamic_cast<const CCopasiObject*>(duplicate->getObject(reftype + "=" + refname));
1329 
1330  //update the node
1331  if (pRef)
1332  node->setData("<" + pRef->getCN() + ">");
1333 
1334  //std::cout << node->getData() << std::endl;
1335  }
1336  }
1337 }
virtual CCopasiObjectName getCN() const
const CObjectInterface * getObjectInterfacePtr() const
const std::string & getObjectName() const
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
const std::string & getObjectType() const
bool duplicate(const SetOfModelElements &source, const std::string &index, ElementsMap &emap)
virtual bool setData(const Data &data)
const std::vector< CEvaluationNode * > & getNodeList() const
CCopasiContainer * getObjectParent() const
void CModelExpansion::replaceInMetab ( CMetab pX,
const ElementsMap emap 
)

Definition at line 1165 of file CModelExpansion.cpp.

References CCompartment::addMetabolite(), CModelExpansion::ElementsMap::exists(), CMetab::getCompartment(), CModelExpansion::ElementsMap::getDuplicatePtr(), CCompartment::getMetabolites(), CCopasiObject::getObjectName(), CModel::initializeMetabolites(), mpModel, CCopasiVectorN< CType >::remove(), replaceInModelEntity(), CModel::setCompileFlag(), and CCopasiObject::setObjectName().

Referenced by replaceInModel().

1166 {
1167  replaceInModelEntity(pX, emap);
1168 
1169  //is the metab in a compartment that needs to be replaced?
1170  if (emap.exists(pX->getCompartment()))
1171  {
1172  //move the metab to the new compartment
1173  CCompartment* oldComp = const_cast<CCompartment*>(pX->getCompartment());
1174  CCompartment* newComp = dynamic_cast<CCompartment*>(emap.getDuplicatePtr(pX->getCompartment()));
1175  bool success = false;
1176 
1177  do
1178  {
1179  success = newComp->addMetabolite(pX);
1180 
1181  if (success)
1182  {
1183  oldComp->getMetabolites().remove(pX->getObjectName());
1186  }
1187  else
1188  {
1189  //rename the metab so that it can be added to the new compartment
1190  pX->setObjectName(pX->getObjectName() + "_");
1191  //TODO: check if the renaming actually worked
1192  }
1193  }
1194  while (!success);
1195  }
1196 }
bool addMetabolite(CMetab *metabolite)
CCopasiVectorNS< CMetab > & getMetabolites()
const std::string & getObjectName() const
void replaceInModelEntity(CModelEntity *pX, const ElementsMap &emap)
void initializeMetabolites()
Definition: CModel.cpp:942
void setCompileFlag(bool flag=true)
Definition: CModel.cpp:607
virtual void remove(const std::string &name)
bool setObjectName(const std::string &name)
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
void CModelExpansion::replaceInModel ( const ElementsMap emap,
bool  remove 
)

Definition at line 1092 of file CModelExpansion.cpp.

References CModel::forceCompile(), CModel::getCompartments(), CModel::getEvents(), CModelExpansion::ElementsMap::getMap(), CModel::getMetabolites(), CModel::getModelValues(), CModel::getReactions(), mpModel, CModel::removeCompartment(), CModel::removeEvent(), CModel::removeMetabolite(), CModel::removeModelValue(), CModel::removeReaction(), replaceInCompartment(), replaceInEvent(), replaceInMetab(), replaceInModelEntity(), replaceInReaction(), and CCopasiVector< T >::size().

Referenced by CQMergingData::slotBtnMerge().

1093 {
1094  if (!mpModel)
1095  return;
1096 
1097  size_t i;
1098 
1099  for (i = 0; i < mpModel->getCompartments().size(); ++i)
1101 
1102  std::vector<CMetab*> metvec;
1103 
1104  for (i = 0; i < mpModel->getMetabolites().size(); ++i)
1105  metvec.push_back(mpModel->getMetabolites()[i]);
1106 
1107  for (i = 0; i < metvec.size(); ++i)
1108  replaceInMetab(metvec[i], emap);
1109 
1110  for (i = 0; i < mpModel->getReactions().size(); ++i)
1111  replaceInReaction(mpModel->getReactions()[i], emap);
1112 
1113  for (i = 0; i < mpModel->getModelValues().size(); ++i)
1115 
1116  for (i = 0; i < mpModel->getEvents().size(); ++i)
1117  replaceInEvent(mpModel->getEvents()[i], emap);
1118 
1119  mpModel->forceCompile(NULL);
1120 
1121  if (remove)
1122  {
1123  std::map<const CCopasiObject*, CCopasiObject*>::const_iterator it;
1124 
1125  for (it = emap.getMap().begin(); it != emap.getMap().end(); ++it)
1126  {
1127  if (dynamic_cast<const CCompartment*>(it->first))
1128  {
1129  mpModel->removeCompartment(const_cast<CCompartment*>(dynamic_cast<const CCompartment*>(it->first)), true);
1130  break;
1131  }
1132 
1133  if (dynamic_cast<const CMetab*>(it->first))
1134  {
1135  mpModel->removeMetabolite(const_cast<CMetab*>(dynamic_cast<const CMetab*>(it->first)), true);
1136  break;
1137  }
1138 
1139  if (dynamic_cast<const CReaction*>(it->first))
1140  {
1141  mpModel->removeReaction(const_cast<CReaction*>(dynamic_cast<const CReaction*>(it->first)), true);
1142  break;
1143  }
1144 
1145  if (dynamic_cast<const CModelValue*>(it->first))
1146  {
1147  mpModel->removeModelValue(const_cast<CModelValue*>(dynamic_cast<const CModelValue*>(it->first)), true);
1148  break;
1149  }
1150 
1151  if (dynamic_cast<const CEvent*>(it->first))
1152  {
1153  mpModel->removeEvent(const_cast<CEvent*>(dynamic_cast<const CEvent*>(it->first)), true);
1154  break;
1155  }
1156  }
1157  }
1158 }
CCopasiVectorN< CEvent > & getEvents()
Definition: CModel.cpp:1110
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual size_t size() const
bool removeMetabolite(const std::string &key, const bool &recursive=true)
Definition: CModel.cpp:2667
bool removeCompartment(const size_t index, const bool &recursive=true)
Definition: CModel.cpp:2720
void replaceInModelEntity(CModelEntity *pX, const ElementsMap &emap)
void replaceInReaction(CReaction *pX, const ElementsMap &emap)
bool removeModelValue(const CModelValue *pModelValue, const bool &recursive=true)
Definition: CModel.cpp:2903
void replaceInMetab(CMetab *pX, const ElementsMap &emap)
void replaceInEvent(CEvent *pX, const ElementsMap &emap)
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
void replaceInCompartment(CCompartment *pX, const ElementsMap &emap)
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
bool removeEvent(const size_t index, const bool &recursive=true)
Definition: CModel.cpp:2945
bool removeReaction(const CReaction *pReaction, const bool &recursive=true)
Definition: CModel.cpp:2792
bool forceCompile(CProcessReport *pProcessReport)
Definition: CModel.cpp:636
void CModelExpansion::replaceInModelEntity ( CModelEntity pX,
const ElementsMap emap 
)

Definition at line 1266 of file CModelExpansion.cpp.

References CModelEntity::getExpressionPtr(), CModelEntity::getInitialExpressionPtr(), and replaceInExpression().

Referenced by replaceInCompartment(), replaceInMetab(), and replaceInModel().

1267 {
1268  //expression (for assignment or ODE)
1270 
1271  //initial expression
1273 }
void replaceInExpression(CExpression *exp, const ElementsMap &emap)
const CExpression * getExpressionPtr() const
const CExpression * getInitialExpressionPtr() const
void CModelExpansion::replaceInReaction ( CReaction pX,
const ElementsMap emap 
)

Definition at line 1198 of file CModelExpansion.cpp.

References CReaction::getChemEq(), CModelExpansion::ElementsMap::getDuplicateKey(), CModelExpansion::ElementsMap::getDuplicatePtr(), CReaction::getFunctionParameters(), CModelEntity::getKey(), CChemEqElement::getMetabolite(), CChemEq::getModifiers(), CReaction::getParameterMappings(), CChemEq::getProducts(), CChemEq::getSubstrates(), CFunctionParameter::MODIFIER, CFunctionParameter::PARAMETER, CFunctionParameter::PRODUCT, CChemEqElement::setMetabolite(), CFunctionParameters::size(), CCopasiVector< T >::size(), CFunctionParameter::SUBSTRATE, CFunctionParameter::TIME, and CFunctionParameter::VOLUME.

Referenced by replaceInModel().

1199 {
1200  //replace in the chemical equation
1201  size_t i;
1202 
1203  for (i = 0; i < pX->getChemEq().getSubstrates().size(); ++i)
1204  {
1205  CChemEqElement * sourceElement = pX->getChemEq().getSubstrates()[i];
1206  const CMetab* pMetab = dynamic_cast<const CMetab*>(emap.getDuplicatePtr(sourceElement->getMetabolite()));
1207 
1208  if (pMetab)
1209  {
1210  sourceElement->setMetabolite(pMetab->getKey());
1211  }
1212  }
1213 
1214  for (i = 0; i < pX->getChemEq().getProducts().size(); ++i)
1215  {
1216  CChemEqElement * sourceElement = pX->getChemEq().getProducts()[i];
1217  const CMetab* pMetab = dynamic_cast<const CMetab*>(emap.getDuplicatePtr(sourceElement->getMetabolite()));
1218 
1219  if (pMetab)
1220  {
1221  sourceElement->setMetabolite(pMetab->getKey());
1222  }
1223  }
1224 
1225  for (i = 0; i < pX->getChemEq().getModifiers().size(); ++i)
1226  {
1227  CChemEqElement * sourceElement = pX->getChemEq().getModifiers()[i];
1228  const CMetab* pMetab = dynamic_cast<const CMetab*>(emap.getDuplicatePtr(sourceElement->getMetabolite()));
1229 
1230  if (pMetab)
1231  {
1232  sourceElement->setMetabolite(pMetab->getKey());
1233  }
1234  }
1235 
1236  //mapping and local parameters
1237  for (i = 0; i < pX->getFunctionParameters().size(); ++i)
1238  {
1239  switch (pX->getFunctionParameters()[i]->getUsage())
1240  {
1246  {
1247  size_t k;
1248 
1249  for (k = 0; k < pX->getParameterMappings()[i].size(); ++k)
1250  {
1251  std::string targetKey = emap.getDuplicateKey(pX->getParameterMappings()[i][k]);
1252 
1253  if (targetKey != "")
1254  pX->getParameterMappings()[i][k] = targetKey;
1255  }
1256  }
1257  break;
1258 
1260  default:
1261  break;
1262  }
1263  }
1264 }
virtual size_t size() const
const CMetab * getMetabolite() const
Definition: CMetab.h:178
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
const CFunctionParameters & getFunctionParameters() const
Definition: CReaction.cpp:576
void setMetabolite(const std::string &key)
virtual const std::string & getKey() const
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
const CCopasiVector< CChemEqElement > & getModifiers() const
Definition: CChemEq.cpp:66
const std::vector< std::vector< std::string > > & getParameterMappings() const
Definition: CReaction.h:285
const CChemEq & getChemEq() const
Definition: CReaction.cpp:223
void CModelExpansion::setModel ( CModel pModel)

Definition at line 268 of file CModelExpansion.cpp.

References mpModel.

269 {
270  mpModel = pModel;
271 }
void CModelExpansion::simpleCall ( const CCompartment source,
std::vector< std::string >  listOfMetabolites,
int  mult,
bool  diff 
)

Definition at line 273 of file CModelExpansion.cpp.

References CModelExpansion::SetOfModelElements::addCompartment(), CModel::compileIfNecessary(), createDiffusionReaction(), CModel::createModelValue(), duplicate(), CModelExpansion::SetOfModelElements::fillDependencies(), CModelExpansion::ElementsMap::getDuplicateKey(), CModelEntity::getKey(), and mpModel.

274 {
275  if (!mpModel) return;
276 
277  if (!source) return;
278 
279  //First we create a SetOfModelElements object. It will contain the list of all things in the model that
280  //should be duplicated. (This means that we can duplicate also parts of models, not only complete models)
281  SetOfModelElements originalSet;
282 
283  //We start by specifying one compartment that we want to duplicate
284  originalSet.addCompartment(source);
285 
286  //Now we (automatically) include everything that needs to be duplicated with the compartment.
287  //(The species in the compartment, the reactions incolving these species)
288  originalSet.fillDependencies(mpModel);
289 
290  //now we want to create one copy. indexstring contains a postfix that will be added to the names of
291  //the duplicated model parts to identify them
292  std::string indexstr = "[1]";
293 
294  //the ElementsMap object will contain a mapping between original and duplicated objects
295  //after the duplicating has been performed. This means we will be able to access the duplicated
296  //objects e.g. for creating diffusion reactions.
297  ElementsMap map_1;
298 
299  //this performes the actual duplication:
300  duplicate(originalSet, indexstr, map_1);
301 
302  //now a second copy (this can easily be put in a loop)
303  indexstr = "[2]";
304  ElementsMap map_2;
305  duplicate(originalSet, indexstr, map_2);
306 
307  //and a third
308  indexstr = "[3]";
309  ElementsMap map_3;
310  duplicate(originalSet, indexstr, map_3);
311 
312  if (listOfMetabolites.size() > 0)
313  {
314  //now create the diffusion reactions:
315  //we pick a metab for which we want to create diffusion reactions
316  std::string original_metab_key = listOfMetabolites[0];
317 
318  //create a global quantity that will be used as the diffusion parameter
319  CModelValue* pMV = mpModel->createModelValue("Diff_glu", 7);
320 
321  //create first reaction.
322  //the maps let us find the duplicates of the original metab.
323  createDiffusionReaction("Diff_glu[1-2]",
324  map_1.getDuplicateKey(original_metab_key),
325  map_2.getDuplicateKey(original_metab_key), pMV->getKey());
326 
327  //create second reaction (this can easily be put in a loop)
328  createDiffusionReaction("Diff_glu[2-3]",
329  map_2.getDuplicateKey(original_metab_key),
330  map_3.getDuplicateKey(original_metab_key), pMV->getKey());
331  }
332 
334 }
CModelValue * createModelValue(const std::string &name, const C_FLOAT64 &value=0.0)
Definition: CModel.cpp:2838
bool duplicate(const SetOfModelElements &source, const std::string &index, ElementsMap &emap)
void createDiffusionReaction(const std::string &name, const std::string &metabkey1, const std::string &metabkey2, const std::string &parameterkey)
virtual const std::string & getKey() const
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
void CModelExpansion::updateExpression ( CExpression exp,
const std::string &  index,
const SetOfModelElements sourceSet,
ElementsMap emap 
)

steps through an expression and replaces references to objects with references to their duplicate. (In case an object that should be duplicated according to sourceSet is not yet duplicated according to emap, the duplication is performed also)

Definition at line 952 of file CModelExpansion.cpp.

References CModelExpansion::SetOfModelElements::contains(), duplicate(), duplicateCompartment(), duplicateGlobalQuantity(), duplicateMetab(), duplicateReaction(), CModelExpansion::ElementsMap::exists(), CCopasiObject::getCN(), CModelExpansion::ElementsMap::getDuplicatePtr(), CEvaluationTree::getNodeList(), CCopasiContainer::getObject(), CCopasiObject::getObject(), CEvaluationNodeObject::getObjectCN(), CEvaluationNodeObject::getObjectInterfacePtr(), CCopasiObject::getObjectName(), CCopasiObject::getObjectParent(), CCopasiObjectName::getObjectType(), CCopasiObject::getObjectType(), CCopasiObjectName::getPrimary(), CCopasiObjectName::getRemainder(), mpSourceModel, and CEvaluationNodeObject::setData().

Referenced by duplicateCompartment(), duplicateEvent(), duplicateGlobalQuantity(), and duplicateMetab().

953 {
954  if (!exp)
955  return;
956 
957  //we loop through the complete expression
958  std::vector< CEvaluationNode * >::const_iterator it = exp->getNodeList().begin();
959  std::vector< CEvaluationNode * >::const_iterator end = exp->getNodeList().end();
960 
961  for (; it != end; ++it)
962  {
963  CEvaluationNodeObject * node = dynamic_cast<CEvaluationNodeObject*>(*it);
964 
965  if (!node)
966  continue;
967 
968  //std::cout << node->getData() << std::endl;
969  const CCopasiObject * pObj = dynamic_cast<const CCopasiObject*>(node->getObjectInterfacePtr());
970  std::string refname = "";
971  std::string reftype = "";
972 
973  //when copying between models, pObj=NULL. This is because the expression could not be compiled
974  //if it points to an object in a different model.
975  //We try to fix this now:
976  if (!pObj && mpSourceModel)
977  {
978  CCopasiObjectName cn = node->getObjectCN();
979 
980  while (cn.getPrimary().getObjectType() != "Model" && !cn.empty())
981  {
982  cn = cn.getRemainder();
983  }
984 
985  pObj = dynamic_cast<const CCopasiObject*>(mpSourceModel->getObject(cn));
986  }
987 
988  if (pObj)
989  {
990  refname = pObj->getObjectName();
991  reftype = pObj->getObjectType();
992  pObj = pObj->getObjectParent();
993  }
994 
995  //is the object one that is/should be copied?
996  if (sourceSet.contains(pObj))
997  {
998  if (!emap.exists(pObj))
999  {
1000  //we have to create the duplicate
1001  std::cout << "!!!" << std::endl;
1002 
1003  if (dynamic_cast<const CCompartment*>(pObj))
1004  duplicateCompartment(dynamic_cast<const CCompartment*>(pObj), index, sourceSet, emap);
1005 
1006  if (dynamic_cast<const CMetab*>(pObj))
1007  duplicateMetab(dynamic_cast<const CMetab*>(pObj), index, sourceSet, emap);
1008 
1009  if (dynamic_cast<const CModelValue*>(pObj))
1010  duplicateGlobalQuantity(dynamic_cast<const CModelValue*>(pObj), index, sourceSet, emap);
1011 
1012  if (dynamic_cast<const CReaction*>(pObj))
1013  duplicateReaction(dynamic_cast<const CReaction*>(pObj), index, sourceSet, emap);
1014  }
1015 
1016  //find the duplicate
1017  const CCopasiObject* duplicate = emap.getDuplicatePtr(pObj);
1018 
1019  if (duplicate)
1020  {
1021  //get the reference object
1022  const CCopasiObject* pRef = dynamic_cast<const CCopasiObject*>(duplicate->getObject(reftype + "=" + refname));
1023 
1024  //update the node
1025  if (pRef)
1026  node->setData("<" + pRef->getCN() + ">");
1027 
1028  //std::cout << node->getData() << std::endl;
1029  }
1030  }
1031  }
1032 }
virtual CCopasiObjectName getCN() const
const CObjectInterface * getObjectInterfacePtr() const
const std::string & getObjectName() const
CCopasiObjectName getRemainder() const
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
const CRegisteredObjectName & getObjectCN() const
const std::string & getObjectType() const
std::string getObjectType() const
void duplicateMetab(const CMetab *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
bool duplicate(const SetOfModelElements &source, const std::string &index, ElementsMap &emap)
CCopasiObjectName getPrimary() const
void duplicateReaction(const CReaction *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
void duplicateGlobalQuantity(const CModelValue *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
virtual bool setData(const Data &data)
void duplicateCompartment(const CCompartment *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
const std::vector< CEvaluationNode * > & getNodeList() const
const CModel * mpSourceModel
CCopasiContainer * getObjectParent() const

Member Data Documentation

CModel* CModelExpansion::mpModel
protected
const CModel* CModelExpansion::mpSourceModel
protected

Definition at line 195 of file CModelExpansion.h.

Referenced by copyCompleteModel(), and updateExpression().


The documentation for this class was generated from the following files: