Partial commit of the project to remove all static variables.
[gromacs.git] / src / contrib / sigeps.c
blob716e7aa0d0c466230656bdb9d48ff4ee4551f33b
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 3.1
11 * Copyright (c) 1991-2001, University of Groningen, The Netherlands
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * If you want to redistribute modifications, please consider that
18 * scientific software is very special. Version control is crucial -
19 * bugs must be traceable. We will be happy to consider code for
20 * inclusion in the official distribution, but derived work must not
21 * be called official GROMACS. Details are found in the README & COPYING
22 * files - if they are missing, get the official version at www.gromacs.org.
24 * To help us fund GROMACS development, we humbly ask that you cite
25 * the papers on the package - you can find them in the top README file.
27 * For more info, check our website at http://www.gromacs.org
29 * And Hey:
30 * Great Red Owns Many ACres of Sand
33 #include <stdio.h>
34 #include <math.h>
35 #include "typedefs.h"
36 #include "statutil.h"
37 #include "copyrite.h"
38 #include "fatal.h"
39 #include "xvgr.h"
40 #include "pdbio.h"
41 #include "macros.h"
42 #include "smalloc.h"
43 #include "vec.h"
44 #include "pbc.h"
45 #include "physics.h"
46 #include "names.h"
47 #include "txtdump.h"
48 #include "trnio.h"
49 #include "symtab.h"
50 #include "confio.h"
52 real pot(real x,real qq,real c6,real c12)
54 return c12*pow(x,-12)-c6*pow(x,-6)+qq*ONE_4PI_EPS0/x;
57 real dpot(real x,real qq,real c6,real c12)
59 return -(12*c12*pow(x,-13)-6*c6*pow(x,-7)+qq*ONE_4PI_EPS0/sqr(x));
62 int main(int argc,char *argv[])
64 static char *desc[] = {
65 "Plot the potential"
67 static real c6=1.0e-3,c12=1.0e-6,qi=1,qj=2,sig=0.3,eps=1,sigfac=0.7;
68 t_pargs pa[] = {
69 { "-c6", FALSE, etREAL, {&c6}, "c6" },
70 { "-c12", FALSE, etREAL, {&c12}, "c12" },
71 { "-sig", FALSE, etREAL, {&sig}, "sig" },
72 { "-eps", FALSE, etREAL, {&eps}, "eps" },
73 { "-qi", FALSE, etREAL, {&qi}, "qi" },
74 { "-qj", FALSE, etREAL, {&qj}, "qj" },
75 { "-sigfac", FALSE, etREAL, {&sigfac}, "Factor in front of sigma for starting the plot" }
77 t_filenm fnm[] = {
78 { efXVG, "-o", "potje", ffWRITE }
80 #define NFILE asize(fnm)
82 FILE *fp;
83 int i;
84 real qq,x,oldx,minimum,mval,dp[2],pp[2];
85 int cur=0;
86 #define next (1-cur)
88 /* CopyRight(stdout,argv[0]);*/
89 parse_common_args(&argc,argv,PCA_CAN_VIEW,
90 NFILE,fnm,asize(pa),pa,asize(desc),
91 desc,0,NULL);
93 if (opt2parg_bSet("-sig",asize(pa),pa) ||
94 opt2parg_bSet("-eps",asize(pa),pa)) {
95 c6 = 4*eps*pow(sig,6);
96 c12 = 4*eps*pow(sig,12);
98 else if ((c6 != 0) && (c12 != 0)) {
99 sig = pow(c12/c6,1.0/6.0);
100 eps = c6*c6/(4*c12);
102 else {
103 sig = eps = 0;
105 printf("c6 = %12.5e, c12 = %12.5e\n",c6,c12);
106 printf("sigma = %12.5f, epsilon = %12.5f\n",sig,eps);
107 qq = qi*qj;
109 fp = xvgropen(ftp2fn(efXVG,NFILE,fnm),"Potential","r (nm)","E (kJ/mol)");
110 if (sig == 0)
111 sig=0.25;
112 minimum = -1;
113 mval = 0;
114 oldx = 0;
115 for(i=0; (i<100); i++) {
116 x = sigfac*sig+sig*i*0.02;
117 dp[next] = dpot(x,qq,c6,c12);
118 fprintf(fp,"%10g %10g %10g\n",x,pot(x,qq,c6,c12),
119 dp[next]);
120 if ((i > 0) && (dp[cur]*dp[next] < 0)) {
121 minimum = oldx + dp[cur]*(x-oldx)/(dp[cur]-dp[next]);
122 mval = pot(minimum,qq,c6,c12);
123 /*fprintf(stdout,"dp[cur] = %g, dp[next] = %g oldx = %g, dx = %g\n",
124 dp[cur],dp[next],oldx,x-oldx);*/
125 printf("Minimum at r = %g (nm). Value = %g (kJ/mol)\n",
126 minimum,mval);
128 cur = next;
129 oldx = x;
132 fclose(fp);
134 do_view(ftp2fn(efXVG,NFILE,fnm),NULL);
136 thanx(stderr);
138 return 0;