| 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 | } | |
| 88bdd7 | 91 | |
| SP | 92 | // plane confinement check whether the new position of vertex will be out of bounds |
| 93 | if(vesicle->tape->plane_confinement_switch){ | |
| 94 | if(vtx->z>vesicle->confinement_plane.z_max || vtx->z<vesicle->confinement_plane.z_min){ | |
| 95 | vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); | |
| 96 | return TS_FAIL; | |
| 97 | } | |
| 98 | } | |
| bac004 | 99 | //#undef SQ |
| fe24d2 | 100 | //self avoidance check with distant vertices |
| M | 101 | cellidx=vertex_self_avoidance(vesicle, vtx); |
| 102 | //check occupation number | |
| 103 | retval=cell_occupation_number_and_internal_proximity(vesicle->clist,cellidx,vtx); | |
| 104 | ||
| aec47d | 105 | if(retval==TS_FAIL){ |
| dcd350 | 106 | vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); |
| aec47d | 107 | return TS_FAIL; |
| SP | 108 | } |
| 1ad6d1 | 109 | |
| SP | 110 | |
| c0ae90 | 111 | //if all the tests are successful, then energy for vtx and neighbours is calculated |
| 1ad6d1 | 112 | for(i=0;i<vtx->neigh_no;i++){ |
| dcd350 | 113 | memcpy((void *)&backupvtx[i+1],(void *)vtx->neigh[i],sizeof(ts_vertex)); |
| 1ad6d1 | 114 | } |
| aec47d | 115 | |
| 1121fa | 116 | if(vesicle->pswitch == 1 || vesicle->tape->constvolswitch>0){ |
| 414b8a | 117 | for(i=0;i<vtx->tristar_no;i++) dvol-=vtx->tristar[i]->volume; |
| c0ae90 | 118 | } |
| SP | 119 | |
| 120 | if(vesicle->tape->constareaswitch==2){ | |
| 121 | for(i=0;i<vtx->tristar_no;i++) darea-=vtx->tristar[i]->area; | |
| 122 | ||
| 123 | } | |
| a63f17 | 124 | |
| aec47d | 125 | delta_energy=0; |
| 0dd5ba | 126 | |
| SP | 127 | |
| fe5069 | 128 | // vesicle_volume(vesicle); |
| SP | 129 | // fprintf(stderr,"Volume in the beginning=%1.16e\n", vesicle->volume); |
| 43c042 | 130 | |
| aec47d | 131 | //update the normals of triangles that share bead i. |
| 8f6a69 | 132 | for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]); |
| a63f17 | 133 | oenergy=vtx->energy; |
| aec47d | 134 | energy_vertex(vtx); |
| a63f17 | 135 | delta_energy=vtx->xk*(vtx->energy - oenergy); |
| aec47d | 136 | //the same is done for neighbouring vertices |
| 8f6a69 | 137 | for(i=0;i<vtx->neigh_no;i++){ |
| SP | 138 | oenergy=vtx->neigh[i]->energy; |
| 139 | energy_vertex(vtx->neigh[i]); | |
| 140 | delta_energy+=vtx->neigh[i]->xk*(vtx->neigh[i]->energy-oenergy); | |
| aec47d | 141 | } |
| 414b8a | 142 | |
| 1121fa | 143 | if(vesicle->pswitch == 1 || vesicle->tape->constvolswitch >0){ |
| 414b8a | 144 | for(i=0;i<vtx->tristar_no;i++) dvol+=vtx->tristar[i]->volume; |
| fbcbdf | 145 | if(vesicle->pswitch==1) delta_energy-=vesicle->pressure*dvol; |
| 414b8a | 146 | }; |
| 43c042 | 147 | |
| c0ae90 | 148 | if(vesicle->tape->constareaswitch==2){ |
| SP | 149 | /* check whether the darea is gt epsarea */ |
| 150 | for(i=0;i<vtx->tristar_no;i++) darea+=vtx->tristar[i]->area; | |
| 151 | if(fabs(vesicle->area+darea-A0)>epsarea){ | |
| 152 | //restore old state. | |
| 153 | vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); | |
| 154 | for(i=0;i<vtx->neigh_no;i++){ | |
| 155 | vtx->neigh[i]=memcpy((void *)vtx->neigh[i],(void *)&backupvtx[i+1],sizeof(ts_vertex)); | |
| 156 | } | |
| 157 | for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]); | |
| 158 | //fprintf(stderr,"fajlam!\n"); | |
| 159 | return TS_FAIL; | |
| 160 | } | |
| 161 | ||
| 162 | ||
| 163 | } | |
| 1121fa | 164 | |
| SP | 165 | if(vesicle->tape->constvolswitch==2){ |
| 166 | /*check whether the dvol is gt than epsvol */ | |
| 167 | //fprintf(stderr,"DVOL=%1.16e\n",dvol); | |
| 168 | if(fabs(vesicle->volume+dvol-V0)>epsvol){ | |
| 169 | //restore old state. | |
| 170 | vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); | |
| 171 | for(i=0;i<vtx->neigh_no;i++){ | |
| 172 | vtx->neigh[i]=memcpy((void *)vtx->neigh[i],(void *)&backupvtx[i+1],sizeof(ts_vertex)); | |
| 173 | } | |
| 174 | for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]); | |
| 175 | //fprintf(stderr,"fajlam!\n"); | |
| 176 | return TS_FAIL; | |
| 177 | } | |
| 178 | ||
| 179 | } else | |
| fe5069 | 180 | // vesicle_volume(vesicle); |
| SP | 181 | // fprintf(stderr,"Volume before=%1.16e\n", vesicle->volume); |
| fbcbdf | 182 | if(vesicle->tape->constvolswitch == 1){ |
| fe5069 | 183 | retval=constvolume(vesicle, vtx, -dvol, &delta_energy_cv, &constvol_vtx_moved,&constvol_vtx_backup); |
| fbcbdf | 184 | if(retval==TS_FAIL){ // if we couldn't move the vertex to assure constant volume |
| SP | 185 | vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); |
| 186 | for(i=0;i<vtx->neigh_no;i++){ | |
| 187 | vtx->neigh[i]=memcpy((void *)vtx->neigh[i],(void *)&backupvtx[i+1],sizeof(ts_vertex)); | |
| 188 | } | |
| 189 | for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]); | |
| fe5069 | 190 | // fprintf(stderr,"fajlam!\n"); |
| fbcbdf | 191 | return TS_FAIL; |
| SP | 192 | } |
| fe5069 | 193 | // vesicle_volume(vesicle); |
| SP | 194 | // fprintf(stderr,"Volume after=%1.16e\n", vesicle->volume); |
| 195 | // fprintf(stderr,"Volume after-dvol=%1.16e\n", vesicle->volume-dvol); | |
| 196 | // fprintf(stderr,"Denergy before=%e\n",delta_energy); | |
| 197 | ||
| fbcbdf | 198 | delta_energy+=delta_energy_cv; |
| fe5069 | 199 | // fprintf(stderr,"Denergy after=%e\n",delta_energy); |
| fbcbdf | 200 | } |
| 250de4 | 201 | /* Vertices with spontaneous curvature may have spontaneous force perpendicular to the surface of the vesicle. additional delta energy is calculated in this function */ |
| SP | 202 | delta_energy+=direct_force_energy(vesicle,vtx,backupvtx); |
| 304510 | 203 | /* No poly-bond energy for now! |
| fedf2b | 204 | if(vtx->grafted_poly!=NULL){ |
| M | 205 | delta_energy+= |
| 206 | (pow(sqrt(vtx_distance_sq(vtx, vtx->grafted_poly->vlist->vtx[0])-1),2)- | |
| 207 | pow(sqrt(vtx_distance_sq(&backupvtx[0], vtx->grafted_poly->vlist->vtx[0])-1),2)) *vtx->grafted_poly->k; | |
| 208 | } | |
| 304510 | 209 | */ |
| 0dd5ba | 210 | |
| SP | 211 | // plane confinement energy due to compressing force |
| 212 | if(vesicle->tape->plane_confinement_switch){ | |
| 213 | if(vesicle->confinement_plane.force_switch){ | |
| 214 | //substract old energy | |
| 215 | if(abs(vesicle->tape->plane_d/2.0-vesicle->confinement_plane.z_max)>1e-10) { | |
| 216 | delta_energy-=vesicle->tape->plane_F / pow(vesicle->confinement_plane.z_max-backupvtx[0].z,2); | |
| 217 | delta_energy+=vesicle->tape->plane_F / pow(vesicle->confinement_plane.z_max-vtx->z,2); | |
| 218 | } | |
| 219 | if(abs(-vesicle->tape->plane_d/2.0-vesicle->confinement_plane.z_min)>1e-10) { | |
| 220 | delta_energy-=vesicle->tape->plane_F / pow(vesicle->confinement_plane.z_min-backupvtx[0].z,2); | |
| 221 | delta_energy+=vesicle->tape->plane_F / pow(vesicle->confinement_plane.z_min-vtx->z,2); | |
| 222 | } | |
| 223 | } | |
| 224 | } | |
| 225 | ||
| 314f2d | 226 | // fprintf(stderr, "DE=%f\n",delta_energy); |
| aec47d | 227 | //MONTE CARLOOOOOOOO |
| e5858f | 228 | // if(vtx->c!=0.0) printf("DE=%f\n",delta_energy); |
| aec47d | 229 | if(delta_energy>=0){ |
| SP | 230 | #ifdef TS_DOUBLE_DOUBLE |
| 3de289 | 231 | if(exp(-delta_energy)< drand48()) |
| aec47d | 232 | #endif |
| SP | 233 | #ifdef TS_DOUBLE_FLOAT |
| 234 | if(expf(-delta_energy)< (ts_float)drand48()) | |
| 235 | #endif | |
| 236 | #ifdef TS_DOUBLE_LONGDOUBLE | |
| 237 | if(expl(-delta_energy)< (ts_ldouble)drand48()) | |
| 238 | #endif | |
| 239 | { | |
| 240 | //not accepted, reverting changes | |
| fbcbdf | 241 | // fprintf(stderr,"MC failed\n"); |
| dcd350 | 242 | vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); |
| 1ad6d1 | 243 | for(i=0;i<vtx->neigh_no;i++){ |
| a63f17 | 244 | vtx->neigh[i]=memcpy((void *)vtx->neigh[i],(void *)&backupvtx[i+1],sizeof(ts_vertex)); |
| 1ad6d1 | 245 | } |
| SP | 246 | |
| aec47d | 247 | //update the normals of triangles that share bead i. |
| dcd350 | 248 | for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]); |
| 1ad6d1 | 249 | |
| fe5069 | 250 | // fprintf(stderr, "before vtx(x,y,z)=%e,%e,%e\n",constvol_vtx_moved->x, constvol_vtx_moved->y, constvol_vtx_moved->z); |
| 43c042 | 251 | if(vesicle->tape->constvolswitch == 1){ |
| 958e0e | 252 | constvolumerestore(constvol_vtx_moved,constvol_vtx_backup); |
| 43c042 | 253 | } |
| fe5069 | 254 | // fprintf(stderr, "after vtx(x,y,z)=%e,%e,%e\n",constvol_vtx_moved->x, constvol_vtx_moved->y, constvol_vtx_moved->z); |
| dd5aca | 255 | // vesicle_volume(vesicle); |
| SP | 256 | // fprintf(stderr,"Volume after fail=%1.16e\n", vesicle->volume); |
| aec47d | 257 | return TS_FAIL; |
| SP | 258 | } |
| 259 | } | |
| 2b14da | 260 | //accepted |
| fbcbdf | 261 | // fprintf(stderr,"MC accepted\n"); |
| a63f17 | 262 | // oldcellidx=vertex_self_avoidance(vesicle, &backupvtx[0]); |
| SP | 263 | if(vtx->cell!=vesicle->clist->cell[cellidx]){ |
| 264 | retval=cell_add_vertex(vesicle->clist->cell[cellidx],vtx); | |
| 265 | // if(retval==TS_SUCCESS) cell_remove_vertex(vesicle->clist->cell[oldcellidx],vtx); | |
| 266 | if(retval==TS_SUCCESS) cell_remove_vertex(backupvtx[0].cell,vtx); | |
| 267 | ||
| 268 | } | |
| 2b14da | 269 | |
| 1121fa | 270 | if(vesicle->tape->constvolswitch == 2){ |
| SP | 271 | vesicle->volume+=dvol; |
| 272 | } else | |
| 43c042 | 273 | if(vesicle->tape->constvolswitch == 1){ |
| fbcbdf | 274 | constvolumeaccept(vesicle,constvol_vtx_moved,constvol_vtx_backup); |
| 43c042 | 275 | } |
| c0ae90 | 276 | |
| SP | 277 | if(vesicle->tape->constareaswitch==2){ |
| 278 | vesicle->area+=darea; | |
| 279 | } | |
| a63f17 | 280 | // if(oldcellidx); |
| aec47d | 281 | //END MONTE CARLOOOOOOO |
| dd5aca | 282 | // vesicle_volume(vesicle); |
| SP | 283 | // fprintf(stderr,"Volume after success=%1.16e\n", vesicle->volume); |
| aec47d | 284 | return TS_SUCCESS; |
| SP | 285 | } |
| 286 | ||
| fedf2b | 287 | |
| M | 288 | ts_bool single_poly_vertex_move(ts_vesicle *vesicle,ts_poly *poly,ts_vertex *vtx,ts_double *rn){ |
| 289 | ts_uint i; | |
| 290 | ts_bool retval; | |
| 291 | ts_uint cellidx; | |
| 304510 | 292 | // ts_double delta_energy; |
| fedf2b | 293 | ts_double costheta,sintheta,phi,r; |
| 304510 | 294 | ts_double dist; |
| fedf2b | 295 | //This will hold all the information of vtx and its neighbours |
| M | 296 | ts_vertex backupvtx; |
| 304510 | 297 | // ts_bond backupbond[2]; |
| fedf2b | 298 | memcpy((void *)&backupvtx,(void *)vtx,sizeof(ts_vertex)); |
| M | 299 | |
| 300 | //random move in a sphere with radius stepsize: | |
| 301 | r=vesicle->stepsize*rn[0]; | |
| 302 | phi=rn[1]*2*M_PI; | |
| 303 | costheta=2*rn[2]-1; | |
| 304 | sintheta=sqrt(1-pow(costheta,2)); | |
| 305 | vtx->x=vtx->x+r*sintheta*cos(phi); | |
| 306 | vtx->y=vtx->y+r*sintheta*sin(phi); | |
| 307 | vtx->z=vtx->z+r*costheta; | |
| 308 | ||
| 309 | ||
| 310 | //distance with neighbours check | |
| 304510 | 311 | for(i=0;i<vtx->neigh_no;i++){ |
| M | 312 | dist=vtx_distance_sq(vtx,vtx->neigh[i]); |
| 313 | if(dist<1.0 || dist>vesicle->dmax) { | |
| 314 | vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); | |
| 315 | return TS_FAIL; | |
| 316 | } | |
| 317 | } | |
| 318 | ||
| 319 | // Distance with grafted vesicle-vertex check: | |
| 320 | if(vtx==poly->vlist->vtx[0]){ | |
| 321 | dist=vtx_distance_sq(vtx,poly->grafted_vtx); | |
| 322 | if(dist<1.0 || dist>vesicle->dmax) { | |
| 323 | vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); | |
| 324 | return TS_FAIL; | |
| 325 | } | |
| 326 | } | |
| 327 | ||
| fedf2b | 328 | |
| M | 329 | //self avoidance check with distant vertices |
| 330 | cellidx=vertex_self_avoidance(vesicle, vtx); | |
| 331 | //check occupation number | |
| 332 | retval=cell_occupation_number_and_internal_proximity(vesicle->clist,cellidx,vtx); | |
| 333 | ||
| 334 | if(retval==TS_FAIL){ | |
| 335 | vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); | |
| 336 | return TS_FAIL; | |
| 337 | } | |
| 338 | ||
| 339 | ||
| 340 | //if all the tests are successful, then energy for vtx and neighbours is calculated | |
| 304510 | 341 | /* Energy ignored for now! |
| fedf2b | 342 | delta_energy=0; |
| M | 343 | for(i=0;i<vtx->bond_no;i++){ |
| 344 | memcpy((void *)&backupbond[i],(void *)vtx->bond[i],sizeof(ts_bond)); | |
| 345 | ||
| 346 | vtx->bond[i]->bond_length=sqrt(vtx_distance_sq(vtx->bond[i]->vtx1,vtx->bond[i]->vtx2)); | |
| 347 | bond_energy(vtx->bond[i],poly); | |
| 348 | delta_energy+= vtx->bond[i]->energy - backupbond[i].energy; | |
| 349 | } | |
| 350 | ||
| 351 | if(vtx==poly->vlist->vtx[0]){ | |
| 352 | delta_energy+= | |
| 353 | (pow(sqrt(vtx_distance_sq(vtx, poly->grafted_vtx)-1),2)- | |
| 354 | pow(sqrt(vtx_distance_sq(&backupvtx, poly->grafted_vtx)-1),2)) *poly->k; | |
| 355 | ||
| 356 | } | |
| 357 | ||
| 358 | ||
| 359 | if(delta_energy>=0){ | |
| 360 | #ifdef TS_DOUBLE_DOUBLE | |
| 361 | if(exp(-delta_energy)< drand48() ) | |
| 362 | #endif | |
| 363 | #ifdef TS_DOUBLE_FLOAT | |
| 364 | if(expf(-delta_energy)< (ts_float)drand48()) | |
| 365 | #endif | |
| 366 | #ifdef TS_DOUBLE_LONGDOUBLE | |
| 367 | if(expl(-delta_energy)< (ts_ldouble)drand48()) | |
| 368 | #endif | |
| 369 | { | |
| 370 | //not accepted, reverting changes | |
| 371 | vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); | |
| 372 | for(i=0;i<vtx->bond_no;i++){ | |
| 373 | vtx->bond[i]=memcpy((void *)vtx->bond[i],(void *)&backupbond[i],sizeof(ts_bond)); | |
| 374 | } | |
| 375 | ||
| 376 | return TS_FAIL; | |
| 377 | } | |
| 378 | } | |
| 304510 | 379 | */ |
| fedf2b | 380 | |
| M | 381 | // oldcellidx=vertex_self_avoidance(vesicle, &backupvtx[0]); |
| 382 | if(vtx->cell!=vesicle->clist->cell[cellidx]){ | |
| 383 | retval=cell_add_vertex(vesicle->clist->cell[cellidx],vtx); | |
| 384 | // if(retval==TS_SUCCESS) cell_remove_vertex(vesicle->clist->cell[oldcellidx],vtx); | |
| 385 | if(retval==TS_SUCCESS) cell_remove_vertex(backupvtx.cell,vtx); | |
| 386 | } | |
| 387 | // if(oldcellidx); | |
| 388 | //END MONTE CARLOOOOOOO | |
| 389 | return TS_SUCCESS; | |
| 390 | } | |
| 58230a | 391 | |
| M | 392 | |
| 393 | ||
| 394 | ||
| 395 | ts_bool single_filament_vertex_move(ts_vesicle *vesicle,ts_poly *poly,ts_vertex *vtx,ts_double *rn){ | |
| 396 | ts_uint i; | |
| 397 | ts_bool retval; | |
| 398 | ts_uint cellidx; | |
| b30f45 | 399 | ts_double delta_energy; |
| 58230a | 400 | ts_double costheta,sintheta,phi,r; |
| M | 401 | ts_double dist[2]; |
| 402 | //This will hold all the information of vtx and its neighbours | |
| b30f45 | 403 | ts_vertex backupvtx,backupneigh[2]; |
| 58230a | 404 | ts_bond backupbond[2]; |
| b30f45 | 405 | |
| M | 406 | //backup vertex: |
| 58230a | 407 | memcpy((void *)&backupvtx,(void *)vtx,sizeof(ts_vertex)); |
| M | 408 | |
| 409 | //random move in a sphere with radius stepsize: | |
| 410 | r=vesicle->stepsize*rn[0]; | |
| 411 | phi=rn[1]*2*M_PI; | |
| 412 | costheta=2*rn[2]-1; | |
| 413 | sintheta=sqrt(1-pow(costheta,2)); | |
| 414 | vtx->x=vtx->x+r*sintheta*cos(phi); | |
| 415 | vtx->y=vtx->y+r*sintheta*sin(phi); | |
| 416 | vtx->z=vtx->z+r*costheta; | |
| 417 | ||
| 418 | ||
| 419 | //distance with neighbours check | |
| 420 | for(i=0;i<vtx->bond_no;i++){ | |
| 421 | dist[i]=vtx_distance_sq(vtx->bond[i]->vtx1,vtx->bond[i]->vtx2); | |
| 422 | if(dist[i]<1.0 || dist[i]>vesicle->dmax) { | |
| 423 | vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); | |
| 424 | return TS_FAIL; | |
| 425 | } | |
| 426 | } | |
| 427 | ||
| fe24d2 | 428 | // TODO: Maybe faster if checks only nucleus-neighboring cells |
| M | 429 | // Nucleus penetration check: |
| 430 | if (vtx->x*vtx->x + vtx->y*vtx->y + vtx->z*vtx->z < vesicle->R_nucleus){ | |
| 431 | vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); | |
| 432 | return TS_FAIL; | |
| 433 | } | |
| 434 | ||
| 58230a | 435 | |
| M | 436 | //self avoidance check with distant vertices |
| 437 | cellidx=vertex_self_avoidance(vesicle, vtx); | |
| 438 | //check occupation number | |
| 439 | retval=cell_occupation_number_and_internal_proximity(vesicle->clist,cellidx,vtx); | |
| 440 | if(retval==TS_FAIL){ | |
| 441 | vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); | |
| 442 | return TS_FAIL; | |
| 443 | } | |
| 444 | ||
| 445 | //backup bonds | |
| 446 | for(i=0;i<vtx->bond_no;i++){ | |
| 447 | memcpy(&backupbond[i],vtx->bond[i], sizeof(ts_bond)); | |
| 448 | vtx->bond[i]->bond_length=sqrt(dist[i]); | |
| 449 | bond_vector(vtx->bond[i]); | |
| b30f45 | 450 | } |
| M | 451 | |
| 452 | //backup neighboring vertices: | |
| 453 | for(i=0;i<vtx->neigh_no;i++){ | |
| 454 | memcpy(&backupneigh[i],vtx->neigh[i], sizeof(ts_vertex)); | |
| 58230a | 455 | } |
| M | 456 | |
| 457 | //if all the tests are successful, then energy for vtx and neighbours is calculated | |
| b30f45 | 458 | delta_energy=0; |
| M | 459 | |
| 460 | if(vtx->bond_no == 2){ | |
| 461 | 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; | |
| 462 | delta_energy += vtx->energy - backupvtx.energy; | |
| 58230a | 463 | } |
| M | 464 | |
| b30f45 | 465 | for(i=0;i<vtx->neigh_no;i++){ |
| M | 466 | if(vtx->neigh[i]->bond_no == 2){ |
| 467 | 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; | |
| 468 | delta_energy += vtx->neigh[i]->energy - backupneigh[i].energy; | |
| 469 | } | |
| 58230a | 470 | } |
| M | 471 | |
| b30f45 | 472 | // poly->k is filament persistence length (in units l_min) |
| M | 473 | delta_energy *= poly->k; |
| 58230a | 474 | |
| M | 475 | if(delta_energy>=0){ |
| 476 | #ifdef TS_DOUBLE_DOUBLE | |
| 477 | if(exp(-delta_energy)< drand48() ) | |
| 478 | #endif | |
| 479 | #ifdef TS_DOUBLE_FLOAT | |
| 480 | if(expf(-delta_energy)< (ts_float)drand48()) | |
| 481 | #endif | |
| 482 | #ifdef TS_DOUBLE_LONGDOUBLE | |
| 483 | if(expl(-delta_energy)< (ts_ldouble)drand48()) | |
| 484 | #endif | |
| 485 | { | |
| 486 | //not accepted, reverting changes | |
| 487 | vtx=memcpy((void *)vtx,(void *)&backupvtx,sizeof(ts_vertex)); | |
| b30f45 | 488 | for(i=0;i<vtx->neigh_no;i++){ |
| M | 489 | memcpy(vtx->neigh[i],&backupneigh[i],sizeof(ts_vertex)); |
| 490 | } | |
| 58230a | 491 | for(i=0;i<vtx->bond_no;i++){ |
| b30f45 | 492 | vtx->bond[i]=memcpy((void *)vtx->bond[i],(void *)&backupbond[i],sizeof(ts_bond)); |
| 58230a | 493 | } |
| M | 494 | |
| 495 | return TS_FAIL; | |
| 496 | } | |
| 497 | } | |
| 498 | ||
| b30f45 | 499 | |
| 58230a | 500 | // oldcellidx=vertex_self_avoidance(vesicle, &backupvtx[0]); |
| M | 501 | if(vtx->cell!=vesicle->clist->cell[cellidx]){ |
| 502 | retval=cell_add_vertex(vesicle->clist->cell[cellidx],vtx); | |
| 503 | // if(retval==TS_SUCCESS) cell_remove_vertex(vesicle->clist->cell[oldcellidx],vtx); | |
| 504 | if(retval==TS_SUCCESS) cell_remove_vertex(backupvtx.cell,vtx); | |
| 505 | } | |
| 506 | // if(oldcellidx); | |
| 507 | //END MONTE CARLOOOOOOO | |
| 508 | return TS_SUCCESS; | |
| 509 | } | |