static void shell_comm(const char *title, const char *script, int nsleep) { FILE *tfil; char command[STRLEN]; char tmp[32]; strcpy(tmp, "dialogXXXXXX"); gmx_tmpnam(tmp); if ((tfil = fopen(tmp, "w")) == NULL) { sprintf(tmp, "%ctmp%cdialogXXXXXX", DIR_SEPARATOR, DIR_SEPARATOR); gmx_tmpnam(tmp); } else { fclose(tfil); } if ((tfil = fopen(tmp, "w")) == NULL) { gmx_fatal(FARGS, "Can not open tmp file %s", tmp); } fprintf(tfil, "%s\n", script); fprintf(tfil, "sleep %d\n", nsleep); fclose(tfil); sprintf(command, "xterm -title %s -e sh %s", title, tmp); #ifdef DEBUG fprintf(stderr, "command: %s\n", command); #endif #ifdef GMX_NO_SYSTEM printf("Warning-- No calls to system(3) supported on this platform."); printf("Warning-- Skipping execution of 'system(\"%s\")'.", buf); #else if (0 != system(command)) { gmx_fatal(FARGS, "Failed to execute command: %s", command); } #endif #ifdef DEBUG unlink(tmp) #endif }
static void shell_comm(const char *title, const char *script, int nsleep) { FILE *tfil; char command[STRLEN]; char tmp[32]; strcpy(tmp, "dialogXXXXXX"); gmx_tmpnam(tmp); if ((tfil = fopen(tmp, "w")) == NULL) { sprintf(tmp, "%ctmp%cdialogXXXXXX", DIR_SEPARATOR, DIR_SEPARATOR); gmx_tmpnam(tmp); } else { fclose(tfil); } if ((tfil = fopen(tmp, "w")) == NULL) { gmx_fatal(FARGS, "Can not open tmp file %s", tmp); } fprintf(tfil, "%s\n", script); fprintf(tfil, "sleep %d\n", nsleep); fclose(tfil); sprintf(command, "xterm -title %s -e sh %s", title, tmp); #ifdef DEBUG fprintf(stderr, "command: %s\n", command); #endif if (0 != system(command)) { gmx_fatal(FARGS, "Failed to execute command: %s", command); } #ifdef DEBUG unlink(tmp) #endif }
t_dlg *select_filter(t_x11 *x11, t_gmx *gmx) { static const char *title = "Group"; static const char *dummy = "\"FALSE\""; static const char *ok = "\"Ok\""; FILE *tmp; t_dlg *dlg; char tmpfile[STRLEN]; int i, j, k, len, tlen, ht, ncol, nrow, x0; len = strlen(title); for (i = 0; (i < (int)gmx->filter->grps->nr); i++) { len = std::max(len, (int)strlen(gmx->filter->grpnames[i])); } len += 2; ncol = 1+(gmx->filter->grps->nr / 15); nrow = gmx->filter->grps->nr/ncol; if (nrow*ncol < gmx->filter->grps->nr) { nrow++; } if (ncol > 1) { ht = 1+(nrow+1)*2+3; } else { ht = 1+(gmx->filter->grps->nr+1)*2+3; } strcpy(tmpfile, "filterXXXXXX"); gmx_tmpnam(tmpfile); #ifdef DEBUG fprintf(stderr, "file: %s\n", tmpfile); #endif if ((tmp = fopen(tmpfile, "w")) == NULL) { sprintf(tmpfile, "%ctmp%cfilterXXXXXX", DIR_SEPARATOR, DIR_SEPARATOR); gmx_tmpnam(tmpfile); if ((tmp = fopen(tmpfile, "w")) == NULL) { gmx_fatal(FARGS, "Can not open tmp file %s", tmpfile); } } tlen = 1+ncol*(1+len); fprintf(tmp, "grid %d %d {\n\n", tlen, ht); for (k = j = 0, x0 = 1; (j < ncol); j++, x0 += len+1) { fprintf(tmp, "group \"%s-%d\" %d 1 %d %d {\n", title, j+1, x0, len, ht-5); for (i = 0; (i < nrow) && (k < gmx->filter->grps->nr); i++, k++) { if (!gmx->filter->bDisable[k]) { fprintf(tmp, "checkbox \"%s\" \"%d\" %s %s %s\n", gmx->filter->grpnames[k], k, dummy, dummy, dummy); } else { fprintf(tmp, "statictext { \" %s\" } \"%d\" %s %s %s\n", gmx->filter->grpnames[k], k, dummy, dummy, dummy); } } fprintf(tmp, "}\n\n"); } fprintf(tmp, "simple 1 %d %d 2 {\n", ht-3, tlen-2); fprintf(tmp, "defbutton %s %s %s %s %s\n", ok, ok, dummy, dummy, dummy); fprintf(tmp, "}\n\n}\n"); fclose(tmp); dlg = ReadDlg(x11, gmx->wd->self, title, tmpfile, 0, 0, true, false, FilterCB, gmx); remove(tmpfile); return dlg; }
int main(int argc,char *argv[]) { const char *desc[] = { "[TT]do_multiprot[tt] ", "reads a trajectory file and aligns it to a reference structure ", "each time frame", "calling the multiprot program. This allows you to use a reference", "structure whose sequence is different than that of the protein in the ", "trajectory, since the alignment is based on the geometry, not sequence.", "The output of [TT]do_multiprot[tt] includes the rmsd and the number of residues", "on which it was calculated.", "[PAR]", "An aligned trajectory file is generated with the [TT]-ox[tt] option.[PAR]", "With the [TT]-cr[tt] option, the number of hits in the alignment is given", "per residue. This number can be between 0 and the number of frames, and", "indicates the structural conservation of this residue.[PAR]", "If you do not have the [TT]multiprot[tt] program, get it. [TT]do_multiprot[tt] assumes", "that the [TT]multiprot[tt] executable is [TT]/usr/local/bin/multiprot[tt]. If this is ", "not the case, then you should set an environment variable [BB]MULTIPROT[bb]", "pointing to the [TT]multiprot[tt] executable, e.g.: [PAR]", "[TT]setenv MULTIPROT /usr/MultiProtInstall/multiprot.Linux[tt][PAR]", "Note that at the current implementation only binary alignment (your", "molecule to a reference) is supported. In addition, note that the ", "by default [TT]multiprot[tt] aligns the two proteins on their C-alpha carbons.", "and that this depends on the [TT]multiprot[tt] parameters which are not dealt ", "with here. Thus, the C-alpha carbons is expected to give the same " "results as choosing the whole protein and will be slightly faster.[PAR]", "For information about [TT]multiprot[tt], see:", "http://bioinfo3d.cs.tau.ac.il/MultiProt/.[PAR]" }; static bool bVerbose; t_pargs pa[] = { { "-v", FALSE, etBOOL, {&bVerbose}, "HIDDENGenerate miles of useless information" } }; const char *bugs[] = { "The program is very slow, since multiprot is run externally" }; t_trxstatus *status; t_trxstatus *trxout=NULL; FILE *tapein,*fo,*frc,*tmpf,*out=NULL,*fres=NULL; const char *fnRef; const char *fn="2_sol.res"; t_topology top; int ePBC; t_atoms *atoms,ratoms,useatoms; t_trxframe fr; t_pdbinfo p; int nres,nres2,nr0; real t; int i,j,natoms,nratoms,nframe=0,model_nr=-1; int cur_res,prev_res; int nout; t_countres *countres=NULL; matrix box,rbox; int gnx; char *grpnm,*ss_str; atom_id *index; rvec *xp,*x,*xr; char pdbfile[32],refpdb[256],title[256],rtitle[256],filemode[5]; char out_title[256]; char multiprot[256],*mptr; int ftp; int outftp=-1; real rmsd; bool bTrjout,bCountres; const char *TrjoutFile=NULL; output_env_t oenv; static rvec translation={0,0,0},rotangles={0,0,0}; gmx_rmpbc_t gpbc=NULL; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPS, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffOPTRD }, { efSTX, "-r", NULL , ffREAD }, { efXVG, "-o", "rmss", ffWRITE }, { efXVG, "-rc", "rescount", ffWRITE}, { efXVG, "-cr", "countres", ffOPTWR}, { efTRX, "-ox", "aligned", ffOPTWR } }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_CAN_VIEW | PCA_TIME_UNIT, NFILE,fnm, asize(pa),pa, asize(desc),desc, asize(bugs),bugs,&oenv ); fnRef=opt2fn("-r",NFILE,fnm); bTrjout = opt2bSet("-ox",NFILE,fnm); bCountres= opt2bSet("-cr",NFILE,fnm); if (bTrjout) { TrjoutFile = opt2fn_null("-ox",NFILE,fnm); } read_tps_conf(ftp2fn(efTPS,NFILE,fnm),title,&top,&ePBC,&xp,NULL,box,FALSE); gpbc = gmx_rmpbc_init(&top.idef,ePBC,top.atoms.nr,box); atoms=&(top.atoms); ftp=fn2ftp(fnRef); get_stx_coordnum(fnRef,&nratoms); init_t_atoms(&ratoms,nratoms,TRUE); snew(xr,nratoms); read_stx_conf(fnRef,rtitle,&ratoms,xr,NULL,&ePBC,rbox); if (bVerbose) { fprintf(stderr,"Read %d atoms\n",atoms->nr); fprintf(stderr,"Read %d reference atoms\n",ratoms.nr); } if (bCountres) { snew(countres,ratoms.nres); j=0; cur_res=0; for (i=0;i<ratoms.nr;i++) { prev_res=cur_res; cur_res=ratoms.atom[i].resind; if (cur_res != prev_res) { countres[j].resnr=cur_res; countres[j].count=0; j++; } } } get_index(atoms,ftp2fn_null(efNDX,NFILE,fnm),1,&gnx,&index,&grpnm); nres=0; nr0=-1; for(i=0; (i<gnx); i++) { if (atoms->atom[index[i]].resind != nr0) { nr0=atoms->atom[index[i]].resind; nres++; } } fprintf(stderr,"There are %d residues in your selected group\n",nres); strcpy(pdbfile,"ddXXXXXX"); gmx_tmpnam(pdbfile); if ((tmpf = fopen(pdbfile,"w")) == NULL) { sprintf(pdbfile,"%ctmp%cfilterXXXXXX",DIR_SEPARATOR,DIR_SEPARATOR); gmx_tmpnam(pdbfile); if ((tmpf = fopen(pdbfile,"w")) == NULL) { gmx_fatal(FARGS,"Can not open tmp file %s",pdbfile); } } else { gmx_ffclose(tmpf); } if (ftp != efPDB) { strcpy(refpdb,"ddXXXXXX"); gmx_tmpnam(refpdb); strcat(refpdb,".pdb"); write_sto_conf(refpdb,rtitle,&ratoms,xr,NULL,ePBC,rbox); } else { strcpy(refpdb,fnRef); } if ((mptr=getenv("MULTIPROT")) == NULL) { mptr="/usr/local/bin/multiprot"; } if (!gmx_fexist(mptr)) { gmx_fatal(FARGS,"MULTIPROT executable (%s) does not exist (use setenv MULTIPROT)", mptr); } sprintf (multiprot,"%s %s %s > /dev/null %s", mptr, refpdb, pdbfile, "2> /dev/null"); if (bVerbose) fprintf(stderr,"multiprot cmd='%s'\n",multiprot); if (!read_first_frame(oenv,&status,ftp2fn(efTRX,NFILE,fnm),&fr,TRX_READ_X)) gmx_fatal(FARGS,"Could not read a frame from %s",ftp2fn(efTRX,NFILE,fnm)); natoms = fr.natoms; if (bTrjout) { nout=natoms; /* open file now */ outftp=fn2ftp(TrjoutFile); if (bVerbose) fprintf(stderr,"Will write %s: %s\n",ftp2ext(ftp),ftp2desc(outftp)); strcpy(filemode,"w"); switch (outftp) { case efXTC: case efG87: case efTRR: case efTRJ: out=NULL; trxout = open_trx(TrjoutFile,filemode); break; case efGRO: case efG96: case efPDB: /* Make atoms struct for output in GRO or PDB files */ /* get memory for stuff to go in pdb file */ init_t_atoms(&useatoms,nout,FALSE); sfree(useatoms.resinfo); useatoms.resinfo=atoms->resinfo; for(i=0;(i<nout);i++) { useatoms.atomname[i]=atoms->atomname[i]; useatoms.atom[i]=atoms->atom[i]; useatoms.nres=max(useatoms.nres,useatoms.atom[i].resind+1); } useatoms.nr=nout; out=gmx_ffopen(TrjoutFile,filemode); break; } } if (natoms > atoms->nr) { gmx_fatal(FARGS,"\nTrajectory does not match topology!"); } if (gnx > natoms) { gmx_fatal(FARGS,"\nTrajectory does not match selected group!"); } fo = xvgropen(opt2fn("-o",NFILE,fnm),"RMSD","Time (ps)","RMSD (nm)",oenv); frc = xvgropen(opt2fn("-rc",NFILE,fnm),"Number of Residues in the alignment","Time (ps)","Residues",oenv); do { t = output_env_conv_time(oenv,fr.time); gmx_rmpbc(gpbc,natoms,fr.box,fr.x); tapein=gmx_ffopen(pdbfile,"w"); write_pdbfile_indexed(tapein,NULL,atoms,fr.x,ePBC,fr.box,' ',-1,gnx,index,NULL,TRUE); gmx_ffclose(tapein); system(multiprot); remove(pdbfile); process_multiprot_output(fn, &rmsd, &nres2,rotangles,translation,bCountres,countres); fprintf(fo,"%12.7f",t); fprintf(fo," %12.7f\n",rmsd); fprintf(frc,"%12.7f",t); fprintf(frc,"%12d\n",nres2); if (bTrjout) { rotate_conf(natoms,fr.x,NULL,rotangles[XX],rotangles[YY],rotangles[ZZ]); for(i=0; i<natoms; i++) { rvec_inc(fr.x[i],translation); } switch(outftp) { case efTRJ: case efTRR: case efG87: case efXTC: write_trxframe(trxout,&fr,NULL); break; case efGRO: case efG96: case efPDB: sprintf(out_title,"Generated by do_multiprot : %s t= %g %s", title,output_env_conv_time(oenv,fr.time),output_env_get_time_unit(oenv)); switch(outftp) { case efGRO: write_hconf_p(out,out_title,&useatoms,prec2ndec(fr.prec), fr.x,NULL,fr.box); break; case efPDB: fprintf(out,"REMARK GENERATED BY DO_MULTIPROT\n"); sprintf(out_title,"%s t= %g %s",title,output_env_conv_time(oenv,fr.time),output_env_get_time_unit(oenv)); /* if reading from pdb, we want to keep the original model numbering else we write the output frame number plus one, because model 0 is not allowed in pdb */ if (ftp==efPDB && fr.step > model_nr) { model_nr = fr.step; } else { model_nr++; } write_pdbfile(out,out_title,&useatoms,fr.x,ePBC,fr.box,' ',model_nr,NULL,TRUE); break; case efG96: fr.title = out_title; fr.bTitle = (nframe == 0); fr.bAtoms = FALSE; fr.bStep = TRUE; fr.bTime = TRUE; write_g96_conf(out,&fr,-1,NULL); } break; } } nframe++; } while(read_next_frame(oenv,status,&fr)); if (bCountres) { fres= xvgropen(opt2fn("-cr",NFILE,fnm),"Number of frames in which the residues are aligned to","Residue","Number",oenv); for (i=0;i<ratoms.nres;i++) { fprintf(fres,"%10d %12d\n",countres[i].resnr,countres[i].count); } gmx_ffclose(fres); } gmx_ffclose(fo); gmx_ffclose(frc); fprintf(stderr,"\n"); close_trj(status); if (trxout != NULL) { close_trx(trxout); } else if (out != NULL) { gmx_ffclose(out); } view_all(oenv,NFILE, fnm); sfree(xr); if (bCountres) { sfree(countres); } free_t_atoms(&ratoms,TRUE); if (bTrjout) { if (outftp==efPDB || outftp==efGRO || outftp==efG96) { free_t_atoms(&useatoms,TRUE); } } gmx_thanx(stderr); return 0; }
int gmx_do_dssp(int argc, char *argv[]) { const char *desc[] = { "[THISMODULE] ", "reads a trajectory file and computes the secondary structure for", "each time frame ", "calling the dssp program. If you do not have the dssp program,", "get it from http://swift.cmbi.ru.nl/gv/dssp. [THISMODULE] assumes ", "that the dssp executable is located in ", "[TT]/usr/local/bin/dssp[tt]. If this is not the case, then you should", "set an environment variable [TT]DSSP[tt] pointing to the dssp", "executable, e.g.: [PAR]", "[TT]setenv DSSP /opt/dssp/bin/dssp[tt][PAR]", "Since version 2.0.0, dssp is invoked with a syntax that differs", "from earlier versions. If you have an older version of dssp,", "use the [TT]-ver[tt] option to direct do_dssp to use the older syntax.", "By default, do_dssp uses the syntax introduced with version 2.0.0.", "Even newer versions (which at the time of writing are not yet released)", "are assumed to have the same syntax as 2.0.0.[PAR]", "The structure assignment for each residue and time is written to an", "[TT].xpm[tt] matrix file. This file can be visualized with for instance", "[TT]xv[tt] and can be converted to postscript with [TT]xpm2ps[tt].", "Individual chains are separated by light grey lines in the [TT].xpm[tt] and", "postscript files.", "The number of residues with each secondary structure type and the", "total secondary structure ([TT]-sss[tt]) count as a function of", "time are also written to file ([TT]-sc[tt]).[PAR]", "Solvent accessible surface (SAS) per residue can be calculated, both in", "absolute values (A^2) and in fractions of the maximal accessible", "surface of a residue. The maximal accessible surface is defined as", "the accessible surface of a residue in a chain of glycines.", "[BB]Note[bb] that the program [gmx-sas] can also compute SAS", "and that is more efficient.[PAR]", "Finally, this program can dump the secondary structure in a special file", "[TT]ssdump.dat[tt] for usage in the program [gmx-chi]. Together", "these two programs can be used to analyze dihedral properties as a", "function of secondary structure type." }; static gmx_bool bVerbose; static const char *ss_string = "HEBT"; static int dsspVersion = 2; t_pargs pa[] = { { "-v", FALSE, etBOOL, {&bVerbose}, "HIDDENGenerate miles of useless information" }, { "-sss", FALSE, etSTR, {&ss_string}, "Secondary structures for structure count"}, { "-ver", FALSE, etINT, {&dsspVersion}, "DSSP major version. Syntax changed with version 2"} }; t_trxstatus *status; FILE *tapein; FILE *ss, *acc, *fTArea, *tmpf; const char *fnSCount, *fnArea, *fnTArea, *fnAArea; const char *leg[] = { "Phobic", "Phylic" }; t_topology top; int ePBC; t_atoms *atoms; t_matrix mat; int nres, nr0, naccr, nres_plus_separators; gmx_bool *bPhbres, bDoAccSurf; real t; int i, j, natoms, nframe = 0; matrix box = {{0}}; int gnx; char *grpnm, *ss_str; atom_id *index; rvec *xp, *x; int *average_area; real **accr, *accr_ptr = NULL, *av_area, *norm_av_area; char pdbfile[32], tmpfile[32], title[256]; char dssp[256]; const char *dptr; output_env_t oenv; gmx_rmpbc_t gpbc = NULL; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPS, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffOPTRD }, { efDAT, "-ssdump", "ssdump", ffOPTWR }, { efMAP, "-map", "ss", ffLIBRD }, { efXPM, "-o", "ss", ffWRITE }, { efXVG, "-sc", "scount", ffWRITE }, { efXPM, "-a", "area", ffOPTWR }, { efXVG, "-ta", "totarea", ffOPTWR }, { efXVG, "-aa", "averarea", ffOPTWR } }; #define NFILE asize(fnm) if (!parse_common_args(&argc, argv, PCA_CAN_TIME | PCA_CAN_VIEW | PCA_TIME_UNIT, NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL, &oenv)) { return 0; } fnSCount = opt2fn("-sc", NFILE, fnm); fnArea = opt2fn_null("-a", NFILE, fnm); fnTArea = opt2fn_null("-ta", NFILE, fnm); fnAArea = opt2fn_null("-aa", NFILE, fnm); bDoAccSurf = (fnArea || fnTArea || fnAArea); read_tps_conf(ftp2fn(efTPS, NFILE, fnm), title, &top, &ePBC, &xp, NULL, box, FALSE); atoms = &(top.atoms); check_oo(atoms); bPhbres = bPhobics(atoms); get_index(atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &gnx, &index, &grpnm); nres = 0; nr0 = -1; for (i = 0; (i < gnx); i++) { if (atoms->atom[index[i]].resind != nr0) { nr0 = atoms->atom[index[i]].resind; nres++; } } fprintf(stderr, "There are %d residues in your selected group\n", nres); strcpy(pdbfile, "ddXXXXXX"); gmx_tmpnam(pdbfile); if ((tmpf = fopen(pdbfile, "w")) == NULL) { sprintf(pdbfile, "%ctmp%cfilterXXXXXX", DIR_SEPARATOR, DIR_SEPARATOR); gmx_tmpnam(pdbfile); if ((tmpf = fopen(pdbfile, "w")) == NULL) { gmx_fatal(FARGS, "Can not open tmp file %s", pdbfile); } } else { fclose(tmpf); } strcpy(tmpfile, "ddXXXXXX"); gmx_tmpnam(tmpfile); if ((tmpf = fopen(tmpfile, "w")) == NULL) { sprintf(tmpfile, "%ctmp%cfilterXXXXXX", DIR_SEPARATOR, DIR_SEPARATOR); gmx_tmpnam(tmpfile); if ((tmpf = fopen(tmpfile, "w")) == NULL) { gmx_fatal(FARGS, "Can not open tmp file %s", tmpfile); } } else { fclose(tmpf); } if ((dptr = getenv("DSSP")) == NULL) { dptr = "/usr/local/bin/dssp"; } if (!gmx_fexist(dptr)) { gmx_fatal(FARGS, "DSSP executable (%s) does not exist (use setenv DSSP)", dptr); } if (dsspVersion >= 2) { if (dsspVersion > 2) { printf("\nWARNING: You use DSSP version %d, which is not explicitly\nsupported by do_dssp. Assuming version 2 syntax.\n\n", dsspVersion); } sprintf(dssp, "%s -i %s -o %s > /dev/null %s", dptr, pdbfile, tmpfile, bVerbose ? "" : "2> /dev/null"); } else { sprintf(dssp, "%s %s %s %s > /dev/null %s", dptr, bDoAccSurf ? "" : "-na", pdbfile, tmpfile, bVerbose ? "" : "2> /dev/null"); } fprintf(stderr, "dssp cmd='%s'\n", dssp); if (fnTArea) { fTArea = xvgropen(fnTArea, "Solvent Accessible Surface Area", output_env_get_xvgr_tlabel(oenv), "Area (nm\\S2\\N)", oenv); xvgr_legend(fTArea, 2, leg, oenv); } else { fTArea = NULL; } mat.map = NULL; mat.nmap = readcmap(opt2fn("-map", NFILE, fnm), &(mat.map)); natoms = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box); if (natoms > atoms->nr) { gmx_fatal(FARGS, "\nTrajectory does not match topology!"); } if (gnx > natoms) { gmx_fatal(FARGS, "\nTrajectory does not match selected group!"); } snew(average_area, atoms->nres); snew(av_area, atoms->nres); snew(norm_av_area, atoms->nres); accr = NULL; naccr = 0; gpbc = gmx_rmpbc_init(&top.idef, ePBC, natoms); do { t = output_env_conv_time(oenv, t); if (bDoAccSurf && nframe >= naccr) { naccr += 10; srenew(accr, naccr); for (i = naccr-10; i < naccr; i++) { snew(accr[i], 2*atoms->nres-1); } } gmx_rmpbc(gpbc, natoms, box, x); tapein = gmx_ffopen(pdbfile, "w"); write_pdbfile_indexed(tapein, NULL, atoms, x, ePBC, box, ' ', -1, gnx, index, NULL, TRUE); gmx_ffclose(tapein); if (0 != system(dssp)) { gmx_fatal(FARGS, "Failed to execute command: %s\n", "Try specifying your dssp version with the -ver option.", dssp); } /* strip_dssp returns the number of lines found in the dssp file, i.e. * the number of residues plus the separator lines */ if (bDoAccSurf) { accr_ptr = accr[nframe]; } nres_plus_separators = strip_dssp(tmpfile, nres, bPhbres, t, accr_ptr, fTArea, &mat, average_area, oenv); remove(tmpfile); remove(pdbfile); nframe++; } while (read_next_x(oenv, status, &t, x, box)); fprintf(stderr, "\n"); close_trj(status); if (fTArea) { xvgrclose(fTArea); } gmx_rmpbc_done(gpbc); prune_ss_legend(&mat); ss = opt2FILE("-o", NFILE, fnm, "w"); mat.flags = 0; write_xpm_m(ss, mat); gmx_ffclose(ss); if (opt2bSet("-ssdump", NFILE, fnm)) { ss = opt2FILE("-ssdump", NFILE, fnm, "w"); snew(ss_str, nres+1); fprintf(ss, "%d\n", nres); for (j = 0; j < mat.nx; j++) { for (i = 0; (i < mat.ny); i++) { ss_str[i] = mat.map[mat.matrix[j][i]].code.c1; } ss_str[i] = '\0'; fprintf(ss, "%s\n", ss_str); } gmx_ffclose(ss); sfree(ss_str); } analyse_ss(fnSCount, &mat, ss_string, oenv); if (bDoAccSurf) { write_sas_mat(fnArea, accr, nframe, nres_plus_separators, &mat); for (i = 0; i < atoms->nres; i++) { av_area[i] = (average_area[i] / (real)nframe); } norm_acc(atoms, nres, av_area, norm_av_area); if (fnAArea) { acc = xvgropen(fnAArea, "Average Accessible Area", "Residue", "A\\S2", oenv); for (i = 0; (i < nres); i++) { fprintf(acc, "%5d %10g %10g\n", i+1, av_area[i], norm_av_area[i]); } xvgrclose(acc); } } view_all(oenv, NFILE, fnm); return 0; }
int main(int argc,char *argv[]) { static char *desc[] = { "do_dssp ", "reads a trajectory file and computes the secondary structure for", "each time frame ", "calling the dssp program. If you do not have the dssp program,", "get it. do_dssp assumes that the dssp executable is", "/usr/local/bin/dssp. If this is not the case, then you should", "set an environment variable [BB]DSSP[bb] pointing to the dssp", "executable, e.g.: [PAR]", "[TT]setenv DSSP /opt/dssp/bin/dssp[tt][PAR]", "The structure assignment for each residue and time is written to an", "[TT].xpm[tt] matrix file. This file can be visualized with for instance", "[TT]xv[tt] and can be converted to postscript with [TT]xpm2ps[tt].", "The number of residues with each secondary structure type and the", "total secondary structure ([TT]-sss[tt]) count as a function of", "time are also written to file ([TT]-sc[tt]).[PAR]", "Solvent accessible surface (SAS) per residue can be calculated, both in", "absolute values (A^2) and in fractions of the maximal accessible", "surface of a residue. The maximal accessible surface is defined as", "the accessible surface of a residue in a chain of glycines.", "[BB]Note[bb] that the program [TT]g_sas[tt] can also compute SAS", "and that is more efficient.[PAR]", "Finally, this program can dump the secondary structure in a special file", "[TT]ssdump.dat[tt] for usage in the program [TT]g_chi[tt]. Together", "these two programs can be used to analyze dihedral properties as a", "function of secondary structure type." }; static bool bVerbose; static char *ss_string="HEBT"; t_pargs pa[] = { { "-v", FALSE, etBOOL, {&bVerbose}, "HIDDENGenerate miles of useless information" }, { "-sss", FALSE, etSTR, {&ss_string}, "Secondary structures for structure count"} }; int status; FILE *tapein; FILE *ss,*acc,*fTArea,*tmpf; char *fnSCount,*fnArea,*fnTArea,*fnAArea; char *leg[] = { "Phobic", "Phylic" }; t_topology top; int ePBC; t_atoms *atoms; t_matrix mat; int nres,nr0,naccr; bool *bPhbres,bDoAccSurf; real t; int i,j,natoms,nframe=0; matrix box; int gnx; char *grpnm,*ss_str; atom_id *index; rvec *xp,*x; int *average_area; real **accr,*av_area, *norm_av_area; char pdbfile[32],tmpfile[32],title[256]; char dssp[256],*dptr; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPS, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffOPTRD }, { efDAT, "-ssdump", "ssdump", ffOPTWR }, { efMAP, "-map", "ss", ffLIBRD }, { efXPM, "-o", "ss", ffWRITE }, { efXVG, "-sc", "scount", ffWRITE }, { efXPM, "-a", "area", ffOPTWR }, { efXVG, "-ta", "totarea", ffOPTWR }, { efXVG, "-aa", "averarea",ffOPTWR } }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_CAN_VIEW | PCA_TIME_UNIT | PCA_BE_NICE , NFILE,fnm, asize(pa),pa, asize(desc),desc,0,NULL); fnSCount= opt2fn("-sc",NFILE,fnm); fnArea = opt2fn_null("-a", NFILE,fnm); fnTArea = opt2fn_null("-ta",NFILE,fnm); fnAArea = opt2fn_null("-aa",NFILE,fnm); bDoAccSurf=(fnArea || fnTArea || fnAArea); read_tps_conf(ftp2fn(efTPS,NFILE,fnm),title,&top,&ePBC,&xp,NULL,box,FALSE); atoms=&(top.atoms); check_oo(atoms); bPhbres=bPhobics(atoms); get_index(atoms,ftp2fn_null(efNDX,NFILE,fnm),1,&gnx,&index,&grpnm); nres=0; nr0=-1; for(i=0; (i<gnx); i++) { if (atoms->atom[index[i]].resnr != nr0) { nr0=atoms->atom[index[i]].resnr; nres++; } } fprintf(stderr,"There are %d residues in your selected group\n",nres); strcpy(pdbfile,"ddXXXXXX"); gmx_tmpnam(pdbfile); if ((tmpf = fopen(pdbfile,"w")) == NULL) { sprintf(pdbfile,"%ctmp%cfilterXXXXXX",DIR_SEPARATOR,DIR_SEPARATOR); gmx_tmpnam(pdbfile); if ((tmpf = fopen(pdbfile,"w")) == NULL) gmx_fatal(FARGS,"Can not open tmp file %s",pdbfile); } else fclose(tmpf); strcpy(tmpfile,"ddXXXXXX"); gmx_tmpnam(tmpfile); if ((tmpf = fopen(tmpfile,"w")) == NULL) { sprintf(tmpfile,"%ctmp%cfilterXXXXXX",DIR_SEPARATOR,DIR_SEPARATOR); gmx_tmpnam(tmpfile); if ((tmpf = fopen(tmpfile,"w")) == NULL) gmx_fatal(FARGS,"Can not open tmp file %s",tmpfile); } else fclose(tmpf); if ((dptr=getenv("DSSP")) == NULL) dptr="/usr/local/bin/dssp"; if (!fexist(dptr)) gmx_fatal(FARGS,"DSSP executable (%s) does not exist (use setenv DSSP)", dptr); sprintf(dssp,"%s %s %s %s > /dev/null %s", dptr,bDoAccSurf?"":"-na",pdbfile,tmpfile,bVerbose?"":"2> /dev/null"); if (bVerbose) fprintf(stderr,"dssp cmd='%s'\n",dssp); if (fnTArea) { fTArea=xvgropen(fnTArea,"Solvent Accessible Surface Area", xvgr_tlabel(),"Area (nm\\S2\\N)"); xvgr_legend(fTArea,2,leg); } else fTArea=NULL; mat.map=NULL; mat.nmap=getcmap(libopen(opt2fn("-map",NFILE,fnm)), opt2fn("-map",NFILE,fnm),&(mat.map)); natoms=read_first_x(&status,ftp2fn(efTRX,NFILE,fnm),&t,&x,box); if (natoms > atoms->nr) gmx_fatal(FARGS,"\nTrajectory does not match topology!"); if (gnx > natoms) gmx_fatal(FARGS,"\nTrajectory does not match selected group!"); snew(average_area,atoms->nres+10); snew(av_area,atoms->nres+10); snew(norm_av_area,atoms->nres+10); accr=NULL; naccr=0; do { t = convert_time(t); if (nframe>=naccr) { naccr+=10; srenew(accr,naccr); for(i=naccr-10; i<naccr; i++) snew(accr[i],atoms->nres+10); } rm_pbc(&(top.idef),ePBC,natoms,box,x,x); tapein=ffopen(pdbfile,"w"); write_pdbfile_indexed(tapein,NULL,atoms,x,ePBC,box,0,-1,gnx,index); fclose(tapein); #ifdef GMX_NO_SYSTEM printf("Warning-- No calls to system(3) supported on this platform."); printf("Warning-- Skipping execution of 'system(\"%s\")'.", dssp); exit(1); #else if(0 != system(dssp)) { gmx_fatal(FARGS,"Failed to execute command: %s",dssp); } #endif strip_dssp(tmpfile,nres,bPhbres,t, accr[nframe],fTArea,&mat,average_area); remove(tmpfile); remove(pdbfile); nframe++; } while(read_next_x(status,&t,natoms,x,box)); fprintf(stderr,"\n"); close_trj(status); if (fTArea) ffclose(fTArea); prune_ss_legend(&mat); ss=opt2FILE("-o",NFILE,fnm,"w"); write_xpm_m(ss,mat); ffclose(ss); if (opt2bSet("-ssdump",NFILE,fnm)) { snew(ss_str,nres+1); for(i=0; (i<nres); i++) ss_str[i] = mat.map[mat.matrix[0][i]].code.c1; ss_str[i] = '\0'; ss = opt2FILE("-ssdump",NFILE,fnm,"w"); fprintf(ss,"%d\n%s\n",nres,ss_str); fclose(ss); sfree(ss_str); } analyse_ss(fnSCount,&mat,ss_string); if (bDoAccSurf) { write_sas_mat(fnArea,accr,nframe,nres,&mat); for(i=0; i<atoms->nres; i++) av_area[i] = (average_area[i] / (real)nframe); norm_acc(atoms, nres, av_area, norm_av_area); if (fnAArea) { acc=xvgropen(fnAArea,"Average Accessible Area", "Residue","A\\S2"); for(i=0; (i<nres); i++) fprintf(acc,"%5d %10g %10g\n",i+1,av_area[i], norm_av_area[i]); ffclose(acc); } } view_all(NFILE, fnm); thanx(stderr); return 0; }
static void update_topol(const char *topinout, int p_num, int n_num, const char *p_name, const char *n_name, char *grpname) { FILE *fpin, *fpout; char buf[STRLEN], buf2[STRLEN], *temp, **mol_line = NULL; int line, i, nmol_line, sol_line, nsol_last; gmx_bool bMolecules; char temporary_filename[STRLEN]; printf("\nProcessing topology\n"); fpin = gmx_ffopen(topinout, "r"); std::strncpy(temporary_filename, "temp.topXXXXXX", STRLEN); gmx_tmpnam(temporary_filename); fpout = gmx_ffopen(temporary_filename, "w"); line = 0; bMolecules = FALSE; nmol_line = 0; sol_line = -1; nsol_last = -1; while (fgets(buf, STRLEN, fpin)) { line++; std::strcpy(buf2, buf); if ((temp = std::strchr(buf2, '\n')) != NULL) { temp[0] = '\0'; } ltrim(buf2); if (buf2[0] == '[') { buf2[0] = ' '; if ((temp = std::strchr(buf2, '\n')) != NULL) { temp[0] = '\0'; } rtrim(buf2); if (buf2[std::strlen(buf2)-1] == ']') { buf2[std::strlen(buf2)-1] = '\0'; ltrim(buf2); rtrim(buf2); bMolecules = (gmx_strcasecmp(buf2, "molecules") == 0); } fprintf(fpout, "%s", buf); } else if (!bMolecules) { fprintf(fpout, "%s", buf); } else { /* Check if this is a line with solvent molecules */ sscanf(buf, "%s", buf2); if (gmx_strcasecmp(buf2, grpname) == 0) { sol_line = nmol_line; sscanf(buf, "%*s %d", &nsol_last); } /* Store this molecules section line */ srenew(mol_line, nmol_line+1); mol_line[nmol_line] = gmx_strdup(buf); nmol_line++; } } gmx_ffclose(fpin); if (sol_line == -1) { gmx_ffclose(fpout); gmx_fatal(FARGS, "No line with moleculetype '%s' found the [ molecules ] section of file '%s'", grpname, topinout); } if (nsol_last < p_num+n_num) { gmx_ffclose(fpout); gmx_fatal(FARGS, "The last entry for moleculetype '%s' in the [ molecules ] section of file '%s' has less solvent molecules (%d) than were replaced (%d)", grpname, topinout, nsol_last, p_num+n_num); } /* Print all the molecule entries */ for (i = 0; i < nmol_line; i++) { if (i != sol_line) { fprintf(fpout, "%s", mol_line[i]); } else { printf("Replacing %d solute molecules in topology file (%s) " " by %d %s and %d %s ions.\n", p_num+n_num, topinout, p_num, p_name, n_num, n_name); nsol_last -= p_num + n_num; if (nsol_last > 0) { fprintf(fpout, "%-10s %d\n", grpname, nsol_last); } if (p_num > 0) { fprintf(fpout, "%-15s %d\n", p_name, p_num); } if (n_num > 0) { fprintf(fpout, "%-15s %d\n", n_name, n_num); } } } gmx_ffclose(fpout); /* use gmx_ffopen to generate backup of topinout */ fpout = gmx_ffopen(topinout, "w"); gmx_ffclose(fpout); rename(temporary_filename, topinout); }
int main(int argc,char *argv[]) { static char *desc[] = { "[TT]do_shift[tt] reads a trajectory file and computes the chemical", "shift for each time frame (or every [BB]dt[bb] ps) by", "calling the 'total' program. If you do not have the total program,", "get it. do_shift assumes that the total executable is in", "[TT]/home/mdgroup/total/total[tt]. If that is not the case, then you should", "set an environment variable [BB]TOTAL[bb] as in: [PAR]", "[TT]setenv TOTAL /usr/local/bin/total[tt][PAR]", "where the right hand side should point to the total executable.[PAR]", "Output is printed in files [TT]shift.out[tt] where t is the time of the frame.[PAR]", "The program also needs an input file called [BB]random.dat[bb] which", "contains the random coil chemical shifts of all protons." }; static real dt=0.0; t_pargs pa[] = { { "-dt", FALSE, etREAL, { &dt }, "Time interval between frames." } }; static char *bugs[] = { "The program is very slow" }; static char *OXYGEN="O"; FILE *out,*tot,*fp; t_topology *top; t_atoms *atoms; int status,nres; real t,nt; int i,natoms,nframe=0; matrix box; int gnx; char *grpnm,*randf; atom_id *index; rvec *x,*x_s; char pdbfile[32],tmpfile[32]; char total[256],*dptr; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPX, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffREAD }, { efOUT, "-o", "shift", ffWRITE }, { efDAT, "-d", "random", ffREAD } }; char *leg[] = { "shift","ring","anisCO","anisCN","sigmaE","sum" }; #define NFILE asize(fnm) CopyRight(stdout,argv[0]); parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_BE_NICE ,NFILE,fnm, asize(pa),pa,asize(desc),desc,asize(bugs),bugs); top=read_top(ftp2fn(efTPX,NFILE,fnm)); atoms=&(top->atoms); nres=atoms->nres; for(i=0; (i<atoms->nr); i++) if ((strcmp(*atoms->atomname[i],"O1") == 0) || (strcmp(*atoms->atomname[i],"O2") == 0) || (strcmp(*atoms->atomname[i],"OXT") == 0) || (strcmp(*atoms->atomname[i],"OT") == 0)) atoms->atomname[i]=&OXYGEN; rd_index(ftp2fn(efNDX,NFILE,fnm),1,&gnx,&index,&grpnm); snew(x_s,atoms->nr); strcpy(pdbfile,"dsXXXXXX"); gmx_tmpnam(pdbfile); strcpy(tmpfile,"dsXXXXXX"); gmx_tmpnam(tmpfile); fprintf(stderr,"pdbfile = %s\ntmpfile = %s\n",pdbfile,tmpfile); if ((dptr=getenv("TOTAL")) == NULL) dptr="/home/mdgroup/total/total"; sprintf(total,"%s > /dev/null",dptr); fprintf(stderr,"total cmd='%s'\n",total); randf=ftp2fn(efDAT,NFILE,fnm); natoms=read_first_x(&status,ftp2fn(efTRX,NFILE,fnm),&t,&x,box); if (natoms != atoms->nr) gmx_fatal(FARGS,"Trajectory does not match topology!"); out=ftp2FILE(efOUT,NFILE,fnm,"w"); xvgr_legend(out,asize(leg),leg); nt=t; do { if (t >= nt) { rm_pbc(&(top->idef),top->atoms.nr,box,x,x_s); fp=gmx_ffopen(pdbfile,"w"); write_pdbfile_indexed(fp,"Generated by do_shift", atoms,x_s,box,0,-1,gnx,index); gmx_ffclose(fp); if ((tot=popen(total,"w")) == NULL) perror("opening pipe to total"); fprintf(tot,"%s\n",pdbfile); fprintf(tot,"%s\n",tmpfile); fprintf(tot,"3\n"); fprintf(tot,"N\n"); fprintf(tot,"%s\n",randf); fprintf(tot,"N\n"); fprintf(tot,"N\n"); if (pclose(tot) != 0) perror("closing pipe to total"); cat(out,tmpfile,t); remove(pdbfile); remove(tmpfile); nt+=dt; nframe++; } } while(read_next_x(status,&t,natoms,x,box)); close_trj(status); gmx_ffclose(out); gmx_thanx(stderr); return 0; }