-
Notifications
You must be signed in to change notification settings - Fork 0
/
RATtransition.c
167 lines (141 loc) · 4.58 KB
/
RATtransition.c
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <math.h>
#include <stdio.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h>
#include <limits.h>
#include <float.h>
#include <stdbool.h>
#include "definiciones.h"
//Funciones
//Variables Globales
extern double cheyp[nbac][nfla];
extern double ddt;
extern double MU[nbac][nfla];
extern double THETA;
extern double QCH;
extern double tmpcheyp[nbac][nfla];
extern double CRT;
extern double CTR;
extern int shift[nbac][nfla];
extern int ticks;
extern int doingshift[nbac][nfla];
extern double PI;
extern double TPI;
extern double etta;
extern double meanrun;
extern double meantumble;
extern double varrun;
extern double vartumble;
extern double tiempo;
extern double lmax;
extern double LigInit;
extern double lcero;
extern double amp;
extern double frec;
extern double frecVA;
extern double meanrENbias;
extern double meantENbias;
extern double meanENCrossFla;
extern double meanrbias;
extern double meantbias;
extern double varrENbias;
extern double vartENbias;
extern double varrbias;
extern double vartbias;
extern double tmpbiast[nbac];
extern double tmpbiasr[nbac];
extern double crosscor[nbac];
extern double meancheyp;
// Calculates the sum of a variable to obtain a mean value
double medio(double tmpmedio,double var){
tmpmedio = tmpmedio + var;
return tmpmedio;
};
//Random Variate with Normal Distribution (0,1)
double generateGaussianNoise(double mu, double sigma){ //Box MIller Method
static const double epsilon = DBL_MIN;//std::numeric_limits<double>::min();
double z1=0.0;
bool generate=0;
generate = !generate;
if (!generate)
return z1 * sigma + mu;
double u1, u2;
do
{
u1 = rand() * (1.0 / RAND_MAX);
u2 = rand() * (1.0 / RAND_MAX);
}
while ( u1 <= epsilon );
double z0;
z0 = sqrt(-2.0 * log(u1)) * cos(TPI * u2);
z1 = sqrt(-2.0 * log(u1)) * sin(TPI * u2);
//printf("gass: %3.3f \n",z0 * sigma + mu);
etta=z0 * sigma + mu;
return etta;
};
//Langevin Equation for each flagella , numerical integration following Risken.
void cheypsolver(double initcond,int idn,int idf){
double temcheyp=0.0;
temcheyp=initcond;
// Equation 1 in the paper:
cheyp[idn][idf]=temcheyp + ddt*THETA*(MU[idn][idf]-temcheyp)*temcheyp+ sqrt(2.0f*QCH*ddt)*generateGaussianNoise(0.0, 1.0);
tmpcheyp[idn][idf] = cheyp[idn][idf];
if(tmpcheyp[idn][idf] < 0.0){cheyp[idn][idf]=-cheyp[idn][idf];tmpcheyp[idn][idf] = -tmpcheyp[idn][idf];};
if(cheyp[idn][idf] < 0.0){printf("cheyp error: %3.3f \n",cheyp[idn][idf]);exit(5);};
//printf("CHEYP: %3.3f \n",cheyp[idn][idf]);
meancheyp=medio(meancheyp,tmpcheyp[idn][idf]);
};
// Selects the mode for each flagella
void transicionRT(double cheypvalue,int idn,int idf){
if(shift[idn][idf]==1 && cheypvalue < CRT){ //CCW
shift[idn][idf]=1;
}
else if(shift[idn][idf]==1 && cheypvalue >= CRT){ // Transition from CCW to CW
doingshift[idn][idf]=1;
shift[idn][idf]=0;
}
else if(shift[idn][idf]==0 && cheypvalue > CTR){ // CW
shift[idn][idf]=0;
}
else if(shift[idn][idf]==0 && cheypvalue <= CTR){ // Transition from CW to CCW
doingshift[idn][idf]=2;
shift[idn][idf]=1;
};
};
// Function to obtain mean and variance for run and tumble times
void statistical(double runtime,double tumbletime,int count){
double tmpmeanrun=0.0;
double tmpmeantumble=0.0;
meanrun = meanrun + runtime;
meantumble = meantumble + tumbletime;
tmpmeanrun=meanrun/(double)count;
tmpmeantumble=meantumble/(double)count;
varrun =varrun + (tmpmeanrun - runtime)*(tmpmeanrun - runtime);
vartumble =vartumble + (tmpmeantumble - tumbletime)*(tmpmeantumble - tumbletime);
};
//Mean ensamble with time dependence
void meanbias(void){
double tmpmeanbiasR=0.0;double tmpmeanbiasT=0.0;double tmpvarbiasR=0.0;double tmpvarbiasT=0.0;
for(int k=0;k < nbac;k++){
tmpmeanbiasR=tmpmeanbiasR+tmpbiasr[k];
tmpmeanbiasT=tmpmeanbiasT+tmpbiast[k];
//tmpcrossfla=tmpcrossfla+crosscor[k];
};
meanrENbias=tmpmeanbiasR/(double)nbac;
meantENbias=tmpmeanbiasT/(double)nbac;
//meanENCrossFla=tmpcrossfla/(double)nbac;
for(int k=0;k < nbac;k++){
tmpvarbiasR=tmpvarbiasR+(tmpbiasr[k]-meanrENbias)*(tmpbiasr[k]-meanrENbias);
tmpvarbiasT=tmpvarbiasT+(tmpbiast[k]-meantENbias)*(tmpbiast[k]-meantENbias);
};
varrENbias=tmpmeanbiasR/(double)nbac;
vartENbias=tmpmeanbiasT/(double)nbac;
};
double crossfla(void){
double crf=0.0;double tmpcrossfla=0.0;
for(int k=0;k < nbac;k++){
tmpcrossfla=tmpcrossfla+(crosscor[k]);
};
crf=tmpcrossfla/(double)nbac;
return crf;
};