4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
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 * For more info, check our website at http://www.gromacs.org
34 * Green Red Orange Magenta Azure Cyan Skyblue
51 static int get_nf(void)
56 printf("Number of frames ? ");
58 } while (scanf("%d",&nf
) != 1);
63 static void dump_dih(int nframes
,char *title
,real time
[],real dih
[])
69 sprintf(fname
,"dih.%s",title
);
70 printf("A dihedral transition occurred in %s\n",fname
);
71 printf("Do you want to plot it to %s ? (y/n) ",fname
);
73 out
=ffopen(fname
,"w");
74 for(i
=0; (i
<nframes
); i
++)
75 fprintf(out
,"%10.3f %12.5e\n",time
[i
],dih
[i
]);
79 static void ana_dih(FILE *out
,char *index
,int nframes
,real dih
[],t_dih
*dd
)
82 real mind
,maxd
,sum
,av
,var
,prev
,width
;
85 mind
=5400,maxd
=-5400,sum
=0,av
=0,var
=0;
88 for(i
=0; (i
<nframes
); i
++) {
89 if ((dih
[i
]-prev
) > 180) {
93 else if ((dih
[i
]-prev
) < -180)
98 mind
=min(mind
,dih
[i
]);
99 maxd
=max(maxd
,dih
[i
]);
102 for(i
=0; (i
<nframes
); i
++)
105 width
=(360.0/dd
->mult
);
106 bTrans
=((maxd
- mind
) > width
);
108 fprintf(out
,"%-10s %10.3f %10.3f %10.3f %10.3f %10.3f %-10s%3.0f\n",
109 index
,mind
,av
,maxd
,var
,sqrt(var
),
110 bTrans
? "Yep" : "",width
);
113 static int find_min(real phi
,int ntab
,real phitab
[])
119 /* Set closest minimum to the first one */
121 mind
=fabs(phi
-phitab
[0]);
123 for(i
=1; (i
<ntab
); i
++) {
124 mm
=fabs(phi
-phitab
[i
]);
130 if (mind
< width
*0.5 )
136 static int vphi(t_dih
*dih
,real phi
,int mult
)
138 static real m2
[] = { 90, 270 };
139 static real m3
[] = { 60, 180, 300 };
140 static real m4
[] = { 45, 135, 225, 315 };
141 static real m6
[] = { 30, 90, 150, 210, 270, 330 };
146 phiref
=RAD2DEG
*(phi
-dih
->phi0
);
154 vpp
=find_min(phiref
,2,m2
);
157 vpp
=find_min(phiref
,3,m3
);
160 vpp
=find_min(phiref
,4,m4
);
163 vpp
=find_min(phiref
,6,m6
);
166 fatal_error(0,"No such multiplicity %d",dih
->mult
);
175 typedef struct t_cluster
{
179 struct t_cluster
*next
;
182 static t_cluster
*search_cluster(t_cluster
*cl
,char *minimum
)
186 while (ccl
!= NULL
) {
187 if (strcmp(minimum
,ccl
->minimum
)==0)
194 static void add_cluster(t_cluster
**cl
,int ndih
,char *minimum
)
202 ccl
->minimum
=strdup(minimum
);
209 while (loper
->next
!= NULL
)
215 static void p_cluster(FILE *out
,t_cluster
*cl
)
219 fprintf(out
,"* * * C L U S T E R A N A L Y S I S * * *\n\n");
220 fprintf(out
," Frequency Dihedral minima\n");
222 while (loper
!= NULL
) {
223 fprintf(out
,"%10d %s\n",loper
->freq
,loper
->minimum
);
228 static void ana_cluster(FILE *out
, t_xrama
*xr
,real
**dih
,real time
[],
229 t_topology
*top
,int nframes
,int mult
)
231 t_cluster
*cl
=NULL
,*scl
;
235 /* Number of dihedrals + terminating NULL
236 * this allows for using string routines
238 snew(minimum
,xr
->ndih
+1);
240 for(i
=0; (i
<nframes
); i
++) {
242 for(j
=0; (j
<xr
->ndih
); j
++) {
243 minimum
[j
] = vphi(&xr
->dih
[j
],dih
[j
][i
],
244 mult
== -1 ? xr
->dih
[j
].mult
: mult
);
245 if (minimum
[j
] == NOMIN
)
249 if ((scl
=search_cluster(cl
,minimum
)) == NULL
)
250 add_cluster(&cl
,xr
->ndih
,minimum
);
260 static void ana_trans(FILE *out
, t_xrama
*xr
,real
**dih
,real time
[],
261 t_topology
*top
,int nframes
)
264 real prev_phi
,prev_psi
;
268 fprintf(out
,"\n\t* * * D I H E D R A L S T A T I S T I C S * * *\n\n");
269 fprintf(out
,"%-10s %10s %10s %10s %10s %10s %10s\n",
270 "index","minimum","average","maximum","variance","std.dev",
272 for(i
=0; (i
>xr
->ndih
); i
++) {
273 sprintf(buf
,"dih-%d",i
);
274 ana_dih(out
,buf
,nframes
,dih
[i
],&(xr
->dih
[i
]));
276 for(i
=0; (i
<xr
->npp
); i
++) {
277 sprintf(buf
,"%s",xr
->pp
[i
].label
);
278 outd
=xvgropen(buf
,"Dihedral Angles","Time (ps)","Degrees");
282 prev_phi
=dih
[phi
][0];
283 prev_psi
=dih
[psi
][0];
284 for(j
=0; (j
<nframes
); j
++) {
286 if ((dih
[phi
][j
]-prev_phi
) > 180)
288 else if ((dih
[phi
][j
]-prev_phi
) < -180)
290 prev_phi
=dih
[phi
][j
];
291 if ((dih
[psi
][j
]-prev_psi
) > 180)
293 else if ((dih
[psi
][j
]-prev_psi
) < -180)
295 prev_psi
=dih
[psi
][j
];
296 fprintf(outd
,"%10g %10g %10g\n",time
[j
],prev_phi
,prev_psi
);
302 int gmx_dih(int argc
,char *argv
[])
304 static char *desc
[] = {
305 "g_dih can do two things. The default is to analyze dihedral transitions",
306 "by merely computing all the dihedral angles defined in your topology",
307 "for the whole trajectory. When a dihedral flips over to another minimum",
308 "an angle/time plot is made.[PAR]",
309 "The opther option is to discretize the dihedral space into a number of",
310 "bins, and group each conformation in dihedral space in the",
311 "appropriate bin. The output is then given as a number of dihedral",
312 "conformations sorted according to occupancy."
314 static char *bugs
[] = {
315 "should not ask for number of frames"
317 static int mult
= -1;
318 static bool bSA
= FALSE
;
320 { "-sa", FALSE
, etBOOL
, {&bSA
},
321 "Perform cluster analysis in dihedral space instead of analysing dihedral transitions." },
322 { "-mult", FALSE
, etINT
, {&mult
},
323 "mulitiplicity for dihedral angles (by default read from topology)" }
332 { efTRX
, "-f", NULL
, ffREAD
},
333 { efTPX
, NULL
, NULL
, ffREAD
},
334 { efOUT
, NULL
, NULL
, ffWRITE
}
336 #define NFILE asize(fnm)
338 CopyRight(stderr
,argv
[0]);
339 parse_common_args(&argc
,argv
,PCA_CAN_VIEW
| PCA_CAN_TIME
| PCA_BE_NICE
,
340 NFILE
,fnm
,asize(pa
),pa
,asize(desc
),desc
,asize(bugs
),bugs
);
343 fprintf(stderr
,"Using %d for dihedral multiplicity rather than topology values\n",mult
);
346 init_rama(ftp2fn(efTRX
,NFILE
,fnm
),
347 ftp2fn(efTPX
,NFILE
,fnm
),xr
);
348 top
=read_top(ftp2fn(efTPX
,NFILE
,fnm
));
350 /* Brute force malloc, may be too big... */
353 for(i
=0; (i
<xr
->ndih
); i
++)
354 snew(dih
[i
],nframes
);
357 fprintf(stderr
,"\n");
358 for(step
=0; (step
<nframes
); step
++) {
361 for(i
=0; (i
<xr
->ndih
); i
++) {
362 dd
=xr
->dih
[i
].ang
*RAD2DEG
;
372 fprintf(stderr
,"\nCalculated all dihedrals, now analysing...\n");
373 if (step
< nframes
) {
375 fprintf(stderr
,"By the way, there were only %d frames\n",nframes
);
378 out
=ftp2FILE(efOUT
,NFILE
,fnm
,"w");
381 /* Cluster and structure analysis */
382 ana_cluster(out
,xr
,dih
,time
,top
,nframes
,mult
);
385 /* Analyse transitions... */
386 ana_trans(out
,xr
,dih
,time
,top
,nframes
);