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-2008, 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 * Groningen Machine for Chemical Simulation
46 #include "gmx_fatal.h"
57 t_histo *init_histo(int np,real minx,real maxx)
66 gmx_fatal(FARGS,"minx (%f) should be less than maxx (%f) in init_histo",minx,maxx);
69 h->dx_1 = np/(maxx-minx);
70 h->dx = (maxx-minx)/np;
75 void done_histo(t_histo *h)
82 void add_histo(t_histo *h,real x,real y)
86 n = (x-h->minx)*h->dx_1;
87 if ((n < 0) || (n > h->np))
88 gmx_fatal(FARGS,"Invalid x (%f) in add_histo. Should be in %f - %f",x,h->minx,h->maxx);
93 void dump_histo(t_histo *h,char *fn,char *title,char *xaxis,char *yaxis,
94 int enorm,real norm_fac)
99 for(nn=h->np; (nn > 0); nn--)
102 for(i=0; (i<nn); i++)
105 fp = xvgropen(fn,title,xaxis,yaxis);
106 for( ; (i<nn); i++) {
109 fprintf(fp,"%12f %12f %d\n",h->minx+h->dx*i,h->y[i],h->nh[i]);
112 fprintf(fp,"%12f %12f %d\n",h->minx+h->dx*i,h->y[i]*norm_fac,h->nh[i]);
116 fprintf(fp,"%12f %12f %d\n",
117 h->minx+h->dx*i,h->y[i]*norm_fac/h->nh[i],h->nh[i]);
120 gmx_fatal(FARGS,"Wrong value for enorm (%d)",enorm);
126 /*******************************************************************
128 * Functions to analyse and monitor scattering
130 *******************************************************************/
132 void add_scatter_event(t_ana_scat *scatter,rvec pos,gmx_bool bInel,
135 int np = scatter->np;
137 if (np == scatter->maxp) {
139 srenew(scatter->time,scatter->maxp);
140 srenew(scatter->ekin,scatter->maxp);
141 srenew(scatter->bInel,scatter->maxp);
142 srenew(scatter->pos,scatter->maxp);
144 scatter->time[np] = t;
145 scatter->bInel[np] = np;
146 scatter->ekin[np] = ekin;
147 copy_rvec(pos,scatter->pos[np]);
151 void reset_ana_scat(t_ana_scat *scatter)
156 void done_scatter(t_ana_scat *scatter)
159 sfree(scatter->time);
160 sfree(scatter->ekin);
161 sfree(scatter->bInel);
165 void analyse_scatter(t_ana_scat *scatter,t_histo *hmfp)
170 if (scatter->np > 1) {
171 for(i=1; (i<scatter->np); i++) {
172 rvec_sub(scatter->pos[i],scatter->pos[i-1],dx);
173 add_histo(hmfp,scatter->ekin[i],norm(dx));
178 /*******************************************************************
180 * Functions to analyse structural changes
182 *******************************************************************/
184 t_ana_struct *init_ana_struct(int nstep,int nsave,real timestep,
190 anal->nanal = 1.2*((nstep / nsave)+1);
192 anal->dt = nsave*timestep;
193 snew(anal->t,anal->nanal);
194 snew(anal->maxdist,anal->nanal);
195 snew(anal->d2_com,anal->nanal);
196 snew(anal->d2_origin,anal->nanal);
197 snew(anal->nion,anal->nanal);
200 anal->maxparticle = maxparticle;
203 snew(anal->x[0],maxparticle);
208 void done_ana_struct(t_ana_struct *anal)
213 sfree(anal->maxdist);
215 sfree(anal->d2_origin);
218 for(i=0; (i<anal->nstruct); i++)
223 void reset_ana_struct(t_ana_struct *anal)
227 for(i=0; (i<anal->nanal); i++) {
229 anal->maxdist[i] = 0;
230 clear_rvec(anal->d2_com[i]);
231 clear_rvec(anal->d2_origin[i]);
237 void add_ana_struct(t_ana_struct *total,t_ana_struct *add)
241 if (total->index == 0)
242 total->index = add->index;
243 else if (total->index != add->index)
244 gmx_fatal(FARGS,"Analysis incompatible (total: %d, add: %d) %s, %d",
245 total->index,add->index,__FILE__,__LINE__);
246 for(i=0; (i<total->index); i++) {
247 if (total->t[i] == 0)
248 total->t[i] = add->t[i];
249 else if (total->t[i] != add->t[i])
250 gmx_fatal(FARGS,"Inconsistent times in analysis (%f-%f) %s, %d",
251 total->t[i],add->t[i],__FILE__,__LINE__);
252 if (add->maxdist[i] > total->maxdist[i])
253 total->maxdist[i] = add->maxdist[i];
254 for(m=0; (m<DIM); m++) {
255 total->d2_com[i][m] += add->d2_com[i][m]/add->nion[i];
256 total->d2_origin[i][m] += add->d2_origin[i][m]/add->nion[i];
258 total->nion[i] += add->nion[i];
262 static void do_add_struct(t_ana_struct *anal,int nparticle,rvec x[])
266 if (nparticle > anal->nparticle) {
267 for(i=0; (i<anal->nstruct); i++) {
268 for(j=anal->nparticle; (j<nparticle); j++)
269 copy_rvec(x[j],anal->x[i][j]);
272 anal->nparticle=nparticle;
273 srenew(anal->x,anal->nstruct+1);
274 snew(anal->x[anal->nstruct],anal->maxparticle);
275 for(j=0; (j<nparticle); j++)
276 copy_rvec(x[j],anal->x[anal->nstruct][j]);
280 void analyse_structure(t_ana_struct *anal,real t,rvec center,
281 rvec x[],int nparticle,real charge[])
288 if (j >= anal->nanal)
289 gmx_fatal(FARGS,"Too many points in analyse_structure");
291 anal->maxdist[j] = 0;
294 for(i=0; (i<nparticle); i++) {
303 for(i=0; (i<nparticle); i++) {
305 rvec_sub(x[i],com,dx);
306 for(m=0; (m<DIM); m++) {
307 anal->d2_com[j][m] += sqr(dx[m]);
308 anal->d2_origin[j][m] += sqr(x[i][m]);
310 dx2 = iprod(x[i],x[i]);
312 if (dx1 > anal->maxdist[j])
313 anal->maxdist[j] = dx1;
317 do_add_struct(anal,nparticle,x);
322 void dump_ana_struct(char *rmax,char *nion,char *gyr_com,char *gyr_origin,
323 t_ana_struct *anal,int nsim)
325 FILE *fp,*gp,*hp,*kp;
328 char *legend[] = { "Rg", "RgX", "RgY", "RgZ" };
330 fp = xvgropen(rmax,"rmax","Time (fs)","r (nm)");
331 gp = xvgropen(nion,"N ion","Time (fs)","N ions");
332 hp = xvgropen(gyr_com,"Radius of gyration wrt. C.O.M.",
333 "Time (fs)","Rg (nm)");
334 xvgr_legend(hp,asize(legend),legend);
335 kp = xvgropen(gyr_origin,"Radius of gyration wrt. Origin",
336 "Time (fs)","Rg (nm)");
337 xvgr_legend(kp,asize(legend),legend);
338 for(i=0; (i<anal->index); i++) {
340 fprintf(fp,"%12g %10.3f\n",t,anal->maxdist[i]);
341 fprintf(gp,"%12g %10.3f\n",t,(1.0*anal->nion[i])/nsim-1);
342 d2 = anal->d2_com[i][XX] + anal->d2_com[i][YY] + anal->d2_com[i][ZZ];
343 fprintf(hp,"%12g %10.3f %10.3f %10.3f %10.3f\n",
345 sqrt(anal->d2_com[i][XX]/nsim),
346 sqrt(anal->d2_com[i][YY]/nsim),
347 sqrt(anal->d2_com[i][ZZ]/nsim));
348 d2 = anal->d2_origin[i][XX] + anal->d2_origin[i][YY] + anal->d2_origin[i][ZZ];
349 fprintf(kp,"%12g %10.3f %10.3f %10.3f %10.3f\n",
351 sqrt(anal->d2_origin[i][XX]/nsim),
352 sqrt(anal->d2_origin[i][YY]/nsim),
353 sqrt(anal->d2_origin[i][ZZ]/nsim));
361 void dump_as_pdb(char *pdb,t_ana_struct *anal)
367 kp = ffopen(pdb,"w");
368 for(i=0; (i<anal->nstruct); i++) {
370 fprintf(kp,"MODEL %d time %g fs\n",i+1,t);
371 for(j=0; (j<anal->nparticle); j++) {
372 fprintf(kp,get_pdbformat(),"ATOM",i+1,(j < anal->nion[i]) ? "O" : "N",
374 anal->x[i][j][XX]/100,
375 anal->x[i][j][YY]/100,
376 anal->x[i][j][ZZ]/100);
379 fprintf(kp,"ENDMDL\n");
385 "Coulomb", "Repulsion", "Potential",
386 "EkHole", "EkElectron", "EkLattice", "Kinetic",
390 void add_ana_ener(t_ana_ener *ae,int nn,real e[])
394 /* First time around we are constantly increasing the array size */
396 if (ae->nx == ae->maxx) {
398 srenew(ae->e,ae->maxx);
400 for(i=0; (i<eNR); i++)
401 ae->e[ae->nx][i] = e[i];
405 for(i=0; (i<eNR); i++)
406 ae->e[nn][i] += e[i];
410 void dump_ana_ener(t_ana_ener *ae,int nsim,real dt,char *edump,
417 fac = 1.0/(nsim*ELECTRONVOLT);
418 fp=xvgropen(edump,"Energies","Time (fs)","E (eV)");
419 xvgr_legend(fp,eNR,enms);
420 fprintf(fp,"@ s%d legend \"Ek/Nelec\"\n",eNR);
421 fprintf(fp,"@ type nxy\n");
422 for(i=0; (i<ae->nx); i++) {
423 fprintf(fp,"%10f",1000.0*dt*i);
424 for(j=0; (j<eNR); j++)
425 fprintf(fp," %8.3f",ae->e[i][j]*fac);
426 fprintf(fp," %8.3f\n",ae->e[i][eELECTRON]/(ELECTRONVOLT*total->nion[i]));