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_rdens_c
= "$Id$";
47 real
sphere_vol(real r
)
49 return (4.0*M_PI
/3.0)*(r
*r
*r
);
52 /* rdf_add just counts nr. of atoms in each slice and total mass
54 void rdf_add(int bin
[], real mbin
[],real width
,real hb2
,rvec x
[],rvec xcm
,
55 int nx2
,atom_id index2
[], t_atom atom
[])
62 for(j
=0; (j
< nx2
); j
++) {
64 rvec_sub(x
[jx
],xcm
,dx
);
68 mbin
[ind
]+=atom
[jx
].m
;
76 void rdf_calc(char *fn
,char *pdens
, char *rdens
, char *ndens
,
77 real width
, int n1
,char *grp1
,atom_id index1
[],
78 int ngrps
,int n2
[],char **grpname
,atom_id
*index
[],
81 FILE *pout
,*rout
,*nout
;
83 real
**mbin
; /* keeps mass per bin */
86 int i
,j
,natoms
,status
,maxbin
;
90 if ((natoms
=read_first_x(&status
,fn
,&t
,&x0
,box
))==0)
91 fatal_error(0,"Could not read coordinates from statusfile\n");
93 hb2
=min(box
[XX
][XX
],min(box
[YY
][YY
],box
[ZZ
][ZZ
]))/2;
97 for(i
=0; (i
<ngrps
); i
++)
100 snew(mbin
[i
],maxbin
);
103 fprintf(stderr
,"maxbin = %d, hb2 = %g\n",maxbin
,hb2
);
108 fprintf(stderr
,"\rframe: %5d",j
);
110 /* Must init pbc every step because of pressure coupling */
113 calc_xcm(x0
,n1
,index1
,atom
,xcm
,FALSE
);
115 for(i
=0; (i
<ngrps
); i
++)
116 rdf_add(bin
[i
],mbin
[i
],width
,sqr(hb2
),x0
,xcm
,n2
[i
],index
[i
],
119 } while (read_next_x(status
,&t
,natoms
,x0
,box
));
120 fprintf(stderr
,"\n");
125 /* now bin is a mega array with the total nr. of atoms of each type
126 in each bin. bin*nf_1 is the nr. of atoms of each type in each bin
129 for(i
=0; (i
<ngrps
); i
++) {
130 sprintf(buf
,"prob:%s-%s.xvg",grp1
,grpname
[i
]);
131 pout
=xvgropen(buf
,"Radial Probability Plot","R (nm)","nm\\S-1\\N");
132 sprintf(buf
,"dens:%s-%s.xvg",grp1
,grpname
[i
]);
133 rout
=xvgropen(buf
,"Radial Density Plot","R (nm)","g cm\\S-3\\N");
134 sprintf(buf
,"ndens:%s-%s.xvg",grp1
,grpname
[i
]);
135 nout
=xvgropen(buf
,"Radial Number Density Plot","R (nm)","Atoms nm\\S-3\\N");
137 fprintf(pout
,"@ subtitle \"%s-%s\"\n",grpname
[0],grpname
[1]);
138 fprintf(nout
,"@ subtitle \"%s-%s\"\n",grpname
[0],grpname
[1]);
139 fprintf(rout
,"@ subtitle \"%s-%s\"\n",grpname
[0],grpname
[1]);
141 for(j
=0; (j
<maxbin
); j
++) {
142 fprintf(nout
,"%10g %10g\n",width
*j
,bin
[i
][j
]*nf_1
/
143 (4*M_PI
*width
*(j
+0.5)*width
*(j
+0.5)));
144 fprintf(pout
,"%10g %10g\n",width
*j
,bin
[i
][j
]*nf_1
);
145 fprintf(rout
,"%10g %10g\n",width
*j
,mbin
[i
][j
]*nf_1
/
146 (60.22*4*M_PI
*width
*(j
+0.5)*width
*(j
+0.5)));
148 fclose(nout
); fclose(pout
); fclose(rout
);
152 int main(int argc
,char *argv
[])
154 static char *desc
[] = {
155 "Compute radial densities across the box, in three flavors:"
156 "probability density, number density, real density"
158 static real width
=0.12;
160 { "-width", FALSE
, etREAL
, {&width
}, "bin width for radial axis" }
163 char *grp1
,**grpname
; /* groupnames */
164 int gnx1
,*gnx
; /* sizes of groups */
165 atom_id
*ind1
,**index
; /* indices for all groups */
167 t_topology
*top
; /* topology */
168 t_filenm fnm
[] = { /* files for g_order */
169 { efTRX
, "-f", NULL
, ffREAD
}, /* trajectory file */
170 { efNDX
, NULL
, NULL
, ffREAD
}, /* index file */
171 { efTPX
, NULL
, NULL
, ffREAD
}, /* topology file */
172 { efXVG
,"-op","p_rdens", ffWRITE
}, /* xvgr output: prob. dens. */
173 { efXVG
,"-on","n_rdens", ffWRITE
}, /* xvgr output: number. dens. */
174 { efXVG
,"-or","r_rdens", ffWRITE
}, /* xvgr output: real dens. */
177 #define NFILE asize(fnm)
179 CopyRight(stderr
,argv
[0]);
180 parse_common_args(&argc
,argv
,PCA_CAN_TIME
,TRUE
,NFILE
,fnm
,
181 asize(pa
),pa
,asize(desc
),desc
,0,NULL
);
183 top
= read_top(ftp2fn(efTPX
,NFILE
,fnm
)); /* read topology file */
184 fprintf(stderr
,"Choose first group for Center of Mass computation!\n");
186 fprintf(stderr
,"Select group for Center of Mass calculation:\n");
187 rd_index(ftp2fn(efNDX
,NFILE
,fnm
),1,&gnx1
,&ind1
,&grp1
);
189 fprintf(stderr
,"How many groups do you want to calc the density plot of?\n");
197 fprintf(stderr
,"Select groups for Density Plot:\n");
198 rd_index(ftp2fn(efNDX
,NFILE
,fnm
),ngrps
,gnx
,index
,grpname
);
200 rdf_calc(ftp2fn(efTRX
,NFILE
,fnm
),opt2fn("-op",NFILE
,fnm
),
201 opt2fn("-or",NFILE
,fnm
),opt2fn("-on",NFILE
,fnm
),
202 width
,gnx1
,grp1
,ind1
,ngrps
,gnx
,grpname
,index
,top
->atoms
.atom
);