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 *)); |
40aa5b
|
29 |
ts_uint i=0,j=0, idx; |
8db569
|
30 |
ts_uint gvtxi; |
M |
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++){ |
40aa5b
|
52 |
xnorm-=poly_list->poly[i]->grafted_vtx->tristar[j]->xnorm; |
SP |
53 |
ynorm-=poly_list->poly[i]->grafted_vtx->tristar[j]->ynorm; |
|
54 |
znorm-=poly_list->poly[i]->grafted_vtx->tristar[j]->znorm; |
8db569
|
55 |
} |
M |
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 |
|
40aa5b
|
68 |
//index correction for polymeres. Important, since each vtx has to have unique id |
SP |
69 |
idx=vlist->n; |
|
70 |
for(i=0;i<n_poly;i++){ |
|
71 |
for(j=0;j<n_mono;j++,idx++){ |
|
72 |
|
|
73 |
poly_list->poly[i]->vlist->vtx[j]->idx=idx; |
|
74 |
|
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
|
1d5dff
|
79 |
return poly_list; |
M |
80 |
} |
|
81 |
|
8db569
|
82 |
|
M |
83 |
ts_bool poly_free(ts_poly *poly){ |
|
84 |
|
|
85 |
if (poly->grafted_vtx!=NULL){ |
|
86 |
poly->grafted_vtx->grafted_poly=NULL; |
|
87 |
} |
|
88 |
vtx_list_free(poly->vlist); |
|
89 |
bond_list_free(poly->blist); |
|
90 |
free(poly); |
|
91 |
|
|
92 |
return TS_SUCCESS; |
|
93 |
} |
|
94 |
|
|
95 |
ts_bool poly_list_free(ts_poly_list *poly_list){ |
|
96 |
ts_uint i; |
|
97 |
|
|
98 |
for(i=0;i<poly_list->n;i++){ |
|
99 |
poly_free(poly_list->poly[i]); |
|
100 |
} |
|
101 |
free(poly_list->poly); |
|
102 |
free(poly_list); |
|
103 |
|
|
104 |
return TS_SUCCESS; |
|
105 |
} |