commit | author | age
|
7f6076
|
1 |
/* vim: set ts=4 sts=4 sw=4 noet : */ |
aec47d
|
2 |
#include<stdlib.h> |
SP |
3 |
#include<math.h> |
|
4 |
#include "general.h" |
|
5 |
#include "vertex.h" |
|
6 |
#include "bond.h" |
|
7 |
#include "triangle.h" |
|
8 |
#include "vesicle.h" |
|
9 |
#include "energy.h" |
|
10 |
#include "timestep.h" |
|
11 |
#include "cell.h" |
|
12 |
//#include "io.h" |
9166cb
|
13 |
#include "io.h" |
aec47d
|
14 |
#include<stdio.h> |
SP |
15 |
#include "vertexmove.h" |
1ad6d1
|
16 |
#include <string.h> |
43c042
|
17 |
#include "constvol.h" |
aec47d
|
18 |
|
fedf2b
|
19 |
ts_bool single_verticle_timestep(ts_vesicle *vesicle,ts_vertex *vtx,ts_double *rn){ |
aec47d
|
20 |
ts_uint i; |
SP |
21 |
ts_double dist; |
|
22 |
ts_bool retval; |
|
23 |
ts_uint cellidx; |
c0ae90
|
24 |
ts_double delta_energy, delta_energy_cv,oenergy,dvol=0.0, darea=0.0; |
ed31fe
|
25 |
ts_double costheta,sintheta,phi,r; |
1ad6d1
|
26 |
//This will hold all the information of vtx and its neighbours |
958e0e
|
27 |
ts_vertex backupvtx[20], *constvol_vtx_moved=NULL, *constvol_vtx_backup=NULL; |
dcd350
|
28 |
memcpy((void *)&backupvtx[0],(void *)vtx,sizeof(ts_vertex)); |
a63f17
|
29 |
|
SP |
30 |
//Some stupid tests for debugging cell occupation! |
|
31 |
/* cellidx=vertex_self_avoidance(vesicle, vtx); |
|
32 |
if(vesicle->clist->cell[cellidx]==vtx->cell){ |
|
33 |
fprintf(stderr,"Idx match!\n"); |
|
34 |
} else { |
|
35 |
fprintf(stderr,"***** Idx don't match!\n"); |
|
36 |
fatal("ENding.",1); |
|
37 |
} |
|
38 |
*/ |
|
39 |
|
352fad
|
40 |
//temporarly moving the vertex |
672ae4
|
41 |
// vtx->x=vtx->x+vesicle->stepsize*(2.0*rn[0]-1.0); |
SP |
42 |
// vtx->y=vtx->y+vesicle->stepsize*(2.0*rn[1]-1.0); |
|
43 |
// vtx->z=vtx->z+vesicle->stepsize*(2.0*rn[2]-1.0); |
|
44 |
|
c0ae90
|
45 |
//random move in a sphere with radius stepsize: |
ed31fe
|
46 |
r=vesicle->stepsize*rn[0]; |
M |
47 |
phi=rn[1]*2*M_PI; |
|
48 |
costheta=2*rn[2]-1; |
|
49 |
sintheta=sqrt(1-pow(costheta,2)); |
672ae4
|
50 |
vtx->x=vtx->x+r*sintheta*cos(phi); |
SP |
51 |
vtx->y=vtx->y+r*sintheta*sin(phi); |
|
52 |
vtx->z=vtx->z+r*costheta; |
|
53 |
|
|
54 |
|
c0ae90
|
55 |
//distance with neighbours check |
8f6a69
|
56 |
for(i=0;i<vtx->neigh_no;i++){ |
352fad
|
57 |
dist=vtx_distance_sq(vtx,vtx->neigh[i]); |
8f6a69
|
58 |
if(dist<1.0 || dist>vesicle->dmax) { |
c0ae90
|
59 |
vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); |
SP |
60 |
return TS_FAIL; |
8f6a69
|
61 |
} |
aec47d
|
62 |
} |
304510
|
63 |
|
M |
64 |
// Distance with grafted poly-vertex check: |
|
65 |
if(vtx->grafted_poly!=NULL){ |
|
66 |
dist=vtx_distance_sq(vtx,vtx->grafted_poly->vlist->vtx[0]); |
|
67 |
if(dist<1.0 || dist>vesicle->dmax) { |
|
68 |
vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); |
|
69 |
return TS_FAIL; |
|
70 |
} |
|
71 |
} |
|
72 |
|
fe24d2
|
73 |
// TODO: Maybe faster if checks only nucleus-neighboring cells |
M |
74 |
// Nucleus penetration check: |
bac004
|
75 |
//#define SQ(x) x*x |
37791b
|
76 |
if(vesicle->R_nucleus>0.0){ |
bac004
|
77 |
if ((vtx->x-vesicle->nucleus_center[0])*(vtx->x-vesicle->nucleus_center[0])+ (vtx->y-vesicle->nucleus_center[1])*(vtx->y-vesicle->nucleus_center[1]) + (vtx->z-vesicle->nucleus_center[2])*(vtx->z-vesicle->nucleus_center[2]) < vesicle->R_nucleus){ |
fe24d2
|
78 |
vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); |
M |
79 |
return TS_FAIL; |
|
80 |
} |
37791b
|
81 |
} else if(vesicle->R_nucleusX>0.0){ |
SP |
82 |
// fprintf(stderr,"DEBUG, (Rx, Ry,Rz)^2=(%f,%f,%f)\n",vesicle->R_nucleusX, vesicle->R_nucleusY, vesicle->R_nucleusZ); |
bac004
|
83 |
// if (SQ(vtx->x-vesicle->nucleus_center[0])/vesicle->R_nucleusX + SQ(vtx->y-vesicle->nucleus_center[1])/vesicle->R_nucleusY + SQ(vtx->z-vesicle->nucleus_center[2])/vesicle->R_nucleusZ < 1.0){ |
SP |
84 |
if ((vtx->x-vesicle->nucleus_center[0])*(vtx->x-vesicle->nucleus_center[0])/vesicle->R_nucleusX + (vtx->y-vesicle->nucleus_center[1])*(vtx->y-vesicle->nucleus_center[1])/vesicle->R_nucleusY + (vtx->z-vesicle->nucleus_center[2])*(vtx->z-vesicle->nucleus_center[2])/vesicle->R_nucleusZ < 1.0){ |
|
85 |
// if (SQ(vtx->x)/vesicle->R_nucleusX + SQ(vtx->y)/vesicle->R_nucleusY + SQ(vtx->z)/vesicle->R_nucleusZ < 1.0){ |
37791b
|
86 |
vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); |
SP |
87 |
return TS_FAIL; |
|
88 |
} |
|
89 |
|
|
90 |
} |
bac004
|
91 |
//#undef SQ |
fe24d2
|
92 |
//self avoidance check with distant vertices |
M |
93 |
cellidx=vertex_self_avoidance(vesicle, vtx); |
|
94 |
//check occupation number |
|
95 |
retval=cell_occupation_number_and_internal_proximity(vesicle->clist,cellidx,vtx); |
|
96 |
|
aec47d
|
97 |
if(retval==TS_FAIL){ |
dcd350
|
98 |
vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); |
aec47d
|
99 |
return TS_FAIL; |
SP |
100 |
} |
1ad6d1
|
101 |
|
SP |
102 |
|
c0ae90
|
103 |
//if all the tests are successful, then energy for vtx and neighbours is calculated |
1ad6d1
|
104 |
for(i=0;i<vtx->neigh_no;i++){ |
dcd350
|
105 |
memcpy((void *)&backupvtx[i+1],(void *)vtx->neigh[i],sizeof(ts_vertex)); |
1ad6d1
|
106 |
} |
aec47d
|
107 |
|
1121fa
|
108 |
if(vesicle->pswitch == 1 || vesicle->tape->constvolswitch>0){ |
414b8a
|
109 |
for(i=0;i<vtx->tristar_no;i++) dvol-=vtx->tristar[i]->volume; |
c0ae90
|
110 |
} |
SP |
111 |
|
|
112 |
if(vesicle->tape->constareaswitch==2){ |
|
113 |
for(i=0;i<vtx->tristar_no;i++) darea-=vtx->tristar[i]->area; |
|
114 |
|
|
115 |
} |
a63f17
|
116 |
|
aec47d
|
117 |
delta_energy=0; |
fe5069
|
118 |
|
SP |
119 |
// vesicle_volume(vesicle); |
|
120 |
// fprintf(stderr,"Volume in the beginning=%1.16e\n", vesicle->volume); |
43c042
|
121 |
|
aec47d
|
122 |
//update the normals of triangles that share bead i. |
8f6a69
|
123 |
for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]); |
a63f17
|
124 |
oenergy=vtx->energy; |
aec47d
|
125 |
energy_vertex(vtx); |
a63f17
|
126 |
delta_energy=vtx->xk*(vtx->energy - oenergy); |
aec47d
|
127 |
//the same is done for neighbouring vertices |
8f6a69
|
128 |
for(i=0;i<vtx->neigh_no;i++){ |
SP |
129 |
oenergy=vtx->neigh[i]->energy; |
|
130 |
energy_vertex(vtx->neigh[i]); |
|
131 |
delta_energy+=vtx->neigh[i]->xk*(vtx->neigh[i]->energy-oenergy); |
aec47d
|
132 |
} |
414b8a
|
133 |
|
1121fa
|
134 |
if(vesicle->pswitch == 1 || vesicle->tape->constvolswitch >0){ |
414b8a
|
135 |
for(i=0;i<vtx->tristar_no;i++) dvol+=vtx->tristar[i]->volume; |
fbcbdf
|
136 |
if(vesicle->pswitch==1) delta_energy-=vesicle->pressure*dvol; |
414b8a
|
137 |
}; |
43c042
|
138 |
|
c0ae90
|
139 |
if(vesicle->tape->constareaswitch==2){ |
SP |
140 |
/* check whether the darea is gt epsarea */ |
|
141 |
for(i=0;i<vtx->tristar_no;i++) darea+=vtx->tristar[i]->area; |
|
142 |
if(fabs(vesicle->area+darea-A0)>epsarea){ |
|
143 |
//restore old state. |
|
144 |
vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); |
|
145 |
for(i=0;i<vtx->neigh_no;i++){ |
|
146 |
vtx->neigh[i]=memcpy((void *)vtx->neigh[i],(void *)&backupvtx[i+1],sizeof(ts_vertex)); |
|
147 |
} |
|
148 |
for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]); |
|
149 |
//fprintf(stderr,"fajlam!\n"); |
|
150 |
return TS_FAIL; |
|
151 |
} |
|
152 |
|
|
153 |
|
|
154 |
} |
1121fa
|
155 |
|
SP |
156 |
if(vesicle->tape->constvolswitch==2){ |
|
157 |
/*check whether the dvol is gt than epsvol */ |
|
158 |
//fprintf(stderr,"DVOL=%1.16e\n",dvol); |
|
159 |
if(fabs(vesicle->volume+dvol-V0)>epsvol){ |
|
160 |
//restore old state. |
|
161 |
vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); |
|
162 |
for(i=0;i<vtx->neigh_no;i++){ |
|
163 |
vtx->neigh[i]=memcpy((void *)vtx->neigh[i],(void *)&backupvtx[i+1],sizeof(ts_vertex)); |
|
164 |
} |
|
165 |
for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]); |
|
166 |
//fprintf(stderr,"fajlam!\n"); |
|
167 |
return TS_FAIL; |
|
168 |
} |
|
169 |
|
|
170 |
} else |
fe5069
|
171 |
// vesicle_volume(vesicle); |
SP |
172 |
// fprintf(stderr,"Volume before=%1.16e\n", vesicle->volume); |
fbcbdf
|
173 |
if(vesicle->tape->constvolswitch == 1){ |
fe5069
|
174 |
retval=constvolume(vesicle, vtx, -dvol, &delta_energy_cv, &constvol_vtx_moved,&constvol_vtx_backup); |
fbcbdf
|
175 |
if(retval==TS_FAIL){ // if we couldn't move the vertex to assure constant volume |
SP |
176 |
vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); |
|
177 |
for(i=0;i<vtx->neigh_no;i++){ |
|
178 |
vtx->neigh[i]=memcpy((void *)vtx->neigh[i],(void *)&backupvtx[i+1],sizeof(ts_vertex)); |
|
179 |
} |
|
180 |
for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]); |
fe5069
|
181 |
// fprintf(stderr,"fajlam!\n"); |
fbcbdf
|
182 |
return TS_FAIL; |
SP |
183 |
} |
fe5069
|
184 |
// vesicle_volume(vesicle); |
SP |
185 |
// fprintf(stderr,"Volume after=%1.16e\n", vesicle->volume); |
|
186 |
// fprintf(stderr,"Volume after-dvol=%1.16e\n", vesicle->volume-dvol); |
|
187 |
// fprintf(stderr,"Denergy before=%e\n",delta_energy); |
|
188 |
|
fbcbdf
|
189 |
delta_energy+=delta_energy_cv; |
fe5069
|
190 |
// fprintf(stderr,"Denergy after=%e\n",delta_energy); |
fbcbdf
|
191 |
} |
304510
|
192 |
/* No poly-bond energy for now! |
fedf2b
|
193 |
if(vtx->grafted_poly!=NULL){ |
M |
194 |
delta_energy+= |
|
195 |
(pow(sqrt(vtx_distance_sq(vtx, vtx->grafted_poly->vlist->vtx[0])-1),2)- |
|
196 |
pow(sqrt(vtx_distance_sq(&backupvtx[0], vtx->grafted_poly->vlist->vtx[0])-1),2)) *vtx->grafted_poly->k; |
|
197 |
} |
304510
|
198 |
*/ |
314f2d
|
199 |
// fprintf(stderr, "DE=%f\n",delta_energy); |
aec47d
|
200 |
//MONTE CARLOOOOOOOO |
SP |
201 |
if(delta_energy>=0){ |
|
202 |
#ifdef TS_DOUBLE_DOUBLE |
3de289
|
203 |
if(exp(-delta_energy)< drand48()) |
aec47d
|
204 |
#endif |
SP |
205 |
#ifdef TS_DOUBLE_FLOAT |
|
206 |
if(expf(-delta_energy)< (ts_float)drand48()) |
|
207 |
#endif |
|
208 |
#ifdef TS_DOUBLE_LONGDOUBLE |
|
209 |
if(expl(-delta_energy)< (ts_ldouble)drand48()) |
|
210 |
#endif |
|
211 |
{ |
|
212 |
//not accepted, reverting changes |
fbcbdf
|
213 |
// fprintf(stderr,"MC failed\n"); |
dcd350
|
214 |
vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); |
1ad6d1
|
215 |
for(i=0;i<vtx->neigh_no;i++){ |
a63f17
|
216 |
vtx->neigh[i]=memcpy((void *)vtx->neigh[i],(void *)&backupvtx[i+1],sizeof(ts_vertex)); |
1ad6d1
|
217 |
} |
SP |
218 |
|
aec47d
|
219 |
//update the normals of triangles that share bead i. |
dcd350
|
220 |
for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]); |
1ad6d1
|
221 |
|
fe5069
|
222 |
// fprintf(stderr, "before vtx(x,y,z)=%e,%e,%e\n",constvol_vtx_moved->x, constvol_vtx_moved->y, constvol_vtx_moved->z); |
43c042
|
223 |
if(vesicle->tape->constvolswitch == 1){ |
958e0e
|
224 |
constvolumerestore(constvol_vtx_moved,constvol_vtx_backup); |
43c042
|
225 |
} |
fe5069
|
226 |
// fprintf(stderr, "after vtx(x,y,z)=%e,%e,%e\n",constvol_vtx_moved->x, constvol_vtx_moved->y, constvol_vtx_moved->z); |
dd5aca
|
227 |
// vesicle_volume(vesicle); |
SP |
228 |
// fprintf(stderr,"Volume after fail=%1.16e\n", vesicle->volume); |
aec47d
|
229 |
return TS_FAIL; |
SP |
230 |
} |
|
231 |
} |
2b14da
|
232 |
//accepted |
fbcbdf
|
233 |
// fprintf(stderr,"MC accepted\n"); |
a63f17
|
234 |
// oldcellidx=vertex_self_avoidance(vesicle, &backupvtx[0]); |
SP |
235 |
if(vtx->cell!=vesicle->clist->cell[cellidx]){ |
|
236 |
retval=cell_add_vertex(vesicle->clist->cell[cellidx],vtx); |
|
237 |
// if(retval==TS_SUCCESS) cell_remove_vertex(vesicle->clist->cell[oldcellidx],vtx); |
|
238 |
if(retval==TS_SUCCESS) cell_remove_vertex(backupvtx[0].cell,vtx); |
|
239 |
|
|
240 |
} |
2b14da
|
241 |
|
1121fa
|
242 |
if(vesicle->tape->constvolswitch == 2){ |
SP |
243 |
vesicle->volume+=dvol; |
|
244 |
} else |
43c042
|
245 |
if(vesicle->tape->constvolswitch == 1){ |
fbcbdf
|
246 |
constvolumeaccept(vesicle,constvol_vtx_moved,constvol_vtx_backup); |
43c042
|
247 |
} |
c0ae90
|
248 |
|
SP |
249 |
if(vesicle->tape->constareaswitch==2){ |
|
250 |
vesicle->area+=darea; |
|
251 |
} |
a63f17
|
252 |
// if(oldcellidx); |
aec47d
|
253 |
//END MONTE CARLOOOOOOO |
dd5aca
|
254 |
// vesicle_volume(vesicle); |
SP |
255 |
// fprintf(stderr,"Volume after success=%1.16e\n", vesicle->volume); |
aec47d
|
256 |
return TS_SUCCESS; |
SP |
257 |
} |
|
258 |
|
fedf2b
|
259 |
|
M |
260 |
ts_bool single_poly_vertex_move(ts_vesicle *vesicle,ts_poly *poly,ts_vertex *vtx,ts_double *rn){ |
|
261 |
ts_uint i; |
|
262 |
ts_bool retval; |
|
263 |
ts_uint cellidx; |
304510
|
264 |
// ts_double delta_energy; |
fedf2b
|
265 |
ts_double costheta,sintheta,phi,r; |
304510
|
266 |
ts_double dist; |
fedf2b
|
267 |
//This will hold all the information of vtx and its neighbours |
M |
268 |
ts_vertex backupvtx; |
304510
|
269 |
// ts_bond backupbond[2]; |
fedf2b
|
270 |
memcpy((void *)&backupvtx,(void *)vtx,sizeof(ts_vertex)); |
M |
271 |
|
|
272 |
//random move in a sphere with radius stepsize: |
|
273 |
r=vesicle->stepsize*rn[0]; |
|
274 |
phi=rn[1]*2*M_PI; |
|
275 |
costheta=2*rn[2]-1; |
|
276 |
sintheta=sqrt(1-pow(costheta,2)); |
|
277 |
vtx->x=vtx->x+r*sintheta*cos(phi); |
|
278 |
vtx->y=vtx->y+r*sintheta*sin(phi); |
|
279 |
vtx->z=vtx->z+r*costheta; |
|
280 |
|
|
281 |
|
|
282 |
//distance with neighbours check |
304510
|
283 |
for(i=0;i<vtx->neigh_no;i++){ |
M |
284 |
dist=vtx_distance_sq(vtx,vtx->neigh[i]); |
|
285 |
if(dist<1.0 || dist>vesicle->dmax) { |
|
286 |
vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); |
|
287 |
return TS_FAIL; |
|
288 |
} |
|
289 |
} |
|
290 |
|
|
291 |
// Distance with grafted vesicle-vertex check: |
|
292 |
if(vtx==poly->vlist->vtx[0]){ |
|
293 |
dist=vtx_distance_sq(vtx,poly->grafted_vtx); |
|
294 |
if(dist<1.0 || dist>vesicle->dmax) { |
|
295 |
vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); |
|
296 |
return TS_FAIL; |
|
297 |
} |
|
298 |
} |
|
299 |
|
fedf2b
|
300 |
|
M |
301 |
//self avoidance check with distant vertices |
|
302 |
cellidx=vertex_self_avoidance(vesicle, vtx); |
|
303 |
//check occupation number |
|
304 |
retval=cell_occupation_number_and_internal_proximity(vesicle->clist,cellidx,vtx); |
|
305 |
|
|
306 |
if(retval==TS_FAIL){ |
|
307 |
vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); |
|
308 |
return TS_FAIL; |
|
309 |
} |
|
310 |
|
|
311 |
|
|
312 |
//if all the tests are successful, then energy for vtx and neighbours is calculated |
304510
|
313 |
/* Energy ignored for now! |
fedf2b
|
314 |
delta_energy=0; |
M |
315 |
for(i=0;i<vtx->bond_no;i++){ |
|
316 |
memcpy((void *)&backupbond[i],(void *)vtx->bond[i],sizeof(ts_bond)); |
|
317 |
|
|
318 |
vtx->bond[i]->bond_length=sqrt(vtx_distance_sq(vtx->bond[i]->vtx1,vtx->bond[i]->vtx2)); |
|
319 |
bond_energy(vtx->bond[i],poly); |
|
320 |
delta_energy+= vtx->bond[i]->energy - backupbond[i].energy; |
|
321 |
} |
|
322 |
|
|
323 |
if(vtx==poly->vlist->vtx[0]){ |
|
324 |
delta_energy+= |
|
325 |
(pow(sqrt(vtx_distance_sq(vtx, poly->grafted_vtx)-1),2)- |
|
326 |
pow(sqrt(vtx_distance_sq(&backupvtx, poly->grafted_vtx)-1),2)) *poly->k; |
|
327 |
|
|
328 |
} |
|
329 |
|
|
330 |
|
|
331 |
if(delta_energy>=0){ |
|
332 |
#ifdef TS_DOUBLE_DOUBLE |
|
333 |
if(exp(-delta_energy)< drand48() ) |
|
334 |
#endif |
|
335 |
#ifdef TS_DOUBLE_FLOAT |
|
336 |
if(expf(-delta_energy)< (ts_float)drand48()) |
|
337 |
#endif |
|
338 |
#ifdef TS_DOUBLE_LONGDOUBLE |
|
339 |
if(expl(-delta_energy)< (ts_ldouble)drand48()) |
|
340 |
#endif |
|
341 |
{ |
|
342 |
//not accepted, reverting changes |
|
343 |
vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); |
|
344 |
for(i=0;i<vtx->bond_no;i++){ |
|
345 |
vtx->bond[i]=memcpy((void *)vtx->bond[i],(void *)&backupbond[i],sizeof(ts_bond)); |
|
346 |
} |
|
347 |
|
|
348 |
return TS_FAIL; |
|
349 |
} |
|
350 |
} |
304510
|
351 |
*/ |
fedf2b
|
352 |
|
M |
353 |
// oldcellidx=vertex_self_avoidance(vesicle, &backupvtx[0]); |
|
354 |
if(vtx->cell!=vesicle->clist->cell[cellidx]){ |
|
355 |
retval=cell_add_vertex(vesicle->clist->cell[cellidx],vtx); |
|
356 |
// if(retval==TS_SUCCESS) cell_remove_vertex(vesicle->clist->cell[oldcellidx],vtx); |
|
357 |
if(retval==TS_SUCCESS) cell_remove_vertex(backupvtx.cell,vtx); |
|
358 |
} |
|
359 |
// if(oldcellidx); |
|
360 |
//END MONTE CARLOOOOOOO |
|
361 |
return TS_SUCCESS; |
|
362 |
} |
58230a
|
363 |
|
M |
364 |
|
|
365 |
|
|
366 |
|
|
367 |
ts_bool single_filament_vertex_move(ts_vesicle *vesicle,ts_poly *poly,ts_vertex *vtx,ts_double *rn){ |
|
368 |
ts_uint i; |
|
369 |
ts_bool retval; |
|
370 |
ts_uint cellidx; |
b30f45
|
371 |
ts_double delta_energy; |
58230a
|
372 |
ts_double costheta,sintheta,phi,r; |
M |
373 |
ts_double dist[2]; |
|
374 |
//This will hold all the information of vtx and its neighbours |
b30f45
|
375 |
ts_vertex backupvtx,backupneigh[2]; |
58230a
|
376 |
ts_bond backupbond[2]; |
b30f45
|
377 |
|
M |
378 |
//backup vertex: |
58230a
|
379 |
memcpy((void *)&backupvtx,(void *)vtx,sizeof(ts_vertex)); |
M |
380 |
|
|
381 |
//random move in a sphere with radius stepsize: |
|
382 |
r=vesicle->stepsize*rn[0]; |
|
383 |
phi=rn[1]*2*M_PI; |
|
384 |
costheta=2*rn[2]-1; |
|
385 |
sintheta=sqrt(1-pow(costheta,2)); |
|
386 |
vtx->x=vtx->x+r*sintheta*cos(phi); |
|
387 |
vtx->y=vtx->y+r*sintheta*sin(phi); |
|
388 |
vtx->z=vtx->z+r*costheta; |
|
389 |
|
|
390 |
|
|
391 |
//distance with neighbours check |
|
392 |
for(i=0;i<vtx->bond_no;i++){ |
|
393 |
dist[i]=vtx_distance_sq(vtx->bond[i]->vtx1,vtx->bond[i]->vtx2); |
|
394 |
if(dist[i]<1.0 || dist[i]>vesicle->dmax) { |
|
395 |
vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); |
|
396 |
return TS_FAIL; |
|
397 |
} |
|
398 |
} |
|
399 |
|
fe24d2
|
400 |
// TODO: Maybe faster if checks only nucleus-neighboring cells |
M |
401 |
// Nucleus penetration check: |
|
402 |
if (vtx->x*vtx->x + vtx->y*vtx->y + vtx->z*vtx->z < vesicle->R_nucleus){ |
|
403 |
vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); |
|
404 |
return TS_FAIL; |
|
405 |
} |
|
406 |
|
58230a
|
407 |
|
M |
408 |
//self avoidance check with distant vertices |
|
409 |
cellidx=vertex_self_avoidance(vesicle, vtx); |
|
410 |
//check occupation number |
|
411 |
retval=cell_occupation_number_and_internal_proximity(vesicle->clist,cellidx,vtx); |
|
412 |
if(retval==TS_FAIL){ |
|
413 |
vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); |
|
414 |
return TS_FAIL; |
|
415 |
} |
|
416 |
|
|
417 |
//backup bonds |
|
418 |
for(i=0;i<vtx->bond_no;i++){ |
|
419 |
memcpy(&backupbond[i],vtx->bond[i], sizeof(ts_bond)); |
|
420 |
vtx->bond[i]->bond_length=sqrt(dist[i]); |
|
421 |
bond_vector(vtx->bond[i]); |
b30f45
|
422 |
} |
M |
423 |
|
|
424 |
//backup neighboring vertices: |
|
425 |
for(i=0;i<vtx->neigh_no;i++){ |
|
426 |
memcpy(&backupneigh[i],vtx->neigh[i], sizeof(ts_vertex)); |
58230a
|
427 |
} |
M |
428 |
|
|
429 |
//if all the tests are successful, then energy for vtx and neighbours is calculated |
b30f45
|
430 |
delta_energy=0; |
M |
431 |
|
|
432 |
if(vtx->bond_no == 2){ |
|
433 |
vtx->energy = -(vtx->bond[0]->x*vtx->bond[1]->x + vtx->bond[0]->y*vtx->bond[1]->y + vtx->bond[0]->z*vtx->bond[1]->z)/vtx->bond[0]->bond_length/vtx->bond[1]->bond_length; |
|
434 |
delta_energy += vtx->energy - backupvtx.energy; |
58230a
|
435 |
} |
M |
436 |
|
b30f45
|
437 |
for(i=0;i<vtx->neigh_no;i++){ |
M |
438 |
if(vtx->neigh[i]->bond_no == 2){ |
|
439 |
vtx->neigh[i]->energy = -(vtx->neigh[i]->bond[0]->x*vtx->neigh[i]->bond[1]->x + vtx->neigh[i]->bond[0]->y*vtx->neigh[i]->bond[1]->y + vtx->neigh[i]->bond[0]->z*vtx->neigh[i]->bond[1]->z)/vtx->neigh[i]->bond[0]->bond_length/vtx->neigh[i]->bond[1]->bond_length; |
|
440 |
delta_energy += vtx->neigh[i]->energy - backupneigh[i].energy; |
|
441 |
} |
58230a
|
442 |
} |
M |
443 |
|
b30f45
|
444 |
// poly->k is filament persistence length (in units l_min) |
M |
445 |
delta_energy *= poly->k; |
58230a
|
446 |
|
M |
447 |
if(delta_energy>=0){ |
|
448 |
#ifdef TS_DOUBLE_DOUBLE |
|
449 |
if(exp(-delta_energy)< drand48() ) |
|
450 |
#endif |
|
451 |
#ifdef TS_DOUBLE_FLOAT |
|
452 |
if(expf(-delta_energy)< (ts_float)drand48()) |
|
453 |
#endif |
|
454 |
#ifdef TS_DOUBLE_LONGDOUBLE |
|
455 |
if(expl(-delta_energy)< (ts_ldouble)drand48()) |
|
456 |
#endif |
|
457 |
{ |
|
458 |
//not accepted, reverting changes |
|
459 |
vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); |
b30f45
|
460 |
for(i=0;i<vtx->neigh_no;i++){ |
M |
461 |
memcpy(vtx->neigh[i],&backupneigh[i],sizeof(ts_vertex)); |
|
462 |
} |
58230a
|
463 |
for(i=0;i<vtx->bond_no;i++){ |
b30f45
|
464 |
vtx->bond[i]=memcpy((void *)vtx->bond[i],(void *)&backupbond[i],sizeof(ts_bond)); |
58230a
|
465 |
} |
M |
466 |
|
|
467 |
return TS_FAIL; |
|
468 |
} |
|
469 |
} |
|
470 |
|
b30f45
|
471 |
|
58230a
|
472 |
// oldcellidx=vertex_self_avoidance(vesicle, &backupvtx[0]); |
M |
473 |
if(vtx->cell!=vesicle->clist->cell[cellidx]){ |
|
474 |
retval=cell_add_vertex(vesicle->clist->cell[cellidx],vtx); |
|
475 |
// if(retval==TS_SUCCESS) cell_remove_vertex(vesicle->clist->cell[oldcellidx],vtx); |
|
476 |
if(retval==TS_SUCCESS) cell_remove_vertex(backupvtx.cell,vtx); |
|
477 |
} |
|
478 |
// if(oldcellidx); |
|
479 |
//END MONTE CARLOOOOOOO |
|
480 |
return TS_SUCCESS; |
|
481 |
} |