Trisurf Monte Carlo simulator
Samo Penic
2016-07-05 0a2c81d28b72c6ab68ad418130148b144da90309
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
e5858f 201 //    if(vtx->c!=0.0) printf("DE=%f\n",delta_energy);
aec47d 202     if(delta_energy>=0){
SP 203 #ifdef TS_DOUBLE_DOUBLE
3de289 204         if(exp(-delta_energy)< drand48())
aec47d 205 #endif
SP 206 #ifdef TS_DOUBLE_FLOAT
207         if(expf(-delta_energy)< (ts_float)drand48())
208 #endif
209 #ifdef TS_DOUBLE_LONGDOUBLE
210         if(expl(-delta_energy)< (ts_ldouble)drand48())
211 #endif
212     {
213     //not accepted, reverting changes
fbcbdf 214   //  fprintf(stderr,"MC failed\n");
dcd350 215     vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex));
1ad6d1 216     for(i=0;i<vtx->neigh_no;i++){
a63f17 217         vtx->neigh[i]=memcpy((void *)vtx->neigh[i],(void *)&backupvtx[i+1],sizeof(ts_vertex));
1ad6d1 218     }
SP 219     
aec47d 220     //update the normals of triangles that share bead i.
dcd350 221    for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]);
1ad6d1 222
fe5069 223 //    fprintf(stderr, "before vtx(x,y,z)=%e,%e,%e\n",constvol_vtx_moved->x, constvol_vtx_moved->y, constvol_vtx_moved->z);
43c042 224     if(vesicle->tape->constvolswitch == 1){
958e0e 225         constvolumerestore(constvol_vtx_moved,constvol_vtx_backup);
43c042 226     }
fe5069 227 //    fprintf(stderr, "after vtx(x,y,z)=%e,%e,%e\n",constvol_vtx_moved->x, constvol_vtx_moved->y, constvol_vtx_moved->z);
dd5aca 228 //    vesicle_volume(vesicle);
SP 229 //    fprintf(stderr,"Volume after fail=%1.16e\n", vesicle->volume);
aec47d 230     return TS_FAIL; 
SP 231     }
232 }
2b14da 233     //accepted    
fbcbdf 234  //   fprintf(stderr,"MC accepted\n");
a63f17 235 //    oldcellidx=vertex_self_avoidance(vesicle, &backupvtx[0]);
SP 236     if(vtx->cell!=vesicle->clist->cell[cellidx]){
237         retval=cell_add_vertex(vesicle->clist->cell[cellidx],vtx);
238 //        if(retval==TS_SUCCESS) cell_remove_vertex(vesicle->clist->cell[oldcellidx],vtx);
239         if(retval==TS_SUCCESS) cell_remove_vertex(backupvtx[0].cell,vtx);
240         
241     }
2b14da 242
1121fa 243     if(vesicle->tape->constvolswitch == 2){
SP 244     vesicle->volume+=dvol;
245     } else
43c042 246     if(vesicle->tape->constvolswitch == 1){
fbcbdf 247         constvolumeaccept(vesicle,constvol_vtx_moved,constvol_vtx_backup);
43c042 248     }
c0ae90 249
SP 250     if(vesicle->tape->constareaswitch==2){
251         vesicle->area+=darea;
252     }
a63f17 253 //    if(oldcellidx);
aec47d 254     //END MONTE CARLOOOOOOO
dd5aca 255 //    vesicle_volume(vesicle);
SP 256 //    fprintf(stderr,"Volume after success=%1.16e\n", vesicle->volume);
aec47d 257     return TS_SUCCESS;
SP 258 }
259
fedf2b 260
M 261 ts_bool single_poly_vertex_move(ts_vesicle *vesicle,ts_poly *poly,ts_vertex *vtx,ts_double *rn){
262     ts_uint i;
263     ts_bool retval; 
264     ts_uint cellidx; 
304510 265 //    ts_double delta_energy;
fedf2b 266     ts_double costheta,sintheta,phi,r;
304510 267     ts_double dist;
fedf2b 268     //This will hold all the information of vtx and its neighbours
M 269     ts_vertex backupvtx;
304510 270 //    ts_bond backupbond[2];
fedf2b 271     memcpy((void *)&backupvtx,(void *)vtx,sizeof(ts_vertex));
M 272
273     //random move in a sphere with radius stepsize:
274     r=vesicle->stepsize*rn[0];
275     phi=rn[1]*2*M_PI;
276     costheta=2*rn[2]-1;
277     sintheta=sqrt(1-pow(costheta,2));
278     vtx->x=vtx->x+r*sintheta*cos(phi);
279     vtx->y=vtx->y+r*sintheta*sin(phi);
280     vtx->z=vtx->z+r*costheta;
281
282
283     //distance with neighbours check
304510 284     for(i=0;i<vtx->neigh_no;i++){
M 285         dist=vtx_distance_sq(vtx,vtx->neigh[i]);
286         if(dist<1.0 || dist>vesicle->dmax) {
287             vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex));
288             return TS_FAIL;
289         }
290     }
291
292 // Distance with grafted vesicle-vertex check:    
293     if(vtx==poly->vlist->vtx[0]){
294         dist=vtx_distance_sq(vtx,poly->grafted_vtx);
295         if(dist<1.0 || dist>vesicle->dmax) {
296         vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex));
297         return TS_FAIL;
298         }
299     }
300
fedf2b 301
M 302     //self avoidance check with distant vertices
303     cellidx=vertex_self_avoidance(vesicle, vtx);
304     //check occupation number
305     retval=cell_occupation_number_and_internal_proximity(vesicle->clist,cellidx,vtx);
306     
307     if(retval==TS_FAIL){
308         vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex));
309         return TS_FAIL;
310     } 
311
312
313     //if all the tests are successful, then energy for vtx and neighbours is calculated
304510 314 /* Energy ignored for now!
fedf2b 315     delta_energy=0;
M 316     for(i=0;i<vtx->bond_no;i++){
317         memcpy((void *)&backupbond[i],(void *)vtx->bond[i],sizeof(ts_bond));
318
319         vtx->bond[i]->bond_length=sqrt(vtx_distance_sq(vtx->bond[i]->vtx1,vtx->bond[i]->vtx2));
320         bond_energy(vtx->bond[i],poly);
321         delta_energy+= vtx->bond[i]->energy - backupbond[i].energy;
322     }
323
324     if(vtx==poly->vlist->vtx[0]){
325         delta_energy+=
326             (pow(sqrt(vtx_distance_sq(vtx, poly->grafted_vtx)-1),2)-
327             pow(sqrt(vtx_distance_sq(&backupvtx, poly->grafted_vtx)-1),2)) *poly->k;
328         
329     }
330
331
332     if(delta_energy>=0){
333 #ifdef TS_DOUBLE_DOUBLE
334         if(exp(-delta_energy)< drand48() )
335 #endif
336 #ifdef TS_DOUBLE_FLOAT
337         if(expf(-delta_energy)< (ts_float)drand48())
338 #endif
339 #ifdef TS_DOUBLE_LONGDOUBLE
340         if(expl(-delta_energy)< (ts_ldouble)drand48())
341 #endif
342         {
343     //not accepted, reverting changes
344     vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex));
345     for(i=0;i<vtx->bond_no;i++){
346     vtx->bond[i]=memcpy((void *)vtx->bond[i],(void *)&backupbond[i],sizeof(ts_bond));
347     }
348
349     return TS_FAIL; 
350     }
351     }
304510 352 */
fedf2b 353         
M 354 //    oldcellidx=vertex_self_avoidance(vesicle, &backupvtx[0]);
355     if(vtx->cell!=vesicle->clist->cell[cellidx]){
356         retval=cell_add_vertex(vesicle->clist->cell[cellidx],vtx);
357 //        if(retval==TS_SUCCESS) cell_remove_vertex(vesicle->clist->cell[oldcellidx],vtx);
358         if(retval==TS_SUCCESS) cell_remove_vertex(backupvtx.cell,vtx);    
359     }
360 //    if(oldcellidx);
361     //END MONTE CARLOOOOOOO
362     return TS_SUCCESS;
363 }
58230a 364
M 365
366
367
368 ts_bool single_filament_vertex_move(ts_vesicle *vesicle,ts_poly *poly,ts_vertex *vtx,ts_double *rn){
369     ts_uint i;
370     ts_bool retval; 
371     ts_uint cellidx; 
b30f45 372     ts_double delta_energy;
58230a 373     ts_double costheta,sintheta,phi,r;
M 374     ts_double dist[2];
375     //This will hold all the information of vtx and its neighbours
b30f45 376     ts_vertex backupvtx,backupneigh[2];
58230a 377     ts_bond backupbond[2];
b30f45 378
M 379     //backup vertex:        
58230a 380     memcpy((void *)&backupvtx,(void *)vtx,sizeof(ts_vertex));
M 381
382     //random move in a sphere with radius stepsize:
383     r=vesicle->stepsize*rn[0];
384     phi=rn[1]*2*M_PI;
385     costheta=2*rn[2]-1;
386     sintheta=sqrt(1-pow(costheta,2));
387     vtx->x=vtx->x+r*sintheta*cos(phi);
388     vtx->y=vtx->y+r*sintheta*sin(phi);
389     vtx->z=vtx->z+r*costheta;
390
391
392     //distance with neighbours check
393     for(i=0;i<vtx->bond_no;i++){
394         dist[i]=vtx_distance_sq(vtx->bond[i]->vtx1,vtx->bond[i]->vtx2);
395         if(dist[i]<1.0 || dist[i]>vesicle->dmax) {
396             vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex));
397             return TS_FAIL;
398         }
399     }
400
fe24d2 401 // TODO: Maybe faster if checks only nucleus-neighboring cells
M 402 // Nucleus penetration check:
403     if (vtx->x*vtx->x + vtx->y*vtx->y + vtx->z*vtx->z < vesicle->R_nucleus){
404         vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex));
405         return TS_FAIL;
406     }
407
58230a 408
M 409     //self avoidance check with distant vertices
410     cellidx=vertex_self_avoidance(vesicle, vtx);
411     //check occupation number
412     retval=cell_occupation_number_and_internal_proximity(vesicle->clist,cellidx,vtx);
413     if(retval==TS_FAIL){
414         vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex));
415         return TS_FAIL;
416     } 
417
418     //backup bonds
419     for(i=0;i<vtx->bond_no;i++){
420         memcpy(&backupbond[i],vtx->bond[i], sizeof(ts_bond));
421         vtx->bond[i]->bond_length=sqrt(dist[i]);
422         bond_vector(vtx->bond[i]);
b30f45 423     }
M 424
425     //backup neighboring vertices:
426     for(i=0;i<vtx->neigh_no;i++){
427         memcpy(&backupneigh[i],vtx->neigh[i], sizeof(ts_vertex));
58230a 428     }
M 429     
430     //if all the tests are successful, then energy for vtx and neighbours is calculated
b30f45 431     delta_energy=0;
M 432     
433     if(vtx->bond_no == 2){
434         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;
435         delta_energy += vtx->energy - backupvtx.energy;
58230a 436     }
M 437
b30f45 438     for(i=0;i<vtx->neigh_no;i++){
M 439         if(vtx->neigh[i]->bond_no == 2){
440             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;
441             delta_energy += vtx->neigh[i]->energy - backupneigh[i].energy;
442         }
58230a 443     }
M 444
b30f45 445     // poly->k is filament persistence length (in units l_min)
M 446     delta_energy *= poly->k;
58230a 447
M 448     if(delta_energy>=0){
449 #ifdef TS_DOUBLE_DOUBLE
450         if(exp(-delta_energy)< drand48() )
451 #endif
452 #ifdef TS_DOUBLE_FLOAT
453         if(expf(-delta_energy)< (ts_float)drand48())
454 #endif
455 #ifdef TS_DOUBLE_LONGDOUBLE
456         if(expl(-delta_energy)< (ts_ldouble)drand48())
457 #endif
458         {
459     //not accepted, reverting changes
460     vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex));
b30f45 461     for(i=0;i<vtx->neigh_no;i++){
M 462         memcpy(vtx->neigh[i],&backupneigh[i],sizeof(ts_vertex));
463     }
58230a 464     for(i=0;i<vtx->bond_no;i++){
b30f45 465         vtx->bond[i]=memcpy((void *)vtx->bond[i],(void *)&backupbond[i],sizeof(ts_bond));
58230a 466     }
M 467
468     return TS_FAIL; 
469     }
470     }
471     
b30f45 472     
58230a 473 //    oldcellidx=vertex_self_avoidance(vesicle, &backupvtx[0]);
M 474     if(vtx->cell!=vesicle->clist->cell[cellidx]){
475         retval=cell_add_vertex(vesicle->clist->cell[cellidx],vtx);
476 //        if(retval==TS_SUCCESS) cell_remove_vertex(vesicle->clist->cell[oldcellidx],vtx);
477         if(retval==TS_SUCCESS) cell_remove_vertex(backupvtx.cell,vtx);    
478     }
479 //    if(oldcellidx);
480     //END MONTE CARLOOOOOOO
481     return TS_SUCCESS;
482 }