| | |
| | | /* vim: set ts=4 sts=4 sw=4 noet : */ |
| | | #include"general.h" |
| | | #include"poly.h" |
| | | #include<stdlib.h> |
| | |
| | | |
| | | // Grafting polymers: |
| | | if (vlist!=NULL){ |
| | | if (n_poly > vlist->n){fatal("Number of polymers larger then numbero f vertices on a vesicle.",310);} |
| | | if (n_poly > vlist->n){fatal("Number of polymers larger than numbero f vertices on a vesicle.",310);} |
| | | |
| | | while(i<n_poly){ |
| | | gvtxi = rand() % vlist->n; |
| | |
| | | |
| | | if (vlist!=NULL){ |
| | | /* Make straight grafted poylmers normal to membrane (polymer brush). Dist. between poly vertices put to 1*/ |
| | | ts_int intpoly=vesicle->tape->internal_poly; |
| | | for (i=0;i<poly_list->n;i++){ |
| | | |
| | | xnorm=0.0; |
| | |
| | | znorm-=poly_list->poly[i]->grafted_vtx->tristar[j]->znorm; |
| | | } |
| | | normlength=sqrt(xnorm*xnorm+ynorm*ynorm+znorm*znorm); |
| | | if(intpoly && i%2){ |
| | | normlength=-normlength; |
| | | } |
| | | xnorm=xnorm/normlength; |
| | | ynorm=ynorm/normlength; |
| | | znorm=znorm/normlength; |
| | |
| | | |
| | | ts_bool poly_free(ts_poly *poly){ |
| | | |
| | | if (poly->grafted_vtx!=NULL){ |
| | | poly->grafted_vtx->grafted_poly=NULL; |
| | | } |
| | | // if (poly->grafted_vtx!=NULL){ |
| | | // poly->grafted_vtx->grafted_poly=NULL; |
| | | // } |
| | | vtx_list_free(poly->vlist); |
| | | bond_list_free(poly->blist); |
| | | free(poly); |
| | |
| | | |
| | | ts_bool poly_list_free(ts_poly_list *poly_list){ |
| | | ts_uint i; |
| | | |
| | | //fprintf(stderr,"no. of polys=%d\n", poly_list->n); |
| | | for(i=0;i<poly_list->n;i++){ |
| | | // fprintf(stderr,"%d poly address in mem=%ld\n",i+1,(long)&(poly_list->poly[i])); |
| | | poly_free(poly_list->poly[i]); |
| | | } |
| | | free(poly_list->poly); |
| | |
| | | |
| | | return TS_SUCCESS; |
| | | } |
| | | |
| | | |
| | | ts_poly *remove_poly_with_index(ts_poly_list *poly_list, ts_uint idx){ |
| | | ts_uint i; |
| | | ts_poly *removed_poly=poly_list->poly[idx]; |
| | | |
| | | poly_list->n--; //decrease the total number of polymeres |
| | | for(i=idx;i<poly_list->n;i++){ //move the rest of the polymeres up. |
| | | poly_list->poly[i]=poly_list->poly[i+1]; |
| | | // poly_list->poly[idx]->idx=idx; |
| | | } |
| | | |
| | | return removed_poly; |
| | | } |
| | | |
| | | |
| | | ts_bool remove_random_polymeres(ts_poly_list *poly_list, ts_uint number){ |
| | | |
| | | ts_uint i, idx; |
| | | ts_poly *poly; |
| | | |
| | | ts_poly **new_poly_array; |
| | | if(number>poly_list->n) fatal("The number of polymeres to be removed from the list is greater than the number of total polymeres in the list",999); |
| | | for(i=number;i>0;i--){ |
| | | idx=rand() % poly_list->n; |
| | | poly=remove_poly_with_index(poly_list, idx); |
| | | poly_free(poly); |
| | | } |
| | | printf("Addr before %ld\n", (long)poly_list->poly); |
| | | new_poly_array=(ts_poly **)calloc(poly_list->n,sizeof(ts_poly *)); |
| | | for(i=0;i<poly_list->n;i++){ |
| | | new_poly_array[i]=poly_list->poly[i]; |
| | | } |
| | | free(poly_list->poly); |
| | | poly_list->poly=new_poly_array; |
| | | printf("Addr after %ld\n", (long)poly_list->poly); |
| | | return TS_SUCCESS; |
| | | } |
| | | |