4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-2001
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
34 * Gromacs Runs On Most of All Computer Systems
36 static char *SRCID_do_shift_c = "$Id$";
55 void cat(FILE *out,char *fn,real t)
61 double f1,f2,f3,f4,f5,f6;
64 while ((ptr=fgets2(buf,255,in)) != NULL) {
65 sscanf(buf,"%d%d%s%s%lf%lf%lf%lf%lf%lf",
66 &anr,&rnr,rnm,anm,&f1,&f2,&f3,&f4,&f5,&f6);
67 fprintf(out,"%8g %10g %10g %10g %10g %10g %10g %s%d-%s%d\n",
68 t,f6,f1,f2,f3,f4,f5,rnm,rnr,anm,anr);
70 /*if ((int)strlen(buf) > 0)
71 fprintf(out,"%s\n",buf);*/
76 int main(int argc,char *argv[])
78 static char *desc[] = {
79 "do_shift reads a trajectory file and computes the chemical",
80 "shift for each time frame (or every [BB]dt[bb] ps) by",
81 "calling the 'total' program. If you do not have the total program,",
82 "get it. do_shift assumes that the total executable is in",
83 "/home/mdgroup/total/total. If that is not the case, then you should",
84 "set an environment variable [BB]TOTAL[bb] as in: [PAR]",
85 "[TT]setenv TOTAL /usr/local/bin/total[tt][PAR]",
86 "where the right hand side should point to the total executable.[PAR]",
87 "Output is printed in files shift.out where t is the time of the frame.[PAR]",
88 "The program also needs an input file called [BB]random.dat[bb] which",
89 "contains the random coil chemical shifts of all protons."
93 { "-dt", FALSE, etREAL, &dt, "Time interval between frames." }
95 static char *bugs[] = {
96 "The program is very slow"
98 static char *OXYGEN="O";
104 int i,natoms,nframe=0;
110 char pdbfile[L_tmpnam],tmpfile[L_tmpnam];
111 char total[256],*dptr;
113 { efTRX, "-f", NULL, ffREAD },
114 { efTPX, NULL, NULL, ffREAD },
115 { efNDX, NULL, NULL, ffREAD },
116 { efOUT, "-o", "shift", ffWRITE },
117 { efDAT, "-d", "random", ffREAD }
119 char *leg[] = { "shift","ring","anisCO","anisCN","sigmaE","sum" };
120 #define NFILE asize(fnm)
122 CopyRight(stdout,argv[0]);
123 parse_common_args(&argc,argv,PCA_CAN_TIME,TRUE,NFILE,fnm,
124 asize(pa),pa,asize(desc),desc,asize(bugs),bugs);
126 top=read_top(ftp2fn(efTPX,NFILE,fnm));
129 for(i=0; (i<atoms->nr); i++)
130 if ((strcmp(*atoms->atomname[i],"O1") == 0) ||
131 (strcmp(*atoms->atomname[i],"O2") == 0) ||
132 (strcmp(*atoms->atomname[i],"OXT") == 0) ||
133 (strcmp(*atoms->atomname[i],"OT") == 0))
134 atoms->atomname[i]=&OXYGEN;
135 rd_index(ftp2fn(efNDX,NFILE,fnm),1,&gnx,&index,&grpnm);
139 (void) tmpnam(pdbfile);
140 (void) tmpnam(tmpfile);
141 fprintf(stderr,"pdbfile = %s\ntmpfile = %s\n",pdbfile,tmpfile);
143 if ((dptr=getenv("TOTAL")) == NULL)
144 dptr="/home/mdgroup/total/total";
145 sprintf(total,"%s > /dev/null",dptr);
146 fprintf(stderr,"total cmd='%s'\n",total);
147 randf=ftp2fn(efDAT,NFILE,fnm);
149 natoms=read_first_x(&status,ftp2fn(efTRX,NFILE,fnm),&t,&x,box);
150 if (natoms != atoms->nr)
151 fatal_error(0,"Trajectory does not match topology!");
152 out=ftp2FILE(efOUT,NFILE,fnm,"w");
153 xvgr_legend(out,asize(leg),leg);
157 rm_pbc(&(top->idef),top->atoms.nr,box,x,x_s);
158 fp=ffopen(pdbfile,"w");
159 write_pdbfile_indexed(fp,"Generated by do_shift",
160 atoms,x_s,box,0,-1,gnx,index);
163 if ((tot=popen(total,"w")) == NULL)
164 perror("opening pipe to total");
165 fprintf(tot,"%s\n",pdbfile);
166 fprintf(tot,"%s\n",tmpfile);
169 fprintf(tot,"%s\n",randf);
172 if (pclose(tot) != 0)
173 perror("closing pipe to total");
180 } while(read_next_x(status,&t,natoms,x,box));