Trisurf Monte Carlo simulator
mihaf
2013-12-03 8db569a42c280be13ea9edbe4c528e0041b6fd3f
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>
7
8
1d5dff 9 ts_poly    *init_poly(ts_uint n, ts_vertex *grafted_vtx){
M 10     ts_poly    *poly=(ts_poly *)calloc(1,sizeof(ts_poly));
11     poly->vlist = init_vertex_list(n);
12     poly->blist = init_bond_list();
13     poly->grafted_vtx = grafted_vtx;
14     grafted_vtx->grafted_poly = poly;
15
16     ts_uint i;
8db569 17     for(i=0;i<n-1;i++){
1d5dff 18         vtx_add_cneighbour(poly->blist, poly->vlist->vtx[i], poly->vlist->vtx[i+1]);
8db569 19         vtx_add_neighbour(poly->vlist->vtx[i+1], poly->vlist->vtx[i]);
1d5dff 20     }
M 21
22     return poly;
23 }
24
25
8db569 26 ts_poly_list *init_poly_list(ts_uint n_poly, ts_uint n_mono, ts_vertex_list *vlist){
1d5dff 27     ts_poly_list *poly_list=(ts_poly_list *)calloc(1,sizeof(ts_poly_list));
8db569 28     poly_list->poly    = (ts_poly **)calloc(n_poly,sizeof(ts_poly *));
M 29     ts_uint i=0,j=0;
30     ts_uint gvtxi;
31     ts_double xnorm,ynorm,znorm,normlength;
1d5dff 32
M 33     if (n_poly > vlist->n){fatal("Number of polymers larger then numbero f vertices on a vesicle.",310);}
34     
35     while(i<n_poly){
8db569 36         gvtxi = rand() % vlist->n;
1d5dff 37         if (vlist->vtx[gvtxi]->grafted_poly == NULL){
8db569 38         poly_list->poly[i] = init_poly(n_mono, vlist->vtx[gvtxi]);
1d5dff 39         i++;
M 40         }
41     }
42     
43     poly_list->n = n_poly;
44
8db569 45 /* Make straight poylmers normal to membrane. Dist. between poly vertices put to 1*/
M 46     for (i=0;i<poly_list->n;i++){
47
48         xnorm=0.0;
49         ynorm=0.0;
50         znorm=0.0;
51         for (j=0;j<poly_list->poly[i]->grafted_vtx->tristar_no;j++){
52             xnorm+=poly_list->poly[i]->grafted_vtx->tristar[j]->xnorm;
53             ynorm+=poly_list->poly[i]->grafted_vtx->tristar[j]->ynorm;
54             znorm+=poly_list->poly[i]->grafted_vtx->tristar[j]->znorm;    
55         }
56         normlength=sqrt(xnorm*xnorm+ynorm*ynorm+znorm*znorm);
57         xnorm=xnorm/normlength;
58         ynorm=ynorm/normlength;
59         znorm=znorm/normlength;
60
61         for (j=0;j<poly_list->poly[i]->vlist->n;j++){
62             poly_list->poly[i]->vlist->vtx[j]->x = poly_list->poly[i]->grafted_vtx->x + xnorm*(ts_double)(j+1);
63             poly_list->poly[i]->vlist->vtx[j]->y = poly_list->poly[i]->grafted_vtx->y + ynorm*(ts_double)(j+1);
64             poly_list->poly[i]->vlist->vtx[j]->z = poly_list->poly[i]->grafted_vtx->z + znorm*(ts_double)(j+1);
65         }
66     }
67
1d5dff 68     return poly_list;
M 69 }
70
8db569 71
M 72 ts_bool poly_free(ts_poly *poly){
73
74     if (poly->grafted_vtx!=NULL){
75         poly->grafted_vtx->grafted_poly=NULL;
76     }
77     vtx_list_free(poly->vlist);
78     bond_list_free(poly->blist);
79     free(poly);
80
81     return TS_SUCCESS;
82 }
83
84 ts_bool poly_list_free(ts_poly_list *poly_list){
85     ts_uint i;
86
87     for(i=0;i<poly_list->n;i++){
88         poly_free(poly_list->poly[i]);
89     }
90     free(poly_list->poly);
91     free(poly_list);
92     
93     return TS_SUCCESS;
94 }