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-2004, 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 * Green Red Orange Magenta Azure Cyan Skyblue
43 #include "gmx_fatal.h"
62 static void index_atom2mol(int *n
,atom_id
*index
,t_block
*mols
)
71 while (index
[i
] > mols
->index
[mol
]) {
74 gmx_fatal(FARGS
,"Atom index out of range: %d",index
[i
]+1);
76 for(j
=mols
->index
[mol
]; j
<mols
->index
[mol
+1]; j
++) {
77 if (i
>= nat
|| index
[i
] != j
)
78 gmx_fatal(FARGS
,"The index group does not consist of whole molecules");
84 fprintf(stderr
,"\nSplit group of %d atoms into %d molecules\n",nat
,nmol
);
89 static void precalc(t_topology top
,real normm
[]){
94 for(i
=0;i
<top
.mols
.nr
;i
++){
96 l
=top
.mols
.index
[i
+1];
100 mtot
+=top
.atoms
.atom
[j
].m
;
103 normm
[j
]=top
.atoms
.atom
[j
].m
/mtot
;
111 int gmx_velacc(int argc
,char *argv
[])
113 const char *desc
[] = {
114 "g_velacc computes the velocity autocorrelation function.",
115 "When the [TT]-m[tt] option is used, the momentum autocorrelation",
116 "function is calculated.[PAR]",
117 "With option [TT]-mol[tt] the velocity autocorrelation function of",
118 "molecules is calculated. In this case the index group should consist",
119 "of molecule numbers instead of atom numbers."
122 static bool bM
=FALSE
,bMol
=FALSE
;
124 { "-m", FALSE
, etBOOL
, {&bM
},
125 "Calculate the momentum autocorrelation function" },
126 { "-mol", FALSE
, etBOOL
, {&bMol
},
127 "Calculate the velocity acf of molecules" }
134 bool bTPS
=FALSE
,bTop
=FALSE
;
140 int status
,teller
,n_alloc
,i
,j
,tel3
,k
,l
;
149 { efTRN
, "-f", NULL
, ffREAD
},
150 { efTPS
, NULL
, NULL
, ffOPTRD
},
151 { efNDX
, NULL
, NULL
, ffOPTRD
},
152 { efXVG
, "-o", "vac", ffWRITE
}
154 #define NFILE asize(fnm)
158 CopyRight(stderr
,argv
[0]);
160 ppa
= add_acf_pargs(&npargs
,pa
);
161 parse_common_args(&argc
,argv
,PCA_CAN_VIEW
| PCA_CAN_TIME
| PCA_BE_NICE
,
162 NFILE
,fnm
,npargs
,ppa
,asize(desc
),desc
,0,NULL
,&oenv
);
165 bTPS
= bM
|| ftp2bSet(efTPS
,NFILE
,fnm
) || !ftp2bSet(efNDX
,NFILE
,fnm
);
168 bTop
=read_tps_conf(ftp2fn(efTPS
,NFILE
,fnm
),title
,&top
,&ePBC
,NULL
,NULL
,box
,
170 get_index(&top
.atoms
,ftp2fn_null(efNDX
,NFILE
,fnm
),1,&gnx
,&index
,&grpname
);
172 rd_index(ftp2fn(efNDX
,NFILE
,fnm
),1,&gnx
,&index
,&grpname
);
176 gmx_fatal(FARGS
,"Need a topology to determine the molecules");
177 snew(normm
,top
.atoms
.nr
);
179 index_atom2mol(&gnx
,index
,&top
.mols
);
182 /* Correlation stuff */
184 for(i
=0; (i
<gnx
); i
++)
187 read_first_frame(oenv
,&status
,ftp2fn(efTRN
,NFILE
,fnm
),&fr
,TRX_NEED_V
);
193 if (teller
>= n_alloc
) {
196 srenew(c1
[i
],DIM
*n_alloc
);
200 for(i
=0; i
<gnx
; i
++) {
202 k
=top
.mols
.index
[index
[i
]];
203 l
=top
.mols
.index
[index
[i
]+1];
206 m
= top
.atoms
.atom
[j
].m
;
209 mv_mol
[XX
] += m
*fr
.v
[j
][XX
];
210 mv_mol
[YY
] += m
*fr
.v
[j
][YY
];
211 mv_mol
[ZZ
] += m
*fr
.v
[j
][ZZ
];
213 c1
[i
][tel3
+XX
]=mv_mol
[XX
];
214 c1
[i
][tel3
+YY
]=mv_mol
[YY
];
215 c1
[i
][tel3
+ZZ
]=mv_mol
[ZZ
];
218 for(i
=0; i
<gnx
; i
++) {
220 m
= top
.atoms
.atom
[index
[i
]].m
;
223 c1
[i
][tel3
+XX
]=m
*fr
.v
[index
[i
]][XX
];
224 c1
[i
][tel3
+YY
]=m
*fr
.v
[index
[i
]][YY
];
225 c1
[i
][tel3
+ZZ
]=m
*fr
.v
[index
[i
]][ZZ
];
231 } while (read_next_frame(oenv
,status
,&fr
));
235 do_autocorr(ftp2fn(efXVG
,NFILE
,fnm
), oenv
,
237 "Momentum Autocorrelation Function" :
238 "Velocity Autocorrelation Function",
239 teller
,gnx
,c1
,(t1
-t0
)/(teller
-1),eacVector
,TRUE
);
241 do_view(oenv
,ftp2fn(efXVG
,NFILE
,fnm
),"-nxy");