void gmx_abort(int noderank, int nnodes, int errorno) { #ifndef GMX_MPI gmx_call("gmx_abort"); #else #ifdef GMX_THREAD_MPI fprintf(stderr, "Halting program %s\n", ShortProgram()); thanx(stderr); exit(1); #else if (nnodes > 1) { fprintf(stderr, "Halting parallel program %s on CPU %d out of %d\n", ShortProgram(), noderank, nnodes); } else { fprintf(stderr, "Halting program %s\n", ShortProgram()); } thanx(stderr); MPI_Abort(MPI_COMM_WORLD, errorno); exit(1); #endif #endif }
int main(int argc,char *argv[]) { const char *desc[] = { "[TT]g_anadock[tt] analyses the results of an Autodock run and clusters the", "structures together, based on distance or RMSD. The docked energy", "and free energy estimates are analysed, and for each cluster the", "energy statistics are printed.[PAR]", "An alternative approach to this is to cluster the structures first", "using [TT]g_cluster[tt] and then sort the clusters on either lowest", "energy or average energy." }; t_filenm fnm[] = { { efPDB, "-f", NULL, ffREAD }, { efPDB, "-ox", "cluster", ffWRITE }, { efXVG, "-od", "edocked", ffWRITE }, { efXVG, "-of", "efree", ffWRITE }, { efLOG, "-g", "anadock", ffWRITE } }; output_env_t oenv; #define NFILE asize(fnm) static gmx_bool bFree=FALSE,bRMS=TRUE; static real cutoff = 0.2; t_pargs pa[] = { { "-free", FALSE, etBOOL, {&bFree}, "Use Free energy estimate from autodock for sorting the classes" }, { "-rms", FALSE, etBOOL, {&bRMS}, "Cluster on RMS or distance" }, { "-cutoff", FALSE, etREAL, {&cutoff}, "Maximum RMSD/distance for belonging to the same cluster" } }; #define NPA asize(pa) FILE *fp; t_pdbfile **pdbf=NULL; int npdbf; CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,0,NFILE,fnm,NPA,pa, asize(desc),desc,0, NULL,&oenv); fp = ffopen(opt2fn("-g",NFILE,fnm),"w"); please_cite(stdout,"Hetenyi2002b"); please_cite(fp,"Hetenyi2002b"); pdbf = read_em_all(opt2fn("-f",NFILE,fnm),&npdbf); analyse_em_all(npdbf,pdbf,opt2fn("-od",NFILE,fnm),opt2fn("-of",NFILE,fnm), oenv); cluster_em_all(fp,npdbf,pdbf,opt2fn("-ox",NFILE,fnm), bFree,bRMS,cutoff); thanx(fp); ffclose(fp); thanx(stdout); return 0; }
int main(int argc,char *argv[]) { const char *desc[] = { "proptrj" }; t_manual man = { asize(desc),desc,0,NULL,NULL,0,NULL}; t_filenm fnm[] = { { efGRO, "-c", "aver",FALSE }, { efDAT, "-d", "eigenvec", FALSE }, { efTPX, NULL, NULL, FALSE }, { efDAT, "-pi","pinp", FALSE }, { efDAT, "-po","poutp", FALSE } }; #define NFILE asize(fnm) t_topology *top; t_pinp *p; CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_VIEW | PCA_CAN_TIME, NFILE,fnm,TRUE,&man); top=read_top(ftp2fn(efTPX,NFILE,fnm)); init_debug("proptim.dbg",0); snew(p,1); read_inp(opt2fn("-pi",NFILE,fnm),opt2fn("-po",NFILE,fnm),p); proptrj(ftp2fn(efGRO,NFILE,fnm),ftp2fn(efDAT,NFILE,fnm),top,p); thanx(stderr); return 0; }
int main(int argc,char *argv[]) { static char *desc[] = { "[TT]gmxdump[tt] reads a run input file ([TT].tpa[tt]/[TT].tpr[tt]/[TT].tpb[tt]),", "a trajectory ([TT].trj[tt]/[TT].trr[tt]/[TT].xtc[tt]) or an energy", "file ([TT].ene[tt]/[TT].edr[tt]) and prints that to standard", "output in a readable format. This program is essential for", "checking your run input file in case of problems.[PAR]" }; t_filenm fnm[] = { { efTRN, "-f", NULL, ffOPTRD } }; #define NFILE asize(fnm) char *fn; /* Command line options */ CopyRight(stdout,argv[0]); parse_common_args(&argc,argv,0,NFILE,fnm,0,NULL, asize(desc),desc,0,NULL); if (ftp2bSet(efTRN,NFILE,fnm)) { fn = ftp2fn(efTRN,NFILE,fnm); printf("Going to open %s\n",fn); list_trn(fn); } thanx(stderr); return 0; }
int main(int argc,char *argv[]) { static char *desc[] = { "gmxdump reads a run input file ([TT].tpa[tt]/[TT].tpr[tt]/[TT].tpb[tt]),", "a trajectory ([TT].trj[tt]/[TT].trr[tt]/[TT].xtc[tt]), an energy", "file ([TT].ene[tt]/[TT].edr[tt]), or a checkpoint file ([TT].cpt[tt])", "and prints that to standard output in a readable format.", "This program is essential for checking your run input file in case of", "problems.[PAR]", "The program can also preprocess a topology to help finding problems.", "Note that currently setting GMXLIB is the only way to customize", "directories used for searching include files.", }; t_filenm fnm[] = { { efTPX, "-s", NULL, ffOPTRD }, { efTRX, "-f", NULL, ffOPTRD }, { efENX, "-e", NULL, ffOPTRD }, { efCPT, NULL, NULL, ffOPTRD }, { efTOP, "-p", NULL, ffOPTRD }, { efMTX, "-mtx", "hessian", ffOPTRD }, { efMDP, "-om", NULL, ffOPTWR } }; #define NFILE asize(fnm) /* Command line options */ static bool bXVG=FALSE; static bool bShowNumbers=TRUE; static bool bSysTop=FALSE; t_pargs pa[] = { { "-xvg", FALSE, etBOOL, {&bXVG}, "HIDDENXVG layout for xtc" }, { "-nr",FALSE, etBOOL, {&bShowNumbers},"Show index numbers in output (leaving them out makes comparison easier, but creates a useless topology)" }, { "-sys", FALSE, etBOOL, {&bSysTop}, "List the atoms and bonded interactions for the whole system instead of for each molecule type" } }; CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,0,NFILE,fnm,asize(pa),pa, asize(desc),desc,0,NULL); if (ftp2bSet(efTPX,NFILE,fnm)) list_tpx(ftp2fn(efTPX,NFILE,fnm),bShowNumbers, ftp2fn_null(efMDP,NFILE,fnm),bSysTop); else if (ftp2bSet(efTRX,NFILE,fnm)) list_trx(ftp2fn(efTRX,NFILE,fnm),bXVG); else if (ftp2bSet(efENX,NFILE,fnm)) list_ene(ftp2fn(efENX,NFILE,fnm)); else if (ftp2bSet(efCPT,NFILE,fnm)) list_checkpoint(ftp2fn(efCPT,NFILE,fnm),stdout); else if (ftp2bSet(efTOP,NFILE,fnm)) list_top(ftp2fn(efTOP,NFILE,fnm)); else if (ftp2bSet(efMTX,NFILE,fnm)) list_mtx(ftp2fn(efMTX,NFILE,fnm)); thanx(stderr); return 0; }
int gmx_rama(int argc,char *argv[]) { const char *desc[] = { "[TT]g_rama[tt] selects the [GRK]phi[grk]/[GRK]psi[grk] dihedral combinations from your topology file", "and computes these as a function of time.", "Using simple Unix tools such as [IT]grep[it] you can select out", "specific residues." }; FILE *out; t_xrama *xr; int j; output_env_t oenv; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPX, NULL, NULL, ffREAD }, { efXVG, NULL, "rama",ffWRITE } }; #define NFILE asize(fnm) parse_common_args(&argc,argv,PCA_CAN_VIEW | PCA_CAN_TIME | PCA_BE_NICE, NFILE,fnm,0,NULL,asize(desc),desc,0,NULL,&oenv); snew(xr,1); init_rama(oenv,ftp2fn(efTRX,NFILE,fnm),ftp2fn(efTPX,NFILE,fnm),xr,3); out=xvgropen(ftp2fn(efXVG,NFILE,fnm),"Ramachandran Plot","Phi","Psi",oenv); xvgr_line_props(out,0,elNone,ecFrank,oenv); xvgr_view(out,0.2,0.2,0.8,0.8,oenv); xvgr_world(out,-180,-180,180,180,oenv); fprintf(out,"@ xaxis tick on\n@ xaxis tick major 60\n@ xaxis tick minor 30\n"); fprintf(out,"@ yaxis tick on\n@ yaxis tick major 60\n@ yaxis tick minor 30\n"); fprintf(out,"@ s0 symbol 2\n@ s0 symbol size 0.4\n@ s0 symbol fill 1\n"); j=0; do { plot_rama(out,xr); j++; } while (new_data(xr)); fprintf(stderr,"\n"); ffclose(out); do_view(oenv,ftp2fn(efXVG,NFILE,fnm),NULL); thanx(stderr); return 0; }
int main(int argc, char *argv[]) { const char *desc[] = { "[TT]g_xrama[tt] shows a Ramachandran movie, that is, it shows", "the Phi/Psi angles as a function of time in an X-Window.[PAR]" "Static Phi/Psi plots for printing can be made with [TT]g_rama[tt].[PAR]", "Some of the more common X command line options can be used:[BR]", "[TT]-bg[tt], [TT]-fg[tt] change colors, [TT]-font fontname[tt], changes the font." }; output_env_t oenv; t_x11 *x11; t_topology *ramatop; t_app *app; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPX, NULL, NULL, ffREAD } }; #define NFILE asize(fnm) CopyRight(stderr, argv[0]); parse_common_args(&argc, argv, PCA_CAN_TIME, NFILE, fnm, 0, NULL, asize(desc), desc, 0, NULL, &oenv); if ((x11 = GetX11(&argc, argv)) == NULL) { fprintf(stderr, "Can't open display, set your DISPLAY environment variable\n"); exit(1); } XSetForeground(x11->disp, x11->gc, x11->fg); app = init_app(x11, argc, argv); ramatop = init_rama(oenv, ftp2fn(efTRX, NFILE, fnm), ftp2fn(efTPX, NFILE, fnm), app->xr, 3); mk_gly(app); XMapWindow(x11->disp, app->wd.self); XMapSubwindows(x11->disp, app->wd.self); x11->MainLoop(x11); x11->CleanUp(x11); thanx(stderr); return 0; }
int main(int argc, char *argv[]) { const char *desc[] = { "[TT]highway[tt] is the GROMCAS highway simulator. It is an X-windows", "gadget that shows a (periodic) Autobahn with a user defined", "number of cars. Fog can be turned on or off to increase the", "number of crashes. Nice for a background CPU-eater. A sample", "input file is in [TT]$GMXDATA/top/highway.dat[tt]" }; output_env_t oenv; t_x11 *x11; t_xhighway *xhw; t_filenm fnm[] = { { efDAT, "-f", "highway", ffREAD } }; #define NFILE asize(fnm) CopyRight(stderr, argv[0]); parse_common_args(&argc, argv, 0, NFILE, fnm, 0, NULL, asize(desc), desc, 0, NULL, &oenv); if ((x11 = GetX11(&argc, argv)) == NULL) { fprintf(stderr, "Can't connect to X Server.\n" "Check your DISPLAY environment variable\n"); exit(1); } xhw = GetXHW(x11, opt2fn("-f", NFILE, fnm)); XMapWindow(x11->disp, xhw->main.self); XMapSubwindows(x11->disp, xhw->main.self); x11->MainLoop(x11); x11->CleanUp(x11); thanx(stderr); return 0; }
int gmx_xpm2ps(int argc,char *argv[]) { static char *desc[] = { "xpm2ps makes a beautiful color plot of an XPixelMap file.", "Labels and axis can be displayed, when they are supplied", "in the correct matrix format.", "Matrix data may be generated by programs such as do_dssp, g_rms or", "g_mdmat.[PAR]", "Parameters are set in the [TT]m2p[tt] file optionally supplied with", "[TT]-di[tt]. Reasonable defaults are provided. Settings for the y-axis", "default to those for the x-axis. Font names have a defaulting hierarchy:", "titlefont -> legendfont; titlefont -> (xfont -> yfont -> ytickfont)", "-> xtickfont, e.g. setting titlefont sets all fonts, setting xfont", "sets yfont, ytickfont and xtickfont.[PAR]", "When no [TT]m2p[tt] file is supplied, many setting are set by", "command line options. The most important option is [TT]-size[tt]", "which sets the size of the whole matrix in postscript units.", "This option can be overridden with the [TT]-bx[tt] and [TT]-by[tt]", "options (and the corresponding parameters in the [TT]m2p[tt] file),", "which set the size of a single matrix element.[PAR]", "With [TT]-f2[tt] a 2nd matrix file can be supplied, both matrix", "files will be read simultaneously and the upper left half of the", "first one ([TT]-f[tt]) is plotted together with the lower right", "half of the second one ([TT]-f2[tt]). The diagonal will contain", "values from the matrix file selected with [TT]-diag[tt].", "Plotting of the diagonal values can be suppressed altogether by", "setting [TT]-diag[tt] to [TT]none[tt].", "In this case, a new color map will be generated with", "a red gradient for negative numbers and a blue for positive.", "If the color coding and legend labels of both matrices are identical,", "only one legend will be displayed, else two separate legends are", "displayed.", "With [TT]-combine[tt] an alternative operation can be selected", "to combine the matrices. The output range is automatically set", "to the actual range of the combined matrix. This can be overridden", "with [TT]-cmin[tt] and [TT]-cmax[tt].[PAR]", "[TT]-title[tt] can be set to [TT]none[tt] to suppress the title, or to", "[TT]ylabel[tt] to show the title in the Y-label position (alongside", "the Y-axis).[PAR]", "With the [TT]-rainbow[tt] option dull grey-scale matrices can be turned", "into attractive color pictures.[PAR]", "Merged or rainbowed matrices can be written to an XPixelMap file with", "the [TT]-xpm[tt] option." }; char *fn,*epsfile=NULL,*xpmfile=NULL; int i,nmat,nmat2,etitle,elegend,ediag,erainbow,ecombine; t_matrix *mat=NULL,*mat2=NULL; bool bTitle,bTitleOnce,bDiag,bFirstDiag,bGrad; static bool bFrame=TRUE,bZeroLine=FALSE,bYonce=FALSE,bAdd=FALSE; static real size=400,boxx=0,boxy=0,cmin=0,cmax=0; static rvec grad={0,0,0}; enum { etSel, etTop, etOnce, etYlabel, etNone, etNR }; static char *title[] = { NULL, "top", "once", "ylabel", "none", NULL }; /* MUST correspond to enum elXxx as defined at top of file */ static char *legend[] = { NULL, "both", "first", "second", "none", NULL }; enum { edSel, edFirst, edSecond, edNone, edNR }; static char *diag[] = { NULL, "first", "second", "none", NULL }; enum { erSel, erNo, erBlue, erRed, erNR }; static char *rainbow[] = { NULL, "no", "blue", "red", NULL }; /* MUST correspond to enum ecXxx as defined at top of file */ static char *combine[] = { NULL, "halves", "add", "sub", "mult", "div", NULL }; static int skip=1,mapoffset=0; t_pargs pa[] = { { "-frame", FALSE, etBOOL, {&bFrame}, "Display frame, ticks, labels, title and legend" }, { "-title", FALSE, etENUM, {title}, "Show title at" }, { "-yonce", FALSE, etBOOL, {&bYonce}, "Show y-label only once" }, { "-legend", FALSE, etENUM, {legend}, "Show legend" }, { "-diag", FALSE, etENUM, {diag}, "Diagonal" }, { "-size", FALSE, etREAL, {&size}, "Horizontal size of the matrix in ps units" }, { "-bx", FALSE, etREAL, {&boxx}, "Element x-size, overrides -size (also y-size when -by is not set)" }, { "-by", FALSE, etREAL, {&boxy}, "Element y-size" }, { "-rainbow", FALSE, etENUM, {rainbow}, "Rainbow colors, convert white to" }, { "-gradient",FALSE, etRVEC, {grad}, "Re-scale colormap to a smooth gradient from white {1,1,1} to {r,g,b}" }, { "-skip", FALSE, etINT, {&skip}, "only write out every nr-th row and column" }, { "-zeroline",FALSE, etBOOL, {&bZeroLine}, "insert line in xpm matrix where axis label is zero"}, { "-legoffset", FALSE, etINT, {&mapoffset}, "Skip first N colors from xpm file for the legend" }, { "-combine", FALSE, etENUM, {combine}, "Combine two matrices" }, { "-cmin", FALSE, etREAL, {&cmin}, "Minimum for combination output" }, { "-cmax", FALSE, etREAL, {&cmax}, "Maximum for combination output" } }; #define NPA asize(pa) t_filenm fnm[] = { { efXPM, "-f", NULL, ffREAD }, { efXPM, "-f2", "root2", ffOPTRD }, { efM2P, "-di", NULL, ffLIBOPTRD }, { efM2P, "-do", "out", ffOPTWR }, { efEPS, "-o", NULL, ffOPTWR }, { efXPM, "-xpm",NULL, ffOPTWR } }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_VIEW, NFILE,fnm,NPA,pa, asize(desc),desc,0,NULL); etitle = nenum(title); elegend = nenum(legend); ediag = nenum(diag); erainbow = nenum(rainbow); ecombine = nenum(combine); bGrad = opt2parg_bSet("-gradient",NPA,pa); for(i=0; i<DIM; i++) if (grad[i] < 0 || grad[i] > 1) gmx_fatal(FARGS, "RGB value %g out of range (0.0-1.0)", grad[i]); if (!bFrame) { etitle = etNone; elegend = elNone; } epsfile=ftp2fn_null(efEPS,NFILE,fnm); xpmfile=opt2fn_null("-xpm",NFILE,fnm); if ( epsfile==NULL && xpmfile==NULL ) { if (ecombine!=ecHalves) xpmfile=opt2fn("-xpm",NFILE,fnm); else epsfile=ftp2fn(efEPS,NFILE,fnm); } if (ecombine!=ecHalves && epsfile) { fprintf(stderr, "WARNING: can only write result of arithmetic combination " "of two matrices to .xpm file\n" " file %s will not be written\n", epsfile); epsfile = NULL; } bDiag = ediag!=edNone; bFirstDiag = ediag!=edSecond; fn=opt2fn("-f",NFILE,fnm); nmat=read_xpm_matrix(fn,&mat); fprintf(stderr,"There are %d matrices in %s\n",nmat,fn); fn=opt2fn_null("-f2",NFILE,fnm); if (fn) { nmat2=read_xpm_matrix(fn,&mat2); fprintf(stderr,"There are %d matrices in %s\n",nmat2,fn); if (nmat != nmat2) { fprintf(stderr,"Different number of matrices, using the smallest number.\n"); nmat=nmat2=min(nmat,nmat2); } } else { if (ecombine!=ecHalves) fprintf(stderr, "WARNING: arithmetic matrix combination selected (-combine), " "but no second matrix (-f2) supplied\n" " no matrix combination will be performed\n"); ecombine=0; nmat2=0; } bTitle = etitle==etTop; bTitleOnce = etitle==etOnce; if ( etitle==etYlabel ) for (i=0; (i<nmat); i++) { strcpy(mat[i].label_y, mat[i].title); if (mat2) strcpy(mat2[i].label_y, mat2[i].title); } if (bGrad) { gradient_mat(grad,nmat,mat); if (mat2) gradient_mat(grad,nmat2,mat2); } if (erainbow!=erNo) { rainbow_mat(erainbow==erBlue,nmat,mat); if (mat2) rainbow_mat(erainbow==erBlue,nmat2,mat2); } if ((mat2 == NULL) && (elegend!=elNone)) elegend = elFirst; if (ecombine && ecombine!=ecHalves) write_combined_matrix(ecombine, xpmfile, nmat, mat, mat2, opt2parg_bSet("-cmin",NPA,pa) ? &cmin : NULL, opt2parg_bSet("-cmax",NPA,pa) ? &cmax : NULL); else do_mat(nmat,mat,mat2,bFrame,bZeroLine,bDiag,bFirstDiag, bTitle,bTitleOnce,bYonce, elegend,size,boxx,boxy,epsfile,xpmfile, opt2fn_null("-di",NFILE,fnm),opt2fn_null("-do",NFILE,fnm), skip, mapoffset); view_all(NFILE, fnm); thanx(stderr); return 0; }
int gmx_dos(int argc, char *argv[]) { const char *desc[] = { "[TT]g_dos[tt] computes the Density of States from a simulations.", "In order for this to be meaningful the velocities must be saved", "in the trajecotry with sufficiently high frequency such as to cover", "all vibrations. For flexible systems that would be around a few fs", "between saving. Properties based on the DoS are printed on the", "standard output." }; const char *bugs[] = { "This program needs a lot of memory: total usage equals the number of atoms times 3 times number of frames times 4 (or 8 when run in double precision)." }; FILE *fp, *fplog; t_topology top; int ePBC = -1; t_trxframe fr; matrix box; int gnx; char title[256]; real t0, t1, m; t_trxstatus *status; int nV, nframes, n_alloc, i, j, k, l, fftcode, Nmol, Natom; double rho, dt, V2sum, Vsum, V, tmass, dostot, dos2, dosabs; real **c1, **dos, mi, beta, bfac, *nu, *tt, stddev, c1j; output_env_t oenv; gmx_fft_t fft; double cP, S, A, E, DiffCoeff, Delta, f, y, z, sigHS, Shs, Sig, DoS0, recip_fac; double wCdiff, wSdiff, wAdiff, wEdiff; static gmx_bool bVerbose = TRUE, bAbsolute = FALSE, bNormalize = FALSE; static gmx_bool bRecip = FALSE, bDump = FALSE; static real Temp = 298.15, toler = 1e-6; t_pargs pa[] = { { "-v", FALSE, etBOOL, {&bVerbose}, "Be loud and noisy." }, { "-recip", FALSE, etBOOL, {&bRecip}, "Use cm^-1 on X-axis instead of 1/ps for DoS plots." }, { "-abs", FALSE, etBOOL, {&bAbsolute}, "Use the absolute value of the Fourier transform of the VACF as the Density of States. Default is to use the real component only" }, { "-normdos", FALSE, etBOOL, {&bNormalize}, "Normalize the DoS such that it adds up to 3N. This is a hack that should not be necessary." }, { "-T", FALSE, etREAL, {&Temp}, "Temperature in the simulation" }, { "-toler", FALSE, etREAL, {&toler}, "[HIDDEN]Tolerance when computing the fluidicity using bisection algorithm" }, { "-dump", FALSE, etBOOL, {&bDump}, "[HIDDEN]Dump the y/fy plot corresponding to Fig. 2 inLin2003a and the and the weighting functions corresponding to Fig. 1 in Berens1983a." } }; t_filenm fnm[] = { { efTRN, "-f", NULL, ffREAD }, { efTPX, "-s", NULL, ffREAD }, { efNDX, NULL, NULL, ffOPTRD }, { efXVG, "-vacf", "vacf", ffWRITE }, { efXVG, "-mvacf", "mvacf", ffWRITE }, { efXVG, "-dos", "dos", ffWRITE }, { efLOG, "-g", "dos", ffWRITE }, }; #define NFILE asize(fnm) int npargs; t_pargs *ppa; const char *DoSlegend[] = { "DoS(v)", "DoS(v)[Solid]", "DoS(v)[Diff]" }; npargs = asize(pa); ppa = add_acf_pargs(&npargs, pa); parse_common_args(&argc, argv, PCA_CAN_VIEW | PCA_CAN_TIME | PCA_BE_NICE, NFILE, fnm, npargs, ppa, asize(desc), desc, asize(bugs), bugs, &oenv); beta = 1/(Temp*BOLTZ); if (bDump) { printf("Dumping reference figures. Thanks for your patience.\n"); dump_fy(oenv, toler); dump_w(oenv, beta); exit(0); } fplog = gmx_fio_fopen(ftp2fn(efLOG, NFILE, fnm), "w"); fprintf(fplog, "Doing density of states analysis based on trajectory.\n"); please_cite(fplog, "Pascal2011a"); please_cite(fplog, "Caleman2011b"); read_tps_conf(ftp2fn(efTPX, NFILE, fnm), title, &top, &ePBC, NULL, NULL, box, TRUE); V = det(box); tmass = 0; for (i = 0; (i < top.atoms.nr); i++) { tmass += top.atoms.atom[i].m; } Natom = top.atoms.nr; Nmol = top.mols.nr; gnx = Natom*DIM; /* Correlation stuff */ snew(c1, gnx); for (i = 0; (i < gnx); i++) { c1[i] = NULL; } read_first_frame(oenv, &status, ftp2fn(efTRN, NFILE, fnm), &fr, TRX_NEED_V); t0 = fr.time; n_alloc = 0; nframes = 0; Vsum = V2sum = 0; nV = 0; do { if (fr.bBox) { V = det(fr.box); V2sum += V*V; Vsum += V; nV++; } if (nframes >= n_alloc) { n_alloc += 100; for (i = 0; i < gnx; i++) { srenew(c1[i], n_alloc); } } for (i = 0; i < gnx; i += DIM) { c1[i+XX][nframes] = fr.v[i/DIM][XX]; c1[i+YY][nframes] = fr.v[i/DIM][YY]; c1[i+ZZ][nframes] = fr.v[i/DIM][ZZ]; } t1 = fr.time; nframes++; } while (read_next_frame(oenv, status, &fr)); close_trj(status); dt = (t1-t0)/(nframes-1); if (nV > 0) { V = Vsum/nV; } if (bVerbose) { printf("Going to do %d fourier transforms of length %d. Hang on.\n", gnx, nframes); } low_do_autocorr(NULL, oenv, NULL, nframes, gnx, nframes, c1, dt, eacNormal, 0, FALSE, FALSE, FALSE, -1, -1, 0, 0); snew(dos, DOS_NR); for (j = 0; (j < DOS_NR); j++) { snew(dos[j], nframes+4); } if (bVerbose) { printf("Going to merge the ACFs into the mass-weighted and plain ACF\n"); } for (i = 0; (i < gnx); i += DIM) { mi = top.atoms.atom[i/DIM].m; for (j = 0; (j < nframes/2); j++) { c1j = (c1[i+XX][j] + c1[i+YY][j] + c1[i+ZZ][j]); dos[VACF][j] += c1j/Natom; dos[MVACF][j] += mi*c1j; } } fp = xvgropen(opt2fn("-vacf", NFILE, fnm), "Velocity ACF", "Time (ps)", "C(t)", oenv); snew(tt, nframes/2); for (j = 0; (j < nframes/2); j++) { tt[j] = j*dt; fprintf(fp, "%10g %10g\n", tt[j], dos[VACF][j]); } xvgrclose(fp); fp = xvgropen(opt2fn("-mvacf", NFILE, fnm), "Mass-weighted velocity ACF", "Time (ps)", "C(t)", oenv); for (j = 0; (j < nframes/2); j++) { fprintf(fp, "%10g %10g\n", tt[j], dos[MVACF][j]); } xvgrclose(fp); if ((fftcode = gmx_fft_init_1d_real(&fft, nframes/2, GMX_FFT_FLAG_NONE)) != 0) { gmx_fatal(FARGS, "gmx_fft_init_1d_real returned %d", fftcode); } if ((fftcode = gmx_fft_1d_real(fft, GMX_FFT_REAL_TO_COMPLEX, (void *)dos[MVACF], (void *)dos[DOS])) != 0) { gmx_fatal(FARGS, "gmx_fft_1d_real returned %d", fftcode); } /* First compute the DoS */ /* Magic factor of 8 included now. */ bfac = 8*dt*beta/2; dos2 = 0; snew(nu, nframes/4); for (j = 0; (j < nframes/4); j++) { nu[j] = 2*j/(t1-t0); dos2 += sqr(dos[DOS][2*j]) + sqr(dos[DOS][2*j+1]); if (bAbsolute) { dos[DOS][j] = bfac*sqrt(sqr(dos[DOS][2*j]) + sqr(dos[DOS][2*j+1])); } else { dos[DOS][j] = bfac*dos[DOS][2*j]; } } /* Normalize it */ dostot = evaluate_integral(nframes/4, nu, dos[DOS], NULL, nframes/4, &stddev); if (bNormalize) { for (j = 0; (j < nframes/4); j++) { dos[DOS][j] *= 3*Natom/dostot; } } /* Now analyze it */ DoS0 = dos[DOS][0]; /* Note this eqn. is incorrect in Pascal2011a! */ Delta = ((2*DoS0/(9*Natom))*sqrt(M_PI*BOLTZ*Temp*Natom/tmass)* pow((Natom/V), 1.0/3.0)*pow(6/M_PI, 2.0/3.0)); f = calc_fluidicity(Delta, toler); y = calc_y(f, Delta, toler); z = calc_compress(y); Sig = BOLTZ*(5.0/2.0+log(2*M_PI*BOLTZ*Temp/(sqr(PLANCK))*V/(f*Natom))); Shs = Sig+calc_Shs(f, y); rho = (tmass*AMU)/(V*NANO*NANO*NANO); sigHS = pow(6*y*V/(M_PI*Natom), 1.0/3.0); fprintf(fplog, "System = \"%s\"\n", title); fprintf(fplog, "Nmol = %d\n", Nmol); fprintf(fplog, "Natom = %d\n", Natom); fprintf(fplog, "dt = %g ps\n", dt); fprintf(fplog, "tmass = %g amu\n", tmass); fprintf(fplog, "V = %g nm^3\n", V); fprintf(fplog, "rho = %g g/l\n", rho); fprintf(fplog, "T = %g K\n", Temp); fprintf(fplog, "beta = %g mol/kJ\n", beta); fprintf(fplog, "\nDoS parameters\n"); fprintf(fplog, "Delta = %g\n", Delta); fprintf(fplog, "fluidicity = %g\n", f); fprintf(fplog, "hard sphere packing fraction = %g\n", y); fprintf(fplog, "hard sphere compressibility = %g\n", z); fprintf(fplog, "ideal gas entropy = %g\n", Sig); fprintf(fplog, "hard sphere entropy = %g\n", Shs); fprintf(fplog, "sigma_HS = %g nm\n", sigHS); fprintf(fplog, "DoS0 = %g\n", DoS0); fprintf(fplog, "Dos2 = %g\n", dos2); fprintf(fplog, "DoSTot = %g\n", dostot); /* Now compute solid (2) and diffusive (3) components */ fp = xvgropen(opt2fn("-dos", NFILE, fnm), "Density of states", bRecip ? "E (cm\\S-1\\N)" : "\\f{12}n\\f{4} (1/ps)", "\\f{4}S(\\f{12}n\\f{4})", oenv); xvgr_legend(fp, asize(DoSlegend), DoSlegend, oenv); recip_fac = bRecip ? (1e7/SPEED_OF_LIGHT) : 1.0; for (j = 0; (j < nframes/4); j++) { dos[DOS_DIFF][j] = DoS0/(1+sqr(DoS0*M_PI*nu[j]/(6*f*Natom))); dos[DOS_SOLID][j] = dos[DOS][j]-dos[DOS_DIFF][j]; fprintf(fp, "%10g %10g %10g %10g\n", recip_fac*nu[j], dos[DOS][j]/recip_fac, dos[DOS_SOLID][j]/recip_fac, dos[DOS_DIFF][j]/recip_fac); } xvgrclose(fp); /* Finally analyze the results! */ wCdiff = 0.5; wSdiff = Shs/(3*BOLTZ); /* Is this correct? */ wEdiff = 0.5; wAdiff = wEdiff-wSdiff; for (j = 0; (j < nframes/4); j++) { dos[DOS_CP][j] = (dos[DOS_DIFF][j]*wCdiff + dos[DOS_SOLID][j]*wCsolid(nu[j], beta)); dos[DOS_S][j] = (dos[DOS_DIFF][j]*wSdiff + dos[DOS_SOLID][j]*wSsolid(nu[j], beta)); dos[DOS_A][j] = (dos[DOS_DIFF][j]*wAdiff + dos[DOS_SOLID][j]*wAsolid(nu[j], beta)); dos[DOS_E][j] = (dos[DOS_DIFF][j]*wEdiff + dos[DOS_SOLID][j]*wEsolid(nu[j], beta)); } DiffCoeff = evaluate_integral(nframes/2, tt, dos[VACF], NULL, nframes/2, &stddev); DiffCoeff = 1000*DiffCoeff/3.0; fprintf(fplog, "Diffusion coefficient from VACF %g 10^-5 cm^2/s\n", DiffCoeff); fprintf(fplog, "Diffusion coefficient from DoS %g 10^-5 cm^2/s\n", 1000*DoS0/(12*tmass*beta)); cP = BOLTZ * evaluate_integral(nframes/4, nu, dos[DOS_CP], NULL, nframes/4, &stddev); fprintf(fplog, "Heat capacity %g J/mol K\n", 1000*cP/Nmol); /* S = BOLTZ * evaluate_integral(nframes/4,nu,dos[DOS_S],NULL, nframes/4,&stddev); fprintf(fplog,"Entropy %g J/mol K\n",1000*S/Nmol); A = BOLTZ * evaluate_integral(nframes/4,nu,dos[DOS_A],NULL, nframes/4,&stddev); fprintf(fplog,"Helmholtz energy %g kJ/mol\n",A/Nmol); E = BOLTZ * evaluate_integral(nframes/4,nu,dos[DOS_E],NULL, nframes/4,&stddev); fprintf(fplog,"Internal energy %g kJ/mol\n",E/Nmol); */ fprintf(fplog, "\nArrivederci!\n"); gmx_fio_fclose(fplog); do_view(oenv, ftp2fn(efXVG, NFILE, fnm), "-nxy"); thanx(stderr); return 0; }
int gmx_principal(int argc,char *argv[]) { const char *desc[] = { "g_principal calculates the three principal axes of inertia for a group", "of atoms.", }; static bool foo = FALSE; t_pargs pa[] = { { "-foo", FALSE, etBOOL, {&foo}, "Dummy option to avoid empty array" } }; int status; t_topology top; int ePBC; real t; rvec * x; int natoms; char *grpname,title[256]; int i,j,m,gnx,nam,mol; atom_id *index; rvec a1,a2,a3,moi; FILE * axis1; FILE * axis2; FILE * axis3; FILE * fmoi; matrix axes,box; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPS, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffOPTRD }, { efDAT, "-a1", "axis1", ffWRITE }, { efDAT, "-a2", "axis2", ffWRITE }, { efDAT, "-a3", "axis3", ffWRITE }, { efDAT, "-om", "moi", ffWRITE } }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); parse_common_args(&argc,argv, PCA_CAN_TIME | PCA_TIME_UNIT | PCA_CAN_VIEW | PCA_BE_NICE, NFILE,fnm,asize(pa),pa,asize(desc),desc,0,NULL); axis1=fopen(opt2fn("-a1",NFILE,fnm),"w"); axis2=fopen(opt2fn("-a2",NFILE,fnm),"w"); axis3=fopen(opt2fn("-a3",NFILE,fnm),"w"); fmoi =fopen(opt2fn("-om",NFILE,fnm),"w"); read_tps_conf(ftp2fn(efTPS,NFILE,fnm),title,&top,&ePBC,NULL,NULL,box,TRUE); get_index(&top.atoms,ftp2fn_null(efNDX,NFILE,fnm),1,&gnx,&index,&grpname); natoms=read_first_x(&status,ftp2fn(efTRX,NFILE,fnm),&t,&x,box); do { rm_pbc(&(top.idef),ePBC,natoms,box,x,x); calc_principal_axes(&top,x,index,gnx,axes,moi); fprintf(axis1,"%15.10f %15.10f %15.10f %15.10f\n",t,axes[XX][XX],axes[YY][XX],axes[ZZ][XX]); fprintf(axis2,"%15.10f %15.10f %15.10f %15.10f\n",t,axes[XX][YY],axes[YY][YY],axes[ZZ][YY]); fprintf(axis3,"%15.10f %15.10f %15.10f %15.10f\n",t,axes[XX][ZZ],axes[YY][ZZ],axes[ZZ][ZZ]); fprintf(fmoi, "%15.10f %15.10f %15.10f %15.10f\n",t,moi[XX],moi[YY],moi[ZZ]); } while(read_next_x(status,&t,natoms,x,box)); close_trj(status); fclose(axis1); fclose(axis2); fclose(axis3); fclose(fmoi); thanx(stderr); return 0; }
int main (int argc,char *argv[]) { const char *desc[] = { "[TT]g_protonate[tt] reads (a) conformation(s) and adds all missing", "hydrogens as defined in [TT]gmx2.ff/aminoacids.hdb[tt]. If only [TT]-s[tt] is", "specified, this conformation will be protonated, if also [TT]-f[tt]", "is specified, the conformation(s) will be read from this file, ", "which can be either a single conformation or a trajectory.", "[PAR]", "If a [TT].pdb[tt] file is supplied, residue names might not correspond to", "to the GROMACS naming conventions, in which case these residues will", "probably not be properly protonated.", "[PAR]", "If an index file is specified, please note that the atom numbers", "should correspond to the [BB]protonated[bb] state." }; char title[STRLEN+1]; const char *infile; char *grpnm; t_topology top; int ePBC; t_atoms *atoms,*iatoms; t_protonate protdata; atom_id *index; t_trxstatus *status; t_trxstatus *out; t_trxframe fr,frout; rvec *x,*ix; int nidx,natoms,natoms_out; matrix box; int i,frame,resind; gmx_bool bReadMultiple; output_env_t oenv; const char *bugs[] = { "For the moment, only .pdb files are accepted to the -s flag" }; t_filenm fnm[] = { { efTPS, NULL, NULL, ffREAD }, { efTRX, "-f", NULL, ffOPTRD }, { efNDX, NULL, NULL, ffOPTRD }, { efTRO, "-o", "protonated", ffWRITE } }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_TIME, NFILE,fnm,0,NULL,asize(desc),desc,asize(bugs),bugs,&oenv); infile=opt2fn("-s",NFILE,fnm); read_tps_conf(infile,title,&top,&ePBC,&x,NULL,box,FALSE); atoms=&(top.atoms); printf("Select group to process:\n"); get_index(atoms,ftp2fn_null(efNDX,NFILE,fnm),1,&nidx,&index,&grpnm); bReadMultiple = opt2bSet("-f",NFILE,fnm); if (bReadMultiple) { infile = opt2fn("-f",NFILE,fnm); if ( !read_first_frame(oenv,&status, infile, &fr, TRX_NEED_X ) ) { gmx_fatal(FARGS,"cannot read coordinate file %s",infile); } natoms = fr.natoms; } else { clear_trxframe(&fr,TRUE); fr.natoms = atoms->nr; fr.bTitle = TRUE; fr.title = title; fr.bX = TRUE; fr.x = x; fr.bBox = TRUE; copy_mat(box, fr.box); natoms = fr.natoms; } /* check input */ if ( natoms == 0 ) { gmx_fatal(FARGS,"no atoms in coordinate file %s",infile); } if ( natoms > atoms->nr ) { gmx_fatal(FARGS,"topology with %d atoms does not match " "coordinates with %d atoms",atoms->nr,natoms); } for(i=0; i<nidx; i++) { if (index[i] > natoms) { gmx_fatal(FARGS,"An atom number in group %s is larger than the number of " "atoms (%d) in the coordinate file %s",grpnm,natoms,infile); } } /* get indexed copy of atoms */ snew(iatoms,1); init_t_atoms(iatoms,nidx,FALSE); snew(iatoms->atom, iatoms->nr); resind = 0; for(i=0; i<nidx; i++) { iatoms->atom[i] = atoms->atom[index[i]]; iatoms->atomname[i] = atoms->atomname[index[i]]; if ( i>0 && (atoms->atom[index[i]].resind!=atoms->atom[index[i-1]].resind) ) { resind++; } iatoms->atom[i].resind = resind; iatoms->resinfo[resind] = atoms->resinfo[atoms->atom[index[i]].resind]; /* allocate some space for the rtp name and copy from name */ snew(iatoms->resinfo[resind].rtp,1); *iatoms->resinfo[resind].rtp = gmx_strdup(*atoms->resinfo[resind].name); iatoms->nres = max(iatoms->nres, iatoms->atom[i].resind+1); } init_t_protonate(&protdata); out = open_trx(opt2fn("-o",NFILE,fnm),"w"); snew(ix, nidx); frame=0; do { if (debug) { fprintf(debug,"FRAME %d (%d %g)\n",frame,fr.step,fr.time); } /* get indexed copy of x */ for(i=0; i<nidx; i++) { copy_rvec(fr.x[index[i]], ix[i]); } /* protonate */ natoms_out = protonate(&iatoms, &ix, &protdata); /* setup output frame */ frout = fr; frout.natoms = natoms_out; frout.bAtoms = TRUE; frout.atoms = iatoms; frout.bV = FALSE; frout.bF = FALSE; frout.x = ix; /* write output */ write_trxframe(out,&frout,NULL); frame++; } while ( bReadMultiple && read_next_frame(oenv,status, &fr) ); sfree(ix); sfree(iatoms); thanx(stderr); return 0; }
int gmx_genbox(int argc, char *argv[]) { const char *desc[] = { "[TT]genbox[tt] can do one of 3 things:[PAR]", "1) Generate a box of solvent. Specify [TT]-cs[tt] and [TT]-box[tt]. Or specify [TT]-cs[tt] and", "[TT]-cp[tt] with a structure file with a box, but without atoms.[PAR]", "2) Solvate a solute configuration, e.g. a protein, in a bath of solvent ", "molecules. Specify [TT]-cp[tt] (solute) and [TT]-cs[tt] (solvent). ", "The box specified in the solute coordinate file ([TT]-cp[tt]) is used,", "unless [TT]-box[tt] is set.", "If you want the solute to be centered in the box,", "the program [TT]editconf[tt] has sophisticated options", "to change the box dimensions and center the solute.", "Solvent molecules are removed from the box where the ", "distance between any atom of the solute molecule(s) and any atom of ", "the solvent molecule is less than the sum of the van der Waals radii of ", "both atoms. A database ([TT]vdwradii.dat[tt]) of van der Waals radii is ", "read by the program, and atoms not in the database are ", "assigned a default distance [TT]-vdwd[tt].", "Note that this option will also influence the distances between", "solvent molecules if they contain atoms that are not in the database.", "[PAR]", "3) Insert a number ([TT]-nmol[tt]) of extra molecules ([TT]-ci[tt]) ", "at random positions.", "The program iterates until [TT]nmol[tt] molecules", "have been inserted in the box. To test whether an insertion is ", "successful the same van der Waals criterium is used as for removal of ", "solvent molecules. When no appropriately-sized ", "holes (holes that can hold an extra molecule) are available, the ", "program tries for [TT]-nmol[tt] * [TT]-try[tt] times before giving up. ", "Increase [TT]-try[tt] if you have several small holes to fill.[PAR]", "If you need to do more than one of the above operations, it can be", "best to call [TT]genbox[tt] separately for each operation, so that", "you are sure of the order in which the operations occur.[PAR]", "The default solvent is Simple Point Charge water (SPC), with coordinates ", "from [TT]$GMXLIB/spc216.gro[tt]. These coordinates can also be used", "for other 3-site water models, since a short equibilibration will remove", "the small differences between the models.", "Other solvents are also supported, as well as mixed solvents. The", "only restriction to solvent types is that a solvent molecule consists", "of exactly one residue. The residue information in the coordinate", "files is used, and should therefore be more or less consistent.", "In practice this means that two subsequent solvent molecules in the ", "solvent coordinate file should have different residue number.", "The box of solute is built by stacking the coordinates read from", "the coordinate file. This means that these coordinates should be ", "equlibrated in periodic boundary conditions to ensure a good", "alignment of molecules on the stacking interfaces.", "The [TT]-maxsol[tt] option simply adds only the first [TT]-maxsol[tt]", "solvent molecules and leaves out the rest that would have fitted", "into the box. This can create a void that can cause problems later.", "Choose your volume wisely.[PAR]", "The program can optionally rotate the solute molecule to align the", "longest molecule axis along a box edge. This way the amount of solvent", "molecules necessary is reduced.", "It should be kept in mind that this only works for", "short simulations, as e.g. an alpha-helical peptide in solution can ", "rotate over 90 degrees, within 500 ps. In general it is therefore ", "better to make a more or less cubic box.[PAR]", "Setting [TT]-shell[tt] larger than zero will place a layer of water of", "the specified thickness (nm) around the solute. Hint: it is a good", "idea to put the protein in the center of a box first (using [TT]editconf[tt]).", "[PAR]", "Finally, [TT]genbox[tt] will optionally remove lines from your topology file in ", "which a number of solvent molecules is already added, and adds a ", "line with the total number of solvent molecules in your coordinate file." }; const char *bugs[] = { "Molecules must be whole in the initial configurations.", }; /* parameter data */ gmx_bool bSol, bProt, bBox; const char *conf_prot, *confout; int bInsert; real *r; char *title_ins; gmx_atomprop_t aps; /* protein configuration data */ char *title = NULL; t_atoms atoms; rvec *x, *v = NULL; int ePBC = -1; matrix box; t_pbc pbc; /* other data types */ int atoms_added, residues_added; t_filenm fnm[] = { { efSTX, "-cp", "protein", ffOPTRD }, { efSTX, "-cs", "spc216", ffLIBOPTRD}, { efSTX, "-ci", "insert", ffOPTRD}, { efSTO, NULL, NULL, ffWRITE}, { efTOP, NULL, NULL, ffOPTRW}, }; #define NFILE asize(fnm) static int nmol_ins = 0, nmol_try = 10, seed = 1997; static real r_distance = 0.105, r_shell = 0; static rvec new_box = {0.0, 0.0, 0.0}; static gmx_bool bReadV = FALSE; static int max_sol = 0; output_env_t oenv; t_pargs pa[] = { { "-box", FALSE, etRVEC, {new_box}, "Box size" }, { "-nmol", FALSE, etINT, {&nmol_ins}, "Number of extra molecules to insert" }, { "-try", FALSE, etINT, {&nmol_try}, "Try inserting [TT]-nmol[tt] times [TT]-try[tt] times" }, { "-seed", FALSE, etINT, {&seed}, "Random generator seed"}, { "-vdwd", FALSE, etREAL, {&r_distance}, "Default van der Waals distance"}, { "-shell", FALSE, etREAL, {&r_shell}, "Thickness of optional water layer around solute" }, { "-maxsol", FALSE, etINT, {&max_sol}, "Maximum number of solvent molecules to add if they fit in the box. If zero (default) this is ignored" }, { "-vel", FALSE, etBOOL, {&bReadV}, "Keep velocities from input solute and solvent" } }; CopyRight(stderr, argv[0]); parse_common_args(&argc, argv, PCA_BE_NICE, NFILE, fnm, asize(pa), pa, asize(desc), desc, asize(bugs), bugs, &oenv); bInsert = opt2bSet("-ci", NFILE, fnm) && (nmol_ins > 0); bSol = opt2bSet("-cs", NFILE, fnm); bProt = opt2bSet("-cp", NFILE, fnm); bBox = opt2parg_bSet("-box", asize(pa), pa); /* check input */ if (bInsert && nmol_ins <= 0) { gmx_fatal(FARGS, "When specifying inserted molecules (-ci), " "-nmol must be larger than 0"); } if (!bInsert && nmol_ins > 0) { gmx_fatal(FARGS, "You tried to insert molecules with -nmol, but did not supply " "a molecule to insert with -ci."); } if (!bProt && !bBox) { gmx_fatal(FARGS, "When no solute (-cp) is specified, " "a box size (-box) must be specified"); } aps = gmx_atomprop_init(); if (bProt) { /*generate a solute configuration */ conf_prot = opt2fn("-cp", NFILE, fnm); title = read_prot(conf_prot, &atoms, &x, bReadV ? &v : NULL, &r, &ePBC, box, aps, r_distance); if (bReadV && !v) { fprintf(stderr, "Note: no velocities found\n"); } if (atoms.nr == 0) { fprintf(stderr, "Note: no atoms in %s\n", conf_prot); bProt = FALSE; } } if (!bProt) { atoms.nr = 0; atoms.nres = 0; atoms.resinfo = NULL; atoms.atomname = NULL; atoms.atom = NULL; atoms.pdbinfo = NULL; x = NULL; r = NULL; } if (bBox) { ePBC = epbcXYZ; clear_mat(box); box[XX][XX] = new_box[XX]; box[YY][YY] = new_box[YY]; box[ZZ][ZZ] = new_box[ZZ]; } if (det(box) == 0) { gmx_fatal(FARGS, "Undefined solute box.\nCreate one with editconf " "or give explicit -box command line option"); } /* add nmol_ins molecules of atoms_ins in random orientation at random place */ if (bInsert) { title_ins = insert_mols(opt2fn("-ci", NFILE, fnm), nmol_ins, nmol_try, seed, &atoms, &x, &r, ePBC, box, aps, r_distance, r_shell, oenv); } else { title_ins = strdup("Generated by genbox"); } /* add solvent */ if (bSol) { add_solv(opt2fn("-cs", NFILE, fnm), &atoms, &x, v ? &v : NULL, &r, ePBC, box, aps, r_distance, &atoms_added, &residues_added, r_shell, max_sol, oenv); } /* write new configuration 1 to file confout */ confout = ftp2fn(efSTO, NFILE, fnm); fprintf(stderr, "Writing generated configuration to %s\n", confout); if (bProt) { write_sto_conf(confout, title, &atoms, x, v, ePBC, box); /* print box sizes and box type to stderr */ fprintf(stderr, "%s\n", title); } else { write_sto_conf(confout, title_ins, &atoms, x, v, ePBC, box); } /* print size of generated configuration */ fprintf(stderr, "\nOutput configuration contains %d atoms in %d residues\n", atoms.nr, atoms.nres); update_top(&atoms, box, NFILE, fnm, aps); gmx_atomprop_destroy(aps); thanx(stderr); return 0; }
int main(int argc,char *argv[]) { const char *desc[] = { #ifdef GMX_OPENMM "This is an experimental release of GROMACS for accelerated", "Molecular Dynamics simulations on GPU processors. Support is provided", "by the OpenMM library (https://simtk.org/home/openmm).[PAR]", "*Warning*[BR]", "This release is targeted at developers and advanced users and", "care should be taken before production use. The following should be", "noted before using the program:[PAR]", " * The current release runs only on modern nVidia GPU hardware with CUDA support.", "Make sure that the necessary CUDA drivers and libraries for your operating system", "are already installed. The CUDA SDK also should be installed in order to compile", "the program from source (http://www.nvidia.com/object/cuda_home.html).[PAR]", " * Multiple GPU cards are not supported.[PAR]", " * Only a small subset of the GROMACS features and options are supported on the GPUs.", "See below for a detailed list.[PAR]", " * Consumer level GPU cards are known to often have problems with faulty memory.", "It is recommended that a full memory check of the cards is done at least once", "(for example, using the memtest=full option).", "A partial memory check (for example, memtest=15) before and", "after the simulation run would help spot", "problems resulting from processor overheating.[PAR]", " * The maximum size of the simulated systems depends on the available", "GPU memory,for example, a GTX280 with 1GB memory has been tested with systems", "of up to about 100,000 atoms.[PAR]", " * In order to take a full advantage of the GPU platform features, many algorithms", "have been implemented in a very different way than they are on the CPUs.", "Therefore numercal correspondence between properties of the state of", "simulated systems should not be expected. Moreover, the values will likely vary", "when simulations are done on different GPU hardware.[PAR]", " * Frequent retrieval of system state information such as", "trajectory coordinates and energies can greatly influence the performance", "of the program due to slow CPU<->GPU memory transfer speed.[PAR]", " * MD algorithms are complex, and although the Gromacs code is highly tuned for them,", "they often do not translate very well onto the streaming architetures.", "Realistic expectations about the achievable speed-up from test with GTX280:", "For small protein systems in implicit solvent using all-vs-all kernels the acceleration", "can be as high as 20 times, but in most other setups involving cutoffs and PME the", "acceleration is usually only ~4 times relative to a 3GHz CPU.[PAR]", "Supported features:[PAR]", " * Integrators: md/md-vv/md-vv-avek, sd/sd1 and bd.\n", " * Long-range interactions (option coulombtype): Reaction-Field, Ewald, PME, and cut-off (for Implicit Solvent only)\n", " * Temperature control: Supported only with the md/md-vv/md-vv-avek, sd/sd1 and bd integrators.\n", " * Pressure control: Supported.\n", " * Implicit solvent: Supported.\n", "A detailed description can be found on the GROMACS website:\n", "http://www.gromacs.org/gpu[PAR]", /* From the original mdrun documentaion */ "The [TT]mdrun[tt] program reads the run input file ([TT]-s[tt])", "and distributes the topology over nodes if needed.", "[TT]mdrun[tt] produces at least four output files.", "A single log file ([TT]-g[tt]) is written, unless the option", "[TT]-seppot[tt] is used, in which case each node writes a log file.", "The trajectory file ([TT]-o[tt]), contains coordinates, velocities and", "optionally forces.", "The structure file ([TT]-c[tt]) contains the coordinates and", "velocities of the last step.", "The energy file ([TT]-e[tt]) contains energies, the temperature,", "pressure, etc, a lot of these things are also printed in the log file.", "Optionally coordinates can be written to a compressed trajectory file", "([TT]-x[tt]).[PAR]", /* openmm specific information */ "Usage with OpenMM:[BR]", "[TT]mdrun -device \"OpenMM:platform=Cuda,memtest=15,deviceid=0,force-device=no\"[tt][PAR]", "Options:[PAR]", " [TT]platform[tt] = Cuda\t\t:\tThe only available value. OpenCL support will be available in future.\n", " [TT]memtest[tt] = 15\t\t:\tRun a partial, random GPU memory test for the given amount of seconds. A full test", "(recommended!) can be run with \"memtest=full\". Memory testing can be disabled with \"memtest=off\".\n", " [TT]deviceid[tt] = 0\t\t:\tSpecify the target device when multiple cards are present.", "Only one card can be used at any given time though.\n", " [TT]force-device[tt] = no\t\t:\tIf set to \"yes\" [TT]mdrun[tt] will be forced to execute on", "hardware that is not officially supported. GPU acceleration can also be achieved on older", "but Cuda capable cards, although the simulation might be too slow, and the memory limits too strict.", #else "The [TT]mdrun[tt] program is the main computational chemistry engine", "within GROMACS. Obviously, it performs Molecular Dynamics simulations,", "but it can also perform Stochastic Dynamics, Energy Minimization,", "test particle insertion or (re)calculation of energies.", "Normal mode analysis is another option. In this case [TT]mdrun[tt]", "builds a Hessian matrix from single conformation.", "For usual Normal Modes-like calculations, make sure that", "the structure provided is properly energy-minimized.", "The generated matrix can be diagonalized by [TT]g_nmeig[tt].[PAR]", "The [TT]mdrun[tt] program reads the run input file ([TT]-s[tt])", "and distributes the topology over nodes if needed.", "[TT]mdrun[tt] produces at least four output files.", "A single log file ([TT]-g[tt]) is written, unless the option", "[TT]-seppot[tt] is used, in which case each node writes a log file.", "The trajectory file ([TT]-o[tt]), contains coordinates, velocities and", "optionally forces.", "The structure file ([TT]-c[tt]) contains the coordinates and", "velocities of the last step.", "The energy file ([TT]-e[tt]) contains energies, the temperature,", "pressure, etc, a lot of these things are also printed in the log file.", "Optionally coordinates can be written to a compressed trajectory file", "([TT]-x[tt]).[PAR]", "The option [TT]-dhdl[tt] is only used when free energy calculation is", "turned on.[PAR]", "When [TT]mdrun[tt] is started using MPI with more than 1 node, parallelization", "is used. By default domain decomposition is used, unless the [TT]-pd[tt]", "option is set, which selects particle decomposition.[PAR]", "With domain decomposition, the spatial decomposition can be set", "with option [TT]-dd[tt]. By default [TT]mdrun[tt] selects a good decomposition.", "The user only needs to change this when the system is very inhomogeneous.", "Dynamic load balancing is set with the option [TT]-dlb[tt],", "which can give a significant performance improvement,", "especially for inhomogeneous systems. The only disadvantage of", "dynamic load balancing is that runs are no longer binary reproducible,", "but in most cases this is not important.", "By default the dynamic load balancing is automatically turned on", "when the measured performance loss due to load imbalance is 5% or more.", "At low parallelization these are the only important options", "for domain decomposition.", "At high parallelization the options in the next two sections", "could be important for increasing the performace.", "[PAR]", "When PME is used with domain decomposition, separate nodes can", "be assigned to do only the PME mesh calculation;", "this is computationally more efficient starting at about 12 nodes.", "The number of PME nodes is set with option [TT]-npme[tt],", "this can not be more than half of the nodes.", "By default [TT]mdrun[tt] makes a guess for the number of PME", "nodes when the number of nodes is larger than 11 or performance wise", "not compatible with the PME grid x dimension.", "But the user should optimize npme. Performance statistics on this issue", "are written at the end of the log file.", "For good load balancing at high parallelization, the PME grid x and y", "dimensions should be divisible by the number of PME nodes", "(the simulation will run correctly also when this is not the case).", "[PAR]", "This section lists all options that affect the domain decomposition.", "[PAR]", "Option [TT]-rdd[tt] can be used to set the required maximum distance", "for inter charge-group bonded interactions.", "Communication for two-body bonded interactions below the non-bonded", "cut-off distance always comes for free with the non-bonded communication.", "Atoms beyond the non-bonded cut-off are only communicated when they have", "missing bonded interactions; this means that the extra cost is minor", "and nearly indepedent of the value of [TT]-rdd[tt].", "With dynamic load balancing option [TT]-rdd[tt] also sets", "the lower limit for the domain decomposition cell sizes.", "By default [TT]-rdd[tt] is determined by [TT]mdrun[tt] based on", "the initial coordinates. The chosen value will be a balance", "between interaction range and communication cost.", "[PAR]", "When inter charge-group bonded interactions are beyond", "the bonded cut-off distance, [TT]mdrun[tt] terminates with an error message.", "For pair interactions and tabulated bonds", "that do not generate exclusions, this check can be turned off", "with the option [TT]-noddcheck[tt].", "[PAR]", "When constraints are present, option [TT]-rcon[tt] influences", "the cell size limit as well.", "Atoms connected by NC constraints, where NC is the LINCS order plus 1,", "should not be beyond the smallest cell size. A error message is", "generated when this happens and the user should change the decomposition", "or decrease the LINCS order and increase the number of LINCS iterations.", "By default [TT]mdrun[tt] estimates the minimum cell size required for P-LINCS", "in a conservative fashion. For high parallelization it can be useful", "to set the distance required for P-LINCS with the option [TT]-rcon[tt].", "[PAR]", "The [TT]-dds[tt] option sets the minimum allowed x, y and/or z scaling", "of the cells with dynamic load balancing. [TT]mdrun[tt] will ensure that", "the cells can scale down by at least this factor. This option is used", "for the automated spatial decomposition (when not using [TT]-dd[tt])", "as well as for determining the number of grid pulses, which in turn", "sets the minimum allowed cell size. Under certain circumstances", "the value of [TT]-dds[tt] might need to be adjusted to account for", "high or low spatial inhomogeneity of the system.", "[PAR]", "The option [TT]-gcom[tt] can be used to only do global communication", "every n steps.", "This can improve performance for highly parallel simulations", "where this global communication step becomes the bottleneck.", "For a global thermostat and/or barostat the temperature", "and/or pressure will also only be updated every [TT]-gcom[tt] steps.", "By default it is set to the minimum of nstcalcenergy and nstlist.[PAR]", "With [TT]-rerun[tt] an input trajectory can be given for which ", "forces and energies will be (re)calculated. Neighbor searching will be", "performed for every frame, unless [TT]nstlist[tt] is zero", "(see the [TT].mdp[tt] file).[PAR]", "ED (essential dynamics) sampling is switched on by using the [TT]-ei[tt]", "flag followed by an [TT].edi[tt] file.", "The [TT].edi[tt] file can be produced using options in the essdyn", "menu of the WHAT IF program. [TT]mdrun[tt] produces a [TT].edo[tt] file that", "contains projections of positions, velocities and forces onto selected", "eigenvectors.[PAR]", "When user-defined potential functions have been selected in the", "[TT].mdp[tt] file the [TT]-table[tt] option is used to pass [TT]mdrun[tt]", "a formatted table with potential functions. The file is read from", "either the current directory or from the [TT]GMXLIB[tt] directory.", "A number of pre-formatted tables are presented in the [TT]GMXLIB[tt] dir,", "for 6-8, 6-9, 6-10, 6-11, 6-12 Lennard-Jones potentials with", "normal Coulomb.", "When pair interactions are present, a separate table for pair interaction", "functions is read using the [TT]-tablep[tt] option.[PAR]", "When tabulated bonded functions are present in the topology,", "interaction functions are read using the [TT]-tableb[tt] option.", "For each different tabulated interaction type the table file name is", "modified in a different way: before the file extension an underscore is", "appended, then a 'b' for bonds, an 'a' for angles or a 'd' for dihedrals", "and finally the table number of the interaction type.[PAR]", "The options [TT]-px[tt] and [TT]-pf[tt] are used for writing pull COM", "coordinates and forces when pulling is selected", "in the [TT].mdp[tt] file.[PAR]", "With [TT]-multi[tt] or [TT]-multidir[tt], multiple systems can be ", "simulated in parallel.", "As many input files/directories are required as the number of systems. ", "The [TT]-multidir[tt] option takes a list of directories (one for each ", "system) and runs in each of them, using the input/output file names, ", "such as specified by e.g. the [TT]-s[tt] option, relative to these ", "directories.", "With [TT]-multi[tt], the system number is appended to the run input ", "and each output filename, for instance [TT]topol.tpr[tt] becomes", "[TT]topol0.tpr[tt], [TT]topol1.tpr[tt] etc.", "The number of nodes per system is the total number of nodes", "divided by the number of systems.", "One use of this option is for NMR refinement: when distance", "or orientation restraints are present these can be ensemble averaged", "over all the systems.[PAR]", "With [TT]-replex[tt] replica exchange is attempted every given number", "of steps. The number of replicas is set with the [TT]-multi[tt] or ", "[TT]-multidir[tt] option, described above.", "All run input files should use a different coupling temperature,", "the order of the files is not important. The random seed is set with", "[TT]-reseed[tt]. The velocities are scaled and neighbor searching", "is performed after every exchange.[PAR]", "Finally some experimental algorithms can be tested when the", "appropriate options have been given. Currently under", "investigation are: polarizability and X-ray bombardments.", "[PAR]", "The option [TT]-pforce[tt] is useful when you suspect a simulation", "crashes due to too large forces. With this option coordinates and", "forces of atoms with a force larger than a certain value will", "be printed to stderr.", "[PAR]", "Checkpoints containing the complete state of the system are written", "at regular intervals (option [TT]-cpt[tt]) to the file [TT]-cpo[tt],", "unless option [TT]-cpt[tt] is set to -1.", "The previous checkpoint is backed up to [TT]state_prev.cpt[tt] to", "make sure that a recent state of the system is always available,", "even when the simulation is terminated while writing a checkpoint.", "With [TT]-cpnum[tt] all checkpoint files are kept and appended", "with the step number.", "A simulation can be continued by reading the full state from file", "with option [TT]-cpi[tt]. This option is intelligent in the way that", "if no checkpoint file is found, Gromacs just assumes a normal run and", "starts from the first step of the [TT].tpr[tt] file. By default the output", "will be appending to the existing output files. The checkpoint file", "contains checksums of all output files, such that you will never", "loose data when some output files are modified, corrupt or removed.", "There are three scenarios with [TT]-cpi[tt]:[PAR]", "[TT]*[tt] no files with matching names are present: new output files are written[PAR]", "[TT]*[tt] all files are present with names and checksums matching those stored", "in the checkpoint file: files are appended[PAR]", "[TT]*[tt] otherwise no files are modified and a fatal error is generated[PAR]", "With [TT]-noappend[tt] new output files are opened and the simulation", "part number is added to all output file names.", "Note that in all cases the checkpoint file itself is not renamed", "and will be overwritten, unless its name does not match", "the [TT]-cpo[tt] option.", "[PAR]", "With checkpointing the output is appended to previously written", "output files, unless [TT]-noappend[tt] is used or none of the previous", "output files are present (except for the checkpoint file).", "The integrity of the files to be appended is verified using checksums", "which are stored in the checkpoint file. This ensures that output can", "not be mixed up or corrupted due to file appending. When only some", "of the previous output files are present, a fatal error is generated", "and no old output files are modified and no new output files are opened.", "The result with appending will be the same as from a single run.", "The contents will be binary identical, unless you use a different number", "of nodes or dynamic load balancing or the FFT library uses optimizations", "through timing.", "[PAR]", "With option [TT]-maxh[tt] a simulation is terminated and a checkpoint", "file is written at the first neighbor search step where the run time", "exceeds [TT]-maxh[tt]*0.99 hours.", "[PAR]", "When [TT]mdrun[tt] receives a TERM signal, it will set nsteps to the current", "step plus one. When [TT]mdrun[tt] receives an INT signal (e.g. when ctrl+C is", "pressed), it will stop after the next neighbor search step ", "(with nstlist=0 at the next step).", "In both cases all the usual output will be written to file.", "When running with MPI, a signal to one of the [TT]mdrun[tt] processes", "is sufficient, this signal should not be sent to mpirun or", "the [TT]mdrun[tt] process that is the parent of the others.", "[PAR]", "When [TT]mdrun[tt] is started with MPI, it does not run niced by default." #endif }; t_commrec *cr; t_filenm fnm[] = { { efTPX, NULL, NULL, ffREAD }, { efTRN, "-o", NULL, ffWRITE }, { efXTC, "-x", NULL, ffOPTWR }, { efCPT, "-cpi", NULL, ffOPTRD }, { efCPT, "-cpo", NULL, ffOPTWR }, { efSTO, "-c", "confout", ffWRITE }, { efEDR, "-e", "ener", ffWRITE }, { efLOG, "-g", "md", ffWRITE }, { efXVG, "-dhdl", "dhdl", ffOPTWR }, { efXVG, "-field", "field", ffOPTWR }, { efXVG, "-table", "table", ffOPTRD }, { efXVG, "-tabletf", "tabletf", ffOPTRD }, { efXVG, "-tablep", "tablep", ffOPTRD }, { efXVG, "-tableb", "table", ffOPTRD }, { efTRX, "-rerun", "rerun", ffOPTRD }, { efXVG, "-tpi", "tpi", ffOPTWR }, { efXVG, "-tpid", "tpidist", ffOPTWR }, { efEDI, "-ei", "sam", ffOPTRD }, { efEDO, "-eo", "sam", ffOPTWR }, { efGCT, "-j", "wham", ffOPTRD }, { efGCT, "-jo", "bam", ffOPTWR }, { efXVG, "-ffout", "gct", ffOPTWR }, { efXVG, "-devout", "deviatie", ffOPTWR }, { efXVG, "-runav", "runaver", ffOPTWR }, { efXVG, "-px", "pullx", ffOPTWR }, { efXVG, "-pf", "pullf", ffOPTWR }, { efXVG, "-ro", "rotation", ffOPTWR }, { efLOG, "-ra", "rotangles",ffOPTWR }, { efLOG, "-rs", "rotslabs", ffOPTWR }, { efLOG, "-rt", "rottorque",ffOPTWR }, { efMTX, "-mtx", "nm", ffOPTWR }, { efNDX, "-dn", "dipole", ffOPTWR }, { efRND, "-multidir",NULL, ffOPTRDMULT}, { efGMX, "-mmcg", "mmcg", ffOPTRD }, { efWPO, "-wpot", "wpot", ffOPTRD } }; #define NFILE asize(fnm) /* Command line options ! */ gmx_bool bCart = FALSE; gmx_bool bPPPME = FALSE; gmx_bool bPartDec = FALSE; gmx_bool bDDBondCheck = TRUE; gmx_bool bDDBondComm = TRUE; gmx_bool bVerbose = FALSE; gmx_bool bCompact = TRUE; gmx_bool bSepPot = FALSE; gmx_bool bRerunVSite = FALSE; gmx_bool bIonize = FALSE; gmx_bool bConfout = TRUE; gmx_bool bReproducible = FALSE; int npme=-1; int nmultisim=0; int nstglobalcomm=-1; int repl_ex_nst=0; int repl_ex_seed=-1; int nstepout=100; int nthreads=0; /* set to determine # of threads automatically */ int resetstep=-1; rvec realddxyz={0,0,0}; const char *ddno_opt[ddnoNR+1] = { NULL, "interleave", "pp_pme", "cartesian", NULL }; const char *dddlb_opt[] = { NULL, "auto", "no", "yes", NULL }; real rdd=0.0,rconstr=0.0,dlb_scale=0.8,pforce=-1; char *ddcsx=NULL,*ddcsy=NULL,*ddcsz=NULL; real cpt_period=15.0,max_hours=-1; gmx_bool bAppendFiles=TRUE; gmx_bool bKeepAndNumCPT=FALSE; gmx_bool bResetCountersHalfWay=FALSE; output_env_t oenv=NULL; const char *deviceOptions = ""; t_pargs pa[] = { { "-pd", FALSE, etBOOL,{&bPartDec}, "Use particle decompostion" }, { "-dd", FALSE, etRVEC,{&realddxyz}, "Domain decomposition grid, 0 is optimize" }, #ifdef GMX_THREADS { "-nt", FALSE, etINT, {&nthreads}, "Number of threads to start (0 is guess)" }, #endif { "-npme", FALSE, etINT, {&npme}, "Number of separate nodes to be used for PME, -1 is guess" }, { "-ddorder", FALSE, etENUM, {ddno_opt}, "DD node order" }, { "-ddcheck", FALSE, etBOOL, {&bDDBondCheck}, "Check for all bonded interactions with DD" }, { "-ddbondcomm", FALSE, etBOOL, {&bDDBondComm}, "HIDDENUse special bonded atom communication when [TT]-rdd[tt] > cut-off" }, { "-rdd", FALSE, etREAL, {&rdd}, "The maximum distance for bonded interactions with DD (nm), 0 is determine from initial coordinates" }, { "-rcon", FALSE, etREAL, {&rconstr}, "Maximum distance for P-LINCS (nm), 0 is estimate" }, { "-dlb", FALSE, etENUM, {dddlb_opt}, "Dynamic load balancing (with DD)" }, { "-dds", FALSE, etREAL, {&dlb_scale}, "Minimum allowed dlb scaling of the DD cell size" }, { "-ddcsx", FALSE, etSTR, {&ddcsx}, "HIDDENThe DD cell sizes in x" }, { "-ddcsy", FALSE, etSTR, {&ddcsy}, "HIDDENThe DD cell sizes in y" }, { "-ddcsz", FALSE, etSTR, {&ddcsz}, "HIDDENThe DD cell sizes in z" }, { "-gcom", FALSE, etINT,{&nstglobalcomm}, "Global communication frequency" }, { "-v", FALSE, etBOOL,{&bVerbose}, "Be loud and noisy" }, { "-compact", FALSE, etBOOL,{&bCompact}, "Write a compact log file" }, { "-seppot", FALSE, etBOOL, {&bSepPot}, "Write separate V and dVdl terms for each interaction type and node to the log file(s)" }, { "-pforce", FALSE, etREAL, {&pforce}, "Print all forces larger than this (kJ/mol nm)" }, { "-reprod", FALSE, etBOOL,{&bReproducible}, "Try to avoid optimizations that affect binary reproducibility" }, { "-cpt", FALSE, etREAL, {&cpt_period}, "Checkpoint interval (minutes)" }, { "-cpnum", FALSE, etBOOL, {&bKeepAndNumCPT}, "Keep and number checkpoint files" }, { "-append", FALSE, etBOOL, {&bAppendFiles}, "Append to previous output files when continuing from checkpoint instead of adding the simulation part number to all file names" }, { "-maxh", FALSE, etREAL, {&max_hours}, "Terminate after 0.99 times this time (hours)" }, { "-multi", FALSE, etINT,{&nmultisim}, "Do multiple simulations in parallel" }, { "-replex", FALSE, etINT, {&repl_ex_nst}, "Attempt replica exchange every # steps" }, { "-reseed", FALSE, etINT, {&repl_ex_seed}, "Seed for replica exchange, -1 is generate a seed" }, { "-rerunvsite", FALSE, etBOOL, {&bRerunVSite}, "HIDDENRecalculate virtual site coordinates with [TT]-rerun[tt]" }, { "-ionize", FALSE, etBOOL,{&bIonize}, "Do a simulation including the effect of an X-Ray bombardment on your system" }, { "-confout", FALSE, etBOOL, {&bConfout}, "HIDDENWrite the last configuration with [TT]-c[tt] and force checkpointing at the last step" }, { "-stepout", FALSE, etINT, {&nstepout}, "HIDDENFrequency of writing the remaining runtime" }, { "-resetstep", FALSE, etINT, {&resetstep}, "HIDDENReset cycle counters after these many time steps" }, { "-resethway", FALSE, etBOOL, {&bResetCountersHalfWay}, "HIDDENReset the cycle counters after half the number of steps or halfway [TT]-maxh[tt]" } #ifdef GMX_OPENMM , { "-device", FALSE, etSTR, {&deviceOptions}, "Device option string" } #endif }; gmx_edsam_t ed; unsigned long Flags, PCA_Flags; ivec ddxyz; int dd_node_order; gmx_bool bAddPart; FILE *fplog,*fptest; int sim_part,sim_part_fn; const char *part_suffix=".part"; char suffix[STRLEN]; int rc; char **multidir=NULL; cr = init_par(&argc,&argv); if (MASTER(cr)) CopyRight(stderr, argv[0]); PCA_Flags = (PCA_KEEP_ARGS | PCA_NOEXIT_ON_ARGS | PCA_CAN_SET_DEFFNM | (MASTER(cr) ? 0 : PCA_QUIET)); /* Comment this in to do fexist calls only on master * works not with rerun or tables at the moment * also comment out the version of init_forcerec in md.c * with NULL instead of opt2fn */ /* if (!MASTER(cr)) { PCA_Flags |= PCA_NOT_READ_NODE; } */ parse_common_args(&argc,argv,PCA_Flags, NFILE,fnm,asize(pa),pa, asize(desc),desc,0,NULL, &oenv); /* we set these early because they might be used in init_multisystem() Note that there is the potential for npme>nnodes until the number of threads is set later on, if there's thread parallelization. That shouldn't lead to problems. */ dd_node_order = nenum(ddno_opt); cr->npmenodes = npme; #ifndef GMX_THREADS nthreads=1; #endif /* now check the -multi and -multidir option */ if (opt2bSet("-multidir", NFILE, fnm)) { int i; if (nmultisim > 0) { gmx_fatal(FARGS, "mdrun -multi and -multidir options are mutually exclusive."); } nmultisim = opt2fns(&multidir, "-multidir", NFILE, fnm); } if (repl_ex_nst != 0 && nmultisim < 2) gmx_fatal(FARGS,"Need at least two replicas for replica exchange (option -multi)"); if (nmultisim > 1) { #ifndef GMX_THREADS gmx_bool bParFn = (multidir == NULL); init_multisystem(cr, nmultisim, multidir, NFILE, fnm, bParFn); #else gmx_fatal(FARGS,"mdrun -multi is not supported with the thread library.Please compile GROMACS with MPI support"); #endif } bAddPart = !bAppendFiles; /* Check if there is ANY checkpoint file available */ sim_part = 1; sim_part_fn = sim_part; if (opt2bSet("-cpi",NFILE,fnm)) { if (bSepPot && bAppendFiles) { gmx_fatal(FARGS,"Output file appending is not supported with -seppot"); } bAppendFiles = read_checkpoint_simulation_part(opt2fn_master("-cpi", NFILE, fnm,cr), &sim_part_fn,NULL,cr, bAppendFiles,NFILE,fnm, part_suffix,&bAddPart); if (sim_part_fn==0 && MASTER(cr)) { fprintf(stdout,"No previous checkpoint file present, assuming this is a new run.\n"); } else { sim_part = sim_part_fn + 1; } if (MULTISIM(cr) && MASTER(cr)) { check_multi_int(stdout,cr->ms,sim_part,"simulation part"); } } else { bAppendFiles = FALSE; } if (!bAppendFiles) { sim_part_fn = sim_part; } if (bAddPart) { /* Rename all output files (except checkpoint files) */ /* create new part name first (zero-filled) */ sprintf(suffix,"%s%04d",part_suffix,sim_part_fn); add_suffix_to_output_names(fnm,NFILE,suffix); if (MASTER(cr)) { fprintf(stdout,"Checkpoint file is from part %d, new output files will be suffixed '%s'.\n",sim_part-1,suffix); } } Flags = opt2bSet("-rerun",NFILE,fnm) ? MD_RERUN : 0; Flags = Flags | (opt2bSet("-mmcg",NFILE,fnm) ? MD_MMCG : 0); Flags = Flags | (bSepPot ? MD_SEPPOT : 0); Flags = Flags | (bIonize ? MD_IONIZE : 0); Flags = Flags | (bPartDec ? MD_PARTDEC : 0); Flags = Flags | (bDDBondCheck ? MD_DDBONDCHECK : 0); Flags = Flags | (bDDBondComm ? MD_DDBONDCOMM : 0); Flags = Flags | (bConfout ? MD_CONFOUT : 0); Flags = Flags | (bRerunVSite ? MD_RERUN_VSITE : 0); Flags = Flags | (bReproducible ? MD_REPRODUCIBLE : 0); Flags = Flags | (bAppendFiles ? MD_APPENDFILES : 0); Flags = Flags | (bKeepAndNumCPT ? MD_KEEPANDNUMCPT : 0); Flags = Flags | (sim_part>1 ? MD_STARTFROMCPT : 0); Flags = Flags | (bResetCountersHalfWay ? MD_RESETCOUNTERSHALFWAY : 0); Flags = Flags | (opt2bSet("-wpot",NFILE,fnm) ? MD_WALLPOT : 0); /* We postpone opening the log file if we are appending, so we can first truncate the old log file and append to the correct position there instead. */ if ((MASTER(cr) || bSepPot) && !bAppendFiles) { gmx_log_open(ftp2fn(efLOG,NFILE,fnm),cr,!bSepPot,Flags,&fplog); CopyRight(fplog,argv[0]); please_cite(fplog,"Hess2008b"); please_cite(fplog,"Spoel2005a"); please_cite(fplog,"Lindahl2001a"); please_cite(fplog,"Berendsen95a"); } else if (!MASTER(cr) && bSepPot) { gmx_log_open(ftp2fn(efLOG,NFILE,fnm),cr,!bSepPot,Flags,&fplog); } else { fplog = NULL; } ddxyz[XX] = (int)(realddxyz[XX] + 0.5); ddxyz[YY] = (int)(realddxyz[YY] + 0.5); ddxyz[ZZ] = (int)(realddxyz[ZZ] + 0.5); rc = mdrunner(nthreads, fplog,cr,NFILE,fnm,oenv,bVerbose,bCompact, nstglobalcomm, ddxyz,dd_node_order,rdd,rconstr, dddlb_opt[0],dlb_scale,ddcsx,ddcsy,ddcsz, nstepout,resetstep,nmultisim,repl_ex_nst,repl_ex_seed, pforce, cpt_period,max_hours,deviceOptions,Flags); if (gmx_parallel_env_initialized()) gmx_finalize(); if (MULTIMASTER(cr)) { thanx(stderr); } /* Log file has to be closed in mdrunner if we are appending to it (fplog not set here) */ if (MASTER(cr) && !bAppendFiles) { gmx_log_close(fplog); } return rc; }
int gmx_densmap(int argc,char *argv[]) { const char *desc[] = { "[TT]g_densmap[tt] computes 2D number-density maps.", "It can make planar and axial-radial density maps.", "The output [TT].xpm[tt] file can be visualized with for instance xv", "and can be converted to postscript with [TT]xpm2ps[tt].", "Optionally, output can be in text form to a [TT].dat[tt] file with [TT]-od[tt], instead of the usual [TT].xpm[tt] file with [TT]-o[tt].", "[PAR]", "The default analysis is a 2-D number-density map for a selected", "group of atoms in the x-y plane.", "The averaging direction can be changed with the option [TT]-aver[tt].", "When [TT]-xmin[tt] and/or [TT]-xmax[tt] are set only atoms that are", "within the limit(s) in the averaging direction are taken into account.", "The grid spacing is set with the option [TT]-bin[tt].", "When [TT]-n1[tt] or [TT]-n2[tt] is non-zero, the grid", "size is set by this option.", "Box size fluctuations are properly taken into account.", "[PAR]", "When options [TT]-amax[tt] and [TT]-rmax[tt] are set, an axial-radial", "number-density map is made. Three groups should be supplied, the centers", "of mass of the first two groups define the axis, the third defines the", "analysis group. The axial direction goes from -amax to +amax, where", "the center is defined as the midpoint between the centers of mass and", "the positive direction goes from the first to the second center of mass.", "The radial direction goes from 0 to rmax or from -rmax to +rmax", "when the [TT]-mirror[tt] option has been set.", "[PAR]", "The normalization of the output is set with the [TT]-unit[tt] option.", "The default produces a true number density. Unit [TT]nm-2[tt] leaves out", "the normalization for the averaging or the angular direction.", "Option [TT]count[tt] produces the count for each grid cell.", "When you do not want the scale in the output to go", "from zero to the maximum density, you can set the maximum", "with the option [TT]-dmax[tt]." }; static int n1=0,n2=0; static real xmin=-1,xmax=-1,bin=0.02,dmin=0,dmax=0,amax=0,rmax=0; static gmx_bool bMirror=FALSE, bSums=FALSE; static const char *eaver[]= { NULL, "z", "y", "x", NULL }; static const char *eunit[]= { NULL, "nm-3", "nm-2", "count", NULL }; t_pargs pa[] = { { "-bin", FALSE, etREAL, {&bin}, "Grid size (nm)" }, { "-aver", FALSE, etENUM, {eaver}, "The direction to average over" }, { "-xmin", FALSE, etREAL, {&xmin}, "Minimum coordinate for averaging" }, { "-xmax", FALSE, etREAL, {&xmax}, "Maximum coordinate for averaging" }, { "-n1", FALSE, etINT, {&n1}, "Number of grid cells in the first direction" }, { "-n2", FALSE, etINT, {&n2}, "Number of grid cells in the second direction" }, { "-amax", FALSE, etREAL, {&amax}, "Maximum axial distance from the center" }, { "-rmax", FALSE, etREAL, {&rmax}, "Maximum radial distance" }, { "-mirror", FALSE, etBOOL, {&bMirror}, "Add the mirror image below the axial axis" }, { "-sums", FALSE, etBOOL, {&bSums}, "Print density sums (1D map) to stdout" }, { "-unit", FALSE, etENUM, {eunit}, "Unit for the output" }, { "-dmin", FALSE, etREAL, {&dmin}, "Minimum density in output" }, { "-dmax", FALSE, etREAL, {&dmax}, "Maximum density in output (0 means calculate it)" }, }; gmx_bool bXmin,bXmax,bRadial; FILE *fp; t_trxstatus *status; t_topology top; int ePBC=-1; rvec *x,xcom[2],direction,center,dx; matrix box; real t,m,mtot; t_pbc pbc; int cav=0,c1=0,c2=0,natoms; char **grpname,title[256],buf[STRLEN]; const char *unit; int i,j,k,l,ngrps,anagrp,*gnx=NULL,nindex,nradial=0,nfr,nmpower; atom_id **ind=NULL,*index; real **grid,maxgrid,m1,m2,box1,box2,*tickx,*tickz,invcellvol; real invspa=0,invspz=0,axial,r,vol_old,vol,rowsum; int nlev=51; t_rgb rlo= {1,1,1}, rhi= {0,0,0}; output_env_t oenv; const char *label[]= { "x (nm)", "y (nm)", "z (nm)" }; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPS, NULL, NULL, ffOPTRD }, { efNDX, NULL, NULL, ffOPTRD }, { efDAT, "-od", "densmap", ffOPTWR }, { efXPM, "-o", "densmap", ffWRITE } }; #define NFILE asize(fnm) int npargs; CopyRight(stderr,argv[0]); npargs = asize(pa); parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_CAN_VIEW | PCA_BE_NICE, NFILE,fnm,npargs,pa,asize(desc),desc,0,NULL,&oenv); bXmin = opt2parg_bSet("-xmin",npargs,pa); bXmax = opt2parg_bSet("-xmax",npargs,pa); bRadial = (amax>0 || rmax>0); if (bRadial) { if (amax<=0 || rmax<=0) gmx_fatal(FARGS,"Both amax and rmax should be larger than zero"); } if (strcmp(eunit[0],"nm-3") == 0) { nmpower = -3; unit = "(nm^-3)"; } else if (strcmp(eunit[0],"nm-2") == 0) { nmpower = -2; unit = "(nm^-2)"; } else { nmpower = 0; unit = "count"; } if (ftp2bSet(efTPS,NFILE,fnm) || !ftp2bSet(efNDX,NFILE,fnm)) read_tps_conf(ftp2fn(efTPS,NFILE,fnm),title,&top,&ePBC,&x,NULL,box, bRadial); if (!bRadial) { ngrps = 1; fprintf(stderr,"\nSelect an analysis group\n"); } else { ngrps = 3; fprintf(stderr, "\nSelect two groups to define the axis and an analysis group\n"); } snew(gnx,ngrps); snew(grpname,ngrps); snew(ind,ngrps); get_index(&top.atoms,ftp2fn_null(efNDX,NFILE,fnm),ngrps,gnx,ind,grpname); anagrp = ngrps - 1; nindex = gnx[anagrp]; index = ind[anagrp]; if (bRadial) { if ((gnx[0]>1 || gnx[1]>1) && !ftp2bSet(efTPS,NFILE,fnm)) gmx_fatal(FARGS,"No run input file was supplied (option -s), this is required for the center of mass calculation"); } switch (eaver[0][0]) { case 'x': cav = XX; c1 = YY; c2 = ZZ; break; case 'y': cav = YY; c1 = XX; c2 = ZZ; break; case 'z': cav = ZZ; c1 = XX; c2 = YY; break; } natoms=read_first_x(oenv,&status,ftp2fn(efTRX,NFILE,fnm),&t,&x,box); if (!bRadial) { if (n1 == 0) n1 = (int)(box[c1][c1]/bin + 0.5); if (n2 == 0) n2 = (int)(box[c2][c2]/bin + 0.5); } else { n1 = (int)(2*amax/bin + 0.5); nradial = (int)(rmax/bin + 0.5); invspa = n1/(2*amax); invspz = nradial/rmax; if (bMirror) n2 = 2*nradial; else n2 = nradial; } snew(grid,n1); for(i=0; i<n1; i++) snew(grid[i],n2); box1 = 0; box2 = 0; nfr = 0; do { if (!bRadial) { box1 += box[c1][c1]; box2 += box[c2][c2]; invcellvol = n1*n2; if (nmpower == -3) invcellvol /= det(box); else if (nmpower == -2) invcellvol /= box[c1][c1]*box[c2][c2]; for(i=0; i<nindex; i++) { j = index[i]; if ((!bXmin || x[j][cav] >= xmin) && (!bXmax || x[j][cav] <= xmax)) { m1 = x[j][c1]/box[c1][c1]; if (m1 >= 1) m1 -= 1; if (m1 < 0) m1 += 1; m2 = x[j][c2]/box[c2][c2]; if (m2 >= 1) m2 -= 1; if (m2 < 0) m2 += 1; grid[(int)(m1*n1)][(int)(m2*n2)] += invcellvol; } } } else { set_pbc(&pbc,ePBC,box); for(i=0; i<2; i++) { if (gnx[i] == 1) { /* One atom, just copy the coordinates */ copy_rvec(x[ind[i][0]],xcom[i]); } else { /* Calculate the center of mass */ clear_rvec(xcom[i]); mtot = 0; for(j=0; j<gnx[i]; j++) { k = ind[i][j]; m = top.atoms.atom[k].m; for(l=0; l<DIM; l++) xcom[i][l] += m*x[k][l]; mtot += m; } svmul(1/mtot,xcom[i],xcom[i]); } } pbc_dx(&pbc,xcom[1],xcom[0],direction); for(i=0; i<DIM; i++) center[i] = xcom[0][i] + 0.5*direction[i]; unitv(direction,direction); for(i=0; i<nindex; i++) { j = index[i]; pbc_dx(&pbc,x[j],center,dx); axial = iprod(dx,direction); r = sqrt(norm2(dx) - axial*axial); if (axial>=-amax && axial<amax && r<rmax) { if (bMirror) r += rmax; grid[(int)((axial + amax)*invspa)][(int)(r*invspz)] += 1; } } } nfr++; } while(read_next_x(oenv,status,&t,natoms,x,box)); close_trj(status); /* normalize gridpoints */ maxgrid = 0; if (!bRadial) { for (i=0; i<n1; i++) { for (j=0; j<n2; j++) { grid[i][j] /= nfr; if (grid[i][j] > maxgrid) maxgrid = grid[i][j]; } } } else { for (i=0; i<n1; i++) { vol_old = 0; for (j=0; j<nradial; j++) { switch (nmpower) { case -3: vol = M_PI*(j+1)*(j+1)/(invspz*invspz*invspa); break; case -2: vol = (j+1)/(invspz*invspa); break; default: vol = j+1; break; } if (bMirror) k = j + nradial; else k = j; grid[i][k] /= nfr*(vol - vol_old); if (bMirror) grid[i][nradial-1-j] = grid[i][k]; vol_old = vol; if (grid[i][k] > maxgrid) maxgrid = grid[i][k]; } } } fprintf(stdout,"\n The maximum density is %f %s\n",maxgrid,unit); if (dmax > 0) maxgrid = dmax; snew(tickx,n1+1); snew(tickz,n2+1); if (!bRadial) { /* normalize box-axes */ box1 /= nfr; box2 /= nfr; for (i=0; i<=n1; i++) tickx[i] = i*box1/n1; for (i=0; i<=n2; i++) tickz[i] = i*box2/n2; } else { for (i=0; i<=n1; i++) tickx[i] = i/invspa - amax; if (bMirror) { for (i=0; i<=n2; i++) tickz[i] = i/invspz - rmax; } else { for (i=0; i<=n2; i++) tickz[i] = i/invspz; } } if (bSums) { for (i=0; i<n1; ++i) { fprintf(stdout,"Density sums:\n"); rowsum=0; for (j=0; j<n2; ++j) rowsum+=grid[i][j]; fprintf(stdout,"%g\t",rowsum); } fprintf(stdout,"\n"); } sprintf(buf,"%s number density",grpname[anagrp]); if (!bRadial && (bXmin || bXmax)) { if (!bXmax) sprintf(buf+strlen(buf),", %c > %g nm",eaver[0][0],xmin); else if (!bXmin) sprintf(buf+strlen(buf),", %c < %g nm",eaver[0][0],xmax); else sprintf(buf+strlen(buf),", %c: %g - %g nm",eaver[0][0],xmin,xmax); } if (ftp2bSet(efDAT,NFILE,fnm)) { fp = ffopen(ftp2fn(efDAT,NFILE,fnm),"w"); /*optional text form output: first row is tickz; first col is tickx */ fprintf(fp,"0\t"); for(j=0; j<n2; ++j) fprintf(fp,"%g\t",tickz[j]); fprintf(fp,"\n"); for (i=0; i<n1; ++i) { fprintf(fp,"%g\t",tickx[i]); for (j=0; j<n2; ++j) fprintf(fp,"%g\t",grid[i][j]); fprintf(fp,"\n"); } ffclose(fp); } else { fp = ffopen(ftp2fn(efXPM,NFILE,fnm),"w"); write_xpm(fp,MAT_SPATIAL_X | MAT_SPATIAL_Y,buf,unit, bRadial ? "axial (nm)" : label[c1],bRadial ? "r (nm)" : label[c2], n1,n2,tickx,tickz,grid,dmin,maxgrid,rlo,rhi,&nlev); ffclose(fp); } thanx(stderr); do_view(oenv,opt2fn("-o",NFILE,fnm),NULL); return 0; }
int cmain (int argc, char *argv[]) { const char *desc[] = { "tpbconv can edit run input files in four ways.[PAR]", "[BB]1.[bb] by modifying the number of steps in a run input file", "with options [TT]-extend[tt], [TT]-until[tt] or [TT]-nsteps[tt]", "(nsteps=-1 means unlimited number of steps)[PAR]", "[BB]2.[bb] (OBSOLETE) by creating a run input file", "for a continuation run when your simulation has crashed due to e.g.", "a full disk, or by making a continuation run input file.", "This option is obsolete, since mdrun now writes and reads", "checkpoint files.", "[BB]Note[bb] that a frame with coordinates and velocities is needed.", "When pressure and/or Nose-Hoover temperature coupling is used", "an energy file can be supplied to get an exact continuation", "of the original run.[PAR]", "[BB]3.[bb] by creating a [TT].tpx[tt] file for a subset of your original", "tpx file, which is useful when you want to remove the solvent from", "your [TT].tpx[tt] file, or when you want to make e.g. a pure C[GRK]alpha[grk] [TT].tpx[tt] file.", "Note that you may need to use [TT]-nsteps -1[tt] (or similar) to get", "this to work.", "[BB]WARNING: this [TT].tpx[tt] file is not fully functional[bb].[PAR]", "[BB]4.[bb] by setting the charges of a specified group", "to zero. This is useful when doing free energy estimates", "using the LIE (Linear Interaction Energy) method." }; const char *top_fn, *frame_fn; t_fileio *fp; ener_file_t fp_ener = NULL; t_trnheader head; int i; gmx_large_int_t nsteps_req, run_step, frame; double run_t, state_t; gmx_bool bOK, bNsteps, bExtend, bUntil, bTime, bTraj; gmx_bool bFrame, bUse, bSel, bNeedEner, bReadEner, bScanEner, bFepState; gmx_mtop_t mtop; t_atoms atoms; t_inputrec *ir, *irnew = NULL; t_gromppopts *gopts; t_state state; rvec *newx = NULL, *newv = NULL, *tmpx, *tmpv; matrix newbox; int gnx; char *grpname; atom_id *index = NULL; int nre; gmx_enxnm_t *enm = NULL; t_enxframe *fr_ener = NULL; char buf[200], buf2[200]; output_env_t oenv; t_filenm fnm[] = { { efTPX, NULL, NULL, ffREAD }, { efTRN, "-f", NULL, ffOPTRD }, { efEDR, "-e", NULL, ffOPTRD }, { efNDX, NULL, NULL, ffOPTRD }, { efTPX, "-o", "tpxout", ffWRITE } }; #define NFILE asize(fnm) /* Command line options */ static int nsteps_req_int = 0; static real start_t = -1.0, extend_t = 0.0, until_t = 0.0; static int init_fep_state = 0; static gmx_bool bContinuation = TRUE, bZeroQ = FALSE, bVel = TRUE; static t_pargs pa[] = { { "-extend", FALSE, etREAL, {&extend_t}, "Extend runtime by this amount (ps)" }, { "-until", FALSE, etREAL, {&until_t}, "Extend runtime until this ending time (ps)" }, { "-nsteps", FALSE, etINT, {&nsteps_req_int}, "Change the number of steps" }, { "-time", FALSE, etREAL, {&start_t}, "Continue from frame at this time (ps) instead of the last frame" }, { "-zeroq", FALSE, etBOOL, {&bZeroQ}, "Set the charges of a group (from the index) to zero" }, { "-vel", FALSE, etBOOL, {&bVel}, "Require velocities from trajectory" }, { "-cont", FALSE, etBOOL, {&bContinuation}, "For exact continuation, the constraints should not be applied before the first step" }, { "-init_fep_state", FALSE, etINT, {&init_fep_state}, "fep state to initialize from" }, }; int nerror = 0; CopyRight(stderr, argv[0]); /* Parse the command line */ parse_common_args(&argc, argv, 0, NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL, &oenv); /* Convert int to gmx_large_int_t */ nsteps_req = nsteps_req_int; bNsteps = opt2parg_bSet("-nsteps", asize(pa), pa); bExtend = opt2parg_bSet("-extend", asize(pa), pa); bUntil = opt2parg_bSet("-until", asize(pa), pa); bFepState = opt2parg_bSet("-init_fep_state", asize(pa), pa); bTime = opt2parg_bSet("-time", asize(pa), pa); bTraj = (opt2bSet("-f", NFILE, fnm) || bTime); top_fn = ftp2fn(efTPX, NFILE, fnm); fprintf(stderr, "Reading toplogy and stuff from %s\n", top_fn); snew(ir, 1); read_tpx_state(top_fn, ir, &state, NULL, &mtop); run_step = ir->init_step; run_t = ir->init_step*ir->delta_t + ir->init_t; if (!EI_STATE_VELOCITY(ir->eI)) { bVel = FALSE; } if (bTraj) { fprintf(stderr, "\n" "NOTE: Reading the state from trajectory is an obsolete feature of tpbconv.\n" " Continuation should be done by loading a checkpoint file with mdrun -cpi\n" " This guarantees that all state variables are transferred.\n" " tpbconv is now only useful for increasing nsteps,\n" " but even that can often be avoided by using mdrun -maxh\n" "\n"); if (ir->bContinuation != bContinuation) { fprintf(stderr, "Modifying ir->bContinuation to %s\n", bool_names[bContinuation]); } ir->bContinuation = bContinuation; bNeedEner = (ir->epc == epcPARRINELLORAHMAN || ir->etc == etcNOSEHOOVER); bReadEner = (bNeedEner && ftp2bSet(efEDR, NFILE, fnm)); bScanEner = (bReadEner && !bTime); if (ir->epc != epcNO || EI_SD(ir->eI) || ir->eI == eiBD) { fprintf(stderr, "NOTE: The simulation uses pressure coupling and/or stochastic dynamics.\n" "tpbconv can not provide binary identical continuation.\n" "If you want that, supply a checkpoint file to mdrun\n\n"); } if (EI_SD(ir->eI) || ir->eI == eiBD) { fprintf(stderr, "\nChanging ld-seed from %d ", ir->ld_seed); ir->ld_seed = make_seed(); fprintf(stderr, "to %d\n\n", ir->ld_seed); } frame_fn = ftp2fn(efTRN, NFILE, fnm); if (fn2ftp(frame_fn) == efCPT) { int sim_part; fprintf(stderr, "\nREADING STATE FROM CHECKPOINT %s...\n\n", frame_fn); read_checkpoint_state(frame_fn, &sim_part, &run_step, &run_t, &state); } else { fprintf(stderr, "\nREADING COORDS, VELS AND BOX FROM TRAJECTORY %s...\n\n", frame_fn); fp = open_trn(frame_fn, "r"); if (bScanEner) { fp_ener = open_enx(ftp2fn(efEDR, NFILE, fnm), "r"); do_enxnms(fp_ener, &nre, &enm); snew(fr_ener, 1); fr_ener->t = -1e-12; } /* Now scan until the last set of x and v (step == 0) * or the ones at step step. */ bFrame = TRUE; frame = 0; while (bFrame) { bFrame = fread_trnheader(fp, &head, &bOK); if (bOK && frame == 0) { if (mtop.natoms != head.natoms) { gmx_fatal(FARGS, "Number of atoms in Topology (%d) " "is not the same as in Trajectory (%d)\n", mtop.natoms, head.natoms); } snew(newx, head.natoms); snew(newv, head.natoms); } bFrame = bFrame && bOK; if (bFrame) { bOK = fread_htrn(fp, &head, newbox, newx, newv, NULL); } bFrame = bFrame && bOK; bUse = FALSE; if (bFrame && (head.x_size) && (head.v_size || !bVel)) { bUse = TRUE; if (bScanEner) { /* Read until the energy time is >= the trajectory time */ while (fr_ener->t < head.t && do_enx(fp_ener, fr_ener)) { ; } bUse = (fr_ener->t == head.t); } if (bUse) { tmpx = newx; newx = state.x; state.x = tmpx; tmpv = newv; newv = state.v; state.v = tmpv; run_t = head.t; run_step = head.step; state.fep_state = head.fep_state; state.lambda[efptFEP] = head.lambda; copy_mat(newbox, state.box); } } if (bFrame || !bOK) { sprintf(buf, "\r%s %s frame %s%s: step %s%s time %s", "%s", "%s", "%6", gmx_large_int_fmt, "%6", gmx_large_int_fmt, " %8.3f"); fprintf(stderr, buf, bUse ? "Read " : "Skipped", ftp2ext(fn2ftp(frame_fn)), frame, head.step, head.t); frame++; if (bTime && (head.t >= start_t)) { bFrame = FALSE; } } } if (bScanEner) { close_enx(fp_ener); free_enxframe(fr_ener); free_enxnms(nre, enm); } close_trn(fp); fprintf(stderr, "\n"); if (!bOK) { fprintf(stderr, "%s frame %s (step %s, time %g) is incomplete\n", ftp2ext(fn2ftp(frame_fn)), gmx_step_str(frame-1, buf2), gmx_step_str(head.step, buf), head.t); } fprintf(stderr, "\nUsing frame of step %s time %g\n", gmx_step_str(run_step, buf), run_t); if (bNeedEner) { if (bReadEner) { get_enx_state(ftp2fn(efEDR, NFILE, fnm), run_t, &mtop.groups, ir, &state); } else { fprintf(stderr, "\nWARNING: The simulation uses %s temperature and/or %s pressure coupling,\n" " the continuation will only be exact when an energy file is supplied\n\n", ETCOUPLTYPE(etcNOSEHOOVER), EPCOUPLTYPE(epcPARRINELLORAHMAN)); } } if (bFepState) { ir->fepvals->init_fep_state = init_fep_state; } } } if (bNsteps) { fprintf(stderr, "Setting nsteps to %s\n", gmx_step_str(nsteps_req, buf)); ir->nsteps = nsteps_req; } else { /* Determine total number of steps remaining */ if (bExtend) { ir->nsteps = ir->nsteps - (run_step - ir->init_step) + (gmx_large_int_t)(extend_t/ir->delta_t + 0.5); printf("Extending remaining runtime of by %g ps (now %s steps)\n", extend_t, gmx_step_str(ir->nsteps, buf)); } else if (bUntil) { printf("nsteps = %s, run_step = %s, current_t = %g, until = %g\n", gmx_step_str(ir->nsteps, buf), gmx_step_str(run_step, buf2), run_t, until_t); ir->nsteps = (gmx_large_int_t)((until_t - run_t)/ir->delta_t + 0.5); printf("Extending remaining runtime until %g ps (now %s steps)\n", until_t, gmx_step_str(ir->nsteps, buf)); } else { ir->nsteps -= run_step - ir->init_step; /* Print message */ printf("%s steps (%g ps) remaining from first run.\n", gmx_step_str(ir->nsteps, buf), ir->nsteps*ir->delta_t); } } if (bNsteps || bZeroQ || (ir->nsteps > 0)) { ir->init_step = run_step; if (ftp2bSet(efNDX, NFILE, fnm) || !(bNsteps || bExtend || bUntil || bTraj)) { atoms = gmx_mtop_global_atoms(&mtop); get_index(&atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &gnx, &index, &grpname); if (!bZeroQ) { bSel = (gnx != state.natoms); for (i = 0; ((i < gnx) && (!bSel)); i++) { bSel = (i != index[i]); } } else { bSel = FALSE; } if (bSel) { fprintf(stderr, "Will write subset %s of original tpx containing %d " "atoms\n", grpname, gnx); reduce_topology_x(gnx, index, &mtop, state.x, state.v); state.natoms = gnx; } else if (bZeroQ) { zeroq(gnx, index, &mtop); fprintf(stderr, "Zero-ing charges for group %s\n", grpname); } else { fprintf(stderr, "Will write full tpx file (no selection)\n"); } } state_t = ir->init_t + ir->init_step*ir->delta_t; sprintf(buf, "Writing statusfile with starting step %s%s and length %s%s steps...\n", "%10", gmx_large_int_fmt, "%10", gmx_large_int_fmt); fprintf(stderr, buf, ir->init_step, ir->nsteps); fprintf(stderr, " time %10.3f and length %10.3f ps\n", state_t, ir->nsteps*ir->delta_t); write_tpx_state(opt2fn("-o", NFILE, fnm), ir, &state, &mtop); } else { printf("You've simulated long enough. Not writing tpr file\n"); } thanx(stderr); return 0; }
int main(int argc,char *argv[]) { static char *desc[] = { "The [TT]pmetest[tt] program tests the scaling of the PME code. When only given", "a [TT].tpr[tt] file it will compute PME for one frame. When given a trajectory", "it will do so for all the frames in the trajectory. Before the PME", "routine is called the coordinates are sorted along the X-axis.[PAR]", "As an extra service to the public the program can also compute", "long-range Coulomb energies for components of the system. When the", "[TT]-groups[tt] flag is given to the program the energy groups", "from the [TT].tpr[tt] file will be read, and half an energy matrix computed." }; t_commrec *cr,*mcr; static t_filenm fnm[] = { { efTPX, NULL, NULL, ffREAD }, { efTRN, "-o", NULL, ffWRITE }, { efLOG, "-g", "pme", ffWRITE }, { efTRX, "-f", NULL, ffOPTRD }, { efXVG, "-x", "ener-pme", ffWRITE } }; #define NFILE asize(fnm) /* Command line options ! */ static gmx_bool bVerbose=FALSE; static gmx_bool bOptFFT=FALSE; static gmx_bool bSort=FALSE; static int ewald_geometry=eewg3D; static int nnodes=1; static int pme_order=0; static rvec grid = { -1, -1, -1 }; static real rc = 0.0; static real dtol = 0.0; static gmx_bool bGroups = FALSE; static t_pargs pa[] = { { "-np", FALSE, etINT, {&nnodes}, "Number of nodes, must be the same as used for [TT]grompp[tt]" }, { "-v", FALSE, etBOOL,{&bVerbose}, "Be loud and noisy" }, { "-sort", FALSE, etBOOL,{&bSort}, "Sort coordinates. Crucial for domain decomposition." }, { "-grid", FALSE, etRVEC,{&grid}, "Number of grid cells in X, Y, Z dimension (if -1 use from [TT].tpr[tt])" }, { "-order", FALSE, etINT, {&pme_order}, "Order of the PME spreading algorithm" }, { "-groups", FALSE, etBOOL, {&bGroups}, "Compute half an energy matrix based on the energy groups in your [TT].tpr[tt] file" }, { "-rc", FALSE, etREAL, {&rc}, "Rcoulomb for Ewald summation" }, { "-tol", FALSE, etREAL, {&dtol}, "Tolerance for Ewald summation" } }; FILE *fp; t_inputrec *ir; t_topology top; t_tpxheader tpx; t_nrnb nrnb; t_nsborder *nsb; t_forcerec *fr; t_mdatoms *mdatoms; char title[STRLEN]; int natoms,step,status,i,ncg,root; real t,lambda,ewaldcoeff,qtot; rvec *x,*f,*xbuf; int *index; gmx_bool bCont; real *charge,*qbuf,*qqbuf; matrix box; /* Start the actual parallel code if necessary */ cr = init_par(&argc,&argv); root = 0; if (MASTER(cr)) CopyRight(stderr,argv[0]); /* Parse command line on all processors, arguments are passed on in * init_par (see above) */ parse_common_args(&argc,argv, PCA_KEEP_ARGS | PCA_NOEXIT_ON_ARGS | PCA_BE_NICE | PCA_CAN_SET_DEFFNM | (MASTER(cr) ? 0 : PCA_QUIET), NFILE,fnm,asize(pa),pa,asize(desc),desc,0,NULL); #ifndef GMX_MPI if (nnodes > 1) gmx_fatal(FARGS,"GROMACS compiled without MPI support - can't do parallel runs"); #endif /* Open log files on all processors */ open_log(ftp2fn(efLOG,NFILE,fnm),cr); snew(ir,1); if (MASTER(cr)) { /* Read tpr file etc. */ read_tpxheader(ftp2fn(efTPX,NFILE,fnm),&tpx,FALSE,NULL,NULL); snew(x,tpx.natoms); read_tpx(ftp2fn(efTPX,NFILE,fnm),&step,&t,&lambda,ir, box,&natoms,x,NULL,NULL,&top); /* Charges */ qtot = 0; snew(charge,natoms); for(i=0; (i<natoms); i++) { charge[i] = top.atoms.atom[i].q; qtot += charge[i]; } /* Grid stuff */ if (opt2parg_bSet("-grid",asize(pa),pa)) { ir->nkx = grid[XX]; ir->nky = grid[YY]; ir->nkz = grid[ZZ]; } /* Check command line parameters for consistency */ if ((ir->nkx <= 0) || (ir->nky <= 0) || (ir->nkz <= 0)) gmx_fatal(FARGS,"PME grid = %d %d %d",ir->nkx,ir->nky,ir->nkz); if (opt2parg_bSet("-rc",asize(pa),pa)) ir->rcoulomb = rc; if (ir->rcoulomb <= 0) gmx_fatal(FARGS,"rcoulomb should be > 0 (not %f)",ir->rcoulomb); if (opt2parg_bSet("-order",asize(pa),pa)) ir->pme_order = pme_order; if (ir->pme_order <= 0) gmx_fatal(FARGS,"pme_order should be > 0 (not %d)",ir->pme_order); if (opt2parg_bSet("-tol",asize(pa),pa)) ir->ewald_rtol = dtol; if (ir->ewald_rtol <= 0) gmx_fatal(FARGS,"ewald_tol should be > 0 (not %f)",ir->ewald_rtol); } else { init_top(&top); } /* Add parallellization code here */ snew(nsb,1); if (MASTER(cr)) { ncg = top.blocks[ebCGS].multinr[0]; for(i=0; (i<cr->nnodes-1); i++) top.blocks[ebCGS].multinr[i] = min(ncg,(ncg*(i+1))/cr->nnodes); for( ; (i<MAXNODES); i++) top.blocks[ebCGS].multinr[i] = ncg; } if (PAR(cr)) { /* Set some variables to zero to avoid core dumps */ ir->opts.ngtc = ir->opts.ngacc = ir->opts.ngfrz = ir->opts.ngener = 0; #ifdef GMX_MPI /* Distribute the data over processors */ MPI_Bcast(&natoms,1,MPI_INT,root,MPI_COMM_WORLD); MPI_Bcast(ir,sizeof(*ir),MPI_BYTE,root,MPI_COMM_WORLD); MPI_Bcast(&qtot,1,GMX_MPI_REAL,root,MPI_COMM_WORLD); #endif /* Call some dedicated communication routines, master sends n-1 times */ if (MASTER(cr)) { for(i=1; (i<cr->nnodes); i++) { mv_block(i,&(top.blocks[ebCGS])); mv_block(i,&(top.atoms.excl)); } } else { ld_block(root,&(top.blocks[ebCGS])); ld_block(root,&(top.atoms.excl)); } if (!MASTER(cr)) { snew(charge,natoms); snew(x,natoms); } #ifdef GMX_MPI MPI_Bcast(charge,natoms,GMX_MPI_REAL,root,MPI_COMM_WORLD); #endif } ewaldcoeff = calc_ewaldcoeff(ir->rcoulomb,ir->ewald_rtol); if (bVerbose) pr_inputrec(stdlog,0,"Inputrec",ir); /* Allocate memory for temp arrays etc. */ snew(xbuf,natoms); snew(f,natoms); snew(qbuf,natoms); snew(qqbuf,natoms); snew(index,natoms); /* Initialize the PME code */ init_pme(stdlog,cr,ir->nkx,ir->nky,ir->nkz,ir->pme_order, natoms,FALSE,bOptFFT,ewald_geometry); /* MFlops accounting */ init_nrnb(&nrnb); /* Initialize the work division */ calc_nsb(stdlog,&(top.blocks[ebCGS]),cr->nnodes,nsb,0); nsb->nodeid = cr->nodeid; print_nsb(stdlog,"pmetest",nsb); /* Initiate forcerec */ mdatoms = atoms2md(stdlog,&top.atoms,ir->opts.nFreeze,ir->eI, ir->delta_t,0,ir->opts.tau_t,FALSE,FALSE); snew(fr,1); init_forcerec(stdlog,fr,ir,&top,cr,mdatoms,nsb,box,FALSE,NULL,NULL,FALSE); /* First do PME based on coordinates in tpr file, send them to * other processors if needed. */ if (MASTER(cr)) fprintf(stdlog,"-----\n" "Results based on tpr file %s\n",ftp2fn(efTPX,NFILE,fnm)); #ifdef GMX_MPI if (PAR(cr)) { MPI_Bcast(x[0],natoms*DIM,GMX_MPI_REAL,root,MPI_COMM_WORLD); MPI_Bcast(box[0],DIM*DIM,GMX_MPI_REAL,root,MPI_COMM_WORLD); MPI_Bcast(&t,1,GMX_MPI_REAL,root,MPI_COMM_WORLD); } #endif do_my_pme(stdlog,0,bVerbose,ir,x,xbuf,f,charge,qbuf,qqbuf,box,bSort, cr,nsb,&nrnb,&(top.atoms.excl),qtot,fr,index,NULL, bGroups ? ir->opts.ngener : 1,mdatoms->cENER); /* If we have a trajectry file, we will read the frames in it and compute * the PME energy. */ if (ftp2bSet(efTRX,NFILE,fnm)) { fprintf(stdlog,"-----\n" "Results based on trx file %s\n",ftp2fn(efTRX,NFILE,fnm)); if (MASTER(cr)) { sfree(x); natoms = read_first_x(&status,ftp2fn(efTRX,NFILE,fnm),&t,&x,box); if (natoms != top.atoms.nr) gmx_fatal(FARGS,"natoms in trx = %d, in tpr = %d",natoms,top.atoms.nr); fp = xvgropen(ftp2fn(efXVG,NFILE,fnm),"PME Energy","Time (ps)","E (kJ/mol)"); } else fp = NULL; do { /* Send coordinates, box and time to the other nodes */ #ifdef GMX_MPI if (PAR(cr)) { MPI_Bcast(x[0],natoms*DIM,GMX_MPI_REAL,root,MPI_COMM_WORLD); MPI_Bcast(box[0],DIM*DIM,GMX_MPI_REAL,root,MPI_COMM_WORLD); MPI_Bcast(&t,1,GMX_MPI_REAL,root,MPI_COMM_WORLD); } #endif rm_pbc(&top.idef,nsb->natoms,box,x,x); /* Call the PME wrapper function */ do_my_pme(stdlog,t,bVerbose,ir,x,xbuf,f,charge,qbuf,qqbuf,box,bSort,cr, nsb,&nrnb,&(top.atoms.excl),qtot,fr,index,fp, bGroups ? ir->opts.ngener : 1,mdatoms->cENER); /* Only the master processor reads more data */ if (MASTER(cr)) bCont = read_next_x(status,&t,natoms,x,box); /* Check whether we need to continue */ #ifdef GMX_MPI if (PAR(cr)) MPI_Bcast(&bCont,1,MPI_INT,root,MPI_COMM_WORLD); #endif } while (bCont); /* Finish I/O, close files */ if (MASTER(cr)) { close_trx(status); ffclose(fp); } } if (bVerbose) { /* Do some final I/O about performance, might be useful in debugging */ fprintf(stdlog,"-----\n"); print_nrnb(stdlog,&nrnb); } /* Finish the parallel stuff */ if (gmx_parallel_env_initialized()) gmx_finalize(cr); /* Thank the audience, as usual */ if (MASTER(cr)) thanx(stderr); return 0; }
int gmx_dielectric(int argc,char *argv[]) { static char *desc[] = { "dielectric calculates frequency dependent dielectric constants", "from the autocorrelation function of the total dipole moment in", "your simulation. This ACF can be generated by g_dipoles.", "For an estimate of the error you can run g_statistics on the", "ACF, and use the output thus generated for this program.", "The functional forms of the available functions are:[PAR]", "One parmeter : y = Exp[-a1 x]", "Two parmeters : y = a2 Exp[-a1 x]", "Three parmeter: y = a2 Exp[-a1 x] + (1 - a2) Exp[-a3 x]", "Startvalues for the fit procedure can be given on the commandline.", "It is also possible to fix parameters at their start value, use -fix", "with the number of the parameter you want to fix.", "[PAR]", "Three output files are generated, the first contains the ACF,", "an exponential fit to it with 1, 2 or 3 parameters, and the", "numerical derivative of the combination data/fit.", "The second file contains the real and imaginary parts of the", "frequency-dependent dielectric constant, the last gives a plot", "known as the Cole-Cole plot, in which the imaginary", "component is plotted as a function of the real component.", "For a pure exponential relaxation (Debye relaxation) the latter", "plot should be one half of a circle" }; t_filenm fnm[] = { { efXVG, "-f", "dipcorr",ffREAD }, { efXVG, "-d", "deriv", ffWRITE }, { efXVG, "-o", "epsw", ffWRITE }, { efXVG, "-c", "cole", ffWRITE } }; #define NFILE asize(fnm) int i,j,nx,ny,nxtail,eFitFn,nfitparm; real dt,integral,fitintegral,*fitparms,fac,rffac; double **yd; real **y; char *legend[] = { "Correlation", "Std. Dev.", "Fit", "Combined", "Derivative" }; static int fix=0,bFour = 0,bX = 1,nsmooth=3; static real tendInt=5.0,tbegin=5.0,tend=500.0; static real A=0.5,tau1=10.0,tau2=1.0,eps0=80,epsRF=78.5,tail=500.0; real lambda; t_pargs pa[] = { { "-fft", FALSE, etBOOL, {&bFour}, "use fast fourier transform for correlation function" }, { "-x1", FALSE, etBOOL, {&bX}, "use first column as X axis rather than first data set" }, { "-eint", FALSE, etREAL, {&tendInt}, "Time were to end the integration of the data and start to use the fit"}, { "-bfit", FALSE, etREAL, {&tbegin}, "Begin time of fit" }, { "-efit", FALSE, etREAL, {&tend}, "End time of fit" }, { "-tail", FALSE, etREAL, {&tail}, "Length of function including data and tail from fit" }, { "-A", FALSE, etREAL, {&A}, "Start value for fit parameter A" }, { "-tau1", FALSE, etREAL, {&tau1}, "Start value for fit parameter tau1" }, { "-tau2", FALSE, etREAL, {&tau2}, "Start value for fit parameter tau2" }, { "-eps0", FALSE, etREAL, {&eps0}, "Epsilon 0 of your liquid" }, { "-epsRF", FALSE, etREAL, {&epsRF}, "Epsilon of the reaction field used in your simulation. A value of 0 means infinity." }, { "-fix", FALSE, etINT, {&fix}, "Fix parameters at their start values, A (2), tau1 (1), or tau2 (4)" }, { "-ffn", FALSE, etENUM, {s_ffn}, "Fit function" }, { "-nsmooth", FALSE, etINT, {&nsmooth}, "Number of points for smoothing" } }; CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_CAN_VIEW | PCA_BE_NICE, NFILE,fnm,asize(pa),pa,asize(desc),desc,0,NULL); please_cite(stdout,"Spoel98a"); nx = read_xvg(opt2fn("-f",NFILE,fnm),&yd,&ny); dt = yd[0][1] - yd[0][0]; nxtail = min(tail/dt,nx); printf("Read data set containing %d colums and %d rows\n",ny,nx); printf("Assuming (from data) that timestep is %g, nxtail = %d\n", dt,nxtail); snew(y,6); for(i=0; (i<ny); i++) snew(y[i],max(nx,nxtail)); for(i=0; (i<nx); i++) { y[0][i] = yd[0][i]; for(j=1; (j<ny); j++) y[j][i] = yd[j][i]; } if (nxtail > nx) { for(i=nx; (i<nxtail); i++) { y[0][i] = dt*i+y[0][0]; for(j=1; (j<ny); j++) y[j][i] = 0.0; } nx=nxtail; } /* We have read a file WITHOUT standard deviations, so we make our own... */ if (ny==2) { printf("Creating standard deviation numbers ...\n"); srenew(y,3); snew(y[2],nx); fac=1.0/((real)nx); for(i=0; (i<nx); i++) y[2][i] = fac; } eFitFn = sffn2effn(s_ffn); nfitparm = nfp_ffn[eFitFn]; snew(fitparms,4); fitparms[0]=tau1; if (nfitparm > 1) fitparms[1]=A; if (nfitparm > 2) fitparms[2]=tau2; snew(y[3],nx); snew(y[4],nx); snew(y[5],nx); integral = print_and_integrate(NULL,calc_nbegin(nx,y[0],tbegin), dt,y[1],NULL,1); integral += do_lmfit(nx,y[1],y[2],dt,y[0],tbegin,tend, TRUE,eFitFn,fitparms,fix); for(i=0; i<nx; i++) y[3][i] = fit_function(eFitFn,fitparms,y[0][i]); if (epsRF == 0) { /* This means infinity! */ lambda = 0; rffac = 1; } else { lambda = (eps0 - 1.0)/(2*epsRF - 1.0); rffac = (2*epsRF+eps0)/(2*epsRF+1); } printf("DATA INTEGRAL: %5.1f, tauD(old) = %5.1f ps, " "tau_slope = %5.1f, tau_slope,D = %5.1f ps\n", integral,integral*rffac,fitparms[0],fitparms[0]*rffac); printf("tau_D from tau1 = %8.3g , eps(Infty) = %8.3f\n", fitparms[0]*(1 + fitparms[1]*lambda), 1 + ((1 - fitparms[1])*(eps0 - 1))/(1 + fitparms[1]*lambda)); fitintegral=numerical_deriv(nx,y[0],y[1],y[3],y[4],y[5],tendInt,nsmooth); printf("FIT INTEGRAL (tau_M): %5.1f, tau_D = %5.1f\n", fitintegral,fitintegral*rffac); /* Now we have the negative gradient of <Phi(0) Phi(t)> */ write_xvg(opt2fn("-d",NFILE,fnm),"Data",nx-1,6,y,legend); /* Do FFT and analysis */ do_four(opt2fn("-o",NFILE,fnm),opt2fn("-c",NFILE,fnm), nx-1,y[0],y[5],eps0,epsRF); do_view(opt2fn("-o",NFILE,fnm),"-nxy"); do_view(opt2fn("-c",NFILE,fnm),NULL); do_view(opt2fn("-d",NFILE,fnm),"-nxy"); thanx(stderr); return 0; }
int main(int argc,char *argv[]) { static char *desc[] = { "[TT]g_anavel[tt] computes temperature profiles in a sample. The sample", "can be analysed radial, i.e. the temperature as a function of", "distance from the center, cylindrical, i.e. as a function of distance", "from the vector (0,0,1) through the center of the box, or otherwise", "(will be specified later)" }; t_filenm fnm[] = { { efTRN, "-f", NULL, ffREAD }, { efTPX, "-s", NULL, ffREAD }, { efXPM, "-o", "xcm", ffWRITE } }; #define NFILE asize(fnm) static int mode = 0, nlevels = 10; static real tmax = 300, xmax = -1; t_pargs pa[] = { { "-mode", FALSE, etINT, {&mode}, "mode" }, { "-nlevels", FALSE, etINT, {&nlevels}, "number of levels" }, { "-tmax", FALSE, etREAL, {&tmax}, "max temperature in output" }, { "-xmax", FALSE, etREAL, {&xmax}, "max distance from center" } }; FILE *fp; int *npts,nmax; int status; int i,j,idum,step,nframe=0,index; real temp,rdum,hboxx,hboxy,scale,xnorm=0; real **profile=NULL; real *t_x=NULL,*t_y,hi=0; t_topology *top; int d,m,n; matrix box; atom_id *sysindex; gmx_bool bHaveV,bReadV; t_rgb rgblo = { 0, 0, 1 },rgbhi = { 1, 0, 0 }; int flags = TRX_READ_X | TRX_READ_V; t_trxframe fr; CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_BE_NICE ,NFILE,fnm, asize(pa),pa,asize(desc),desc,0,NULL); top = read_top(ftp2fn(efTPX,NFILE,fnm)); read_first_frame(&status,ftp2fn(efTRX,NFILE,fnm),&fr,flags); if (xmax > 0) { scale = 5; nmax = xmax*scale; } else { scale = 5; nmax = (0.5*sqrt(sqr(box[XX][XX])+sqr(box[YY][YY])))*scale; } snew(npts,nmax+1); snew(t_y,nmax+1); for(i=0; (i<=nmax); i++) { npts[i] = 0; t_y[i] = i/scale; } do { srenew(profile,++nframe); snew(profile[nframe-1],nmax+1); srenew(t_x,nframe); t_x[nframe-1] = fr.time*1000; hboxx = box[XX][XX]/2; hboxy = box[YY][YY]/2; for(i=0; (i<fr.natoms); i++) { /* determine position dependent on mode */ switch (mode) { case 0: xnorm = sqrt(sqr(fr.x[i][XX]-hboxx) + sqr(fr.x[i][YY]-hboxy)); break; default: gmx_fatal(FARGS,"Unknown mode %d",mode); } index = xnorm*scale; if (index <= nmax) { temp = top->atoms.atom[i].m*iprod(fr.v[i],fr.v[i])/(2*BOLTZ); if (temp > hi) hi = temp; npts[index]++; profile[nframe-1][index] += temp; } } for(i=0; (i<=nmax); i++) { if (npts[i] != 0) profile[nframe-1][i] /= npts[i]; npts[i] = 0; } } while (read_next_frame(status,&fr)); close_trx(status); fp = ftp2FILE(efXPM,NFILE,fnm,"w"); write_xpm(fp,0,"Temp. profile","T (a.u.)", "t (fs)","R (nm)", nframe,nmax+1,t_x,t_y,profile,0,tmax, rgblo,rgbhi,&nlevels); thanx(stderr); return 0; }
int gmx_dist(int argc,char *argv[]) { const char *desc[] = { "[TT]g_dist[tt] can calculate the distance between the centers of mass of two", "groups of atoms as a function of time. The total distance and its", "[IT]x[it]-, [IT]y[it]-, and [IT]z[it]-components are plotted.[PAR]", "Or when [TT]-dist[tt] is set, print all the atoms in group 2 that are", "closer than a certain distance to the center of mass of group 1.[PAR]", "With options [TT]-lt[tt] and [TT]-dist[tt] the number of contacts", "of all atoms in group 2 that are closer than a certain distance", "to the center of mass of group 1 are plotted as a function of the time", "that the contact was continuously present.[PAR]", "Other programs that calculate distances are [TT]g_mindist[tt]", "and [TT]g_bond[tt]." }; t_topology *top=NULL; int ePBC; real t,t0,cut2,dist2; rvec *x=NULL,*v=NULL,dx; matrix box; t_trxstatus *status; int natoms; int g,d,i,j,res,teller=0; atom_id aid; int ngrps; /* the number of index groups */ atom_id **index,max; /* the index for the atom numbers */ int *isize; /* the size of each group */ char **grpname; /* the name of each group */ rvec *com; real *mass; FILE *fp=NULL,*fplt=NULL; gmx_bool bCutoff,bPrintDist,bLifeTime; t_pbc *pbc; int *contact_time=NULL,*ccount=NULL,ccount_nalloc=0,sum; char buf[STRLEN]; output_env_t oenv; gmx_rmpbc_t gpbc=NULL; const char *leg[4] = { "|d|","d\\sx\\N","d\\sy\\N","d\\sz\\N" }; static real cut=0; static t_pargs pa[] = { { "-dist", FALSE, etREAL, {&cut}, "Print all atoms in group 2 closer than dist to the center of mass of group 1" } }; #define NPA asize(pa) t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPX, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffOPTRD }, { efXVG, NULL, "dist", ffOPTWR }, { efXVG, "-lt", "lifetime", ffOPTWR }, }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_BE_NICE, NFILE,fnm,NPA,pa,asize(desc),desc,0,NULL,&oenv); bCutoff = opt2parg_bSet("-dist",NPA,pa); cut2 = cut*cut; bLifeTime = opt2bSet("-lt",NFILE,fnm); bPrintDist = (bCutoff && !bLifeTime); top=read_top(ftp2fn(efTPX,NFILE,fnm),&ePBC); /* read index files */ ngrps = 2; snew(com,ngrps); snew(grpname,ngrps); snew(index,ngrps); snew(isize,ngrps); get_index(&top->atoms,ftp2fn(efNDX,NFILE,fnm),ngrps,isize,index,grpname); /* calculate mass */ max=0; snew(mass,ngrps); for(g=0;(g<ngrps);g++) { mass[g]=0; for(i=0;(i<isize[g]);i++) { if (index[g][i]>max) max=index[g][i]; if (index[g][i] >= top->atoms.nr) gmx_fatal(FARGS,"Atom number %d, item %d of group %d, is larger than number of atoms in the topolgy (%d)\n",index[g][i]+1,i+1,g+1,top->atoms.nr+1); mass[g]+=top->atoms.atom[index[g][i]].m; } } natoms=read_first_x(oenv,&status,ftp2fn(efTRX,NFILE,fnm),&t,&x,box); t0 = t; if (max>=natoms) gmx_fatal(FARGS,"Atom number %d in an index group is larger than number of atoms in the trajectory (%d)\n",(int)max+1,natoms); if (!bCutoff) { /* open output file */ fp = xvgropen(ftp2fn(efXVG,NFILE,fnm), "Distance","Time (ps)","Distance (nm)",oenv); xvgr_legend(fp,4,leg,oenv); } else { ngrps = 1; if (bLifeTime) snew(contact_time,isize[1]); } if (ePBC != epbcNONE) snew(pbc,1); else pbc = NULL; gpbc = gmx_rmpbc_init(&top->idef,ePBC,natoms,box); do { /* initialisation for correct distance calculations */ if (pbc) { set_pbc(pbc,ePBC,box); /* make molecules whole again */ gmx_rmpbc(gpbc,natoms,box,x); } /* calculate center of masses */ for(g=0;(g<ngrps);g++) { if (isize[g] == 1) { copy_rvec(x[index[g][0]],com[g]); } else { for(d=0;(d<DIM);d++) { com[g][d]=0; for(i=0;(i<isize[g]);i++) { com[g][d] += x[index[g][i]][d] * top->atoms.atom[index[g][i]].m; } com[g][d] /= mass[g]; } } } if (!bCutoff) { /* write to output */ fprintf(fp,"%12.7f ",t); for(g=0;(g<ngrps/2);g++) { if (pbc) pbc_dx(pbc,com[2*g],com[2*g+1],dx); else rvec_sub(com[2*g],com[2*g+1],dx); fprintf(fp,"%12.7f %12.7f %12.7f %12.7f", norm(dx),dx[XX],dx[YY],dx[ZZ]); } fprintf(fp,"\n"); } else { for(i=0;(i<isize[1]);i++) { j=index[1][i]; if (pbc) pbc_dx(pbc,x[j],com[0],dx); else rvec_sub(x[j],com[0],dx); dist2 = norm2(dx); if (dist2<cut2) { if (bPrintDist) { res=top->atoms.atom[j].resind; fprintf(stdout,"\rt: %g %d %s %d %s %g (nm)\n", t,top->atoms.resinfo[res].nr,*top->atoms.resinfo[res].name, j+1,*top->atoms.atomname[j],sqrt(dist2)); } if (bLifeTime) contact_time[i]++; } else { if (bLifeTime) { if (contact_time[i]) { add_contact_time(&ccount,&ccount_nalloc,contact_time[i]-1); contact_time[i] = 0; } } } } } teller++; } while (read_next_x(oenv,status,&t,natoms,x,box)); gmx_rmpbc_done(gpbc); if (!bCutoff) ffclose(fp); close_trj(status); if (bCutoff && bLifeTime) { /* Add the contacts still present in the last frame */ for(i=0; i<isize[1]; i++) if (contact_time[i]) add_contact_time(&ccount,&ccount_nalloc,contact_time[i]-1); sprintf(buf,"%s - %s within %g nm", grpname[0],grpname[1],cut); fp = xvgropen(opt2fn("-lt",NFILE,fnm), buf,"Time (ps)","Number of contacts",oenv); for(i=0; i<min(ccount_nalloc,teller-1); i++) { /* Account for all subintervals of longer intervals */ sum = 0; for(j=i; j<ccount_nalloc; j++) sum += (j-i+1)*ccount[j]; fprintf(fp,"%10.3f %10.3f\n",i*(t-t0)/(teller-1),sum/(double)(teller-i)); } ffclose(fp); } thanx(stderr); return 0; }
int gmx_mdmat(int argc, char *argv[]) { const char *desc[] = { "[TT]g_mdmat[tt] makes distance matrices consisting of the smallest distance", "between residue pairs. With [TT]-frames[tt], these distance matrices can be", "stored in order to see differences in tertiary structure as a", "function of time. If you choose your options unwisely, this may generate", "a large output file. By default, only an averaged matrix over the whole", "trajectory is output.", "Also a count of the number of different atomic contacts between", "residues over the whole trajectory can be made.", "The output can be processed with [TT]xpm2ps[tt] to make a PostScript (tm) plot." }; static real truncate = 1.5; static gmx_bool bAtom = FALSE; static int nlevels = 40; t_pargs pa[] = { { "-t", FALSE, etREAL, {&truncate}, "trunc distance" }, { "-nlevels", FALSE, etINT, {&nlevels}, "Discretize distance in this number of levels" } }; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPS, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffOPTRD }, { efXPM, "-mean", "dm", ffWRITE }, { efXPM, "-frames", "dmf", ffOPTWR }, { efXVG, "-no", "num", ffOPTWR }, }; #define NFILE asize(fnm) FILE *out = NULL, *fp; t_topology top; int ePBC; t_atoms useatoms; int isize; atom_id *index; char *grpname; int *rndx, *natm, prevres, newres; int i, j, nres, natoms, nframes, it, trxnat; t_trxstatus *status; int nr0; gmx_bool bCalcN, bFrames; real t, ratio; char title[256], label[234]; t_rgb rlo, rhi; rvec *x; real **mdmat, *resnr, **totmdmat; int **nmat, **totnmat; real *mean_n; int *tot_n; matrix box; output_env_t oenv; gmx_rmpbc_t gpbc = NULL; CopyRight(stderr, argv[0]); parse_common_args(&argc, argv, PCA_CAN_TIME | PCA_BE_NICE, NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL, &oenv); fprintf(stderr, "Will truncate at %f nm\n", truncate); bCalcN = opt2bSet("-no", NFILE, fnm); bFrames = opt2bSet("-frames", NFILE, fnm); if (bCalcN) { fprintf(stderr, "Will calculate number of different contacts\n"); } read_tps_conf(ftp2fn(efTPS, NFILE, fnm), title, &top, &ePBC, &x, NULL, box, FALSE); fprintf(stderr, "Select group for analysis\n"); get_index(&top.atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &isize, &index, &grpname); natoms = isize; snew(useatoms.atom, natoms); snew(useatoms.atomname, natoms); useatoms.nres = 0; snew(useatoms.resinfo, natoms); prevres = top.atoms.atom[index[0]].resind; newres = 0; for (i = 0; (i < isize); i++) { int ii = index[i]; useatoms.atomname[i] = top.atoms.atomname[ii]; if (top.atoms.atom[ii].resind != prevres) { prevres = top.atoms.atom[ii].resind; newres++; useatoms.resinfo[i] = top.atoms.resinfo[prevres]; if (debug) { fprintf(debug, "New residue: atom %5s %5s %6d, index entry %5d, newres %5d\n", *(top.atoms.resinfo[top.atoms.atom[ii].resind].name), *(top.atoms.atomname[ii]), ii, i, newres); } } useatoms.atom[i].resind = newres; } useatoms.nres = newres+1; useatoms.nr = isize; rndx = res_ndx(&(useatoms)); natm = res_natm(&(useatoms)); nres = useatoms.nres; fprintf(stderr, "There are %d residues with %d atoms\n", nres, natoms); snew(resnr, nres); snew(mdmat, nres); snew(nmat, nres); snew(totnmat, nres); snew(mean_n, nres); snew(tot_n, nres); for (i = 0; (i < nres); i++) { snew(mdmat[i], nres); snew(nmat[i], natoms); snew(totnmat[i], natoms); resnr[i] = i+1; } snew(totmdmat, nres); for (i = 0; (i < nres); i++) { snew(totmdmat[i], nres); } trxnat = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box); nframes = 0; rlo.r = 1.0, rlo.g = 1.0, rlo.b = 1.0; rhi.r = 0.0, rhi.g = 0.0, rhi.b = 0.0; gpbc = gmx_rmpbc_init(&top.idef, ePBC, trxnat, box); if (bFrames) { out = opt2FILE("-frames", NFILE, fnm, "w"); } do { gmx_rmpbc(gpbc, trxnat, box, x); nframes++; calc_mat(nres, natoms, rndx, x, index, truncate, mdmat, nmat, ePBC, box); for (i = 0; (i < nres); i++) { for (j = 0; (j < natoms); j++) { if (nmat[i][j]) { totnmat[i][j]++; } } } for (i = 0; (i < nres); i++) { for (j = 0; (j < nres); j++) { totmdmat[i][j] += mdmat[i][j]; } } if (bFrames) { sprintf(label, "t=%.0f ps", t); write_xpm(out, 0, label, "Distance (nm)", "Residue Index", "Residue Index", nres, nres, resnr, resnr, mdmat, 0, truncate, rlo, rhi, &nlevels); } } while (read_next_x(oenv, status, &t, trxnat, x, box)); fprintf(stderr, "\n"); close_trj(status); gmx_rmpbc_done(gpbc); if (bFrames) { ffclose(out); } fprintf(stderr, "Processed %d frames\n", nframes); for (i = 0; (i < nres); i++) { for (j = 0; (j < nres); j++) { totmdmat[i][j] /= nframes; } } write_xpm(opt2FILE("-mean", NFILE, fnm, "w"), 0, "Mean smallest distance", "Distance (nm)", "Residue Index", "Residue Index", nres, nres, resnr, resnr, totmdmat, 0, truncate, rlo, rhi, &nlevels); if (bCalcN) { tot_nmat(nres, natoms, nframes, totnmat, tot_n, mean_n); fp = xvgropen(ftp2fn(efXVG, NFILE, fnm), "Increase in number of contacts", "Residue", "Ratio", oenv); fprintf(fp, "@ legend on\n"); fprintf(fp, "@ legend box on\n"); fprintf(fp, "@ legend loctype view\n"); fprintf(fp, "@ legend 0.75, 0.8\n"); fprintf(fp, "@ legend string 0 \"Total/mean\"\n"); fprintf(fp, "@ legend string 1 \"Total\"\n"); fprintf(fp, "@ legend string 2 \"Mean\"\n"); fprintf(fp, "@ legend string 3 \"# atoms\"\n"); fprintf(fp, "@ legend string 4 \"Mean/# atoms\"\n"); fprintf(fp, "#%3s %8s %3s %8s %3s %8s\n", "res", "ratio", "tot", "mean", "natm", "mean/atm"); for (i = 0; (i < nres); i++) { if (mean_n[i] == 0) { ratio = 1; } else { ratio = tot_n[i]/mean_n[i]; } fprintf(fp, "%3d %8.3f %3d %8.3f %3d %8.3f\n", i+1, ratio, tot_n[i], mean_n[i], natm[i], mean_n[i]/natm[i]); } ffclose(fp); } thanx(stderr); return 0; }
int gmx_editconf(int argc, char *argv[]) { const char *desc[] = { "editconf converts generic structure format to [TT].gro[tt], [TT].g96[tt]", "or [TT].pdb[tt].", "[PAR]", "The box can be modified with options [TT]-box[tt], [TT]-d[tt] and", "[TT]-angles[tt]. Both [TT]-box[tt] and [TT]-d[tt]", "will center the system in the box, unless [TT]-noc[tt] is used.", "[PAR]", "Option [TT]-bt[tt] determines the box type: [TT]triclinic[tt] is a", "triclinic box, [TT]cubic[tt] is a rectangular box with all sides equal", "[TT]dodecahedron[tt] represents a rhombic dodecahedron and", "[TT]octahedron[tt] is a truncated octahedron.", "The last two are special cases of a triclinic box.", "The length of the three box vectors of the truncated octahedron is the", "shortest distance between two opposite hexagons.", "The volume of a dodecahedron is 0.71 and that of a truncated octahedron", "is 0.77 of that of a cubic box with the same periodic image distance.", "[PAR]", "Option [TT]-box[tt] requires only", "one value for a cubic box, dodecahedron and a truncated octahedron.", "[PAR]", "With [TT]-d[tt] and a [TT]triclinic[tt] box the size of the system in the x, y", "and z directions is used. With [TT]-d[tt] and [TT]cubic[tt],", "[TT]dodecahedron[tt] or [TT]octahedron[tt] boxes, the dimensions are set", "to the diameter of the system (largest distance between atoms) plus twice", "the specified distance.", "[PAR]", "Option [TT]-angles[tt] is only meaningful with option [TT]-box[tt] and", "a triclinic box and can not be used with option [TT]-d[tt].", "[PAR]", "When [TT]-n[tt] or [TT]-ndef[tt] is set, a group", "can be selected for calculating the size and the geometric center,", "otherwise the whole system is used.", "[PAR]", "[TT]-rotate[tt] rotates the coordinates and velocities.", "[PAR]", "[TT]-princ[tt] aligns the principal axes of the system along the", "coordinate axes, this may allow you to decrease the box volume,", "but beware that molecules can rotate significantly in a nanosecond.", "[PAR]", "Scaling is applied before any of the other operations are", "performed. Boxes and coordinates can be scaled to give a certain density (option", "[TT]-density[tt]). Note that this may be inaccurate in case a gro", "file is given as input. A special feature of the scaling option, when the", "factor -1 is given in one dimension, one obtains a mirror image,", "mirrored in one of the plains, when one uses -1 in three dimensions", "a point-mirror image is obtained.[PAR]", "Groups are selected after all operations have been applied.[PAR]", "Periodicity can be removed in a crude manner.", "It is important that the box sizes at the bottom of your input file", "are correct when the periodicity is to be removed.", "[PAR]", "When writing [TT].pdb[tt] files, B-factors can be", "added with the [TT]-bf[tt] option. B-factors are read", "from a file with with following format: first line states number of", "entries in the file, next lines state an index", "followed by a B-factor. The B-factors will be attached per residue", "unless an index is larger than the number of residues or unless the", "[TT]-atom[tt] option is set. Obviously, any type of numeric data can", "be added instead of B-factors. [TT]-legend[tt] will produce", "a row of CA atoms with B-factors ranging from the minimum to the", "maximum value found, effectively making a legend for viewing.", "[PAR]", "With the option -mead a special pdb (pqr) file for the MEAD electrostatics", "program (Poisson-Boltzmann solver) can be made. A further prerequisite", "is that the input file is a run input file.", "The B-factor field is then filled with the Van der Waals radius", "of the atoms while the occupancy field will hold the charge.", "[PAR]", "The option -grasp is similar, but it puts the charges in the B-factor", "and the radius in the occupancy.", "[PAR]", "Option [TT]-align[tt] allows alignment", "of the principal axis of a specified group against the given vector, ", "with an optional center of rotation specified by [TT]-aligncenter[tt].", "[PAR]", "Finally with option [TT]-label[tt] editconf can add a chain identifier", "to a pdb file, which can be useful for analysis with e.g. rasmol.", "[PAR]", "To convert a truncated octrahedron file produced by a package which uses", "a cubic box with the corners cut off (such as Gromos) use:[BR]", "[TT]editconf -f <in> -rotate 0 45 35.264 -bt o -box <veclen> -o <out>[tt][BR]", "where [TT]veclen[tt] is the size of the cubic box times sqrt(3)/2." }; const char *bugs[] = { "For complex molecules, the periodicity removal routine may break down, ", "in that case you can use trjconv." }; static real dist = 0.0, rbox = 0.0, to_diam = 0.0; static gmx_bool bNDEF = FALSE, bRMPBC = FALSE, bCenter = FALSE, bReadVDW = FALSE, bCONECT = FALSE; static gmx_bool peratom = FALSE, bLegend = FALSE, bOrient = FALSE, bMead = FALSE, bGrasp = FALSE, bSig56 = FALSE; static rvec scale = { 1, 1, 1 }, newbox = { 0, 0, 0 }, newang = { 90, 90, 90 }; static real rho = 1000.0, rvdw = 0.12; static rvec center = { 0, 0, 0 }, translation = { 0, 0, 0 }, rotangles = { 0, 0, 0 }, aligncenter = { 0, 0, 0 }, targetvec = { 0, 0, 0 }; static const char *btype[] = { NULL, "triclinic", "cubic", "dodecahedron", "octahedron", NULL }, *label = "A"; static rvec visbox = { 0, 0, 0 }; t_pargs pa[] = { { "-ndef", FALSE, etBOOL, { &bNDEF }, "Choose output from default index groups" }, { "-visbox", FALSE, etRVEC, { visbox }, "HIDDENVisualize a grid of boxes, -1 visualizes the 14 box images" }, { "-bt", FALSE, etENUM, { btype }, "Box type for -box and -d" }, { "-box", FALSE, etRVEC, { newbox }, "Box vector lengths (a,b,c)" }, { "-angles", FALSE, etRVEC, { newang }, "Angles between the box vectors (bc,ac,ab)" }, { "-d", FALSE, etREAL, { &dist }, "Distance between the solute and the box" }, { "-c", FALSE, etBOOL, { &bCenter }, "Center molecule in box (implied by -box and -d)" }, { "-center", FALSE, etRVEC, { center }, "Coordinates of geometrical center" }, { "-aligncenter", FALSE, etRVEC, { aligncenter }, "Center of rotation for alignment" }, { "-align", FALSE, etRVEC, { targetvec }, "Align to target vector" }, { "-translate", FALSE, etRVEC, { translation }, "Translation" }, { "-rotate", FALSE, etRVEC, { rotangles }, "Rotation around the X, Y and Z axes in degrees" }, { "-princ", FALSE, etBOOL, { &bOrient }, "Orient molecule(s) along their principal axes" }, { "-scale", FALSE, etRVEC, { scale }, "Scaling factor" }, { "-density", FALSE, etREAL, { &rho }, "Density (g/l) of the output box achieved by scaling" }, { "-pbc", FALSE, etBOOL, { &bRMPBC }, "Remove the periodicity (make molecule whole again)" }, { "-grasp", FALSE, etBOOL, { &bGrasp }, "Store the charge of the atom in the B-factor field and the radius of the atom in the occupancy field" }, { "-rvdw", FALSE, etREAL, { &rvdw }, "Default Van der Waals radius (in nm) if one can not be found in the database or if no parameters are present in the topology file" }, { "-sig56", FALSE, etREAL, { &bSig56 }, "Use rmin/2 (minimum in the Van der Waals potential) rather than sigma/2 " }, { "-vdwread", FALSE, etBOOL, { &bReadVDW }, "Read the Van der Waals radii from the file vdwradii.dat rather than computing the radii based on the force field" }, { "-atom", FALSE, etBOOL, { &peratom }, "Force B-factor attachment per atom" }, { "-legend", FALSE, etBOOL, { &bLegend }, "Make B-factor legend" }, { "-label", FALSE, etSTR, { &label }, "Add chain label for all residues" }, { "-conect", FALSE, etBOOL, { &bCONECT }, "Add CONECT records to a pdb file when written. Can only be done when a topology is present" } }; #define NPA asize(pa) FILE *out; const char *infile, *outfile; char title[STRLEN]; int outftp, inftp, natom, i, j, n_bfac, itype, ntype; double *bfac = NULL, c6, c12; int *bfac_nr = NULL; t_topology *top = NULL; t_atoms atoms; char *grpname, *sgrpname, *agrpname; int isize, ssize, tsize, asize; atom_id *index, *sindex, *tindex, *aindex; rvec *x, *v, gc, min, max, size; int ePBC; matrix box,rotmatrix,trans; rvec princd,tmpvec; gmx_bool bIndex, bSetSize, bSetAng, bCubic, bDist, bSetCenter, bAlign; gmx_bool bHaveV, bScale, bRho, bTranslate, bRotate, bCalcGeom, bCalcDiam; real xs, ys, zs, xcent, ycent, zcent, diam = 0, mass = 0, d, vdw; gmx_atomprop_t aps; gmx_conect conect; output_env_t oenv; t_filenm fnm[] = { { efSTX, "-f", NULL, ffREAD }, { efNDX, "-n", NULL, ffOPTRD }, { efSTO, NULL, NULL, ffOPTWR }, { efPQR, "-mead", "mead", ffOPTWR }, { efDAT, "-bf", "bfact", ffOPTRD } }; #define NFILE asize(fnm) CopyRight(stderr, argv[0]); parse_common_args(&argc, argv, PCA_CAN_VIEW, NFILE, fnm, NPA, pa, asize(desc), desc, asize(bugs), bugs, &oenv); bIndex = opt2bSet("-n", NFILE, fnm) || bNDEF; bMead = opt2bSet("-mead", NFILE, fnm); bSetSize = opt2parg_bSet("-box", NPA, pa); bSetAng = opt2parg_bSet("-angles", NPA, pa); bSetCenter = opt2parg_bSet("-center", NPA, pa); bDist = opt2parg_bSet("-d", NPA, pa); bAlign = opt2parg_bSet("-align", NPA, pa); /* Only automatically turn on centering without -noc */ if ((bDist || bSetSize || bSetCenter) && !opt2parg_bSet("-c", NPA, pa)) { bCenter = TRUE; } bScale = opt2parg_bSet("-scale", NPA, pa); bRho = opt2parg_bSet("-density", NPA, pa); bTranslate = opt2parg_bSet("-translate", NPA, pa); bRotate = opt2parg_bSet("-rotate", NPA, pa); if (bScale && bRho) fprintf(stderr, "WARNING: setting -density overrides -scale\n"); bScale = bScale || bRho; bCalcGeom = bCenter || bRotate || bOrient || bScale; bCalcDiam = btype[0][0] == 'c' || btype[0][0] == 'd' || btype[0][0] == 'o'; infile = ftp2fn(efSTX, NFILE, fnm); if (bMead) outfile = ftp2fn(efPQR, NFILE, fnm); else outfile = ftp2fn(efSTO, NFILE, fnm); outftp = fn2ftp(outfile); inftp = fn2ftp(infile); aps = gmx_atomprop_init(); if (bMead && bGrasp) { printf("Incompatible options -mead and -grasp. Turning off -grasp\n"); bGrasp = FALSE; } if (bGrasp && (outftp != efPDB)) gmx_fatal(FARGS, "Output file should be a .pdb file" " when using the -grasp option\n"); if ((bMead || bGrasp) && !((fn2ftp(infile) == efTPR) || (fn2ftp(infile) == efTPA) || (fn2ftp(infile) == efTPB))) gmx_fatal(FARGS,"Input file should be a .tp[abr] file" " when using the -mead option\n"); get_stx_coordnum(infile,&natom); init_t_atoms(&atoms,natom,TRUE); snew(x,natom); snew(v,natom); read_stx_conf(infile,title,&atoms,x,v,&ePBC,box); if (fn2ftp(infile) == efPDB) { get_pdb_atomnumber(&atoms,aps); } printf("Read %d atoms\n",atoms.nr); /* Get the element numbers if available in a pdb file */ if (fn2ftp(infile) == efPDB) get_pdb_atomnumber(&atoms,aps); if (ePBC != epbcNONE) { real vol = det(box); printf("Volume: %g nm^3, corresponds to roughly %d electrons\n", vol,100*((int)(vol*4.5))); } if (bMead || bGrasp || bCONECT) top = read_top(infile,NULL); if (bMead || bGrasp) { if (atoms.nr != top->atoms.nr) gmx_fatal(FARGS,"Atom numbers don't match (%d vs. %d)",atoms.nr,top->atoms.nr); snew(atoms.pdbinfo,top->atoms.nr); ntype = top->idef.atnr; for(i=0; (i<atoms.nr); i++) { /* Determine the Van der Waals radius from the force field */ if (bReadVDW) { if (!gmx_atomprop_query(aps,epropVDW, *top->atoms.resinfo[top->atoms.atom[i].resind].name, *top->atoms.atomname[i],&vdw)) vdw = rvdw; } else { itype = top->atoms.atom[i].type; c12 = top->idef.iparams[itype*ntype+itype].lj.c12; c6 = top->idef.iparams[itype*ntype+itype].lj.c6; if ((c6 != 0) && (c12 != 0)) { real sig6; if (bSig56) sig6 = 2*c12/c6; else sig6 = c12/c6; vdw = 0.5*pow(sig6,1.0/6.0); } else vdw = rvdw; } /* Factor of 10 for nm -> Angstroms */ vdw *= 10; if (bMead) { atoms.pdbinfo[i].occup = top->atoms.atom[i].q; atoms.pdbinfo[i].bfac = vdw; } else { atoms.pdbinfo[i].occup = vdw; atoms.pdbinfo[i].bfac = top->atoms.atom[i].q; } } } bHaveV=FALSE; for (i=0; (i<natom) && !bHaveV; i++) for (j=0; (j<DIM) && !bHaveV; j++) bHaveV=bHaveV || (v[i][j]!=0); printf("%selocities found\n",bHaveV?"V":"No v"); if (visbox[0] > 0) { if (bIndex) gmx_fatal(FARGS,"Sorry, can not visualize box with index groups"); if (outftp != efPDB) gmx_fatal(FARGS,"Sorry, can only visualize box with a pdb file"); } else if (visbox[0] == -1) visualize_images("images.pdb",ePBC,box); /* remove pbc */ if (bRMPBC) rm_gropbc(&atoms,x,box); if (bCalcGeom) { if (bIndex) { fprintf(stderr,"\nSelect a group for determining the system size:\n"); get_index(&atoms,ftp2fn_null(efNDX,NFILE,fnm), 1,&ssize,&sindex,&sgrpname); } else { ssize = atoms.nr; sindex = NULL; } diam=calc_geom(ssize,sindex,x,gc,min,max,bCalcDiam); rvec_sub(max, min, size); printf(" system size :%7.3f%7.3f%7.3f (nm)\n", size[XX], size[YY], size[ZZ]); if (bCalcDiam) printf(" diameter :%7.3f (nm)\n",diam); printf(" center :%7.3f%7.3f%7.3f (nm)\n", gc[XX], gc[YY], gc[ZZ]); printf(" box vectors :%7.3f%7.3f%7.3f (nm)\n", norm(box[XX]), norm(box[YY]), norm(box[ZZ])); printf(" box angles :%7.2f%7.2f%7.2f (degrees)\n", norm2(box[ZZ])==0 ? 0 : RAD2DEG*acos(cos_angle_no_table(box[YY],box[ZZ])), norm2(box[ZZ])==0 ? 0 : RAD2DEG*acos(cos_angle_no_table(box[XX],box[ZZ])), norm2(box[YY])==0 ? 0 : RAD2DEG*acos(cos_angle_no_table(box[XX],box[YY]))); printf(" box volume :%7.2f (nm^3)\n",det(box)); } if (bRho || bOrient || bAlign) mass = calc_mass(&atoms,!fn2bTPX(infile),aps); if (bOrient) { atom_id *index; char *grpnames; /* Get a group for principal component analysis */ fprintf(stderr,"\nSelect group for the determining the orientation\n"); get_index(&atoms,ftp2fn_null(efNDX,NFILE,fnm),1,&isize,&index,&grpnames); /* Orient the principal axes along the coordinate axes */ orient_princ(&atoms,isize,index,natom,x,bHaveV ? v : NULL, NULL); sfree(index); sfree(grpnames); } if ( bScale ) { /* scale coordinates and box */ if (bRho) { /* Compute scaling constant */ real vol,dens; vol = det(box); dens = (mass*AMU)/(vol*NANO*NANO*NANO); fprintf(stderr,"Volume of input %g (nm^3)\n",vol); fprintf(stderr,"Mass of input %g (a.m.u.)\n",mass); fprintf(stderr,"Density of input %g (g/l)\n",dens); if (vol==0 || mass==0) gmx_fatal(FARGS,"Cannot scale density with " "zero mass (%g) or volume (%g)\n",mass,vol); scale[XX] = scale[YY] = scale[ZZ] = pow(dens/rho,1.0/3.0); fprintf(stderr,"Scaling all box vectors by %g\n",scale[XX]); } scale_conf(atoms.nr,x,box,scale); } if (bAlign) { if (bIndex) { fprintf(stderr,"\nSelect a group that you want to align:\n"); get_index(&atoms,ftp2fn_null(efNDX,NFILE,fnm), 1,&asize,&aindex,&agrpname); } else { asize = atoms.nr; snew(aindex,asize); for (i=0;i<asize;i++) aindex[i]=i; } printf("Aligning %d atoms (out of %d) to %g %g %g, center of rotation %g %g %g\n",asize,natom, targetvec[XX],targetvec[YY],targetvec[ZZ], aligncenter[XX],aligncenter[YY],aligncenter[ZZ]); /*subtract out pivot point*/ for(i=0; i<asize; i++) rvec_dec(x[aindex[i]],aligncenter); /*now determine transform and rotate*/ /*will this work?*/ principal_comp(asize,aindex,atoms.atom,x, trans,princd); unitv(targetvec,targetvec); printf("Using %g %g %g as principal axis\n", trans[0][2],trans[1][2],trans[2][2]); tmpvec[XX]=trans[0][2]; tmpvec[YY]=trans[1][2]; tmpvec[ZZ]=trans[2][2]; calc_rotmatrix(tmpvec, targetvec, rotmatrix); /* rotmatrix finished */ for (i=0;i<asize;++i) { mvmul(rotmatrix,x[aindex[i]],tmpvec); copy_rvec(tmpvec,x[aindex[i]]); } /*add pivot point back*/ for(i=0; i<asize; i++) rvec_inc(x[aindex[i]],aligncenter); if (!bIndex) sfree(aindex); } if (bTranslate) { if (bIndex) { fprintf(stderr,"\nSelect a group that you want to translate:\n"); get_index(&atoms,ftp2fn_null(efNDX,NFILE,fnm), 1,&ssize,&sindex,&sgrpname); } else { ssize = atoms.nr; sindex = NULL; } printf("Translating %d atoms (out of %d) by %g %g %g nm\n",ssize,natom, translation[XX],translation[YY],translation[ZZ]); if (sindex) { for(i=0; i<ssize; i++) rvec_inc(x[sindex[i]],translation); } else { for(i=0; i<natom; i++) rvec_inc(x[i],translation); } } if (bRotate) { /* Rotate */ printf("Rotating %g, %g, %g degrees around the X, Y and Z axis respectively\n",rotangles[XX],rotangles[YY],rotangles[ZZ]); for(i=0; i<DIM; i++) rotangles[i] *= DEG2RAD; rotate_conf(natom,x,v,rotangles[XX],rotangles[YY],rotangles[ZZ]); } if (bCalcGeom) { /* recalc geometrical center and max and min coordinates and size */ calc_geom(ssize,sindex,x,gc,min,max,FALSE); rvec_sub(max, min, size); if (bScale || bOrient || bRotate) printf("new system size : %6.3f %6.3f %6.3f\n", size[XX],size[YY],size[ZZ]); } if (bSetSize || bDist || (btype[0][0]=='t' && bSetAng)) { ePBC = epbcXYZ; if (!(bSetSize || bDist)) for (i=0; i<DIM; i++) newbox[i] = norm(box[i]); clear_mat(box); /* calculate new boxsize */ switch(btype[0][0]){ case 't': if (bDist) for(i=0; i<DIM; i++) newbox[i] = size[i]+2*dist; if (!bSetAng) { box[XX][XX] = newbox[XX]; box[YY][YY] = newbox[YY]; box[ZZ][ZZ] = newbox[ZZ]; } else { matrix_convert(box,newbox,newang); } break; case 'c': case 'd': case 'o': if (bSetSize) d = newbox[0]; else d = diam+2*dist; if (btype[0][0] == 'c') for(i=0; i<DIM; i++) box[i][i] = d; else if (btype[0][0] == 'd') { box[XX][XX] = d; box[YY][YY] = d; box[ZZ][XX] = d/2; box[ZZ][YY] = d/2; box[ZZ][ZZ] = d*sqrt(2)/2; } else { box[XX][XX] = d; box[YY][XX] = d/3; box[YY][YY] = d*sqrt(2)*2/3; box[ZZ][XX] = -d/3; box[ZZ][YY] = d*sqrt(2)/3; box[ZZ][ZZ] = d*sqrt(6)/3; } break; } } /* calculate new coords for geometrical center */ if (!bSetCenter) calc_box_center(ecenterDEF,box,center); /* center molecule on 'center' */ if (bCenter) center_conf(natom,x,center,gc); /* print some */ if (bCalcGeom) { calc_geom(ssize,sindex,x, gc, min, max, FALSE); printf("new center :%7.3f%7.3f%7.3f (nm)\n",gc[XX],gc[YY],gc[ZZ]); } if (bOrient || bScale || bDist || bSetSize) { printf("new box vectors :%7.3f%7.3f%7.3f (nm)\n", norm(box[XX]), norm(box[YY]), norm(box[ZZ])); printf("new box angles :%7.2f%7.2f%7.2f (degrees)\n", norm2(box[ZZ])==0 ? 0 : RAD2DEG*acos(cos_angle_no_table(box[YY],box[ZZ])), norm2(box[ZZ])==0 ? 0 : RAD2DEG*acos(cos_angle_no_table(box[XX],box[ZZ])), norm2(box[YY])==0 ? 0 : RAD2DEG*acos(cos_angle_no_table(box[XX],box[YY]))); printf("new box volume :%7.2f (nm^3)\n",det(box)); } if (check_box(epbcXYZ,box)) printf("\nWARNING: %s\n",check_box(epbcXYZ,box)); if (bDist && btype[0][0]=='t') { if(TRICLINIC(box)) { printf("\nWARNING: Your box is triclinic with non-orthogonal axes. In this case, the\n" "distance from the solute to a box surface along the corresponding normal\n" "vector might be somewhat smaller than your specified value %f.\n" "You can check the actual value with g_mindist -pi\n",dist); } else { printf("\nWARNING: No boxtype specified - distance condition applied in each dimension.\n" "If the molecule rotates the actual distance will be smaller. You might want\n" "to use a cubic box instead, or why not try a dodecahedron today?\n"); } } if (bCONECT && (outftp == efPDB) && (inftp == efTPR)) conect = gmx_conect_generate(top); else conect = NULL; if (bIndex) { fprintf(stderr,"\nSelect a group for output:\n"); get_index(&atoms,opt2fn_null("-n",NFILE,fnm), 1,&isize,&index,&grpname); if (opt2parg_bSet("-label",NPA,pa)) { for(i=0; (i<atoms.nr); i++) atoms.resinfo[atoms.atom[i].resind].chainid=label[0]; } if (opt2bSet("-bf",NFILE,fnm) || bLegend) { gmx_fatal(FARGS,"Sorry, cannot do bfactors with an index group."); } if (outftp == efPDB) { out=ffopen(outfile,"w"); write_pdbfile_indexed(out,title,&atoms,x,ePBC,box,' ',1,isize,index,conect,TRUE); ffclose(out); } else { write_sto_conf_indexed(outfile,title,&atoms,x,bHaveV?v:NULL,ePBC,box,isize,index); } } else { if ((outftp == efPDB) || (outftp == efPQR)) { out=ffopen(outfile,"w"); if (bMead) { set_pdb_wide_format(TRUE); fprintf(out,"REMARK " "The B-factors in this file hold atomic radii\n"); fprintf(out,"REMARK " "The occupancy in this file hold atomic charges\n"); } else if (bGrasp) { fprintf(out,"GRASP PDB FILE\nFORMAT NUMBER=1\n"); fprintf(out,"REMARK " "The B-factors in this file hold atomic charges\n"); fprintf(out,"REMARK " "The occupancy in this file hold atomic radii\n"); } else if (opt2bSet("-bf",NFILE,fnm)) { read_bfac(opt2fn("-bf",NFILE,fnm),&n_bfac,&bfac,&bfac_nr); set_pdb_conf_bfac(atoms.nr,atoms.nres,&atoms, n_bfac,bfac,bfac_nr,peratom); } if (opt2parg_bSet("-label",NPA,pa)) { for(i=0; (i<atoms.nr); i++) atoms.resinfo[atoms.atom[i].resind].chainid=label[0]; } write_pdbfile(out,title,&atoms,x,ePBC,box,' ',-1,conect,TRUE); if (bLegend) pdb_legend(out,atoms.nr,atoms.nres,&atoms,x); if (visbox[0] > 0) visualize_box(out,bLegend ? atoms.nr+12 : atoms.nr, bLegend? atoms.nres=12 : atoms.nres,box,visbox); ffclose(out); } else write_sto_conf(outfile,title,&atoms,x,bHaveV?v:NULL,ePBC,box); } gmx_atomprop_destroy(aps); do_view(oenv,outfile,NULL); thanx(stderr); return 0; }
int gmx_analyze(int argc,char *argv[]) { static const char *desc[] = { "g_analyze reads an ascii file and analyzes data sets.", "A line in the input file may start with a time", "(see option [TT]-time[tt]) and any number of y values may follow.", "Multiple sets can also be", "read when they are seperated by & (option [TT]-n[tt]),", "in this case only one y value is read from each line.", "All lines starting with # and @ are skipped.", "All analyses can also be done for the derivative of a set", "(option [TT]-d[tt]).[PAR]", "All options, except for [TT]-av[tt] and [TT]-power[tt] assume that the", "points are equidistant in time.[PAR]", "g_analyze always shows the average and standard deviation of each", "set. For each set it also shows the relative deviation of the third", "and forth cumulant from those of a Gaussian distribution with the same", "standard deviation.[PAR]", "Option [TT]-ac[tt] produces the autocorrelation function(s).[PAR]", "Option [TT]-cc[tt] plots the resemblance of set i with a cosine of", "i/2 periods. The formula is:[BR]" "2 (int0-T y(t) cos(i pi t) dt)^2 / int0-T y(t) y(t) dt[BR]", "This is useful for principal components obtained from covariance", "analysis, since the principal components of random diffusion are", "pure cosines.[PAR]", "Option [TT]-msd[tt] produces the mean square displacement(s).[PAR]", "Option [TT]-dist[tt] produces distribution plot(s).[PAR]", "Option [TT]-av[tt] produces the average over the sets.", "Error bars can be added with the option [TT]-errbar[tt].", "The errorbars can represent the standard deviation, the error", "(assuming the points are independent) or the interval containing", "90% of the points, by discarding 5% of the points at the top and", "the bottom.[PAR]", "Option [TT]-ee[tt] produces error estimates using block averaging.", "A set is divided in a number of blocks and averages are calculated for", "each block. The error for the total average is calculated from", "the variance between averages of the m blocks B_i as follows:", "error^2 = Sum (B_i - <B>)^2 / (m*(m-1)).", "These errors are plotted as a function of the block size.", "Also an analytical block average curve is plotted, assuming", "that the autocorrelation is a sum of two exponentials.", "The analytical curve for the block average is:[BR]", "f(t) = sigma sqrt(2/T ( a (tau1 ((exp(-t/tau1) - 1) tau1/t + 1)) +[BR]", " (1-a) (tau2 ((exp(-t/tau2) - 1) tau2/t + 1)))),[BR]" "where T is the total time.", "a, tau1 and tau2 are obtained by fitting f^2(t) to error^2.", "When the actual block average is very close to the analytical curve,", "the error is sigma*sqrt(2/T (a tau1 + (1-a) tau2)).", "The complete derivation is given in", "B. Hess, J. Chem. Phys. 116:209-217, 2002.[PAR]", "Option [TT]-filter[tt] prints the RMS high-frequency fluctuation", "of each set and over all sets with respect to a filtered average.", "The filter is proportional to cos(pi t/len) where t goes from -len/2", "to len/2. len is supplied with the option [TT]-filter[tt].", "This filter reduces oscillations with period len/2 and len by a factor", "of 0.79 and 0.33 respectively.[PAR]", "Option [TT]-g[tt] fits the data to the function given with option", "[TT]-fitfn[tt].[PAR]", "Option [TT]-power[tt] fits the data to b t^a, which is accomplished", "by fitting to a t + b on log-log scale. All points after the first", "zero or negative value are ignored.[PAR]" "Option [TT]-luzar[tt] performs a Luzar & Chandler kinetics analysis", "on output from [TT]g_hbond[tt]. The input file can be taken directly", "from [TT]g_hbond -ac[tt], and then the same result should be produced." }; static real tb=-1,te=-1,frac=0.5,filtlen=0,binwidth=0.1,aver_start=0; static bool bHaveT=TRUE,bDer=FALSE,bSubAv=TRUE,bAverCorr=FALSE,bXYdy=FALSE; static bool bEESEF=FALSE,bEENLC=FALSE,bEeFitAc=FALSE,bPower=FALSE; static bool bIntegrate=FALSE,bRegression=FALSE,bLuzar=FALSE,bLuzarError=FALSE; static int nsets_in=1,d=1,nb_min=4,resol=10; static real temp=298.15,fit_start=1,smooth_tail_start=-1; /* must correspond to enum avbar* declared at beginning of file */ static const char *avbar_opt[avbarNR+1] = { NULL, "none", "stddev", "error", "90", NULL }; t_pargs pa[] = { { "-time", FALSE, etBOOL, {&bHaveT}, "Expect a time in the input" }, { "-b", FALSE, etREAL, {&tb}, "First time to read from set" }, { "-e", FALSE, etREAL, {&te}, "Last time to read from set" }, { "-n", FALSE, etINT, {&nsets_in}, "Read # sets seperated by &" }, { "-d", FALSE, etBOOL, {&bDer}, "Use the derivative" }, { "-dp", FALSE, etINT, {&d}, "HIDDENThe derivative is the difference over # points" }, { "-bw", FALSE, etREAL, {&binwidth}, "Binwidth for the distribution" }, { "-errbar", FALSE, etENUM, {avbar_opt}, "Error bars for -av" }, { "-integrate",FALSE,etBOOL, {&bIntegrate}, "Integrate data function(s) numerically using trapezium rule" }, { "-aver_start",FALSE, etREAL, {&aver_start}, "Start averaging the integral from here" }, { "-xydy", FALSE, etBOOL, {&bXYdy}, "Interpret second data set as error in the y values for integrating" }, { "-regression",FALSE,etBOOL,{&bRegression}, "Perform a linear regression analysis on the data" }, { "-luzar", FALSE, etBOOL, {&bLuzar}, "Do a Luzar and Chandler analysis on a correlation function and related as produced by g_hbond. When in addition the -xydy flag is given the second and fourth column will be interpreted as errors in c(t) and n(t)." }, { "-temp", FALSE, etREAL, {&temp}, "Temperature for the Luzar hydrogen bonding kinetics analysis" }, { "-fitstart", FALSE, etREAL, {&fit_start}, "Time (ps) from which to start fitting the correlation functions in order to obtain the forward and backward rate constants for HB breaking and formation" }, { "-smooth",FALSE, etREAL, {&smooth_tail_start}, "If >= 0, the tail of the ACF will be smoothed by fitting it to an exponential function: y = A exp(-x/tau)" }, { "-nbmin", FALSE, etINT, {&nb_min}, "HIDDENMinimum number of blocks for block averaging" }, { "-resol", FALSE, etINT, {&resol}, "HIDDENResolution for the block averaging, block size increases with" " a factor 2^(1/#)" }, { "-eeexpfit", FALSE, etBOOL, {&bEESEF}, "HIDDENAlways use a single exponential fit for the error estimate" }, { "-eenlc", FALSE, etBOOL, {&bEENLC}, "HIDDENAllow a negative long-time correlation" }, { "-eefitac", FALSE, etBOOL, {&bEeFitAc}, "HIDDENAlso plot analytical block average using a autocorrelation fit" }, { "-filter", FALSE, etREAL, {&filtlen}, "Print the high-frequency fluctuation after filtering with a cosine filter of length #" }, { "-power", FALSE, etBOOL, {&bPower}, "Fit data to: b t^a" }, { "-subav", FALSE, etBOOL, {&bSubAv}, "Subtract the average before autocorrelating" }, { "-oneacf", FALSE, etBOOL, {&bAverCorr}, "Calculate one ACF over all sets" } }; #define NPA asize(pa) FILE *out,*out_fit; int n,nlast,s,nset,i,j=0; real **val,*t,dt,tot,error; double *av,*sig,cum1,cum2,cum3,cum4,db; char *acfile,*msdfile,*ccfile,*distfile,*avfile,*eefile,*fitfile; t_filenm fnm[] = { { efXVG, "-f", "graph", ffREAD }, { efXVG, "-ac", "autocorr", ffOPTWR }, { efXVG, "-msd", "msd", ffOPTWR }, { efXVG, "-cc", "coscont", ffOPTWR }, { efXVG, "-dist", "distr", ffOPTWR }, { efXVG, "-av", "average", ffOPTWR }, { efXVG, "-ee", "errest", ffOPTWR }, { efLOG, "-g", "fitlog", ffOPTWR } }; #define NFILE asize(fnm) int npargs; t_pargs *ppa; npargs = asize(pa); ppa = add_acf_pargs(&npargs,pa); CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_VIEW, NFILE,fnm,npargs,ppa,asize(desc),desc,0,NULL); acfile = opt2fn_null("-ac",NFILE,fnm); msdfile = opt2fn_null("-msd",NFILE,fnm); ccfile = opt2fn_null("-cc",NFILE,fnm); distfile = opt2fn_null("-dist",NFILE,fnm); avfile = opt2fn_null("-av",NFILE,fnm); eefile = opt2fn_null("-ee",NFILE,fnm); if (opt2parg_bSet("-fitfn",npargs,ppa)) fitfile = opt2fn("-g",NFILE,fnm); else fitfile = opt2fn_null("-g",NFILE,fnm); val=read_xvg_time(opt2fn("-f",NFILE,fnm),bHaveT, opt2parg_bSet("-b",npargs,ppa),tb, opt2parg_bSet("-e",npargs,ppa),te, nsets_in,&nset,&n,&dt,&t); printf("Read %d sets of %d points, dt = %g\n\n",nset,n,dt); if (bDer) { printf("Calculating the derivative as (f[i+%d]-f[i])/(%d*dt)\n\n", d,d); n -= d; for(s=0; s<nset; s++) for(i=0; (i<n); i++) val[s][i] = (val[s][i+d]-val[s][i])/(d*dt); } if (bIntegrate) { real sum,stddev; printf("Calculating the integral using the trapezium rule\n"); if (bXYdy) { sum = evaluate_integral(n,t,val[0],val[1],aver_start,&stddev); printf("Integral %10.3f +/- %10.5f\n",sum,stddev); } else { for(s=0; s<nset; s++) { sum = evaluate_integral(n,t,val[s],NULL,aver_start,&stddev); printf("Integral %d %10.5f +/- %10.5f\n",s+1,sum,stddev); } } } if (fitfile) { out_fit = ffopen(fitfile,"w"); if (bXYdy && nset>=2) { do_fit(out_fit,0,TRUE,n,t,val,npargs,ppa); } else { for(s=0; s<nset; s++) do_fit(out_fit,s,FALSE,n,t,val,npargs,ppa); } fclose(out_fit); } printf(" std. dev. relative deviation of\n"); printf(" standard --------- cumulants from those of\n"); printf("set average deviation sqrt(n-1) a Gaussian distribition\n"); printf(" cum. 3 cum. 4\n"); snew(av,nset); snew(sig,nset); for(s=0; (s<nset); s++) { cum1 = 0; cum2 = 0; cum3 = 0; cum4 = 0; for(i=0; (i<n); i++) cum1 += val[s][i]; cum1 /= n; for(i=0; (i<n); i++) { db = val[s][i]-cum1; cum2 += db*db; cum3 += db*db*db; cum4 += db*db*db*db; } cum2 /= n; cum3 /= n; cum4 /= n; av[s] = cum1; sig[s] = sqrt(cum2); if (n > 1) error = sqrt(cum2/(n-1)); else error = 0; printf("SS%d %13.6e %12.6e %12.6e %6.3f %6.3f\n", s+1,av[s],sig[s],error, sig[s] ? cum3/(sig[s]*sig[s]*sig[s]*sqrt(8/M_PI)) : 0, sig[s] ? cum4/(sig[s]*sig[s]*sig[s]*sig[s]*3)-1 : 0); } printf("\n"); if (filtlen) filter(filtlen,n,nset,val,dt); if (msdfile) { out=xvgropen(msdfile,"Mean square displacement", "time","MSD (nm\\S2\\N)"); nlast = (int)(n*frac); for(s=0; s<nset; s++) { for(j=0; j<=nlast; j++) { if (j % 100 == 0) fprintf(stderr,"\r%d",j); tot=0; for(i=0; i<n-j; i++) tot += sqr(val[s][i]-val[s][i+j]); tot /= (real)(n-j); fprintf(out," %g %8g\n",dt*j,tot); } if (s<nset-1) fprintf(out,"&\n"); } fclose(out); fprintf(stderr,"\r%d, time=%g\n",j-1,(j-1)*dt); } if (ccfile) plot_coscont(ccfile,n,nset,val); if (distfile) histogram(distfile,binwidth,n,nset,val); if (avfile) average(avfile,nenum(avbar_opt),n,nset,val,t); if (eefile) estimate_error(eefile,nb_min,resol,n,nset,av,sig,val,dt, bEeFitAc,bEESEF,bEENLC); if (bPower) power_fit(n,nset,val,t); if (acfile) { if (bSubAv) for(s=0; s<nset; s++) for(i=0; i<n; i++) val[s][i] -= av[s]; do_autocorr(acfile,"Autocorrelation",n,nset,val,dt, eacNormal,bAverCorr); } if (bRegression) regression_analysis(n,bXYdy,t,val); if (bLuzar) luzar_correl(n,t,nset,val,temp,bXYdy,fit_start,smooth_tail_start); view_all(NFILE, fnm); thanx(stderr); return 0; }
int gmx_select(int argc, char *argv[]) { const char *desc[] = { "g_select writes out basic data about dynamic selections.", "It can be used for some simple analyses, or the output can", "be combined with output from other programs and/or external", "analysis programs to calculate more complex things.", "Any combination of the output options is possible, but note", "that [TT]-om[tt] only operates on the first selection.[PAR]", "With [TT]-os[tt], calculates the number of positions in each", "selection for each frame. With [TT]-norm[tt], the output is", "between 0 and 1 and describes the fraction from the maximum", "number of positions (e.g., for selection 'resname RA and x < 5'", "the maximum number of positions is the number of atoms in", "RA residues). With [TT]-cfnorm[tt], the output is divided", "by the fraction covered by the selection.", "[TT]-norm[tt] and [TT]-cfnorm[tt] can be specified independently", "of one another.[PAR]", "With [TT]-oc[tt], the fraction covered by each selection is", "written out as a function of time.[PAR]", "With [TT]-oi[tt], the selected atoms/residues/molecules are", "written out as a function of time. In the output, the first", "column contains the frame time, the second contains the number", "of positions, followed by the atom/residue/molecule numbers.", "If more than one selection is specified, the size of the second", "group immediately follows the last number of the first group", "and so on. With [TT]-dump[tt], the frame time and the number", "of positions is omitted from the output. In this case, only one", "selection can be given.[PAR]", "With [TT]-om[tt], a mask is printed for the first selection", "as a function of time. Each line in the output corresponds to", "one frame, and contains either 0/1 for each atom/residue/molecule", "possibly selected. 1 stands for the atom/residue/molecule being", "selected for the current frame, 0 for not selected.", "With [TT]-dump[tt], the frame time is omitted from the output.", }; bool bDump = FALSE; bool bFracNorm = FALSE; bool bTotNorm = FALSE; t_pargs pa[] = { {"-dump", FALSE, etBOOL, {&bDump}, "Do not print the frame time (-om, -oi) or the index size (-oi)"}, {"-norm", FALSE, etBOOL, {&bTotNorm}, "Normalize by total number of positions with -os"}, {"-cfnorm", FALSE, etBOOL, {&bFracNorm}, "Normalize by covered fraction with -os"}, }; t_filenm fnm[] = { {efXVG, "-os", "size.xvg", ffOPTWR}, {efXVG, "-oc", "cfrac.xvg", ffOPTWR}, {efDAT, "-oi", "index.dat", ffOPTWR}, {efDAT, "-om", "mask.dat", ffOPTWR}, }; #define NFILE asize(fnm) gmx_ana_traj_t *trj; t_topology *top; int ngrps; gmx_ana_selection_t **sel; char **grpnames; t_dsdata d; char *fnSize, *fnFrac, *fnIndex, *fnMask; int g; int rc; CopyRight(stderr, argv[0]); gmx_ana_traj_create(&trj, 0); gmx_ana_set_nanagrps(trj, -1); parse_trjana_args(trj, &argc, argv, 0, NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL); gmx_ana_get_nanagrps(trj, &ngrps); gmx_ana_get_anagrps(trj, &sel); gmx_ana_init_coverfrac(trj, CFRAC_SOLIDANGLE); /* Get output file names */ fnSize = opt2fn_null("-os", NFILE, fnm); fnFrac = opt2fn_null("-oc", NFILE, fnm); fnIndex = opt2fn_null("-oi", NFILE, fnm); fnMask = opt2fn_null("-om", NFILE, fnm); /* Write out sizes if nothing specified */ if (!fnFrac && !fnIndex && !fnMask) { fnSize = opt2fn("-os", NFILE, fnm); } if (bDump && ngrps > 1) { gmx_fatal(FARGS, "Only one index group allowed with -dump"); } if (fnMask && ngrps > 1) { fprintf(stderr, "warning: the mask (-om) will only be written for the first group\n"); } if (fnMask && !sel[0]->bDynamic) { fprintf(stderr, "warning: will not write the mask (-om) for a static selection\n"); fnMask = NULL; } /* Initialize reference calculation for masks */ if (fnMask) { gmx_ana_get_topology(trj, FALSE, &top, NULL); snew(d.mmap, 1); gmx_ana_indexmap_init(d.mmap, sel[0]->g, top, sel[0]->p.m.type); } /* Initialize calculation data */ d.bDump = bDump; d.bFracNorm = bFracNorm; snew(d.size, ngrps); for (g = 0; g < ngrps; ++g) { d.size[g] = bTotNorm ? sel[g]->p.nr : 1; } /* Open output files */ d.sfp = d.cfp = d.ifp = d.mfp = NULL; gmx_ana_get_grpnames(trj, &grpnames); if (fnSize) { d.sfp = xvgropen(fnSize, "Selection size", "Time (ps)", "Number"); xvgr_selections(d.sfp, trj); xvgr_legend(d.sfp, ngrps, grpnames); } if (fnFrac) { d.cfp = xvgropen(fnFrac, "Covered fraction", "Time (ps)", "Fraction"); xvgr_selections(d.cfp, trj); xvgr_legend(d.cfp, ngrps, grpnames); } if (fnIndex) { d.ifp = ffopen(fnIndex, "w"); xvgr_selections(d.ifp, trj); } if (fnMask) { d.mfp = ffopen(fnMask, "w"); xvgr_selections(d.mfp, trj); } /* Do the analysis and write out results */ gmx_ana_do(trj, 0, &print_data, &d); /* Close the files */ if (d.sfp) { fclose(d.sfp); } if (d.cfp) { fclose(d.cfp); } if (d.ifp) { fclose(d.ifp); } if (d.mfp) { fclose(d.mfp); } thanx(stderr); return 0; }
int gmx_rotacf(int argc,char *argv[]) { static char *desc[] = { "g_rotacf calculates the rotational correlation function", "for molecules. Three atoms (i,j,k) must be given in the index", "file, defining two vectors ij and jk. The rotational acf", "is calculated as the autocorrelation function of the vector", "n = ij x jk, i.e. the cross product of the two vectors.", "Since three atoms span a plane, the order of the three atoms", "does not matter. Optionally, controlled by the -d switch, you can", "calculate the rotational correlation function for linear molecules", "by specifying two atoms (i,j) in the index file.", "[PAR]", "EXAMPLES[PAR]", "g_rotacf -P 1 -nparm 2 -fft -n index -o rotacf-x-P1", "-fa expfit-x-P1 -beginfit 2.5 -endfit 20.0[PAR]", "This will calculate the rotational correlation function using a first", "order Legendre polynomial of the angle of a vector defined by the index", "file. The correlation function will be fitted from 2.5 ps till 20.0 ps", "to a two parameter exponential", "" }; static bool bVec = FALSE,bAver=TRUE; t_pargs pa[] = { { "-d", FALSE, etBOOL, {&bVec}, "Use index doublets (vectors) for correlation function instead of triplets (planes)" }, { "-aver",FALSE, etBOOL, {&bAver}, "Average over molecules" } }; int status,isize; atom_id *index; char *grpname; rvec *x,*x_s; matrix box; real **c1; rvec xij,xjk,n; int i,m,teller,n_alloc,natoms,nvec,ai,aj,ak; unsigned long mode; real t,t0,t1,dt; t_topology *top; int ePBC; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPX, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffREAD }, { efXVG, "-o", "rotacf", ffWRITE } }; #define NFILE asize(fnm) int npargs; t_pargs *ppa; CopyRight(stderr,argv[0]); npargs = asize(pa); ppa = add_acf_pargs(&npargs,pa); parse_common_args(&argc,argv,PCA_CAN_VIEW | PCA_CAN_TIME | PCA_BE_NICE, NFILE,fnm,npargs,ppa,asize(desc),desc,0,NULL); rd_index(ftp2fn(efNDX,NFILE,fnm),1,&isize,&index,&grpname); if (bVec) nvec = isize/2; else nvec = isize/3; if (((isize % 3) != 0) && !bVec) gmx_fatal(FARGS,"number of index elements not multiple of 3, " "these can not be atom triplets\n"); if (((isize % 2) != 0) && bVec) gmx_fatal(FARGS,"number of index elements not multiple of 2, " "these can not be atom doublets\n"); top=read_top(ftp2fn(efTPX,NFILE,fnm),&ePBC); snew(c1,nvec); for (i=0; (i<nvec); i++) c1[i]=NULL; n_alloc=0; natoms=read_first_x(&status,ftp2fn(efTRX,NFILE,fnm),&t,&x,box); snew(x_s,natoms); /* Start the loop over frames */ t1 = t0 = t; teller = 0; do { if (teller >= n_alloc) { n_alloc+=100; for (i=0; (i<nvec); i++) srenew(c1[i],DIM*n_alloc); } t1 = t; /* Remove periodicity */ rm_pbc(&(top->idef),ePBC,natoms,box,x,x_s); /* Compute crossproducts for all vectors, if triplets. * else, just get the vectors in case of doublets. */ if (bVec == FALSE) { for (i=0; (i<nvec); i++) { ai=index[3*i]; aj=index[3*i+1]; ak=index[3*i+2]; rvec_sub(x_s[ai],x_s[aj],xij); rvec_sub(x_s[aj],x_s[ak],xjk); cprod(xij,xjk,n); for(m=0; (m<DIM); m++) c1[i][DIM*teller+m]=n[m]; } } else { for (i=0; (i<nvec); i++) { ai=index[2*i]; aj=index[2*i+1]; rvec_sub(x_s[ai],x_s[aj],n); for(m=0; (m<DIM); m++) c1[i][DIM*teller+m]=n[m]; } } /* Increment loop counter */ teller++; } while (read_next_x(status,&t,natoms,x,box)); close_trj(status); fprintf(stderr,"\nDone with trajectory\n"); /* Autocorrelation function */ if (teller < 2) fprintf(stderr,"Not enough frames for correlation function\n"); else { dt=(t1 - t0)/(teller-1); mode = eacVector; do_autocorr(ftp2fn(efXVG,NFILE,fnm),"Rotational Correlation Function", teller,nvec,c1,dt,mode,bAver); } do_view(ftp2fn(efXVG,NFILE,fnm),NULL); thanx(stderr); return 0; }
int gmx_anaeig(int argc,char *argv[]) { static const char *desc[] = { "[TT]g_anaeig[tt] analyzes eigenvectors. The eigenvectors can be of a", "covariance matrix ([TT]g_covar[tt]) or of a Normal Modes analysis", "([TT]g_nmeig[tt]).[PAR]", "When a trajectory is projected on eigenvectors, all structures are", "fitted to the structure in the eigenvector file, if present, otherwise", "to the structure in the structure file. When no run input file is", "supplied, periodicity will not be taken into account. Most analyses", "are performed on eigenvectors [TT]-first[tt] to [TT]-last[tt], but when", "[TT]-first[tt] is set to -1 you will be prompted for a selection.[PAR]", "[TT]-comp[tt]: plot the vector components per atom of eigenvectors", "[TT]-first[tt] to [TT]-last[tt].[PAR]", "[TT]-rmsf[tt]: plot the RMS fluctuation per atom of eigenvectors", "[TT]-first[tt] to [TT]-last[tt] (requires [TT]-eig[tt]).[PAR]", "[TT]-proj[tt]: calculate projections of a trajectory on eigenvectors", "[TT]-first[tt] to [TT]-last[tt].", "The projections of a trajectory on the eigenvectors of its", "covariance matrix are called principal components (pc's).", "It is often useful to check the cosine content of the pc's,", "since the pc's of random diffusion are cosines with the number", "of periods equal to half the pc index.", "The cosine content of the pc's can be calculated with the program", "[TT]g_analyze[tt].[PAR]", "[TT]-2d[tt]: calculate a 2d projection of a trajectory on eigenvectors", "[TT]-first[tt] and [TT]-last[tt].[PAR]", "[TT]-3d[tt]: calculate a 3d projection of a trajectory on the first", "three selected eigenvectors.[PAR]", "[TT]-filt[tt]: filter the trajectory to show only the motion along", "eigenvectors [TT]-first[tt] to [TT]-last[tt].[PAR]", "[TT]-extr[tt]: calculate the two extreme projections along a trajectory", "on the average structure and interpolate [TT]-nframes[tt] frames", "between them, or set your own extremes with [TT]-max[tt]. The", "eigenvector [TT]-first[tt] will be written unless [TT]-first[tt] and", "[TT]-last[tt] have been set explicitly, in which case all eigenvectors", "will be written to separate files. Chain identifiers will be added", "when writing a [TT].pdb[tt] file with two or three structures (you", "can use [TT]rasmol -nmrpdb[tt] to view such a [TT].pdb[tt] file).[PAR]", " Overlap calculations between covariance analysis:[BR]", " [BB]Note:[bb] the analysis should use the same fitting structure[PAR]", "[TT]-over[tt]: calculate the subspace overlap of the eigenvectors in", "file [TT]-v2[tt] with eigenvectors [TT]-first[tt] to [TT]-last[tt]", "in file [TT]-v[tt].[PAR]", "[TT]-inpr[tt]: calculate a matrix of inner-products between", "eigenvectors in files [TT]-v[tt] and [TT]-v2[tt]. All eigenvectors", "of both files will be used unless [TT]-first[tt] and [TT]-last[tt]", "have been set explicitly.[PAR]", "When [TT]-v[tt], [TT]-eig[tt], [TT]-v2[tt] and [TT]-eig2[tt] are given,", "a single number for the overlap between the covariance matrices is", "generated. The formulas are:[BR]", " difference = sqrt(tr((sqrt(M1) - sqrt(M2))^2))[BR]", "normalized overlap = 1 - difference/sqrt(tr(M1) + tr(M2))[BR]", " shape overlap = 1 - sqrt(tr((sqrt(M1/tr(M1)) - sqrt(M2/tr(M2)))^2))[BR]", "where M1 and M2 are the two covariance matrices and tr is the trace", "of a matrix. The numbers are proportional to the overlap of the square", "root of the fluctuations. The normalized overlap is the most useful", "number, it is 1 for identical matrices and 0 when the sampled", "subspaces are orthogonal.[PAR]", "When the [TT]-entropy[tt] flag is given an entropy estimate will be", "computed based on the Quasiharmonic approach and based on", "Schlitter's formula." }; static int first=1,last=-1,skip=1,nextr=2,nskip=6; static real max=0.0,temp=298.15; static gmx_bool bSplit=FALSE,bEntropy=FALSE; t_pargs pa[] = { { "-first", FALSE, etINT, {&first}, "First eigenvector for analysis (-1 is select)" }, { "-last", FALSE, etINT, {&last}, "Last eigenvector for analysis (-1 is till the last)" }, { "-skip", FALSE, etINT, {&skip}, "Only analyse every nr-th frame" }, { "-max", FALSE, etREAL, {&max}, "Maximum for projection of the eigenvector on the average structure, " "max=0 gives the extremes" }, { "-nframes", FALSE, etINT, {&nextr}, "Number of frames for the extremes output" }, { "-split", FALSE, etBOOL, {&bSplit}, "Split eigenvector projections where time is zero" }, { "-entropy", FALSE, etBOOL, {&bEntropy}, "Compute entropy according to the Quasiharmonic formula or Schlitter's method." }, { "-temp", FALSE, etREAL, {&temp}, "Temperature for entropy calculations" }, { "-nevskip", FALSE, etINT, {&nskip}, "Number of eigenvalues to skip when computing the entropy due to the quasi harmonic approximation. When you do a rotational and/or translational fit prior to the covariance analysis, you get 3 or 6 eigenvalues that are very close to zero, and which should not be taken into account when computing the entropy." } }; #define NPA asize(pa) FILE *out; int status,trjout; t_topology top; int ePBC=-1; t_atoms *atoms=NULL; rvec *xtop,*xref1,*xref2,*xrefp=NULL; gmx_bool bDMR1,bDMA1,bDMR2,bDMA2; int nvec1,nvec2,*eignr1=NULL,*eignr2=NULL; rvec *x,*xread,*xav1,*xav2,**eigvec1=NULL,**eigvec2=NULL; matrix topbox; real xid,totmass,*sqrtm,*w_rls,t,lambda; int natoms,step; char *grpname; const char *indexfile; char title[STRLEN]; int i,j,d; int nout,*iout,noutvec,*outvec,nfit; atom_id *index,*ifit; const char *VecFile,*Vec2File,*topfile; const char *EigFile,*Eig2File; const char *CompFile,*RmsfFile,*ProjOnVecFile; const char *TwoDPlotFile,*ThreeDPlotFile; const char *FilterFile,*ExtremeFile; const char *OverlapFile,*InpMatFile; gmx_bool bFit1,bFit2,bM,bIndex,bTPS,bTop,bVec2,bProj; gmx_bool bFirstToLast,bFirstLastSet,bTraj,bCompare,bPDB3D; real *eigval1=NULL,*eigval2=NULL; int neig1,neig2; double **xvgdata; output_env_t oenv; gmx_rmpbc_t gpbc; t_filenm fnm[] = { { efTRN, "-v", "eigenvec", ffREAD }, { efTRN, "-v2", "eigenvec2", ffOPTRD }, { efTRX, "-f", NULL, ffOPTRD }, { efTPS, NULL, NULL, ffOPTRD }, { efNDX, NULL, NULL, ffOPTRD }, { efXVG, "-eig", "eigenval", ffOPTRD }, { efXVG, "-eig2", "eigenval2", ffOPTRD }, { efXVG, "-comp", "eigcomp", ffOPTWR }, { efXVG, "-rmsf", "eigrmsf", ffOPTWR }, { efXVG, "-proj", "proj", ffOPTWR }, { efXVG, "-2d", "2dproj", ffOPTWR }, { efSTO, "-3d", "3dproj.pdb", ffOPTWR }, { efTRX, "-filt", "filtered", ffOPTWR }, { efTRX, "-extr", "extreme.pdb", ffOPTWR }, { efXVG, "-over", "overlap", ffOPTWR }, { efXPM, "-inpr", "inprod", ffOPTWR } }; #define NFILE asize(fnm) parse_common_args(&argc,argv, PCA_CAN_TIME | PCA_TIME_UNIT | PCA_CAN_VIEW | PCA_BE_NICE , NFILE,fnm,NPA,pa,asize(desc),desc,0,NULL,&oenv); indexfile=ftp2fn_null(efNDX,NFILE,fnm); VecFile = opt2fn("-v",NFILE,fnm); Vec2File = opt2fn_null("-v2",NFILE,fnm); topfile = ftp2fn(efTPS,NFILE,fnm); EigFile = opt2fn_null("-eig",NFILE,fnm); Eig2File = opt2fn_null("-eig2",NFILE,fnm); CompFile = opt2fn_null("-comp",NFILE,fnm); RmsfFile = opt2fn_null("-rmsf",NFILE,fnm); ProjOnVecFile = opt2fn_null("-proj",NFILE,fnm); TwoDPlotFile = opt2fn_null("-2d",NFILE,fnm); ThreeDPlotFile = opt2fn_null("-3d",NFILE,fnm); FilterFile = opt2fn_null("-filt",NFILE,fnm); ExtremeFile = opt2fn_null("-extr",NFILE,fnm); OverlapFile = opt2fn_null("-over",NFILE,fnm); InpMatFile = ftp2fn_null(efXPM,NFILE,fnm); bTop = fn2bTPX(topfile); bProj = ProjOnVecFile || TwoDPlotFile || ThreeDPlotFile || FilterFile || ExtremeFile; bFirstLastSet = opt2parg_bSet("-first",NPA,pa) && opt2parg_bSet("-last",NPA,pa); bFirstToLast = CompFile || RmsfFile || ProjOnVecFile || FilterFile || OverlapFile || ((ExtremeFile || InpMatFile) && bFirstLastSet); bVec2 = Vec2File || OverlapFile || InpMatFile; bM = RmsfFile || bProj; bTraj = ProjOnVecFile || FilterFile || (ExtremeFile && (max==0)) || TwoDPlotFile || ThreeDPlotFile; bIndex = bM || bProj; bTPS = ftp2bSet(efTPS,NFILE,fnm) || bM || bTraj || FilterFile || (bIndex && indexfile); bCompare = Vec2File || Eig2File; bPDB3D = fn2ftp(ThreeDPlotFile)==efPDB; read_eigenvectors(VecFile,&natoms,&bFit1, &xref1,&bDMR1,&xav1,&bDMA1, &nvec1,&eignr1,&eigvec1,&eigval1); neig1 = DIM*natoms; /* Overwrite eigenvalues from separate files if the user provides them */ if (EigFile != NULL) { int neig_tmp = read_xvg(EigFile,&xvgdata,&i); if (neig_tmp != neig1) fprintf(stderr,"Warning: number of eigenvalues in xvg file (%d) does not mtch trr file (%d)\n",neig1,natoms); neig1 = neig_tmp; srenew(eigval1,neig1); for(j=0;j<neig1;j++) { real tmp = eigval1[j]; eigval1[j]=xvgdata[1][j]; if (debug && (eigval1[j] != tmp)) fprintf(debug,"Replacing eigenvalue %d. From trr: %10g, from xvg: %10g\n", j,tmp,eigval1[j]); } for(j=0;j<i;j++) sfree(xvgdata[j]); sfree(xvgdata); fprintf(stderr,"Read %d eigenvalues from %s\n",neig1,EigFile); } if (bEntropy) { if (bDMA1) { gmx_fatal(FARGS,"Can not calculate entropies from mass-weighted eigenvalues, redo the analysis without mass-weighting"); } calc_entropy_qh(stdout,neig1,eigval1,temp,nskip); calc_entropy_schlitter(stdout,neig1,nskip,eigval1,temp); } if (bVec2) { if (!Vec2File) gmx_fatal(FARGS,"Need a second eigenvector file to do this analysis."); read_eigenvectors(Vec2File,&neig2,&bFit2, &xref2,&bDMR2,&xav2,&bDMA2,&nvec2,&eignr2,&eigvec2,&eigval2); neig2 = DIM*neig2; if (neig2 != neig1) gmx_fatal(FARGS,"Dimensions in the eigenvector files don't match"); } if(Eig2File != NULL) { neig2 = read_xvg(Eig2File,&xvgdata,&i); srenew(eigval2,neig2); for(j=0;j<neig2;j++) eigval2[j]=xvgdata[1][j]; for(j=0;j<i;j++) sfree(xvgdata[j]); sfree(xvgdata); fprintf(stderr,"Read %d eigenvalues from %s\n",neig2,Eig2File); } if ((!bFit1 || xref1) && !bDMR1 && !bDMA1) bM=FALSE; if ((xref1==NULL) && (bM || bTraj)) bTPS=TRUE; xtop=NULL; nfit=0; ifit=NULL; w_rls=NULL; if (!bTPS) { bTop=FALSE; } else { bTop=read_tps_conf(ftp2fn(efTPS,NFILE,fnm), title,&top,&ePBC,&xtop,NULL,topbox,bM); atoms=&top.atoms; gpbc = gmx_rmpbc_init(&top.idef,ePBC,atoms->nr,topbox); gmx_rmpbc(gpbc,atoms->nr,topbox,xtop); /* Fitting is only required for the projection */ if (bProj && bFit1) { if (xref1 == NULL) { printf("\nNote: the structure in %s should be the same\n" " as the one used for the fit in g_covar\n",topfile); } printf("\nSelect the index group that was used for the least squares fit in g_covar\n"); get_index(atoms,indexfile,1,&nfit,&ifit,&grpname); snew(w_rls,atoms->nr); for(i=0; (i<nfit); i++) { if (bDMR1) { w_rls[ifit[i]] = atoms->atom[ifit[i]].m; } else { w_rls[ifit[i]] = 1.0; } } snew(xrefp,atoms->nr); if (xref1 != NULL) { for(i=0; (i<nfit); i++) { copy_rvec(xref1[i],xrefp[ifit[i]]); } } else { /* The top coordinates are the fitting reference */ for(i=0; (i<nfit); i++) { copy_rvec(xtop[ifit[i]],xrefp[ifit[i]]); } reset_x(nfit,ifit,atoms->nr,NULL,xrefp,w_rls); } } gmx_rmpbc_done(gpbc); } if (bIndex) { printf("\nSelect an index group of %d elements that corresponds to the eigenvectors\n",natoms); get_index(atoms,indexfile,1,&i,&index,&grpname); if (i!=natoms) gmx_fatal(FARGS,"you selected a group with %d elements instead of %d",i,natoms); printf("\n"); } snew(sqrtm,natoms); if (bM && bDMA1) { proj_unit="u\\S1/2\\Nnm"; for(i=0; (i<natoms); i++) sqrtm[i]=sqrt(atoms->atom[index[i]].m); } else { proj_unit="nm"; for(i=0; (i<natoms); i++) sqrtm[i]=1.0; } if (bVec2) { t=0; totmass=0; for(i=0; (i<natoms); i++) for(d=0;(d<DIM);d++) { t+=sqr((xav1[i][d]-xav2[i][d])*sqrtm[i]); totmass+=sqr(sqrtm[i]); } fprintf(stdout,"RMSD (without fit) between the two average structures:" " %.3f (nm)\n\n",sqrt(t/totmass)); } if (last==-1) last=natoms*DIM; if (first>-1) { if (bFirstToLast) { /* make an index from first to last */ nout=last-first+1; snew(iout,nout); for(i=0; i<nout; i++) iout[i]=first-1+i; } else if (ThreeDPlotFile) { /* make an index of first+(0,1,2) and last */ nout = bPDB3D ? 4 : 3; nout = min(last-first+1, nout); snew(iout,nout); iout[0]=first-1; iout[1]=first; if (nout>3) iout[2]=first+1; iout[nout-1]=last-1; } else { /* make an index of first and last */ nout=2; snew(iout,nout); iout[0]=first-1; iout[1]=last-1; } } else { printf("Select eigenvectors for output, end your selection with 0\n"); nout=-1; iout=NULL; do { nout++; srenew(iout,nout+1); if(1 != scanf("%d",&iout[nout])) { gmx_fatal(FARGS,"Error reading user input"); } iout[nout]--; } while (iout[nout]>=0); printf("\n"); } /* make an index of the eigenvectors which are present */ snew(outvec,nout); noutvec=0; for(i=0; i<nout; i++) { j=0; while ((j<nvec1) && (eignr1[j]!=iout[i])) j++; if ((j<nvec1) && (eignr1[j]==iout[i])) { outvec[noutvec]=j; noutvec++; } } fprintf(stderr,"%d eigenvectors selected for output",noutvec); if (noutvec <= 100) { fprintf(stderr,":"); for(j=0; j<noutvec; j++) fprintf(stderr," %d",eignr1[outvec[j]]+1); } fprintf(stderr,"\n"); if (CompFile) components(CompFile,natoms,eignr1,eigvec1,noutvec,outvec,oenv); if (RmsfFile) rmsf(RmsfFile,natoms,sqrtm,eignr1,eigvec1,noutvec,outvec,eigval1, neig1,oenv); if (bProj) project(bTraj ? opt2fn("-f",NFILE,fnm) : NULL, bTop ? &top : NULL,ePBC,topbox, ProjOnVecFile,TwoDPlotFile,ThreeDPlotFile,FilterFile,skip, ExtremeFile,bFirstLastSet,max,nextr,atoms,natoms,index, bFit1,xrefp,nfit,ifit,w_rls, sqrtm,xav1,eignr1,eigvec1,noutvec,outvec,bSplit, oenv); if (OverlapFile) overlap(OverlapFile,natoms, eigvec1,nvec2,eignr2,eigvec2,noutvec,outvec,oenv); if (InpMatFile) inprod_matrix(InpMatFile,natoms, nvec1,eignr1,eigvec1,nvec2,eignr2,eigvec2, bFirstLastSet,noutvec,outvec); if (bCompare) compare(natoms,nvec1,eigvec1,nvec2,eigvec2,eigval1,neig1,eigval2,neig2); if (!CompFile && !bProj && !OverlapFile && !InpMatFile && !bCompare && !bEntropy) { fprintf(stderr,"\nIf you want some output," " set one (or two or ...) of the output file options\n"); } view_all(oenv,NFILE, fnm); thanx(stdout); return 0; }
int gmx_trjcat(int argc,char *argv[]) { static char *desc[] = { "trjcat concatenates several input trajectory files in sorted order. ", "In case of double time frames the one in the later file is used. ", "By specifying [TT]-settime[tt] you will be asked for the start time ", "of each file. The input files are taken from the command line, ", "such that a command like [TT]trjcat -o fixed.trr *.trr[tt] should do ", "the trick. Using [TT]-cat[tt] you can simply paste several files ", "together without removal of frames with identical time stamps.[PAR]", "One important option is inferred when the output file is amongst the", "input files. In that case that particular file will be appended to", "which implies you do not need to store double the amount of data.", "Obviously the file to append to has to be the one with lowest starting", "time since one can only append at the end of a file.[PAR]", "If the [TT]-demux[tt] option is given, the N trajectories that are", "read, are written in another order as specified in the xvg file." "The xvg file should contain something like:[PAR]", "0 0 1 2 3 4 5[BR]", "2 1 0 2 3 5 4[BR]", "Where the first number is the time, and subsequent numbers point to", "trajectory indices.", "The frames corresponding to the numbers present at the first line", "are collected into the output trajectory. If the number of frames in", "the trajectory does not match that in the xvg file then the program", "tries to be smart. Beware." }; static bool bVels=TRUE; static int prec=3; static bool bCat=FALSE; static bool bSort=TRUE; static bool bKeepLast=FALSE; static bool bSetTime=FALSE; static bool bDeMux; static real begin=-1; static real end=-1; static real dt=0; t_pargs pa[] = { { "-b", FALSE, etTIME, {&begin}, "First time to use (%t)"}, { "-e", FALSE, etTIME, {&end}, "Last time to use (%t)"}, { "-dt", FALSE, etTIME, {&dt}, "Only write frame when t MOD dt = first time (%t)" }, { "-prec", FALSE, etINT, {&prec}, "Precision for .xtc and .gro writing in number of decimal places" }, { "-vel", FALSE, etBOOL, {&bVels}, "Read and write velocities if possible" }, { "-settime", FALSE, etBOOL, {&bSetTime}, "Change starting time interactively" }, { "-sort", FALSE, etBOOL, {&bSort}, "Sort trajectory files (not frames)" }, { "-keeplast",FALSE, etBOOL, {&bKeepLast}, "keep overlapping frames at end of trajectory" }, { "-cat", FALSE, etBOOL, {&bCat}, "do not discard double time frames" } }; #define npargs asize(pa) int status,ftpin,i,frame,frame_out,step=0,trjout=0; rvec *x,*v; real xtcpr,t_corr; t_trxframe fr,frout; char **fnms,**fnms_out,*in_file,*out_file; int n_append; int trxout=-1; bool bNewFile,bIndex,bWrite; int earliersteps,nfile_in,nfile_out,*cont_type,last_ok_step; real *readtime,*timest,*settime; real first_time=0,lasttime=NOTSET,last_ok_t=-1,timestep; int isize,j; atom_id *index=NULL,imax; char *grpname; real **val=NULL,*t=NULL,dt_remd; int n,nset; t_filenm fnm[] = { { efTRX, "-f", NULL, ffRDMULT }, { efTRO, "-o", NULL, ffWRMULT }, { efNDX, "-n", "index", ffOPTRD }, { efXVG, "-demux", "remd", ffOPTRD } }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_BE_NICE|PCA_TIME_UNIT, NFILE,fnm,asize(pa),pa,asize(desc),desc, 0,NULL); bIndex = ftp2bSet(efNDX,NFILE,fnm); bDeMux = ftp2bSet(efXVG,NFILE,fnm); bSort = bSort && !bDeMux; imax=NO_ATID; if (bIndex) { printf("Select group for output\n"); rd_index(ftp2fn(efNDX,NFILE,fnm),1,&isize,&index,&grpname); /* scan index */ imax=index[0]; for(i=1; i<isize; i++) imax = max(imax, index[i]); } if (bDeMux) { nset = 0; dt_remd = 0; val=read_xvg_time(opt2fn("-demux",NFILE,fnm),TRUE, opt2parg_bSet("-b",npargs,pa),begin, opt2parg_bSet("-e",npargs,pa),end, 1,&nset,&n,&dt_remd,&t); printf("Read %d sets of %d points, dt = %g\n\n",nset,n,dt_remd); if (debug) { fprintf(debug,"Dump of replica_index.xvg\n"); for(i=0; (i<n); i++) { fprintf(debug,"%10g",t[i]); for(j=0; (j<nset); j++) { fprintf(debug," %3d",gmx_nint(val[j][i])); } fprintf(debug,"\n"); } } } /* prec is in nr of decimal places, xtcprec is a multiplication factor: */ xtcpr=1; for (i=0; i<prec; i++) xtcpr*=10; nfile_in = opt2fns(&fnms,"-f",NFILE,fnm); if (!nfile_in) gmx_fatal(FARGS,"No input files!"); if (bDeMux && (nfile_in != nset)) gmx_fatal(FARGS,"You have specified %d files and %d entries in the demux table",nfile_in,nset); nfile_out = opt2fns(&fnms_out,"-o",NFILE,fnm); if (!nfile_out) gmx_fatal(FARGS,"No output files!"); if ((nfile_out > 1) && !bDeMux) gmx_fatal(FARGS,"Don't know what to do with more than 1 output file if not demultiplexing"); else if (bDeMux && (nfile_out != nset) && (nfile_out != 1)) gmx_fatal(FARGS,"Number of output files should be 1 or %d (#input files), not %d",nset,nfile_out); if (bDeMux) { if (nfile_out != nset) { char *buf = strdup(fnms_out[0]); snew(fnms_out,nset); for(i=0; (i<nset); i++) { snew(fnms_out[i],strlen(buf)+32); sprintf(fnms_out[i],"%d_%s",i,buf); } } do_demux(nfile_in,fnms,fnms_out,n,val,t,dt_remd,isize,index,dt); } else { snew(readtime,nfile_in+1); snew(timest,nfile_in+1); scan_trj_files(fnms,nfile_in,readtime,timest,imax); snew(settime,nfile_in+1); snew(cont_type,nfile_in+1); edit_files(fnms,nfile_in,readtime,timest,settime,cont_type,bSetTime,bSort); /* Check whether the output file is amongst the input files * This has to be done after sorting etc. */ out_file = fnms_out[0]; n_append = -1; for(i=0; ((i<nfile_in) && (n_append==-1)); i++) { if (strcmp(fnms[i],out_file) == 0) { n_append = i; } } if (n_append == 0) fprintf(stderr,"Will append to %s rather than creating a new file\n", out_file); else if (n_append != -1) gmx_fatal(FARGS,"Can only append to the first file which is %s (not %s)", fnms[0],out_file); earliersteps=0; /* Not checking input format, could be dangerous :-) */ /* Not checking output format, equally dangerous :-) */ frame=-1; frame_out=-1; /* the default is not to change the time at all, * but this is overridden by the edit_files routine */ t_corr=0; if (n_append == -1) { trxout = open_trx(out_file,"w"); memset(&frout,0,sizeof(frout)); } else { /* Read file to find what is the last frame in it */ if (!read_first_frame(&status,out_file,&fr,FLAGS)) gmx_fatal(FARGS,"Reading first frame from %s",out_file); while (read_next_frame(status,&fr)) ; close_trj(status); lasttime = fr.time; bKeepLast = TRUE; trxout = open_trx(out_file,"a"); frout = fr; } /* Lets stitch up some files */ timestep = timest[0]; for(i=n_append+1; (i<nfile_in); i++) { /* Open next file */ /* set the next time from the last frame in previous file */ if (i > 0) { if (frame_out >= 0) { if(cont_type[i]==TIME_CONTINUE) { begin =frout.time; begin += 0.5*timestep; settime[i]=frout.time; cont_type[i]=TIME_EXPLICIT; } else if(cont_type[i]==TIME_LAST) { begin=frout.time; begin += 0.5*timestep; } /* Or, if the time in the next part should be changed by the * same amount, start at half a timestep from the last time * so we dont repeat frames. */ /* I don't understand the comment above, but for all the cases * I tried the code seems to work properly. B. Hess 2008-4-2. */ } /* Or, if time is set explicitly, we check for overlap/gap */ if(cont_type[i]==TIME_EXPLICIT) if( ( i < nfile_in ) && ( frout.time < settime[i]-1.5*timestep ) ) fprintf(stderr, "WARNING: Frames around t=%f %s have a different " "spacing than the rest,\n" "might be a gap or overlap that couldn't be corrected " "automatically.\n",convert_time(frout.time),time_unit()); } /* if we don't have a timestep in the current file, use the old one */ if ( timest[i] != 0 ) timestep = timest[i]; read_first_frame(&status,fnms[i],&fr,FLAGS); if(!fr.bTime) { fr.time=0; fprintf(stderr,"\nWARNING: Couldn't find a time in the frame.\n"); } if(cont_type[i]==TIME_EXPLICIT) t_corr=settime[i]-fr.time; /* t_corr is the amount we want to change the time. * If the user has chosen not to change the time for * this part of the trajectory t_corr remains at * the value it had in the last part, changing this * by the same amount. * If no value was given for the first trajectory part * we let the time start at zero, see the edit_files routine. */ bNewFile=TRUE; printf("\n"); if (lasttime != NOTSET) printf("lasttime %g\n", lasttime); do { /* copy the input frame to the output frame */ frout=fr; /* set the new time by adding the correct calculated above */ frout.time += t_corr; /* quit if we have reached the end of what should be written */ if((end > 0) && (frout.time > end+GMX_REAL_EPS)) { i=nfile_in; break; } /* determine if we should write this frame (dt is handled elsewhere) */ if (bCat) /* write all frames of all files */ bWrite = TRUE; else if ( bKeepLast ) /* write till last frame of this traj and skip first frame(s) of next traj */ bWrite = ( frout.time > lasttime+0.5*timestep ); else /* write till first frame of next traj */ bWrite = ( frout.time < settime[i+1]-0.5*timestep ); if( bWrite && (frout.time >= begin) ) { frame++; if (frame_out == -1) first_time = frout.time; lasttime = frout.time; if (dt==0 || bRmod(frout.time,first_time,dt)) { frame_out++; last_ok_t=frout.time; if(bNewFile) { fprintf(stderr,"\nContinue writing frames from %s t=%g %s, " "frame=%d \n", fnms[i],convert_time(frout.time),time_unit(),frame); bNewFile=FALSE; } if (bIndex) write_trxframe_indexed(trxout,&frout,isize,index); else write_trxframe(trxout,&frout); if ( ((frame % 10) == 0) || (frame < 10) ) fprintf(stderr," -> frame %6d time %8.3f %s \r", frame_out,convert_time(frout.time),time_unit()); } } } while( read_next_frame(status,&fr)); close_trj(status); earliersteps+=step; } if (trxout >= 0) close_trx(trxout); fprintf(stderr,"\nLast frame written was %d, time %f %s\n", frame,convert_time(last_ok_t),time_unit()); } thanx(stderr); return 0; }
int gmx_covar(int argc,char *argv[]) { const char *desc[] = { "[TT]g_covar[tt] calculates and diagonalizes the (mass-weighted)", "covariance matrix.", "All structures are fitted to the structure in the structure file.", "When this is not a run input file periodicity will not be taken into", "account. When the fit and analysis groups are identical and the analysis", "is non mass-weighted, the fit will also be non mass-weighted.", "[PAR]", "The eigenvectors are written to a trajectory file ([TT]-v[tt]).", "When the same atoms are used for the fit and the covariance analysis,", "the reference structure for the fit is written first with t=-1.", "The average (or reference when [TT]-ref[tt] is used) structure is", "written with t=0, the eigenvectors", "are written as frames with the eigenvector number as timestamp.", "[PAR]", "The eigenvectors can be analyzed with [TT]g_anaeig[tt].", "[PAR]", "Option [TT]-ascii[tt] writes the whole covariance matrix to", "an ASCII file. The order of the elements is: x1x1, x1y1, x1z1, x1x2, ...", "[PAR]", "Option [TT]-xpm[tt] writes the whole covariance matrix to an [TT].xpm[tt] file.", "[PAR]", "Option [TT]-xpma[tt] writes the atomic covariance matrix to an [TT].xpm[tt] file,", "i.e. for each atom pair the sum of the xx, yy and zz covariances is", "written.", "[PAR]", "Note that the diagonalization of a matrix requires memory and time", "that will increase at least as fast as than the square of the number", "of atoms involved. It is easy to run out of memory, in which", "case this tool will probably exit with a 'Segmentation fault'. You", "should consider carefully whether a reduced set of atoms will meet", "your needs for lower costs." }; static gmx_bool bFit=TRUE,bRef=FALSE,bM=FALSE,bPBC=TRUE; static int end=-1; t_pargs pa[] = { { "-fit", FALSE, etBOOL, {&bFit}, "Fit to a reference structure"}, { "-ref", FALSE, etBOOL, {&bRef}, "Use the deviation from the conformation in the structure file instead of from the average" }, { "-mwa", FALSE, etBOOL, {&bM}, "Mass-weighted covariance analysis"}, { "-last", FALSE, etINT, {&end}, "Last eigenvector to write away (-1 is till the last)" }, { "-pbc", FALSE, etBOOL, {&bPBC}, "Apply corrections for periodic boundary conditions" } }; FILE *out; t_trxstatus *status; t_trxstatus *trjout; t_topology top; int ePBC; t_atoms *atoms; rvec *x,*xread,*xref,*xav,*xproj; matrix box,zerobox; real *sqrtm,*mat,*eigval,sum,trace,inv_nframes; real t,tstart,tend,**mat2; real xj,*w_rls=NULL; real min,max,*axis; int ntopatoms,step; int natoms,nat,count,nframes0,nframes,nlevels; gmx_large_int_t ndim,i,j,k,l; int WriteXref; const char *fitfile,*trxfile,*ndxfile; const char *eigvalfile,*eigvecfile,*averfile,*logfile; const char *asciifile,*xpmfile,*xpmafile; char str[STRLEN],*fitname,*ananame,*pcwd; int d,dj,nfit; atom_id *index,*ifit; gmx_bool bDiffMass1,bDiffMass2; time_t now; char timebuf[STRLEN]; t_rgb rlo,rmi,rhi; real *tmp; output_env_t oenv; gmx_rmpbc_t gpbc=NULL; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPS, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffOPTRD }, { efXVG, NULL, "eigenval", ffWRITE }, { efTRN, "-v", "eigenvec", ffWRITE }, { efSTO, "-av", "average.pdb", ffWRITE }, { efLOG, NULL, "covar", ffWRITE }, { efDAT, "-ascii","covar", ffOPTWR }, { efXPM, "-xpm","covar", ffOPTWR }, { efXPM, "-xpma","covara", ffOPTWR } }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_TIME_UNIT | PCA_BE_NICE, NFILE,fnm,asize(pa),pa,asize(desc),desc,0,NULL,&oenv); clear_mat(zerobox); fitfile = ftp2fn(efTPS,NFILE,fnm); trxfile = ftp2fn(efTRX,NFILE,fnm); ndxfile = ftp2fn_null(efNDX,NFILE,fnm); eigvalfile = ftp2fn(efXVG,NFILE,fnm); eigvecfile = ftp2fn(efTRN,NFILE,fnm); averfile = ftp2fn(efSTO,NFILE,fnm); logfile = ftp2fn(efLOG,NFILE,fnm); asciifile = opt2fn_null("-ascii",NFILE,fnm); xpmfile = opt2fn_null("-xpm",NFILE,fnm); xpmafile = opt2fn_null("-xpma",NFILE,fnm); read_tps_conf(fitfile,str,&top,&ePBC,&xref,NULL,box,TRUE); atoms=&top.atoms; if (bFit) { printf("\nChoose a group for the least squares fit\n"); get_index(atoms,ndxfile,1,&nfit,&ifit,&fitname); if (nfit < 3) gmx_fatal(FARGS,"Need >= 3 points to fit!\n"); } else nfit=0; printf("\nChoose a group for the covariance analysis\n"); get_index(atoms,ndxfile,1,&natoms,&index,&ananame); bDiffMass1=FALSE; if (bFit) { snew(w_rls,atoms->nr); for(i=0; (i<nfit); i++) { w_rls[ifit[i]]=atoms->atom[ifit[i]].m; if (i) bDiffMass1 = bDiffMass1 || (w_rls[ifit[i]]!=w_rls[ifit[i-1]]); } } bDiffMass2=FALSE; snew(sqrtm,natoms); for(i=0; (i<natoms); i++) if (bM) { sqrtm[i]=sqrt(atoms->atom[index[i]].m); if (i) bDiffMass2 = bDiffMass2 || (sqrtm[i]!=sqrtm[i-1]); } else sqrtm[i]=1.0; if (bFit && bDiffMass1 && !bDiffMass2) { bDiffMass1 = natoms != nfit; i=0; for (i=0; (i<natoms) && !bDiffMass1; i++) bDiffMass1 = index[i] != ifit[i]; if (!bDiffMass1) { fprintf(stderr,"\n" "Note: the fit and analysis group are identical,\n" " while the fit is mass weighted and the analysis is not.\n" " Making the fit non mass weighted.\n\n"); for(i=0; (i<nfit); i++) w_rls[ifit[i]]=1.0; } } /* Prepare reference frame */ if (bPBC) { gpbc = gmx_rmpbc_init(&top.idef,ePBC,atoms->nr,box); gmx_rmpbc(gpbc,atoms->nr,box,xref); } if (bFit) reset_x(nfit,ifit,atoms->nr,NULL,xref,w_rls); snew(x,natoms); snew(xav,natoms); ndim=natoms*DIM; if (sqrt(GMX_LARGE_INT_MAX)<ndim) { gmx_fatal(FARGS,"Number of degrees of freedoms to large for matrix.\n"); } snew(mat,ndim*ndim); fprintf(stderr,"Calculating the average structure ...\n"); nframes0 = 0; nat=read_first_x(oenv,&status,trxfile,&t,&xread,box); if (nat != atoms->nr) fprintf(stderr,"\nWARNING: number of atoms in tpx (%d) and trajectory (%d) do not match\n",natoms,nat); do { nframes0++; /* calculate x: a fitted struture of the selected atoms */ if (bPBC) gmx_rmpbc(gpbc,nat,box,xread); if (bFit) { reset_x(nfit,ifit,nat,NULL,xread,w_rls); do_fit(nat,w_rls,xref,xread); } for (i=0; i<natoms; i++) rvec_inc(xav[i],xread[index[i]]); } while (read_next_x(oenv,status,&t,nat,xread,box)); close_trj(status); inv_nframes = 1.0/nframes0; for(i=0; i<natoms; i++) for(d=0; d<DIM; d++) { xav[i][d] *= inv_nframes; xread[index[i]][d] = xav[i][d]; } write_sto_conf_indexed(opt2fn("-av",NFILE,fnm),"Average structure", atoms,xread,NULL,epbcNONE,zerobox,natoms,index); sfree(xread); fprintf(stderr,"Constructing covariance matrix (%dx%d) ...\n",(int)ndim,(int)ndim); nframes=0; nat=read_first_x(oenv,&status,trxfile,&t,&xread,box); tstart = t; do { nframes++; tend = t; /* calculate x: a (fitted) structure of the selected atoms */ if (bPBC) gmx_rmpbc(gpbc,nat,box,xread); if (bFit) { reset_x(nfit,ifit,nat,NULL,xread,w_rls); do_fit(nat,w_rls,xref,xread); } if (bRef) for (i=0; i<natoms; i++) rvec_sub(xread[index[i]],xref[index[i]],x[i]); else for (i=0; i<natoms; i++) rvec_sub(xread[index[i]],xav[i],x[i]); for (j=0; j<natoms; j++) { for (dj=0; dj<DIM; dj++) { k=ndim*(DIM*j+dj); xj=x[j][dj]; for (i=j; i<natoms; i++) { l=k+DIM*i; for(d=0; d<DIM; d++) mat[l+d] += x[i][d]*xj; } } } } while (read_next_x(oenv,status,&t,nat,xread,box) && (bRef || nframes < nframes0)); close_trj(status); gmx_rmpbc_done(gpbc); fprintf(stderr,"Read %d frames\n",nframes); if (bRef) { /* copy the reference structure to the ouput array x */ snew(xproj,natoms); for (i=0; i<natoms; i++) copy_rvec(xref[index[i]],xproj[i]); } else { xproj = xav; } /* correct the covariance matrix for the mass */ inv_nframes = 1.0/nframes; for (j=0; j<natoms; j++) for (dj=0; dj<DIM; dj++) for (i=j; i<natoms; i++) { k = ndim*(DIM*j+dj)+DIM*i; for (d=0; d<DIM; d++) mat[k+d] = mat[k+d]*inv_nframes*sqrtm[i]*sqrtm[j]; } /* symmetrize the matrix */ for (j=0; j<ndim; j++) for (i=j; i<ndim; i++) mat[ndim*i+j]=mat[ndim*j+i]; trace=0; for(i=0; i<ndim; i++) trace+=mat[i*ndim+i]; fprintf(stderr,"\nTrace of the covariance matrix: %g (%snm^2)\n", trace,bM ? "u " : ""); if (asciifile) { out = ffopen(asciifile,"w"); for (j=0; j<ndim; j++) { for (i=0; i<ndim; i+=3) fprintf(out,"%g %g %g\n", mat[ndim*j+i],mat[ndim*j+i+1],mat[ndim*j+i+2]); } ffclose(out); } if (xpmfile) { min = 0; max = 0; snew(mat2,ndim); for (j=0; j<ndim; j++) { mat2[j] = &(mat[ndim*j]); for (i=0; i<=j; i++) { if (mat2[j][i] < min) min = mat2[j][i]; if (mat2[j][j] > max) max = mat2[j][i]; } } snew(axis,ndim); for(i=0; i<ndim; i++) axis[i] = i+1; rlo.r = 0; rlo.g = 0; rlo.b = 1; rmi.r = 1; rmi.g = 1; rmi.b = 1; rhi.r = 1; rhi.g = 0; rhi.b = 0; out = ffopen(xpmfile,"w"); nlevels = 80; write_xpm3(out,0,"Covariance",bM ? "u nm^2" : "nm^2", "dim","dim",ndim,ndim,axis,axis, mat2,min,0.0,max,rlo,rmi,rhi,&nlevels); ffclose(out); sfree(axis); sfree(mat2); } if (xpmafile) { min = 0; max = 0; snew(mat2,ndim/DIM); for (i=0; i<ndim/DIM; i++) snew(mat2[i],ndim/DIM); for (j=0; j<ndim/DIM; j++) { for (i=0; i<=j; i++) { mat2[j][i] = 0; for(d=0; d<DIM; d++) mat2[j][i] += mat[ndim*(DIM*j+d)+DIM*i+d]; if (mat2[j][i] < min) min = mat2[j][i]; if (mat2[j][j] > max) max = mat2[j][i]; mat2[i][j] = mat2[j][i]; } } snew(axis,ndim/DIM); for(i=0; i<ndim/DIM; i++) axis[i] = i+1; rlo.r = 0; rlo.g = 0; rlo.b = 1; rmi.r = 1; rmi.g = 1; rmi.b = 1; rhi.r = 1; rhi.g = 0; rhi.b = 0; out = ffopen(xpmafile,"w"); nlevels = 80; write_xpm3(out,0,"Covariance",bM ? "u nm^2" : "nm^2", "atom","atom",ndim/DIM,ndim/DIM,axis,axis, mat2,min,0.0,max,rlo,rmi,rhi,&nlevels); ffclose(out); sfree(axis); for (i=0; i<ndim/DIM; i++) sfree(mat2[i]); sfree(mat2); } /* call diagonalization routine */ fprintf(stderr,"\nDiagonalizing ...\n"); fflush(stderr); snew(eigval,ndim); snew(tmp,ndim*ndim); memcpy(tmp,mat,ndim*ndim*sizeof(real)); eigensolver(tmp,ndim,0,ndim,eigval,mat); sfree(tmp); /* now write the output */ sum=0; for(i=0; i<ndim; i++) sum+=eigval[i]; fprintf(stderr,"\nSum of the eigenvalues: %g (%snm^2)\n", sum,bM ? "u " : ""); if (fabs(trace-sum)>0.01*trace) fprintf(stderr,"\nWARNING: eigenvalue sum deviates from the trace of the covariance matrix\n"); fprintf(stderr,"\nWriting eigenvalues to %s\n",eigvalfile); sprintf(str,"(%snm\\S2\\N)",bM ? "u " : ""); out=xvgropen(eigvalfile, "Eigenvalues of the covariance matrix", "Eigenvector index",str,oenv); for (i=0; (i<ndim); i++) fprintf (out,"%10d %g\n",(int)i+1,eigval[ndim-1-i]); ffclose(out); if (end==-1) { if (nframes-1 < ndim) end=nframes-1; else end=ndim; } if (bFit) { /* misuse lambda: 0/1 mass weighted analysis no/yes */ if (nfit==natoms) { WriteXref = eWXR_YES; for(i=0; i<nfit; i++) copy_rvec(xref[ifit[i]],x[i]); } else WriteXref = eWXR_NO; } else { /* misuse lambda: -1 for no fit */ WriteXref = eWXR_NOFIT; } write_eigenvectors(eigvecfile,natoms,mat,TRUE,1,end, WriteXref,x,bDiffMass1,xproj,bM,eigval); out = ffopen(logfile,"w"); time(&now); gmx_ctime_r(&now,timebuf,STRLEN); fprintf(out,"Covariance analysis log, written %s\n",timebuf); fprintf(out,"Program: %s\n",argv[0]); #if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __CYGWIN__ && !defined __CYGWIN32__) pcwd=_getcwd(str,STRLEN); #else pcwd=getcwd(str,STRLEN); #endif if(NULL==pcwd) { gmx_fatal(FARGS,"Current working directory is undefined"); } fprintf(out,"Working directory: %s\n\n",str); fprintf(out,"Read %d frames from %s (time %g to %g %s)\n",nframes,trxfile, output_env_conv_time(oenv,tstart),output_env_conv_time(oenv,tend),output_env_get_time_unit(oenv)); if (bFit) fprintf(out,"Read reference structure for fit from %s\n",fitfile); if (ndxfile) fprintf(out,"Read index groups from %s\n",ndxfile); fprintf(out,"\n"); fprintf(out,"Analysis group is '%s' (%d atoms)\n",ananame,natoms); if (bFit) fprintf(out,"Fit group is '%s' (%d atoms)\n",fitname,nfit); else fprintf(out,"No fit was used\n"); fprintf(out,"Analysis is %smass weighted\n", bDiffMass2 ? "":"non-"); if (bFit) fprintf(out,"Fit is %smass weighted\n", bDiffMass1 ? "":"non-"); fprintf(out,"Diagonalized the %dx%d covariance matrix\n",(int)ndim,(int)ndim); fprintf(out,"Trace of the covariance matrix before diagonalizing: %g\n", trace); fprintf(out,"Trace of the covariance matrix after diagonalizing: %g\n\n", sum); fprintf(out,"Wrote %d eigenvalues to %s\n",(int)ndim,eigvalfile); if (WriteXref == eWXR_YES) fprintf(out,"Wrote reference structure to %s\n",eigvecfile); fprintf(out,"Wrote average structure to %s and %s\n",averfile,eigvecfile); fprintf(out,"Wrote eigenvectors %d to %d to %s\n",1,end,eigvecfile); ffclose(out); fprintf(stderr,"Wrote the log to %s\n",logfile); thanx(stderr); return 0; }
int gmx_lie(int argc,char *argv[]) { const char *desc[] = { "g_lie computes a free energy estimate based on an energy analysis", "from. One needs an energy file with the following components:", "Coul (A-B) LJ-SR (A-B) etc." }; static real lie_lj=0,lie_qq=0,fac_lj=0.181,fac_qq=0.5; static const char *ligand="none"; t_pargs pa[] = { { "-Elj", FALSE, etREAL, {&lie_lj}, "Lennard-Jones interaction between ligand and solvent" }, { "-Eqq", FALSE, etREAL, {&lie_qq}, "Coulomb interaction between ligand and solvent" }, { "-Clj", FALSE, etREAL, {&fac_lj}, "Factor in the LIE equation for Lennard-Jones component of energy" }, { "-Cqq", FALSE, etREAL, {&fac_qq}, "Factor in the LIE equation for Coulomb component of energy" }, { "-ligand", FALSE, etSTR, {&ligand}, "Name of the ligand in the energy file" } }; #define NPA asize(pa) FILE *out; int nre,nframes=0,ct=0; ener_file_t fp; gmx_bool bCont; t_liedata *ld; gmx_enxnm_t *enm=NULL; t_enxframe *fr; real lie; double lieaver=0,lieav2=0; output_env_t oenv; t_filenm fnm[] = { { efEDR, "-f", "ener", ffREAD }, { efXVG, "-o", "lie", ffWRITE } }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_VIEW | PCA_CAN_TIME | PCA_BE_NICE, NFILE,fnm,NPA,pa,asize(desc),desc,0,NULL,&oenv); fp = open_enx(ftp2fn(efEDR,NFILE,fnm),"r"); do_enxnms(fp,&nre,&enm); ld = analyze_names(nre,enm,ligand); snew(fr,1); out = xvgropen(ftp2fn(efXVG,NFILE,fnm),"LIE free energy estimate", "Time (ps)","DGbind (kJ/mol)",oenv); do { bCont = do_enx(fp,fr); ct = check_times(fr->t); if (ct == 0) { lie = calc_lie(ld,fr->ener,lie_lj,lie_qq,fac_lj,fac_qq); lieaver += lie; lieav2 += lie*lie; nframes ++; fprintf(out,"%10g %10g\n",fr->t,lie); } } while (bCont); close_enx(fp); ffclose(out); fprintf(stderr,"\n"); if (nframes > 0) printf("DGbind = %.3f (%.3f)\n",lieaver/nframes, sqrt(lieav2/nframes-sqr(lieaver/nframes))); do_view(oenv,ftp2fn(efXVG,NFILE,fnm),"-nxy"); thanx(stderr); return 0; }
int gmx_spatial(int argc,char *argv[]) { const char *desc[] = { "g_spatial calculates the spatial distribution function and ", "outputs it in a form that can be read by VMD as Gaussian98 cube format. ", "This was developed from template.c (gromacs-3.3). ", "For a system of 32K atoms and a 50ns trajectory, the SDF can be generated ", "in about 30 minutes, with most of the time dedicated to the two runs through ", "trjconv that are required to center everything properly. ", "This also takes a whole bunch of space (3 copies of the xtc file). ", "Still, the pictures are pretty and very informative when the fitted selection is properly made. ", "3-4 atoms in a widely mobile group like a free amino acid in solution works ", "well, or select the protein backbone in a stable folded structure to get the SDF ", "of solvent and look at the time-averaged solvation shell. ", "It is also possible using this program to generate the SDF based on some arbitrarty ", "Cartesian coordinate. To do that, simply omit the preliminary trjconv steps. \n", "USAGE: \n", "1. Use make_ndx to create a group containing the atoms around which you want the SDF \n", "2. trjconv -s a.tpr -f a.xtc -o b.xtc -center tric -ur compact -pbc none \n", "3. trjconv -s a.tpr -f b.xtc -o c.xtc -fit rot+trans \n", "4. run g_spatial on the xtc output of step #3. \n", "5. Load grid.cube into VMD and view as an isosurface. \n", "*** Systems such as micelles will require trjconv -pbc cluster between steps 1 and 2\n", "WARNINGS: \n", "The SDF will be generated for a cube that contains all bins that have some non-zero occupancy. ", "However, the preparatory -fit rot+trans option to trjconv implies that your system will be rotating ", "and translating in space (in order that the selected group does not). Therefore the values that are ", "returned will only be valid for some region around your central group/coordinate that has full overlap ", "with system volume throughout the entire translated/rotated system over the course of the trajectory. ", "It is up to the user to ensure that this is the case. \n", "BUGS: \n", "When the allocated memory is not large enough, a segmentation fault may occur. This is usually detected ", "and the program is halted prior to the fault while displaying a warning message suggesting the use of the -nab ", "option. However, the program does not detect all such events. If you encounter a segmentation fault, run it again ", "with an increased -nab value. \n", "RISKY OPTIONS: \n", "To reduce the amount of space and time required, you can output only the coords ", "that are going to be used in the first and subsequent run through trjconv. ", "However, be sure to set the -nab option to a sufficiently high value since ", "memory is allocated for cube bins based on the initial coords and the -nab ", "(Number of Additional Bins) option value. \n" }; static gmx_bool bPBC=FALSE; static gmx_bool bSHIFT=FALSE; static int iIGNOREOUTER=-1; /*Positive values may help if the surface is spikey */ static gmx_bool bCUTDOWN=TRUE; static real rBINWIDTH=0.05; /* nm */ static gmx_bool bCALCDIV=TRUE; static int iNAB=4; t_pargs pa[] = { { "-pbc", FALSE, etBOOL, {&bPBC}, "Use periodic boundary conditions for computing distances" }, { "-div", FALSE, etBOOL, {&bCALCDIV}, "Calculate and apply the divisor for bin occupancies based on atoms/minimal cube size. Set as TRUE for visualization and as FALSE (-nodiv) to get accurate counts per frame" }, { "-ign", FALSE, etINT, {&iIGNOREOUTER}, "Do not display this number of outer cubes (positive values may reduce boundary speckles; -1 ensures outer surface is visible)" }, /* { "-cut", bCUTDOWN, etBOOL, {&bCUTDOWN},*/ /* "Display a total cube that is of minimal size" }, */ { "-bin", FALSE, etREAL, {&rBINWIDTH}, "Width of the bins in nm" }, { "-nab", FALSE, etINT, {&iNAB}, "Number of additional bins to ensure proper memory allocation" } }; double MINBIN[3]; double MAXBIN[3]; t_topology top; int ePBC; char title[STRLEN]; t_trxframe fr; rvec *xtop,*shx[26]; matrix box,box_pbc; t_trxstatus *status; int flags = TRX_READ_X; t_pbc pbc; t_atoms *atoms; int natoms; char *grpnm,*grpnmp; atom_id *index,*indexp; int i,nidx,nidxp; int v; int j,k; long ***bin=(long ***)NULL; long nbin[3]; FILE *flp; long x,y,z,minx,miny,minz,maxx,maxy,maxz; long numfr, numcu; long tot,max,min; double norm; output_env_t oenv; gmx_rmpbc_t gpbc=NULL; t_filenm fnm[] = { { efTPS, NULL, NULL, ffREAD }, /* this is for the topology */ { efTRX, "-f", NULL, ffREAD }, /* and this for the trajectory */ { efNDX, NULL, NULL, ffOPTRD } }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); /* This is the routine responsible for adding default options, * calling the X/motif interface, etc. */ parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_CAN_VIEW, NFILE,fnm,asize(pa),pa,asize(desc),desc,0,NULL,&oenv); read_tps_conf(ftp2fn(efTPS,NFILE,fnm),title,&top,&ePBC,&xtop,NULL,box,TRUE); sfree(xtop); atoms=&(top.atoms); printf("Select group to generate SDF:\n"); get_index(atoms,ftp2fn_null(efNDX,NFILE,fnm),1,&nidx,&index,&grpnm); printf("Select group to output coords (e.g. solute):\n"); get_index(atoms,ftp2fn_null(efNDX,NFILE,fnm),1,&nidxp,&indexp,&grpnmp); /* The first time we read data is a little special */ natoms=read_first_frame(oenv,&status,ftp2fn(efTRX,NFILE,fnm),&fr,flags); /* Memory Allocation */ MINBIN[XX]=MAXBIN[XX]=fr.x[0][XX]; MINBIN[YY]=MAXBIN[YY]=fr.x[0][YY]; MINBIN[ZZ]=MAXBIN[ZZ]=fr.x[0][ZZ]; for(i=1; i<top.atoms.nr; ++i) { if(fr.x[i][XX]<MINBIN[XX])MINBIN[XX]=fr.x[i][XX]; if(fr.x[i][XX]>MAXBIN[XX])MAXBIN[XX]=fr.x[i][XX]; if(fr.x[i][YY]<MINBIN[YY])MINBIN[YY]=fr.x[i][YY]; if(fr.x[i][YY]>MAXBIN[YY])MAXBIN[YY]=fr.x[i][YY]; if(fr.x[i][ZZ]<MINBIN[ZZ])MINBIN[ZZ]=fr.x[i][ZZ]; if(fr.x[i][ZZ]>MAXBIN[ZZ])MAXBIN[ZZ]=fr.x[i][ZZ]; } for (i=ZZ; i>=XX; --i){ MAXBIN[i]=(ceil((MAXBIN[i]-MINBIN[i])/rBINWIDTH)+(double)iNAB)*rBINWIDTH+MINBIN[i]; MINBIN[i]-=(double)iNAB*rBINWIDTH; nbin[i]=(long)ceil((MAXBIN[i]-MINBIN[i])/rBINWIDTH); } bin=(long ***)malloc(nbin[XX]*sizeof(long **)); if(!bin)mequit(); for(i=0; i<nbin[XX]; ++i){ bin[i]=(long **)malloc(nbin[YY]*sizeof(long *)); if(!bin[i])mequit(); for(j=0; j<nbin[YY]; ++j){ bin[i][j]=(long *)calloc(nbin[ZZ],sizeof(long)); if(!bin[i][j])mequit(); } } copy_mat(box,box_pbc); numfr=0; minx=miny=minz=999; maxx=maxy=maxz=0; if (bPBC) gpbc = gmx_rmpbc_init(&top.idef,ePBC,natoms,box); /* This is the main loop over frames */ do { /* Must init pbc every step because of pressure coupling */ copy_mat(box,box_pbc); if (bPBC) { gmx_rmpbc_trxfr(gpbc,&fr); set_pbc(&pbc,ePBC,box_pbc); } for(i=0; i<nidx; i++) { if(fr.x[index[i]][XX]<MINBIN[XX]||fr.x[index[i]][XX]>MAXBIN[XX]|| fr.x[index[i]][YY]<MINBIN[YY]||fr.x[index[i]][YY]>MAXBIN[YY]|| fr.x[index[i]][ZZ]<MINBIN[ZZ]||fr.x[index[i]][ZZ]>MAXBIN[ZZ]) { printf("There was an item outside of the allocated memory. Increase the value given with the -nab option.\n"); printf("Memory was allocated for [%f,%f,%f]\tto\t[%f,%f,%f]\n",MINBIN[XX],MINBIN[YY],MINBIN[ZZ],MAXBIN[XX],MAXBIN[YY],MAXBIN[ZZ]); printf("Memory was required for [%f,%f,%f]\n",fr.x[index[i]][XX],fr.x[index[i]][YY],fr.x[index[i]][ZZ]); exit(1); } x=(long)ceil((fr.x[index[i]][XX]-MINBIN[XX])/rBINWIDTH); y=(long)ceil((fr.x[index[i]][YY]-MINBIN[YY])/rBINWIDTH); z=(long)ceil((fr.x[index[i]][ZZ]-MINBIN[ZZ])/rBINWIDTH); ++bin[x][y][z]; if(x<minx)minx=x; if(x>maxx)maxx=x; if(y<miny)miny=y; if(y>maxy)maxy=y; if(z<minz)minz=z; if(z>maxz)maxz=z; } numfr++; /* printf("%f\t%f\t%f\n",box[XX][XX],box[YY][YY],box[ZZ][ZZ]); */ } while(read_next_frame(oenv,status,&fr)); if (bPBC) gmx_rmpbc_done(gpbc); if(!bCUTDOWN){ minx=miny=minz=0; maxx=nbin[XX]; maxy=nbin[YY]; maxz=nbin[ZZ]; } /* OUTPUT */ flp=ffopen("grid.cube","w"); fprintf(flp,"Spatial Distribution Function\n"); fprintf(flp,"test\n"); fprintf(flp,"%5d%12.6f%12.6f%12.6f\n",nidxp,(MINBIN[XX]+(minx+iIGNOREOUTER)*rBINWIDTH)*10./bohr,(MINBIN[YY]+(miny+iIGNOREOUTER)*rBINWIDTH)*10./bohr,(MINBIN[ZZ]+(minz+iIGNOREOUTER)*rBINWIDTH)*10./bohr); fprintf(flp,"%5ld%12.6f%12.6f%12.6f\n",maxx-minx+1-(2*iIGNOREOUTER),rBINWIDTH*10./bohr,0.,0.); fprintf(flp,"%5ld%12.6f%12.6f%12.6f\n",maxy-miny+1-(2*iIGNOREOUTER),0.,rBINWIDTH*10./bohr,0.); fprintf(flp,"%5ld%12.6f%12.6f%12.6f\n",maxz-minz+1-(2*iIGNOREOUTER),0.,0.,rBINWIDTH*10./bohr); for(i=0; i<nidxp; i++){ v=2; if(*(top.atoms.atomname[indexp[i]][0])=='C')v=6; if(*(top.atoms.atomname[indexp[i]][0])=='N')v=7; if(*(top.atoms.atomname[indexp[i]][0])=='O')v=8; if(*(top.atoms.atomname[indexp[i]][0])=='H')v=1; if(*(top.atoms.atomname[indexp[i]][0])=='S')v=16; fprintf(flp,"%5d%12.6f%12.6f%12.6f%12.6f\n",v,0.,(double)fr.x[indexp[i]][XX]*10./bohr,(double)fr.x[indexp[i]][YY]*10./bohr,(double)fr.x[indexp[i]][ZZ]*10./bohr); } tot=0; for(k=0;k<nbin[XX];k++) { if(!(k<minx||k>maxx))continue; for(j=0;j<nbin[YY];j++) { if(!(j<miny||j>maxy))continue; for(i=0;i<nbin[ZZ];i++) { if(!(i<minz||i>maxz))continue; if(bin[k][j][i]!=0){ printf("A bin was not empty when it should have been empty. Programming error.\n"); printf("bin[%d][%d][%d] was = %ld\n",k,j,i,bin[k][j][i]); exit(1); } } } } min=999; max=0; for(k=0;k<nbin[XX];k++) { if(k<minx+iIGNOREOUTER||k>maxx-iIGNOREOUTER)continue; for(j=0;j<nbin[YY];j++) { if(j<miny+iIGNOREOUTER||j>maxy-iIGNOREOUTER)continue; for(i=0;i<nbin[ZZ];i++) { if(i<minz+iIGNOREOUTER||i>maxz-iIGNOREOUTER)continue; tot+=bin[k][j][i]; if(bin[k][j][i]>max)max=bin[k][j][i]; if(bin[k][j][i]<min)min=bin[k][j][i]; } } } numcu=(maxx-minx+1-(2*iIGNOREOUTER))*(maxy-miny+1-(2*iIGNOREOUTER))*(maxz-minz+1-(2*iIGNOREOUTER)); if(bCALCDIV){ norm=((double)numcu*(double)numfr) / (double)tot; }else{ norm=1.0; } for(k=0;k<nbin[XX];k++) { if(k<minx+iIGNOREOUTER||k>maxx-iIGNOREOUTER)continue; for(j=0;j<nbin[YY];j++) { if(j<miny+iIGNOREOUTER||j>maxy-iIGNOREOUTER)continue; for(i=0;i<nbin[ZZ];i++) { if(i<minz+iIGNOREOUTER||i>maxz-iIGNOREOUTER)continue; fprintf(flp,"%12.6f ",norm*(double)bin[k][j][i]/(double)numfr); } fprintf(flp,"\n"); } fprintf(flp,"\n"); } ffclose(flp); /* printf("x=%d to %d\n",minx,maxx); */ /* printf("y=%d to %d\n",miny,maxy); */ /* printf("z=%d to %d\n",minz,maxz); */ if(bCALCDIV){ printf("Counts per frame in all %ld cubes divided by %le\n",numcu,1.0/norm); printf("Normalized data: average %le, min %le, max %le\n",1.0,norm*(double)min/(double)numfr,norm*(double)max/(double)numfr); }else{ printf("grid.cube contains counts per frame in all %ld cubes\n",numcu); printf("Raw data: average %le, min %le, max %le\n",1.0/norm,(double)min/(double)numfr,(double)max/(double)numfr); } thanx(stderr); return 0; }