From a752b502e11eababc1bae73434b9dde9380c0c59 Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Wed, 03 Sep 2014 21:19:57 +0000 Subject: [PATCH] Added capability to decrease number of poly in tape and random polymeres are removed from the vesicle in dump aswell. --- src/main.c | 14 ++++++++++++++ src/poly.c | 41 ++++++++++++++++++++++++++++++++++++++++- src/tape | 2 +- src/poly.h | 2 ++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 00bd95f..8a3a550 100644 --- a/src/main.c +++ b/src/main.c @@ -73,6 +73,20 @@ ts_fprintf(stdout, "Simulation already completed. if you want to rerun it try with --force-from-tape or --reset-iteration-count\n\n"); return 0; } + + /* if requested in tape, we can have smaller number of polymeres attached to membrane than the number of polymeres in dump file */ + if(vesicle->tape->npoly != vesicle->poly_list->n){ + + ts_fprintf(stdout,"(INFO) the number of polymeres attached to membrane in tape is different than a number of polymeres in dump file!\n"); + if(vesicle->tape->npoly > vesicle->poly_list->n){ + ts_fprintf(stdout,"(INFO) It is possible to decrease the number of polymeres on the membrane, but it is not allowed to increase its number. The maximal allowed number in tape is %d The execution of program will terminate!\n",vesicle->poly_list->n); + fatal("Terminating due to increase of number of polymeres",1); + } else { + remove_random_polymeres(vesicle->poly_list, vesicle->poly_list->n - vesicle->tape->npoly); + ts_fprintf(stdout,"(INFO)\n(INFO) The new number of polymeres from tape is %d.\n\n",vesicle->poly_list->n); + + } + } } run_simulation(vesicle, tape->mcsweeps, tape->inititer, tape->iterations, start_iteration); diff --git a/src/poly.c b/src/poly.c index b2b13f9..6af59e9 100644 --- a/src/poly.c +++ b/src/poly.c @@ -61,7 +61,7 @@ // 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; @@ -172,3 +172,42 @@ 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; +} + diff --git a/src/poly.h b/src/poly.h index 26dd444..2b37c92 100644 --- a/src/poly.h +++ b/src/poly.h @@ -16,4 +16,6 @@ ts_bool poly_assign_filament_xi(ts_vesicle *vesicle, ts_tape *tape); +ts_poly *remove_poly_with_index(ts_poly_list *poly_list, ts_uint idx); +ts_bool remove_random_polymeres(ts_poly_list *poly_list, ts_uint number); #endif diff --git a/src/tape b/src/tape index 034c8a4..b0ac65c 100644 --- a/src/tape +++ b/src/tape @@ -23,7 +23,7 @@ ####### Polymer (brush) definitions ########### # npoly is a number of polymers attached to npoly distinct vertices on vesicle -npoly=0 +npoly=500 # nmono is a number of monomers in each polymer nmono=10 # Spring constant between monomers of the polymer -- Gitblit v1.9.3