Trisurf Monte Carlo simulator
Samo Penic
2014-03-21 42641cde38cfd1d27a2031604cc1397b5bd2849b
commit | author | age
8db569 1 #include"general.h"
M 2 #include"poly.h"
3 #include<stdlib.h>
4 #include"vertex.h"
5 #include"bond.h"
6 #include<math.h>
fedf2b 7 #include"energy.h"
8db569 8
bcf455 9 ts_bool poly_assign_filament_xi(ts_vesicle *vesicle, ts_tape *tape){
M 10     ts_uint i;
11
12     for(i=0;i<vesicle->filament_list->n;i++){
13      vesicle->filament_list->poly[i]->k = tape->xi;
14         }
15     
16     return TS_SUCCESS;
17 }
18
19
48bb92 20 ts_bool poly_assign_spring_const(ts_vesicle *vesicle){
M 21     ts_uint i;
22
23     for(i=0;i<vesicle->poly_list->n;i++){
24      vesicle->poly_list->poly[i]->k = vesicle->spring_constant;
25         }
26     
27     return TS_SUCCESS;
28 }
8db569 29
1d5dff 30 ts_poly    *init_poly(ts_uint n, ts_vertex *grafted_vtx){
M 31     ts_poly    *poly=(ts_poly *)calloc(1,sizeof(ts_poly));
32     poly->vlist = init_vertex_list(n);
33     poly->blist = init_bond_list();
624f81 34     if (grafted_vtx!=NULL){
M 35         poly->grafted_vtx = grafted_vtx;
36         grafted_vtx->grafted_poly = poly;
37     }
1d5dff 38
M 39     ts_uint i;
8db569 40     for(i=0;i<n-1;i++){
1d5dff 41         vtx_add_cneighbour(poly->blist, poly->vlist->vtx[i], poly->vlist->vtx[i+1]);
8db569 42         vtx_add_neighbour(poly->vlist->vtx[i+1], poly->vlist->vtx[i]);
1d5dff 43     }
M 44
48bb92 45     for(i=0;i<poly->blist->n;i++){
M 46     poly->blist->bond[i]->bond_length=sqrt(vtx_distance_sq(poly->blist->bond[i]->vtx1,poly->blist->bond[i]->vtx2));
fedf2b 47     bond_energy(poly->blist->bond[i],poly);
48bb92 48     }
M 49
1d5dff 50     return poly;
M 51 }
52
53
624f81 54 ts_poly_list *init_poly_list(ts_uint n_poly, ts_uint n_mono, ts_vertex_list *vlist, ts_vesicle *vesicle){
1d5dff 55     ts_poly_list *poly_list=(ts_poly_list *)calloc(1,sizeof(ts_poly_list));
8db569 56     poly_list->poly    = (ts_poly **)calloc(n_poly,sizeof(ts_poly *));
3c1ac1 57     ts_uint i=0,j=0; //idx;
8db569 58     ts_uint gvtxi;
M 59     ts_double xnorm,ynorm,znorm,normlength;
624f81 60     ts_double dphi,dh;
M 61     ts_uint ji;
1d5dff 62
624f81 63     // Grafting polymers:
M 64     if (vlist!=NULL){
65         if (n_poly > vlist->n){fatal("Number of polymers larger then numbero f vertices on a vesicle.",310);}
1d5dff 66     
624f81 67         while(i<n_poly){
M 68             gvtxi = rand() % vlist->n;
69             if (vlist->vtx[gvtxi]->grafted_poly == NULL){
70             poly_list->poly[i] = init_poly(n_mono, vlist->vtx[gvtxi]);
71             i++;
72             }
1d5dff 73         }
M 74     }
624f81 75     else
M 76     {
77         for(i=0;i<n_poly;i++){
78             poly_list->poly[i] = init_poly(n_mono, NULL);
79         }
80     }
81
1d5dff 82     poly_list->n = n_poly;
M 83
624f81 84     if (vlist!=NULL){
M 85     /* Make straight grafted poylmers normal to membrane (polymer brush). Dist. between poly vertices put to 1*/
86         for (i=0;i<poly_list->n;i++){
87     
88             xnorm=0.0;
89             ynorm=0.0;
90             znorm=0.0;
91             for (j=0;j<poly_list->poly[i]->grafted_vtx->tristar_no;j++){
92                 xnorm-=poly_list->poly[i]->grafted_vtx->tristar[j]->xnorm;
93                 ynorm-=poly_list->poly[i]->grafted_vtx->tristar[j]->ynorm;
94                 znorm-=poly_list->poly[i]->grafted_vtx->tristar[j]->znorm;    
95             }
96             normlength=sqrt(xnorm*xnorm+ynorm*ynorm+znorm*znorm);
97             xnorm=xnorm/normlength;
98             ynorm=ynorm/normlength;
99             znorm=znorm/normlength;
8db569 100
624f81 101             for (j=0;j<poly_list->poly[i]->vlist->n;j++){
M 102                 poly_list->poly[i]->vlist->vtx[j]->x = poly_list->poly[i]->grafted_vtx->x + xnorm*(ts_double)(j+1);
103                 poly_list->poly[i]->vlist->vtx[j]->y = poly_list->poly[i]->grafted_vtx->y + ynorm*(ts_double)(j+1);
104                 poly_list->poly[i]->vlist->vtx[j]->z = poly_list->poly[i]->grafted_vtx->z + znorm*(ts_double)(j+1);
105             }
8db569 106         }
624f81 107     }
M 108     else
109     {
110     /* Make filaments inside the vesicle. Helix with radius... Dist. between poly vertices put to 1*/
402e8f 111         dphi = 2.0*asin(1.0/2.0/vesicle->R_nucleus)*1.001;
M 112         dh = dphi/2.0/M_PI*1.001;
624f81 113         for(i=0;i<poly_list->n;i++){
M 114             for (j=0;j<poly_list->poly[i]->vlist->n;j++){
115                 ji = j + i*poly_list->poly[i]->vlist->n;
116                 poly_list->poly[i]->vlist->vtx[j]->x = vesicle->R_nucleus*cos(ji*dphi);
117                 poly_list->poly[i]->vlist->vtx[j]->y = vesicle->R_nucleus*sin(ji*dphi);
58230a 118                 poly_list->poly[i]->vlist->vtx[j]->z = ji*dh - (dh*poly_list->n*poly_list->poly[i]->vlist->n/2.0);
624f81 119             }
8db569 120         }
M 121     }
122
40aa5b 123         //index correction for polymeres. Important, since each vtx has to have unique id
3c1ac1 124 /*    idx=vlist->n;
40aa5b 125     for(i=0;i<n_poly;i++){
SP 126         for(j=0;j<n_mono;j++,idx++){
127
128             poly_list->poly[i]->vlist->vtx[j]->idx=idx;
129
130         }
131     }
3c1ac1 132 */
40aa5b 133
1d5dff 134     return poly_list;
M 135 }
136
8db569 137
M 138 ts_bool poly_free(ts_poly *poly){
139
140     if (poly->grafted_vtx!=NULL){
141         poly->grafted_vtx->grafted_poly=NULL;
142     }
143     vtx_list_free(poly->vlist);
144     bond_list_free(poly->blist);
145     free(poly);
146
147     return TS_SUCCESS;
148 }
149
150 ts_bool poly_list_free(ts_poly_list *poly_list){
151     ts_uint i;
152
153     for(i=0;i<poly_list->n;i++){
154         poly_free(poly_list->poly[i]);
155     }
156     free(poly_list->poly);
157     free(poly_list);
158     
159     return TS_SUCCESS;
160 }