roadrunner  2.6.0
Fast simulator for SBML models
rrNOMSupport.h
1 #ifndef rrNOMSupportH
2 #define rrNOMSupportH
3 //---------------------------------------------------------------------------
4 #include <list>
5 #include <vector>
6 #include <deque>
7 #include <string>
8 #include <stack>
9 #include <tr1proxy/rr_memory.h>
10 #include "sbml/math/ASTNode.h"
11 #include "rrExporter.h"
12 #include "rrStringListContainer.h"
13 #include "rrHashTable.h"
14 //---------------------------------------------------------------------------
15 
16 namespace rr
17 {
18 using std::vector;
19 using std::string;
20 using std::pair;
21 using std::list;
22 using std::stack;
23 using std::deque;
24 
25 // You HAVE to define LIBSBML_USE_CPP_NAMESPACE for your project to compile this!
26 using libsbml::Model;
27 using libsbml::SBMLDocument;
28 using libsbml::ASTNode;
29 using libsbml::SBase;
30 using libsbml::Rule;
31 using libsbml::UnitDefinition;
32 using libsbml::KineticLaw;
33 
40 class RR_DECLSPEC NOMSupport
41 {
42 public:
43  NOMSupport();
44  ~NOMSupport();
45  Model* getModel();
46  SBMLDocument* getSBMLDocument();
47  static std::string getlibSBMLVersion();
48 
49  StringListContainer getDerivedUnitDefinition(const std::string& sId);
50  StringListContainer getListOfBoundarySpeciesIds();
51  StringListContainer getListOfErrors();
52  StringListContainer getListOfFloatingSpecies();
53  StringListContainer getListOfFloatingSpeciesIds();
54  StringListContainer getListOfParameters();
55  StringListContainer getNthError(const int& nIndex);
56  StringListContainer getNthEvent(const int& arg);
57  StringListContainer getNthFunctionDefinition(const int& arg);
58  StringListContainer getNthListOfModifiers(const int& nIndex);
59  StringListContainer getNthListOfProducts(const int& nIndex);
60  StringListContainer getNthListOfReactants(const int& nIndex);
61  ASTNode replaceSymbol(ASTNode* node, const std::string& oldId, const std::string& newId);
62  bool exists(const std::string& sId);
63  bool getNthParameterHasValue(const int& nReactionIndex, const int& nParameterIndex);
64  bool getNthUseValuesFromTriggerTime(const int& arg);
65  bool hasInitialAmount(const std::string& sId);
66  bool hasInitialConcentration(const std::string& sId);
67  bool hasSBOTerm(const std::string& sId);
68  bool hasValue(const std::string& sId);
69 
75  bool isBoundary(const std::string& sId);
76 
83  bool isCompartment(const std::string& sId);
84  bool isConstantImpl(const std::string& sId);
85  bool isFloating(const std::string& sId);
86  bool isReactionReversible(const int& nIndex);
87  bool isSpecies (const std::string& sId);
88  bool multiplyCompartment(const std::string& sbmlId, std::string& compartmentId);
89  bool needEmptySetNode(Model model);
90  bool needSinkNode(Model model);
91  bool needSourceNode(Model model);
92  double getNthParameterValue(const int& nReactionIndex, const int& nParameterIndex);
93  double getNthProductStoichiometryDouble(const int& nIndex, const int& nProduct);
94  double getNthReactantStoichiometryDouble(const int& nIndex, const int& nReactant);
95  double getValue(const std::string& sId);
96  int checkConsistency();
97  int getNthProductStoichiometry(const int& nIndex, const int& nProduct);
98  int getNthReactantStoichiometry(const int& nIndex, const int& nReactant);
99  int getNumBoundarySpecies();
100  int getNumCompartments();
101  int getNumConstraints();
102  int getNumErrors();
103  int getNumEvents();
104  int getNumFloatingSpecies();
105  int getNumFunctionDefinitions();
106  int getNumGlobalParameters();
107  int getNumInitialAssignments();
108 
113  int getNumParameters(int reaction);
114 
115  int getNumProducts(const int& var0);
116  int getNumReactants(const int& var0);
117 
121  int getNumReactions();
122 
123  int getNumRules();
124  int getSBOTerm(const std::string& sId);
125  std::pair<std::string, std::string> getNthInitialAssignmentPair(const int& nIndex);
126  SBase* getElement(const std::string& sId);
127 
128  std::string addEmptySetNode(const std::string& sbml);
129  std::string addEmptySetNodes(const std::string& sbml);
130  std::string addMissingModifiers(const std::string& sModel);
131  std::string addSourceSinkNodes(const std::string& sbml);
132  std::string convertLevel1ToLevel2Impl(const std::string& sSBML);
133  std::string convertLevel2ToLevel1Impl(const std::string& sSBML);
134 
135  std::string convertPowImpl(const std::string& sSBML);
136  std::string convertSBML(const std::string& sModel, const int& nLevel, const int& nVersion);
137  std::string convertSBML(const std::string& sModel, const int& nLevel, const int& nVersion, bool throwError);
138  std::string convertTimeToCSymbol(const std::string& sArg, const std::string& sTimeSymbol);
139  std::string fixCommonIssues(const std::string& sbml);
140  std::string fixCommonIssues(const std::string& sbml, const std::string& programName, const std::string& programVersion);
141  std::string fetAnnotatedModel(const std::string& targetSBML, const std::string& sourceSBML, bool checkModelId);
142 
143  std::string getAnnotation(const std::string& sId);
144  std::string getCompartmentIdBySpeciesId(const std::string& sId);
149  std::string getKineticLaw(const int& index);
150  std::string getMetaId(const std::string& sId);
151  std::string getModelId();
152  std::string getModelName() const;
153  std::string getNotes(const std::string& sId);
154  std::string getNthBoundarySpeciesId(const int& nIndex);
155  std::string getNthBoundarySpeciesName(const int& nIndex);
156  std::string getNthCompartmentId(const int& nIndex);
157  std::string getNthCompartmentName(const int& nIndex);
158  std::string getNthConstraint(const int& nIndex, std::string& sMessage);
159  std::string getNthFloatingSpeciesId(const int& nIndex);
160  std::string getNthFloatingSpeciesName(const int& nIndex);
161  std::string getNthGlobalParameterId(const int& nIndex);
162  std::string getNthGlobalParameterName(const int& nIndex);
163  std::string getNthInitialAssignment(const int& nIndex);
164  std::string getNthParameterId(const int& nReactionIndex, const int& nParameterIndex);
165  std::string getNthParameterName(const int& nReactionIndex, const int& nParameterIndex);
166  std::string getNthProductName(const int& nIndex, const int& nProduct);
167  std::string getNthReactantName(const int& nIndex, const int& nReactant);
168  std::string getNthReactionId(const int& nIndex);
169  std::string getNthReactionName(const int& nIndex);
170  std::string getNthRule(const int& nIndex);
171  std::string getNthRuleType(const int& arg);
172  std::string getOutsideCompartment(const std::string& var0);
173 
174  std::string getSBML();
175  std::string getSBOCapableSBML(const std::string& sModel);
176  std::string removeJD1Layout(const std::string& sSBML);
177  std::string removeJD2Layout(const std::string& sSBML);
178  std::string removeLayoutInformation(const std::string& sSBML);
179  std::string validateSBML(const std::string& sModel);
180  std::string validateWithConsistency(const std::string& sModel);
181  std::vector<std::string> getBuiltinFunctionInfo(const std::string& var0);
182  std::vector<std::string> getBuiltinFunctions();
183  void changeConstantForRules(Model* model);
184 
185  void loadFromFile(const std::string& fileName);
186  void loadParameterPromotedSBML(const std::string& var0, const std::string& sTimeSymbol);
187  void loadSBML(const std::string& var0);
188  void loadSBML(const std::string& var0, const std::string& sTimeSymbol);
189 
190  void setAnnotation(const std::string& sId, const std::string& sAnnotation);
191  void setModelId(const std::string& sId);
192  void setNotes(const std::string& sId, const std::string& sNotes);
193  void setSBOTerm(const std::string& sId, const int& nSBOTerm);
194  void setValue(const std::string& sId, const double& dValue);
195  void setValue(Model* model, const std::string& id, const double& value, const bool& throwIfNotFound);
196  void testASTTime();
197 
198  std::string getNthBoundarySpeciesCompartmentName(const int& nIndex);
199 
215  std::string getNthFloatingSpeciesCompartmentName(int index);
216  StringListContainer getListOfBoundarySpecies();
217 
222  static std::string convertTime(const std::string& sArg, const std::string& sTimeSymbol);
223 
230  static StringList getSymbols(const ASTNode* math);
231 
235  stack<std::string> getMatchForSymbol(const std::string& sbmlId);
236 
246  static deque<Rule*> reorderAssignmentRules(deque<Rule*>& assignmentRules);
247 
248  static void fillStack(stack<std::string>& stack, SBMLSymbol& symbol);
249 
257  static void reorderRules(SBMLDocument& oc, Model& model);
258 
259  static std::string getParamPromotedSBML(const std::string& sArg);
260 
261  static std::string getId(SBase& element);
262  static std::string convertMathMLToString(const std::string& sMathML);
263 
264  static std::string convertStringToMathML(const std::string& var0);
265 
266 private:
267 
271  SBMLDocument *mSBMLDoc;
272 
277  Model *mModel;
278 
279  StringSymbolHashTable mSymbolTable;
280 
281  StringListContainer returnUnitDefinition(UnitDefinition oDefinition);
282 
283  ASTNode changeTimeToCSymbol(ASTNode* node, const std::string& name, const int& type);
284  bool addMissingModifiers(Model *oModel);
285  StringList getSymbols(const std::string& formula);
286 
287  std::string getInitialAssignmentFor(const std::string& sbmlId);
288 
289  std::string getRuleFor(const std::string& sbmlId);
290  void addDependenciesToList(const ASTNode* node, StringList& sResult);
291  void addMissingParameter(const std::string& parameterId, SBMLDocument *doc);
292  void buildSymbolTable();
293  void changeNameToCSymbol(Model* model, const std::string& name, const int& type);
294  void changePow(ASTNode* node);
295  void checkForMissingNames(ASTNode *node, StringListContainer results, StringListContainer symbols);
296  void lookForDependencies();
297  void removeSpatialSizeUnitsFromSpecies(SBMLDocument* doc);
298  void removeSubstanceUnitsFromKineticLaws(SBMLDocument* doc);
299  void removeTimeUnitsFromKineticLaws(SBMLDocument* doc);
300  void updateDependencies(const std::string& sbmlId);
301  void upgradeToL2V4IfNecessary(SBMLDocument* doc);
302 
306  void reset();
311  static std::string getName(const SBase* element);
312  static void modifyKineticLaws(SBMLDocument& oSBMLDoc, Model &oModel);
313  static void modifyKineticLawsForLocalParameters(KineticLaw& oLaw, const std::string& reactionId, Model &oModel);
314  static void modifyKineticLawsForReaction(KineticLaw& oLaw, const std::string& reactionId, Model &oModel);
315  static void changeSymbol(Model& oModel, const std::string& sTimeSymbol, const int& targetType);
316  static void changeTimeSymbol(Model& model, const std::string& timeSymbol);
317 
318  static void changeParameterName(ASTNode& node, const std::string& sParameterName, const std::string& sPrefix);
319  static void getSymbols(const ASTNode* node, StringList& list);
320 
324  static const std::string STR_DoubleFormat;
325 };
326 
333 std::string SBML_formulaToStdString(const ASTNode *tree);
334 
335 }//namespace rr
336 #endif
Methods to query various information from an SBML document.
Definition: rrNOMSupport.h:41
bool isBoundary(const std::string &sId)
Checks whether the element for the given SBML id is a boundary species.
Definition: rrSBMLSymbol.h:16
Definition: rrStringListContainer.h:18
Definition: rrStringList.h:19
Definition: rrHashTable.h:17
C_DECL_SPEC char *rrcCallConv getModelId(RRHandle handle)
Returns the id of currently loaded SBML model.
C_DECL_SPEC void rrcCallConv setModelId(RRHandle handle, char *id)
Sets the id of currently loaded SBML model.
C_DECL_SPEC char *rrcCallConv getModelName(RRHandle handle)
Returns the name of currently loaded SBML model.
C_DECL_SPEC char *rrcCallConv getKineticLaw(RRHandle handle, const char *rid)
Get the kinetic law for a existing reaction in the current model.
C_DECL_SPEC char *rrcCallConv getSBML(RRHandle handle)
Retrieve the SBML model that was last loaded into roadRunner.
C_DECL_SPEC bool rrcCallConv loadSBML(RRHandle handle, const char *sbml)
Load a model from an SBML string.
C_DECL_SPEC bool rrcCallConv reset(RRHandle handle)
Resets all variables of the model to their current initial values. Does not change the parameters.
C_DECL_SPEC bool rrcCallConv getValue(RRHandle handle, const char *symbolId, double *value)
Get the value for a given symbol, use getAvailableTimeCourseSymbols(void) for a list of symbols.
C_DECL_SPEC bool rrcCallConv setValue(RRHandle handle, const char *symbolId, const double value)
Set the value for a given symbol, use getAvailableTimeCourseSymbols(void) for a list of symbols.
C_DECL_SPEC char *rrcCallConv getlibSBMLVersion(RRHandle handle)
Retrieve the current version number of the libSBML library.
C_DECL_SPEC char *rrcCallConv getParamPromotedSBML(RRHandle handle, const char *sArg)
Promote any local parameters to global status.