static void writesurftoxpms(t_interf ***surf1,t_interf ***surf2, int tblocks,int xbins, int ybins, int zbins, real bw,real bwz, char **outfiles,int maplevels ) { char numbuf[12]; int n, i, j; real **profile1, **profile2; real max1, max2, min1, min2, *xticks, *yticks; t_rgb lo={0,0,0}; t_rgb hi={1,1,1}; FILE *xpmfile1, *xpmfile2; /*Prepare xpm structures for output*/ /*Allocate memory to tick's and matrices*/ snew (xticks,xbins+1); snew (yticks,ybins+1); profile1=mk_matrix(xbins,ybins,FALSE); profile2=mk_matrix(xbins,ybins,FALSE); for (i=0;i<xbins+1;i++) xticks[i]+=bw; for (j=0;j<ybins+1;j++) yticks[j]+=bw; xpmfile1 = ffopen(outfiles[0],"w"); xpmfile2 = ffopen(outfiles[1],"w"); max1=max2=0.0; min1=min2=zbins*bwz; for(n=0;n<tblocks;n++) { sprintf(numbuf,"tblock: %4i",n); /*Filling matrices for inclusion in xpm-files*/ for(i=0;i<xbins;i++) { for(j=0;j<ybins;j++) { profile1[i][j]=(surf1[n][j+ybins*i])->Z; profile2[i][j]=(surf2[n][j+ybins*i])->Z; /*Finding max and min values*/ if(profile1[i][j]>max1) max1=profile1[i][j]; if(profile1[i][j]<min1) min1=profile1[i][j]; if(profile2[i][j]>max2) max2=profile2[i][j]; if(profile2[i][j]<min2) min2=profile2[i][j]; } } write_xpm(xpmfile1,3,numbuf,"Height","x[nm]","y[nm]",xbins,ybins,xticks,yticks,profile1,min1,max1,lo,hi,&maplevels); write_xpm(xpmfile2,3,numbuf,"Height","x[nm]","y[nm]",xbins,ybins,xticks,yticks,profile2,min2,max2,lo,hi,&maplevels); } ffclose(xpmfile1); ffclose(xpmfile2); sfree(profile1); sfree(profile2); sfree(xticks); sfree(yticks); }
t_mat *init_mat(int n1, gmx_bool b1D) { t_mat *m; snew(m, 1); m->n1 = n1; m->nn = 0; m->b1D = b1D; m->maxrms = 0; m->minrms = 1e20; m->sumrms = 0; m->mat = mk_matrix(n1, n1, b1D); snew(m->erow, n1); snew(m->m_ind, n1); reset_index(m); return m; }
static void jarvis_patrick(int n1,real **mat,int M,int P, real rmsdcut,t_clusters *clust) { t_dist *row; t_clustid *c; int **nnb; int i,j,k,cid,diff,max; bool bChange; real **mcpy=NULL; if (rmsdcut < 0) rmsdcut = 10000; /* First we sort the entries in the RMSD matrix row by row. * This gives us the nearest neighbor list. */ snew(nnb,n1); snew(row,n1); for(i=0; (i<n1); i++) { for(j=0; (j<n1); j++) { row[j].j = j; row[j].dist = mat[i][j]; } qsort(row,n1,sizeof(row[0]),rms_dist_comp); if (M>0) { /* Put the M nearest neighbors in the list */ snew(nnb[i],M+1); for(j=k=0; (k<M) && (j<n1) && (mat[i][row[j].j] < rmsdcut); j++) if (row[j].j != i) { nnb[i][k] = row[j].j; k++; } nnb[i][k] = -1; } else { /* Put all neighbors nearer than rmsdcut in the list */ max=0; k=0; for(j=0; (j<n1) && (mat[i][row[j].j] < rmsdcut); j++) if (row[j].j != i) { if (k >= max) { max += 10; srenew(nnb[i],max); } nnb[i][k] = row[j].j; k++; } if (k == max) srenew(nnb[i],max+1); nnb[i][k] = -1; } } sfree(row); if (debug) { fprintf(debug,"Nearest neighborlist. M = %d, P = %d\n",M,P); for(i=0; (i<n1); i++) { fprintf(debug,"i:%5d nbs:",i); for(j=0; nnb[i][j]>=0; j++) fprintf(debug,"%5d[%5.3f]",nnb[i][j],mat[i][nnb[i][j]]); fprintf(debug,"\n"); } } c = new_clustid(n1); fprintf(stderr,"Linking structures "); /* Use mcpy for temporary storage of booleans */ mcpy = mk_matrix(n1,n1,FALSE); for(i=0; i<n1; i++) for(j=i+1; j<n1; j++) mcpy[i][j] = jp_same(nnb,i,j,P); do { fprintf(stderr,"*"); bChange=FALSE; for(i=0; i<n1; i++) { for(j=i+1; j<n1; j++) if (mcpy[i][j]) { diff = c[j].clust - c[i].clust; if (diff) { bChange = TRUE; if (diff > 0) c[j].clust = c[i].clust; else c[i].clust = c[j].clust; } } } } while (bChange); fprintf(stderr,"\nSorting and renumbering clusters\n"); /* Sort on cluster number */ qsort(c,n1,sizeof(c[0]),clust_id_comp); /* Renumber clusters */ cid = 1; for(k=1; k<n1; k++) { if (c[k].clust != c[k-1].clust) { c[k-1].clust = cid; cid ++; } else c[k-1].clust = cid; } c[k-1].clust = cid; clust->ncl = cid; for(k=0; k<n1; k++) clust->cl[c[k].conf] = c[k].clust; if (debug) for(k=0; (k<n1); k++) fprintf(debug,"Cluster index for conformation %d: %d\n", c[k].conf,c[k].clust); /* Again, I don't see the point in this... (AF) */ /* for(i=0; (i<n1); i++) { */ /* for(j=0; (j<n1); j++) */ /* mcpy[c[i].conf][c[j].conf] = mat[i][j]; */ /* } */ /* for(i=0; (i<n1); i++) { */ /* for(j=0; (j<n1); j++) */ /* mat[i][j] = mcpy[i][j]; */ /* } */ done_matrix(n1,&mcpy); sfree(c); for(i=0; (i<n1); i++) sfree(nnb[i]); sfree(nnb); }