roadrunner  2.6.0
Fast simulator for SBML models
LLVMModelDataSymbols.h
1 /*
2  * LLVMModelDataSymbols.h
3  *
4  * Created on: Jun 28, 2013
5  *
6  * Author: Andy Somogyi,
7  * email decode: V1 = "."; V2 = "@"; V3 = V1;
8  * andy V1 somogyi V2 gmail V3 com
9  */
10 
11 #ifndef LLVMModelDataSymbolsH
12 #define LLVMModelDataSymbolsH
13 
14 #include "LLVMModelData.h"
15 #include "rrExecutableModel.h"
16 
17 #include "tr1proxy/rr_memory.h"
18 #include "tr1proxy/rr_unordered_map.h"
19 
20 
21 #include <map>
22 #include <set>
23 #include <list>
24 
25 namespace libsbml
26 {
27  class Model;
28  class SimpleSpeciesReference;
29  class ASTNode;
30 }
31 
32 namespace rrllvm
33 {
34 
35 enum ModelDataFields {
36  Size = 0, // 0
37  Flags, // 1
38  Time, // 2
39  NumIndCompartments, // 3
40  NumIndFloatingSpecies, // 4
41  NumIndBoundarySpecies, // 5
42  NumIndGlobalParameters, // 6
43  NumRateRules, // 7
44  NumReactions, // 8
45 
46  NumInitCompartments, // 9
47  NumInitFloatingSpecies, // 10
48  NumInitBoundarySpecies, // 11
49  NumInitGlobalParameters, // 12
50 
51  Stoichiometry, // 13
52  RandomPtr, // 14
53  NumEvents, // 15
54  NumPiecewiseTriggers, // 16
55  StateVectorSize, // 17
56  StateVector, // 18
57  StateVectorRate, // 19
58  RateRuleRates, // 20
59  FloatingSpeciesAmountRates, // 21
60 
61  CompartmentVolumesAlias, // 22
62  InitCompartmentVolumesAlias, // 23
63  InitFloatingSpeciesAmountsAlias, // 24
64  BoundarySpeciesAmountsAlias, // 25
65  InitBoundarySpeciesAmountsAlias, // 26
66  GlobalParametersAlias, // 27
67  InitGlobalParametersAlias, // 28
68  ReactionRatesAlias, // 29
69 
70  RateRuleValuesAlias, // 30
71  FloatingSpeciesAmountsAlias, // 31
72 
73  CompartmentVolumes, // 32
74  InitCompartmentVolumes, // 33
75  InitFloatingSpeciesAmounts, // 34
76  BoundarySpeciesAmounts, // 35
77  InitBoundarySpeciesAmounts, // 36
78  GlobalParameters, // 37
79  InitGlobalParameters, // 38
80  ReactionRates, // 39
81  NotSafe_RateRuleValues, // 40
82  NotSafe_FloatingSpeciesAmounts, // 41
83 };
84 
85 enum EventAtributes
86 {
87  EventUseValuesFromTriggerTime = (0x1 << 0), // => 0x00000001
88  EventInitialValue = (0x1 << 1), // => 0x00000010
89  EventPersistent = (0x1 << 2) // => 0x00000100
90 };
91 
92 
93 
128 {
129 public:
130 
131  typedef std::map<std::string, uint> StringUIntMap;
132  typedef std::map<std::string, std::vector<uint> > StringUIntVectorMap;
133  typedef std::pair<std::string, uint> StringUIntPair;
134  typedef std::unordered_map<uint, uint> UIntUIntMap;
135 
136  enum SpeciesReferenceType
137  {
138  Reactant, Product, Modifier, MultiReactantProduct
139  };
140 
148  {
149  FLOATING_SPECIES,
150  BOUNDARY_SPECIES,
151  COMPARTMENT,
152  GLOBAL_PARAMETER,
153  REACTION,
154  EVENT,
155  STOICHIOMETRY,
156  INVALID_SYMBOL
157  };
158 
165  {
166  uint row;
167  uint column;
168  SpeciesReferenceType type;
169  std::string id;
170  };
171 
173 
174  LLVMModelDataSymbols(libsbml::Model const* model, unsigned options);
175 
176  LLVMModelDataSymbols(std::istream& in);
177 
178  virtual ~LLVMModelDataSymbols();
179 
180  const std::string& getModelName() const;
181 
182  int getCompartmentIndex(std::string const&) const;
183 
192  SymbolIndexType getSymbolIndex(const std::string& name, int& result) const;
193 
201  int getFloatingSpeciesIndex(std::string const& id, bool requireIndependent = true) const;
202 
208  int getBoundarySpeciesIndex(std::string const& id) const;
209 
213  size_t getIndependentBoundarySpeciesSize() const;
214 
223  size_t getIndependentFloatingSpeciesSize() const;
224 
229  int getGlobalParameterIndex(std::string const&) const;
230 
231  int getRateRuleIndex(std::string const&) const;
232 
233  size_t getRateRuleSize() const;
234 
238  std::string getRateRuleId(size_t indx) const;
239 
243  size_t getIndependentGlobalParameterSize() const;
244 
245  int getReactionIndex(std::string const&) const;
246  std::vector<std::string> getReactionIds() const;
247  size_t getReactionSize() const;
248 
249  int getStoichiometryIndex(std::string const&) const;
250  int getStoichiometryIndex(const std::string&, const std::string&) const;
251  std::vector<std::string> getStoichiometryIds() const;
252  size_t getStoichiometrySize() const;
253 
254 
255  std::vector<std::string> getGlobalParameterIds() const;
256 
260  bool isRateRuleGlobalParameter(uint gid) const;
261 
266  std::vector<std::string> getFloatingSpeciesIds() const;
267 
268 
272  std::string getFloatingSpeciesId(size_t indx) const;
273 
274 
278  std::string getBoundarySpeciesId(size_t indx) const;
279 
280 
284  std::string getCompartmentId(size_t indx) const;
285 
286 
290  std::string getGlobalParameterId(size_t indx) const;
291 
295  size_t getFloatingSpeciesSize() const;
296 
297  size_t getBoundarySpeciesSize() const;
298 
299  size_t getCompartmentsSize() const;
300 
301  size_t getGlobalParametersSize() const;
302 
303  std::vector<std::string> getCompartmentIds() const;
304 
308  size_t getIndependentCompartmentSize() const;
309 
310 
311  std::vector<std::string> getBoundarySpeciesIds() const;
312 
320  std::list<SpeciesReferenceInfo> getStoichiometryList() const;
321 
326  //void initAllocModelDataBuffers(LLVMModelData& m) const;
327 
328  void print() const;
329 
339  bool isIndependentElement(const std::string& id) const;
340 
341  bool hasRateRule(const std::string& id) const;
342 
343  bool hasAssignmentRule(const std::string& id) const;
344 
345  bool hasInitialAssignmentRule(const std::string& id) const;
346 
347  bool isIndependentFloatingSpecies(const std::string& id) const;
348 
349  bool isIndependentBoundarySpecies(const std::string& id) const;
350 
351  bool isBoundarySpecies(const std::string& id) const;
352 
353  bool isIndependentGlobalParameter(const std::string& id) const;
354 
355  bool isIndependentCompartment(const std::string& id) const;
356 
357  bool isNamedSpeciesReference(const std::string& id) const;
358 
359  const SpeciesReferenceInfo& getNamedSpeciesReferenceInfo(
360  const std::string& id);
361 
362 
363 
383  bool isConservedMoietySpecies(const std::string& symbol) const;
384 
394  bool isConservedMoietySpecies(uint id, uint &result) const;
395 
400  bool isConservedMoietyParameter(uint id) const;
401 
405  size_t getConservedMoietySize() const;
406 
410  int getDepSpeciesIndexForConservedMoietyId(std::string id) const;
411 
415  const std::vector<uint>& getIndSpeciesIndexForConservedMoietyId(std::string id) const;
416 
420  int getConservedMoietyGlobalParameterIndex(uint cmIndex) const;
421 
425  std::string getConservedMoietyId(size_t indx) const;
426 
430  int getConservedMoietyIndex(const std::string& name) const;
431 
435  bool isConservedMoietyAnalysis() const;
436 
437 private:
438 
442  std::set<std::string> conservedMoietySpeciesSet;
443 
447  std::vector<bool> conservedMoietyGlobalParameter;
448 
456  std::vector<uint> conservedMoietyGlobalParameterIndex;
457 
464  UIntUIntMap floatingSpeciesToConservedMoietyIdMap;
465 
466  // holds the conserved moiety id for each dependent species
467  StringUIntMap conservedMoietyDepSpecies;
468 
469  // holds the conserved moiety id for each independent species
470  StringUIntVectorMap conservedMoietyIndSpecies;
471 
472 
473  /* End Conserved Moiety Section ******************************************/
474 public:
475 
476  const std::vector<unsigned char>& getEventAttributes() const;
477 
481  static const char* getFieldName(ModelDataFields field);
482 
487  size_t getEventBufferSize(size_t eventId) const;
488 
492  const std::vector<uint>& getStoichRowIndx() const;
493 
497  const std::vector<uint>& getStoichColIndx() const;
498 
499 
500 
510  bool isIndependentInitFloatingSpecies(const std::string& symbol) const;
511 
520  bool isIndependentInitBoundarySpecies(const std::string& symbol) const;
521 
531  bool isIndependentInitElement(const std::string& symbol) const;
532 
533  bool isIndependentInitCompartment(const std::string& symbol) const;
534 
539  bool isIndependentInitGlobalParameter(const std::string& symbol) const;
540 
541 
546  bool isIndependentInitGlobalParameter(size_t id) const;
547 
553  int getFloatingSpeciesInitIndex(const std::string& symbol) const;
554 
560  int getBoundarySpeciesInitIndex(const std::string& symbol) const;
561 
567  int getCompartmentInitIndex(const std::string& symbol) const;
568 
572  int getCompartmentIndexForFloatingSpecies(size_t floatIndex) const;
573 
577  int getCompartmentIndexForBoundarySpecies(size_t floatIndex) const;
578 
584  int getGlobalParameterInitIndex(const std::string& symbol) const;
585 
586  size_t getInitCompartmentSize() const;
587  size_t getInitFloatingSpeciesSize() const;
588  size_t getInitBoundarySpeciesSize() const;
589  size_t getInitGlobalParameterSize() const;
590 
591  std::vector<std::string> getEventIds() const;
592 
593  std::vector<std::string> getAssignmentRuleIds() const;
594 
595  std::vector<std::string> getRateRuleIds() const;
596 
597  std::vector<std::string> getInitialAssignmentIds() const;
598 
599  std::string getEventId(size_t indx) const;
600 
601  int getEventIndex(const std::string& id) const;
602 
603  void saveState(std::ostream&) const;
604 
605  void loadState(std::istream&);
606 
607 private:
608 
609  std::set<std::string> initAssignmentRules;
610 
619  StringUIntMap initFloatingSpeciesMap;
620  StringUIntMap initBoundarySpeciesMap;
621  StringUIntMap initCompartmentsMap;
622  StringUIntMap initGlobalParametersMap;
623 
640  uint independentInitFloatingSpeciesSize;
641 
646  uint independentInitBoundarySpeciesSize;
647 
651  uint independentInitGlobalParameterSize;
652 
656  uint independentInitCompartmentSize;
657 
661  std::vector<uint> floatingSpeciesCompartmentIndices;
662 
666  std::vector<uint> boundarySpeciesCompartmentIndices;
667 
668 
671 private:
672 
673  std::string modelName;
674  StringUIntMap floatingSpeciesMap;
675  StringUIntMap boundarySpeciesMap;
676  StringUIntMap compartmentsMap;
677  StringUIntMap globalParametersMap;
678 
679 
684  typedef std::map<std::string, SpeciesReferenceInfo> StringRefInfoMap;
685  StringRefInfoMap namedSpeciesReferenceInfo;
686 
690  StringUIntMap reactionsMap;
691 
697  std::vector<uint> stoichColIndx;
698 
702  std::vector<uint> stoichRowIndx;
703 
708  std::vector<std::string> stoichIds;
709 
710  std::vector<SpeciesReferenceType> stoichTypes;
711 
716  std::set<std::string> assignmentRules;
717 
721  StringUIntMap rateRules;
722 
727  std::vector<bool> globalParameterRateRules;
728 
729  size_t independentFloatingSpeciesSize;
730  size_t independentBoundarySpeciesSize;
731  size_t independentGlobalParameterSize;
732  size_t independentCompartmentSize;
733 
737  std::vector<size_t> eventAssignmentsSize;
738 
739  std::vector<unsigned char> eventAttributes;
740 
744  StringUIntMap eventIds;
745 
746  void initBoundarySpecies(const libsbml::Model *);
747 
754  void initFloatingSpecies(const libsbml::Model *model,
755  bool conservedMoieties);
756 
760  void initCompartments(const libsbml::Model *);
761 
769  void initGlobalParameters(const libsbml::Model *model,
770  bool conservedMoieties);
771 
772  void initReactions(const libsbml::Model *model);
773 
774  void displayCompartmentInfo();
775 
776  void initEvents(const libsbml::Model *model);
777 
787  bool isValidFloatingSpeciesReference(const libsbml::SimpleSpeciesReference*,
788  const std::string& reacOrProd);
789 
794  void setNamedSpeciesReferenceInfo(uint row, uint column,
795  SpeciesReferenceType type);
796 
797  void saveStringRefInfoMap(std::ostream&, const StringRefInfoMap&) const;
798 
799  void loadStringRefInfoMap(std::istream&, StringRefInfoMap&);
800 
801  void saveBinarySpeciesReferenceInfo(std::ostream&, SpeciesReferenceInfo& sri) const;
802 
803  void loadBinarySpeciesReferenceInfo(std::istream&, SpeciesReferenceInfo&);
804 };
805 
806 } /* namespace rr */
807 #endif /* RRLLVMMODELDATASYMBOLS_H_ */
stores the names of all the symbols in the sbml model and thier indexes in the ModelData arrays.
Definition: LLVMModelDataSymbols.h:128
int getBoundarySpeciesIndex(std::string const &id) const
Get the index of a boundary species.
Definition: LLVMModelDataSymbols.cpp:310
void print() const
initialize and allocate the buffers (including the stoich matrix) for an existing ModelData struct.
Definition: LLVMModelDataSymbols.cpp:435
size_t getIndependentFloatingSpeciesSize() const
number of fully indenpendent species, these are species that have thier dynamics fully determined by ...
Definition: LLVMModelDataSymbols.cpp:564
const std::vector< uint > & getStoichColIndx() const
the column indices of non-zero stoichiometry values
Definition: LLVMModelDataSymbols.cpp:342
SymbolIndexType getSymbolIndex(const std::string &name, int &result) const
checks to see if we have the given symbol in the sbml.
Definition: LLVMModelDataSymbols.cpp:235
const std::vector< uint > & getStoichRowIndx() const
the row indices of non-zero stoichiometry values
Definition: LLVMModelDataSymbols.cpp:337
static const char * getFieldName(ModelDataFields field)
get the textual form of the field names.
Definition: LLVMModelDataSymbols.cpp:607
std::vector< std::string > getFloatingSpeciesIds() const
the list that is returned by ExecutableModel, so order must remain constant.
Definition: LLVMModelDataSymbols.cpp:478
int getConservedMoietyGlobalParameterIndex(uint cmIndex) const
get the index of a global parameter given a conserved moiety index.
Definition: LLVMModelDataSymbols.cpp:1886
bool isIndependentInitBoundarySpecies(const std::string &symbol) const
checks if the given symbol is an init value for an independent boundary species.
Definition: LLVMModelDataSymbols.cpp:1731
bool isConservedMoietySpecies(const std::string &symbol) const
checks if the given symbol is a init value for a conserved species.
Definition: LLVMModelDataSymbols.cpp:1718
bool isRateRuleGlobalParameter(uint gid) const
is the global parameter index defined by a rate rule.
Definition: LLVMModelDataSymbols.cpp:1243
std::string getBoundarySpeciesId(size_t indx) const
get the symbolic id of the i'th boundary species.
Definition: LLVMModelDataSymbols.cpp:510
std::string getCompartmentId(size_t indx) const
get the symbolic id of the i'th compartment.
Definition: LLVMModelDataSymbols.cpp:537
const std::vector< uint > & getIndSpeciesIndexForConservedMoietyId(std::string id) const
get all the independent species for a given conserved moiety id
Definition: LLVMModelDataSymbols.cpp:1873
bool isConservedMoietyAnalysis() const
check if the conserved moiety is turned on for this model
Definition: LLVMModelDataSymbols.cpp:1922
std::list< SpeciesReferenceInfo > getStoichiometryList() const
get a list of all the non-zero entries in the stoichiometry matrix.
Definition: LLVMModelDataSymbols.cpp:421
bool isIndependentElement(const std::string &id) const
if there are no rules for an element, then they are considered independent.
Definition: LLVMModelDataSymbols.cpp:675
int getConservedMoietyIndex(const std::string &name) const
get the id of a conserved moiety given its name.
Definition: LLVMModelDataSymbols.cpp:1902
int getGlobalParameterIndex(std::string const &) const
index of a global param given its name.
Definition: LLVMModelDataSymbols.cpp:326
bool isIndependentInitElement(const std::string &symbol) const
Is this sbml element an independent initial value.
Definition: LLVMModelDataSymbols.cpp:1760
std::string getFloatingSpeciesId(size_t indx) const
get the symbolic id of the i'th floating species.
Definition: LLVMModelDataSymbols.cpp:483
size_t getConservedMoietySize() const
get the number of conserved moieties.
Definition: LLVMModelDataSymbols.cpp:1858
bool isConservedMoietyParameter(uint id) const
check if the global parameter with the given id is a conserved moiety.
Definition: LLVMModelDataSymbols.cpp:1237
bool isIndependentInitGlobalParameter(const std::string &symbol) const
has this std::string been found to be an independent init global param– is a global param and not hav...
Definition: LLVMModelDataSymbols.cpp:1747
SymbolIndexType
The model frequently looks for indices to sbml symbols.
Definition: LLVMModelDataSymbols.h:148
int getFloatingSpeciesIndex(std::string const &id, bool requireIndependent=true) const
Get the index of a floating species.
Definition: LLVMModelDataSymbols.cpp:295
size_t getEventBufferSize(size_t eventId) const
get the size (in number of doubles) of the buffer that events need to save the event data to.
Definition: LLVMModelDataSymbols.cpp:1620
size_t getIndependentBoundarySpeciesSize() const
number of boundary species not defined by rules.
Definition: LLVMModelDataSymbols.cpp:629
int getFloatingSpeciesInitIndex(const std::string &symbol) const
get the index of a floating species initial value.
Definition: LLVMModelDataSymbols.cpp:1672
int getCompartmentIndexForFloatingSpecies(size_t floatIndex) const
get the index of a compartment for a float species.
Definition: LLVMModelDataSymbols.cpp:1275
int getDepSpeciesIndexForConservedMoietyId(std::string id) const
get the dependent species for a given conserved moiety id
Definition: LLVMModelDataSymbols.cpp:1863
int getGlobalParameterInitIndex(const std::string &symbol) const
get the index of a global parameter initial value
Definition: LLVMModelDataSymbols.cpp:1706
std::string getConservedMoietyId(size_t indx) const
find the id of the given conserved moiety index.
Definition: LLVMModelDataSymbols.cpp:1896
std::string getRateRuleId(size_t indx) const
get the symbolic id of the i'th rate rule
Definition: LLVMModelDataSymbols.cpp:649
int getCompartmentIndexForBoundarySpecies(size_t floatIndex) const
get the index of a compartment for a boundary species.
Definition: LLVMModelDataSymbols.cpp:1285
size_t getIndependentGlobalParameterSize() const
number of global parameters which are not determined by rules.
Definition: LLVMModelDataSymbols.cpp:619
size_t getFloatingSpeciesSize() const
total size of all floating species.
Definition: LLVMModelDataSymbols.cpp:415
int getCompartmentInitIndex(const std::string &symbol) const
get the index of a compartment initial value
Definition: LLVMModelDataSymbols.cpp:1694
size_t getIndependentCompartmentSize() const
number of compartments which are not determined by rules.
Definition: LLVMModelDataSymbols.cpp:624
bool isIndependentInitFloatingSpecies(const std::string &symbol) const
checks if the given symbol is an init value for an independent floating species.
Definition: LLVMModelDataSymbols.cpp:1723
std::string getGlobalParameterId(size_t indx) const
find the id of the given global parameter index.
Definition: LLVMModelDataSymbols.cpp:1249
int getBoundarySpeciesInitIndex(const std::string &symbol) const
get the index of a boundary species initial value.
Definition: LLVMModelDataSymbols.cpp:1683
Base class for all code generators in RoadRunner.
info about an entry in the stoich matrix.
Definition: LLVMModelDataSymbols.h:165