4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Copyright (c) 1991-2001, University of Groningen, The Netherlands
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * If you want to redistribute modifications, please consider that
18 * scientific software is very special. Version control is crucial -
19 * bugs must be traceable. We will be happy to consider code for
20 * inclusion in the official distribution, but derived work must not
21 * be called official GROMACS. Details are found in the README & COPYING
22 * files - if they are missing, get the official version at www.gromacs.org.
24 * To help us fund GROMACS development, we humbly ask that you cite
25 * the papers on the package - you can find them in the top README file.
27 * For more info, check our website at http://www.gromacs.org
30 * Gromacs Runs One Microsecond At Cannonball Speeds
53 #include "shift_util.h"
58 static void clust_size(char *ndx
,char *trx
,char *xpm
,char *ncl
,char *acl
,
59 char *mcl
,real cut
,int nskip
,int nlevels
,
64 int nindex
,natoms
,status
;
68 real t
,dx2
,cut2
,**cs_dist
=NULL
,*t_x
=NULL
,*t_y
,mid
,cav
;
69 int i
,j
,k
,ai
,aj
,ak
,ci
,cj
,nframe
,nclust
,n_x
,n_y
,max_size
=0;
70 int *clust_index
,*clust_size
,max_clust_size
,nav
;
71 t_rgb rlo
= { 1.0, 1.0, 1.0 };
73 fp
= xvgropen(ncl
,"Number of clusters","Time (ps)","N");
74 gp
= xvgropen(acl
,"Average cluster size","Time (ps)","#molecules");
75 hp
= xvgropen(mcl
,"Max cluster size","Time (ps)","#molecules");
76 rd_index(ndx
,1,&nindex
,&index
,&gname
);
77 natoms
= read_first_x(&status
,trx
,&t
,&x
,box
);
78 snew(clust_index
,nindex
);
79 snew(clust_size
,nindex
);
84 for(i
=0; (i
<nindex
); i
++)
87 if ((nskip
== 0) || ((nskip
> 0) && ((nframe
% nskip
) == 0))) {
90 for(i
=0; (i
<nindex
); i
++) {
95 for(i
=0; (i
<nindex
); i
++) {
98 for(j
=i
+1; (j
<nindex
); j
++) {
102 pbc_dx(x
[ai
],x
[aj
],dx
);
106 for(k
=j
; (k
<nindex
); k
++) {
107 if (clust_index
[k
] == cj
) {
121 snew(cs_dist
[n_x
-1],nindex
);
125 for(i
=0; (i
<nindex
); i
++) {
127 if (ci
> max_clust_size
) max_clust_size
= ci
;
130 cs_dist
[n_x
-1][ci
-1] += 100.0*ci
/(real
)nindex
;
131 max_size
= max(max_size
,ci
);
138 fprintf(fp
,"%10.3e %10d\n",t
,nclust
);
140 fprintf(gp
,"%10.3e %10.3f\n",t
,cav
/nav
);
141 fprintf(hp
, "%10.3e %10d\n", t
, max_clust_size
);
144 } while (read_next_x(status
,&t
,natoms
,x
,box
));
150 /* Look for the smallest entry that is not zero */
152 for(i
=0; (i
<n_x
); i
++)
153 for(j
=0; (j
<max_size
); j
++)
154 if ((cs_dist
[i
][j
] > 0) && (cs_dist
[i
][j
] < mid
))
157 fp
= ffopen(xpm
,"w");
158 write_xpm3(fp
,"Cluster size distribution","Fraction","Time (ps)","Size",
159 n_x
,max_size
-1,t_x
,t_y
,cs_dist
,0,mid
,100.0,
160 rlo
,rmid
,rhi
,&nlevels
);
168 int main(int argc
,char *argv
[])
170 static char *desc
[] = {
171 "This program computes the size distributions of molecular/atomic clusters in",
172 "the gas phase. The output is given in the form of a XPM file.",
173 "The total number of clusters is written to a XVG file."
175 static real cutoff
= 0.35;
176 static int nskip
= 0;
177 static int nlevels
= 20;
178 static rvec rlo
= { 1.0, 1.0, 0.0 };
179 static rvec rhi
= { 0.0, 0.0, 1.0 };
181 { "-cut", FALSE
, etREAL
, {&cutoff
},
182 "Largest distance (nm) to be considered in a cluster" },
183 { "-nskip", FALSE
, etINT
, {&nskip
},
184 "Number of frames to skip between writing" },
185 { "-nlevels", FALSE
, etINT
, {&nlevels
},
186 "Number of levels of grey in xpm output" },
187 { "-rgblo", FALSE
, etRVEC
, {rlo
},
188 "RGB values for the color of the lowest occupied cluster size" },
189 { "-rgbhi", FALSE
, etRVEC
, {rhi
},
190 "RGB values for the color of the highest occupied cluster size" }
192 #define NPA asize(pa)
198 { efTRX
, "-f", NULL
, ffREAD
},
199 { efNDX
, NULL
, NULL
, ffOPTRD
},
200 { efXPM
, "-o", "csize", ffWRITE
},
201 { efXVG
, "-nc","nclust", ffWRITE
},
202 { efXVG
, "-mc","maxclust", ffWRITE
},
203 { efXVG
, "-ac","avclust", ffWRITE
}
205 #define NFILE asize(fnm)
207 CopyRight(stderr
,argv
[0]);
208 parse_common_args(&argc
,argv
,PCA_CAN_VIEW
| PCA_CAN_TIME
| PCA_BE_NICE
,
209 NFILE
,fnm
,NPA
,pa
,asize(desc
),desc
,0,NULL
);
211 fnNDX
= ftp2fn_null(efNDX
,NFILE
,fnm
);
212 rgblo
.r
= rlo
[XX
],rgblo
.g
= rlo
[YY
],rgblo
.b
= rlo
[ZZ
];
213 rgbhi
.r
= rhi
[XX
],rgbhi
.g
= rhi
[YY
],rgbhi
.b
= rhi
[ZZ
];
215 clust_size(fnNDX
,ftp2fn(efTRX
,NFILE
,fnm
),ftp2fn(efXPM
,NFILE
,fnm
),
216 opt2fn("-nc",NFILE
,fnm
),opt2fn("-ac",NFILE
,fnm
),opt2fn("-mc",NFILE
,fnm
),
217 cutoff
,nskip
,nlevels
,rgblo
,rgbhi
);