4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * GRowing Old MAkes el Chrono Sweat
29 static char *SRCID_g_dih_c
= "$Id$";
46 static int get_nf(void)
51 printf("Number of frames ? ");
53 } while (scanf("%d",&nf
) != 1);
58 static void dump_dih(int nframes
,char *title
,real time
[],real dih
[])
64 sprintf(fname
,"dih.%s",title
);
65 printf("A dihedral transition occurred in %s\n",fname
);
66 printf("Do you want to plot it to %s ? (y/n) ",fname
);
68 out
=ffopen(fname
,"w");
69 for(i
=0; (i
<nframes
); i
++)
70 fprintf(out
,"%10.3f %12.5e\n",time
[i
],dih
[i
]);
74 static void ana_dih(FILE *out
,char *index
,int nframes
,real dih
[],t_dih
*dd
)
77 real mind
,maxd
,sum
,av
,var
,prev
,width
;
80 mind
=5400,maxd
=-5400,sum
=0,av
=0,var
=0;
83 for(i
=0; (i
<nframes
); i
++) {
84 if ((dih
[i
]-prev
) > 180) {
88 else if ((dih
[i
]-prev
) < -180)
93 mind
=min(mind
,dih
[i
]);
94 maxd
=max(maxd
,dih
[i
]);
97 for(i
=0; (i
<nframes
); i
++)
100 width
=(360.0/dd
->mult
);
101 bTrans
=((maxd
- mind
) > width
);
103 fprintf(out
,"%-10s %10.3f %10.3f %10.3f %10.3f %10.3f %-10s%3.0f\n",
104 index
,mind
,av
,maxd
,var
,sqrt(var
),
105 bTrans
? "Yep" : "",width
);
108 static int find_min(real phi
,int ntab
,real phitab
[])
114 /* Set closest minimum to the first one */
116 mind
=fabs(phi
-phitab
[0]);
118 for(i
=1; (i
<ntab
); i
++) {
119 mm
=fabs(phi
-phitab
[i
]);
125 if (mind
< width
*0.5 )
131 static int vphi(t_dih
*dih
,real phi
,int mult
)
133 static real m2
[] = { 90, 270 };
134 static real m3
[] = { 60, 180, 300 };
135 static real m4
[] = { 45, 135, 225, 315 };
136 static real m6
[] = { 30, 90, 150, 210, 270, 330 };
141 phiref
=RAD2DEG
*(phi
-dih
->phi0
);
149 vpp
=find_min(phiref
,2,m2
);
152 vpp
=find_min(phiref
,3,m3
);
155 vpp
=find_min(phiref
,4,m4
);
158 vpp
=find_min(phiref
,6,m6
);
161 fatal_error(0,"No such multiplicity %d",dih
->mult
);
170 typedef struct t_cluster
{
174 struct t_cluster
*next
;
177 static t_cluster
*search_cluster(t_cluster
*cl
,char *minimum
)
181 while (ccl
!= NULL
) {
182 if (strcmp(minimum
,ccl
->minimum
)==0)
189 static void add_cluster(t_cluster
**cl
,int ndih
,char *minimum
)
197 ccl
->minimum
=strdup(minimum
);
204 while (loper
->next
!= NULL
)
210 static void p_cluster(FILE *out
,t_cluster
*cl
)
214 fprintf(out
,"* * * C L U S T E R A N A L Y S I S * * *\n\n");
215 fprintf(out
," Frequency Dihedral minima\n");
217 while (loper
!= NULL
) {
218 fprintf(out
,"%10d %s\n",loper
->freq
,loper
->minimum
);
223 static void ana_cluster(FILE *out
, t_xrama
*xr
,real
**dih
,real time
[],
224 t_topology
*top
,int nframes
,int mult
)
226 t_cluster
*cl
=NULL
,*scl
;
230 /* Number of dihedrals + terminating NULL
231 * this allows for using string routines
233 snew(minimum
,xr
->ndih
+1);
235 for(i
=0; (i
<nframes
); i
++) {
237 for(j
=0; (j
<xr
->ndih
); j
++) {
238 minimum
[j
] = vphi(&xr
->dih
[j
],dih
[j
][i
],
239 mult
== -1 ? xr
->dih
[j
].mult
: mult
);
240 if (minimum
[j
] == NOMIN
)
244 if ((scl
=search_cluster(cl
,minimum
)) == NULL
)
245 add_cluster(&cl
,xr
->ndih
,minimum
);
255 static void ana_trans(FILE *out
, t_xrama
*xr
,real
**dih
,real time
[],
256 t_topology
*top
,int nframes
)
259 real prev_phi
,prev_psi
;
263 fprintf(out
,"\n\t* * * D I H E D R A L S T A T I S T I C S * * *\n\n");
264 fprintf(out
,"%-10s %10s %10s %10s %10s %10s %10s\n",
265 "index","minimum","average","maximum","variance","std.dev",
267 for(i
=0; (i
>xr
->ndih
); i
++) {
268 sprintf(buf
,"dih-%d",i
);
269 ana_dih(out
,buf
,nframes
,dih
[i
],&(xr
->dih
[i
]));
271 for(i
=0; (i
<xr
->npp
); i
++) {
272 sprintf(buf
,"%s",xr
->pp
[i
].label
);
273 outd
=xvgropen(buf
,"Dihedral Angles","Time (ps)","Degrees");
277 prev_phi
=dih
[phi
][0];
278 prev_psi
=dih
[psi
][0];
279 for(j
=0; (j
<nframes
); j
++) {
281 if ((dih
[phi
][j
]-prev_phi
) > 180)
283 else if ((dih
[phi
][j
]-prev_phi
) < -180)
285 prev_phi
=dih
[phi
][j
];
286 if ((dih
[psi
][j
]-prev_psi
) > 180)
288 else if ((dih
[psi
][j
]-prev_psi
) < -180)
290 prev_psi
=dih
[psi
][j
];
291 fprintf(outd
,"%10g %10g %10g\n",time
[j
],prev_phi
,prev_psi
);
297 int main(int argc
,char *argv
[])
299 static char *desc
[] = {
300 "g_dih can do two things. The default is to analyze dihedral transitions",
301 "by merely computing all the dihedral angles defined in your topology",
302 "for the whole trajectory. When a dihedral flips over to another minimum",
303 "an angle/time plot is made.[PAR]",
304 "The opther option is to discretize the dihedral space into a number of",
305 "bins, and group each conformation in dihedral space in the",
306 "appropriate bin. The output is then given as a number of dihedral",
307 "conformations sorted according to occupancy."
309 static char *bugs
[] = {
310 "should not ask for number of frames"
312 static int mult
= -1;
313 static bool bSA
= FALSE
;
315 { "-sa", FALSE
, etBOOL
, {&bSA
},
316 "Perform cluster analysis in dihedral space instead of analysing dihedral transitions." },
317 { "-mult", FALSE
, etINT
, {&mult
},
318 "mulitiplicity for dihedral angles (by default read from topology)" }
327 { efTRX
, "-f", NULL
, ffREAD
},
328 { efTPX
, NULL
, NULL
, ffREAD
},
329 { efOUT
, NULL
, NULL
, ffWRITE
}
331 #define NFILE asize(fnm)
333 CopyRight(stderr
,argv
[0]);
334 parse_common_args(&argc
,argv
,PCA_CAN_VIEW
| PCA_CAN_TIME
,TRUE
,
335 NFILE
,fnm
,asize(pa
),pa
,asize(desc
),desc
,asize(bugs
),bugs
);
338 fprintf(stderr
,"Using %d for dihedral multiplicity rather than topology values\n",mult
);
341 init_rama(ftp2fn(efTRX
,NFILE
,fnm
),
342 ftp2fn(efTPX
,NFILE
,fnm
),xr
);
343 top
=read_top(ftp2fn(efTPX
,NFILE
,fnm
));
345 /* Brute force malloc, may be too big... */
348 for(i
=0; (i
<xr
->ndih
); i
++)
349 snew(dih
[i
],nframes
);
352 fprintf(stderr
,"\n");
353 for(step
=0; (step
<nframes
); step
++) {
356 for(i
=0; (i
<xr
->ndih
); i
++) {
357 dd
=xr
->dih
[i
].ang
*RAD2DEG
;
367 fprintf(stderr
,"\nCalculated all dihedrals, now analysing...\n");
368 if (step
< nframes
) {
370 fprintf(stderr
,"By the way, there were only %d frames\n",nframes
);
373 out
=ftp2FILE(efOUT
,NFILE
,fnm
,"w");
376 /* Cluster and structure analysis */
377 ana_cluster(out
,xr
,dih
,time
,top
,nframes
,mult
);
380 /* Analyse transitions... */
381 ana_trans(out
,xr
,dih
,time
,top
,nframes
);