int write_trxframe(t_trxstatus *status,t_trxframe *fr,gmx_conect gc) { char title[STRLEN]; real prec; if (fr->bPrec) prec = fr->prec; else prec = 1000.0; switch (gmx_fio_getftp(status->fio)) { case efTRJ: case efTRR: break; default: if (!fr->bX) gmx_fatal(FARGS,"Need coordinates to write a %s trajectory", ftp2ext(gmx_fio_getftp(status->fio))); break; } switch (gmx_fio_getftp(status->fio)) { case efXTC: write_xtc(status->fio,fr->natoms,fr->step,fr->time,fr->box,fr->x,prec); break; case efTRJ: case efTRR: fwrite_trn(status->fio,fr->step,fr->time,fr->lambda,fr->box,fr->natoms, fr->bX ? fr->x:NULL,fr->bV ? fr->v:NULL ,fr->bF ? fr->f:NULL); break; case efGRO: case efPDB: case efBRK: case efENT: if (!fr->bAtoms) gmx_fatal(FARGS,"Can not write a %s file without atom names", ftp2ext(gmx_fio_getftp(status->fio))); sprintf(title,"frame t= %.3f",fr->time); if (gmx_fio_getftp(status->fio) == efGRO) write_hconf_p(gmx_fio_getfp(status->fio),title,fr->atoms, prec2ndec(prec),fr->x,fr->bV ? fr->v : NULL,fr->box); else write_pdbfile(gmx_fio_getfp(status->fio),title, fr->atoms,fr->x,fr->bPBC ? fr->ePBC : -1,fr->box, ' ',fr->step,gc,TRUE); break; case efG87: write_gms(gmx_fio_getfp(status->fio),fr->natoms,fr->x,fr->box); break; case efG96: write_g96_conf(gmx_fio_getfp(status->fio),fr,-1,NULL); break; default: gmx_fatal(FARGS,"Sorry, write_trxframe can not write %s", ftp2ext(gmx_fio_getftp(status->fio))); break; } return 0; }
void write_sto_conf_indexed(const char *outfile, const char *title, t_atoms *atoms, rvec x[], rvec *v, int ePBC, matrix box, atom_id nindex, atom_id index[]) { FILE *out; int ftp; t_trxframe fr; ftp = fn2ftp(outfile); switch (ftp) { case efGRO: out = gmx_fio_fopen(outfile, "w"); write_hconf_indexed_p(out, title, atoms, nindex, index, 3, x, v, box); gmx_fio_fclose(out); break; case efG96: clear_trxframe(&fr, TRUE); fr.bTitle = TRUE; fr.title = title; fr.natoms = atoms->nr; fr.bAtoms = TRUE; fr.atoms = atoms; fr.bX = TRUE; fr.x = x; if (v) { fr.bV = TRUE; fr.v = v; } fr.bBox = TRUE; copy_mat(box, fr.box); out = gmx_fio_fopen(outfile, "w"); write_g96_conf(out, &fr, nindex, index); gmx_fio_fclose(out); break; case efPDB: case efBRK: case efENT: case efPQR: out = gmx_fio_fopen(outfile, "w"); write_pdbfile_indexed(out, title, atoms, x, ePBC, box, ' ', -1, nindex, index, NULL, TRUE); gmx_fio_fclose(out); break; case efESP: out = gmx_fio_fopen(outfile, "w"); write_espresso_conf_indexed(out, title, atoms, nindex, index, x, v, box); gmx_fio_fclose(out); break; case efTPR: case efTPB: case efTPA: gmx_fatal(FARGS, "Sorry, can not write a topology to %s", outfile); break; default: gmx_incons("Not supported in write_sto_conf_indexed"); } }
int write_trxframe(t_trxstatus *status, t_trxframe *fr, gmx_conect gc) { char title[STRLEN]; real prec; if (fr->bPrec) { prec = fr->prec; } else { prec = 1000.0; } if (status->tng) { gmx_tng_set_compression_precision(status->tng, prec); write_tng_frame(status, fr); return 0; } switch (gmx_fio_getftp(status->fio)) { case efTRR: break; default: if (!fr->bX) { gmx_fatal(FARGS, "Need coordinates to write a %s trajectory", ftp2ext(gmx_fio_getftp(status->fio))); } break; } switch (gmx_fio_getftp(status->fio)) { case efXTC: write_xtc(status->fio, fr->natoms, fr->step, fr->time, fr->box, fr->x, prec); break; case efTRR: gmx_trr_write_frame(status->fio, fr->step, fr->time, fr->lambda, fr->box, fr->natoms, fr->bX ? fr->x : nullptr, fr->bV ? fr->v : nullptr, fr->bF ? fr->f : nullptr); break; case efGRO: case efPDB: case efBRK: case efENT: if (!fr->bAtoms) { gmx_fatal(FARGS, "Can not write a %s file without atom names", ftp2ext(gmx_fio_getftp(status->fio))); } sprintf(title, "frame t= %.3f", fr->time); if (gmx_fio_getftp(status->fio) == efGRO) { write_hconf_p(gmx_fio_getfp(status->fio), title, fr->atoms, fr->x, fr->bV ? fr->v : nullptr, fr->box); } else { write_pdbfile(gmx_fio_getfp(status->fio), title, fr->atoms, fr->x, fr->bPBC ? fr->ePBC : -1, fr->box, ' ', fr->step, gc, TRUE); } break; case efG96: write_g96_conf(gmx_fio_getfp(status->fio), title, fr, -1, nullptr); break; default: gmx_fatal(FARGS, "Sorry, write_trxframe can not write %s", ftp2ext(gmx_fio_getftp(status->fio))); break; } return 0; }
int write_trxframe_indexed(t_trxstatus *status, const t_trxframe *fr, int nind, const int *ind, gmx_conect gc) { char title[STRLEN]; rvec *xout = nullptr, *vout = nullptr, *fout = nullptr; int i, ftp = -1; real prec; if (fr->bPrec) { prec = fr->prec; } else { prec = 1000.0; } if (status->tng) { ftp = efTNG; } else if (status->fio) { ftp = gmx_fio_getftp(status->fio); } else { gmx_incons("No input file available"); } switch (ftp) { case efTRR: case efTNG: break; default: if (!fr->bX) { gmx_fatal(FARGS, "Need coordinates to write a %s trajectory", ftp2ext(ftp)); } break; } switch (ftp) { case efTRR: case efTNG: if (fr->bV) { snew(vout, nind); for (i = 0; i < nind; i++) { copy_rvec(fr->v[ind[i]], vout[i]); } } if (fr->bF) { snew(fout, nind); for (i = 0; i < nind; i++) { copy_rvec(fr->f[ind[i]], fout[i]); } } // fallthrough case efXTC: if (fr->bX) { snew(xout, nind); for (i = 0; i < nind; i++) { copy_rvec(fr->x[ind[i]], xout[i]); } } break; default: break; } switch (ftp) { case efTNG: gmx_write_tng_from_trxframe(status->tng, fr, nind); break; case efXTC: write_xtc(status->fio, nind, fr->step, fr->time, fr->box, xout, prec); break; case efTRR: gmx_trr_write_frame(status->fio, nframes_read(status), fr->time, fr->step, fr->box, nind, xout, vout, fout); break; case efGRO: case efPDB: case efBRK: case efENT: if (!fr->bAtoms) { gmx_fatal(FARGS, "Can not write a %s file without atom names", ftp2ext(ftp)); } sprintf(title, "frame t= %.3f", fr->time); if (ftp == efGRO) { write_hconf_indexed_p(gmx_fio_getfp(status->fio), title, fr->atoms, nind, ind, fr->x, fr->bV ? fr->v : nullptr, fr->box); } else { write_pdbfile_indexed(gmx_fio_getfp(status->fio), title, fr->atoms, fr->x, -1, fr->box, ' ', fr->step, nind, ind, gc, TRUE); } break; case efG96: sprintf(title, "frame t= %.3f", fr->time); write_g96_conf(gmx_fio_getfp(status->fio), title, fr, nind, ind); break; default: gmx_fatal(FARGS, "Sorry, write_trxframe_indexed can not write %s", ftp2ext(ftp)); break; } switch (ftp) { case efTRR: case efTNG: if (vout) { sfree(vout); } if (fout) { sfree(fout); } // fallthrough case efXTC: sfree(xout); break; default: break; } return 0; }
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 write_trxframe_indexed(t_trxstatus *status, t_trxframe *fr, int nind, const atom_id *ind, gmx_conect gc) { char title[STRLEN]; rvec *xout = NULL, *vout = NULL, *fout = NULL; int i; real prec; if (fr->bPrec) { prec = fr->prec; } else { prec = 1000.0; } switch (gmx_fio_getftp(status->fio)) { case efTRJ: case efTRR: break; default: if (!fr->bX) { gmx_fatal(FARGS, "Need coordinates to write a %s trajectory", ftp2ext(gmx_fio_getftp(status->fio))); } break; } switch (gmx_fio_getftp(status->fio)) { case efTRJ: case efTRR: if (fr->bV) { snew(vout, nind); for (i = 0; i < nind; i++) { copy_rvec(fr->v[ind[i]], vout[i]); } } if (fr->bF) { snew(fout, nind); for (i = 0; i < nind; i++) { copy_rvec(fr->f[ind[i]], fout[i]); } } /* no break */ case efXTC: case efG87: if (fr->bX) { snew(xout, nind); for (i = 0; i < nind; i++) { copy_rvec(fr->x[ind[i]], xout[i]); } } break; default: break; } switch (gmx_fio_getftp(status->fio)) { case efXTC: write_xtc(status->fio, nind, fr->step, fr->time, fr->box, xout, prec); break; case efTRJ: case efTRR: fwrite_trn(status->fio, nframes_read(status), fr->time, fr->step, fr->box, nind, xout, vout, fout); break; case efGRO: case efPDB: case efBRK: case efENT: if (!fr->bAtoms) { gmx_fatal(FARGS, "Can not write a %s file without atom names", ftp2ext(gmx_fio_getftp(status->fio))); } sprintf(title, "frame t= %.3f", fr->time); if (gmx_fio_getftp(status->fio) == efGRO) { write_hconf_indexed_p(gmx_fio_getfp(status->fio), title, fr->atoms, nind, ind, prec2ndec(prec), fr->x, fr->bV ? fr->v : NULL, fr->box); } else { write_pdbfile_indexed(gmx_fio_getfp(status->fio), title, fr->atoms, fr->x, -1, fr->box, ' ', fr->step, nind, ind, gc, TRUE); } break; case efG87: write_gms(gmx_fio_getfp(status->fio), nind, xout, fr->box); break; case efG96: write_g96_conf(gmx_fio_getfp(status->fio), fr, nind, ind); break; default: gmx_fatal(FARGS, "Sorry, write_trxframe_indexed can not write %s", ftp2ext(gmx_fio_getftp(status->fio))); break; } switch (gmx_fio_getftp(status->fio)) { case efTRN: case efTRJ: case efTRR: if (vout) { sfree(vout); } if (fout) { sfree(fout); } /* no break */ case efXTC: case efG87: sfree(xout); break; default: break; } return 0; }