00001 00002 #include "../headers/voronoi_lst.h" 00003 00004 /* 00005 00006 ## GENERAL INFORMATION 00007 ## 00008 ## FILE voronoi_lst.c 00009 ## AUTHORS P. Schmidtke and V. Le Guilloux 00010 ## LAST MODIFIED 02-12-08 00011 ## 00012 ## SPECIFICATIONS 00013 ## 00014 ## Routines dealing with chained list of vertices. 00015 ## 00016 ## MODIFICATIONS HISTORY 00017 ## 00018 ## 02-12-08 (v) Comments UTD 00019 ## 01-04-08 (v) Added template for comments and creation of history 00020 ## 01-01-08 (vp) Created (random date...) 00021 ## 00022 ## TODO or SUGGESTIONS 00023 ## 00024 00025 */ 00026 00027 /* 00028 COPYRIGHT DISCLAIMER 00029 00030 Vincent Le Guilloux, Peter Schmidtke and Pierre Tuffery, hereby 00031 disclaim all copyright interest in the program “fpocket” (which 00032 performs protein cavity detection) written by Vincent Le Guilloux and Peter 00033 Schmidtke. 00034 00035 Vincent Le Guilloux 28 November 2008 00036 Peter Schmidtke 28 November 2008 00037 Pierre Tuffery 28 November 2008 00038 00039 GNU GPL 00040 00041 This file is part of the fpocket package. 00042 00043 fpocket is free software: you can redistribute it and/or modify 00044 it under the terms of the GNU General Public License as published by 00045 the Free Software Foundation, either version 3 of the License, or 00046 (at your option) any later version. 00047 00048 fpocket is distributed in the hope that it will be useful, 00049 but WITHOUT ANY WARRANTY; without even the implied warranty of 00050 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00051 GNU General Public License for more details. 00052 00053 You should have received a copy of the GNU General Public License 00054 along with fpocket. If not, see <http://www.gnu.org/licenses/>. 00055 00056 **/ 00057 00058 /** 00059 ## FONCTION: 00060 lst_vertices_alloc 00061 00062 ## SPECIFICATION: 00063 Allocate a list of vertices 00064 00065 ## PARAMETRES: 00066 00067 ## RETURN: 00068 c_lst_vertices* 00069 00070 */ 00071 c_lst_vertices *c_lst_vertices_alloc(void) 00072 { 00073 c_lst_vertices *lst = (c_lst_vertices *)my_malloc(sizeof(c_lst_vertices)) ; 00074 00075 lst->first = NULL ; 00076 lst->last = NULL ; 00077 lst->current = NULL ; 00078 lst->n_vertices = 0 ; 00079 00080 return lst ; 00081 } 00082 00083 /** 00084 ## FONCTION: 00085 node_vertice_alloc 00086 00087 ## SPECIFICATION: 00088 Allocate memory for one vertice node. 00089 00090 ## PARAMETRES: 00091 @ s_vvertice *vertice : pointer to the vertice to store in the node 00092 00093 ## RETURN: 00094 node_vertice*: Allocated node 00095 00096 */ 00097 node_vertice *node_vertice_alloc(s_vvertice *vertice) 00098 { 00099 node_vertice *n_vertice = (node_vertice *) my_malloc(sizeof(node_vertice)) ; 00100 00101 n_vertice->next = NULL ; 00102 n_vertice->prev = NULL ; 00103 n_vertice->vertice = vertice ; 00104 00105 return n_vertice ; 00106 } 00107 00108 /** 00109 ## FONCTION: 00110 c_vertice_lst_add_first 00111 00112 ## SPECIFICATION: 00113 Add a vertice at the first position of the list. 00114 00115 ## PARAMETRES: 00116 @ c_lst_vertices *lst : chained list of vertices 00117 @ s_vvertice *vertice : vertice to add 00118 00119 ## RETURN: 00120 node_vertice *: pointer toi the new node. 00121 00122 */ 00123 node_vertice *c_lst_vertices_add_first(c_lst_vertices *lst, s_vvertice *vertice) 00124 { 00125 node_vertice *newn = NULL ; 00126 00127 if(lst) { 00128 newn = node_vertice_alloc(vertice) ; 00129 lst->first->prev = newn ; 00130 newn->next = lst->first ; 00131 00132 lst->first = newn ; 00133 lst->n_vertices += 1 ; 00134 } 00135 00136 return newn ; 00137 } 00138 00139 /** 00140 ## FONCTION: 00141 c_vertice_lst_add_last 00142 00143 ## SPECIFICATION: 00144 Add a vertice at the end of the chained list 00145 00146 ## PARAMETRES: 00147 @ c_lst_pocket *lst : chained list of pockets 00148 @ s_vvertice *vertice : vertice to add 00149 00150 ## RETURN: 00151 node_vertice *: Pointer to the new node 00152 00153 */ 00154 node_vertice *c_lst_vertices_add_last(c_lst_vertices *lst,s_vvertice *vertice) 00155 { 00156 struct node_vertice *newn = NULL ; 00157 00158 if(lst) { 00159 newn = node_vertice_alloc(vertice) ; 00160 if(lst->last) { 00161 newn->prev = lst->last ; 00162 lst->last->next = newn ; 00163 } 00164 else { 00165 lst->first = newn ; 00166 00167 } 00168 lst->last = newn ; 00169 lst->n_vertices += 1 ; 00170 } 00171 00172 return newn ; 00173 } 00174 00175 /** 00176 ## FONCTION: 00177 lst_vertice_free 00178 00179 ## SPECIFICATION: 00180 Free memory of a chained list 00181 00182 ## PARAMETRES: 00183 @ c_lst_vertices *lst: list of voronoi vertices 00184 00185 ## RETURN: 00186 00187 */ 00188 void c_lst_vertices_free(c_lst_vertices *lst) 00189 { 00190 //fprintf(stdout, "Freeing list of vertices\n") ; 00191 node_vertice *next = NULL ; 00192 00193 if(lst) { 00194 lst->current = lst->first ; 00195 while(lst->current) { 00196 next = lst->current->next ; 00197 my_free(lst->current) ; 00198 lst->current = next ; 00199 } 00200 } 00201 00202 lst->first = NULL ; 00203 lst->last = NULL ; 00204 lst->current = NULL ; 00205 00206 my_free(lst) ; 00207 } 00208 00209 /** 00210 ## FUNCTION: 00211 get_vert_contacted_atms 00212 00213 ## SPECIFICATION: 00214 Get the list of atoms contacted by each vertice in the given list of vertices. 00215 00216 ## PARAMETRES: 00217 @ c_lst_vertices *v_lst : The list of vertices of the pocket. 00218 @ int *nneigh : OUTPUT A pointer to the number of neighbour found, 00219 will be modified 00220 00221 ## RETURN: 00222 A tab of pointers to the pocket contacting atoms. 00223 00224 */ 00225 s_atm** get_vert_contacted_atms(c_lst_vertices *v_lst, int *nneigh) 00226 { 00227 int i ; 00228 int nb_neigh = 0 ; 00229 int atm_seen[v_lst->n_vertices * 4] ; 00230 00231 s_atm **neigh = (s_atm **)my_malloc(sizeof(s_atm*)*v_lst->n_vertices * 4) ; 00232 00233 node_vertice *cur = v_lst->first ; 00234 00235 while(cur) { 00236 s_vvertice *vcur = cur->vertice ; 00237 00238 for(i = 0 ; i < 4 ; i++) { 00239 /* For each neighbor, if this atom has not been see yet, add it. */ 00240 if(!in_tab(atm_seen, nb_neigh, vcur->neigh[i]->id)) { 00241 neigh[nb_neigh] = vcur->neigh[i] ; 00242 atm_seen[nb_neigh] = neigh[nb_neigh]->id ; 00243 nb_neigh++ ; 00244 } 00245 } 00246 00247 cur = cur->next ; 00248 } 00249 00250 *nneigh = nb_neigh ; 00251 00252 return neigh ; 00253 }