FILE *fflib_open(const char *file) { char *file_fullpath; FILE *fp; file_fullpath = gmxlibfn(file); fprintf(stderr,"Opening force field file %s\n",file_fullpath); fp = ffopen(file_fullpath,"r"); sfree(file_fullpath); return fp; }
static void add_solv(const char *fn, t_atoms *atoms, rvec **x, rvec **v, real **r, int ePBC, matrix box, gmx_atomprop_t aps, real r_distance, int *atoms_added, int *residues_added, real rshell, int max_sol, const output_env_t oenv) { int i, nmol; ivec n_box; char filename[STRLEN]; char title_solvt[STRLEN]; t_atoms *atoms_solvt; rvec *x_solvt, *v_solvt = NULL; real *r_solvt; int ePBC_solvt; matrix box_solvt; int onr, onres; char *lfn; lfn = gmxlibfn(fn); strncpy(filename, lfn, STRLEN); sfree(lfn); snew(atoms_solvt, 1); get_stx_coordnum(filename, &(atoms_solvt->nr)); if (atoms_solvt->nr == 0) { gmx_fatal(FARGS, "No solvent in %s, please check your input\n", filename); } snew(x_solvt, atoms_solvt->nr); if (v) { snew(v_solvt, atoms_solvt->nr); } snew(r_solvt, atoms_solvt->nr); snew(atoms_solvt->resinfo, atoms_solvt->nr); snew(atoms_solvt->atomname, atoms_solvt->nr); snew(atoms_solvt->atom, atoms_solvt->nr); atoms_solvt->pdbinfo = NULL; fprintf(stderr, "Reading solvent configuration%s\n", v_solvt ? " and velocities" : ""); read_stx_conf(filename, title_solvt, atoms_solvt, x_solvt, v_solvt, &ePBC_solvt, box_solvt); fprintf(stderr, "\"%s\"\n", title_solvt); fprintf(stderr, "solvent configuration contains %d atoms in %d residues\n", atoms_solvt->nr, atoms_solvt->nres); fprintf(stderr, "\n"); /* apply pbc for solvent configuration for whole molecules */ rm_res_pbc(atoms_solvt, x_solvt, box_solvt); /* initialise van der waals arrays of solvent configuration */ mk_vdw(atoms_solvt, r_solvt, aps, r_distance); /* calculate the box multiplication factors n_box[0...DIM] */ nmol = 1; for (i = 0; (i < DIM); i++) { n_box[i] = 1; while (n_box[i]*box_solvt[i][i] < box[i][i]) { n_box[i]++; } nmol *= n_box[i]; } fprintf(stderr, "Will generate new solvent configuration of %dx%dx%d boxes\n", n_box[XX], n_box[YY], n_box[ZZ]); /* realloc atoms_solvt for the new solvent configuration */ srenew(atoms_solvt->resinfo, atoms_solvt->nres*nmol); srenew(atoms_solvt->atomname, atoms_solvt->nr*nmol); srenew(atoms_solvt->atom, atoms_solvt->nr*nmol); srenew(x_solvt, atoms_solvt->nr*nmol); if (v_solvt) { srenew(v_solvt, atoms_solvt->nr*nmol); } srenew(r_solvt, atoms_solvt->nr*nmol); /* generate a new solvent configuration */ genconf(atoms_solvt, x_solvt, v_solvt, r_solvt, box_solvt, n_box); #ifdef DEBUG print_stat(x_solvt, atoms_solvt->nr, box_solvt); #endif #ifdef DEBUG print_stat(x_solvt, atoms_solvt->nr, box_solvt); #endif /* Sort the solvent mixture, not the protein... */ sort_molecule(&atoms_solvt, x_solvt, v_solvt, r_solvt); /* add the two configurations */ onr = atoms->nr; onres = atoms->nres; add_conf(atoms, x, v, r, TRUE, ePBC, box, FALSE, atoms_solvt, x_solvt, v_solvt, r_solvt, TRUE, rshell, max_sol, oenv); *atoms_added = atoms->nr-onr; *residues_added = atoms->nres-onres; sfree(x_solvt); sfree(r_solvt); fprintf(stderr, "Generated solvent containing %d atoms in %d residues\n", *atoms_added, *residues_added); }
static int low_fflib_search_file_end(const char *ffdir, gmx_bool bAddCWD, const char *file_end, gmx_bool bFatalError, char ***filenames, char ***filenames_short) { char *ret=NULL; char *lib,*dir; char buf[1024]; char *libpath; gmx_bool env_is_set; int len_fe,len_name; char **fns,**fns_short; char dir_print[GMX_PATH_MAX]; char *pdum; char *s,fn_dir[GMX_PATH_MAX]; gmx_directory_t dirhandle; char nextname[STRLEN]; int n,n_thisdir,rc; len_fe = strlen(file_end); env_is_set = FALSE; if (ffdir != NULL) { /* Search in current dir and ffdir */ libpath = gmxlibfn(ffdir); } else { /* GMXLIB can be a path now */ lib = getenv("GMXLIB"); snew(libpath,GMX_PATH_MAX); if (bAddCWD) { sprintf(libpath,"%s%s",".",PATH_SEPARATOR); } if (lib != NULL) { env_is_set = TRUE; strncat(libpath,lib,GMX_PATH_MAX); } else if (!get_libdir(libpath+strlen(libpath))) { strncat(libpath,GMXLIBDIR,GMX_PATH_MAX); } } s = libpath; n = 0; fns = NULL; fns_short = NULL; /* Loop over all the entries in libpath */ while ((dir=gmx_strsep(&s, PATH_SEPARATOR)) != NULL) { rc = gmx_directory_open(&dirhandle,dir); if (rc==0) { strcpy(dir_print,dir); n_thisdir = 0; while (gmx_directory_nextfile(dirhandle,nextname,STRLEN-1)==0) { nextname[STRLEN-1]=0; if (debug) { fprintf(debug,"dir '%s' %d file '%s'\n", dir,n_thisdir,nextname); } len_name = strlen(nextname); /* What about case sensitivity? */ if (len_name >= len_fe && strcmp(nextname+len_name-len_fe,file_end) == 0) { /* We have a match */ srenew(fns,n+1); sprintf(fn_dir,"%s%c%s", dir_print,DIR_SEPARATOR,nextname); /* Copy the file name, possibly including the path. */ fns[n] = strdup(fn_dir); if (ffdir == NULL) { /* We are searching in a path. * Use the relative path when we use share/top * from the installation. * Add the full path when we use the current * working directory of GMXLIB. */ srenew(fns_short,n+1); if (strcmp(dir,".") == 0 || env_is_set) { fns_short[n] = strdup(fn_dir); } else { fns_short[n] = strdup(nextname); } } n++; n_thisdir++; } } gmx_directory_close(dirhandle); sort_filenames(n_thisdir, fns+n-n_thisdir, fns_short==NULL ? NULL : fns_short+n-n_thisdir); } } sfree(libpath); if (n == 0 && bFatalError) { if (ffdir != NULL) { gmx_fatal(FARGS,"Could not find any files ending on '%s' in the force field directory '%s'",file_end,ffdir); } else { gmx_fatal(FARGS,"Could not find any files ending on '%s' in the current directory or the GROMACS library search path",file_end); } } *filenames = fns; if (ffdir == NULL) { *filenames_short = fns_short; } return n; }
static void read_tables(FILE *fp,const char *fn, int ntab,int angle,t_tabledata td[]) { char *libfn; char buf[STRLEN]; double **yy=NULL,start,end,dx0,dx1,ssd,vm,vp,f,numf; int k,i,nx,nx0=0,ny,nny,ns; gmx_bool bAllZero,bZeroV,bZeroF; double tabscale; nny = 2*ntab+1; libfn = gmxlibfn(fn); nx = read_xvg(libfn,&yy,&ny); if (ny != nny) gmx_fatal(FARGS,"Trying to read file %s, but nr columns = %d, should be %d", libfn,ny,nny); if (angle == 0) { if (yy[0][0] != 0.0) gmx_fatal(FARGS, "The first distance in file %s is %f nm instead of %f nm", libfn,yy[0][0],0.0); } else { if (angle == 1) start = 0.0; else start = -180.0; end = 180.0; if (yy[0][0] != start || yy[0][nx-1] != end) gmx_fatal(FARGS,"The angles in file %s should go from %f to %f instead of %f to %f\n", libfn,start,end,yy[0][0],yy[0][nx-1]); } tabscale = (nx-1)/(yy[0][nx-1] - yy[0][0]); if (fp) { fprintf(fp,"Read user tables from %s with %d data points.\n",libfn,nx); if (angle == 0) fprintf(fp,"Tabscale = %g points/nm\n",tabscale); } bAllZero = TRUE; for(k=0; k<ntab; k++) { bZeroV = TRUE; bZeroF = TRUE; for(i=0; (i < nx); i++) { if (i >= 2) { dx0 = yy[0][i-1] - yy[0][i-2]; dx1 = yy[0][i] - yy[0][i-1]; /* Check for 1% deviation in spacing */ if (fabs(dx1 - dx0) >= 0.005*(fabs(dx0) + fabs(dx1))) { gmx_fatal(FARGS,"In table file '%s' the x values are not equally spaced: %f %f %f",fn,yy[0][i-2],yy[0][i-1],yy[0][i]); } } if (yy[1+k*2][i] != 0) { bZeroV = FALSE; if (bAllZero) { bAllZero = FALSE; nx0 = i; } if (yy[1+k*2][i] > 0.01*GMX_REAL_MAX || yy[1+k*2][i] < -0.01*GMX_REAL_MAX) { gmx_fatal(FARGS,"Out of range potential value %g in file '%s'", yy[1+k*2][i],fn); } } if (yy[1+k*2+1][i] != 0) { bZeroF = FALSE; if (bAllZero) { bAllZero = FALSE; nx0 = i; } if (yy[1+k*2+1][i] > 0.01*GMX_REAL_MAX || yy[1+k*2+1][i] < -0.01*GMX_REAL_MAX) { gmx_fatal(FARGS,"Out of range force value %g in file '%s'", yy[1+k*2+1][i],fn); } } } if (!bZeroV && bZeroF) { set_forces(fp,angle,nx,1/tabscale,yy[1+k*2],yy[1+k*2+1],k); } else { /* Check if the second column is close to minus the numerical * derivative of the first column. */ ssd = 0; ns = 0; for(i=1; (i < nx-1); i++) { vm = yy[1+2*k][i-1]; vp = yy[1+2*k][i+1]; f = yy[1+2*k+1][i]; if (vm != 0 && vp != 0 && f != 0) { /* Take the centered difference */ numf = -(vp - vm)*0.5*tabscale; ssd += fabs(2*(f - numf)/(f + numf)); ns++; } } if (ns > 0) { ssd /= ns; sprintf(buf,"For the %d non-zero entries for table %d in %s the forces deviate on average %d%% from minus the numerical derivative of the potential\n",ns,k,libfn,(int)(100*ssd+0.5)); if (debug) fprintf(debug,"%s",buf); if (ssd > 0.2) { if (fp) fprintf(fp,"\nWARNING: %s\n",buf); fprintf(stderr,"\nWARNING: %s\n",buf); } } } } if (bAllZero && fp) { fprintf(fp,"\nNOTE: All elements in table %s are zero\n\n",libfn); } for(k=0; (k<ntab); k++) { init_table(fp,nx,nx0,tabscale,&(td[k]),TRUE); for(i=0; (i<nx); i++) { td[k].x[i] = yy[0][i]; td[k].v[i] = yy[2*k+1][i]; td[k].f[i] = yy[2*k+2][i]; } } for(i=0; (i<ny); i++) sfree(yy[i]); sfree(yy); sfree(libfn); }
static int low_fflib_search_file_end(const char *ffdir, gmx_bool bAddCWD, const char *file_end, gmx_bool bFatalError, char ***filenames, char ***filenames_short) { char **fns = NULL, **fns_short = NULL; int n = 0; try { std::vector<std::string> libPaths; bool bEnvIsSet = false; if (ffdir != NULL) { /* Search ffdir in current dir and library dirs */ libPaths.push_back(gmxlibfn(ffdir)); } else { /* GMXLIB can be a path now */ if (bAddCWD) { libPaths.push_back("."); } const char *lib = getenv("GMXLIB"); if (lib != NULL) { bEnvIsSet = true; gmx::Path::splitPathEnvironment(lib, &libPaths); } else { libPaths.push_back(gmx::getProgramContext().defaultLibraryDataPath()); } } const int len_fe = strlen(file_end); std::vector<std::string>::const_iterator i; for (i = libPaths.begin(); i != libPaths.end(); ++i) { const char *dir = i->c_str(); gmx_directory_t dirhandle; const int rc = gmx_directory_open(&dirhandle, dir); if (rc == 0) { char nextname[STRLEN]; int n_thisdir = 0; while (gmx_directory_nextfile(dirhandle, nextname, STRLEN-1) == 0) { nextname[STRLEN-1] = 0; if (debug) { fprintf(debug, "dir '%s' %d file '%s'\n", dir, n_thisdir, nextname); } const int len_name = strlen(nextname); /* What about case sensitivity? */ if (len_name >= len_fe && strcmp(nextname+len_name-len_fe, file_end) == 0) { char fn_dir[GMX_PATH_MAX]; /* We have a match */ srenew(fns, n+1); sprintf(fn_dir, "%s%c%s", dir, DIR_SEPARATOR, nextname); /* Copy the file name, possibly including the path. */ fns[n] = gmx_strdup(fn_dir); if (ffdir == NULL) { /* We are searching in a path. * Use the relative path when we use share/top * from the installation. * Add the full path when we use the current * working directory of GMXLIB. */ srenew(fns_short, n+1); if (strcmp(dir, ".") == 0 || bEnvIsSet) { fns_short[n] = gmx_strdup(fn_dir); } else { fns_short[n] = gmx_strdup(nextname); } } n++; n_thisdir++; } } gmx_directory_close(dirhandle); sort_filenames(n_thisdir, fns+n-n_thisdir, fns_short == NULL ? NULL : fns_short+n-n_thisdir); } } } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR; if (n == 0 && bFatalError) { if (ffdir != NULL) { gmx_fatal(FARGS, "Could not find any files ending on '%s' in the force field directory '%s'", file_end, ffdir); } else { gmx_fatal(FARGS, "Could not find any files ending on '%s' in the current directory or the GROMACS library search path", file_end); } } *filenames = fns; if (ffdir == NULL) { *filenames_short = fns_short; } return n; }
void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[], gmx_bool bFrame, gmx_bool bDiag, gmx_bool bFirstDiag, gmx_bool bTitle, gmx_bool bTitleOnce, gmx_bool bYonce, int elegend, real size, real boxx, real boxy, const char *m2p, const char *m2pout, int mapoffset) { const char *libm2p; char buf[256], *legend; t_psdata out; t_psrec psrec, *psr; int W, H; int i, j, x, y, col, leg = 0; real x0, y0, xx; real w, h, dw, dh; int nmap1 = 0, nmap2 = 0, leg_nmap; t_mapping *map1 = NULL, *map2 = NULL, *leg_map; gmx_bool bMap1, bNextMap1, bDiscrete; /* memory leak: */ libm2p = m2p ? gmxlibfn(m2p) : m2p; get_params(libm2p, m2pout, &psrec); psr = &psrec; if (psr->X.major <= 0) { tick_spacing((mat[0].flags & MAT_SPATIAL_X) ? mat[0].nx + 1 : mat[0].nx, mat[0].axis_x, psr->X.offset, 'X', &(psr->X.major), &(psr->X.minor) ); } if (psr->X.minor <= 0) { psr->X.minor = psr->X.major / 2; } if (psr->Y.major <= 0) { tick_spacing((mat[0].flags & MAT_SPATIAL_Y) ? mat[0].ny + 1 : mat[0].ny, mat[0].axis_y, psr->Y.offset, 'Y', &(psr->Y.major), &(psr->Y.minor) ); } if (psr->Y.minor <= 0) { psr->Y.minor = psr->Y.major / 2; } if (boxx > 0) { psr->xboxsize = boxx; psr->yboxsize = boxx; } if (boxy > 0) { psr->yboxsize = boxy; } if (psr->xboxsize == 0) { psr->xboxsize = size/mat[0].nx; printf("Set the x-size of the box to %.3f\n", psr->xboxsize); } if (psr->yboxsize == 0) { psr->yboxsize = size/mat[0].nx; printf("Set the y-size of the box to %.3f\n", psr->yboxsize); } nmap1 = 0; for (i = 0; (i < nmat); i++) { if (mat[i].nmap > nmap1) { nmap1 = mat[i].nmap; map1 = mat[i].map; leg = i+1; } } if (leg != 1) { printf("Selected legend of matrix # %d for display\n", leg); } if (mat2) { nmap2 = 0; for (i = 0; (i < nmat); i++) { if (mat2[i].nmap > nmap2) { nmap2 = mat2[i].nmap; map2 = mat2[i].map; leg = i+1; } } if (leg != 1) { printf("Selected legend of matrix # %d for second display\n", leg); } } if ( (mat[0].legend[0] == 0) && psr->legend) { strcpy(mat[0].legend, psr->leglabel); } bTitle = bTitle && mat[nmat-1].title[0]; bTitleOnce = bTitleOnce && mat[nmat-1].title[0]; psr->bTitle = bTitle; psr->bTitleOnce = bTitleOnce; psr->bYonce = bYonce; /* Set up size of box for nice colors */ box_dim(nmat, mat, mat2, psr, elegend, bFrame, &w, &h, &dw, &dh); /* Set up bounding box */ W = w+dw; H = h+dh; /* Start box at */ x0 = dw; y0 = dh; x = W+psr->xoffs; y = H+psr->yoffs; if (bFrame) { x += 5*DDD; y += 4*DDD; } out = ps_open(outf, 0, 0, x, y); ps_linewidth(out, psr->linewidth); ps_init_rgb_box(out, psr->xboxsize, psr->yboxsize); ps_init_rgb_nbox(out, psr->xboxsize, psr->yboxsize); ps_translate(out, psr->xoffs, psr->yoffs); if (bFrame) { ps_comment(out, "Here starts the BOX drawing"); draw_boxes(out, x0, y0, w, nmat, mat, psr); } for (i = 0; (i < nmat); i++) { if (bTitle || (bTitleOnce && i == nmat-1) ) { /* Print title, if any */ ps_rgb(out, BLACK); ps_strfont(out, psr->titfont, psr->titfontsize); if (!mat2 || (strcmp(mat[i].title, mat2[i].title) == 0)) { strcpy(buf, mat[i].title); } else { sprintf(buf, "%s / %s", mat[i].title, mat2[i].title); } ps_ctext(out, x0+w/2, y0+box_height(&(mat[i]), psr)+psr->titfontsize, buf, eXCenter); } sprintf(buf, "Here starts the filling of box #%d", i); ps_comment(out, buf); for (x = 0; (x < mat[i].nx); x++) { int nexty; int nextcol; xx = x0+x*psr->xboxsize; ps_moveto(out, xx, y0); y = 0; bMap1 = (!mat2 || (x < y || (x == y && bFirstDiag))); if ((bDiag) || (x != y)) { col = mat[i].matrix[x][y]; } else { col = -1; } for (nexty = 1; (nexty <= mat[i].ny); nexty++) { bNextMap1 = (!mat2 || (x < nexty || (x == nexty && bFirstDiag))); /* TRUE: upper left -> map1 */ /* FALSE: lower right -> map2 */ if ((nexty == mat[i].ny) || (!bDiag && (x == nexty))) { nextcol = -1; } else { nextcol = mat[i].matrix[x][nexty]; } if ( (nexty == mat[i].ny) || (col != nextcol) || (bMap1 != bNextMap1) ) { if (col >= 0) { if (bMap1) { ps_rgb_nbox(out, &(mat[i].map[col].rgb), nexty-y); } else { ps_rgb_nbox(out, &(mat2[i].map[col].rgb), nexty-y); } } else { ps_moverel(out, 0, psr->yboxsize); } y = nexty; bMap1 = bNextMap1; col = nextcol; } } } y0 += box_height(&(mat[i]), psr)+box_dh(psr)+box_dh_top(IS_ONCE, psr); } if (psr->X.lineatzero || psr->Y.lineatzero) { /* reset y0 for first box */ y0 = dh; ps_comment(out, "Here starts the zero lines drawing"); draw_zerolines(out, x0, y0, w, nmat, mat, psr); } if (elegend != elNone) { ps_comment(out, "Now it's legend time!"); ps_linewidth(out, psr->linewidth); if (mat2 == NULL || elegend != elSecond) { bDiscrete = mat[0].bDiscrete; legend = mat[0].legend; leg_nmap = nmap1; leg_map = map1; } else { bDiscrete = mat2[0].bDiscrete; legend = mat2[0].legend; leg_nmap = nmap2; leg_map = map2; } if (bDiscrete) { leg_discrete(out, psr->legfontsize, DDD, legend, psr->legfontsize, psr->legfont, leg_nmap, leg_map); } else { if (elegend != elBoth) { leg_continuous(out, x0+w/2, w/2, DDD, legend, psr->legfontsize, psr->legfont, leg_nmap, leg_map, mapoffset); } else { leg_bicontinuous(out, x0+w/2, w, DDD, mat[0].legend, mat2[0].legend, psr->legfontsize, psr->legfont, nmap1, map1, nmap2, map2); } } ps_comment(out, "Were there, dude"); } ps_close(out); }