COPASI API  4.16.103
CModelExpansion.h
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/model/CModelExpansion.h,v $
3 // $Revision: 1.8 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/09/30 16:36:30 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 #ifndef CMODELEXPANSION_H
20 #define CMODELEXPANSION_H
21 
22 #include <string>
23 #include <map>
24 #include <set>
25 #include <iostream>
26 #include <fstream>
27 #include <ctype.h>
28 #include "copasi.h"
29 #include <vector>
30 
31 class CModelEntity;
32 class CModel;
33 class CMetab;
34 class CCompartment;
35 class CReaction;
36 class CModelValue;
37 class CExpression;
38 class CEvent;
39 class CCopasiObject;
40 
42 {
43 public:
44 
45 
46  /**
47  * This class describes a set of model elements that are supposed to be duplicated.
48  * The second element in each of the pairs is used temporarily to hold the copy.
49  */
51  {
52  public:
53 
54  void addCompartment(const CCompartment* x);
55  void addMetab(const CMetab* x);
56  void addReaction(const CReaction* x);
57  void addGlobalQuantity(const CModelValue* x);
58  void addEvent(const CEvent* x);
59 
60  bool addObject(const CCopasiObject* x);
61 
62 
63  /**
64  * Checks whether an object is present in this set
65  */
66  bool contains(const CCopasiObject* x) const;
67  bool contains(const std::string & key) const;
68 
69  /**
70  * Determines which other object have to be duplicated based on those already present.
71  */
72  void fillDependencies(const CModel* pModel);
73 
74  /**
75  * enters all the objects from pModel
76  */
77  void fillComplete(const CModel* pModel);
78 
79  //protected:
80  std::set<const CCompartment*> mCompartments;
81  std::set<const CMetab*> mMetabs;
82  std::set<const CReaction*> mReactions;
83  std::set<const CModelValue*> mGlobalQuantities;
84  std::set<const CEvent*> mEvents;
85  };
86 
87  /**
88  * This class contains a map from original to duplicated sets of model elements
89  */
91  {
92  public:
93 
94  ///does a copy of the source object exist?
95  bool exists(const CCopasiObject* source) const;
96  bool exists(const std::string & sourceKey) const;
97 
98  ///add a source->duplicate mapping
99  void add(const CCopasiObject* source, CCopasiObject* copy);
100 
101  ///find the pointer of the duplicated object from the pointer to the source object (if it exists)
102  CCopasiObject* getDuplicatePtr(const CCopasiObject* source) const;
103 
104  ///find the key of the duplicated object from the source object (if it exists)
105  std::string getDuplicateKey(const std::string & sourceKey) const;
106 
107  const std::map<const CCopasiObject*, CCopasiObject*> & getMap() const;
108 
109  protected:
110 
111  std::map<const CCopasiObject*, CCopasiObject*> mMap;
112  };
113 
114 
115  CModelExpansion(CModel* pModel);
116 
117  void setModel(CModel* pModel);
118 
119  //just a simple method to call during development (as an example for how to use the other methods)
120  void simpleCall(const CCompartment* source, std::vector< std::string > listOfMetabolites, int mult, bool diff);
121 
122  /**
123  * creates n copies of the objects in souce. Diffusion reactions are created for each of
124  * the metabs in listOfMetabolites, so that a linear chain is formed.
125  */
126  void createLinearArray(const SetOfModelElements & source, size_t n, const std::set< std::string > & setOfMetabolites);
127 
128  /**
129  * creates nx*ny copies of the objects in souce. Diffusion reactions are created for each of
130  * the metabs in listOfMetabolites, so that a rectangular array is formed.
131  */
132  void createRectangularArray(const SetOfModelElements & source, size_t nx, size_t ny, const std::set< std::string > & setOfMetabolites);
133 
134  /**
135  * adds the contents of the source model to the current model.
136  * A list of created model elements is returned
137  */
138  std::set<CCopasiObject*> copyCompleteModel(const CModel* pSourceModel);
139 
140 
141  /**
142  * creates one duplicate of the set of elements specified by source.
143  * the string index is added to the object names
144  */
145  bool duplicate(const SetOfModelElements & source, const std::string & index, ElementsMap & emap);
146 
147  void duplicateCompartment(const CCompartment* source, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap);
148  void duplicateMetab(const CMetab* source, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap);
149  void duplicateReaction(const CReaction* source, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap);
150  void duplicateGlobalQuantity(const CModelValue* source, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap);
151  void duplicateEvent(CEvent* source, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap);
152 
153  /**
154  * steps through an expression and replaces references to objects with references to their duplicate.
155  * (In case an object that should be duplicated according to sourceSet is not yet duplicated
156  * according to emap, the duplication is performed also)
157  */
158  void updateExpression(CExpression* exp, const std::string & index, const SetOfModelElements & sourceSet, ElementsMap & emap);
159 
160  /**
161  * Check if a given expression contains any of the objects in the sourceSet
162  */
163  bool expressionContainsObject(const CExpression* exp, const SetOfModelElements & sourceSet);
164 
165  /**
166  * Create a first order reversible mass action reaction.
167  * This is intended for diffusion between copies of model parts.
168  * The method takes a reaction name, and keys of two metabolites and
169  * a global quantity that is used as a rate constant.
170  */
171  void createDiffusionReaction(const std::string & name,
172  const std::string & metabkey1, const std::string & metabkey2,
173  const std::string & parameterkey);
174 
175  void replaceInModel(const ElementsMap & emap, bool remove);
176 
177  void replaceInCompartment(CCompartment* pX, const ElementsMap & emap);
178  void replaceInMetab(CMetab* pX, const ElementsMap & emap);
179  void replaceInReaction(CReaction* pX, const ElementsMap & emap);
180  void replaceInModelEntity(CModelEntity* pX, const ElementsMap & emap);
181  void replaceInEvent(CEvent* pX, const ElementsMap & emap);
182 
183  void replaceInExpression(CExpression* exp, const ElementsMap & emap);
184 
185  /**
186  * Tests if there are model elements that refer to the given model entity
187  */
188  bool existDependentEntities(const CCopasiObject* pObj);
189 
190 
191 protected:
192 
193 
196 };
197 
198 #endif // CMODELEXPANSION_H
void replaceInExpression(CExpression *exp, const ElementsMap &emap)
Definition: CEvent.h:152
std::set< CCopasiObject * > copyCompleteModel(const CModel *pSourceModel)
void addReaction(const CReaction *x)
void simpleCall(const CCompartment *source, std::vector< std::string > listOfMetabolites, int mult, bool diff)
std::set< const CEvent * > mEvents
std::set< const CCompartment * > mCompartments
void replaceInModelEntity(CModelEntity *pX, const ElementsMap &emap)
void addGlobalQuantity(const CModelValue *x)
void replaceInReaction(CReaction *pX, const ElementsMap &emap)
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
bool duplicate(const SetOfModelElements &source, const std::string &index, ElementsMap &emap)
void duplicateEvent(CEvent *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
void createRectangularArray(const SetOfModelElements &source, size_t nx, size_t ny, const std::set< std::string > &setOfMetabolites)
void createDiffusionReaction(const std::string &name, const std::string &metabkey1, const std::string &metabkey2, const std::string &parameterkey)
bool existDependentEntities(const CCopasiObject *pObj)
void add(const CCopasiObject *source, CCopasiObject *copy)
add a source->duplicate mapping
void replaceInMetab(CMetab *pX, const ElementsMap &emap)
std::string getDuplicateKey(const std::string &sourceKey) const
find the key of the duplicated object from the source object (if it exists)
void duplicateReaction(const CReaction *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
void replaceInEvent(CEvent *pX, const ElementsMap &emap)
void createLinearArray(const SetOfModelElements &source, size_t n, const std::set< std::string > &setOfMetabolites)
void fillDependencies(const CModel *pModel)
CModelExpansion(CModel *pModel)
bool contains(const CCopasiObject *x) const
bool addObject(const CCopasiObject *x)
void addCompartment(const CCompartment *x)
void duplicateGlobalQuantity(const CModelValue *source, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
std::set< const CModelValue * > mGlobalQuantities
void replaceInCompartment(CCompartment *pX, const ElementsMap &emap)
void fillComplete(const CModel *pModel)
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)
const std::map< const CCopasiObject *, CCopasiObject * > & getMap() const
void updateExpression(CExpression *exp, const std::string &index, const SetOfModelElements &sourceSet, ElementsMap &emap)
std::set< const CMetab * > mMetabs
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
void setModel(CModel *pModel)
std::set< const CReaction * > mReactions
std::map< const CCopasiObject *, CCopasiObject * > mMap