3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Green Red Orange Magenta Azure Cyan Skyblue
56 static void ana_dih(FILE *out,char *index,int nframes,real dih[],t_dih *dd)
59 real mind,maxd,sum,av,var,prev,width;
62 mind=5400,maxd=-5400,sum=0,av=0,var=0;
65 for(i=0; (i<nframes); i++) {
66 if ((dih[i]-prev) > 180) {
70 else if ((dih[i]-prev) < -180)
75 mind=min(mind,dih[i]);
76 maxd=max(maxd,dih[i]);
79 for(i=0; (i<nframes); i++)
82 width=(360.0/dd->mult);
83 bTrans=((maxd - mind) > width);
85 fprintf(out,"%-10s %10.3f %10.3f %10.3f %10.3f %10.3f %-10s%3.0f\n",
86 index,mind,av,maxd,var,sqrt(var),
87 bTrans ? "Yep" : "",width);
90 static int find_min(real phi,int ntab,real phitab[])
96 /* Set closest minimum to the first one */
98 mind=fabs(phi-phitab[0]);
100 for(i=1; (i<ntab); i++) {
101 mm=fabs(phi-phitab[i]);
107 if (mind < width*0.5 )
113 static int vphi(t_dih *dih,real phi,int mult)
115 static real m2[] = { 90, 270 };
116 static real m3[] = { 60, 180, 300 };
117 static real m4[] = { 45, 135, 225, 315 };
118 static real m6[] = { 30, 90, 150, 210, 270, 330 };
123 phiref=RAD2DEG*(phi-dih->phi0);
131 vpp=find_min(phiref,2,m2);
134 vpp=find_min(phiref,3,m3);
137 vpp=find_min(phiref,4,m4);
140 vpp=find_min(phiref,6,m6);
143 gmx_fatal(FARGS,"No such multiplicity %d",dih->mult);
152 typedef struct t_cluster {
156 struct t_cluster *next;
159 static t_cluster *search_cluster(t_cluster *cl,char *minimum)
163 while (ccl != NULL) {
164 if (strcmp(minimum,ccl->minimum)==0)
171 static void add_cluster(t_cluster **cl,int ndih,char *minimum)
179 ccl->minimum=strdup(minimum);
186 while (loper->next != NULL)
192 static void p_cluster(FILE *out,t_cluster *cl)
196 fprintf(out,"* * * C L U S T E R A N A L Y S I S * * *\n\n");
197 fprintf(out," Frequency Dihedral minima\n");
199 while (loper != NULL) {
200 fprintf(out,"%10d %s\n",loper->freq,loper->minimum);
205 static void ana_cluster(FILE *out, t_xrama *xr,real **dih,real time[],
206 t_topology *top,int nframes,int mult)
208 t_cluster *cl=NULL,*scl;
212 /* Number of dihedrals + terminating NULL
213 * this allows for using string routines
215 snew(minimum,xr->ndih+1);
217 for(i=0; (i<nframes); i++) {
219 for(j=0; (j<xr->ndih); j++) {
220 minimum[j] = vphi(&xr->dih[j],dih[j][i],
221 mult == -1 ? xr->dih[j].mult : mult);
222 if (minimum[j] == NOMIN)
226 if ((scl=search_cluster(cl,minimum)) == NULL)
227 add_cluster(&cl,xr->ndih,minimum);
237 static void ana_trans(FILE *out, t_xrama *xr,real **dih,real time[],
238 t_topology *top,int nframes, const output_env_t oenv)
241 real prev_phi,prev_psi;
245 fprintf(out,"\n\t* * * D I H E D R A L S T A T I S T I C S * * *\n\n");
246 fprintf(out,"%-10s %10s %10s %10s %10s %10s %10s\n",
247 "index","minimum","average","maximum","variance","std.dev",
249 for(i=0; (i<xr->ndih); i++) {
250 sprintf(buf,"dih-%d",i);
251 ana_dih(out,buf,nframes,dih[i],&(xr->dih[i]));
253 for(i=0; (i<xr->npp); i++) {
254 sprintf(buf,"%s",xr->pp[i].label);
255 outd=xvgropen(buf,"Dihedral Angles","Time (ps)","Degrees",oenv);
259 prev_phi=dih[phi][0];
260 prev_psi=dih[psi][0];
261 for(j=0; (j<nframes); j++) {
263 if ((dih[phi][j]-prev_phi) > 180)
265 else if ((dih[phi][j]-prev_phi) < -180)
267 prev_phi=dih[phi][j];
268 if ((dih[psi][j]-prev_psi) > 180)
270 else if ((dih[psi][j]-prev_psi) < -180)
272 prev_psi=dih[psi][j];
273 fprintf(outd,"%10g %10g %10g\n",time[j],prev_phi,prev_psi);
279 int gmx_dih(int argc,char *argv[])
281 const char *desc[] = {
282 "[TT]g_dih[tt] can do two things. The default is to analyze dihedral transitions",
283 "by merely computing all the dihedral angles defined in your topology",
284 "for the whole trajectory. When a dihedral flips over to another minimum",
285 "an angle/time plot is made.[PAR]",
286 "The opther option is to discretize the dihedral space into a number of",
287 "bins, and group each conformation in dihedral space in the",
288 "appropriate bin. The output is then given as a number of dihedral",
289 "conformations sorted according to occupancy."
291 static int mult = -1;
292 static gmx_bool bSA = FALSE;
294 { "-sa", FALSE, etBOOL, {&bSA},
295 "Perform cluster analysis in dihedral space instead of analysing dihedral transitions." },
296 { "-mult", FALSE, etINT, {&mult},
297 "mulitiplicity for dihedral angles (by default read from topology)" }
304 int i,nframes,maxframes=1000;
307 { efTRX, "-f", NULL, ffREAD },
308 { efTPX, NULL, NULL, ffREAD },
309 { efOUT, NULL, NULL, ffWRITE }
311 #define NFILE asize(fnm)
313 CopyRight(stderr,argv[0]);
314 parse_common_args(&argc,argv,PCA_CAN_VIEW | PCA_CAN_TIME | PCA_BE_NICE,
315 NFILE,fnm,asize(pa),pa,asize(desc),desc,0,NULL,&oenv);
318 fprintf(stderr,"Using %d for dihedral multiplicity rather than topology values\n",mult);
321 init_rama(oenv,ftp2fn(efTRX,NFILE,fnm),
322 ftp2fn(efTPX,NFILE,fnm),xr,3);
323 top=read_top(ftp2fn(efTPX,NFILE,fnm),NULL);
325 /* Brute force malloc, may be too big... */
327 for(i=0; (i<xr->ndih); i++)
328 snew(dih[i],maxframes);
329 snew(time,maxframes);
331 fprintf(stderr,"\n");
333 while (new_data(xr)) {
334 for(i=0; (i<xr->ndih); i++) {
335 dd=xr->dih[i].ang*RAD2DEG;
344 if (nframes > maxframes) {
346 for(i=0; (i<xr->ndih); i++)
347 srenew(dih[i],maxframes);
348 srenew(time,maxframes);
352 fprintf(stderr,"\nCalculated all dihedrals, now analysing...\n");
354 out=ftp2FILE(efOUT,NFILE,fnm,"w");
357 /* Cluster and structure analysis */
358 ana_cluster(out,xr,dih,time,top,nframes,mult);
361 /* Analyse transitions... */
362 ana_trans(out,xr,dih,time,top,nframes,oenv);