-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhageInfectionProbability.cpp
143 lines (102 loc) · 3.92 KB
/
PhageInfectionProbability.cpp
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "Simulation.hpp"
using namespace std;
int main(int argc, char** argv){
double gamma = 1e6;
for (int i = 0; i < argc; i++) {
if (i == 1) {
gamma = atof(argv[i]);
}
}
// Set the sizes the colonies should reach
vector<int> ColonySize = {10, 32, 100, 316, 1000};
// Set the percentage of infected bacteria
vector<double> f = {0.2, 0.4, 0.6, 0.8};
double L = 25;
// #pragma omp parallel for
for (int i = 0; i < ColonySize.size(); i++) {
// Load master simulation
Simulation m(1);
m.Quiet();
// Set a random seed
m.SetRngSeed(0);
// Sets initial density of the bacteria
m.CellInitialDensity(1 / pow(L, 2));
// Set phage properties
string phage = "P1vir";
m.PhageType(phage);
m.PhageAdsorptionParameter(gamma);
// Set boundary conditions
m.BoundaryType(2); // Reflecting
// Set maximum colony size:
m.MaxColonySize(ColonySize[i]);
// Run until size is reached
m.Run(1e-5);
double T = 1e-5;
while (m.NumberOfUninfectedCells() < ColonySize[i]) {
int err = m.Run(1e-5);
T += 1e-5;
if (err > 0) {
break;
}
if (T > 10) {
break;
}
}
cout << "ColonySize was set to: " << ColonySize[i] << ".\t size obtained is: " << m.NumberOfUninfectedCells() << endl;
cout << "gamma was set to: " << gamma << ".\t gamma obtained is: " << m.GetGamma() << endl;
// #pragma omp parallel for
for (int j = 0; j < f.size(); j++) {
// Copy the simulation state
Simulation c(m);
c.ClearErrors();
c.TimeStepSkip(1);
// Set the number of infected in surface layer
c.PhageInvasionType(6, (int)round(f[j] * ColonySize[i]));
// Set the infection time to be next timestep
double T_i = static_cast<double>(c.GetTime() + 1) * 1e-6;
c.PhageInvasionStartTime(T_i);
// Stop colony growth
c.MaxGrowthRate(0.0);
// Run time forward by dT to check spawning
c.Run(1e-5);
cout << "forcedInfected was set to: " << (int)round(f[j] * ColonySize[i]) << ".\t size obtained is: " << m.NumberOfUninfectedCells() - c.NumberOfUninfectedCells() << endl;
// Spawnphages to diffuse around colony
int N_hit = 0;
int N_try = 0;
int k_max = 5e4;
for (int k = 0; k < k_max; k++) {
N_try++;
// Copy the simulation state
Simulation t(c);
// Set uniform phage invasion
t.PhageInvasionType(3);
// Set the infection time to be next timestep
double T_i = static_cast<double>(t.GetTime()+1)*1e-6;
t.PhageInvasionStartTime(T_i);
// Set density so we get one phage
t.PhageInitialDensity(1/pow(L,3));
t.PhageAdsorptionParameter(gamma);
// Set the rngseed
t.SetRngSeed(k);
// Run time forward by dT to check spawning
t.Run(1e-5);
int N_it = 0;
while (t.NumberOfPhages() > 0) {
t.Run(1e-2);
N_it++;
}
if (t.NumberOfUninfectedCells() < c.NumberOfUninfectedCells()) {
N_hit++;
}
if (N_hit >= 1000) {
k = k_max;
}
}
cout << "\t# of new infections: " << N_hit << " out of "<< N_try << " attempts" << endl;
cout << "\tThe probability of hitting a non-infected cell is: " << (double)N_hit/(double)N_try << endl << endl;
}
cout << endl;
cout << endl;
}
return 0;
}