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 |
|
48bb92
|
8 |
ts_bool poly_assign_spring_const(ts_vesicle *vesicle){ |
M |
9 |
ts_uint i; |
|
10 |
|
|
11 |
for(i=0;i<vesicle->poly_list->n;i++){ |
|
12 |
vesicle->poly_list->poly[i]->k = vesicle->spring_constant; |
|
13 |
} |
|
14 |
|
|
15 |
return TS_SUCCESS; |
|
16 |
} |
8db569
|
17 |
|
1d5dff
|
18 |
ts_poly *init_poly(ts_uint n, ts_vertex *grafted_vtx){ |
M |
19 |
ts_poly *poly=(ts_poly *)calloc(1,sizeof(ts_poly)); |
|
20 |
poly->vlist = init_vertex_list(n); |
|
21 |
poly->blist = init_bond_list(); |
|
22 |
poly->grafted_vtx = grafted_vtx; |
|
23 |
grafted_vtx->grafted_poly = poly; |
|
24 |
|
|
25 |
ts_uint i; |
8db569
|
26 |
for(i=0;i<n-1;i++){ |
1d5dff
|
27 |
vtx_add_cneighbour(poly->blist, poly->vlist->vtx[i], poly->vlist->vtx[i+1]); |
8db569
|
28 |
vtx_add_neighbour(poly->vlist->vtx[i+1], poly->vlist->vtx[i]); |
1d5dff
|
29 |
} |
M |
30 |
|
48bb92
|
31 |
for(i=0;i<poly->blist->n;i++){ |
M |
32 |
poly->blist->bond[i]->bond_length=sqrt(vtx_distance_sq(poly->blist->bond[i]->vtx1,poly->blist->bond[i]->vtx2)); |
|
33 |
} |
|
34 |
|
1d5dff
|
35 |
return poly; |
M |
36 |
} |
|
37 |
|
|
38 |
|
8db569
|
39 |
ts_poly_list *init_poly_list(ts_uint n_poly, ts_uint n_mono, ts_vertex_list *vlist){ |
1d5dff
|
40 |
ts_poly_list *poly_list=(ts_poly_list *)calloc(1,sizeof(ts_poly_list)); |
8db569
|
41 |
poly_list->poly = (ts_poly **)calloc(n_poly,sizeof(ts_poly *)); |
40aa5b
|
42 |
ts_uint i=0,j=0, idx; |
8db569
|
43 |
ts_uint gvtxi; |
M |
44 |
ts_double xnorm,ynorm,znorm,normlength; |
1d5dff
|
45 |
|
M |
46 |
if (n_poly > vlist->n){fatal("Number of polymers larger then numbero f vertices on a vesicle.",310);} |
|
47 |
|
|
48 |
while(i<n_poly){ |
8db569
|
49 |
gvtxi = rand() % vlist->n; |
1d5dff
|
50 |
if (vlist->vtx[gvtxi]->grafted_poly == NULL){ |
8db569
|
51 |
poly_list->poly[i] = init_poly(n_mono, vlist->vtx[gvtxi]); |
1d5dff
|
52 |
i++; |
M |
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
poly_list->n = n_poly; |
|
57 |
|
8db569
|
58 |
/* Make straight poylmers normal to membrane. Dist. between poly vertices put to 1*/ |
M |
59 |
for (i=0;i<poly_list->n;i++){ |
|
60 |
|
|
61 |
xnorm=0.0; |
|
62 |
ynorm=0.0; |
|
63 |
znorm=0.0; |
|
64 |
for (j=0;j<poly_list->poly[i]->grafted_vtx->tristar_no;j++){ |
40aa5b
|
65 |
xnorm-=poly_list->poly[i]->grafted_vtx->tristar[j]->xnorm; |
SP |
66 |
ynorm-=poly_list->poly[i]->grafted_vtx->tristar[j]->ynorm; |
|
67 |
znorm-=poly_list->poly[i]->grafted_vtx->tristar[j]->znorm; |
8db569
|
68 |
} |
M |
69 |
normlength=sqrt(xnorm*xnorm+ynorm*ynorm+znorm*znorm); |
|
70 |
xnorm=xnorm/normlength; |
|
71 |
ynorm=ynorm/normlength; |
|
72 |
znorm=znorm/normlength; |
|
73 |
|
|
74 |
for (j=0;j<poly_list->poly[i]->vlist->n;j++){ |
|
75 |
poly_list->poly[i]->vlist->vtx[j]->x = poly_list->poly[i]->grafted_vtx->x + xnorm*(ts_double)(j+1); |
|
76 |
poly_list->poly[i]->vlist->vtx[j]->y = poly_list->poly[i]->grafted_vtx->y + ynorm*(ts_double)(j+1); |
|
77 |
poly_list->poly[i]->vlist->vtx[j]->z = poly_list->poly[i]->grafted_vtx->z + znorm*(ts_double)(j+1); |
|
78 |
} |
|
79 |
} |
|
80 |
|
40aa5b
|
81 |
//index correction for polymeres. Important, since each vtx has to have unique id |
SP |
82 |
idx=vlist->n; |
|
83 |
for(i=0;i<n_poly;i++){ |
|
84 |
for(j=0;j<n_mono;j++,idx++){ |
|
85 |
|
|
86 |
poly_list->poly[i]->vlist->vtx[j]->idx=idx; |
|
87 |
|
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
|
1d5dff
|
92 |
return poly_list; |
M |
93 |
} |
|
94 |
|
8db569
|
95 |
|
M |
96 |
ts_bool poly_free(ts_poly *poly){ |
|
97 |
|
|
98 |
if (poly->grafted_vtx!=NULL){ |
|
99 |
poly->grafted_vtx->grafted_poly=NULL; |
|
100 |
} |
|
101 |
vtx_list_free(poly->vlist); |
|
102 |
bond_list_free(poly->blist); |
|
103 |
free(poly); |
|
104 |
|
|
105 |
return TS_SUCCESS; |
|
106 |
} |
|
107 |
|
|
108 |
ts_bool poly_list_free(ts_poly_list *poly_list){ |
|
109 |
ts_uint i; |
|
110 |
|
|
111 |
for(i=0;i<poly_list->n;i++){ |
|
112 |
poly_free(poly_list->poly[i]); |
|
113 |
} |
|
114 |
free(poly_list->poly); |
|
115 |
free(poly_list); |
|
116 |
|
|
117 |
return TS_SUCCESS; |
|
118 |
} |