COPASI API  4.16.103
CSBMLExporter.h
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) 2008 - 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 // Copyright (C) 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #ifndef CSBMLExporter_H__
16 #define CSBMLExporter_H__
17 
18 #include <vector>
19 #include <string>
20 #include <set>
21 #include <map>
22 
23 #include "copasi.h"
24 
26 #include <sbml/FunctionDefinition.h>
27 
28 class CAnnotation;
29 class CChemEqElement;
30 class CCompartment;
31 class CCopasiDataModel;
32 class CCopasiParameter;
33 class CEvaluationNode;
34 class CEvent;
35 class CExpression;
36 class CFunction;
37 class CFunctionDB;
38 class CMetab;
39 class CModelValue;
40 class CReaction;
41 class Event;
42 class CModelEntity;
43 class KineticLaw;
44 class Model;
45 class Parameter;
46 class Rule;
47 class SBase;
48 class SBMLDocument;
50 class XMLNode;
51 
53 {
54 protected:
55  SBMLDocument* mpSBMLDocument;
56  unsigned int mSBMLLevel;
57  unsigned int mSBMLVersion;
58  std::vector<CModelEntity*> mAssignmentVector;
59  std::vector<CModelEntity*> mODEVector;
60  std::vector<CModelEntity*> mInitialAssignmentVector;
61  std::map<const CCopasiObject*, SBase*> mCOPASI2SBMLMap;
62  std::set<SBase*> mHandledSBMLObjects;
63  std::set<CFunction*> mUsedFunctions;
64  std::map<std::string, const SBase*> mIdMap;
65  std::vector<SBMLIncompatibility> mIncompatibilities;
70  std::map<std::string, const SBase*> mMetaIdMap;
72  std::map<std::string, const CEvaluationTree*> mFunctionIdMap;
75  std::map<std::string, Parameter*> mParameterReplacementMap;
76  std::set<std::string> mSpatialSizeUnitsSpecies;
77  ListOfFunctionDefinitions mExportedFunctions;
78  std::map<const FunctionDefinition*, const CCopasiObject*> mFunctionMap;
79  std::map<const std::string, Parameter*> mInitialValueMap;
83 
84 public:
85  /**
86  * Default Konstruktor
87  */
88  CSBMLExporter();
89 
90  /**
91  * Destruktor
92  */
94 
95  SBMLDocument* getSBMLDocument() {return this->mpSBMLDocument;};
96 
97  /**
98  * Export the model to SBML.
99  * The SBML model is returned as a string. In case of an error, an
100  * empty string is returned.
101  */
102  const std::string exportModelToString(CCopasiDataModel& dataModel, unsigned int sbmlLevel, unsigned int sbmlVersion);
103 
104  /**
105  * Export the model to SBML.
106  * The model is written to the file given by filename.
107  * If the export fails, false is returned.
108  */
109  bool exportModel(CCopasiDataModel& dataModel, const std::string& filename, unsigned int sbmlLevel = 2, unsigned int sbmlVersion = 1, bool overwrite = false);
110 
111  /**
112  * Checks wether the given data model can be exported to a certain version of SBML.
113  * If it can be exported, the result vector will be empty, otherwise it will
114  * contain a number of messages that specify why it can't be exported.
115  */
116  static const std::vector<SBMLIncompatibility> isModelSBMLCompatible(const CCopasiDataModel& pDataModel, int sbmlLevel, int sbmlVersion);
117 
118  /**
119  * This method assures that the SBMLDocument is not deleted by the destructor of the exporter.
120  * This allows us to get the SBMLDocument from the exporter and store it in the data model without having to copy it.
121  */
122  void disownSBMLDocument();
123 
124  /**
125  * Returns a const pointer to the COPASI2SBMLMap.
126  */
127  const std::map<const CCopasiObject*, SBase*>& getCOPASI2SBMLMap() const;
128 
129  /**
130  * Returns whether the exporter is supposed to export COPASIs MIRIAM
131  * annotation in addition to SBML MIRIAM.
132  */
133  bool isSetExportCOPASIMIRIAM() const;
134 
135  /**
136  * Sets whether the exporter is supposed to export COPASIs MIRIAM
137  * annotation in addition to SBML MIRIAM.
138  */
139  void setExportCOPASIMIRIAM(bool exportMIRIAM);
140 
141  /**
142  * Create a unique id for an SBML object.
143  * I can't just take the Copasi key of the object since this might conflict
144  * with an already existing sbml id which came from the sbmlid attribute in a
145  * copasi file or directly by importing an SBML file.
146  */
147  static const std::string createUniqueId(const std::map<std::string, const SBase*>& idMap,
148  const std::string& prefix,
149  bool addIndexForFirst,
150  const std::string & separator = "_");
151 
152 #if LIBSBML_VERSION >= 40001
153  /**
154  * Method to create a valid XHTML node from a CModels comments string.
155  * This method is declared public so that I can call it from the unit tests.
156  */
157  static XMLNode* createSBMLNotes(const std::string& notes_string);
158 #endif // LIBSBML_VERSION
159 
160 protected:
161 
162  /**
163  * Creates the units for the SBML model.
164  */
165  void createUnits(const CCopasiDataModel& dataModel);
166 
167  /**
168  * Creates the time unit for the SBML model.
169  */
170  void createTimeUnit(const CCopasiDataModel& dataModel);
171 
172  /**
173  * Creates the volume unit for the SBML model.
174  */
175  void createLengthUnit(const CCopasiDataModel& dataModel);
176 
177  /**
178  * Creates the volume unit for the SBML model.
179  */
180  void createAreaUnit(const CCopasiDataModel& dataModel);
181 
182  /**
183  * Creates the volume unit for the SBML model.
184  */
185  void createVolumeUnit(const CCopasiDataModel& dataModel);
186 
187  /**
188  * Creates the substance unit for the SBML model.
189  */
190  void createSubstanceUnit(const CCopasiDataModel& dataModel);
191 
192  /**
193  * Creates the compartments for the model.
194  */
195  void createCompartments(CCopasiDataModel& dataModel);
196 
197  /**
198  * Creates the compartment for the given COPASI compartment.
199  */
200  void createCompartment(CCompartment& compartment);
201 
202  /**
203  * Creates the compartments for the model.
204  */
205  void createMetabolites(CCopasiDataModel& dataModel);
206 
207  /**
208  * Creates the species for the given COPASI metabolite.
209  */
210  void createMetabolite(CMetab& metab);
211 
212  /**
213  * Creates the parameters for the model.
214  */
215  void createParameters(CCopasiDataModel& dataModel);
216 
217  /**
218  * Creates the parameter for the given COPASI parameter.
219  */
220  void createParameter(CModelValue& parameter);
221 
222  /**
223  * Creates the reactions for the model.
224  */
225  void createReactions(CCopasiDataModel& dataModel);
226 
227  /**
228  * Creates the reaction for the given COPASI reaction.
229  */
230  void createReaction(CReaction& reaction, CCopasiDataModel& dataModel);
231 
232  /**
233  * Creates the initial assignments for the model.
234  */
236 
237  /**
238  * Creates the initial assignment for the given COPASI model entity.
239  */
240  void createInitialAssignment(const CModelEntity& modelEntity, CCopasiDataModel& dataModel);
241 
242  /**
243  * Creates the rules for the model.
244  */
245  void createRules(CCopasiDataModel& dataModel);
246 
247  /**
248  * Creates the rule for the given COPASI model entity.
249  */
250  void createRule(const CModelEntity& modelEntity, CCopasiDataModel& dataModel, Rule* pOldRule);
251 
252  /**
253  * Create all function definitions.
254  */
256 
257  /**
258  * Create the SBML function definition from the given COPASI function.
259  */
260  void createFunctionDefinition(CFunction& function, CCopasiDataModel& dataModel);
261 
262  /**
263  * Checks all assignments (initial and transient) for references to objects
264  * that can not be exported to SBML.
265  */
266  void checkForUnsupportedObjectReferences(const CCopasiDataModel& dataModel, unsigned int sbmlLevel, unsigned int sbmlVersion, std::vector<SBMLIncompatibility>& result);
267  /**
268  * Checks the given expression for references to objects
269  * that can not be exported to SBML.
270  */
271  static void checkForUnsupportedObjectReferences(const CEvaluationTree& expression, const CCopasiDataModel& dataModel, unsigned int sbmlLevel, unsigned int sbmlVersion, std::vector<SBMLIncompatibility>& result, bool initialExpression = false, std::map<const std::string, Parameter*>* initialMap = NULL);
272 
273  /**
274  * Checks all expressions in the given datamodel for piecewise defined
275  * functions.
276  */
277  static void checkForPiecewiseFunctions(const CCopasiDataModel& dataModel, std::vector<SBMLIncompatibility>& result);
278 
279  /**
280  * Checks the given node and all it's children for the occurence of
281  * piecewise functions.
282  */
283  static void checkForPiecewiseFunctions(const CEvaluationNode& node, std::vector<SBMLIncompatibility>& result, const std::string& objectName, const std::string& objectType);
284 
285  /**
286  * Checks wether the given data model can be exported to SBML Level1
287  * If it can be exported, the result vector will be empty, otherwise it will
288  * contain a number of messages that specify why it can't be exported.
289  */
290  static void isModelSBMLL1Compatible(const CCopasiDataModel& dataModel, std::vector<SBMLIncompatibility>& result);
291 
292  /**
293  * Checks wether the given data model can be exported to SBML Level2 Version1.
294  * If it can be exported, the result vector will be empty, otherwise it will
295  * contain a number of messages that specify why it can't be exported.
296  */
297  static void isModelSBMLL2V1Compatible(const CCopasiDataModel& dataModel, std::vector<SBMLIncompatibility>& result);
298 
299  /**
300  * Checks wether the given data model can be exported to SBML Level2 Version3.
301  * If it can be exported, the result vector will be empty, otherwise it will
302  * contain a number of messages that specify why it can't be exported.
303  */
304  static void isModelSBMLL2V3Compatible(const CCopasiDataModel& dataModel, std::vector<SBMLIncompatibility>& result);
305 
306  /**
307  * Go through all species in the model and check if the corresponding species
308  * in the SBML model has the spatialSizeUnits attribute set.
309  * This attribute is not supported in SBML L2V3 and above, so we have to get
310  * rid of this attribute when we export to a level equal to or higher than
311  * L2V3.
312  * If the attribute has the same value as the compartments units, we can just
313  * delete it without changing the model, otherwise we have to give a
314  * corresponding warning.
315  */
316  static void check_for_spatial_size_units(const CCopasiDataModel& dataModel, std::vector<SBMLIncompatibility>& result);
317 
318  /**
319  * Checks wether the model contains a metabolite that is defined by an ODE
320  * expression and that is located in a variable volume. Since COPASI
321  * interprets the expression differntly from SBML, we can not correctly
322  * export this yet. See Bug 903.
323  */
324  static void checkForODESpeciesInNonfixedCompartment(const CCopasiDataModel& dataModel, std::vector<SBMLIncompatibility> result);
325 
326  /**
327  * Checks wether the rule in the given model entity can be exported to
328  * the specified version of SBML.
329  * If it can be exported, the result vector will be empty, otherwise it will
330  * contain a number of messages that specify why it can't be exported.
331  */
332  static void isExpressionSBMLCompatible(const CEvaluationTree& expr, const CCopasiDataModel& dataModel, int sbmlLevel, int sbmlVersion, std::vector<SBMLIncompatibility>& result,
333  const std::string& objectDescription, bool initialExression = false, std::map<const std::string, Parameter*>* initialMap = NULL);
334 
335  /**
336  * Checks wether the rule in the given model entity can be exported to SBML Level2 Version1.
337  * If it can be exported, the result vector will be empty, otherwise it will
338  * contain a number of messages that specify why it can't be exported.
339  */
340  static void isExpressionSBMLL1Compatible(const CEvaluationTree& expr, const CCopasiDataModel& dataModel, std::vector<SBMLIncompatibility>& result);
341 
342  /**
343  * Checks wether the rule in the given model entity can be exported to SBML Level2 Version1.
344  * If it can be exported, the result vector will be empty, otherwise it will
345  * contain a number of messages that specify why it can't be exported.
346  */
347  static void isExpressionSBMLL2V1Compatible(const CEvaluationTree& expr, const CCopasiDataModel& dataModel, std::vector<SBMLIncompatibility>& result);
348 
349  /**
350  * Checks wether the rule in the given model entity can be exported to SBML Level2 Version3.
351  * If it can be exported, the result vector will be empty, otherwise it will
352  * contain a number of messages that specify why it can't be exported.
353  */
354  static void isExpressionSBMLL2V3Compatible(const CEvaluationTree& expression, const CCopasiDataModel& pDataModel, std::vector<SBMLIncompatibility>& result);
355 
356  /**
357  * This static methods checks, wether the model uses any function calls
358  * that can not be expressed in SBML like the random distribution
359  * functions.
360  */
362  unsigned int sbmlLEvel, unsigned int sbmlVersion,
363  std::vector<SBMLIncompatibility>& result);
364 
365  /**
366  * This static methods checks recursively, whether the given CEvaluationNode constains any function calls
367  * that can not be expressed in SBML like the random distribution
368  * functions.
369  */
370  static void checkForUnsupportedFunctionCalls(const CEvaluationNode& node,
371  const std::set<CEvaluationNodeFunction::SubType>& unsupportedFunctions,
372  std::vector<SBMLIncompatibility>& result,
373  const std::string& objectDescription);
374 
375  /**
376  * This method checks wether the given model contains any initial assignments.
377  */
378  static void checkForInitialAssignments(const CCopasiDataModel& dataModel, std::vector<SBMLIncompatibility>& result);
379 
380  /**
381  * Goes through the given SBML model and puts all ids with the
382  * corresponding object into a map.
383  */
384  const std::map<std::string, const SBase*> createIdMap(const Model& sbmlModel);
385 
386  /**
387  * Create the kinetic law for the given reaction.
388  * On failure NULL is returned.
389  */
390  KineticLaw* createKineticLaw(CReaction& reaction, CCopasiDataModel& dataModel, unsigned int level, unsigned int version);
391 
392  /**
393  * Go through a CEvaluationNode base tree and add the names
394  * of all functions directly called in this tree to the set.
395  */
396  static void findDirectlyUsedFunctions(const CEvaluationNode* pRootNode, std::set<std::string>& result);
397 
398  /**
399  * checks if the given ASTNode based tree is divided by the
400  * volume of the compartment identified by the given id string.
401  */
402  static ASTNode* isDividedByVolume(const ASTNode* pRootNode, const std::string& compartmentId);
403 
404  /**
405  * Creates an expression from a given node and a set of parameter
406  * mappings by
407  * replacing the function arguments with the parameters.
408  static CEvaluationNode* createExpressionTree(const CEvaluationNode* const pNode,
409  const std::map<std::string, std::string>& parameterMap,
410  const CCopasiDataModel& dataModel);
411  */
412 
413  /**
414  * Creates an expression from a given function and a set of parameters by
415  * replacing the function arguments with the parameters.
416  static CEvaluationNode* createExpressionTree(const CFunction* const pFun,
417  const std::vector<std::vector<std::string> >& arguments,
418  const CCopasiDataModel& dataModel);
419  */
420 
421  /**
422  * Create an expression that corresponds to a kinetic law.
423  * If the kinetic law was mass action, the expression is a mass action term
424  * , otherwise it is a function call.
425  */
426  CEvaluationNode* createKineticExpression(CFunction* pFun, const std::vector<std::vector<std::string> >& arguments);
427 
428  /**
429  * Checks if the given datamodel contains events.
430  * This is called if SBML Level 1 is to be exported.
431  */
432  static void checkForEvents(const CCopasiDataModel& dataModel, std::vector<SBMLIncompatibility>& result);
433 
434  /**
435  * Creates an SBMLDocument from the given CCopasiDataModelObject.
436  * It checks if an SBMLDocument already exists from an import and if
437  * this is the case, the old document is copied.
438  * If none exists a new one is created.
439  * Copying the old one makes sure that if something goes wrong during
440  * export, the original model is still consistent.
441  */
442  void createSBMLDocument(CCopasiDataModel& dataModel);
443 
444  /**
445  * Sorts the rules.
446  */
447  std::vector<CModelEntity*> orderRules(const CCopasiDataModel& dataModel);
448 
449  /**
450  * Creates a new COPASI2SBMLMap baed on the old map and the copied
451  * SBMLDocument.
452  */
453  void updateCOPASI2SBMLMap(const CCopasiDataModel& dataModel);
454 
455  /**
456  * Creates the events for the given data model.
457  */
458  void createEvents(CCopasiDataModel& dataModel);
459 
460  /**
461  * Creates an SBML Event for the given COPASI event.
462  */
463  void createEvent(CEvent& event, Event* pSBMLEvent, CCopasiDataModel& dataModel);
464 
465  /**
466  * This method creates the individual event assignments for the given
467  * event.
468  */
469  void exportEventAssignments(const CEvent& event, Event* pSBMLEvent, CCopasiDataModel& dataModel);
470 
471  /**
472  * This method checks if the given event assignment object is SBML
473  * compatible.
474  */
475  static void isEventAssignmentSBMLCompatible(std::string& key, const CExpression* pExpression, const CCopasiDataModel& dataModel, unsigned int sbmlLevel, unsigned int sbmlVersion, const std::string& eventName, std::vector<SBMLIncompatibility>& result);
476 
477  /**
478  * This method checks if the given event object is SBML
479  * compatible.
480  */
481  static void isEventSBMLCompatible(const CEvent* pEvent, const CCopasiDataModel& dataModel, unsigned int sbmlLevel, unsigned int sbmlVersion, std::vector<SBMLIncompatibility>& result);
482 
483  /**
484  * This method creates an ASTNode tree where all the species specified in
485  * the given vector are multiplied. This is used to create the mass action
486  * kinetic law.
487  */
488  static ASTNode* createTimesTree(const CCopasiVector<CChemEqElement >& vect, unsigned int pos = 0);
489 
490  /**
491  * Remove all compartments, species, parameters and reactions
492  * that did not end up in mHandledSBMLObjects during an export.
493  */
494  void removeUnusedObjects();
495 
496  /**
497  * Takes a set of functions and recursively finds functions used by those
498  * functions
499  */
500  static const std::vector<CFunction*> findUsedFunctions(std::set<CFunction*>& functions, CFunctionDB* pFunctionDB);
501 
502  static const std::set<CFunction*> createFunctionSetFromFunctionNames(const std::set<std::string>& names, CFunctionDB* pFunDB);
503 
504  /**
505  * This method takes care of expanding all function calls in all
506  * expressions and converting functions that are not supported in Level 1
507  * as well as constants that were not supported in Level 1
508  */
509  void convertToLevel1();
510 
511  /**
512  * Creates a set of all function subtypes that can not be exported for a
513  * certain SBML level.
514  */
515  static const std::set<CEvaluationNodeFunction::SubType> createUnsupportedFunctionTypeSet(unsigned int sbmlLevel);
516 
517  /**
518  * Find all ModelEntities for which the given node and its children contains
519  * references.
520  */
521  static void findModelEntityDependencies(const CEvaluationNode* pNode, const CCopasiDataModel& dataModel, std::set<const CModelEntity*>& dependencies);
522 
523  /**
524  * Creates an ASTNode based tree where all occurences of nodes that are not
525  * supported in SBML Level 1 are replaced by supported constructs.
526  * On error an exception is created.
527  * The caller is responsible for freeing the memory of the returned object.
528  */
529  static ASTNode* convertASTTreeToLevel1(const ASTNode* pNode, const ListOfFunctionDefinitions& functions, std::string& message);
530 
531  /**
532  * This method goes through the ASTNode based tree rooted at pNode and
533  * replaces all unsupported nodes with constructs supported by SBML Level 1
534  * The caller is responsible for freeing the memory of the returned object.
535  */
536  static ASTNode* replaceL1IncompatibleNodes(const ASTNode* pNode);
537 
538  /**
539  * This method creates the CEvaluationNode based tree for a reversible or
540  * irreversible Mass Action call.
541  * The first parameter contains the arguments from the COPASI reaction.
542  * The second argument determines whether it is reversible or irreversible
543  * mass action.
544  */
545  static CEvaluationNode* createMassActionExpression(const std::vector<std::vector<std::string> >& arguments, bool isReversible);
546 
547  /**
548  * Checks if the given string is a valid SId
549  */
550  static bool isValidSId(const std::string& id);
551 
552  /**
553  * Remove the initial assignment for the entity with the given id
554  * if there is any.
555  */
556  void removeInitialAssignment(const std::string& sbmlId);
557 
558  /**
559  * Remove the rule for the entity with the given id
560  * if there is any.
561  */
562  void removeRule(const std::string& sbmlId);
563 
564  /**
565  * Replaces references to species with reference to species divided by
566  * volume if it is a reference to a concentration or by a reference to the
567  * species times avogadros number if it is a reference to the amount.
568  * The method also takes into consideration the substance units of the
569  * model.
570  */
571  CEvaluationNode* replaceSpeciesReferences(const CEvaluationNode* pOrigNode, const CCopasiDataModel& dataModel);
572 
573  /**
574  * Try to find a global parameter that represents avogadros number.
575  */
576  void findAvogadro(const CCopasiDataModel& dataModel);
577 
578  /**
579  * This method gets the MIRIAM annotation from the given COPASI object and
580  * sets it on the given SBML object.
581  */
582  bool updateMIRIAMAnnotation(const CCopasiObject* pCOPASIObject, SBase* pSBMLObject, std::map<std::string, const SBase*>& metaIds);
583 
584  /**
585  * This is a general method to set the notes of an SBase object based on a COPASI
586  * Annotation.
587  * This will allow us to export notes on objects other than just the model.
588  */
589  static bool setSBMLNotes(SBase* pSBase, const CAnnotation* pAnno);
590 
591  /**
592  * This method creates a copy of parent where the child with the given index is
593  * replaced by the new child given as the second argument.
594  * If index is greater than the number of children - 1, NULL is returned.
595  */
596  XMLNode* replaceChild(const XMLNode* pParent, const XMLNode* pNewChild, unsigned int index);
597 
598  /**
599  * This method goes through the given datamodel and collects all SBML ids.
600  */
601  void collectIds(const CCopasiDataModel& dataModel, std::map<std::string, const SBase*>& idMap);
602 
603  /**
604  * This converts an CEvaluationNode based tree to an ASTNode tree.
605  * It makes sure that all functions used in function calls already have a
606  * unique SBML id.
607  */
608  ASTNode* convertToASTNode(const CEvaluationNode* pOrig, CCopasiDataModel& dataModel);
609 
610  /**
611  * This method traverse a CEvaluationTree and set the SBML id on all
612  * functions that are used in function calls in the tree.
613  */
614  void setFunctionSBMLIds(const CEvaluationNode* pNode, CCopasiDataModel& dataModel);
615 
616  /**
617  * Creates error messages from the list of incompatibilities and thows an
618  * exception.
619  */
620  void outputIncompatibilities() const;
621 
622  /**
623  * Goes through the expression tree and tries to find occurences of local
624  * parameters. If one is found, a global parameter is created and all
625  * references to the local parameters are substituted.
626  */
627  void replace_local_parameters(ASTNode* pOrigNode, const CCopasiDataModel& dataModel);
628 
629  /**
630  * This method goes through the expression tree and tries to find node
631  * names that correspond to common names of local parameters.
632  * If the common name also occurs in the replacement map, the node name has
633  * to be set to the id of the corresponding global parameter, otherwise the name
634  * has to be set to the object name of the parameter.
635  */
636  void restore_local_parameters(ASTNode* pOrigNode, const CCopasiDataModel& dataModel);
637 
638  /**
639  * Since we want to replace local reaction parameters by global parameters if they are used in an assignment,
640  * we have to create the reactions after creating the rules and events. On the other hand, a reaction flux
641  * might also be referenced in an assignment or an event and the creation of this rule or event only works
642  * if the reactions already have SBML ids.
643  * To solve this problem, the reactions have to be assigned SBML ids prior to creating rules and events.
644  * This is what this method does.
645  */
646  void assignSBMLIdsToReactions(CModel* pModel);
647 
648  /**
649  * This method goes through all compartments and events and checks if
650  * there is an assignment to a volume.
651  */
652  bool hasVolumeAssignment(const CCopasiDataModel& dataModel);
653 
654  /**
655  * This method multiplies a given expression by the given object.
656  * The caller is responsible for freeing the memory for the new expression.
657  */
658  static CEvaluationNode* multiplyByObject(const CEvaluationNode* pOrigNode, const CCopasiObject* pObject);
659 
660  /**
661  * Converts the SBML model given in SBML Level 1 Version 2 format to SBML Level 1 Version 1.
662  * The method basically removes the namespace attribute on the sbml element
663  * and changes the version from 2 to 1.
664  * It also renames all "species" elements to "specie".
665  * All other changes between SBML Level 1 Version 2 and Level 1 Version 1 should not be relevant here.
666  */
667  static void convert_to_l1v1(std::string& l1v2_string);
668 };
669 
670 #endif // CSBLExporter_H__
std::vector< CModelEntity * > orderRules(const CCopasiDataModel &dataModel)
Definition: CEvent.h:152
static const std::vector< CFunction * > findUsedFunctions(std::set< CFunction * > &functions, CFunctionDB *pFunctionDB)
void updateCOPASI2SBMLMap(const CCopasiDataModel &dataModel)
void createReaction(CReaction &reaction, CCopasiDataModel &dataModel)
bool mExportCOPASIMIRIAM
Definition: CSBMLExporter.h:74
void createVolumeUnit(const CCopasiDataModel &dataModel)
static void findDirectlyUsedFunctions(const CEvaluationNode *pRootNode, std::set< std::string > &result)
unsigned int mSBMLLevel
Definition: CSBMLExporter.h:56
void createRules(CCopasiDataModel &dataModel)
static ASTNode * replaceL1IncompatibleNodes(const ASTNode *pNode)
static void isExpressionSBMLL2V3Compatible(const CEvaluationTree &expression, const CCopasiDataModel &pDataModel, std::vector< SBMLIncompatibility > &result)
SBMLDocument * mpSBMLDocument
Definition: CSBMLExporter.h:55
objectType
void replace_local_parameters(ASTNode *pOrigNode, const CCopasiDataModel &dataModel)
ListOfFunctionDefinitions mExportedFunctions
Definition: CSBMLExporter.h:77
static void isEventAssignmentSBMLCompatible(std::string &key, const CExpression *pExpression, const CCopasiDataModel &dataModel, unsigned int sbmlLevel, unsigned int sbmlVersion, const std::string &eventName, std::vector< SBMLIncompatibility > &result)
void createInitialAssignment(const CModelEntity &modelEntity, CCopasiDataModel &dataModel)
static CEvaluationNode * multiplyByObject(const CEvaluationNode *pOrigNode, const CCopasiObject *pObject)
bool hasVolumeAssignment(const CCopasiDataModel &dataModel)
std::map< std::string, Parameter * > mParameterReplacementMap
Definition: CSBMLExporter.h:75
void createCompartment(CCompartment &compartment)
void createFunctionDefinitions(CCopasiDataModel &dataModel)
std::map< std::string, const CEvaluationTree * > mFunctionIdMap
Definition: CSBMLExporter.h:72
void createFunctionDefinition(CFunction &function, CCopasiDataModel &dataModel)
static void findModelEntityDependencies(const CEvaluationNode *pNode, const CCopasiDataModel &dataModel, std::set< const CModelEntity * > &dependencies)
void createMetabolite(CMetab &metab)
void collectIds(const CCopasiDataModel &dataModel, std::map< std::string, const SBase * > &idMap)
void createReactions(CCopasiDataModel &dataModel)
static const std::vector< SBMLIncompatibility > isModelSBMLCompatible(const CCopasiDataModel &pDataModel, int sbmlLevel, int sbmlVersion)
void createMetabolites(CCopasiDataModel &dataModel)
void createSBMLDocument(CCopasiDataModel &dataModel)
bool isSetExportCOPASIMIRIAM() const
bool mDocumentDisowned
Definition: CSBMLExporter.h:73
void createAreaUnit(const CCopasiDataModel &dataModel)
static void checkForODESpeciesInNonfixedCompartment(const CCopasiDataModel &dataModel, std::vector< SBMLIncompatibility > result)
std::vector< CModelEntity * > mAssignmentVector
Definition: CSBMLExporter.h:58
bool mIncompleteExport
Definition: CSBMLExporter.h:66
Definition: CMetab.h:178
std::map< std::string, const SBase * > mIdMap
Definition: CSBMLExporter.h:64
void createTimeUnit(const CCopasiDataModel &dataModel)
bool mAvogadroCreated
Definition: CSBMLExporter.h:69
SBMLDocument * getSBMLDocument()
Definition: CSBMLExporter.h:95
std::map< const std::string, Parameter * > mInitialValueMap
Definition: CSBMLExporter.h:79
static bool setSBMLNotes(SBase *pSBase, const CAnnotation *pAnno)
static const std::string createUniqueId(const std::map< std::string, const SBase * > &idMap, const std::string &prefix, bool addIndexForFirst, const std::string &separator="_")
std::set< std::string > mSpatialSizeUnitsSpecies
Definition: CSBMLExporter.h:76
XMLNode * replaceChild(const XMLNode *pParent, const XMLNode *pNewChild, unsigned int index)
bool mHaveModelHistoryModificationDateWarning
Definition: CSBMLExporter.h:82
void checkForUnsupportedFunctionCalls(const CCopasiDataModel &dataModel, unsigned int sbmlLEvel, unsigned int sbmlVersion, std::vector< SBMLIncompatibility > &result)
void setExportCOPASIMIRIAM(bool exportMIRIAM)
static void checkForPiecewiseFunctions(const CCopasiDataModel &dataModel, std::vector< SBMLIncompatibility > &result)
static ASTNode * createTimesTree(const CCopasiVector< CChemEqElement > &vect, unsigned int pos=0)
std::map< const FunctionDefinition *, const CCopasiObject * > mFunctionMap
Definition: CSBMLExporter.h:78
void createCompartments(CCopasiDataModel &dataModel)
std::vector< CModelEntity * > mODEVector
Definition: CSBMLExporter.h:59
static bool isValidSId(const std::string &id)
unsigned int mSBMLVersion
Definition: CSBMLExporter.h:57
static ASTNode * isDividedByVolume(const ASTNode *pRootNode, const std::string &compartmentId)
static const std::set< CEvaluationNodeFunction::SubType > createUnsupportedFunctionTypeSet(unsigned int sbmlLevel)
static void isEventSBMLCompatible(const CEvent *pEvent, const CCopasiDataModel &dataModel, unsigned int sbmlLevel, unsigned int sbmlVersion, std::vector< SBMLIncompatibility > &result)
void assignSBMLIdsToReactions(CModel *pModel)
void exportEventAssignments(const CEvent &event, Event *pSBMLEvent, CCopasiDataModel &dataModel)
bool mHaveModelHistoryCreationDateWarning
Definition: CSBMLExporter.h:81
static void checkForEvents(const CCopasiDataModel &dataModel, std::vector< SBMLIncompatibility > &result)
void removeInitialAssignment(const std::string &sbmlId)
static void check_for_spatial_size_units(const CCopasiDataModel &dataModel, std::vector< SBMLIncompatibility > &result)
void createRule(const CModelEntity &modelEntity, CCopasiDataModel &dataModel, Rule *pOldRule)
void createParameters(CCopasiDataModel &dataModel)
std::map< std::string, const SBase * > mMetaIdMap
Definition: CSBMLExporter.h:70
const std::string exportModelToString(CCopasiDataModel &dataModel, unsigned int sbmlLevel, unsigned int sbmlVersion)
std::vector< SBMLIncompatibility > mIncompatibilities
Definition: CSBMLExporter.h:65
void createParameter(CModelValue &parameter)
std::map< const CCopasiObject *, SBase * > mCOPASI2SBMLMap
Definition: CSBMLExporter.h:61
void createEvents(CCopasiDataModel &dataModel)
bool mHaveModelHistoryAuthorWarning
Definition: CSBMLExporter.h:80
const CModelValue * mpAvogadro
Definition: CSBMLExporter.h:68
ASTNode * convertToASTNode(const CEvaluationNode *pOrig, CCopasiDataModel &dataModel)
static void isExpressionSBMLCompatible(const CEvaluationTree &expr, const CCopasiDataModel &dataModel, int sbmlLevel, int sbmlVersion, std::vector< SBMLIncompatibility > &result, const std::string &objectDescription, bool initialExression=false, std::map< const std::string, Parameter * > *initialMap=NULL)
static void convert_to_l1v1(std::string &l1v2_string)
void restore_local_parameters(ASTNode *pOrigNode, const CCopasiDataModel &dataModel)
CEvaluationNode * replaceSpeciesReferences(const CEvaluationNode *pOrigNode, const CCopasiDataModel &dataModel)
KineticLaw * createKineticLaw(CReaction &reaction, CCopasiDataModel &dataModel, unsigned int level, unsigned int version)
CEvaluationNode * createKineticExpression(CFunction *pFun, const std::vector< std::vector< std::string > > &arguments)
void outputIncompatibilities() const
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
void createInitialAssignments(CCopasiDataModel &dataModel)
bool updateMIRIAMAnnotation(const CCopasiObject *pCOPASIObject, SBase *pSBMLObject, std::map< std::string, const SBase * > &metaIds)
std::set< SBase * > mHandledSBMLObjects
Definition: CSBMLExporter.h:62
void createLengthUnit(const CCopasiDataModel &dataModel)
static void isModelSBMLL1Compatible(const CCopasiDataModel &dataModel, std::vector< SBMLIncompatibility > &result)
Definition: CModel.h:50
static const std::set< CFunction * > createFunctionSetFromFunctionNames(const std::set< std::string > &names, CFunctionDB *pFunDB)
void disownSBMLDocument()
static CEvaluationNode * createMassActionExpression(const std::vector< std::vector< std::string > > &arguments, bool isReversible)
void findAvogadro(const CCopasiDataModel &dataModel)
static void isModelSBMLL2V3Compatible(const CCopasiDataModel &dataModel, std::vector< SBMLIncompatibility > &result)
void removeUnusedObjects()
static void checkForInitialAssignments(const CCopasiDataModel &dataModel, std::vector< SBMLIncompatibility > &result)
bool mVariableVolumes
Definition: CSBMLExporter.h:67
static void isExpressionSBMLL1Compatible(const CEvaluationTree &expr, const CCopasiDataModel &dataModel, std::vector< SBMLIncompatibility > &result)
void createSubstanceUnit(const CCopasiDataModel &dataModel)
void createEvent(CEvent &event, Event *pSBMLEvent, CCopasiDataModel &dataModel)
std::set< CFunction * > mUsedFunctions
Definition: CSBMLExporter.h:63
void removeRule(const std::string &sbmlId)
void createUnits(const CCopasiDataModel &dataModel)
const std::map< const CCopasiObject *, SBase * > & getCOPASI2SBMLMap() const
static void isExpressionSBMLL2V1Compatible(const CEvaluationTree &expr, const CCopasiDataModel &dataModel, std::vector< SBMLIncompatibility > &result)
static ASTNode * convertASTTreeToLevel1(const ASTNode *pNode, const ListOfFunctionDefinitions &functions, std::string &message)
bool exportModel(CCopasiDataModel &dataModel, const std::string &filename, unsigned int sbmlLevel=2, unsigned int sbmlVersion=1, bool overwrite=false)
void checkForUnsupportedObjectReferences(const CCopasiDataModel &dataModel, unsigned int sbmlLevel, unsigned int sbmlVersion, std::vector< SBMLIncompatibility > &result)
const std::map< std::string, const SBase * > createIdMap(const Model &sbmlModel)
static void isModelSBMLL2V1Compatible(const CCopasiDataModel &dataModel, std::vector< SBMLIncompatibility > &result)
void setFunctionSBMLIds(const CEvaluationNode *pNode, CCopasiDataModel &dataModel)
std::vector< CModelEntity * > mInitialAssignmentVector
Definition: CSBMLExporter.h:60