COPASI API  4.16.103
CModelExpansion.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 #include <locale>
12 
13 #include "CModelExpansion.h"
14 
15 #include "CModel.h"
16 #include "function/CExpression.h"
17 #include "report/CCopasiObject.h"
20 
22 {
23  mCompartments.insert(x);
24 }
25 
27 {
28  mMetabs.insert(x);
29 }
30 
32 {
33  mReactions.insert(x);
34 }
35 
37 {
38  mGlobalQuantities.insert(x);
39 }
40 
42 {
43  mEvents.insert(x);
44 }
45 
47 {
48  if (dynamic_cast<const CCompartment*>(x))
49  {
50  addCompartment(dynamic_cast<const CCompartment*>(x));
51  return true;
52  }
53 
54  if (dynamic_cast<const CMetab*>(x))
55  {
56  addMetab(dynamic_cast<const CMetab*>(x));
57  return true;
58  }
59 
60  if (dynamic_cast<const CReaction*>(x))
61  {
62  addReaction(dynamic_cast<const CReaction*>(x));
63  return true;
64  }
65 
66  if (dynamic_cast<const CModelValue*>(x))
67  {
68  addGlobalQuantity(dynamic_cast<const CModelValue*>(x));
69  return true;
70  }
71 
72  if (dynamic_cast<const CEvent*>(x))
73  {
74  addEvent(dynamic_cast<const CEvent*>(x));
75  return true;
76  }
77 
78  return false;
79 }
80 
82 {
83  if (mCompartments.find(static_cast<const CCompartment*>(x)) != mCompartments.end())
84  return true;
85 
86  if (mMetabs.find(static_cast<const CMetab*>(x)) != mMetabs.end())
87  return true;
88 
89  if (mReactions.find(static_cast<const CReaction*>(x)) != mReactions.end())
90  return true;
91 
92  if (mGlobalQuantities.find(static_cast<const CModelValue*>(x)) != mGlobalQuantities.end())
93  return true;
94 
95  if (mEvents.find(static_cast<const CEvent*>(x)) != mEvents.end())
96  return true;
97 
98  return false;
99 }
100 
101 bool CModelExpansion::SetOfModelElements::contains(const std::string & key) const
102 {
104 
105  if (tmp)
106  return contains(tmp);
107  else
108  return false;
109 }
110 
112 {
113  if (!pModel) return;
114 
115  //create a combined set of all elements we know are to be copied
116  std::set< const CCopasiObject * > combinedSet;
117 
118  std::set<const CCompartment*>::const_iterator itComp;
119 
120  for (itComp = mCompartments.begin(); itComp != mCompartments.end(); ++itComp)
121  {
122  std::set< const CCopasiObject * > tmp = (*itComp)->getDeletedObjects();
123  combinedSet.insert(tmp.begin(), tmp.end());
124  }
125 
126  std::set<const CMetab*>::const_iterator itMetab;
127 
128  for (itMetab = mMetabs.begin(); itMetab != mMetabs.end(); ++itMetab)
129  {
130  std::set< const CCopasiObject * > tmp = (*itMetab)->getDeletedObjects();
131  combinedSet.insert(tmp.begin(), tmp.end());
132  }
133 
134  std::set<const CReaction*>::const_iterator itReac;
135 
136  for (itReac = mReactions.begin(); itReac != mReactions.end(); ++itReac)
137  {
138  std::set< const CCopasiObject * > tmp = (*itReac)->getDeletedObjects();
139  combinedSet.insert(tmp.begin(), tmp.end());
140  }
141 
142  std::set<const CModelValue*>::const_iterator itQuant;
143 
144  for (itQuant = mGlobalQuantities.begin(); itQuant != mGlobalQuantities.end(); ++itQuant)
145  {
146  std::set< const CCopasiObject * > tmp = (*itQuant)->getDeletedObjects();
147  combinedSet.insert(tmp.begin(), tmp.end());
148  }
149 
150  /* Events do not contain any relevant objects.
151  std::set<const CEvent*>::const_iterator itEvent;
152 
153  for (itEvent = mEvents.begin(); itEvent != mEvents.end(); ++itEvent)
154  {
155  std::set< const CCopasiObject * > tmp = (*itEvent)->getDeletedObjects();
156  combinedSet.insert(tmp.begin(), tmp.end());
157  }
158  */
159 
160  //ask the model for the dependencies
161 
162  std::set< const CCopasiObject * > reacs, metabs, comps, values, events;
163  pModel->appendDependentModelObjects(combinedSet, reacs, metabs, comps, values, events);
164 
165  //incorporate the results into the local sets
166  std::set< const CCopasiObject * >::const_iterator it;
167 
168  for (it = reacs.begin(); it != reacs.end(); ++it)
169  addReaction(dynamic_cast<const CReaction*>(*it));
170 
171  for (it = metabs.begin(); it != metabs.end(); ++it)
172  addMetab(dynamic_cast<const CMetab*>(*it));
173 
174  for (it = comps.begin(); it != comps.end(); ++it)
175  addCompartment(dynamic_cast<const CCompartment*>(*it));
176 
177  for (it = values.begin(); it != values.end(); ++it)
178  addGlobalQuantity(dynamic_cast<const CModelValue*>(*it));
179 
180  for (it = events.begin(); it != events.end(); ++it)
181  addEvent(dynamic_cast<const CEvent*>(*it));
182 }
183 
185 {
186  if (!pModel)
187  return;
188 
189  size_t i;
190 
191  for (i = 0; i < pModel->getCompartments().size(); ++i)
192  addCompartment(pModel->getCompartments()[i]);
193 
194  for (i = 0; i < pModel->getMetabolites().size(); ++i)
195  addMetab(pModel->getMetabolites()[i]);
196 
197  for (i = 0; i < pModel->getReactions().size(); ++i)
198  addReaction(pModel->getReactions()[i]);
199 
200  for (i = 0; i < pModel->getModelValues().size(); ++i)
201  addGlobalQuantity(pModel->getModelValues()[i]);
202 
203  for (i = 0; i < pModel->getEvents().size(); ++i)
204  addEvent(pModel->getEvents()[i]);
205 }
206 
207 //***************************************************************************************
208 
210 {
211  std::map<const CCopasiObject*, CCopasiObject*>::const_iterator it;
212  it = mMap.find(source);
213  return (it != mMap.end() && it->second != NULL);
214 }
215 
216 bool CModelExpansion::ElementsMap::exists(const std::string & sourceKey) const
217 {
218  const CCopasiObject* tmp = CCopasiRootContainer::getKeyFactory()->get(sourceKey);
219  return exists(tmp);
220 }
221 
223 {
224  mMap[source] = copy;
225 }
226 
228 {
229  std::map<const CCopasiObject*, CCopasiObject*>::const_iterator it;
230  it = mMap.find(source);
231 
232  if (it != mMap.end())
233  return it->second;
234  else
235  return NULL;
236 }
237 
238 std::string CModelExpansion::ElementsMap::getDuplicateKey(const std::string & sourceKey) const
239 {
240  const CCopasiObject* tmp = CCopasiRootContainer::getKeyFactory()->get(sourceKey);
241 
242  if (tmp)
243  {
244  const CCopasiObject* retObj = getDuplicatePtr(tmp);
245 
246  if (retObj)
247  return retObj->getKey();
248  else
249  return "";
250  }
251  else
252  return "";
253 }
254 
255 const std::map<const CCopasiObject*, CCopasiObject*> & CModelExpansion::ElementsMap::getMap() const
256 {
257  return mMap;
258 }
259 
260 //***************************************************************************************
261 
263  : mpModel(pModel),
264  mpSourceModel(NULL)
265 {
266 }
267 
269 {
270  mpModel = pModel;
271 }
272 
273 void CModelExpansion::simpleCall(const CCompartment * source, std::vector< std::string > listOfMetabolites, int /* mult */, bool /* diff */)
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 }
335 
336 void CModelExpansion::createLinearArray(const SetOfModelElements & source, size_t n, const std::set< std::string > & setOfMetabolites)
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 }
396 
397 void CModelExpansion::createRectangularArray(const SetOfModelElements & source, size_t nx, size_t ny, const std::set< std::string > & setOfMetabolites)
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 }
477 
478 std::set<CCopasiObject*> CModelExpansion::copyCompleteModel(const CModel* pSourceModel)
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 }
499 
500 bool CModelExpansion::duplicate(const SetOfModelElements & source, const std::string & index, ElementsMap & emap)
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 }
541 
542 void CModelExpansion::duplicateCompartment(const CCompartment* source, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap)
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 }
581 
582 void CModelExpansion::duplicateMetab(const CMetab* source, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap)
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 }
643 
644 void CModelExpansion::duplicateReaction(const CReaction* source, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap)
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 }
831 
832 void CModelExpansion::duplicateGlobalQuantity(const CModelValue* source, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap)
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 }
868 
869 void CModelExpansion::duplicateEvent(CEvent* source, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap)
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 }
951 
952 void CModelExpansion::updateExpression(CExpression* exp, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap)
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 }
1033 
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 }
1065 
1066 void CModelExpansion::createDiffusionReaction(const std::string & name,
1067  const std::string & metabkey1, const std::string & metabkey2,
1068  const std::string & parameterkey)
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 }
1091 
1092 void CModelExpansion::replaceInModel(const ElementsMap & emap, bool remove)
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 }
1159 
1161 {
1162  replaceInModelEntity(pX, emap);
1163 }
1164 
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 }
1197 
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 }
1265 
1267 {
1268  //expression (for assignment or ODE)
1270 
1271  //initial expression
1273 }
1274 
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 }
1294 
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 }
1338 
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 
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 }
void replaceInExpression(CExpression *exp, const ElementsMap &emap)
const CExpression * getExpressionPtr() const
Definition: CEvent.h:152
Header file of class CExpression.
void setReversible(bool reversible)
Definition: CReaction.cpp:247
const CCopasiVectorN< CEventAssignment > & getAssignments() const
Definition: CEvent.cpp:678
std::set< CCopasiObject * > copyCompleteModel(const CModel *pSourceModel)
const bool & getDelayAssignment() const
Definition: CEvent.cpp:419
bool addMetabolite(CMetab *metabolite)
CEvent * createEvent(const std::string &name)
Definition: CModel.cpp:2928
CCopasiVectorN< CEvent > & getEvents()
Definition: CModel.cpp:1110
CCopasiVectorNS< CMetab > & getMetabolites()
virtual CCopasiObjectName getCN() const
bool addSubstrate(const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
Definition: CReaction.cpp:232
void addReaction(const CReaction *x)
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
const CObjectInterface * getObjectInterfacePtr() const
const std::string & getObjectName() const
void simpleCall(const CCompartment *source, std::vector< std::string > listOfMetabolites, int mult, bool diff)
CCopasiObjectName getRemainder() const
bool setDimensionality(unsigned C_INT32 dim)
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
unsigned C_INT32 getDimensionality() const
virtual size_t size() const
const C_FLOAT64 & getInitialConcentration() const
Definition: CMetab.cpp:220
const CRegisteredObjectName & getObjectCN() const
bool removeMetabolite(const std::string &key, const bool &recursive=true)
Definition: CModel.cpp:2667
std::set< const CEvent * > mEvents
const std::string & getTargetKey() const
Definition: CEvent.cpp:162
std::set< const CCompartment * > mCompartments
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
bool removeCompartment(const size_t index, const bool &recursive=true)
Definition: CModel.cpp:2720
const CMetab * getMetabolite() const
void replaceInModelEntity(CModelEntity *pX, const ElementsMap &emap)
void setNotes(const std::string &notes)
const CExpression * getExpressionPtr() const
Definition: CEvent.cpp:226
bool setExpression(const std::string &expression)
Definition: CEvent.cpp:167
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 addGlobalQuantity(const CModelValue *x)
const std::string & getObjectType() const
bool setInitialExpression(const std::string &expression)
void replaceInReaction(CReaction *pX, const ElementsMap &emap)
std::string getExpression() const
void clearParameterMapping(const std::string &parameterName)
Definition: CReaction.cpp:407
std::string getTriggerExpression() const
Definition: CEvent.cpp:524
std::string getObjectType() const
virtual bool compile(std::vector< CCopasiContainer * > listOfContainer=CCopasiContainer::EmptyList)
Definition: CExpression.cpp:97
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)
bool setTargetKey(const std::string &targetKey)
Definition: CEvent.cpp:151
bool expressionContainsObject(const CExpression *exp, const SetOfModelElements &sourceSet)
void duplicateMetab(const CMetab *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
Definition: CMetab.h:178
const std::string & getMiriamAnnotation() const
bool duplicate(const SetOfModelElements &source, const std::string &index, ElementsMap &emap)
CExpression * getDelayExpressionPtr()
Definition: CEvent.cpp:606
CCopasiObjectName getPrimary() const
virtual const std::string & getKey() const
bool removeModelValue(const CModelValue *pModelValue, const bool &recursive=true)
Definition: CModel.cpp:2903
void duplicateEvent(CEvent *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
const C_FLOAT64 & getInitialValue() const
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
const CFunction * getFunction() const
Definition: CReaction.cpp:252
bool appendDependentModelObjects(const std::set< const CCopasiObject * > &candidates, std::set< const CCopasiObject * > &dependentReactions, std::set< const CCopasiObject * > &dependentMetabolites, std::set< const CCopasiObject * > &dependentCompartments, std::set< const CCopasiObject * > &dependentModelValues, std::set< const CCopasiObject * > &dependentEvents) const
Definition: CModel.cpp:2364
void createRectangularArray(const SetOfModelElements &source, size_t nx, size_t ny, const std::set< std::string > &setOfMetabolites)
const CFunctionParameters & getFunctionParameters() const
Definition: CReaction.cpp:576
virtual bool add(const CType &src)
void createDiffusionReaction(const std::string &name, const std::string &metabkey1, const std::string &metabkey2, const std::string &parameterkey)
bool addModifier(const std::string &metabKey, const C_FLOAT64 &multiplicity=1.0)
Definition: CReaction.cpp:240
void setMetabolite(const std::string &key)
bool existDependentEntities(const CCopasiObject *pObj)
const std::string & getNotes() const
bool setFunction(const std::string &functionName)
Definition: CReaction.cpp:255
virtual const std::string & getKey() const
virtual void setStatus(const CModelEntity::Status &status)
CReaction * createReaction(const std::string &name)
Definition: CModel.cpp:2760
bool setTriggerExpression(const std::string &expression)
Definition: CEvent.cpp:474
const C_FLOAT64 & getMultiplicity() const
void add(const CCopasiObject *source, CCopasiObject *copy)
add a source->duplicate mapping
std::string getInitialExpression() const
void replaceInMetab(CMetab *pX, const ElementsMap &emap)
void initializeMetabolites()
Definition: CModel.cpp:942
std::string getDuplicateKey(const std::string &sourceKey) const
find the key of the duplicated object from the source object (if it exists)
void setDelayAssignment(const bool &delayCalculation)
Definition: CEvent.cpp:408
void duplicateReaction(const CReaction *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
void replaceInEvent(CEvent *pX, const ElementsMap &emap)
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
bool isReversible() const
Definition: CReaction.cpp:229
void createLinearArray(const SetOfModelElements &source, size_t n, const std::set< std::string > &setOfMetabolites)
std::string getDelayExpression() const
Definition: CEvent.cpp:591
void setCompileFlag(bool flag=true)
Definition: CModel.cpp:607
void fillDependencies(const CModel *pModel)
virtual void remove(const std::string &name)
CModelExpansion(CModel *pModel)
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
bool contains(const CCopasiObject *x) const
const CExpression * getTriggerExpressionPtr() const
Definition: CEvent.cpp:534
bool addObject(const CCopasiObject *x)
void addCompartment(const CCompartment *x)
static CKeyFactory * getKeyFactory()
void duplicateGlobalQuantity(const CModelValue *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
bool setDelayExpression(const std::string &expression)
Definition: CEvent.cpp:544
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
const CCopasiVector< CChemEqElement > & getModifiers() const
Definition: CChemEq.cpp:66
std::set< const CModelValue * > mGlobalQuantities
void replaceInCompartment(CCompartment *pX, const ElementsMap &emap)
void setParameterMapping(const size_t &index, const std::string &key)
Definition: CReaction.cpp:339
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
void fillComplete(const CModel *pModel)
virtual bool setData(const Data &data)
void replaceInModel(const ElementsMap &emap, bool remove)
Definition: CModel.h:50
void duplicateCompartment(const CCompartment *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
const CModelEntity::Status & getStatus() const
const std::vector< std::vector< std::string > > & getParameterMappings() const
Definition: CReaction.h:285
bool setExpression(const std::string &expression)
const std::map< const CCopasiObject *, CCopasiObject * > & getMap() const
bool setObjectName(const std::string &name)
const std::vector< CEvaluationNode * > & getNodeList() const
void updateExpression(CExpression *exp, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
std::set< const CMetab * > mMetabs
const CChemEq & getChemEq() const
Definition: CReaction.cpp:223
virtual const std::string & getKey() const
Definition: CEvent.cpp:287
const C_FLOAT64 & getParameterValue(const std::string &parameterName) const
Definition: CReaction.cpp:326
CCopasiObject * getDuplicatePtr(const CCopasiObject *source) const
find the pointer of the duplicated object from the pointer to the source object (if it exists) ...
bool exists(const CCopasiObject *source) const
does a copy of the source object exist?
const CModel * mpSourceModel
CCopasiContainer * getObjectParent() const
std::string getExpression() const
Definition: CEvent.cpp:216
const CExpression * getInitialExpressionPtr() const
void addParameterMapping(const size_t &index, const std::string &key)
Definition: CReaction.cpp:348
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
CCompartment * createCompartment(const std::string &name, const C_FLOAT64 &volume=1.0)
Definition: CModel.cpp:2698
void setModel(CModel *pModel)
bool forceCompile(CProcessReport *pProcessReport)
Definition: CModel.cpp:636
std::set< const CReaction * > mReactions
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