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 * Green Red Orange Magenta Azure Cyan Skyblue
33 static char *SRCID_shift_util_h = "$Id$";
44 /* Routines to set global constants for speeding up the calculation
45 * of potentials, forces and gk-values.
47 extern void set_shift_consts(FILE *log,real r1,real rc,rvec box,t_forcerec *fr);
49 extern real gk(real k,real rc,real r1);
50 /* Compute the Ghat function for a single k-value */
52 extern real gknew(real k,real rc,real r1);
53 /* Compute the (new!) Ghat function for a single k-value */
55 extern void pr_scalar_gk(char *fn,int nx,int ny,int nz,rvec box,real ***ghat);
57 extern real calc_dx2(rvec xi,rvec xj,rvec box);
59 extern void calc_dx(rvec xi,rvec xj,rvec box,rvec dx);
61 extern real phi_sr(FILE *log,int nj,rvec x[],real charge[],real rc,real r1,
62 rvec box,real phi[],t_block *excl,rvec f_sr[],bool bOld);
64 extern real shiftfunction(real r1,real rc,real R);
66 extern real spreadfunction(real r1,real rc,real R);
68 extern real potential(real r1,real rc,real R);
70 extern void calc_ener(FILE *fp,char *title,bool bHeader,
72 real phi[],real charge[],t_block *excl);
74 extern real shift_LRcorrection(FILE *fp,t_nsborder *nsb,
75 t_commrec *cr,t_forcerec *fr,
76 real charge[],t_block *excl,rvec x[],
77 bool bOld,matrix box,matrix lrvir);
78 /* Calculate the self energy and forces
79 * when using long range electrostatics methods.
80 * Part of this is a constant, it is computed only once and stored in
81 * a local variable. The remainder is computed every step.
82 * PBC is taken into account. (Erik L.)
85 extern void calc_weights(int iatom,int nx,int ny,int nz,
86 rvec x,rvec box,rvec invh,ivec ixyz,real WXYZ[]);
88 static void calc_lll(rvec box,rvec lll)
90 lll[XX] = 2.0*M_PI/box[XX];
91 lll[YY] = 2.0*M_PI/box[YY];
92 lll[ZZ] = 2.0*M_PI/box[ZZ];
95 static void calc_k(rvec lll,int ix,int iy,int iz,int nx,int ny,int nz,rvec k)
97 #define IDX(i,n,x) (i<=n/2) ? (i*x) : ((i-n)*x)
98 k[XX] = IDX(ix,nx,lll[XX]);
99 k[YY] = IDX(iy,ny,lll[YY]);
100 k[ZZ] = IDX(iz,nz,lll[ZZ]);
104 /******************************************************************
106 * PLOTTING ROUTINES FOR DEBUGGING
108 ******************************************************************/
110 extern void plot_phi(char *fn,rvec box,int natoms,rvec x[],real phi[]);
111 /* Plot potential (or whatever) in a postscript matrix */
113 extern void print_phi(char *fn,int natoms,rvec x[],real phi[]);
114 /* Print to a text file in x y phi format */
116 extern void plot_qtab(char *fn,int nx,int ny,int nz,real ***qtab);
117 /* Plot a charge table to a postscript matrix */
119 extern void write_grid_pqr(char *fn,int nx,int ny,int nz,real ***phi);
120 extern void write_pqr(char *fn,t_atoms *atoms,rvec x[],real phi[],real dx);
121 /* Write a pdb file where the potential phi is printed as B-factor (for
122 * viewing with rasmol). All atoms are moved over a distance dx in the X
123 * direction, to enable viewing of two data sets simultaneously with rasmol
126 /******************************************************************
128 * ROUTINES FOR GHAT MANIPULATION
130 ******************************************************************/
132 extern void symmetrize_ghat(int nx,int ny,int nz,real ***ghat);
133 /* Symmetrize the Ghat function. It is assumed that the
134 * first octant of the Ghat function is either read or generated
135 * (all k-vectors from 0..nx/2 0..ny/2 0..nz/2).
136 * Since Gk depends on the absolute value of k only,
137 * symmetry operations may shorten the time to generate it.
140 extern void mk_ghat(FILE *fp,int nx,int ny,int nz,real ***ghat,
141 rvec box,real r1,real rc,bool bSym,bool bOld);
142 /* Generate a Ghat function from scratch. The ghat grid should
143 * be allocated using the mk_rgrid function. When bSym, only
144 * the first octant of the function is generated by direct calculation
145 * and the above mentioned function is called for computing the rest.
146 * When !bOld a new experimental function form will be used.
149 extern real ***rd_ghat(FILE *log,char *fn,ivec igrid,rvec gridspacing,
150 rvec beta,int *porder,real *rshort,real *rlong);
151 /* Read a Ghat function from a file as generated by the program
152 * mk_ghat. The grid size (number of grid points) is returned in
153 * igrid, the space between grid points in gridspacing,
154 * beta is a constant that determines the contribution of first
155 * and second neighbours in the grid to the force
156 * (See Luty et al. JCP 103 (1995) 3014)
157 * porder determines whether 8 (when porder = 1) or 27 (when
158 * porder = 2) neighbouring grid points are used for spreading
160 * rshort and rlong are the lengths used for generating the Ghat
164 extern void wr_ghat(char *fn,int n1max,int n2max,int n3max,real h1,
165 real h2,real h3,real ***ghat,int nalias,
166 int porder,int niter,bool bSym,rvec beta,
167 real r1,real rc,real pval,real zval,real eref,real qopt);
168 /* Write a ghat file. (see above) */
170 extern void pr_scalar_gk(char *fn,int nx,int ny,int nz,rvec box,real ***ghat);
172 extern real analyse_diff(FILE *log,char *label,
173 int natom,rvec ffour[],rvec fpppm[],
174 real phi_f[],real phi_p[],real phi_sr[],
175 char *fcorr,char *pcorr,
176 char *ftotcorr,char *ptotcorr);
177 /* Analyse difference between forces from fourier (_f) and other (_p)
178 * LR solvers (and potential also).
179 * If the filenames are given, xvgr files are written.
180 * returns the root mean square error in the force.