-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspecies.h
106 lines (85 loc) · 2.45 KB
/
species.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# ifndef SPECIES_H
# define SPECIES_H
#include <vector>
#include <deque>
#include <string>
#include <memory>
using namespace std;
#endif
//////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
class species{//Class containing the info of each species.
////////////
//////////
public:
string name; // name of the species
double n; // amount of species (it is chosen to be double to allow macroscopic and CLE integration)
bool ftracktime = false; // flag to track time of species that start with a fixed lifetime
deque<double> determtimeque; // queue of deterministic times for deterministc time reaction species (e.g. constant production time for mRNA)
double lifetime; // lifetime of the species
species(string aname,float anum){
name=aname;
n=anum;
}
species(const species &obj) { // copy constructor
name = obj.name;
n = obj.n;
ftracktime = obj.ftracktime;
determtimeque = obj.determtimeque;
}
species* clone(){ //function that returns a pointer to a new copied instance
return new species(*this); // alocates memory and return pointer
}
void MakeSpeciesTimeTracking(double lt){
ftracktime = true;
lifetime = lt;
}
void SetNum(float anum){
n=anum;
}
double GetNum(){
return n;
}
string GetName(){
return name;
}
void React(double ast){
n+=ast; // increase the species an amount ast
if (ftracktime){ // if we keep track of time, the times are updated
if (ast > 0){ // reaction that adds elements to the queue
for (int i=0; i<ast; i++){
determtimeque.push_back(lifetime);
}
}
else if (ast < 0){ // reaction that removes elements from the queue
for (int i=0; i>ast; i--){
if (!(determtimeque.empty())){ // only remove if possible
determtimeque.pop_front();
}
}
}
}
}
double GetNextTime(){
if (ftracktime){
if (n>0){
return determtimeque.front();
}
else{
return -1; // Negative -1 time means that there is not elements in the queue
}
}
else{
return -2; // Negative -2 time means that the reaction is not supposed to be asked for times
}
}
void Updatetime(double tau){
if (ftracktime){
for(auto &time: determtimeque){
time -= tau;
}
}
}
};
typedef std::unique_ptr<species> p_species;
typedef std::vector<std::unique_ptr<species> > v_species; // shortname for vectorsv_species