2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
38 /* This file is completely threadsafe - keep it that way! */
49 static void upd_vir(rvec vir,real dvx,real dvy,real dvz)
56 void calc_vir(FILE *log,int nxf,rvec x[],rvec f[],tensor vir,
57 gmx_bool bScrewPBC,matrix box)
60 double dvxx=0,dvxy=0,dvxz=0,dvyx=0,dvyy=0,dvyz=0,dvzx=0,dvzy=0,dvzz=0;
62 for(i=0; (i<nxf); i++) {
63 dvxx+=x[i][XX]*f[i][XX];
64 dvxy+=x[i][XX]*f[i][YY];
65 dvxz+=x[i][XX]*f[i][ZZ];
67 dvyx+=x[i][YY]*f[i][XX];
68 dvyy+=x[i][YY]*f[i][YY];
69 dvyz+=x[i][YY]*f[i][ZZ];
71 dvzx+=x[i][ZZ]*f[i][XX];
72 dvzy+=x[i][ZZ]*f[i][YY];
73 dvzz+=x[i][ZZ]*f[i][ZZ];
77 /* We should correct all odd x-shifts, but the range of isx is -2 to 2 */
78 if (isx == 1 || isx == -1) {
79 dvyy += box[YY][YY]*f[i][YY];
80 dvyz += box[YY][YY]*f[i][ZZ];
82 dvzy += box[ZZ][ZZ]*f[i][YY];
83 dvzz += box[ZZ][ZZ]*f[i][ZZ];
88 upd_vir(vir[XX],dvxx,dvxy,dvxz);
89 upd_vir(vir[YY],dvyx,dvyy,dvyz);
90 upd_vir(vir[ZZ],dvzx,dvzy,dvzz);
94 static void lo_fcv(int i0,int i1,
95 real x[],real f[],tensor vir,
96 int is[],real box[], gmx_bool bTriclinic)
100 real dvxx=0,dvxy=0,dvxz=0,dvyx=0,dvyy=0,dvyz=0,dvzx=0,dvzy=0,dvzz=0;
103 for(i=i0; (i<i1); i++) {
109 xx=x[i3+XX]-tx*box[XXXX]-ty*box[YYXX]-tz*box[ZZXX];
114 yy=x[i3+YY]-ty*box[YYYY]-tz*box[ZZYY];
119 zz=x[i3+ZZ]-tz*box[ZZZZ];
125 for(i=i0; (i<i1); i++) {
131 xx=x[i3+XX]-tx*box[XXXX];
136 yy=x[i3+YY]-ty*box[YYYY];
141 zz=x[i3+ZZ]-tz*box[ZZZZ];
148 upd_vir(vir[XX],dvxx,dvxy,dvxz);
149 upd_vir(vir[YY],dvyx,dvyy,dvyz);
150 upd_vir(vir[ZZ],dvzx,dvzy,dvzz);
153 static void lo_fcv2(int i0,int i1,
154 rvec x[],rvec f[],tensor vir,
155 ivec is[],matrix box, gmx_bool bTriclinic)
159 real dvxx=0,dvxy=0,dvxz=0,dvyx=0,dvyy=0,dvyz=0,dvzx=0,dvzy=0,dvzz=0;
162 for(i=i0,gg=0; (i<i1); i++,gg++) {
167 xx=x[i][XX]-tx*box[XX][XX]-ty*box[YY][XX]-tz*box[ZZ][XX];
172 yy=x[i][YY]-ty*box[YY][YY]-tz*box[ZZ][YY];
177 zz=x[i][ZZ]-tz*box[ZZ][ZZ];
183 for(i=i0,gg=0; (i<i1); i++,gg++) {
188 xx=x[i][XX]-tx*box[XX][XX];
193 yy=x[i][YY]-ty*box[YY][YY];
198 zz=x[i][ZZ]-tz*box[ZZ][ZZ];
205 upd_vir(vir[XX],dvxx,dvxy,dvxz);
206 upd_vir(vir[YY],dvyx,dvyy,dvyz);
207 upd_vir(vir[ZZ],dvzx,dvzy,dvzz);
210 void f_calc_vir(FILE *log,int i0,int i1,rvec x[],rvec f[],tensor vir,
211 t_graph *g,matrix box)
215 if (g && (g->nnodes > 0)) {
216 /* Calculate virial for bonded forces only when they belong to
219 start = max(i0,g->at_start);
220 end = min(i1,g->at_end);
222 lo_fcv2(start,end,x,f,vir,g->ishift,box,TRICLINIC(box));
224 lo_fcv(start,end,x[0],f[0],vir,g->ishift[0],box[0],TRICLINIC(box));
227 /* If not all atoms are bonded, calculate their virial contribution
228 * anyway, without shifting back their coordinates.
229 * Note the nifty pointer arithmetic...
232 calc_vir(log,start-i0,x + i0,f + i0,vir,FALSE,box);
234 calc_vir(log,i1-end,x + end,f + end,vir,FALSE,box);
237 calc_vir(log,i1-i0,x + i0,f + i0,vir,FALSE,box);