Merge branch 'master' of git://git.gromacs.org/gromacs
[gromacs/adressmacs.git] / src / kernel / ffscan.c
blobbc72dbe6a1c81ba52d4ac7858d4de293d604b949
1 /*
2 *
3 * This source code is part of
4 *
5 * G R O M A C S
6 *
7 * GROningen MAchine for Chemical Simulations
8 *
9 * VERSION 3.2.0
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
32 * And Hey:
33 * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
39 #include <math.h>
40 #include "typedefs.h"
41 #include "macros.h"
42 #include "copyrite.h"
43 #include "main.h"
44 #include "statutil.h"
45 #include "futil.h"
46 #include "smalloc.h"
47 #include "string2.h"
48 #include "edsam.h"
49 #include "mdrun.h"
50 #include "strdb.h"
51 #include "index.h"
52 #include "xmdrun.h"
53 #include "vec.h"
55 int main(int argc,char *argv[])
57 static char *desc[] = {
58 "The ffscan program performs a single point energy and force calculation",
59 "in which the force field is modified. This way a range of parameters can",
60 "be changed and tested for reproduction of e.g. quantum chemical or",
61 "experimental data. A grid scan over the parameters is done as specified",
62 "using command line arguments. All parameters that reproduce the energy",
63 "within a given absolute tolerance are printed to a log file.[PAR]",
64 "Obviously polarizable models can be used, and shell optimisation is",
65 "performed if necessary. Also, like in mdrun table functions can be used",
66 "for user defined potential functions.[PAR]",
67 "If the option -ga with appropriate file is passed, a genetic algorithm will",
68 "be used rather than a grid scan."
70 t_commrec *cr;
71 static t_filenm fnm[] = {
72 { efTPX, NULL, NULL, ffREAD },
73 { efLOG, "-g", "md", ffWRITE },
74 { efXVG, "-table", "table", ffOPTRD },
75 { efDAT, "-parm", "params", ffREAD },
76 { efDAT, "-ga", "genalg", ffOPTRD },
77 { efGRO, "-c", "junk", ffWRITE },
78 { efEDR, "-e", "junk", ffWRITE },
79 { efTRN, "-o", "junk", ffWRITE }
81 #define NFILE asize(fnm)
83 /* Command line options ! */
84 static t_ffscan ff = {
85 /* tol */ 0.1,
86 /* f_max */ 100.0,
87 /* npow */ 12.0,
88 /* epot */ 0.0,
89 /* fac_epot */ 1.0,
90 /* fac_pres */ 0.1,
91 /* fac_msf */ 0.1,
92 /* pres */ 1.0,
93 /* molsize */ 1,
94 /* nmol */ 1,
95 /* bComb */ TRUE,
96 /* bVerbose */ FALSE,
97 /* bLogEps */ FALSE
99 static char *loadx=NULL,*loady=NULL,*loadz=NULL;
100 static t_pargs pa[] = {
101 { "-tol", FALSE, etREAL, {&ff.tol}, "Energy tolerance (kJ/mol) (zero means everything is printed)" },
102 { "-fmax", FALSE, etREAL, {&ff.f_max}, "Force tolerance (zero means everything is printed)" },
103 { "-comb", FALSE, etBOOL, {&ff.bComb}, "Use combination rules" },
104 { "-npow", FALSE, etREAL, {&ff.npow}, "Power for LJ in case of table use" },
105 { "-logeps",FALSE, etBOOL, {&ff.bLogEps}, "Use a logarithmic scale for epsilon" },
106 { "-v", FALSE, etBOOL, {&ff.bVerbose}, "Be loud and noisy" },
107 { "-epot", FALSE, etREAL, {&ff.epot}, "Target energy (kJ/mol)" },
108 { "-fepot", FALSE, etREAL, {&ff.fac_epot}, "Factor for scaling energy violations (0 turns energy contribution off)" },
109 { "-pres", FALSE, etREAL, {&ff.pres}, "Value for reference pressure" },
110 { "-fpres", FALSE, etREAL, {&ff.fac_pres}, "Factor for scaling pressure violations (0 turns pressure contribution off)" },
111 { "-fmsf", FALSE, etREAL, {&ff.fac_msf}, "Factor for scaling mean square force violations (0 turns MSF contribution off)" },
112 { "-molsize",FALSE,etINT, {&ff.molsize}, "Number of atoms per molecule" },
113 { "-nmol", FALSE, etINT, {&ff.nmol}, "Number of molecules (Epot is divided by this value!)" }
115 #define NPA asize(pa)
116 unsigned long Flags = 0;
117 gmx_edsam_t ed=NULL;
118 FILE *fplog;
120 ivec ddxyz = { 1,1,1 };
122 cr = init_par(&argc,&argv);
124 ff.bVerbose = ff.bVerbose && MASTER(cr);
125 #if 0
126 snew(ed,1);
127 ed->eEDtype=eEDnone;
128 #endif
130 if (MASTER(cr))
131 CopyRight(stderr,argv[0]);
133 parse_common_args(&argc,argv,PCA_BE_NICE,NFILE,fnm,
134 NPA,pa,asize(desc),desc,0,NULL);
136 if (ff.npow <= 6.0)
137 gmx_fatal(FARGS,"Can not have repulsion with smaller exponent than 6");
138 if (ff.nmol < 1)
139 gmx_fatal(FARGS,"Can not fit %d molecules",ff.nmol);
141 gmx_log_open(ftp2fn(efLOG,NFILE,fnm),cr,FALSE,0,&fplog);
143 if (MASTER(cr)) {
144 CopyRight(fplog,argv[0]);
145 please_cite(fplog,"Lindahl2001a");
146 please_cite(fplog,"Berendsen95a");
149 set_ffvars(&ff);
151 Flags = (Flags | MD_FFSCAN);
153 mdrunner(fplog,cr,NFILE,fnm,ff.bVerbose,FALSE,
154 ddxyz,0,0,0,loadx,loady,loadz,1,
155 0,0,Flags);
156 if (gmx_parallel_env_initialized())
157 gmx_finalize(cr);
159 gmx_log_close(fplog);
161 return 0;