added mdp parameter for FE dH tables
[gromacs.git] / src / kernel / readir.c
blob815dfff7a9050e862e97ab22f6f51531f8577656
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
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.2.0
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
33 * And Hey:
34 * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
40 #include <ctype.h>
41 #include <stdlib.h>
42 #include <limits.h>
43 #include "sysstuff.h"
44 #include "smalloc.h"
45 #include "typedefs.h"
46 #include "physics.h"
47 #include "names.h"
48 #include "gmx_fatal.h"
49 #include "macros.h"
50 #include "index.h"
51 #include "symtab.h"
52 #include "string2.h"
53 #include "readinp.h"
54 #include "warninp.h"
55 #include "readir.h"
56 #include "toputil.h"
57 #include "index.h"
58 #include "network.h"
59 #include "vec.h"
60 #include "pbc.h"
61 #include "mtop_util.h"
62 #include "chargegroup.h"
64 #define MAXPTR 254
65 #define NOGID 255
67 /* Resource parameters
68 * Do not change any of these until you read the instruction
69 * in readinp.h. Some cpp's do not take spaces after the backslash
70 * (like the c-shell), which will give you a very weird compiler
71 * message.
74 static char tcgrps[STRLEN],tau_t[STRLEN],ref_t[STRLEN],
75 acc[STRLEN],accgrps[STRLEN],freeze[STRLEN],frdim[STRLEN],
76 energy[STRLEN],user1[STRLEN],user2[STRLEN],vcm[STRLEN],xtc_grps[STRLEN],
77 couple_moltype[STRLEN],orirefitgrp[STRLEN],egptable[STRLEN],egpexcl[STRLEN],
78 wall_atomtype[STRLEN],wall_density[STRLEN],deform[STRLEN],QMMM[STRLEN];
79 static char foreign_lambda[STRLEN];
80 static char **pull_grp;
81 static char anneal[STRLEN],anneal_npoints[STRLEN],
82 anneal_time[STRLEN],anneal_temp[STRLEN];
83 static char QMmethod[STRLEN],QMbasis[STRLEN],QMcharge[STRLEN],QMmult[STRLEN],
84 bSH[STRLEN],CASorbitals[STRLEN], CASelectrons[STRLEN],SAon[STRLEN],
85 SAoff[STRLEN],SAsteps[STRLEN],bTS[STRLEN],bOPT[STRLEN];
86 static char efield_x[STRLEN],efield_xt[STRLEN],efield_y[STRLEN],
87 efield_yt[STRLEN],efield_z[STRLEN],efield_zt[STRLEN];
89 enum { egrptpALL, egrptpALL_GENREST, egrptpPART, egrptpONE };
92 /* Minimum number of time steps required for accurate coupling integration
93 * of first and second order thermo- and barostats:
95 int nstcmin1 = 10;
96 int nstcmin2 = 20;
99 void init_ir(t_inputrec *ir, t_gromppopts *opts)
101 snew(opts->include,STRLEN);
102 snew(opts->define,STRLEN);
105 static void _low_check(bool b,char *s,warninp_t wi)
107 if (b)
109 warning_error(wi,s);
113 static void check_nst(const char *desc_nst,int nst,
114 const char *desc_p,int *p,
115 warninp_t wi)
117 char buf[STRLEN];
119 if (*p > 0 && *p % nst != 0)
121 /* Round up to the next multiple of nst */
122 *p = ((*p)/nst + 1)*nst;
123 sprintf(buf,"%s should be a multiple of %s, changing %s to %d\n",
124 desc_p,desc_nst,desc_p,*p);
125 warning(wi,buf);
129 static bool ir_NVE(const t_inputrec *ir)
131 return ((ir->eI == eiMD || EI_VV(ir->eI)) && ir->etc == etcNO);
134 void check_ir(const char *mdparin,t_inputrec *ir, t_gromppopts *opts,
135 warninp_t wi)
136 /* Check internal consistency */
138 /* Strange macro: first one fills the err_buf, and then one can check
139 * the condition, which will print the message and increase the error
140 * counter.
142 #define CHECK(b) _low_check(b,err_buf,wi)
143 char err_buf[256],warn_buf[STRLEN];
144 int ns_type=0;
145 real dt_coupl=0;
146 int nstcmin;
148 set_warning_line(wi,mdparin,-1);
150 /* BASIC CUT-OFF STUFF */
151 if (ir->rlist == 0 ||
152 !((EEL_MIGHT_BE_ZERO_AT_CUTOFF(ir->coulombtype) && ir->rcoulomb > ir->rlist) ||
153 (EVDW_MIGHT_BE_ZERO_AT_CUTOFF(ir->vdwtype) && ir->rvdw > ir->rlist))) {
154 /* No switched potential and/or no twin-range:
155 * we can set the long-range cut-off to the maximum of the other cut-offs.
157 ir->rlistlong = max_cutoff(ir->rlist,max_cutoff(ir->rvdw,ir->rcoulomb));
158 } else if (ir->rlistlong < 0) {
159 ir->rlistlong = max_cutoff(ir->rlist,max_cutoff(ir->rvdw,ir->rcoulomb));
160 sprintf(warn_buf,"rlistlong was not set, setting it to %g (no buffer)",
161 ir->rlistlong);
162 warning(wi,warn_buf);
164 if (ir->rlistlong == 0 && ir->ePBC != epbcNONE) {
165 warning_error(wi,"Can not have an infinite cut-off with PBC");
167 if (ir->rlistlong > 0 && (ir->rlist == 0 || ir->rlistlong < ir->rlist)) {
168 warning_error(wi,"rlistlong can not be shorter than rlist");
170 if (IR_TWINRANGE(*ir) && ir->nstlist <= 0) {
171 warning_error(wi,"Can not have nstlist<=0 with twin-range interactions");
174 /* GENERAL INTEGRATOR STUFF */
175 if (!(ir->eI == eiMD || EI_VV(ir->eI)))
177 ir->etc = etcNO;
179 if (!EI_DYNAMICS(ir->eI))
181 ir->epc = epcNO;
183 if (EI_DYNAMICS(ir->eI))
185 if (ir->nstcalcenergy < 0)
187 if (EI_VV(ir->eI))
189 /* VV coupling algorithms currently only support 1 */
190 ir->nstcalcenergy = 1;
192 else
194 if (ir->nstlist > 0)
196 ir->nstcalcenergy = ir->nstlist;
198 else
200 ir->nstcalcenergy = 10;
204 if (ir->etc != etcNO || ir->epc != epcNO)
206 if (ir->nstcalcenergy == 0)
208 gmx_fatal(FARGS,"Can not have nstcalcenergy=0 with global T/P-coupling");
210 if (EI_VV(ir->eI))
212 sprintf(err_buf,"T- and P-coupling with VV integrators currently only supports nstcalcenergy=1");
213 CHECK(ir->nstcalcenergy > 1);
216 if (IR_TWINRANGE(*ir))
218 check_nst("nstlist",ir->nstlist,
219 "nstcalcenergy",&ir->nstcalcenergy,wi);
221 dt_coupl = ir->nstcalcenergy*ir->delta_t;
223 if (ir->nstcalcenergy > 1)
225 /* for storing exact averages nstenergy should be
226 * a multiple of nstcalcenergy
228 check_nst("nstcalcenergy",ir->nstcalcenergy,
229 "nstenergy",&ir->nstenergy,wi);
230 if (ir->efep != efepNO)
232 /* nstdhdl should be a multiple of nstcalcenergy */
233 check_nst("nstcalcenergy",ir->nstcalcenergy,
234 "nstdhdl",&ir->nstdhdl,wi);
239 /* LD STUFF */
240 if ((EI_SD(ir->eI) || ir->eI == eiBD) &&
241 ir->bContinuation && ir->ld_seed != -1) {
242 warning_note(wi,"You are doing a continuation with SD or BD, make sure that ld_seed is different from the previous run (using ld_seed=-1 will ensure this)");
245 /* TPI STUFF */
246 if (EI_TPI(ir->eI)) {
247 sprintf(err_buf,"TPI only works with pbc = %s",epbc_names[epbcXYZ]);
248 CHECK(ir->ePBC != epbcXYZ);
249 sprintf(err_buf,"TPI only works with ns = %s",ens_names[ensGRID]);
250 CHECK(ir->ns_type != ensGRID);
251 sprintf(err_buf,"with TPI nstlist should be larger than zero");
252 CHECK(ir->nstlist <= 0);
253 sprintf(err_buf,"TPI does not work with full electrostatics other than PME");
254 CHECK(EEL_FULL(ir->coulombtype) && !EEL_PME(ir->coulombtype));
257 /* SHAKE / LINCS */
258 if ( (opts->nshake > 0) && (opts->bMorse) ) {
259 sprintf(warn_buf,
260 "Using morse bond-potentials while constraining bonds is useless");
261 warning(wi,warn_buf);
264 sprintf(err_buf,"shake_tol must be > 0 instead of %g while using shake",
265 ir->shake_tol);
266 CHECK(((ir->shake_tol <= 0.0) && (opts->nshake>0) &&
267 (ir->eConstrAlg == econtSHAKE)));
269 /* PBC/WALLS */
270 sprintf(err_buf,"walls only work with pbc=%s",epbc_names[epbcXY]);
271 CHECK(ir->nwall && ir->ePBC!=epbcXY);
273 /* VACUUM STUFF */
274 if (ir->ePBC != epbcXYZ && ir->nwall != 2) {
275 if (ir->ePBC == epbcNONE) {
276 if (ir->epc != epcNO) {
277 warning(wi,"Turning off pressure coupling for vacuum system");
278 ir->epc = epcNO;
280 } else {
281 sprintf(err_buf,"Can not have pressure coupling with pbc=%s",
282 epbc_names[ir->ePBC]);
283 CHECK(ir->epc != epcNO);
285 sprintf(err_buf,"Can not have Ewald with pbc=%s",epbc_names[ir->ePBC]);
286 CHECK(EEL_FULL(ir->coulombtype));
288 sprintf(err_buf,"Can not have dispersion correction with pbc=%s",
289 epbc_names[ir->ePBC]);
290 CHECK(ir->eDispCorr != edispcNO);
293 if (ir->rlist == 0.0) {
294 sprintf(err_buf,"can only have neighborlist cut-off zero (=infinite)\n"
295 "with coulombtype = %s or coulombtype = %s\n"
296 "without periodic boundary conditions (pbc = %s) and\n"
297 "rcoulomb and rvdw set to zero",
298 eel_names[eelCUT],eel_names[eelUSER],epbc_names[epbcNONE]);
299 CHECK(((ir->coulombtype != eelCUT) && (ir->coulombtype != eelUSER)) ||
300 (ir->ePBC != epbcNONE) ||
301 (ir->rcoulomb != 0.0) || (ir->rvdw != 0.0));
303 if (ir->nstlist < 0) {
304 warning_error(wi,"Can not have heuristic neighborlist updates without cut-off");
306 if (ir->nstlist > 0) {
307 warning_note(wi,"Simulating without cut-offs is usually (slightly) faster with nstlist=0, nstype=simple and particle decomposition");
311 /* COMM STUFF */
312 if (ir->nstcomm == 0) {
313 ir->comm_mode = ecmNO;
315 if (ir->comm_mode != ecmNO) {
316 if (ir->nstcomm < 0) {
317 warning(wi,"If you want to remove the rotation around the center of mass, you should set comm_mode = Angular instead of setting nstcomm < 0. nstcomm is modified to its absolute value");
318 ir->nstcomm = abs(ir->nstcomm);
321 if (ir->nstcalcenergy > 0 && ir->nstcomm < ir->nstcalcenergy) {
322 warning_note(wi,"nstcomm < nstcalcenergy defeats the purpose of nstcalcenergy, setting nstcomm to nstcalcenergy");
323 ir->nstcomm = ir->nstcalcenergy;
326 if (ir->comm_mode == ecmANGULAR) {
327 sprintf(err_buf,"Can not remove the rotation around the center of mass with periodic molecules");
328 CHECK(ir->bPeriodicMols);
329 if (ir->ePBC != epbcNONE)
330 warning(wi,"Removing the rotation around the center of mass in a periodic system (this is not a problem when you have only one molecule).");
334 if (EI_STATE_VELOCITY(ir->eI) && ir->ePBC == epbcNONE && ir->comm_mode != ecmANGULAR) {
335 warning_note(wi,"Tumbling and or flying ice-cubes: We are not removing rotation around center of mass in a non-periodic system. You should probably set comm_mode = ANGULAR.");
338 sprintf(err_buf,"Free-energy not implemented for Ewald and PPPM");
339 CHECK((ir->coulombtype==eelEWALD || ir->coulombtype==eelPPPM)
340 && (ir->efep!=efepNO));
342 sprintf(err_buf,"Twin-range neighbour searching (NS) with simple NS"
343 " algorithm not implemented");
344 CHECK(((ir->rcoulomb > ir->rlist) || (ir->rvdw > ir->rlist))
345 && (ir->ns_type == ensSIMPLE));
347 /* TEMPERATURE COUPLING */
348 if (ir->etc == etcYES)
350 ir->etc = etcBERENDSEN;
351 warning_note(wi,"Old option for temperature coupling given: "
352 "changing \"yes\" to \"Berendsen\"\n");
355 if (ir->etc == etcNOSEHOOVER)
357 if (ir->opts.nhchainlength < 1)
359 sprintf(warn_buf,"number of Nose-Hoover chains (currently %d) cannot be less than 1,reset to 1\n",ir->opts.nhchainlength);
360 ir->opts.nhchainlength =1;
361 warning(wi,warn_buf);
364 if (ir->etc==etcNOSEHOOVER && !EI_VV(ir->eI) && ir->opts.nhchainlength > 1)
366 warning_note(wi,"leapfrog does not yet support Nose-Hoover chains, nhchainlength reset to 1");
367 ir->opts.nhchainlength = 1;
370 else
372 ir->opts.nhchainlength = 0;
375 if (ir->etc == etcBERENDSEN)
377 sprintf(warn_buf,"The %s thermostat does not generate the correct kinetic energy distribution. You might want to consider using the %s thermostat.",
378 ETCOUPLTYPE(ir->etc),ETCOUPLTYPE(etcVRESCALE));
379 warning_note(wi,warn_buf);
382 if ((ir->etc==etcNOSEHOOVER || ir->etc==etcANDERSEN || ir->etc==etcANDERSENINTERVAL)
383 && ir->epc==epcBERENDSEN)
385 sprintf(warn_buf,"Using Berendsen pressure coupling invalidates the "
386 "true ensemble for the thermostat");
387 warning(wi,warn_buf);
390 /* PRESSURE COUPLING */
391 if (ir->epc == epcISOTROPIC)
393 ir->epc = epcBERENDSEN;
394 warning_note(wi,"Old option for pressure coupling given: "
395 "changing \"Isotropic\" to \"Berendsen\"\n");
398 if (ir->epc != epcNO)
400 sprintf(err_buf,"tau_p must be > 0 instead of %g\n",ir->tau_p);
401 CHECK(ir->tau_p <= 0);
403 nstcmin = (ir->epc == epcBERENDSEN ? nstcmin1 : nstcmin2);
404 if (ir->tau_p < nstcmin*dt_coupl)
406 sprintf(warn_buf,"For proper integration of the %s barostat, tau_p (%g) should be at least %d times larger than nstcalcenergy*dt (%g)",
407 EPCOUPLTYPE(ir->epc),ir->tau_p,nstcmin,dt_coupl);
408 warning(wi,warn_buf);
411 sprintf(err_buf,"compressibility must be > 0 when using pressure"
412 " coupling %s\n",EPCOUPLTYPE(ir->epc));
413 CHECK(ir->compress[XX][XX] < 0 || ir->compress[YY][YY] < 0 ||
414 ir->compress[ZZ][ZZ] < 0 ||
415 (trace(ir->compress) == 0 && ir->compress[YY][XX] <= 0 &&
416 ir->compress[ZZ][XX] <= 0 && ir->compress[ZZ][YY] <= 0));
418 sprintf(err_buf,"pressure coupling with PPPM not implemented, use PME");
419 CHECK(ir->coulombtype == eelPPPM);
422 else if (ir->coulombtype == eelPPPM)
424 sprintf(warn_buf,"The pressure with PPPM is incorrect, if you need the pressure use PME");
425 warning(wi,warn_buf);
428 if (EI_VV(ir->eI))
430 if (ir->epc > epcNO)
432 if (ir->epc!=epcMTTK)
434 warning_error(wi,"NPT only defined for vv using Martyna-Tuckerman-Tobias-Klein equations");
439 /* ELECTROSTATICS */
440 /* More checks are in triple check (grompp.c) */
441 if (ir->coulombtype == eelPPPM)
443 warning_error(wi,"PPPM is not functional in the current version, we plan to implement PPPM through a small modification of the PME code");
446 if (ir->coulombtype == eelSWITCH) {
447 sprintf(warn_buf,"coulombtype = %s is only for testing purposes and can lead to serious artifacts, advice: use coulombtype = %s",
448 eel_names[ir->coulombtype],
449 eel_names[eelRF_ZERO]);
450 warning(wi,warn_buf);
453 if (ir->epsilon_r!=1 && ir->implicit_solvent==eisGBSA) {
454 sprintf(warn_buf,"epsilon_r = %g with GB implicit solvent, will use this value for inner dielectric",ir->epsilon_r);
455 warning_note(wi,warn_buf);
458 if (EEL_RF(ir->coulombtype) && ir->epsilon_rf==1 && ir->epsilon_r!=1) {
459 sprintf(warn_buf,"epsilon_r = %g and epsilon_rf = 1 with reaction field, assuming old format and exchanging epsilon_r and epsilon_rf",ir->epsilon_r);
460 warning(wi,warn_buf);
461 ir->epsilon_rf = ir->epsilon_r;
462 ir->epsilon_r = 1.0;
465 if (getenv("GALACTIC_DYNAMICS") == NULL) {
466 sprintf(err_buf,"epsilon_r must be >= 0 instead of %g\n",ir->epsilon_r);
467 CHECK(ir->epsilon_r < 0);
470 if (EEL_RF(ir->coulombtype)) {
471 /* reaction field (at the cut-off) */
473 if (ir->coulombtype == eelRF_ZERO) {
474 sprintf(err_buf,"With coulombtype = %s, epsilon_rf must be 0",
475 eel_names[ir->coulombtype]);
476 CHECK(ir->epsilon_rf != 0);
479 sprintf(err_buf,"epsilon_rf must be >= epsilon_r");
480 CHECK((ir->epsilon_rf < ir->epsilon_r && ir->epsilon_rf != 0) ||
481 (ir->epsilon_r == 0));
482 if (ir->epsilon_rf == ir->epsilon_r) {
483 sprintf(warn_buf,"Using epsilon_rf = epsilon_r with %s does not make sense",
484 eel_names[ir->coulombtype]);
485 warning(wi,warn_buf);
488 /* Allow rlist>rcoulomb for tabulated long range stuff. This just
489 * means the interaction is zero outside rcoulomb, but it helps to
490 * provide accurate energy conservation.
492 if (EEL_MIGHT_BE_ZERO_AT_CUTOFF(ir->coulombtype)) {
493 if (EEL_SWITCHED(ir->coulombtype)) {
494 sprintf(err_buf,
495 "With coulombtype = %s rcoulomb_switch must be < rcoulomb",
496 eel_names[ir->coulombtype]);
497 CHECK(ir->rcoulomb_switch >= ir->rcoulomb);
499 } else if (ir->coulombtype == eelCUT || EEL_RF(ir->coulombtype)) {
500 sprintf(err_buf,"With coulombtype = %s, rcoulomb must be >= rlist",
501 eel_names[ir->coulombtype]);
502 CHECK(ir->rlist > ir->rcoulomb);
505 if (EEL_FULL(ir->coulombtype)) {
506 if (ir->coulombtype==eelPMESWITCH || ir->coulombtype==eelPMEUSER) {
507 sprintf(err_buf,"With coulombtype = %s, rcoulomb must be <= rlist",
508 eel_names[ir->coulombtype]);
509 CHECK(ir->rcoulomb > ir->rlist);
510 } else {
511 if (ir->coulombtype == eelPME) {
512 sprintf(err_buf,
513 "With coulombtype = %s, rcoulomb must be equal to rlist\n"
514 "If you want optimal energy conservation or exact integration use %s",
515 eel_names[ir->coulombtype],eel_names[eelPMESWITCH]);
516 } else {
517 sprintf(err_buf,
518 "With coulombtype = %s, rcoulomb must be equal to rlist",
519 eel_names[ir->coulombtype]);
521 CHECK(ir->rcoulomb != ir->rlist);
525 if (EEL_PME(ir->coulombtype)) {
526 if (ir->pme_order < 3) {
527 warning_error(wi,"pme_order can not be smaller than 3");
531 if (ir->nwall==2 && EEL_FULL(ir->coulombtype)) {
532 if (ir->ewald_geometry == eewg3D) {
533 sprintf(warn_buf,"With pbc=%s you should use ewald_geometry=%s",
534 epbc_names[ir->ePBC],eewg_names[eewg3DC]);
535 warning(wi,warn_buf);
537 /* This check avoids extra pbc coding for exclusion corrections */
538 sprintf(err_buf,"wall_ewald_zfac should be >= 2");
539 CHECK(ir->wall_ewald_zfac < 2);
542 if (EVDW_SWITCHED(ir->vdwtype)) {
543 sprintf(err_buf,"With vdwtype = %s rvdw_switch must be < rvdw",
544 evdw_names[ir->vdwtype]);
545 CHECK(ir->rvdw_switch >= ir->rvdw);
546 } else if (ir->vdwtype == evdwCUT) {
547 sprintf(err_buf,"With vdwtype = %s, rvdw must be >= rlist",evdw_names[ir->vdwtype]);
548 CHECK(ir->rlist > ir->rvdw);
550 if (EEL_IS_ZERO_AT_CUTOFF(ir->coulombtype)
551 && (ir->rlistlong <= ir->rcoulomb)) {
552 sprintf(warn_buf,"For energy conservation with switch/shift potentials, %s should be 0.1 to 0.3 nm larger than rcoulomb.",
553 IR_TWINRANGE(*ir) ? "rlistlong" : "rlist");
554 warning_note(wi,warn_buf);
556 if (EVDW_SWITCHED(ir->vdwtype) && (ir->rlistlong <= ir->rvdw)) {
557 sprintf(warn_buf,"For energy conservation with switch/shift potentials, %s should be 0.1 to 0.3 nm larger than rvdw.",
558 IR_TWINRANGE(*ir) ? "rlistlong" : "rlist");
559 warning_note(wi,warn_buf);
562 if (ir->vdwtype == evdwUSER && ir->eDispCorr != edispcNO) {
563 warning_note(wi,"You have selected user tables with dispersion correction, the dispersion will be corrected to -C6/r^6 beyond rvdw_switch (the tabulated interaction between rvdw_switch and rvdw will not be double counted). Make sure that you really want dispersion correction to -C6/r^6.");
566 if (ir->nstlist == -1) {
567 sprintf(err_buf,
568 "nstlist=-1 only works with switched or shifted potentials,\n"
569 "suggestion: use vdw-type=%s and coulomb-type=%s",
570 evdw_names[evdwSHIFT],eel_names[eelPMESWITCH]);
571 CHECK(!(EEL_MIGHT_BE_ZERO_AT_CUTOFF(ir->coulombtype) &&
572 EVDW_MIGHT_BE_ZERO_AT_CUTOFF(ir->vdwtype)));
574 sprintf(err_buf,"With nstlist=-1 rvdw and rcoulomb should be smaller than rlist to account for diffusion and possibly charge-group radii");
575 CHECK(ir->rvdw >= ir->rlist || ir->rcoulomb >= ir->rlist);
577 sprintf(err_buf,"nstlist can not be smaller than -1");
578 CHECK(ir->nstlist < -1);
580 if (ir->eI == eiLBFGS && (ir->coulombtype==eelCUT || ir->vdwtype==evdwCUT)
581 && ir->rvdw != 0) {
582 warning(wi,"For efficient BFGS minimization, use switch/shift/pme instead of cut-off.");
585 if (ir->eI == eiLBFGS && ir->nbfgscorr <= 0) {
586 warning(wi,"Using L-BFGS with nbfgscorr<=0 just gets you steepest descent.");
589 /* FREE ENERGY */
590 if (ir->efep != efepNO) {
591 sprintf(err_buf,"The soft-core power is %d and can only be 1 or 2",
592 ir->sc_power);
593 CHECK(ir->sc_alpha!=0 && ir->sc_power!=1 && ir->sc_power!=2);
596 /* ENERGY CONSERVATION */
597 if (ir_NVE(ir))
599 if (!EVDW_MIGHT_BE_ZERO_AT_CUTOFF(ir->vdwtype) && ir->rvdw > 0)
601 sprintf(warn_buf,"You are using a cut-off for VdW interactions with NVE, for good energy conservation use vdwtype = %s (possibly with DispCorr)",
602 evdw_names[evdwSHIFT]);
603 warning_note(wi,warn_buf);
605 if (!EEL_MIGHT_BE_ZERO_AT_CUTOFF(ir->coulombtype) && ir->rcoulomb > 0)
607 sprintf(warn_buf,"You are using a cut-off for electrostatics with NVE, for good energy conservation use coulombtype = %s or %s",
608 eel_names[eelPMESWITCH],eel_names[eelRF_ZERO]);
609 warning_note(wi,warn_buf);
613 /* IMPLICIT SOLVENT */
614 if(ir->coulombtype==eelGB_NOTUSED)
616 ir->coulombtype=eelCUT;
617 ir->implicit_solvent=eisGBSA;
618 fprintf(stderr,"Note: Old option for generalized born electrostatics given:\n"
619 "Changing coulombtype from \"generalized-born\" to \"cut-off\" and instead\n"
620 "setting implicit_solvent value to \"GBSA\" in input section.\n");
623 if(ir->implicit_solvent==eisGBSA)
625 sprintf(err_buf,"With GBSA implicit solvent, rgbradii must be equal to rlist.");
626 CHECK(ir->rgbradii != ir->rlist);
628 if(ir->coulombtype!=eelCUT)
630 sprintf(err_buf,"With GBSA, coulombtype must be equal to %s\n",eel_names[eelCUT]);
631 CHECK(ir->coulombtype!=eelCUT);
633 if(ir->vdwtype!=evdwCUT)
635 sprintf(err_buf,"With GBSA, vdw-type must be equal to %s\n",evdw_names[evdwCUT]);
636 CHECK(ir->vdwtype!=evdwCUT);
639 if(ir->nstgbradii<1)
641 sprintf(warn_buf,"Using GBSA with nstgbradii<1, setting nstgbradii=1");
642 warning_note(wi,warn_buf);
643 ir->nstgbradii=1;
648 static int str_nelem(const char *str,int maxptr,char *ptr[])
650 int np=0;
651 char *copy0,*copy;
653 copy0=strdup(str);
654 copy=copy0;
655 ltrim(copy);
656 while (*copy != '\0') {
657 if (np >= maxptr)
658 gmx_fatal(FARGS,"Too many groups on line: '%s' (max is %d)",
659 str,maxptr);
660 if (ptr)
661 ptr[np]=copy;
662 np++;
663 while ((*copy != '\0') && !isspace(*copy))
664 copy++;
665 if (*copy != '\0') {
666 *copy='\0';
667 copy++;
669 ltrim(copy);
671 if (ptr == NULL)
672 sfree(copy0);
674 return np;
677 static void parse_n_double(char *str,int *n,double **r)
679 char *ptr[MAXPTR];
680 int i;
682 *n = str_nelem(str,MAXPTR,ptr);
684 snew(*r,*n);
685 for(i=0; i<*n; i++) {
686 (*r)[i] = strtod(ptr[i],NULL);
690 static void do_wall_params(t_inputrec *ir,
691 char *wall_atomtype, char *wall_density,
692 t_gromppopts *opts)
694 int nstr,i;
695 char *names[MAXPTR];
696 double dbl;
698 opts->wall_atomtype[0] = NULL;
699 opts->wall_atomtype[1] = NULL;
701 ir->wall_atomtype[0] = -1;
702 ir->wall_atomtype[1] = -1;
703 ir->wall_density[0] = 0;
704 ir->wall_density[1] = 0;
706 if (ir->nwall > 0) {
707 nstr = str_nelem(wall_atomtype,MAXPTR,names);
708 if (nstr != ir->nwall)
709 gmx_fatal(FARGS,"Expected %d elements for wall_atomtype, found %d",
710 ir->nwall,nstr);
711 for(i=0; i<ir->nwall; i++)
712 opts->wall_atomtype[i] = strdup(names[i]);
714 if (ir->wall_type != ewtTABLE) {
715 nstr = str_nelem(wall_density,MAXPTR,names);
716 if (nstr != ir->nwall)
717 gmx_fatal(FARGS,"Expected %d elements for wall_density, found %d",
718 ir->nwall,nstr);
719 for(i=0; i<ir->nwall; i++) {
720 sscanf(names[i],"%lf",&dbl);
721 if (dbl <= 0)
722 gmx_fatal(FARGS,"wall_density[%d] = %f\n",i,dbl);
723 ir->wall_density[i] = dbl;
729 static void add_wall_energrps(gmx_groups_t *groups,int nwall,t_symtab *symtab)
731 int i;
732 t_grps *grps;
733 char str[STRLEN];
735 if (nwall > 0) {
736 srenew(groups->grpname,groups->ngrpname+nwall);
737 grps = &(groups->grps[egcENER]);
738 srenew(grps->nm_ind,grps->nr+nwall);
739 for(i=0; i<nwall; i++) {
740 sprintf(str,"wall%d",i);
741 groups->grpname[groups->ngrpname] = put_symtab(symtab,str);
742 grps->nm_ind[grps->nr++] = groups->ngrpname++;
747 void get_ir(const char *mdparin,const char *mdparout,
748 t_inputrec *ir,t_gromppopts *opts,
749 warninp_t wi)
751 char *dumstr[2];
752 double dumdub[2][6];
753 t_inpfile *inp;
754 const char *tmp;
755 int i,j,m,ninp;
756 char warn_buf[STRLEN];
758 inp = read_inpfile(mdparin, &ninp, NULL, wi);
760 snew(dumstr[0],STRLEN);
761 snew(dumstr[1],STRLEN);
763 REM_TYPE("title");
764 REM_TYPE("cpp");
765 REM_TYPE("domain-decomposition");
766 REPL_TYPE("unconstrained-start","continuation");
767 REM_TYPE("dihre-tau");
768 REM_TYPE("nstdihreout");
769 REM_TYPE("nstcheckpoint");
771 CCTYPE ("VARIOUS PREPROCESSING OPTIONS");
772 CTYPE ("Preprocessor information: use cpp syntax.");
773 CTYPE ("e.g.: -I/home/joe/doe -I/home/mary/roe");
774 STYPE ("include", opts->include, NULL);
775 CTYPE ("e.g.: -DI_Want_Cookies -DMe_Too");
776 STYPE ("define", opts->define, NULL);
778 CCTYPE ("RUN CONTROL PARAMETERS");
779 EETYPE("integrator", ir->eI, ei_names);
780 CTYPE ("Start time and timestep in ps");
781 RTYPE ("tinit", ir->init_t, 0.0);
782 RTYPE ("dt", ir->delta_t, 0.001);
783 STEPTYPE ("nsteps", ir->nsteps, 0);
784 CTYPE ("For exact run continuation or redoing part of a run");
785 STEPTYPE ("init_step",ir->init_step, 0);
786 CTYPE ("Part index is updated automatically on checkpointing (keeps files separate)");
787 ITYPE ("simulation_part", ir->simulation_part, 1);
788 CTYPE ("mode for center of mass motion removal");
789 CTYPE ("energy calculation and T/P-coupling frequency");
790 ITYPE ("nstcalcenergy",ir->nstcalcenergy, -1);
791 EETYPE("comm-mode", ir->comm_mode, ecm_names);
792 CTYPE ("number of steps for center of mass motion removal");
793 ITYPE ("nstcomm", ir->nstcomm, 10);
794 CTYPE ("group(s) for center of mass motion removal");
795 STYPE ("comm-grps", vcm, NULL);
797 CCTYPE ("LANGEVIN DYNAMICS OPTIONS");
798 CTYPE ("Friction coefficient (amu/ps) and random seed");
799 RTYPE ("bd-fric", ir->bd_fric, 0.0);
800 ITYPE ("ld-seed", ir->ld_seed, 1993);
802 /* Em stuff */
803 CCTYPE ("ENERGY MINIMIZATION OPTIONS");
804 CTYPE ("Force tolerance and initial step-size");
805 RTYPE ("emtol", ir->em_tol, 10.0);
806 RTYPE ("emstep", ir->em_stepsize,0.01);
807 CTYPE ("Max number of iterations in relax_shells");
808 ITYPE ("niter", ir->niter, 20);
809 CTYPE ("Step size (ps^2) for minimization of flexible constraints");
810 RTYPE ("fcstep", ir->fc_stepsize, 0);
811 CTYPE ("Frequency of steepest descents steps when doing CG");
812 ITYPE ("nstcgsteep", ir->nstcgsteep, 1000);
813 ITYPE ("nbfgscorr", ir->nbfgscorr, 10);
815 CCTYPE ("TEST PARTICLE INSERTION OPTIONS");
816 RTYPE ("rtpi", ir->rtpi, 0.05);
818 /* Output options */
819 CCTYPE ("OUTPUT CONTROL OPTIONS");
820 CTYPE ("Output frequency for coords (x), velocities (v) and forces (f)");
821 ITYPE ("nstxout", ir->nstxout, 100);
822 ITYPE ("nstvout", ir->nstvout, 100);
823 ITYPE ("nstfout", ir->nstfout, 0);
824 ir->nstcheckpoint = 1000;
825 CTYPE ("Output frequency for energies to log file and energy file");
826 ITYPE ("nstlog", ir->nstlog, 100);
827 ITYPE ("nstenergy", ir->nstenergy, 100);
828 CTYPE ("Output frequency and precision for xtc file");
829 ITYPE ("nstxtcout", ir->nstxtcout, 0);
830 RTYPE ("xtc-precision",ir->xtcprec, 1000.0);
831 CTYPE ("This selects the subset of atoms for the xtc file. You can");
832 CTYPE ("select multiple groups. By default all atoms will be written.");
833 STYPE ("xtc-grps", xtc_grps, NULL);
834 CTYPE ("Selection of energy groups");
835 STYPE ("energygrps", energy, NULL);
837 /* Neighbor searching */
838 CCTYPE ("NEIGHBORSEARCHING PARAMETERS");
839 CTYPE ("nblist update frequency");
840 ITYPE ("nstlist", ir->nstlist, 10);
841 CTYPE ("ns algorithm (simple or grid)");
842 EETYPE("ns-type", ir->ns_type, ens_names);
843 /* set ndelta to the optimal value of 2 */
844 ir->ndelta = 2;
845 CTYPE ("Periodic boundary conditions: xyz, no, xy");
846 EETYPE("pbc", ir->ePBC, epbc_names);
847 EETYPE("periodic_molecules", ir->bPeriodicMols, yesno_names);
848 CTYPE ("nblist cut-off");
849 RTYPE ("rlist", ir->rlist, 1.0);
850 CTYPE ("long-range cut-off for switched potentials");
851 RTYPE ("rlistlong", ir->rlistlong, -1);
853 /* Electrostatics */
854 CCTYPE ("OPTIONS FOR ELECTROSTATICS AND VDW");
855 CTYPE ("Method for doing electrostatics");
856 EETYPE("coulombtype", ir->coulombtype, eel_names);
857 CTYPE ("cut-off lengths");
858 RTYPE ("rcoulomb-switch", ir->rcoulomb_switch, 0.0);
859 RTYPE ("rcoulomb", ir->rcoulomb, 1.0);
860 CTYPE ("Relative dielectric constant for the medium and the reaction field");
861 RTYPE ("epsilon_r", ir->epsilon_r, 1.0);
862 RTYPE ("epsilon_rf", ir->epsilon_rf, 1.0);
863 CTYPE ("Method for doing Van der Waals");
864 EETYPE("vdw-type", ir->vdwtype, evdw_names);
865 CTYPE ("cut-off lengths");
866 RTYPE ("rvdw-switch", ir->rvdw_switch, 0.0);
867 RTYPE ("rvdw", ir->rvdw, 1.0);
868 CTYPE ("Apply long range dispersion corrections for Energy and Pressure");
869 EETYPE("DispCorr", ir->eDispCorr, edispc_names);
870 CTYPE ("Extension of the potential lookup tables beyond the cut-off");
871 RTYPE ("table-extension", ir->tabext, 1.0);
872 CTYPE ("Seperate tables between energy group pairs");
873 STYPE ("energygrp_table", egptable, NULL);
874 CTYPE ("Spacing for the PME/PPPM FFT grid");
875 RTYPE ("fourierspacing", opts->fourierspacing,0.12);
876 CTYPE ("FFT grid size, when a value is 0 fourierspacing will be used");
877 ITYPE ("fourier_nx", ir->nkx, 0);
878 ITYPE ("fourier_ny", ir->nky, 0);
879 ITYPE ("fourier_nz", ir->nkz, 0);
880 CTYPE ("EWALD/PME/PPPM parameters");
881 ITYPE ("pme_order", ir->pme_order, 4);
882 RTYPE ("ewald_rtol", ir->ewald_rtol, 0.00001);
883 EETYPE("ewald_geometry", ir->ewald_geometry, eewg_names);
884 RTYPE ("epsilon_surface", ir->epsilon_surface, 0.0);
885 EETYPE("optimize_fft",ir->bOptFFT, yesno_names);
887 CCTYPE("IMPLICIT SOLVENT ALGORITHM");
888 EETYPE("implicit_solvent", ir->implicit_solvent, eis_names);
890 CCTYPE ("GENERALIZED BORN ELECTROSTATICS");
891 CTYPE ("Algorithm for calculating Born radii");
892 EETYPE("gb_algorithm", ir->gb_algorithm, egb_names);
893 CTYPE ("Frequency of calculating the Born radii inside rlist");
894 ITYPE ("nstgbradii", ir->nstgbradii, 1);
895 CTYPE ("Cutoff for Born radii calculation; the contribution from atoms");
896 CTYPE ("between rlist and rgbradii is updated every nstlist steps");
897 RTYPE ("rgbradii", ir->rgbradii, 1.0);
898 CTYPE ("Dielectric coefficient of the implicit solvent");
899 RTYPE ("gb_epsilon_solvent",ir->gb_epsilon_solvent, 80.0);
900 CTYPE ("Salt concentration in M for Generalized Born models");
901 RTYPE ("gb_saltconc", ir->gb_saltconc, 0.0);
902 CTYPE ("Scaling factors used in the OBC GB model. Default values are OBC(II)");
903 RTYPE ("gb_obc_alpha", ir->gb_obc_alpha, 1.0);
904 RTYPE ("gb_obc_beta", ir->gb_obc_beta, 0.8);
905 RTYPE ("gb_obc_gamma", ir->gb_obc_gamma, 4.85);
906 RTYPE ("gb_dielectric_offset", ir->gb_dielectric_offset, 0.009);
907 EETYPE("sa_algorithm", ir->sa_algorithm, esa_names);
908 CTYPE ("Surface tension (kJ/mol/nm^2) for the SA (nonpolar surface) part of GBSA");
909 CTYPE ("The default value (2.092) corresponds to 0.005 kcal/mol/Angstrom^2.");
910 RTYPE ("sa_surface_tension", ir->sa_surface_tension, 2.092);
912 /* Coupling stuff */
913 CCTYPE ("OPTIONS FOR WEAK COUPLING ALGORITHMS");
914 CTYPE ("Temperature coupling");
915 EETYPE("tcoupl", ir->etc, etcoupl_names);
916 ITYPE("nh-chain-length", ir->opts.nhchainlength, NHCHAINLENGTH);
917 CTYPE ("Groups to couple separately");
918 STYPE ("tc-grps", tcgrps, NULL);
919 CTYPE ("Time constant (ps) and reference temperature (K)");
920 STYPE ("tau-t", tau_t, NULL);
921 STYPE ("ref-t", ref_t, NULL);
922 CTYPE ("Pressure coupling");
923 EETYPE("Pcoupl", ir->epc, epcoupl_names);
924 EETYPE("Pcoupltype", ir->epct, epcoupltype_names);
925 CTYPE ("Time constant (ps), compressibility (1/bar) and reference P (bar)");
926 RTYPE ("tau-p", ir->tau_p, 1.0);
927 STYPE ("compressibility", dumstr[0], NULL);
928 STYPE ("ref-p", dumstr[1], NULL);
929 CTYPE ("Scaling of reference coordinates, No, All or COM");
930 EETYPE ("refcoord_scaling",ir->refcoord_scaling,erefscaling_names);
932 CTYPE ("Random seed for Andersen thermostat");
933 ITYPE ("andersen_seed", ir->andersen_seed, 815131);
935 /* QMMM */
936 CCTYPE ("OPTIONS FOR QMMM calculations");
937 EETYPE("QMMM", ir->bQMMM, yesno_names);
938 CTYPE ("Groups treated Quantum Mechanically");
939 STYPE ("QMMM-grps", QMMM, NULL);
940 CTYPE ("QM method");
941 STYPE("QMmethod", QMmethod, NULL);
942 CTYPE ("QMMM scheme");
943 EETYPE("QMMMscheme", ir->QMMMscheme, eQMMMscheme_names);
944 CTYPE ("QM basisset");
945 STYPE("QMbasis", QMbasis, NULL);
946 CTYPE ("QM charge");
947 STYPE ("QMcharge", QMcharge,NULL);
948 CTYPE ("QM multiplicity");
949 STYPE ("QMmult", QMmult,NULL);
950 CTYPE ("Surface Hopping");
951 STYPE ("SH", bSH, NULL);
952 CTYPE ("CAS space options");
953 STYPE ("CASorbitals", CASorbitals, NULL);
954 STYPE ("CASelectrons", CASelectrons, NULL);
955 STYPE ("SAon", SAon, NULL);
956 STYPE ("SAoff",SAoff,NULL);
957 STYPE ("SAsteps", SAsteps, NULL);
958 CTYPE ("Scale factor for MM charges");
959 RTYPE ("MMChargeScaleFactor", ir->scalefactor, 1.0);
960 CTYPE ("Optimization of QM subsystem");
961 STYPE ("bOPT", bOPT, NULL);
962 STYPE ("bTS", bTS, NULL);
964 /* Simulated annealing */
965 CCTYPE("SIMULATED ANNEALING");
966 CTYPE ("Type of annealing for each temperature group (no/single/periodic)");
967 STYPE ("annealing", anneal, NULL);
968 CTYPE ("Number of time points to use for specifying annealing in each group");
969 STYPE ("annealing_npoints", anneal_npoints, NULL);
970 CTYPE ("List of times at the annealing points for each group");
971 STYPE ("annealing_time", anneal_time, NULL);
972 CTYPE ("Temp. at each annealing point, for each group.");
973 STYPE ("annealing_temp", anneal_temp, NULL);
975 /* Startup run */
976 CCTYPE ("GENERATE VELOCITIES FOR STARTUP RUN");
977 EETYPE("gen-vel", opts->bGenVel, yesno_names);
978 RTYPE ("gen-temp", opts->tempi, 300.0);
979 ITYPE ("gen-seed", opts->seed, 173529);
981 /* Shake stuff */
982 CCTYPE ("OPTIONS FOR BONDS");
983 EETYPE("constraints", opts->nshake, constraints);
984 CTYPE ("Type of constraint algorithm");
985 EETYPE("constraint-algorithm", ir->eConstrAlg, econstr_names);
986 CTYPE ("Do not constrain the start configuration");
987 EETYPE("continuation", ir->bContinuation, yesno_names);
988 CTYPE ("Use successive overrelaxation to reduce the number of shake iterations");
989 EETYPE("Shake-SOR", ir->bShakeSOR, yesno_names);
990 CTYPE ("Relative tolerance of shake");
991 RTYPE ("shake-tol", ir->shake_tol, 0.0001);
992 CTYPE ("Highest order in the expansion of the constraint coupling matrix");
993 ITYPE ("lincs-order", ir->nProjOrder, 4);
994 CTYPE ("Number of iterations in the final step of LINCS. 1 is fine for");
995 CTYPE ("normal simulations, but use 2 to conserve energy in NVE runs.");
996 CTYPE ("For energy minimization with constraints it should be 4 to 8.");
997 ITYPE ("lincs-iter", ir->nLincsIter, 1);
998 CTYPE ("Lincs will write a warning to the stderr if in one step a bond");
999 CTYPE ("rotates over more degrees than");
1000 RTYPE ("lincs-warnangle", ir->LincsWarnAngle, 30.0);
1001 CTYPE ("Convert harmonic bonds to morse potentials");
1002 EETYPE("morse", opts->bMorse,yesno_names);
1004 /* Energy group exclusions */
1005 CCTYPE ("ENERGY GROUP EXCLUSIONS");
1006 CTYPE ("Pairs of energy groups for which all non-bonded interactions are excluded");
1007 STYPE ("energygrp_excl", egpexcl, NULL);
1009 /* Walls */
1010 CCTYPE ("WALLS");
1011 CTYPE ("Number of walls, type, atom types, densities and box-z scale factor for Ewald");
1012 ITYPE ("nwall", ir->nwall, 0);
1013 EETYPE("wall_type", ir->wall_type, ewt_names);
1014 RTYPE ("wall_r_linpot", ir->wall_r_linpot, -1);
1015 STYPE ("wall_atomtype", wall_atomtype, NULL);
1016 STYPE ("wall_density", wall_density, NULL);
1017 RTYPE ("wall_ewald_zfac", ir->wall_ewald_zfac, 3);
1019 /* COM pulling */
1020 CCTYPE("COM PULLING");
1021 CTYPE("Pull type: no, umbrella, constraint or constant_force");
1022 EETYPE("pull", ir->ePull, epull_names);
1023 if (ir->ePull != epullNO) {
1024 snew(ir->pull,1);
1025 pull_grp = read_pullparams(&ninp,&inp,ir->pull,&opts->pull_start,wi);
1028 /* Refinement */
1029 CCTYPE("NMR refinement stuff");
1030 CTYPE ("Distance restraints type: No, Simple or Ensemble");
1031 EETYPE("disre", ir->eDisre, edisre_names);
1032 CTYPE ("Force weighting of pairs in one distance restraint: Conservative or Equal");
1033 EETYPE("disre-weighting", ir->eDisreWeighting, edisreweighting_names);
1034 CTYPE ("Use sqrt of the time averaged times the instantaneous violation");
1035 EETYPE("disre-mixed", ir->bDisreMixed, yesno_names);
1036 RTYPE ("disre-fc", ir->dr_fc, 1000.0);
1037 RTYPE ("disre-tau", ir->dr_tau, 0.0);
1038 CTYPE ("Output frequency for pair distances to energy file");
1039 ITYPE ("nstdisreout", ir->nstdisreout, 100);
1040 CTYPE ("Orientation restraints: No or Yes");
1041 EETYPE("orire", opts->bOrire, yesno_names);
1042 CTYPE ("Orientation restraints force constant and tau for time averaging");
1043 RTYPE ("orire-fc", ir->orires_fc, 0.0);
1044 RTYPE ("orire-tau", ir->orires_tau, 0.0);
1045 STYPE ("orire-fitgrp",orirefitgrp, NULL);
1046 CTYPE ("Output frequency for trace(SD) and S to energy file");
1047 ITYPE ("nstorireout", ir->nstorireout, 100);
1048 CTYPE ("Dihedral angle restraints: No or Yes");
1049 EETYPE("dihre", opts->bDihre, yesno_names);
1050 RTYPE ("dihre-fc", ir->dihre_fc, 1000.0);
1052 /* Free energy stuff */
1053 CCTYPE ("Free energy control stuff");
1054 EETYPE("free-energy", ir->efep, efep_names);
1055 RTYPE ("init-lambda", ir->init_lambda,0.0);
1056 RTYPE ("delta-lambda",ir->delta_lambda,0.0);
1057 STYPE ("foreign_lambda", foreign_lambda, NULL);
1058 RTYPE ("sc-alpha",ir->sc_alpha,0.0);
1059 ITYPE ("sc-power",ir->sc_power,0);
1060 RTYPE ("sc-sigma",ir->sc_sigma,0.3);
1061 ITYPE ("nstdhdl", ir->nstdhdl, 10);
1062 ITYPE ("dh_table_size", ir->dh_table_size, 0);
1063 RTYPE ("dh_table_spacing", ir->dh_table_spacing, 0.1);
1064 STYPE ("couple-moltype", couple_moltype, NULL);
1065 EETYPE("couple-lambda0", opts->couple_lam0, couple_lam);
1066 EETYPE("couple-lambda1", opts->couple_lam1, couple_lam);
1067 EETYPE("couple-intramol", opts->bCoupleIntra, yesno_names);
1069 /* Non-equilibrium MD stuff */
1070 CCTYPE("Non-equilibrium MD stuff");
1071 STYPE ("acc-grps", accgrps, NULL);
1072 STYPE ("accelerate", acc, NULL);
1073 STYPE ("freezegrps", freeze, NULL);
1074 STYPE ("freezedim", frdim, NULL);
1075 RTYPE ("cos-acceleration", ir->cos_accel, 0);
1076 STYPE ("deform", deform, NULL);
1078 /* Electric fields */
1079 CCTYPE("Electric fields");
1080 CTYPE ("Format is number of terms (int) and for all terms an amplitude (real)");
1081 CTYPE ("and a phase angle (real)");
1082 STYPE ("E-x", efield_x, NULL);
1083 STYPE ("E-xt", efield_xt, NULL);
1084 STYPE ("E-y", efield_y, NULL);
1085 STYPE ("E-yt", efield_yt, NULL);
1086 STYPE ("E-z", efield_z, NULL);
1087 STYPE ("E-zt", efield_zt, NULL);
1089 /* User defined thingies */
1090 CCTYPE ("User defined thingies");
1091 STYPE ("user1-grps", user1, NULL);
1092 STYPE ("user2-grps", user2, NULL);
1093 ITYPE ("userint1", ir->userint1, 0);
1094 ITYPE ("userint2", ir->userint2, 0);
1095 ITYPE ("userint3", ir->userint3, 0);
1096 ITYPE ("userint4", ir->userint4, 0);
1097 RTYPE ("userreal1", ir->userreal1, 0);
1098 RTYPE ("userreal2", ir->userreal2, 0);
1099 RTYPE ("userreal3", ir->userreal3, 0);
1100 RTYPE ("userreal4", ir->userreal4, 0);
1101 #undef CTYPE
1103 write_inpfile(mdparout,ninp,inp,FALSE,wi);
1104 for (i=0; (i<ninp); i++) {
1105 sfree(inp[i].name);
1106 sfree(inp[i].value);
1108 sfree(inp);
1110 /* Process options if necessary */
1111 for(m=0; m<2; m++) {
1112 for(i=0; i<2*DIM; i++)
1113 dumdub[m][i]=0.0;
1114 if(ir->epc) {
1115 switch (ir->epct) {
1116 case epctISOTROPIC:
1117 if (sscanf(dumstr[m],"%lf",&(dumdub[m][XX]))!=1) {
1118 warning_error(wi,"Pressure coupling not enough values (I need 1)");
1120 dumdub[m][YY]=dumdub[m][ZZ]=dumdub[m][XX];
1121 break;
1122 case epctSEMIISOTROPIC:
1123 case epctSURFACETENSION:
1124 if (sscanf(dumstr[m],"%lf%lf",
1125 &(dumdub[m][XX]),&(dumdub[m][ZZ]))!=2) {
1126 warning_error(wi,"Pressure coupling not enough values (I need 2)");
1128 dumdub[m][YY]=dumdub[m][XX];
1129 break;
1130 case epctANISOTROPIC:
1131 if (sscanf(dumstr[m],"%lf%lf%lf%lf%lf%lf",
1132 &(dumdub[m][XX]),&(dumdub[m][YY]),&(dumdub[m][ZZ]),
1133 &(dumdub[m][3]),&(dumdub[m][4]),&(dumdub[m][5]))!=6) {
1134 warning_error(wi,"Pressure coupling not enough values (I need 6)");
1136 break;
1137 default:
1138 gmx_fatal(FARGS,"Pressure coupling type %s not implemented yet",
1139 epcoupltype_names[ir->epct]);
1143 clear_mat(ir->ref_p);
1144 clear_mat(ir->compress);
1145 for(i=0; i<DIM; i++) {
1146 ir->ref_p[i][i] = dumdub[1][i];
1147 ir->compress[i][i] = dumdub[0][i];
1149 if (ir->epct == epctANISOTROPIC) {
1150 ir->ref_p[XX][YY] = dumdub[1][3];
1151 ir->ref_p[XX][ZZ] = dumdub[1][4];
1152 ir->ref_p[YY][ZZ] = dumdub[1][5];
1153 if (ir->ref_p[XX][YY]!=0 && ir->ref_p[XX][ZZ]!=0 && ir->ref_p[YY][ZZ]!=0) {
1154 warning(wi,"All off-diagonal reference pressures are non-zero. Are you sure you want to apply a threefold shear stress?\n");
1156 ir->compress[XX][YY] = dumdub[0][3];
1157 ir->compress[XX][ZZ] = dumdub[0][4];
1158 ir->compress[YY][ZZ] = dumdub[0][5];
1159 for(i=0; i<DIM; i++) {
1160 for(m=0; m<i; m++) {
1161 ir->ref_p[i][m] = ir->ref_p[m][i];
1162 ir->compress[i][m] = ir->compress[m][i];
1167 if (ir->comm_mode == ecmNO)
1168 ir->nstcomm = 0;
1170 opts->couple_moltype = NULL;
1171 if (strlen(couple_moltype) > 0) {
1172 if (ir->efep != efepNO) {
1173 opts->couple_moltype = strdup(couple_moltype);
1174 if (opts->couple_lam0 == opts->couple_lam1)
1175 warning(wi,"The lambda=0 and lambda=1 states for coupling are identical");
1176 if (ir->eI == eiMD && (opts->couple_lam0 == ecouplamNONE ||
1177 opts->couple_lam1 == ecouplamNONE)) {
1178 warning(wi,"For proper sampling of the (nearly) decoupled state, stochastic dynamics should be used");
1180 } else {
1181 warning(wi,"Can not couple a molecule with free_energy = no");
1185 do_wall_params(ir,wall_atomtype,wall_density,opts);
1187 if (opts->bOrire && str_nelem(orirefitgrp,MAXPTR,NULL)!=1) {
1188 warning_error(wi,"ERROR: Need one orientation restraint fit group\n");
1191 clear_mat(ir->deform);
1192 for(i=0; i<6; i++)
1193 dumdub[0][i] = 0;
1194 m = sscanf(deform,"%lf %lf %lf %lf %lf %lf",
1195 &(dumdub[0][0]),&(dumdub[0][1]),&(dumdub[0][2]),
1196 &(dumdub[0][3]),&(dumdub[0][4]),&(dumdub[0][5]));
1197 for(i=0; i<3; i++)
1198 ir->deform[i][i] = dumdub[0][i];
1199 ir->deform[YY][XX] = dumdub[0][3];
1200 ir->deform[ZZ][XX] = dumdub[0][4];
1201 ir->deform[ZZ][YY] = dumdub[0][5];
1202 if (ir->epc != epcNO) {
1203 for(i=0; i<3; i++)
1204 for(j=0; j<=i; j++)
1205 if (ir->deform[i][j]!=0 && ir->compress[i][j]!=0) {
1206 warning_error(wi,"A box element has deform set and compressibility > 0");
1208 for(i=0; i<3; i++)
1209 for(j=0; j<i; j++)
1210 if (ir->deform[i][j]!=0) {
1211 for(m=j; m<DIM; m++)
1212 if (ir->compress[m][j]!=0) {
1213 sprintf(warn_buf,"An off-diagonal box element has deform set while compressibility > 0 for the same component of another box vector, this might lead to spurious periodicity effects.");
1214 warning(wi,warn_buf);
1219 if (ir->efep != efepNO) {
1220 parse_n_double(foreign_lambda,&ir->n_flambda,&ir->flambda);
1221 if (ir->n_flambda > 0 && ir->rlist < max(ir->rvdw,ir->rcoulomb)) {
1222 warning_note(wi,"For foreign lambda free energy differences it is assumed that the soft-core interactions have no effect beyond the neighborlist cut-off");
1224 } else {
1225 ir->n_flambda = 0;
1228 sfree(dumstr[0]);
1229 sfree(dumstr[1]);
1232 static int search_QMstring(char *s,int ng,const char *gn[])
1234 /* same as normal search_string, but this one searches QM strings */
1235 int i;
1237 for(i=0; (i<ng); i++)
1238 if (strcasecmp(s,gn[i]) == 0)
1239 return i;
1241 gmx_fatal(FARGS,"this QM method or basisset (%s) is not implemented\n!",s);
1243 return -1;
1245 } /* search_QMstring */
1248 int search_string(char *s,int ng,char *gn[])
1250 int i;
1252 for(i=0; (i<ng); i++)
1253 if (strcasecmp(s,gn[i]) == 0)
1254 return i;
1256 gmx_fatal(FARGS,"Group %s not found in indexfile.\nMaybe you have non-default goups in your mdp file, while not using the '-n' option of grompp.\nIn that case use the '-n' option.\n",s);
1258 return -1;
1261 static bool do_numbering(int natoms,gmx_groups_t *groups,int ng,char *ptrs[],
1262 t_blocka *block,char *gnames[],
1263 int gtype,int restnm,
1264 int grptp,bool bVerbose,
1265 warninp_t wi)
1267 unsigned short *cbuf;
1268 t_grps *grps=&(groups->grps[gtype]);
1269 int i,j,gid,aj,ognr,ntot=0;
1270 const char *title;
1271 bool bRest;
1272 char warn_buf[STRLEN];
1274 if (debug)
1275 fprintf(debug,"Starting numbering %d groups of type %d\n",ng,gtype);
1277 title = gtypes[gtype];
1279 snew(cbuf,natoms);
1280 for(i=0; (i<natoms); i++)
1281 cbuf[i]=NOGID;
1283 snew(grps->nm_ind,ng+1); /* +1 for possible rest group */
1284 for(i=0; (i<ng); i++) {
1285 /* Lookup the group name in the block structure */
1286 gid = search_string(ptrs[i],block->nr,gnames);
1287 if ((grptp != egrptpONE) || (i == 0))
1288 grps->nm_ind[grps->nr++]=gid;
1289 if (debug)
1290 fprintf(debug,"Found gid %d for group %s\n",gid,ptrs[i]);
1292 /* Now go over the atoms in the group */
1293 for(j=block->index[gid]; (j<block->index[gid+1]); j++) {
1294 aj=block->a[j];
1296 /* Range checking */
1297 if ((aj < 0) || (aj >= natoms))
1298 gmx_fatal(FARGS,"Invalid atom number %d in indexfile",aj);
1300 /* Lookup up the old group number */
1301 ognr = cbuf[aj];
1302 if (ognr != NOGID)
1303 gmx_fatal(FARGS,"Atom %d in multiple %s groups (%d and %d)",
1304 aj+1,title,ognr+1,i+1);
1305 else {
1306 /* Store the group number in buffer */
1307 if (grptp == egrptpONE)
1308 cbuf[aj] = 0;
1309 else
1310 cbuf[aj] = i;
1311 ntot++;
1316 /* Now check whether we have done all atoms */
1317 bRest = FALSE;
1318 if (ntot != natoms) {
1319 if (grptp == egrptpALL) {
1320 gmx_fatal(FARGS,"%d atoms are not part of any of the %s groups",
1321 natoms-ntot,title);
1322 } else if (grptp == egrptpPART) {
1323 sprintf(warn_buf,"%d atoms are not part of any of the %s groups",
1324 natoms-ntot,title);
1325 warning_note(wi,warn_buf);
1327 /* Assign all atoms currently unassigned to a rest group */
1328 for(j=0; (j<natoms); j++) {
1329 if (cbuf[j] == NOGID) {
1330 cbuf[j] = grps->nr;
1331 bRest = TRUE;
1334 if (grptp != egrptpPART) {
1335 if (bVerbose)
1336 fprintf(stderr,
1337 "Making dummy/rest group for %s containing %d elements\n",
1338 title,natoms-ntot);
1339 /* Add group name "rest" */
1340 grps->nm_ind[grps->nr] = restnm;
1342 /* Assign the rest name to all atoms not currently assigned to a group */
1343 for(j=0; (j<natoms); j++) {
1344 if (cbuf[j] == NOGID)
1345 cbuf[j] = grps->nr;
1347 grps->nr++;
1351 if (grps->nr == 1) {
1352 groups->ngrpnr[gtype] = 0;
1353 groups->grpnr[gtype] = NULL;
1354 } else {
1355 groups->ngrpnr[gtype] = natoms;
1356 snew(groups->grpnr[gtype],natoms);
1357 for(j=0; (j<natoms); j++) {
1358 groups->grpnr[gtype][j] = cbuf[j];
1362 sfree(cbuf);
1364 return (bRest && grptp == egrptpPART);
1367 static void calc_nrdf(gmx_mtop_t *mtop,t_inputrec *ir,char **gnames)
1369 t_grpopts *opts;
1370 gmx_groups_t *groups;
1371 t_pull *pull;
1372 int natoms,ai,aj,i,j,d,g,imin,jmin,nc;
1373 t_iatom *ia;
1374 int *nrdf2,*na_vcm,na_tot;
1375 double *nrdf_tc,*nrdf_vcm,nrdf_uc,n_sub=0;
1376 gmx_mtop_atomloop_all_t aloop;
1377 t_atom *atom;
1378 int mb,mol,ftype,as;
1379 gmx_molblock_t *molb;
1380 gmx_moltype_t *molt;
1382 /* Calculate nrdf.
1383 * First calc 3xnr-atoms for each group
1384 * then subtract half a degree of freedom for each constraint
1386 * Only atoms and nuclei contribute to the degrees of freedom...
1389 opts = &ir->opts;
1391 groups = &mtop->groups;
1392 natoms = mtop->natoms;
1394 /* Allocate one more for a possible rest group */
1395 /* We need to sum degrees of freedom into doubles,
1396 * since floats give too low nrdf's above 3 million atoms.
1398 snew(nrdf_tc,groups->grps[egcTC].nr+1);
1399 snew(nrdf_vcm,groups->grps[egcVCM].nr+1);
1400 snew(na_vcm,groups->grps[egcVCM].nr+1);
1402 for(i=0; i<groups->grps[egcTC].nr; i++)
1403 nrdf_tc[i] = 0;
1404 for(i=0; i<groups->grps[egcVCM].nr+1; i++)
1405 nrdf_vcm[i] = 0;
1407 snew(nrdf2,natoms);
1408 aloop = gmx_mtop_atomloop_all_init(mtop);
1409 while (gmx_mtop_atomloop_all_next(aloop,&i,&atom)) {
1410 nrdf2[i] = 0;
1411 if (atom->ptype == eptAtom || atom->ptype == eptNucleus) {
1412 g = ggrpnr(groups,egcFREEZE,i);
1413 /* Double count nrdf for particle i */
1414 for(d=0; d<DIM; d++) {
1415 if (opts->nFreeze[g][d] == 0) {
1416 nrdf2[i] += 2;
1419 nrdf_tc [ggrpnr(groups,egcTC ,i)] += 0.5*nrdf2[i];
1420 nrdf_vcm[ggrpnr(groups,egcVCM,i)] += 0.5*nrdf2[i];
1424 as = 0;
1425 for(mb=0; mb<mtop->nmolblock; mb++) {
1426 molb = &mtop->molblock[mb];
1427 molt = &mtop->moltype[molb->type];
1428 atom = molt->atoms.atom;
1429 for(mol=0; mol<molb->nmol; mol++) {
1430 for (ftype=F_CONSTR; ftype<=F_CONSTRNC; ftype++) {
1431 ia = molt->ilist[ftype].iatoms;
1432 for(i=0; i<molt->ilist[ftype].nr; ) {
1433 /* Subtract degrees of freedom for the constraints,
1434 * if the particles still have degrees of freedom left.
1435 * If one of the particles is a vsite or a shell, then all
1436 * constraint motion will go there, but since they do not
1437 * contribute to the constraints the degrees of freedom do not
1438 * change.
1440 ai = as + ia[1];
1441 aj = as + ia[2];
1442 if (((atom[ia[1]].ptype == eptNucleus) ||
1443 (atom[ia[1]].ptype == eptAtom)) &&
1444 ((atom[ia[2]].ptype == eptNucleus) ||
1445 (atom[ia[2]].ptype == eptAtom))) {
1446 if (nrdf2[ai] > 0)
1447 jmin = 1;
1448 else
1449 jmin = 2;
1450 if (nrdf2[aj] > 0)
1451 imin = 1;
1452 else
1453 imin = 2;
1454 imin = min(imin,nrdf2[ai]);
1455 jmin = min(jmin,nrdf2[aj]);
1456 nrdf2[ai] -= imin;
1457 nrdf2[aj] -= jmin;
1458 nrdf_tc [ggrpnr(groups,egcTC ,ai)] -= 0.5*imin;
1459 nrdf_tc [ggrpnr(groups,egcTC ,aj)] -= 0.5*jmin;
1460 nrdf_vcm[ggrpnr(groups,egcVCM,ai)] -= 0.5*imin;
1461 nrdf_vcm[ggrpnr(groups,egcVCM,aj)] -= 0.5*jmin;
1463 ia += interaction_function[ftype].nratoms+1;
1464 i += interaction_function[ftype].nratoms+1;
1467 ia = molt->ilist[F_SETTLE].iatoms;
1468 for(i=0; i<molt->ilist[F_SETTLE].nr; ) {
1469 /* Subtract 1 dof from every atom in the SETTLE */
1470 for(ai=as+ia[1]; ai<as+ia[1]+3; ai++) {
1471 imin = min(2,nrdf2[ai]);
1472 nrdf2[ai] -= imin;
1473 nrdf_tc [ggrpnr(groups,egcTC ,ai)] -= 0.5*imin;
1474 nrdf_vcm[ggrpnr(groups,egcVCM,ai)] -= 0.5*imin;
1476 ia += 2;
1477 i += 2;
1479 as += molt->atoms.nr;
1483 if (ir->ePull == epullCONSTRAINT) {
1484 /* Correct nrdf for the COM constraints.
1485 * We correct using the TC and VCM group of the first atom
1486 * in the reference and pull group. If atoms in one pull group
1487 * belong to different TC or VCM groups it is anyhow difficult
1488 * to determine the optimal nrdf assignment.
1490 pull = ir->pull;
1491 if (pull->eGeom == epullgPOS) {
1492 nc = 0;
1493 for(i=0; i<DIM; i++) {
1494 if (pull->dim[i])
1495 nc++;
1497 } else {
1498 nc = 1;
1500 for(i=0; i<pull->ngrp; i++) {
1501 imin = 2*nc;
1502 if (pull->grp[0].nat > 0) {
1503 /* Subtract 1/2 dof from the reference group */
1504 ai = pull->grp[0].ind[0];
1505 if (nrdf_tc[ggrpnr(groups,egcTC,ai)] > 1) {
1506 nrdf_tc [ggrpnr(groups,egcTC ,ai)] -= 0.5;
1507 nrdf_vcm[ggrpnr(groups,egcVCM,ai)] -= 0.5;
1508 imin--;
1511 /* Subtract 1/2 dof from the pulled group */
1512 ai = pull->grp[1+i].ind[0];
1513 nrdf_tc [ggrpnr(groups,egcTC ,ai)] -= 0.5*imin;
1514 nrdf_vcm[ggrpnr(groups,egcVCM,ai)] -= 0.5*imin;
1515 if (nrdf_tc[ggrpnr(groups,egcTC,ai)] < 0)
1516 gmx_fatal(FARGS,"Center of mass pulling constraints caused the number of degrees of freedom for temperature coupling group %s to be negative",gnames[groups->grps[egcTC].nm_ind[ggrpnr(groups,egcTC,ai)]]);
1520 if (ir->nstcomm != 0) {
1521 /* Subtract 3 from the number of degrees of freedom in each vcm group
1522 * when com translation is removed and 6 when rotation is removed
1523 * as well.
1525 switch (ir->comm_mode) {
1526 case ecmLINEAR:
1527 n_sub = ndof_com(ir);
1528 break;
1529 case ecmANGULAR:
1530 n_sub = 6;
1531 break;
1532 default:
1533 n_sub = 0;
1534 gmx_incons("Checking comm_mode");
1537 for(i=0; i<groups->grps[egcTC].nr; i++) {
1538 /* Count the number of atoms of TC group i for every VCM group */
1539 for(j=0; j<groups->grps[egcVCM].nr+1; j++)
1540 na_vcm[j] = 0;
1541 na_tot = 0;
1542 for(ai=0; ai<natoms; ai++)
1543 if (ggrpnr(groups,egcTC,ai) == i) {
1544 na_vcm[ggrpnr(groups,egcVCM,ai)]++;
1545 na_tot++;
1547 /* Correct for VCM removal according to the fraction of each VCM
1548 * group present in this TC group.
1550 nrdf_uc = nrdf_tc[i];
1551 if (debug) {
1552 fprintf(debug,"T-group[%d] nrdf_uc = %g, n_sub = %g\n",
1553 i,nrdf_uc,n_sub);
1555 nrdf_tc[i] = 0;
1556 for(j=0; j<groups->grps[egcVCM].nr+1; j++) {
1557 if (nrdf_vcm[j] > n_sub) {
1558 nrdf_tc[i] += nrdf_uc*((double)na_vcm[j]/(double)na_tot)*
1559 (nrdf_vcm[j] - n_sub)/nrdf_vcm[j];
1561 if (debug) {
1562 fprintf(debug," nrdf_vcm[%d] = %g, nrdf = %g\n",
1563 j,nrdf_vcm[j],nrdf_tc[i]);
1568 for(i=0; (i<groups->grps[egcTC].nr); i++) {
1569 opts->nrdf[i] = nrdf_tc[i];
1570 if (opts->nrdf[i] < 0)
1571 opts->nrdf[i] = 0;
1572 fprintf(stderr,
1573 "Number of degrees of freedom in T-Coupling group %s is %.2f\n",
1574 gnames[groups->grps[egcTC].nm_ind[i]],opts->nrdf[i]);
1577 sfree(nrdf2);
1578 sfree(nrdf_tc);
1579 sfree(nrdf_vcm);
1580 sfree(na_vcm);
1583 static void decode_cos(char *s,t_cosines *cosine,bool bTime)
1585 char *t;
1586 char format[STRLEN],f1[STRLEN];
1587 double a,phi;
1588 int i;
1590 t=strdup(s);
1591 trim(t);
1593 cosine->n=0;
1594 cosine->a=NULL;
1595 cosine->phi=NULL;
1596 if (strlen(t)) {
1597 sscanf(t,"%d",&(cosine->n));
1598 if (cosine->n <= 0) {
1599 cosine->n=0;
1600 } else {
1601 snew(cosine->a,cosine->n);
1602 snew(cosine->phi,cosine->n);
1604 sprintf(format,"%%*d");
1605 for(i=0; (i<cosine->n); i++) {
1606 strcpy(f1,format);
1607 strcat(f1,"%lf%lf");
1608 if (sscanf(t,f1,&a,&phi) < 2)
1609 gmx_fatal(FARGS,"Invalid input for electric field shift: '%s'",t);
1610 cosine->a[i]=a;
1611 cosine->phi[i]=phi;
1612 strcat(format,"%*lf%*lf");
1616 sfree(t);
1619 static bool do_egp_flag(t_inputrec *ir,gmx_groups_t *groups,
1620 const char *option,const char *val,int flag)
1622 /* The maximum number of energy group pairs would be MAXPTR*(MAXPTR+1)/2.
1623 * But since this is much larger than STRLEN, such a line can not be parsed.
1624 * The real maximum is the number of names that fit in a string: STRLEN/2.
1626 #define EGP_MAX (STRLEN/2)
1627 int nelem,i,j,k,nr;
1628 char *names[EGP_MAX];
1629 char ***gnames;
1630 bool bSet;
1632 gnames = groups->grpname;
1634 nelem = str_nelem(val,EGP_MAX,names);
1635 if (nelem % 2 != 0)
1636 gmx_fatal(FARGS,"The number of groups for %s is odd",option);
1637 nr = groups->grps[egcENER].nr;
1638 bSet = FALSE;
1639 for(i=0; i<nelem/2; i++) {
1640 j = 0;
1641 while ((j < nr) &&
1642 strcasecmp(names[2*i],*(gnames[groups->grps[egcENER].nm_ind[j]])))
1643 j++;
1644 if (j == nr)
1645 gmx_fatal(FARGS,"%s in %s is not an energy group\n",
1646 names[2*i],option);
1647 k = 0;
1648 while ((k < nr) &&
1649 strcasecmp(names[2*i+1],*(gnames[groups->grps[egcENER].nm_ind[k]])))
1650 k++;
1651 if (k==nr)
1652 gmx_fatal(FARGS,"%s in %s is not an energy group\n",
1653 names[2*i+1],option);
1654 if ((j < nr) && (k < nr)) {
1655 ir->opts.egp_flags[nr*j+k] |= flag;
1656 ir->opts.egp_flags[nr*k+j] |= flag;
1657 bSet = TRUE;
1661 return bSet;
1664 void do_index(const char* mdparin, const char *ndx,
1665 gmx_mtop_t *mtop,
1666 bool bVerbose,
1667 t_inputrec *ir,rvec *v,
1668 warninp_t wi)
1670 t_blocka *grps;
1671 gmx_groups_t *groups;
1672 int natoms;
1673 t_symtab *symtab;
1674 t_atoms atoms_all;
1675 char warnbuf[STRLEN],**gnames;
1676 int nr,ntcg,ntau_t,nref_t,nacc,nofg,nSA,nSA_points,nSA_time,nSA_temp;
1677 int nstcmin;
1678 int nacg,nfreeze,nfrdim,nenergy,nvcm,nuser;
1679 char *ptr1[MAXPTR],*ptr2[MAXPTR],*ptr3[MAXPTR];
1680 int i,j,k,restnm;
1681 real SAtime;
1682 bool bExcl,bTable,bSetTCpar,bAnneal,bRest;
1683 int nQMmethod,nQMbasis,nQMcharge,nQMmult,nbSH,nCASorb,nCASelec,
1684 nSAon,nSAoff,nSAsteps,nQMg,nbOPT,nbTS;
1685 char warn_buf[STRLEN];
1687 if (bVerbose)
1688 fprintf(stderr,"processing index file...\n");
1689 debug_gmx();
1690 if (ndx == NULL) {
1691 snew(grps,1);
1692 snew(grps->index,1);
1693 snew(gnames,1);
1694 atoms_all = gmx_mtop_global_atoms(mtop);
1695 analyse(&atoms_all,grps,&gnames,FALSE,TRUE);
1696 free_t_atoms(&atoms_all,FALSE);
1697 } else {
1698 grps = init_index(ndx,&gnames);
1701 groups = &mtop->groups;
1702 natoms = mtop->natoms;
1703 symtab = &mtop->symtab;
1705 snew(groups->grpname,grps->nr+1);
1707 for(i=0; (i<grps->nr); i++) {
1708 groups->grpname[i] = put_symtab(symtab,gnames[i]);
1710 groups->grpname[i] = put_symtab(symtab,"rest");
1711 restnm=i;
1712 srenew(gnames,grps->nr+1);
1713 gnames[restnm] = *(groups->grpname[i]);
1714 groups->ngrpname = grps->nr+1;
1716 set_warning_line(wi,mdparin,-1);
1718 ntau_t = str_nelem(tau_t,MAXPTR,ptr1);
1719 nref_t = str_nelem(ref_t,MAXPTR,ptr2);
1720 ntcg = str_nelem(tcgrps,MAXPTR,ptr3);
1721 if ((ntau_t != ntcg) || (nref_t != ntcg)) {
1722 gmx_fatal(FARGS,"Invalid T coupling input: %d groups, %d ref_t values and "
1723 "%d tau_t values",ntcg,nref_t,ntau_t);
1726 bSetTCpar = (ir->etc || EI_SD(ir->eI) || ir->eI==eiBD || EI_TPI(ir->eI));
1727 do_numbering(natoms,groups,ntcg,ptr3,grps,gnames,egcTC,
1728 restnm,bSetTCpar ? egrptpALL : egrptpALL_GENREST,bVerbose,wi);
1729 nr = groups->grps[egcTC].nr;
1730 ir->opts.ngtc = nr;
1731 snew(ir->opts.nrdf,nr);
1732 snew(ir->opts.tau_t,nr);
1733 snew(ir->opts.ref_t,nr);
1734 if (ir->eI==eiBD && ir->bd_fric==0) {
1735 fprintf(stderr,"bd_fric=0, so tau_t will be used as the inverse friction constant(s)\n");
1738 if (bSetTCpar)
1740 if (nr != nref_t)
1742 gmx_fatal(FARGS,"Not enough ref_t and tau_t values!");
1744 nstcmin = (ir->etc == etcBERENDSEN ? nstcmin1 : nstcmin2);
1746 for(i=0; (i<nr); i++)
1748 ir->opts.tau_t[i] = strtod(ptr1[i],NULL);
1749 if (ir->opts.tau_t[i] < 0)
1751 gmx_fatal(FARGS,"tau_t for group %d negative",i);
1753 /* We check the relative magnitude of the coupling time tau_t.
1754 * V-rescale works correctly, even for tau_t=0.
1756 if ((ir->etc == etcBERENDSEN || ir->etc == etcNOSEHOOVER) &&
1757 ir->opts.tau_t[i] != 0 &&
1758 ir->opts.tau_t[i] < nstcmin*ir->nstcalcenergy*ir->delta_t)
1760 sprintf(warn_buf,"For proper integration of the %s thermostat, tau_t (%g) should be at least %d times larger than nstcalcenergy*dt (%g)",
1761 ETCOUPLTYPE(ir->etc),
1762 ir->opts.tau_t[i],nstcmin,
1763 ir->nstcalcenergy*ir->delta_t);
1764 warning(wi,warn_buf);
1767 for(i=0; (i<nr); i++)
1769 ir->opts.ref_t[i] = strtod(ptr2[i],NULL);
1770 if (ir->opts.ref_t[i] < 0)
1772 gmx_fatal(FARGS,"ref_t for group %d negative",i);
1777 /* Simulated annealing for each group. There are nr groups */
1778 nSA = str_nelem(anneal,MAXPTR,ptr1);
1779 if (nSA == 1 && (ptr1[0][0]=='n' || ptr1[0][0]=='N'))
1780 nSA = 0;
1781 if(nSA>0 && nSA != nr)
1782 gmx_fatal(FARGS,"Not enough annealing values: %d (for %d groups)\n",nSA,nr);
1783 else {
1784 snew(ir->opts.annealing,nr);
1785 snew(ir->opts.anneal_npoints,nr);
1786 snew(ir->opts.anneal_time,nr);
1787 snew(ir->opts.anneal_temp,nr);
1788 for(i=0;i<nr;i++) {
1789 ir->opts.annealing[i]=eannNO;
1790 ir->opts.anneal_npoints[i]=0;
1791 ir->opts.anneal_time[i]=NULL;
1792 ir->opts.anneal_temp[i]=NULL;
1794 if (nSA > 0) {
1795 bAnneal=FALSE;
1796 for(i=0;i<nr;i++) {
1797 if(ptr1[i][0]=='n' || ptr1[i][0]=='N') {
1798 ir->opts.annealing[i]=eannNO;
1799 } else if(ptr1[i][0]=='s'|| ptr1[i][0]=='S') {
1800 ir->opts.annealing[i]=eannSINGLE;
1801 bAnneal=TRUE;
1802 } else if(ptr1[i][0]=='p'|| ptr1[i][0]=='P') {
1803 ir->opts.annealing[i]=eannPERIODIC;
1804 bAnneal=TRUE;
1807 if(bAnneal) {
1808 /* Read the other fields too */
1809 nSA_points = str_nelem(anneal_npoints,MAXPTR,ptr1);
1810 if(nSA_points!=nSA)
1811 gmx_fatal(FARGS,"Found %d annealing_npoints values for %d groups\n",nSA_points,nSA);
1812 for(k=0,i=0;i<nr;i++) {
1813 ir->opts.anneal_npoints[i]=strtol(ptr1[i],NULL,10);
1814 if(ir->opts.anneal_npoints[i]==1)
1815 gmx_fatal(FARGS,"Please specify at least a start and an end point for annealing\n");
1816 snew(ir->opts.anneal_time[i],ir->opts.anneal_npoints[i]);
1817 snew(ir->opts.anneal_temp[i],ir->opts.anneal_npoints[i]);
1818 k += ir->opts.anneal_npoints[i];
1821 nSA_time = str_nelem(anneal_time,MAXPTR,ptr1);
1822 if(nSA_time!=k)
1823 gmx_fatal(FARGS,"Found %d annealing_time values, wanter %d\n",nSA_time,k);
1824 nSA_temp = str_nelem(anneal_temp,MAXPTR,ptr2);
1825 if(nSA_temp!=k)
1826 gmx_fatal(FARGS,"Found %d annealing_temp values, wanted %d\n",nSA_temp,k);
1828 for(i=0,k=0;i<nr;i++) {
1830 for(j=0;j<ir->opts.anneal_npoints[i];j++) {
1831 ir->opts.anneal_time[i][j]=strtod(ptr1[k],NULL);
1832 ir->opts.anneal_temp[i][j]=strtod(ptr2[k],NULL);
1833 if(j==0) {
1834 if(ir->opts.anneal_time[i][0] > (ir->init_t+GMX_REAL_EPS))
1835 gmx_fatal(FARGS,"First time point for annealing > init_t.\n");
1836 } else {
1837 /* j>0 */
1838 if(ir->opts.anneal_time[i][j]<ir->opts.anneal_time[i][j-1])
1839 gmx_fatal(FARGS,"Annealing timepoints out of order: t=%f comes after t=%f\n",
1840 ir->opts.anneal_time[i][j],ir->opts.anneal_time[i][j-1]);
1842 if(ir->opts.anneal_temp[i][j]<0)
1843 gmx_fatal(FARGS,"Found negative temperature in annealing: %f\n",ir->opts.anneal_temp[i][j]);
1844 k++;
1847 /* Print out some summary information, to make sure we got it right */
1848 for(i=0,k=0;i<nr;i++) {
1849 if(ir->opts.annealing[i]!=eannNO) {
1850 j = groups->grps[egcTC].nm_ind[i];
1851 fprintf(stderr,"Simulated annealing for group %s: %s, %d timepoints\n",
1852 *(groups->grpname[j]),eann_names[ir->opts.annealing[i]],
1853 ir->opts.anneal_npoints[i]);
1854 fprintf(stderr,"Time (ps) Temperature (K)\n");
1855 /* All terms except the last one */
1856 for(j=0;j<(ir->opts.anneal_npoints[i]-1);j++)
1857 fprintf(stderr,"%9.1f %5.1f\n",ir->opts.anneal_time[i][j],ir->opts.anneal_temp[i][j]);
1859 /* Finally the last one */
1860 j = ir->opts.anneal_npoints[i]-1;
1861 if(ir->opts.annealing[i]==eannSINGLE)
1862 fprintf(stderr,"%9.1f- %5.1f\n",ir->opts.anneal_time[i][j],ir->opts.anneal_temp[i][j]);
1863 else {
1864 fprintf(stderr,"%9.1f %5.1f\n",ir->opts.anneal_time[i][j],ir->opts.anneal_temp[i][j]);
1865 if(fabs(ir->opts.anneal_temp[i][j]-ir->opts.anneal_temp[i][0])>GMX_REAL_EPS)
1866 warning_note(wi,"There is a temperature jump when your annealing loops back.\n");
1874 if (ir->ePull != epullNO) {
1875 make_pull_groups(ir->pull,pull_grp,grps,gnames);
1878 nacc = str_nelem(acc,MAXPTR,ptr1);
1879 nacg = str_nelem(accgrps,MAXPTR,ptr2);
1880 if (nacg*DIM != nacc)
1881 gmx_fatal(FARGS,"Invalid Acceleration input: %d groups and %d acc. values",
1882 nacg,nacc);
1883 do_numbering(natoms,groups,nacg,ptr2,grps,gnames,egcACC,
1884 restnm,egrptpALL_GENREST,bVerbose,wi);
1885 nr = groups->grps[egcACC].nr;
1886 snew(ir->opts.acc,nr);
1887 ir->opts.ngacc=nr;
1889 for(i=k=0; (i<nacg); i++)
1890 for(j=0; (j<DIM); j++,k++)
1891 ir->opts.acc[i][j]=strtod(ptr1[k],NULL);
1892 for( ;(i<nr); i++)
1893 for(j=0; (j<DIM); j++)
1894 ir->opts.acc[i][j]=0;
1896 nfrdim = str_nelem(frdim,MAXPTR,ptr1);
1897 nfreeze = str_nelem(freeze,MAXPTR,ptr2);
1898 if (nfrdim != DIM*nfreeze)
1899 gmx_fatal(FARGS,"Invalid Freezing input: %d groups and %d freeze values",
1900 nfreeze,nfrdim);
1901 do_numbering(natoms,groups,nfreeze,ptr2,grps,gnames,egcFREEZE,
1902 restnm,egrptpALL_GENREST,bVerbose,wi);
1903 nr = groups->grps[egcFREEZE].nr;
1904 ir->opts.ngfrz=nr;
1905 snew(ir->opts.nFreeze,nr);
1906 for(i=k=0; (i<nfreeze); i++)
1907 for(j=0; (j<DIM); j++,k++) {
1908 ir->opts.nFreeze[i][j]=(strncasecmp(ptr1[k],"Y",1)==0);
1909 if (!ir->opts.nFreeze[i][j]) {
1910 if (strncasecmp(ptr1[k],"N",1) != 0) {
1911 sprintf(warnbuf,"Please use Y(ES) or N(O) for freezedim only "
1912 "(not %s)", ptr1[k]);
1913 warning(wi,warn_buf);
1917 for( ; (i<nr); i++)
1918 for(j=0; (j<DIM); j++)
1919 ir->opts.nFreeze[i][j]=0;
1921 nenergy=str_nelem(energy,MAXPTR,ptr1);
1922 do_numbering(natoms,groups,nenergy,ptr1,grps,gnames,egcENER,
1923 restnm,egrptpALL_GENREST,bVerbose,wi);
1924 add_wall_energrps(groups,ir->nwall,symtab);
1925 ir->opts.ngener = groups->grps[egcENER].nr;
1926 nvcm=str_nelem(vcm,MAXPTR,ptr1);
1927 bRest =
1928 do_numbering(natoms,groups,nvcm,ptr1,grps,gnames,egcVCM,
1929 restnm,nvcm==0 ? egrptpALL_GENREST : egrptpPART,bVerbose,wi);
1930 if (bRest) {
1931 warning(wi,"Some atoms are not part of any center of mass motion removal group.\n"
1932 "This may lead to artifacts.\n"
1933 "In most cases one should use one group for the whole system.");
1936 /* Now we have filled the freeze struct, so we can calculate NRDF */
1937 calc_nrdf(mtop,ir,gnames);
1939 if (v && NULL) {
1940 real fac,ntot=0;
1942 /* Must check per group! */
1943 for(i=0; (i<ir->opts.ngtc); i++)
1944 ntot += ir->opts.nrdf[i];
1945 if (ntot != (DIM*natoms)) {
1946 fac = sqrt(ntot/(DIM*natoms));
1947 if (bVerbose)
1948 fprintf(stderr,"Scaling velocities by a factor of %.3f to account for constraints\n"
1949 "and removal of center of mass motion\n",fac);
1950 for(i=0; (i<natoms); i++)
1951 svmul(fac,v[i],v[i]);
1955 nuser=str_nelem(user1,MAXPTR,ptr1);
1956 do_numbering(natoms,groups,nuser,ptr1,grps,gnames,egcUser1,
1957 restnm,egrptpALL_GENREST,bVerbose,wi);
1958 nuser=str_nelem(user2,MAXPTR,ptr1);
1959 do_numbering(natoms,groups,nuser,ptr1,grps,gnames,egcUser2,
1960 restnm,egrptpALL_GENREST,bVerbose,wi);
1961 nuser=str_nelem(xtc_grps,MAXPTR,ptr1);
1962 do_numbering(natoms,groups,nuser,ptr1,grps,gnames,egcXTC,
1963 restnm,egrptpONE,bVerbose,wi);
1964 nofg = str_nelem(orirefitgrp,MAXPTR,ptr1);
1965 do_numbering(natoms,groups,nofg,ptr1,grps,gnames,egcORFIT,
1966 restnm,egrptpALL_GENREST,bVerbose,wi);
1968 /* QMMM input processing */
1969 nQMg = str_nelem(QMMM,MAXPTR,ptr1);
1970 nQMmethod = str_nelem(QMmethod,MAXPTR,ptr2);
1971 nQMbasis = str_nelem(QMbasis,MAXPTR,ptr3);
1972 if((nQMmethod != nQMg)||(nQMbasis != nQMg)){
1973 gmx_fatal(FARGS,"Invalid QMMM input: %d groups %d basissets"
1974 " and %d methods\n",nQMg,nQMbasis,nQMmethod);
1976 /* group rest, if any, is always MM! */
1977 do_numbering(natoms,groups,nQMg,ptr1,grps,gnames,egcQMMM,
1978 restnm,egrptpALL_GENREST,bVerbose,wi);
1979 nr = nQMg; /*atoms->grps[egcQMMM].nr;*/
1980 ir->opts.ngQM = nQMg;
1981 snew(ir->opts.QMmethod,nr);
1982 snew(ir->opts.QMbasis,nr);
1983 for(i=0;i<nr;i++){
1984 /* input consists of strings: RHF CASSCF PM3 .. These need to be
1985 * converted to the corresponding enum in names.c
1987 ir->opts.QMmethod[i] = search_QMstring(ptr2[i],eQMmethodNR,
1988 eQMmethod_names);
1989 ir->opts.QMbasis[i] = search_QMstring(ptr3[i],eQMbasisNR,
1990 eQMbasis_names);
1993 nQMmult = str_nelem(QMmult,MAXPTR,ptr1);
1994 nQMcharge = str_nelem(QMcharge,MAXPTR,ptr2);
1995 nbSH = str_nelem(bSH,MAXPTR,ptr3);
1996 snew(ir->opts.QMmult,nr);
1997 snew(ir->opts.QMcharge,nr);
1998 snew(ir->opts.bSH,nr);
2000 for(i=0;i<nr;i++){
2001 ir->opts.QMmult[i] = strtol(ptr1[i],NULL,10);
2002 ir->opts.QMcharge[i] = strtol(ptr2[i],NULL,10);
2003 ir->opts.bSH[i] = (strncasecmp(ptr3[i],"Y",1)==0);
2006 nCASelec = str_nelem(CASelectrons,MAXPTR,ptr1);
2007 nCASorb = str_nelem(CASorbitals,MAXPTR,ptr2);
2008 snew(ir->opts.CASelectrons,nr);
2009 snew(ir->opts.CASorbitals,nr);
2010 for(i=0;i<nr;i++){
2011 ir->opts.CASelectrons[i]= strtol(ptr1[i],NULL,10);
2012 ir->opts.CASorbitals[i] = strtol(ptr2[i],NULL,10);
2014 /* special optimization options */
2016 nbOPT = str_nelem(bOPT,MAXPTR,ptr1);
2017 nbTS = str_nelem(bTS,MAXPTR,ptr2);
2018 snew(ir->opts.bOPT,nr);
2019 snew(ir->opts.bTS,nr);
2020 for(i=0;i<nr;i++){
2021 ir->opts.bOPT[i] = (strncasecmp(ptr1[i],"Y",1)==0);
2022 ir->opts.bTS[i] = (strncasecmp(ptr2[i],"Y",1)==0);
2024 nSAon = str_nelem(SAon,MAXPTR,ptr1);
2025 nSAoff = str_nelem(SAoff,MAXPTR,ptr2);
2026 nSAsteps = str_nelem(SAsteps,MAXPTR,ptr3);
2027 snew(ir->opts.SAon,nr);
2028 snew(ir->opts.SAoff,nr);
2029 snew(ir->opts.SAsteps,nr);
2031 for(i=0;i<nr;i++){
2032 ir->opts.SAon[i] = strtod(ptr1[i],NULL);
2033 ir->opts.SAoff[i] = strtod(ptr2[i],NULL);
2034 ir->opts.SAsteps[i] = strtol(ptr3[i],NULL,10);
2036 /* end of QMMM input */
2038 if (bVerbose)
2039 for(i=0; (i<egcNR); i++) {
2040 fprintf(stderr,"%-16s has %d element(s):",gtypes[i],groups->grps[i].nr);
2041 for(j=0; (j<groups->grps[i].nr); j++)
2042 fprintf(stderr," %s",*(groups->grpname[groups->grps[i].nm_ind[j]]));
2043 fprintf(stderr,"\n");
2046 nr = groups->grps[egcENER].nr;
2047 snew(ir->opts.egp_flags,nr*nr);
2049 bExcl = do_egp_flag(ir,groups,"energygrp_excl",egpexcl,EGP_EXCL);
2050 if (bExcl && EEL_FULL(ir->coulombtype))
2051 warning(wi,"Can not exclude the lattice Coulomb energy between energy groups");
2053 bTable = do_egp_flag(ir,groups,"energygrp_table",egptable,EGP_TABLE);
2054 if (bTable && !(ir->vdwtype == evdwUSER) &&
2055 !(ir->coulombtype == eelUSER) &&!(ir->coulombtype == eelPMEUSER))
2056 gmx_fatal(FARGS,"Can only have energy group pair tables in combination with user tables for VdW and/or Coulomb");
2058 decode_cos(efield_x,&(ir->ex[XX]),FALSE);
2059 decode_cos(efield_xt,&(ir->et[XX]),TRUE);
2060 decode_cos(efield_y,&(ir->ex[YY]),FALSE);
2061 decode_cos(efield_yt,&(ir->et[YY]),TRUE);
2062 decode_cos(efield_z,&(ir->ex[ZZ]),FALSE);
2063 decode_cos(efield_zt,&(ir->et[ZZ]),TRUE);
2065 for(i=0; (i<grps->nr); i++)
2066 sfree(gnames[i]);
2067 sfree(gnames);
2068 done_blocka(grps);
2069 sfree(grps);
2075 static void check_disre(gmx_mtop_t *mtop)
2077 gmx_ffparams_t *ffparams;
2078 t_functype *functype;
2079 t_iparams *ip;
2080 int i,ndouble,ftype;
2081 int label,old_label;
2083 if (gmx_mtop_ftype_count(mtop,F_DISRES) > 0) {
2084 ffparams = &mtop->ffparams;
2085 functype = ffparams->functype;
2086 ip = ffparams->iparams;
2087 ndouble = 0;
2088 old_label = -1;
2089 for(i=0; i<ffparams->ntypes; i++) {
2090 ftype = functype[i];
2091 if (ftype == F_DISRES) {
2092 label = ip[i].disres.label;
2093 if (label == old_label) {
2094 fprintf(stderr,"Distance restraint index %d occurs twice\n",label);
2095 ndouble++;
2097 old_label = label;
2100 if (ndouble>0)
2101 gmx_fatal(FARGS,"Found %d double distance restraint indices,\n"
2102 "probably the parameters for multiple pairs in one restraint "
2103 "are not identical\n",ndouble);
2107 static bool absolute_reference(t_inputrec *ir,gmx_mtop_t *sys,ivec AbsRef)
2109 int d,g,i;
2110 gmx_mtop_ilistloop_t iloop;
2111 t_ilist *ilist;
2112 int nmol;
2113 t_iparams *pr;
2115 /* Check the COM */
2116 for(d=0; d<DIM; d++) {
2117 AbsRef[d] = (d < ndof_com(ir) ? 0 : 1);
2119 /* Check for freeze groups */
2120 for(g=0; g<ir->opts.ngfrz; g++) {
2121 for(d=0; d<DIM; d++) {
2122 if (ir->opts.nFreeze[g][d] != 0) {
2123 AbsRef[d] = 1;
2127 /* Check for position restraints */
2128 iloop = gmx_mtop_ilistloop_init(sys);
2129 while (gmx_mtop_ilistloop_next(iloop,&ilist,&nmol)) {
2130 if (nmol > 0) {
2131 for(i=0; i<ilist[F_POSRES].nr; i+=2) {
2132 pr = &sys->ffparams.iparams[ilist[F_POSRES].iatoms[i]];
2133 for(d=0; d<DIM; d++) {
2134 if (pr->posres.fcA[d] != 0) {
2135 AbsRef[d] = 1;
2142 return (AbsRef[XX] != 0 && AbsRef[YY] != 0 && AbsRef[ZZ] != 0);
2145 void triple_check(const char *mdparin,t_inputrec *ir,gmx_mtop_t *sys,
2146 warninp_t wi)
2148 char err_buf[256];
2149 int i,m,g,nmol,npct;
2150 bool bCharge,bAcc;
2151 real gdt_max,*mgrp,mt;
2152 rvec acc;
2153 gmx_mtop_atomloop_block_t aloopb;
2154 gmx_mtop_atomloop_all_t aloop;
2155 t_atom *atom;
2156 ivec AbsRef;
2157 char warn_buf[STRLEN];
2159 set_warning_line(wi,mdparin,-1);
2161 if (EI_DYNAMICS(ir->eI) && !EI_SD(ir->eI) && ir->eI != eiBD &&
2162 ir->comm_mode == ecmNO &&
2163 !(absolute_reference(ir,sys,AbsRef) || ir->nsteps <= 10)) {
2164 warning(wi,"You are not using center of mass motion removal (mdp option comm-mode), numerical rounding errors can lead to build up of kinetic energy of the center of mass");
2167 bCharge = FALSE;
2168 aloopb = gmx_mtop_atomloop_block_init(sys);
2169 while (gmx_mtop_atomloop_block_next(aloopb,&atom,&nmol)) {
2170 if (atom->q != 0 || atom->qB != 0) {
2171 bCharge = TRUE;
2175 if (!bCharge) {
2176 if (EEL_FULL(ir->coulombtype)) {
2177 sprintf(err_buf,
2178 "You are using full electrostatics treatment %s for a system without charges.\n"
2179 "This costs a lot of performance for just processing zeros, consider using %s instead.\n",
2180 EELTYPE(ir->coulombtype),EELTYPE(eelCUT));
2181 warning(wi,err_buf);
2183 } else {
2184 if (ir->coulombtype == eelCUT && ir->rcoulomb > 0) {
2185 sprintf(err_buf,
2186 "You are using a plain Coulomb cut-off, which might produce artifacts.\n"
2187 "You might want to consider using %s electrostatics.\n",
2188 EELTYPE(eelPME));
2189 warning_note(wi,err_buf);
2193 /* Generalized reaction field */
2194 if (ir->opts.ngtc == 0) {
2195 sprintf(err_buf,"No temperature coupling while using coulombtype %s",
2196 eel_names[eelGRF]);
2197 CHECK(ir->coulombtype == eelGRF);
2199 else {
2200 sprintf(err_buf,"When using coulombtype = %s"
2201 " ref_t for temperature coupling should be > 0",
2202 eel_names[eelGRF]);
2203 CHECK((ir->coulombtype == eelGRF) && (ir->opts.ref_t[0] <= 0));
2206 if (ir->eI == eiSD1) {
2207 gdt_max = 0;
2208 for(i=0; (i<ir->opts.ngtc); i++)
2209 gdt_max = max(gdt_max,ir->delta_t/ir->opts.tau_t[i]);
2210 if (0.5*gdt_max > 0.0015) {
2211 sprintf(warn_buf,"The relative error with integrator %s is 0.5*delta_t/tau_t = %g, you might want to switch to integrator %s\n",
2212 ei_names[ir->eI],0.5*gdt_max,ei_names[eiSD2]);
2213 warning_note(wi,warn_buf);
2217 bAcc = FALSE;
2218 for(i=0; (i<sys->groups.grps[egcACC].nr); i++) {
2219 for(m=0; (m<DIM); m++) {
2220 if (fabs(ir->opts.acc[i][m]) > 1e-6) {
2221 bAcc = TRUE;
2225 if (bAcc) {
2226 clear_rvec(acc);
2227 snew(mgrp,sys->groups.grps[egcACC].nr);
2228 aloop = gmx_mtop_atomloop_all_init(sys);
2229 while (gmx_mtop_atomloop_all_next(aloop,&i,&atom)) {
2230 mgrp[ggrpnr(&sys->groups,egcACC,i)] += atom->m;
2232 mt = 0.0;
2233 for(i=0; (i<sys->groups.grps[egcACC].nr); i++) {
2234 for(m=0; (m<DIM); m++)
2235 acc[m] += ir->opts.acc[i][m]*mgrp[i];
2236 mt += mgrp[i];
2238 for(m=0; (m<DIM); m++) {
2239 if (fabs(acc[m]) > 1e-6) {
2240 const char *dim[DIM] = { "X", "Y", "Z" };
2241 fprintf(stderr,
2242 "Net Acceleration in %s direction, will %s be corrected\n",
2243 dim[m],ir->nstcomm != 0 ? "" : "not");
2244 if (ir->nstcomm != 0 && m < ndof_com(ir)) {
2245 acc[m] /= mt;
2246 for (i=0; (i<sys->groups.grps[egcACC].nr); i++)
2247 ir->opts.acc[i][m] -= acc[m];
2251 sfree(mgrp);
2254 if (ir->efep != efepNO && ir->sc_alpha != 0 &&
2255 !gmx_within_tol(sys->ffparams.reppow,12.0,10*GMX_DOUBLE_EPS)) {
2256 gmx_fatal(FARGS,"Soft-core interactions are only supported with VdW repulsion power 12");
2259 if (ir->ePull != epullNO) {
2260 if (ir->pull->grp[0].nat == 0) {
2261 absolute_reference(ir,sys,AbsRef);
2262 for(m=0; m<DIM; m++) {
2263 if (ir->pull->dim[m] && !AbsRef[m]) {
2264 warning(wi,"You are using an absolute reference for pulling, but the rest of the system does not have an absolute reference. This will lead to artifacts.");
2265 break;
2270 if (ir->pull->eGeom == epullgDIRPBC) {
2271 for(i=0; i<3; i++) {
2272 for(m=0; m<=i; m++) {
2273 if ((ir->epc != epcNO && ir->compress[i][m] != 0) ||
2274 ir->deform[i][m] != 0) {
2275 for(g=1; g<ir->pull->ngrp; g++) {
2276 if (ir->pull->grp[g].vec[m] != 0) {
2277 gmx_fatal(FARGS,"Can not have dynamic box while using pull geometry '%s' (dim %c)",EPULLGEOM(ir->pull->eGeom),'x'+m);
2286 check_disre(sys);
2289 void double_check(t_inputrec *ir,matrix box,bool bConstr,warninp_t wi)
2291 real min_size;
2292 bool bTWIN;
2293 char warn_buf[STRLEN];
2294 const char *ptr;
2296 ptr = check_box(ir->ePBC,box);
2297 if (ptr) {
2298 warning_error(wi,ptr);
2301 if (bConstr && ir->eConstrAlg == econtSHAKE) {
2302 if (ir->shake_tol <= 0.0) {
2303 sprintf(warn_buf,"ERROR: shake_tol must be > 0 instead of %g\n",
2304 ir->shake_tol);
2305 warning_error(wi,warn_buf);
2308 if (IR_TWINRANGE(*ir) && ir->nstlist > 1) {
2309 sprintf(warn_buf,"With twin-range cut-off's and SHAKE the virial and the pressure are incorrect.");
2310 if (ir->epc == epcNO) {
2311 warning(wi,warn_buf);
2312 } else {
2313 warning_error(wi,warn_buf);
2318 if( (ir->eConstrAlg == econtLINCS) && bConstr) {
2319 /* If we have Lincs constraints: */
2320 if(ir->eI==eiMD && ir->etc==etcNO &&
2321 ir->eConstrAlg==econtLINCS && ir->nLincsIter==1) {
2322 sprintf(warn_buf,"For energy conservation with LINCS, lincs_iter should be 2 or larger.\n");
2323 warning_note(wi,warn_buf);
2326 if ((ir->eI == eiCG || ir->eI == eiLBFGS) && (ir->nProjOrder<8)) {
2327 sprintf(warn_buf,"For accurate %s with LINCS constraints, lincs_order should be 8 or more.",ei_names[ir->eI]);
2328 warning_note(wi,warn_buf);
2330 if (ir->epc==epcMTTK) {
2331 warning_error(wi,"MTTK not compatible with lincs -- use shake instead.");
2335 if (ir->LincsWarnAngle > 90.0) {
2336 sprintf(warn_buf,"lincs-warnangle can not be larger than 90 degrees, setting it to 90.\n");
2337 warning(wi,warn_buf);
2338 ir->LincsWarnAngle = 90.0;
2341 if (ir->ePBC != epbcNONE) {
2342 if (ir->nstlist == 0) {
2343 warning(wi,"With nstlist=0 atoms are only put into the box at step 0, therefore drifting atoms might cause the simulation to crash.");
2345 bTWIN = (ir->rlistlong > ir->rlist);
2346 if (ir->ns_type == ensGRID) {
2347 if (sqr(ir->rlistlong) >= max_cutoff2(ir->ePBC,box)) {
2348 sprintf(warn_buf,"ERROR: The cut-off length is longer than half the shortest box vector or longer than the smallest box diagonal element. Increase the box size or decrease %s.\n",
2349 bTWIN ? (ir->rcoulomb==ir->rlistlong ? "rcoulomb" : "rvdw"):"rlist");
2350 warning_error(wi,warn_buf);
2352 } else {
2353 min_size = min(box[XX][XX],min(box[YY][YY],box[ZZ][ZZ]));
2354 if (2*ir->rlistlong >= min_size) {
2355 sprintf(warn_buf,"ERROR: One of the box lengths is smaller than twice the cut-off length. Increase the box size or decrease rlist.");
2356 warning_error(wi,warn_buf);
2357 if (TRICLINIC(box))
2358 fprintf(stderr,"Grid search might allow larger cut-off's than simple search with triclinic boxes.");
2364 void check_chargegroup_radii(const gmx_mtop_t *mtop,const t_inputrec *ir,
2365 rvec *x,
2366 warninp_t wi)
2368 real rvdw1,rvdw2,rcoul1,rcoul2;
2369 char warn_buf[STRLEN];
2371 calc_chargegroup_radii(mtop,x,&rvdw1,&rvdw2,&rcoul1,&rcoul2);
2373 if (rvdw1 > 0)
2375 printf("Largest charge group radii for Van der Waals: %5.3f, %5.3f nm\n",
2376 rvdw1,rvdw2);
2378 if (rcoul1 > 0)
2380 printf("Largest charge group radii for Coulomb: %5.3f, %5.3f nm\n",
2381 rcoul1,rcoul2);
2384 if (ir->rlist > 0)
2386 if (rvdw1 + rvdw2 > ir->rlist ||
2387 rcoul1 + rcoul2 > ir->rlist)
2389 sprintf(warn_buf,"The sum of the two largest charge group radii (%f) is larger than rlist (%f)\n",max(rvdw1+rvdw2,rcoul1+rcoul2),ir->rlist);
2390 warning(wi,warn_buf);
2392 else
2394 /* Here we do not use the zero at cut-off macro,
2395 * since user defined interactions might purposely
2396 * not be zero at the cut-off.
2398 if (EVDW_IS_ZERO_AT_CUTOFF(ir->vdwtype) &&
2399 rvdw1 + rvdw2 > ir->rlistlong - ir->rvdw)
2401 sprintf(warn_buf,"The sum of the two largest charge group radii (%f) is larger than %s (%f) - rvdw (%f)\n",
2402 rvdw1+rvdw2,
2403 ir->rlistlong > ir->rlist ? "rlistlong" : "rlist",
2404 ir->rlist,ir->rvdw);
2405 if (ir_NVE(ir))
2407 warning(wi,warn_buf);
2409 else
2411 warning_note(wi,warn_buf);
2414 if (EEL_IS_ZERO_AT_CUTOFF(ir->coulombtype) &&
2415 rcoul1 + rcoul2 > ir->rlistlong - ir->rcoulomb)
2417 sprintf(warn_buf,"The sum of the two largest charge group radii (%f) is larger than %s (%f) - rcoulomb (%f)\n",
2418 rcoul1+rcoul2,
2419 ir->rlistlong > ir->rlist ? "rlistlong" : "rlist",
2420 ir->rlistlong,ir->rcoulomb);
2421 if (ir_NVE(ir))
2423 warning(wi,warn_buf);
2425 else
2427 warning_note(wi,warn_buf);