added some comment to group grompp assignment options
[gromacs.git] / src / kernel / readir.c
blob85703f58a7694af4c4b0f9c7ae1647bd39c47a0b
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"
63 #include "inputrec.h"
65 #define MAXPTR 254
66 #define NOGID 255
68 /* Resource parameters
69 * Do not change any of these until you read the instruction
70 * in readinp.h. Some cpp's do not take spaces after the backslash
71 * (like the c-shell), which will give you a very weird compiler
72 * message.
75 static char tcgrps[STRLEN],tau_t[STRLEN],ref_t[STRLEN],
76 acc[STRLEN],accgrps[STRLEN],freeze[STRLEN],frdim[STRLEN],
77 energy[STRLEN],user1[STRLEN],user2[STRLEN],vcm[STRLEN],xtc_grps[STRLEN],
78 couple_moltype[STRLEN],orirefitgrp[STRLEN],egptable[STRLEN],egpexcl[STRLEN],
79 wall_atomtype[STRLEN],wall_density[STRLEN],deform[STRLEN],QMMM[STRLEN];
80 static char foreign_lambda[STRLEN];
81 static char **pull_grp;
82 static char anneal[STRLEN],anneal_npoints[STRLEN],
83 anneal_time[STRLEN],anneal_temp[STRLEN];
84 static char QMmethod[STRLEN],QMbasis[STRLEN],QMcharge[STRLEN],QMmult[STRLEN],
85 bSH[STRLEN],CASorbitals[STRLEN], CASelectrons[STRLEN],SAon[STRLEN],
86 SAoff[STRLEN],SAsteps[STRLEN],bTS[STRLEN],bOPT[STRLEN];
87 static char efield_x[STRLEN],efield_xt[STRLEN],efield_y[STRLEN],
88 efield_yt[STRLEN],efield_z[STRLEN],efield_zt[STRLEN];
90 enum {
91 egrptpALL, /* All particles have to be a member of a group. */
92 egrptpALL_GENREST, /* A rest group with name is generated for particles *
93 * that are not part of any group. */
94 egrptpPART, /* As egrptpALL_GENREST, but no name is generated *
95 * for the rest group. */
96 egrptpONE /* Merge all selected groups into one group, *
97 * make a rest group for the remaining particles. */
101 void init_ir(t_inputrec *ir, t_gromppopts *opts)
103 snew(opts->include,STRLEN);
104 snew(opts->define,STRLEN);
107 static void _low_check(bool b,char *s,warninp_t wi)
109 if (b)
111 warning_error(wi,s);
115 static void check_nst(const char *desc_nst,int nst,
116 const char *desc_p,int *p,
117 warninp_t wi)
119 char buf[STRLEN];
121 if (*p > 0 && *p % nst != 0)
123 /* Round up to the next multiple of nst */
124 *p = ((*p)/nst + 1)*nst;
125 sprintf(buf,"%s should be a multiple of %s, changing %s to %d\n",
126 desc_p,desc_nst,desc_p,*p);
127 warning(wi,buf);
131 static bool ir_NVE(const t_inputrec *ir)
133 return ((ir->eI == eiMD || EI_VV(ir->eI)) && ir->etc == etcNO);
136 static int lcd(int n1,int n2)
138 int d,i;
140 d = 1;
141 for(i=2; (i<=n1 && i<=n2); i++)
143 if (n1 % i == 0 && n2 % i == 0)
145 d = i;
149 return d;
152 void check_ir(const char *mdparin,t_inputrec *ir, t_gromppopts *opts,
153 warninp_t wi)
154 /* Check internal consistency */
156 /* Strange macro: first one fills the err_buf, and then one can check
157 * the condition, which will print the message and increase the error
158 * counter.
160 #define CHECK(b) _low_check(b,err_buf,wi)
161 char err_buf[256],warn_buf[STRLEN];
162 int ns_type=0;
163 real dt_pcoupl;
165 set_warning_line(wi,mdparin,-1);
167 /* BASIC CUT-OFF STUFF */
168 if (ir->rlist == 0 ||
169 !((EEL_MIGHT_BE_ZERO_AT_CUTOFF(ir->coulombtype) && ir->rcoulomb > ir->rlist) ||
170 (EVDW_MIGHT_BE_ZERO_AT_CUTOFF(ir->vdwtype) && ir->rvdw > ir->rlist))) {
171 /* No switched potential and/or no twin-range:
172 * we can set the long-range cut-off to the maximum of the other cut-offs.
174 ir->rlistlong = max_cutoff(ir->rlist,max_cutoff(ir->rvdw,ir->rcoulomb));
175 } else if (ir->rlistlong < 0) {
176 ir->rlistlong = max_cutoff(ir->rlist,max_cutoff(ir->rvdw,ir->rcoulomb));
177 sprintf(warn_buf,"rlistlong was not set, setting it to %g (no buffer)",
178 ir->rlistlong);
179 warning(wi,warn_buf);
181 if (ir->rlistlong == 0 && ir->ePBC != epbcNONE) {
182 warning_error(wi,"Can not have an infinite cut-off with PBC");
184 if (ir->rlistlong > 0 && (ir->rlist == 0 || ir->rlistlong < ir->rlist)) {
185 warning_error(wi,"rlistlong can not be shorter than rlist");
187 if (IR_TWINRANGE(*ir) && ir->nstlist <= 0) {
188 warning_error(wi,"Can not have nstlist<=0 with twin-range interactions");
191 /* GENERAL INTEGRATOR STUFF */
192 if (!(ir->eI == eiMD || EI_VV(ir->eI)))
194 ir->etc = etcNO;
196 if (!EI_DYNAMICS(ir->eI))
198 ir->epc = epcNO;
200 if (EI_DYNAMICS(ir->eI))
202 if (ir->nstcalcenergy < 0)
204 ir->nstcalcenergy = ir_optimal_nstcalcenergy(ir);
205 if (ir->nstenergy != 0 && ir->nstenergy < ir->nstcalcenergy)
207 /* nstcalcenergy larger than nstener does not make sense.
208 * We ideally want nstcalcenergy=nstener.
210 if (ir->nstlist > 0)
212 ir->nstcalcenergy = lcd(ir->nstenergy,ir->nstlist);
214 else
216 ir->nstcalcenergy = ir->nstenergy;
220 if (ir->epc != epcNO)
222 if (EI_VV(ir->eI))
224 /* This should be removed when VV supports nstpcouple */
225 ir->nstpcouple = 1;
227 if (ir->nstpcouple < 0)
229 ir->nstpcouple = ir_optimal_nstpcouple(ir);
232 if (IR_TWINRANGE(*ir))
234 check_nst("nstlist",ir->nstlist,
235 "nstcalcenergy",&ir->nstcalcenergy,wi);
236 if (ir->epc != epcNO)
238 check_nst("nstlist",ir->nstlist,
239 "nstpcouple",&ir->nstpcouple,wi);
243 if (ir->nstcalcenergy > 1)
245 /* for storing exact averages nstenergy should be
246 * a multiple of nstcalcenergy
248 check_nst("nstcalcenergy",ir->nstcalcenergy,
249 "nstenergy",&ir->nstenergy,wi);
250 if (ir->efep != efepNO)
252 /* nstdhdl should be a multiple of nstcalcenergy */
253 check_nst("nstcalcenergy",ir->nstcalcenergy,
254 "nstdhdl",&ir->nstdhdl,wi);
259 /* LD STUFF */
260 if ((EI_SD(ir->eI) || ir->eI == eiBD) &&
261 ir->bContinuation && ir->ld_seed != -1) {
262 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)");
265 /* TPI STUFF */
266 if (EI_TPI(ir->eI)) {
267 sprintf(err_buf,"TPI only works with pbc = %s",epbc_names[epbcXYZ]);
268 CHECK(ir->ePBC != epbcXYZ);
269 sprintf(err_buf,"TPI only works with ns = %s",ens_names[ensGRID]);
270 CHECK(ir->ns_type != ensGRID);
271 sprintf(err_buf,"with TPI nstlist should be larger than zero");
272 CHECK(ir->nstlist <= 0);
273 sprintf(err_buf,"TPI does not work with full electrostatics other than PME");
274 CHECK(EEL_FULL(ir->coulombtype) && !EEL_PME(ir->coulombtype));
277 /* SHAKE / LINCS */
278 if ( (opts->nshake > 0) && (opts->bMorse) ) {
279 sprintf(warn_buf,
280 "Using morse bond-potentials while constraining bonds is useless");
281 warning(wi,warn_buf);
284 sprintf(err_buf,"shake_tol must be > 0 instead of %g while using shake",
285 ir->shake_tol);
286 CHECK(((ir->shake_tol <= 0.0) && (opts->nshake>0) &&
287 (ir->eConstrAlg == econtSHAKE)));
289 /* PBC/WALLS */
290 sprintf(err_buf,"walls only work with pbc=%s",epbc_names[epbcXY]);
291 CHECK(ir->nwall && ir->ePBC!=epbcXY);
293 /* VACUUM STUFF */
294 if (ir->ePBC != epbcXYZ && ir->nwall != 2) {
295 if (ir->ePBC == epbcNONE) {
296 if (ir->epc != epcNO) {
297 warning(wi,"Turning off pressure coupling for vacuum system");
298 ir->epc = epcNO;
300 } else {
301 sprintf(err_buf,"Can not have pressure coupling with pbc=%s",
302 epbc_names[ir->ePBC]);
303 CHECK(ir->epc != epcNO);
305 sprintf(err_buf,"Can not have Ewald with pbc=%s",epbc_names[ir->ePBC]);
306 CHECK(EEL_FULL(ir->coulombtype));
308 sprintf(err_buf,"Can not have dispersion correction with pbc=%s",
309 epbc_names[ir->ePBC]);
310 CHECK(ir->eDispCorr != edispcNO);
313 if (ir->rlist == 0.0) {
314 sprintf(err_buf,"can only have neighborlist cut-off zero (=infinite)\n"
315 "with coulombtype = %s or coulombtype = %s\n"
316 "without periodic boundary conditions (pbc = %s) and\n"
317 "rcoulomb and rvdw set to zero",
318 eel_names[eelCUT],eel_names[eelUSER],epbc_names[epbcNONE]);
319 CHECK(((ir->coulombtype != eelCUT) && (ir->coulombtype != eelUSER)) ||
320 (ir->ePBC != epbcNONE) ||
321 (ir->rcoulomb != 0.0) || (ir->rvdw != 0.0));
323 if (ir->nstlist < 0) {
324 warning_error(wi,"Can not have heuristic neighborlist updates without cut-off");
326 if (ir->nstlist > 0) {
327 warning_note(wi,"Simulating without cut-offs is usually (slightly) faster with nstlist=0, nstype=simple and particle decomposition");
331 /* COMM STUFF */
332 if (ir->nstcomm == 0) {
333 ir->comm_mode = ecmNO;
335 if (ir->comm_mode != ecmNO) {
336 if (ir->nstcomm < 0) {
337 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");
338 ir->nstcomm = abs(ir->nstcomm);
341 if (ir->nstcalcenergy > 0 && ir->nstcomm < ir->nstcalcenergy) {
342 warning_note(wi,"nstcomm < nstcalcenergy defeats the purpose of nstcalcenergy, setting nstcomm to nstcalcenergy");
343 ir->nstcomm = ir->nstcalcenergy;
346 if (ir->comm_mode == ecmANGULAR) {
347 sprintf(err_buf,"Can not remove the rotation around the center of mass with periodic molecules");
348 CHECK(ir->bPeriodicMols);
349 if (ir->ePBC != epbcNONE)
350 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).");
354 if (EI_STATE_VELOCITY(ir->eI) && ir->ePBC == epbcNONE && ir->comm_mode != ecmANGULAR) {
355 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.");
358 sprintf(err_buf,"Free-energy not implemented for Ewald and PPPM");
359 CHECK((ir->coulombtype==eelEWALD || ir->coulombtype==eelPPPM)
360 && (ir->efep!=efepNO));
362 sprintf(err_buf,"Twin-range neighbour searching (NS) with simple NS"
363 " algorithm not implemented");
364 CHECK(((ir->rcoulomb > ir->rlist) || (ir->rvdw > ir->rlist))
365 && (ir->ns_type == ensSIMPLE));
367 /* TEMPERATURE COUPLING */
368 if (ir->etc == etcYES)
370 ir->etc = etcBERENDSEN;
371 warning_note(wi,"Old option for temperature coupling given: "
372 "changing \"yes\" to \"Berendsen\"\n");
375 if (ir->etc == etcNOSEHOOVER)
377 if (ir->opts.nhchainlength < 1)
379 sprintf(warn_buf,"number of Nose-Hoover chains (currently %d) cannot be less than 1,reset to 1\n",ir->opts.nhchainlength);
380 ir->opts.nhchainlength =1;
381 warning(wi,warn_buf);
384 if (ir->etc==etcNOSEHOOVER && !EI_VV(ir->eI) && ir->opts.nhchainlength > 1)
386 warning_note(wi,"leapfrog does not yet support Nose-Hoover chains, nhchainlength reset to 1");
387 ir->opts.nhchainlength = 1;
390 else
392 ir->opts.nhchainlength = 0;
395 if (ir->etc == etcBERENDSEN)
397 sprintf(warn_buf,"The %s thermostat does not generate the correct kinetic energy distribution. You might want to consider using the %s thermostat.",
398 ETCOUPLTYPE(ir->etc),ETCOUPLTYPE(etcVRESCALE));
399 warning_note(wi,warn_buf);
402 if ((ir->etc==etcNOSEHOOVER || ir->etc==etcANDERSEN || ir->etc==etcANDERSENINTERVAL)
403 && ir->epc==epcBERENDSEN)
405 sprintf(warn_buf,"Using Berendsen pressure coupling invalidates the "
406 "true ensemble for the thermostat");
407 warning(wi,warn_buf);
410 /* PRESSURE COUPLING */
411 if (ir->epc == epcISOTROPIC)
413 ir->epc = epcBERENDSEN;
414 warning_note(wi,"Old option for pressure coupling given: "
415 "changing \"Isotropic\" to \"Berendsen\"\n");
418 if (ir->epc != epcNO)
420 dt_pcoupl = ir->nstpcouple*ir->delta_t;
422 sprintf(err_buf,"tau_p must be > 0 instead of %g\n",ir->tau_p);
423 CHECK(ir->tau_p <= 0);
425 if (ir->tau_p/dt_pcoupl < pcouple_min_integration_steps(ir->epc))
427 sprintf(warn_buf,"For proper integration of the %s barostat, tau_p (%g) should be at least %d times larger than nstpcouple*dt (%g)",
428 EPCOUPLTYPE(ir->epc),ir->tau_p,pcouple_min_integration_steps(ir->epc),dt_pcoupl);
429 warning(wi,warn_buf);
432 sprintf(err_buf,"compressibility must be > 0 when using pressure"
433 " coupling %s\n",EPCOUPLTYPE(ir->epc));
434 CHECK(ir->compress[XX][XX] < 0 || ir->compress[YY][YY] < 0 ||
435 ir->compress[ZZ][ZZ] < 0 ||
436 (trace(ir->compress) == 0 && ir->compress[YY][XX] <= 0 &&
437 ir->compress[ZZ][XX] <= 0 && ir->compress[ZZ][YY] <= 0));
439 sprintf(err_buf,"pressure coupling with PPPM not implemented, use PME");
440 CHECK(ir->coulombtype == eelPPPM);
443 else if (ir->coulombtype == eelPPPM)
445 sprintf(warn_buf,"The pressure with PPPM is incorrect, if you need the pressure use PME");
446 warning(wi,warn_buf);
449 if (EI_VV(ir->eI))
451 if (ir->epc > epcNO)
453 if (ir->epc!=epcMTTK)
455 warning_error(wi,"NPT only defined for vv using Martyna-Tuckerman-Tobias-Klein equations");
460 /* ELECTROSTATICS */
461 /* More checks are in triple check (grompp.c) */
462 if (ir->coulombtype == eelPPPM)
464 warning_error(wi,"PPPM is not functional in the current version, we plan to implement PPPM through a small modification of the PME code");
467 if (ir->coulombtype == eelSWITCH) {
468 sprintf(warn_buf,"coulombtype = %s is only for testing purposes and can lead to serious artifacts, advice: use coulombtype = %s",
469 eel_names[ir->coulombtype],
470 eel_names[eelRF_ZERO]);
471 warning(wi,warn_buf);
474 if (ir->epsilon_r!=1 && ir->implicit_solvent==eisGBSA) {
475 sprintf(warn_buf,"epsilon_r = %g with GB implicit solvent, will use this value for inner dielectric",ir->epsilon_r);
476 warning_note(wi,warn_buf);
479 if (EEL_RF(ir->coulombtype) && ir->epsilon_rf==1 && ir->epsilon_r!=1) {
480 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);
481 warning(wi,warn_buf);
482 ir->epsilon_rf = ir->epsilon_r;
483 ir->epsilon_r = 1.0;
486 if (getenv("GALACTIC_DYNAMICS") == NULL) {
487 sprintf(err_buf,"epsilon_r must be >= 0 instead of %g\n",ir->epsilon_r);
488 CHECK(ir->epsilon_r < 0);
491 if (EEL_RF(ir->coulombtype)) {
492 /* reaction field (at the cut-off) */
494 if (ir->coulombtype == eelRF_ZERO) {
495 sprintf(err_buf,"With coulombtype = %s, epsilon_rf must be 0",
496 eel_names[ir->coulombtype]);
497 CHECK(ir->epsilon_rf != 0);
500 sprintf(err_buf,"epsilon_rf must be >= epsilon_r");
501 CHECK((ir->epsilon_rf < ir->epsilon_r && ir->epsilon_rf != 0) ||
502 (ir->epsilon_r == 0));
503 if (ir->epsilon_rf == ir->epsilon_r) {
504 sprintf(warn_buf,"Using epsilon_rf = epsilon_r with %s does not make sense",
505 eel_names[ir->coulombtype]);
506 warning(wi,warn_buf);
509 /* Allow rlist>rcoulomb for tabulated long range stuff. This just
510 * means the interaction is zero outside rcoulomb, but it helps to
511 * provide accurate energy conservation.
513 if (EEL_MIGHT_BE_ZERO_AT_CUTOFF(ir->coulombtype)) {
514 if (EEL_SWITCHED(ir->coulombtype)) {
515 sprintf(err_buf,
516 "With coulombtype = %s rcoulomb_switch must be < rcoulomb",
517 eel_names[ir->coulombtype]);
518 CHECK(ir->rcoulomb_switch >= ir->rcoulomb);
520 } else if (ir->coulombtype == eelCUT || EEL_RF(ir->coulombtype)) {
521 sprintf(err_buf,"With coulombtype = %s, rcoulomb must be >= rlist",
522 eel_names[ir->coulombtype]);
523 CHECK(ir->rlist > ir->rcoulomb);
526 if (EEL_FULL(ir->coulombtype)) {
527 if (ir->coulombtype==eelPMESWITCH || ir->coulombtype==eelPMEUSER ||
528 ir->coulombtype==eelPMEUSERSWITCH) {
529 sprintf(err_buf,"With coulombtype = %s, rcoulomb must be <= rlist",
530 eel_names[ir->coulombtype]);
531 CHECK(ir->rcoulomb > ir->rlist);
532 } else {
533 if (ir->coulombtype == eelPME) {
534 sprintf(err_buf,
535 "With coulombtype = %s, rcoulomb must be equal to rlist\n"
536 "If you want optimal energy conservation or exact integration use %s",
537 eel_names[ir->coulombtype],eel_names[eelPMESWITCH]);
538 } else {
539 sprintf(err_buf,
540 "With coulombtype = %s, rcoulomb must be equal to rlist",
541 eel_names[ir->coulombtype]);
543 CHECK(ir->rcoulomb != ir->rlist);
547 if (EEL_PME(ir->coulombtype)) {
548 if (ir->pme_order < 3) {
549 warning_error(wi,"pme_order can not be smaller than 3");
553 if (ir->nwall==2 && EEL_FULL(ir->coulombtype)) {
554 if (ir->ewald_geometry == eewg3D) {
555 sprintf(warn_buf,"With pbc=%s you should use ewald_geometry=%s",
556 epbc_names[ir->ePBC],eewg_names[eewg3DC]);
557 warning(wi,warn_buf);
559 /* This check avoids extra pbc coding for exclusion corrections */
560 sprintf(err_buf,"wall_ewald_zfac should be >= 2");
561 CHECK(ir->wall_ewald_zfac < 2);
564 if (EVDW_SWITCHED(ir->vdwtype)) {
565 sprintf(err_buf,"With vdwtype = %s rvdw_switch must be < rvdw",
566 evdw_names[ir->vdwtype]);
567 CHECK(ir->rvdw_switch >= ir->rvdw);
568 } else if (ir->vdwtype == evdwCUT) {
569 sprintf(err_buf,"With vdwtype = %s, rvdw must be >= rlist",evdw_names[ir->vdwtype]);
570 CHECK(ir->rlist > ir->rvdw);
572 if (EEL_IS_ZERO_AT_CUTOFF(ir->coulombtype)
573 && (ir->rlistlong <= ir->rcoulomb)) {
574 sprintf(warn_buf,"For energy conservation with switch/shift potentials, %s should be 0.1 to 0.3 nm larger than rcoulomb.",
575 IR_TWINRANGE(*ir) ? "rlistlong" : "rlist");
576 warning_note(wi,warn_buf);
578 if (EVDW_SWITCHED(ir->vdwtype) && (ir->rlistlong <= ir->rvdw)) {
579 sprintf(warn_buf,"For energy conservation with switch/shift potentials, %s should be 0.1 to 0.3 nm larger than rvdw.",
580 IR_TWINRANGE(*ir) ? "rlistlong" : "rlist");
581 warning_note(wi,warn_buf);
584 if (ir->vdwtype == evdwUSER && ir->eDispCorr != edispcNO) {
585 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.");
588 if (ir->nstlist == -1) {
589 sprintf(err_buf,
590 "nstlist=-1 only works with switched or shifted potentials,\n"
591 "suggestion: use vdw-type=%s and coulomb-type=%s",
592 evdw_names[evdwSHIFT],eel_names[eelPMESWITCH]);
593 CHECK(!(EEL_MIGHT_BE_ZERO_AT_CUTOFF(ir->coulombtype) &&
594 EVDW_MIGHT_BE_ZERO_AT_CUTOFF(ir->vdwtype)));
596 sprintf(err_buf,"With nstlist=-1 rvdw and rcoulomb should be smaller than rlist to account for diffusion and possibly charge-group radii");
597 CHECK(ir->rvdw >= ir->rlist || ir->rcoulomb >= ir->rlist);
599 sprintf(err_buf,"nstlist can not be smaller than -1");
600 CHECK(ir->nstlist < -1);
602 if (ir->eI == eiLBFGS && (ir->coulombtype==eelCUT || ir->vdwtype==evdwCUT)
603 && ir->rvdw != 0) {
604 warning(wi,"For efficient BFGS minimization, use switch/shift/pme instead of cut-off.");
607 if (ir->eI == eiLBFGS && ir->nbfgscorr <= 0) {
608 warning(wi,"Using L-BFGS with nbfgscorr<=0 just gets you steepest descent.");
611 /* FREE ENERGY */
612 if (ir->efep != efepNO) {
613 sprintf(err_buf,"The soft-core power is %d and can only be 1 or 2",
614 ir->sc_power);
615 CHECK(ir->sc_alpha!=0 && ir->sc_power!=1 && ir->sc_power!=2);
618 /* ENERGY CONSERVATION */
619 if (ir_NVE(ir))
621 if (!EVDW_MIGHT_BE_ZERO_AT_CUTOFF(ir->vdwtype) && ir->rvdw > 0)
623 sprintf(warn_buf,"You are using a cut-off for VdW interactions with NVE, for good energy conservation use vdwtype = %s (possibly with DispCorr)",
624 evdw_names[evdwSHIFT]);
625 warning_note(wi,warn_buf);
627 if (!EEL_MIGHT_BE_ZERO_AT_CUTOFF(ir->coulombtype) && ir->rcoulomb > 0)
629 sprintf(warn_buf,"You are using a cut-off for electrostatics with NVE, for good energy conservation use coulombtype = %s or %s",
630 eel_names[eelPMESWITCH],eel_names[eelRF_ZERO]);
631 warning_note(wi,warn_buf);
635 /* IMPLICIT SOLVENT */
636 if(ir->coulombtype==eelGB_NOTUSED)
638 ir->coulombtype=eelCUT;
639 ir->implicit_solvent=eisGBSA;
640 fprintf(stderr,"Note: Old option for generalized born electrostatics given:\n"
641 "Changing coulombtype from \"generalized-born\" to \"cut-off\" and instead\n"
642 "setting implicit_solvent value to \"GBSA\" in input section.\n");
645 if(ir->implicit_solvent==eisGBSA)
647 sprintf(err_buf,"With GBSA implicit solvent, rgbradii must be equal to rlist.");
648 CHECK(ir->rgbradii != ir->rlist);
650 if(ir->coulombtype!=eelCUT)
652 sprintf(err_buf,"With GBSA, coulombtype must be equal to %s\n",eel_names[eelCUT]);
653 CHECK(ir->coulombtype!=eelCUT);
655 if(ir->vdwtype!=evdwCUT)
657 sprintf(err_buf,"With GBSA, vdw-type must be equal to %s\n",evdw_names[evdwCUT]);
658 CHECK(ir->vdwtype!=evdwCUT);
661 if(ir->nstgbradii<1)
663 sprintf(warn_buf,"Using GBSA with nstgbradii<1, setting nstgbradii=1");
664 warning_note(wi,warn_buf);
665 ir->nstgbradii=1;
670 static int str_nelem(const char *str,int maxptr,char *ptr[])
672 int np=0;
673 char *copy0,*copy;
675 copy0=strdup(str);
676 copy=copy0;
677 ltrim(copy);
678 while (*copy != '\0') {
679 if (np >= maxptr)
680 gmx_fatal(FARGS,"Too many groups on line: '%s' (max is %d)",
681 str,maxptr);
682 if (ptr)
683 ptr[np]=copy;
684 np++;
685 while ((*copy != '\0') && !isspace(*copy))
686 copy++;
687 if (*copy != '\0') {
688 *copy='\0';
689 copy++;
691 ltrim(copy);
693 if (ptr == NULL)
694 sfree(copy0);
696 return np;
699 static void parse_n_double(char *str,int *n,double **r)
701 char *ptr[MAXPTR];
702 int i;
704 *n = str_nelem(str,MAXPTR,ptr);
706 snew(*r,*n);
707 for(i=0; i<*n; i++) {
708 (*r)[i] = strtod(ptr[i],NULL);
712 static void do_wall_params(t_inputrec *ir,
713 char *wall_atomtype, char *wall_density,
714 t_gromppopts *opts)
716 int nstr,i;
717 char *names[MAXPTR];
718 double dbl;
720 opts->wall_atomtype[0] = NULL;
721 opts->wall_atomtype[1] = NULL;
723 ir->wall_atomtype[0] = -1;
724 ir->wall_atomtype[1] = -1;
725 ir->wall_density[0] = 0;
726 ir->wall_density[1] = 0;
728 if (ir->nwall > 0)
730 nstr = str_nelem(wall_atomtype,MAXPTR,names);
731 if (nstr != ir->nwall)
733 gmx_fatal(FARGS,"Expected %d elements for wall_atomtype, found %d",
734 ir->nwall,nstr);
736 for(i=0; i<ir->nwall; i++)
738 opts->wall_atomtype[i] = strdup(names[i]);
741 if (ir->wall_type == ewt93 || ir->wall_type == ewt104) {
742 nstr = str_nelem(wall_density,MAXPTR,names);
743 if (nstr != ir->nwall)
745 gmx_fatal(FARGS,"Expected %d elements for wall_density, found %d",ir->nwall,nstr);
747 for(i=0; i<ir->nwall; i++)
749 sscanf(names[i],"%lf",&dbl);
750 if (dbl <= 0)
752 gmx_fatal(FARGS,"wall_density[%d] = %f\n",i,dbl);
754 ir->wall_density[i] = dbl;
760 static void add_wall_energrps(gmx_groups_t *groups,int nwall,t_symtab *symtab)
762 int i;
763 t_grps *grps;
764 char str[STRLEN];
766 if (nwall > 0) {
767 srenew(groups->grpname,groups->ngrpname+nwall);
768 grps = &(groups->grps[egcENER]);
769 srenew(grps->nm_ind,grps->nr+nwall);
770 for(i=0; i<nwall; i++) {
771 sprintf(str,"wall%d",i);
772 groups->grpname[groups->ngrpname] = put_symtab(symtab,str);
773 grps->nm_ind[grps->nr++] = groups->ngrpname++;
778 void get_ir(const char *mdparin,const char *mdparout,
779 t_inputrec *ir,t_gromppopts *opts,
780 warninp_t wi)
782 char *dumstr[2];
783 double dumdub[2][6];
784 t_inpfile *inp;
785 const char *tmp;
786 int i,j,m,ninp;
787 char warn_buf[STRLEN];
789 inp = read_inpfile(mdparin, &ninp, NULL, wi);
791 snew(dumstr[0],STRLEN);
792 snew(dumstr[1],STRLEN);
794 REM_TYPE("title");
795 REM_TYPE("cpp");
796 REM_TYPE("domain-decomposition");
797 REPL_TYPE("unconstrained-start","continuation");
798 REM_TYPE("dihre-tau");
799 REM_TYPE("nstdihreout");
800 REM_TYPE("nstcheckpoint");
802 CCTYPE ("VARIOUS PREPROCESSING OPTIONS");
803 CTYPE ("Preprocessor information: use cpp syntax.");
804 CTYPE ("e.g.: -I/home/joe/doe -I/home/mary/roe");
805 STYPE ("include", opts->include, NULL);
806 CTYPE ("e.g.: -DI_Want_Cookies -DMe_Too");
807 STYPE ("define", opts->define, NULL);
809 CCTYPE ("RUN CONTROL PARAMETERS");
810 EETYPE("integrator", ir->eI, ei_names);
811 CTYPE ("Start time and timestep in ps");
812 RTYPE ("tinit", ir->init_t, 0.0);
813 RTYPE ("dt", ir->delta_t, 0.001);
814 STEPTYPE ("nsteps", ir->nsteps, 0);
815 CTYPE ("For exact run continuation or redoing part of a run");
816 STEPTYPE ("init_step",ir->init_step, 0);
817 CTYPE ("Part index is updated automatically on checkpointing (keeps files separate)");
818 ITYPE ("simulation_part", ir->simulation_part, 1);
819 CTYPE ("mode for center of mass motion removal");
820 EETYPE("comm-mode", ir->comm_mode, ecm_names);
821 CTYPE ("number of steps for center of mass motion removal");
822 ITYPE ("nstcomm", ir->nstcomm, 10);
823 CTYPE ("group(s) for center of mass motion removal");
824 STYPE ("comm-grps", vcm, NULL);
826 CCTYPE ("LANGEVIN DYNAMICS OPTIONS");
827 CTYPE ("Friction coefficient (amu/ps) and random seed");
828 RTYPE ("bd-fric", ir->bd_fric, 0.0);
829 ITYPE ("ld-seed", ir->ld_seed, 1993);
831 /* Em stuff */
832 CCTYPE ("ENERGY MINIMIZATION OPTIONS");
833 CTYPE ("Force tolerance and initial step-size");
834 RTYPE ("emtol", ir->em_tol, 10.0);
835 RTYPE ("emstep", ir->em_stepsize,0.01);
836 CTYPE ("Max number of iterations in relax_shells");
837 ITYPE ("niter", ir->niter, 20);
838 CTYPE ("Step size (ps^2) for minimization of flexible constraints");
839 RTYPE ("fcstep", ir->fc_stepsize, 0);
840 CTYPE ("Frequency of steepest descents steps when doing CG");
841 ITYPE ("nstcgsteep", ir->nstcgsteep, 1000);
842 ITYPE ("nbfgscorr", ir->nbfgscorr, 10);
844 CCTYPE ("TEST PARTICLE INSERTION OPTIONS");
845 RTYPE ("rtpi", ir->rtpi, 0.05);
847 /* Output options */
848 CCTYPE ("OUTPUT CONTROL OPTIONS");
849 CTYPE ("Output frequency for coords (x), velocities (v) and forces (f)");
850 ITYPE ("nstxout", ir->nstxout, 100);
851 ITYPE ("nstvout", ir->nstvout, 100);
852 ITYPE ("nstfout", ir->nstfout, 0);
853 ir->nstcheckpoint = 1000;
854 CTYPE ("Output frequency for energies to log file and energy file");
855 ITYPE ("nstlog", ir->nstlog, 100);
856 ITYPE ("nstcalcenergy",ir->nstcalcenergy, -1);
857 ITYPE ("nstenergy", ir->nstenergy, 100);
858 CTYPE ("Output frequency and precision for xtc file");
859 ITYPE ("nstxtcout", ir->nstxtcout, 0);
860 RTYPE ("xtc-precision",ir->xtcprec, 1000.0);
861 CTYPE ("This selects the subset of atoms for the xtc file. You can");
862 CTYPE ("select multiple groups. By default all atoms will be written.");
863 STYPE ("xtc-grps", xtc_grps, NULL);
864 CTYPE ("Selection of energy groups");
865 STYPE ("energygrps", energy, NULL);
867 /* Neighbor searching */
868 CCTYPE ("NEIGHBORSEARCHING PARAMETERS");
869 CTYPE ("nblist update frequency");
870 ITYPE ("nstlist", ir->nstlist, 10);
871 CTYPE ("ns algorithm (simple or grid)");
872 EETYPE("ns-type", ir->ns_type, ens_names);
873 /* set ndelta to the optimal value of 2 */
874 ir->ndelta = 2;
875 CTYPE ("Periodic boundary conditions: xyz, no, xy");
876 EETYPE("pbc", ir->ePBC, epbc_names);
877 EETYPE("periodic_molecules", ir->bPeriodicMols, yesno_names);
878 CTYPE ("nblist cut-off");
879 RTYPE ("rlist", ir->rlist, 1.0);
880 CTYPE ("long-range cut-off for switched potentials");
881 RTYPE ("rlistlong", ir->rlistlong, -1);
883 /* Electrostatics */
884 CCTYPE ("OPTIONS FOR ELECTROSTATICS AND VDW");
885 CTYPE ("Method for doing electrostatics");
886 EETYPE("coulombtype", ir->coulombtype, eel_names);
887 CTYPE ("cut-off lengths");
888 RTYPE ("rcoulomb-switch", ir->rcoulomb_switch, 0.0);
889 RTYPE ("rcoulomb", ir->rcoulomb, 1.0);
890 CTYPE ("Relative dielectric constant for the medium and the reaction field");
891 RTYPE ("epsilon_r", ir->epsilon_r, 1.0);
892 RTYPE ("epsilon_rf", ir->epsilon_rf, 1.0);
893 CTYPE ("Method for doing Van der Waals");
894 EETYPE("vdw-type", ir->vdwtype, evdw_names);
895 CTYPE ("cut-off lengths");
896 RTYPE ("rvdw-switch", ir->rvdw_switch, 0.0);
897 RTYPE ("rvdw", ir->rvdw, 1.0);
898 CTYPE ("Apply long range dispersion corrections for Energy and Pressure");
899 EETYPE("DispCorr", ir->eDispCorr, edispc_names);
900 CTYPE ("Extension of the potential lookup tables beyond the cut-off");
901 RTYPE ("table-extension", ir->tabext, 1.0);
902 CTYPE ("Seperate tables between energy group pairs");
903 STYPE ("energygrp_table", egptable, NULL);
904 CTYPE ("Spacing for the PME/PPPM FFT grid");
905 RTYPE ("fourierspacing", opts->fourierspacing,0.12);
906 CTYPE ("FFT grid size, when a value is 0 fourierspacing will be used");
907 ITYPE ("fourier_nx", ir->nkx, 0);
908 ITYPE ("fourier_ny", ir->nky, 0);
909 ITYPE ("fourier_nz", ir->nkz, 0);
910 CTYPE ("EWALD/PME/PPPM parameters");
911 ITYPE ("pme_order", ir->pme_order, 4);
912 RTYPE ("ewald_rtol", ir->ewald_rtol, 0.00001);
913 EETYPE("ewald_geometry", ir->ewald_geometry, eewg_names);
914 RTYPE ("epsilon_surface", ir->epsilon_surface, 0.0);
915 EETYPE("optimize_fft",ir->bOptFFT, yesno_names);
917 CCTYPE("IMPLICIT SOLVENT ALGORITHM");
918 EETYPE("implicit_solvent", ir->implicit_solvent, eis_names);
920 CCTYPE ("GENERALIZED BORN ELECTROSTATICS");
921 CTYPE ("Algorithm for calculating Born radii");
922 EETYPE("gb_algorithm", ir->gb_algorithm, egb_names);
923 CTYPE ("Frequency of calculating the Born radii inside rlist");
924 ITYPE ("nstgbradii", ir->nstgbradii, 1);
925 CTYPE ("Cutoff for Born radii calculation; the contribution from atoms");
926 CTYPE ("between rlist and rgbradii is updated every nstlist steps");
927 RTYPE ("rgbradii", ir->rgbradii, 1.0);
928 CTYPE ("Dielectric coefficient of the implicit solvent");
929 RTYPE ("gb_epsilon_solvent",ir->gb_epsilon_solvent, 80.0);
930 CTYPE ("Salt concentration in M for Generalized Born models");
931 RTYPE ("gb_saltconc", ir->gb_saltconc, 0.0);
932 CTYPE ("Scaling factors used in the OBC GB model. Default values are OBC(II)");
933 RTYPE ("gb_obc_alpha", ir->gb_obc_alpha, 1.0);
934 RTYPE ("gb_obc_beta", ir->gb_obc_beta, 0.8);
935 RTYPE ("gb_obc_gamma", ir->gb_obc_gamma, 4.85);
936 RTYPE ("gb_dielectric_offset", ir->gb_dielectric_offset, 0.009);
937 EETYPE("sa_algorithm", ir->sa_algorithm, esa_names);
938 CTYPE ("Surface tension (kJ/mol/nm^2) for the SA (nonpolar surface) part of GBSA");
939 CTYPE ("The default value (2.092) corresponds to 0.005 kcal/mol/Angstrom^2.");
940 RTYPE ("sa_surface_tension", ir->sa_surface_tension, 2.092);
942 /* Coupling stuff */
943 CCTYPE ("OPTIONS FOR WEAK COUPLING ALGORITHMS");
944 CTYPE ("Temperature coupling");
945 EETYPE("tcoupl", ir->etc, etcoupl_names);
946 ITYPE ("nsttcouple", ir->nsttcouple, -1);
947 ITYPE("nh-chain-length", ir->opts.nhchainlength, NHCHAINLENGTH);
948 CTYPE ("Groups to couple separately");
949 STYPE ("tc-grps", tcgrps, NULL);
950 CTYPE ("Time constant (ps) and reference temperature (K)");
951 STYPE ("tau-t", tau_t, NULL);
952 STYPE ("ref-t", ref_t, NULL);
953 CTYPE ("Pressure coupling");
954 EETYPE("Pcoupl", ir->epc, epcoupl_names);
955 EETYPE("Pcoupltype", ir->epct, epcoupltype_names);
956 ITYPE ("nstpcouple", ir->nstpcouple, -1);
957 CTYPE ("Time constant (ps), compressibility (1/bar) and reference P (bar)");
958 RTYPE ("tau-p", ir->tau_p, 1.0);
959 STYPE ("compressibility", dumstr[0], NULL);
960 STYPE ("ref-p", dumstr[1], NULL);
961 CTYPE ("Scaling of reference coordinates, No, All or COM");
962 EETYPE ("refcoord_scaling",ir->refcoord_scaling,erefscaling_names);
964 CTYPE ("Random seed for Andersen thermostat");
965 ITYPE ("andersen_seed", ir->andersen_seed, 815131);
967 /* QMMM */
968 CCTYPE ("OPTIONS FOR QMMM calculations");
969 EETYPE("QMMM", ir->bQMMM, yesno_names);
970 CTYPE ("Groups treated Quantum Mechanically");
971 STYPE ("QMMM-grps", QMMM, NULL);
972 CTYPE ("QM method");
973 STYPE("QMmethod", QMmethod, NULL);
974 CTYPE ("QMMM scheme");
975 EETYPE("QMMMscheme", ir->QMMMscheme, eQMMMscheme_names);
976 CTYPE ("QM basisset");
977 STYPE("QMbasis", QMbasis, NULL);
978 CTYPE ("QM charge");
979 STYPE ("QMcharge", QMcharge,NULL);
980 CTYPE ("QM multiplicity");
981 STYPE ("QMmult", QMmult,NULL);
982 CTYPE ("Surface Hopping");
983 STYPE ("SH", bSH, NULL);
984 CTYPE ("CAS space options");
985 STYPE ("CASorbitals", CASorbitals, NULL);
986 STYPE ("CASelectrons", CASelectrons, NULL);
987 STYPE ("SAon", SAon, NULL);
988 STYPE ("SAoff",SAoff,NULL);
989 STYPE ("SAsteps", SAsteps, NULL);
990 CTYPE ("Scale factor for MM charges");
991 RTYPE ("MMChargeScaleFactor", ir->scalefactor, 1.0);
992 CTYPE ("Optimization of QM subsystem");
993 STYPE ("bOPT", bOPT, NULL);
994 STYPE ("bTS", bTS, NULL);
996 /* Simulated annealing */
997 CCTYPE("SIMULATED ANNEALING");
998 CTYPE ("Type of annealing for each temperature group (no/single/periodic)");
999 STYPE ("annealing", anneal, NULL);
1000 CTYPE ("Number of time points to use for specifying annealing in each group");
1001 STYPE ("annealing_npoints", anneal_npoints, NULL);
1002 CTYPE ("List of times at the annealing points for each group");
1003 STYPE ("annealing_time", anneal_time, NULL);
1004 CTYPE ("Temp. at each annealing point, for each group.");
1005 STYPE ("annealing_temp", anneal_temp, NULL);
1007 /* Startup run */
1008 CCTYPE ("GENERATE VELOCITIES FOR STARTUP RUN");
1009 EETYPE("gen-vel", opts->bGenVel, yesno_names);
1010 RTYPE ("gen-temp", opts->tempi, 300.0);
1011 ITYPE ("gen-seed", opts->seed, 173529);
1013 /* Shake stuff */
1014 CCTYPE ("OPTIONS FOR BONDS");
1015 EETYPE("constraints", opts->nshake, constraints);
1016 CTYPE ("Type of constraint algorithm");
1017 EETYPE("constraint-algorithm", ir->eConstrAlg, econstr_names);
1018 CTYPE ("Do not constrain the start configuration");
1019 EETYPE("continuation", ir->bContinuation, yesno_names);
1020 CTYPE ("Use successive overrelaxation to reduce the number of shake iterations");
1021 EETYPE("Shake-SOR", ir->bShakeSOR, yesno_names);
1022 CTYPE ("Relative tolerance of shake");
1023 RTYPE ("shake-tol", ir->shake_tol, 0.0001);
1024 CTYPE ("Highest order in the expansion of the constraint coupling matrix");
1025 ITYPE ("lincs-order", ir->nProjOrder, 4);
1026 CTYPE ("Number of iterations in the final step of LINCS. 1 is fine for");
1027 CTYPE ("normal simulations, but use 2 to conserve energy in NVE runs.");
1028 CTYPE ("For energy minimization with constraints it should be 4 to 8.");
1029 ITYPE ("lincs-iter", ir->nLincsIter, 1);
1030 CTYPE ("Lincs will write a warning to the stderr if in one step a bond");
1031 CTYPE ("rotates over more degrees than");
1032 RTYPE ("lincs-warnangle", ir->LincsWarnAngle, 30.0);
1033 CTYPE ("Convert harmonic bonds to morse potentials");
1034 EETYPE("morse", opts->bMorse,yesno_names);
1036 /* Energy group exclusions */
1037 CCTYPE ("ENERGY GROUP EXCLUSIONS");
1038 CTYPE ("Pairs of energy groups for which all non-bonded interactions are excluded");
1039 STYPE ("energygrp_excl", egpexcl, NULL);
1041 /* Walls */
1042 CCTYPE ("WALLS");
1043 CTYPE ("Number of walls, type, atom types, densities and box-z scale factor for Ewald");
1044 ITYPE ("nwall", ir->nwall, 0);
1045 EETYPE("wall_type", ir->wall_type, ewt_names);
1046 RTYPE ("wall_r_linpot", ir->wall_r_linpot, -1);
1047 STYPE ("wall_atomtype", wall_atomtype, NULL);
1048 STYPE ("wall_density", wall_density, NULL);
1049 RTYPE ("wall_ewald_zfac", ir->wall_ewald_zfac, 3);
1051 /* COM pulling */
1052 CCTYPE("COM PULLING");
1053 CTYPE("Pull type: no, umbrella, constraint or constant_force");
1054 EETYPE("pull", ir->ePull, epull_names);
1055 if (ir->ePull != epullNO) {
1056 snew(ir->pull,1);
1057 pull_grp = read_pullparams(&ninp,&inp,ir->pull,&opts->pull_start,wi);
1060 /* Refinement */
1061 CCTYPE("NMR refinement stuff");
1062 CTYPE ("Distance restraints type: No, Simple or Ensemble");
1063 EETYPE("disre", ir->eDisre, edisre_names);
1064 CTYPE ("Force weighting of pairs in one distance restraint: Conservative or Equal");
1065 EETYPE("disre-weighting", ir->eDisreWeighting, edisreweighting_names);
1066 CTYPE ("Use sqrt of the time averaged times the instantaneous violation");
1067 EETYPE("disre-mixed", ir->bDisreMixed, yesno_names);
1068 RTYPE ("disre-fc", ir->dr_fc, 1000.0);
1069 RTYPE ("disre-tau", ir->dr_tau, 0.0);
1070 CTYPE ("Output frequency for pair distances to energy file");
1071 ITYPE ("nstdisreout", ir->nstdisreout, 100);
1072 CTYPE ("Orientation restraints: No or Yes");
1073 EETYPE("orire", opts->bOrire, yesno_names);
1074 CTYPE ("Orientation restraints force constant and tau for time averaging");
1075 RTYPE ("orire-fc", ir->orires_fc, 0.0);
1076 RTYPE ("orire-tau", ir->orires_tau, 0.0);
1077 STYPE ("orire-fitgrp",orirefitgrp, NULL);
1078 CTYPE ("Output frequency for trace(SD) and S to energy file");
1079 ITYPE ("nstorireout", ir->nstorireout, 100);
1080 CTYPE ("Dihedral angle restraints: No or Yes");
1081 EETYPE("dihre", opts->bDihre, yesno_names);
1082 RTYPE ("dihre-fc", ir->dihre_fc, 1000.0);
1084 /* Free energy stuff */
1085 CCTYPE ("Free energy control stuff");
1086 EETYPE("free-energy", ir->efep, efep_names);
1087 RTYPE ("init-lambda", ir->init_lambda,0.0);
1088 RTYPE ("delta-lambda",ir->delta_lambda,0.0);
1089 STYPE ("foreign_lambda", foreign_lambda, NULL);
1090 RTYPE ("sc-alpha",ir->sc_alpha,0.0);
1091 ITYPE ("sc-power",ir->sc_power,0);
1092 RTYPE ("sc-sigma",ir->sc_sigma,0.3);
1093 ITYPE ("nstdhdl", ir->nstdhdl, 10);
1094 ITYPE ("dh_table_size", ir->dh_table_size, 0);
1095 RTYPE ("dh_table_spacing", ir->dh_table_spacing, 0.1);
1096 STYPE ("couple-moltype", couple_moltype, NULL);
1097 EETYPE("couple-lambda0", opts->couple_lam0, couple_lam);
1098 EETYPE("couple-lambda1", opts->couple_lam1, couple_lam);
1099 EETYPE("couple-intramol", opts->bCoupleIntra, yesno_names);
1101 /* Non-equilibrium MD stuff */
1102 CCTYPE("Non-equilibrium MD stuff");
1103 STYPE ("acc-grps", accgrps, NULL);
1104 STYPE ("accelerate", acc, NULL);
1105 STYPE ("freezegrps", freeze, NULL);
1106 STYPE ("freezedim", frdim, NULL);
1107 RTYPE ("cos-acceleration", ir->cos_accel, 0);
1108 STYPE ("deform", deform, NULL);
1110 /* Electric fields */
1111 CCTYPE("Electric fields");
1112 CTYPE ("Format is number of terms (int) and for all terms an amplitude (real)");
1113 CTYPE ("and a phase angle (real)");
1114 STYPE ("E-x", efield_x, NULL);
1115 STYPE ("E-xt", efield_xt, NULL);
1116 STYPE ("E-y", efield_y, NULL);
1117 STYPE ("E-yt", efield_yt, NULL);
1118 STYPE ("E-z", efield_z, NULL);
1119 STYPE ("E-zt", efield_zt, NULL);
1121 /* User defined thingies */
1122 CCTYPE ("User defined thingies");
1123 STYPE ("user1-grps", user1, NULL);
1124 STYPE ("user2-grps", user2, NULL);
1125 ITYPE ("userint1", ir->userint1, 0);
1126 ITYPE ("userint2", ir->userint2, 0);
1127 ITYPE ("userint3", ir->userint3, 0);
1128 ITYPE ("userint4", ir->userint4, 0);
1129 RTYPE ("userreal1", ir->userreal1, 0);
1130 RTYPE ("userreal2", ir->userreal2, 0);
1131 RTYPE ("userreal3", ir->userreal3, 0);
1132 RTYPE ("userreal4", ir->userreal4, 0);
1133 #undef CTYPE
1135 write_inpfile(mdparout,ninp,inp,FALSE,wi);
1136 for (i=0; (i<ninp); i++) {
1137 sfree(inp[i].name);
1138 sfree(inp[i].value);
1140 sfree(inp);
1142 /* Process options if necessary */
1143 for(m=0; m<2; m++) {
1144 for(i=0; i<2*DIM; i++)
1145 dumdub[m][i]=0.0;
1146 if(ir->epc) {
1147 switch (ir->epct) {
1148 case epctISOTROPIC:
1149 if (sscanf(dumstr[m],"%lf",&(dumdub[m][XX]))!=1) {
1150 warning_error(wi,"Pressure coupling not enough values (I need 1)");
1152 dumdub[m][YY]=dumdub[m][ZZ]=dumdub[m][XX];
1153 break;
1154 case epctSEMIISOTROPIC:
1155 case epctSURFACETENSION:
1156 if (sscanf(dumstr[m],"%lf%lf",
1157 &(dumdub[m][XX]),&(dumdub[m][ZZ]))!=2) {
1158 warning_error(wi,"Pressure coupling not enough values (I need 2)");
1160 dumdub[m][YY]=dumdub[m][XX];
1161 break;
1162 case epctANISOTROPIC:
1163 if (sscanf(dumstr[m],"%lf%lf%lf%lf%lf%lf",
1164 &(dumdub[m][XX]),&(dumdub[m][YY]),&(dumdub[m][ZZ]),
1165 &(dumdub[m][3]),&(dumdub[m][4]),&(dumdub[m][5]))!=6) {
1166 warning_error(wi,"Pressure coupling not enough values (I need 6)");
1168 break;
1169 default:
1170 gmx_fatal(FARGS,"Pressure coupling type %s not implemented yet",
1171 epcoupltype_names[ir->epct]);
1175 clear_mat(ir->ref_p);
1176 clear_mat(ir->compress);
1177 for(i=0; i<DIM; i++) {
1178 ir->ref_p[i][i] = dumdub[1][i];
1179 ir->compress[i][i] = dumdub[0][i];
1181 if (ir->epct == epctANISOTROPIC) {
1182 ir->ref_p[XX][YY] = dumdub[1][3];
1183 ir->ref_p[XX][ZZ] = dumdub[1][4];
1184 ir->ref_p[YY][ZZ] = dumdub[1][5];
1185 if (ir->ref_p[XX][YY]!=0 && ir->ref_p[XX][ZZ]!=0 && ir->ref_p[YY][ZZ]!=0) {
1186 warning(wi,"All off-diagonal reference pressures are non-zero. Are you sure you want to apply a threefold shear stress?\n");
1188 ir->compress[XX][YY] = dumdub[0][3];
1189 ir->compress[XX][ZZ] = dumdub[0][4];
1190 ir->compress[YY][ZZ] = dumdub[0][5];
1191 for(i=0; i<DIM; i++) {
1192 for(m=0; m<i; m++) {
1193 ir->ref_p[i][m] = ir->ref_p[m][i];
1194 ir->compress[i][m] = ir->compress[m][i];
1199 if (ir->comm_mode == ecmNO)
1200 ir->nstcomm = 0;
1202 opts->couple_moltype = NULL;
1203 if (strlen(couple_moltype) > 0) {
1204 if (ir->efep != efepNO) {
1205 opts->couple_moltype = strdup(couple_moltype);
1206 if (opts->couple_lam0 == opts->couple_lam1)
1207 warning(wi,"The lambda=0 and lambda=1 states for coupling are identical");
1208 if (ir->eI == eiMD && (opts->couple_lam0 == ecouplamNONE ||
1209 opts->couple_lam1 == ecouplamNONE)) {
1210 warning(wi,"For proper sampling of the (nearly) decoupled state, stochastic dynamics should be used");
1212 } else {
1213 warning(wi,"Can not couple a molecule with free_energy = no");
1217 do_wall_params(ir,wall_atomtype,wall_density,opts);
1219 if (opts->bOrire && str_nelem(orirefitgrp,MAXPTR,NULL)!=1) {
1220 warning_error(wi,"ERROR: Need one orientation restraint fit group\n");
1223 clear_mat(ir->deform);
1224 for(i=0; i<6; i++)
1225 dumdub[0][i] = 0;
1226 m = sscanf(deform,"%lf %lf %lf %lf %lf %lf",
1227 &(dumdub[0][0]),&(dumdub[0][1]),&(dumdub[0][2]),
1228 &(dumdub[0][3]),&(dumdub[0][4]),&(dumdub[0][5]));
1229 for(i=0; i<3; i++)
1230 ir->deform[i][i] = dumdub[0][i];
1231 ir->deform[YY][XX] = dumdub[0][3];
1232 ir->deform[ZZ][XX] = dumdub[0][4];
1233 ir->deform[ZZ][YY] = dumdub[0][5];
1234 if (ir->epc != epcNO) {
1235 for(i=0; i<3; i++)
1236 for(j=0; j<=i; j++)
1237 if (ir->deform[i][j]!=0 && ir->compress[i][j]!=0) {
1238 warning_error(wi,"A box element has deform set and compressibility > 0");
1240 for(i=0; i<3; i++)
1241 for(j=0; j<i; j++)
1242 if (ir->deform[i][j]!=0) {
1243 for(m=j; m<DIM; m++)
1244 if (ir->compress[m][j]!=0) {
1245 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.");
1246 warning(wi,warn_buf);
1251 if (ir->efep != efepNO) {
1252 parse_n_double(foreign_lambda,&ir->n_flambda,&ir->flambda);
1253 if (ir->n_flambda > 0 && ir->rlist < max(ir->rvdw,ir->rcoulomb)) {
1254 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");
1256 } else {
1257 ir->n_flambda = 0;
1260 sfree(dumstr[0]);
1261 sfree(dumstr[1]);
1264 static int search_QMstring(char *s,int ng,const char *gn[])
1266 /* same as normal search_string, but this one searches QM strings */
1267 int i;
1269 for(i=0; (i<ng); i++)
1270 if (strcasecmp(s,gn[i]) == 0)
1271 return i;
1273 gmx_fatal(FARGS,"this QM method or basisset (%s) is not implemented\n!",s);
1275 return -1;
1277 } /* search_QMstring */
1280 int search_string(char *s,int ng,char *gn[])
1282 int i;
1284 for(i=0; (i<ng); i++)
1285 if (strcasecmp(s,gn[i]) == 0)
1286 return i;
1288 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);
1290 return -1;
1293 static bool do_numbering(int natoms,gmx_groups_t *groups,int ng,char *ptrs[],
1294 t_blocka *block,char *gnames[],
1295 int gtype,int restnm,
1296 int grptp,bool bVerbose,
1297 warninp_t wi)
1299 unsigned short *cbuf;
1300 t_grps *grps=&(groups->grps[gtype]);
1301 int i,j,gid,aj,ognr,ntot=0;
1302 const char *title;
1303 bool bRest;
1304 char warn_buf[STRLEN];
1306 if (debug)
1308 fprintf(debug,"Starting numbering %d groups of type %d\n",ng,gtype);
1311 title = gtypes[gtype];
1313 snew(cbuf,natoms);
1314 /* Mark all id's as not set */
1315 for(i=0; (i<natoms); i++)
1317 cbuf[i] = NOGID;
1320 snew(grps->nm_ind,ng+1); /* +1 for possible rest group */
1321 for(i=0; (i<ng); i++)
1323 /* Lookup the group name in the block structure */
1324 gid = search_string(ptrs[i],block->nr,gnames);
1325 if ((grptp != egrptpONE) || (i == 0))
1327 grps->nm_ind[grps->nr++]=gid;
1329 if (debug)
1331 fprintf(debug,"Found gid %d for group %s\n",gid,ptrs[i]);
1334 /* Now go over the atoms in the group */
1335 for(j=block->index[gid]; (j<block->index[gid+1]); j++)
1338 aj=block->a[j];
1340 /* Range checking */
1341 if ((aj < 0) || (aj >= natoms))
1343 gmx_fatal(FARGS,"Invalid atom number %d in indexfile",aj);
1345 /* Lookup up the old group number */
1346 ognr = cbuf[aj];
1347 if (ognr != NOGID)
1349 gmx_fatal(FARGS,"Atom %d in multiple %s groups (%d and %d)",
1350 aj+1,title,ognr+1,i+1);
1352 else
1354 /* Store the group number in buffer */
1355 if (grptp == egrptpONE)
1357 cbuf[aj] = 0;
1359 else
1361 cbuf[aj] = i;
1363 ntot++;
1368 /* Now check whether we have done all atoms */
1369 bRest = FALSE;
1370 if (ntot != natoms)
1372 if (grptp == egrptpALL)
1374 gmx_fatal(FARGS,"%d atoms are not part of any of the %s groups",
1375 natoms-ntot,title);
1377 else if (grptp == egrptpPART)
1379 sprintf(warn_buf,"%d atoms are not part of any of the %s groups",
1380 natoms-ntot,title);
1381 warning_note(wi,warn_buf);
1383 /* Assign all atoms currently unassigned to a rest group */
1384 for(j=0; (j<natoms); j++)
1386 if (cbuf[j] == NOGID)
1388 cbuf[j] = grps->nr;
1389 bRest = TRUE;
1392 if (grptp != egrptpPART)
1394 if (bVerbose)
1396 fprintf(stderr,
1397 "Making dummy/rest group for %s containing %d elements\n",
1398 title,natoms-ntot);
1400 /* Add group name "rest" */
1401 grps->nm_ind[grps->nr] = restnm;
1403 /* Assign the rest name to all atoms not currently assigned to a group */
1404 for(j=0; (j<natoms); j++)
1406 if (cbuf[j] == NOGID)
1408 cbuf[j] = grps->nr;
1411 grps->nr++;
1415 if (grps->nr == 1)
1417 groups->ngrpnr[gtype] = 0;
1418 groups->grpnr[gtype] = NULL;
1420 else
1422 groups->ngrpnr[gtype] = natoms;
1423 snew(groups->grpnr[gtype],natoms);
1424 for(j=0; (j<natoms); j++)
1426 groups->grpnr[gtype][j] = cbuf[j];
1430 sfree(cbuf);
1432 return (bRest && grptp == egrptpPART);
1435 static void calc_nrdf(gmx_mtop_t *mtop,t_inputrec *ir,char **gnames)
1437 t_grpopts *opts;
1438 gmx_groups_t *groups;
1439 t_pull *pull;
1440 int natoms,ai,aj,i,j,d,g,imin,jmin,nc;
1441 t_iatom *ia;
1442 int *nrdf2,*na_vcm,na_tot;
1443 double *nrdf_tc,*nrdf_vcm,nrdf_uc,n_sub=0;
1444 gmx_mtop_atomloop_all_t aloop;
1445 t_atom *atom;
1446 int mb,mol,ftype,as;
1447 gmx_molblock_t *molb;
1448 gmx_moltype_t *molt;
1450 /* Calculate nrdf.
1451 * First calc 3xnr-atoms for each group
1452 * then subtract half a degree of freedom for each constraint
1454 * Only atoms and nuclei contribute to the degrees of freedom...
1457 opts = &ir->opts;
1459 groups = &mtop->groups;
1460 natoms = mtop->natoms;
1462 /* Allocate one more for a possible rest group */
1463 /* We need to sum degrees of freedom into doubles,
1464 * since floats give too low nrdf's above 3 million atoms.
1466 snew(nrdf_tc,groups->grps[egcTC].nr+1);
1467 snew(nrdf_vcm,groups->grps[egcVCM].nr+1);
1468 snew(na_vcm,groups->grps[egcVCM].nr+1);
1470 for(i=0; i<groups->grps[egcTC].nr; i++)
1471 nrdf_tc[i] = 0;
1472 for(i=0; i<groups->grps[egcVCM].nr+1; i++)
1473 nrdf_vcm[i] = 0;
1475 snew(nrdf2,natoms);
1476 aloop = gmx_mtop_atomloop_all_init(mtop);
1477 while (gmx_mtop_atomloop_all_next(aloop,&i,&atom)) {
1478 nrdf2[i] = 0;
1479 if (atom->ptype == eptAtom || atom->ptype == eptNucleus) {
1480 g = ggrpnr(groups,egcFREEZE,i);
1481 /* Double count nrdf for particle i */
1482 for(d=0; d<DIM; d++) {
1483 if (opts->nFreeze[g][d] == 0) {
1484 nrdf2[i] += 2;
1487 nrdf_tc [ggrpnr(groups,egcTC ,i)] += 0.5*nrdf2[i];
1488 nrdf_vcm[ggrpnr(groups,egcVCM,i)] += 0.5*nrdf2[i];
1492 as = 0;
1493 for(mb=0; mb<mtop->nmolblock; mb++) {
1494 molb = &mtop->molblock[mb];
1495 molt = &mtop->moltype[molb->type];
1496 atom = molt->atoms.atom;
1497 for(mol=0; mol<molb->nmol; mol++) {
1498 for (ftype=F_CONSTR; ftype<=F_CONSTRNC; ftype++) {
1499 ia = molt->ilist[ftype].iatoms;
1500 for(i=0; i<molt->ilist[ftype].nr; ) {
1501 /* Subtract degrees of freedom for the constraints,
1502 * if the particles still have degrees of freedom left.
1503 * If one of the particles is a vsite or a shell, then all
1504 * constraint motion will go there, but since they do not
1505 * contribute to the constraints the degrees of freedom do not
1506 * change.
1508 ai = as + ia[1];
1509 aj = as + ia[2];
1510 if (((atom[ia[1]].ptype == eptNucleus) ||
1511 (atom[ia[1]].ptype == eptAtom)) &&
1512 ((atom[ia[2]].ptype == eptNucleus) ||
1513 (atom[ia[2]].ptype == eptAtom))) {
1514 if (nrdf2[ai] > 0)
1515 jmin = 1;
1516 else
1517 jmin = 2;
1518 if (nrdf2[aj] > 0)
1519 imin = 1;
1520 else
1521 imin = 2;
1522 imin = min(imin,nrdf2[ai]);
1523 jmin = min(jmin,nrdf2[aj]);
1524 nrdf2[ai] -= imin;
1525 nrdf2[aj] -= jmin;
1526 nrdf_tc [ggrpnr(groups,egcTC ,ai)] -= 0.5*imin;
1527 nrdf_tc [ggrpnr(groups,egcTC ,aj)] -= 0.5*jmin;
1528 nrdf_vcm[ggrpnr(groups,egcVCM,ai)] -= 0.5*imin;
1529 nrdf_vcm[ggrpnr(groups,egcVCM,aj)] -= 0.5*jmin;
1531 ia += interaction_function[ftype].nratoms+1;
1532 i += interaction_function[ftype].nratoms+1;
1535 ia = molt->ilist[F_SETTLE].iatoms;
1536 for(i=0; i<molt->ilist[F_SETTLE].nr; ) {
1537 /* Subtract 1 dof from every atom in the SETTLE */
1538 for(ai=as+ia[1]; ai<as+ia[1]+3; ai++) {
1539 imin = min(2,nrdf2[ai]);
1540 nrdf2[ai] -= imin;
1541 nrdf_tc [ggrpnr(groups,egcTC ,ai)] -= 0.5*imin;
1542 nrdf_vcm[ggrpnr(groups,egcVCM,ai)] -= 0.5*imin;
1544 ia += 2;
1545 i += 2;
1547 as += molt->atoms.nr;
1551 if (ir->ePull == epullCONSTRAINT) {
1552 /* Correct nrdf for the COM constraints.
1553 * We correct using the TC and VCM group of the first atom
1554 * in the reference and pull group. If atoms in one pull group
1555 * belong to different TC or VCM groups it is anyhow difficult
1556 * to determine the optimal nrdf assignment.
1558 pull = ir->pull;
1559 if (pull->eGeom == epullgPOS) {
1560 nc = 0;
1561 for(i=0; i<DIM; i++) {
1562 if (pull->dim[i])
1563 nc++;
1565 } else {
1566 nc = 1;
1568 for(i=0; i<pull->ngrp; i++) {
1569 imin = 2*nc;
1570 if (pull->grp[0].nat > 0) {
1571 /* Subtract 1/2 dof from the reference group */
1572 ai = pull->grp[0].ind[0];
1573 if (nrdf_tc[ggrpnr(groups,egcTC,ai)] > 1) {
1574 nrdf_tc [ggrpnr(groups,egcTC ,ai)] -= 0.5;
1575 nrdf_vcm[ggrpnr(groups,egcVCM,ai)] -= 0.5;
1576 imin--;
1579 /* Subtract 1/2 dof from the pulled group */
1580 ai = pull->grp[1+i].ind[0];
1581 nrdf_tc [ggrpnr(groups,egcTC ,ai)] -= 0.5*imin;
1582 nrdf_vcm[ggrpnr(groups,egcVCM,ai)] -= 0.5*imin;
1583 if (nrdf_tc[ggrpnr(groups,egcTC,ai)] < 0)
1584 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)]]);
1588 if (ir->nstcomm != 0) {
1589 /* Subtract 3 from the number of degrees of freedom in each vcm group
1590 * when com translation is removed and 6 when rotation is removed
1591 * as well.
1593 switch (ir->comm_mode) {
1594 case ecmLINEAR:
1595 n_sub = ndof_com(ir);
1596 break;
1597 case ecmANGULAR:
1598 n_sub = 6;
1599 break;
1600 default:
1601 n_sub = 0;
1602 gmx_incons("Checking comm_mode");
1605 for(i=0; i<groups->grps[egcTC].nr; i++) {
1606 /* Count the number of atoms of TC group i for every VCM group */
1607 for(j=0; j<groups->grps[egcVCM].nr+1; j++)
1608 na_vcm[j] = 0;
1609 na_tot = 0;
1610 for(ai=0; ai<natoms; ai++)
1611 if (ggrpnr(groups,egcTC,ai) == i) {
1612 na_vcm[ggrpnr(groups,egcVCM,ai)]++;
1613 na_tot++;
1615 /* Correct for VCM removal according to the fraction of each VCM
1616 * group present in this TC group.
1618 nrdf_uc = nrdf_tc[i];
1619 if (debug) {
1620 fprintf(debug,"T-group[%d] nrdf_uc = %g, n_sub = %g\n",
1621 i,nrdf_uc,n_sub);
1623 nrdf_tc[i] = 0;
1624 for(j=0; j<groups->grps[egcVCM].nr+1; j++) {
1625 if (nrdf_vcm[j] > n_sub) {
1626 nrdf_tc[i] += nrdf_uc*((double)na_vcm[j]/(double)na_tot)*
1627 (nrdf_vcm[j] - n_sub)/nrdf_vcm[j];
1629 if (debug) {
1630 fprintf(debug," nrdf_vcm[%d] = %g, nrdf = %g\n",
1631 j,nrdf_vcm[j],nrdf_tc[i]);
1636 for(i=0; (i<groups->grps[egcTC].nr); i++) {
1637 opts->nrdf[i] = nrdf_tc[i];
1638 if (opts->nrdf[i] < 0)
1639 opts->nrdf[i] = 0;
1640 fprintf(stderr,
1641 "Number of degrees of freedom in T-Coupling group %s is %.2f\n",
1642 gnames[groups->grps[egcTC].nm_ind[i]],opts->nrdf[i]);
1645 sfree(nrdf2);
1646 sfree(nrdf_tc);
1647 sfree(nrdf_vcm);
1648 sfree(na_vcm);
1651 static void decode_cos(char *s,t_cosines *cosine,bool bTime)
1653 char *t;
1654 char format[STRLEN],f1[STRLEN];
1655 double a,phi;
1656 int i;
1658 t=strdup(s);
1659 trim(t);
1661 cosine->n=0;
1662 cosine->a=NULL;
1663 cosine->phi=NULL;
1664 if (strlen(t)) {
1665 sscanf(t,"%d",&(cosine->n));
1666 if (cosine->n <= 0) {
1667 cosine->n=0;
1668 } else {
1669 snew(cosine->a,cosine->n);
1670 snew(cosine->phi,cosine->n);
1672 sprintf(format,"%%*d");
1673 for(i=0; (i<cosine->n); i++) {
1674 strcpy(f1,format);
1675 strcat(f1,"%lf%lf");
1676 if (sscanf(t,f1,&a,&phi) < 2)
1677 gmx_fatal(FARGS,"Invalid input for electric field shift: '%s'",t);
1678 cosine->a[i]=a;
1679 cosine->phi[i]=phi;
1680 strcat(format,"%*lf%*lf");
1684 sfree(t);
1687 static bool do_egp_flag(t_inputrec *ir,gmx_groups_t *groups,
1688 const char *option,const char *val,int flag)
1690 /* The maximum number of energy group pairs would be MAXPTR*(MAXPTR+1)/2.
1691 * But since this is much larger than STRLEN, such a line can not be parsed.
1692 * The real maximum is the number of names that fit in a string: STRLEN/2.
1694 #define EGP_MAX (STRLEN/2)
1695 int nelem,i,j,k,nr;
1696 char *names[EGP_MAX];
1697 char ***gnames;
1698 bool bSet;
1700 gnames = groups->grpname;
1702 nelem = str_nelem(val,EGP_MAX,names);
1703 if (nelem % 2 != 0)
1704 gmx_fatal(FARGS,"The number of groups for %s is odd",option);
1705 nr = groups->grps[egcENER].nr;
1706 bSet = FALSE;
1707 for(i=0; i<nelem/2; i++) {
1708 j = 0;
1709 while ((j < nr) &&
1710 strcasecmp(names[2*i],*(gnames[groups->grps[egcENER].nm_ind[j]])))
1711 j++;
1712 if (j == nr)
1713 gmx_fatal(FARGS,"%s in %s is not an energy group\n",
1714 names[2*i],option);
1715 k = 0;
1716 while ((k < nr) &&
1717 strcasecmp(names[2*i+1],*(gnames[groups->grps[egcENER].nm_ind[k]])))
1718 k++;
1719 if (k==nr)
1720 gmx_fatal(FARGS,"%s in %s is not an energy group\n",
1721 names[2*i+1],option);
1722 if ((j < nr) && (k < nr)) {
1723 ir->opts.egp_flags[nr*j+k] |= flag;
1724 ir->opts.egp_flags[nr*k+j] |= flag;
1725 bSet = TRUE;
1729 return bSet;
1732 void do_index(const char* mdparin, const char *ndx,
1733 gmx_mtop_t *mtop,
1734 bool bVerbose,
1735 t_inputrec *ir,rvec *v,
1736 warninp_t wi)
1738 t_blocka *grps;
1739 gmx_groups_t *groups;
1740 int natoms;
1741 t_symtab *symtab;
1742 t_atoms atoms_all;
1743 char warnbuf[STRLEN],**gnames;
1744 int nr,ntcg,ntau_t,nref_t,nacc,nofg,nSA,nSA_points,nSA_time,nSA_temp;
1745 real tau_min;
1746 int nstcmin;
1747 int nacg,nfreeze,nfrdim,nenergy,nvcm,nuser;
1748 char *ptr1[MAXPTR],*ptr2[MAXPTR],*ptr3[MAXPTR];
1749 int i,j,k,restnm;
1750 real SAtime;
1751 bool bExcl,bTable,bSetTCpar,bAnneal,bRest;
1752 int nQMmethod,nQMbasis,nQMcharge,nQMmult,nbSH,nCASorb,nCASelec,
1753 nSAon,nSAoff,nSAsteps,nQMg,nbOPT,nbTS;
1754 char warn_buf[STRLEN];
1756 if (bVerbose)
1757 fprintf(stderr,"processing index file...\n");
1758 debug_gmx();
1759 if (ndx == NULL) {
1760 snew(grps,1);
1761 snew(grps->index,1);
1762 snew(gnames,1);
1763 atoms_all = gmx_mtop_global_atoms(mtop);
1764 analyse(&atoms_all,grps,&gnames,FALSE,TRUE);
1765 free_t_atoms(&atoms_all,FALSE);
1766 } else {
1767 grps = init_index(ndx,&gnames);
1770 groups = &mtop->groups;
1771 natoms = mtop->natoms;
1772 symtab = &mtop->symtab;
1774 snew(groups->grpname,grps->nr+1);
1776 for(i=0; (i<grps->nr); i++) {
1777 groups->grpname[i] = put_symtab(symtab,gnames[i]);
1779 groups->grpname[i] = put_symtab(symtab,"rest");
1780 restnm=i;
1781 srenew(gnames,grps->nr+1);
1782 gnames[restnm] = *(groups->grpname[i]);
1783 groups->ngrpname = grps->nr+1;
1785 set_warning_line(wi,mdparin,-1);
1787 ntau_t = str_nelem(tau_t,MAXPTR,ptr1);
1788 nref_t = str_nelem(ref_t,MAXPTR,ptr2);
1789 ntcg = str_nelem(tcgrps,MAXPTR,ptr3);
1790 if ((ntau_t != ntcg) || (nref_t != ntcg)) {
1791 gmx_fatal(FARGS,"Invalid T coupling input: %d groups, %d ref_t values and "
1792 "%d tau_t values",ntcg,nref_t,ntau_t);
1795 bSetTCpar = (ir->etc || EI_SD(ir->eI) || ir->eI==eiBD || EI_TPI(ir->eI));
1796 do_numbering(natoms,groups,ntcg,ptr3,grps,gnames,egcTC,
1797 restnm,bSetTCpar ? egrptpALL : egrptpALL_GENREST,bVerbose,wi);
1798 nr = groups->grps[egcTC].nr;
1799 ir->opts.ngtc = nr;
1800 snew(ir->opts.nrdf,nr);
1801 snew(ir->opts.tau_t,nr);
1802 snew(ir->opts.ref_t,nr);
1803 if (ir->eI==eiBD && ir->bd_fric==0) {
1804 fprintf(stderr,"bd_fric=0, so tau_t will be used as the inverse friction constant(s)\n");
1807 if (bSetTCpar)
1809 if (nr != nref_t)
1811 gmx_fatal(FARGS,"Not enough ref_t and tau_t values!");
1814 tau_min = 1e20;
1815 for(i=0; (i<nr); i++)
1817 ir->opts.tau_t[i] = strtod(ptr1[i],NULL);
1818 if (ir->opts.tau_t[i] < 0)
1820 gmx_fatal(FARGS,"tau_t for group %d negative",i);
1821 } else if (ir->opts.tau_t[i] > 0) {
1822 tau_min = min(tau_min,ir->opts.tau_t[i]);
1825 if (ir->etc != etcNO && EI_VV(ir->eI))
1827 /* This should be removed when VV supports nsttcouple */
1828 ir->nsttcouple = 1;
1830 if (ir->etc != etcNO && ir->nsttcouple == -1)
1832 ir->nsttcouple = ir_optimal_nsttcouple(ir);
1834 nstcmin = tcouple_min_integration_steps(ir->etc);
1835 if (nstcmin > 1)
1837 if (tau_min/(ir->delta_t*ir->nsttcouple) < nstcmin)
1839 sprintf(warn_buf,"For proper integration of the %s thermostat, tau_t (%g) should be at least %d times larger than nsttcouple*dt (%g)",
1840 ETCOUPLTYPE(ir->etc),
1841 tau_min,nstcmin,
1842 ir->nsttcouple*ir->delta_t);
1843 warning(wi,warn_buf);
1846 for(i=0; (i<nr); i++)
1848 ir->opts.ref_t[i] = strtod(ptr2[i],NULL);
1849 if (ir->opts.ref_t[i] < 0)
1851 gmx_fatal(FARGS,"ref_t for group %d negative",i);
1856 /* Simulated annealing for each group. There are nr groups */
1857 nSA = str_nelem(anneal,MAXPTR,ptr1);
1858 if (nSA == 1 && (ptr1[0][0]=='n' || ptr1[0][0]=='N'))
1859 nSA = 0;
1860 if(nSA>0 && nSA != nr)
1861 gmx_fatal(FARGS,"Not enough annealing values: %d (for %d groups)\n",nSA,nr);
1862 else {
1863 snew(ir->opts.annealing,nr);
1864 snew(ir->opts.anneal_npoints,nr);
1865 snew(ir->opts.anneal_time,nr);
1866 snew(ir->opts.anneal_temp,nr);
1867 for(i=0;i<nr;i++) {
1868 ir->opts.annealing[i]=eannNO;
1869 ir->opts.anneal_npoints[i]=0;
1870 ir->opts.anneal_time[i]=NULL;
1871 ir->opts.anneal_temp[i]=NULL;
1873 if (nSA > 0) {
1874 bAnneal=FALSE;
1875 for(i=0;i<nr;i++) {
1876 if(ptr1[i][0]=='n' || ptr1[i][0]=='N') {
1877 ir->opts.annealing[i]=eannNO;
1878 } else if(ptr1[i][0]=='s'|| ptr1[i][0]=='S') {
1879 ir->opts.annealing[i]=eannSINGLE;
1880 bAnneal=TRUE;
1881 } else if(ptr1[i][0]=='p'|| ptr1[i][0]=='P') {
1882 ir->opts.annealing[i]=eannPERIODIC;
1883 bAnneal=TRUE;
1886 if(bAnneal) {
1887 /* Read the other fields too */
1888 nSA_points = str_nelem(anneal_npoints,MAXPTR,ptr1);
1889 if(nSA_points!=nSA)
1890 gmx_fatal(FARGS,"Found %d annealing_npoints values for %d groups\n",nSA_points,nSA);
1891 for(k=0,i=0;i<nr;i++) {
1892 ir->opts.anneal_npoints[i]=strtol(ptr1[i],NULL,10);
1893 if(ir->opts.anneal_npoints[i]==1)
1894 gmx_fatal(FARGS,"Please specify at least a start and an end point for annealing\n");
1895 snew(ir->opts.anneal_time[i],ir->opts.anneal_npoints[i]);
1896 snew(ir->opts.anneal_temp[i],ir->opts.anneal_npoints[i]);
1897 k += ir->opts.anneal_npoints[i];
1900 nSA_time = str_nelem(anneal_time,MAXPTR,ptr1);
1901 if(nSA_time!=k)
1902 gmx_fatal(FARGS,"Found %d annealing_time values, wanter %d\n",nSA_time,k);
1903 nSA_temp = str_nelem(anneal_temp,MAXPTR,ptr2);
1904 if(nSA_temp!=k)
1905 gmx_fatal(FARGS,"Found %d annealing_temp values, wanted %d\n",nSA_temp,k);
1907 for(i=0,k=0;i<nr;i++) {
1909 for(j=0;j<ir->opts.anneal_npoints[i];j++) {
1910 ir->opts.anneal_time[i][j]=strtod(ptr1[k],NULL);
1911 ir->opts.anneal_temp[i][j]=strtod(ptr2[k],NULL);
1912 if(j==0) {
1913 if(ir->opts.anneal_time[i][0] > (ir->init_t+GMX_REAL_EPS))
1914 gmx_fatal(FARGS,"First time point for annealing > init_t.\n");
1915 } else {
1916 /* j>0 */
1917 if(ir->opts.anneal_time[i][j]<ir->opts.anneal_time[i][j-1])
1918 gmx_fatal(FARGS,"Annealing timepoints out of order: t=%f comes after t=%f\n",
1919 ir->opts.anneal_time[i][j],ir->opts.anneal_time[i][j-1]);
1921 if(ir->opts.anneal_temp[i][j]<0)
1922 gmx_fatal(FARGS,"Found negative temperature in annealing: %f\n",ir->opts.anneal_temp[i][j]);
1923 k++;
1926 /* Print out some summary information, to make sure we got it right */
1927 for(i=0,k=0;i<nr;i++) {
1928 if(ir->opts.annealing[i]!=eannNO) {
1929 j = groups->grps[egcTC].nm_ind[i];
1930 fprintf(stderr,"Simulated annealing for group %s: %s, %d timepoints\n",
1931 *(groups->grpname[j]),eann_names[ir->opts.annealing[i]],
1932 ir->opts.anneal_npoints[i]);
1933 fprintf(stderr,"Time (ps) Temperature (K)\n");
1934 /* All terms except the last one */
1935 for(j=0;j<(ir->opts.anneal_npoints[i]-1);j++)
1936 fprintf(stderr,"%9.1f %5.1f\n",ir->opts.anneal_time[i][j],ir->opts.anneal_temp[i][j]);
1938 /* Finally the last one */
1939 j = ir->opts.anneal_npoints[i]-1;
1940 if(ir->opts.annealing[i]==eannSINGLE)
1941 fprintf(stderr,"%9.1f- %5.1f\n",ir->opts.anneal_time[i][j],ir->opts.anneal_temp[i][j]);
1942 else {
1943 fprintf(stderr,"%9.1f %5.1f\n",ir->opts.anneal_time[i][j],ir->opts.anneal_temp[i][j]);
1944 if(fabs(ir->opts.anneal_temp[i][j]-ir->opts.anneal_temp[i][0])>GMX_REAL_EPS)
1945 warning_note(wi,"There is a temperature jump when your annealing loops back.\n");
1953 if (ir->ePull != epullNO) {
1954 make_pull_groups(ir->pull,pull_grp,grps,gnames);
1957 nacc = str_nelem(acc,MAXPTR,ptr1);
1958 nacg = str_nelem(accgrps,MAXPTR,ptr2);
1959 if (nacg*DIM != nacc)
1960 gmx_fatal(FARGS,"Invalid Acceleration input: %d groups and %d acc. values",
1961 nacg,nacc);
1962 do_numbering(natoms,groups,nacg,ptr2,grps,gnames,egcACC,
1963 restnm,egrptpALL_GENREST,bVerbose,wi);
1964 nr = groups->grps[egcACC].nr;
1965 snew(ir->opts.acc,nr);
1966 ir->opts.ngacc=nr;
1968 for(i=k=0; (i<nacg); i++)
1969 for(j=0; (j<DIM); j++,k++)
1970 ir->opts.acc[i][j]=strtod(ptr1[k],NULL);
1971 for( ;(i<nr); i++)
1972 for(j=0; (j<DIM); j++)
1973 ir->opts.acc[i][j]=0;
1975 nfrdim = str_nelem(frdim,MAXPTR,ptr1);
1976 nfreeze = str_nelem(freeze,MAXPTR,ptr2);
1977 if (nfrdim != DIM*nfreeze)
1978 gmx_fatal(FARGS,"Invalid Freezing input: %d groups and %d freeze values",
1979 nfreeze,nfrdim);
1980 do_numbering(natoms,groups,nfreeze,ptr2,grps,gnames,egcFREEZE,
1981 restnm,egrptpALL_GENREST,bVerbose,wi);
1982 nr = groups->grps[egcFREEZE].nr;
1983 ir->opts.ngfrz=nr;
1984 snew(ir->opts.nFreeze,nr);
1985 for(i=k=0; (i<nfreeze); i++)
1986 for(j=0; (j<DIM); j++,k++) {
1987 ir->opts.nFreeze[i][j]=(strncasecmp(ptr1[k],"Y",1)==0);
1988 if (!ir->opts.nFreeze[i][j]) {
1989 if (strncasecmp(ptr1[k],"N",1) != 0) {
1990 sprintf(warnbuf,"Please use Y(ES) or N(O) for freezedim only "
1991 "(not %s)", ptr1[k]);
1992 warning(wi,warn_buf);
1996 for( ; (i<nr); i++)
1997 for(j=0; (j<DIM); j++)
1998 ir->opts.nFreeze[i][j]=0;
2000 nenergy=str_nelem(energy,MAXPTR,ptr1);
2001 do_numbering(natoms,groups,nenergy,ptr1,grps,gnames,egcENER,
2002 restnm,egrptpALL_GENREST,bVerbose,wi);
2003 add_wall_energrps(groups,ir->nwall,symtab);
2004 ir->opts.ngener = groups->grps[egcENER].nr;
2005 nvcm=str_nelem(vcm,MAXPTR,ptr1);
2006 bRest =
2007 do_numbering(natoms,groups,nvcm,ptr1,grps,gnames,egcVCM,
2008 restnm,nvcm==0 ? egrptpALL_GENREST : egrptpPART,bVerbose,wi);
2009 if (bRest) {
2010 warning(wi,"Some atoms are not part of any center of mass motion removal group.\n"
2011 "This may lead to artifacts.\n"
2012 "In most cases one should use one group for the whole system.");
2015 /* Now we have filled the freeze struct, so we can calculate NRDF */
2016 calc_nrdf(mtop,ir,gnames);
2018 if (v && NULL) {
2019 real fac,ntot=0;
2021 /* Must check per group! */
2022 for(i=0; (i<ir->opts.ngtc); i++)
2023 ntot += ir->opts.nrdf[i];
2024 if (ntot != (DIM*natoms)) {
2025 fac = sqrt(ntot/(DIM*natoms));
2026 if (bVerbose)
2027 fprintf(stderr,"Scaling velocities by a factor of %.3f to account for constraints\n"
2028 "and removal of center of mass motion\n",fac);
2029 for(i=0; (i<natoms); i++)
2030 svmul(fac,v[i],v[i]);
2034 nuser=str_nelem(user1,MAXPTR,ptr1);
2035 do_numbering(natoms,groups,nuser,ptr1,grps,gnames,egcUser1,
2036 restnm,egrptpALL_GENREST,bVerbose,wi);
2037 nuser=str_nelem(user2,MAXPTR,ptr1);
2038 do_numbering(natoms,groups,nuser,ptr1,grps,gnames,egcUser2,
2039 restnm,egrptpALL_GENREST,bVerbose,wi);
2040 nuser=str_nelem(xtc_grps,MAXPTR,ptr1);
2041 do_numbering(natoms,groups,nuser,ptr1,grps,gnames,egcXTC,
2042 restnm,egrptpONE,bVerbose,wi);
2043 nofg = str_nelem(orirefitgrp,MAXPTR,ptr1);
2044 do_numbering(natoms,groups,nofg,ptr1,grps,gnames,egcORFIT,
2045 restnm,egrptpALL_GENREST,bVerbose,wi);
2047 /* QMMM input processing */
2048 nQMg = str_nelem(QMMM,MAXPTR,ptr1);
2049 nQMmethod = str_nelem(QMmethod,MAXPTR,ptr2);
2050 nQMbasis = str_nelem(QMbasis,MAXPTR,ptr3);
2051 if((nQMmethod != nQMg)||(nQMbasis != nQMg)){
2052 gmx_fatal(FARGS,"Invalid QMMM input: %d groups %d basissets"
2053 " and %d methods\n",nQMg,nQMbasis,nQMmethod);
2055 /* group rest, if any, is always MM! */
2056 do_numbering(natoms,groups,nQMg,ptr1,grps,gnames,egcQMMM,
2057 restnm,egrptpALL_GENREST,bVerbose,wi);
2058 nr = nQMg; /*atoms->grps[egcQMMM].nr;*/
2059 ir->opts.ngQM = nQMg;
2060 snew(ir->opts.QMmethod,nr);
2061 snew(ir->opts.QMbasis,nr);
2062 for(i=0;i<nr;i++){
2063 /* input consists of strings: RHF CASSCF PM3 .. These need to be
2064 * converted to the corresponding enum in names.c
2066 ir->opts.QMmethod[i] = search_QMstring(ptr2[i],eQMmethodNR,
2067 eQMmethod_names);
2068 ir->opts.QMbasis[i] = search_QMstring(ptr3[i],eQMbasisNR,
2069 eQMbasis_names);
2072 nQMmult = str_nelem(QMmult,MAXPTR,ptr1);
2073 nQMcharge = str_nelem(QMcharge,MAXPTR,ptr2);
2074 nbSH = str_nelem(bSH,MAXPTR,ptr3);
2075 snew(ir->opts.QMmult,nr);
2076 snew(ir->opts.QMcharge,nr);
2077 snew(ir->opts.bSH,nr);
2079 for(i=0;i<nr;i++){
2080 ir->opts.QMmult[i] = strtol(ptr1[i],NULL,10);
2081 ir->opts.QMcharge[i] = strtol(ptr2[i],NULL,10);
2082 ir->opts.bSH[i] = (strncasecmp(ptr3[i],"Y",1)==0);
2085 nCASelec = str_nelem(CASelectrons,MAXPTR,ptr1);
2086 nCASorb = str_nelem(CASorbitals,MAXPTR,ptr2);
2087 snew(ir->opts.CASelectrons,nr);
2088 snew(ir->opts.CASorbitals,nr);
2089 for(i=0;i<nr;i++){
2090 ir->opts.CASelectrons[i]= strtol(ptr1[i],NULL,10);
2091 ir->opts.CASorbitals[i] = strtol(ptr2[i],NULL,10);
2093 /* special optimization options */
2095 nbOPT = str_nelem(bOPT,MAXPTR,ptr1);
2096 nbTS = str_nelem(bTS,MAXPTR,ptr2);
2097 snew(ir->opts.bOPT,nr);
2098 snew(ir->opts.bTS,nr);
2099 for(i=0;i<nr;i++){
2100 ir->opts.bOPT[i] = (strncasecmp(ptr1[i],"Y",1)==0);
2101 ir->opts.bTS[i] = (strncasecmp(ptr2[i],"Y",1)==0);
2103 nSAon = str_nelem(SAon,MAXPTR,ptr1);
2104 nSAoff = str_nelem(SAoff,MAXPTR,ptr2);
2105 nSAsteps = str_nelem(SAsteps,MAXPTR,ptr3);
2106 snew(ir->opts.SAon,nr);
2107 snew(ir->opts.SAoff,nr);
2108 snew(ir->opts.SAsteps,nr);
2110 for(i=0;i<nr;i++){
2111 ir->opts.SAon[i] = strtod(ptr1[i],NULL);
2112 ir->opts.SAoff[i] = strtod(ptr2[i],NULL);
2113 ir->opts.SAsteps[i] = strtol(ptr3[i],NULL,10);
2115 /* end of QMMM input */
2117 if (bVerbose)
2118 for(i=0; (i<egcNR); i++) {
2119 fprintf(stderr,"%-16s has %d element(s):",gtypes[i],groups->grps[i].nr);
2120 for(j=0; (j<groups->grps[i].nr); j++)
2121 fprintf(stderr," %s",*(groups->grpname[groups->grps[i].nm_ind[j]]));
2122 fprintf(stderr,"\n");
2125 nr = groups->grps[egcENER].nr;
2126 snew(ir->opts.egp_flags,nr*nr);
2128 bExcl = do_egp_flag(ir,groups,"energygrp_excl",egpexcl,EGP_EXCL);
2129 if (bExcl && EEL_FULL(ir->coulombtype))
2130 warning(wi,"Can not exclude the lattice Coulomb energy between energy groups");
2132 bTable = do_egp_flag(ir,groups,"energygrp_table",egptable,EGP_TABLE);
2133 if (bTable && !(ir->vdwtype == evdwUSER) &&
2134 !(ir->coulombtype == eelUSER) && !(ir->coulombtype == eelPMEUSER) &&
2135 !(ir->coulombtype == eelPMEUSERSWITCH))
2136 gmx_fatal(FARGS,"Can only have energy group pair tables in combination with user tables for VdW and/or Coulomb");
2138 decode_cos(efield_x,&(ir->ex[XX]),FALSE);
2139 decode_cos(efield_xt,&(ir->et[XX]),TRUE);
2140 decode_cos(efield_y,&(ir->ex[YY]),FALSE);
2141 decode_cos(efield_yt,&(ir->et[YY]),TRUE);
2142 decode_cos(efield_z,&(ir->ex[ZZ]),FALSE);
2143 decode_cos(efield_zt,&(ir->et[ZZ]),TRUE);
2145 for(i=0; (i<grps->nr); i++)
2146 sfree(gnames[i]);
2147 sfree(gnames);
2148 done_blocka(grps);
2149 sfree(grps);
2155 static void check_disre(gmx_mtop_t *mtop)
2157 gmx_ffparams_t *ffparams;
2158 t_functype *functype;
2159 t_iparams *ip;
2160 int i,ndouble,ftype;
2161 int label,old_label;
2163 if (gmx_mtop_ftype_count(mtop,F_DISRES) > 0) {
2164 ffparams = &mtop->ffparams;
2165 functype = ffparams->functype;
2166 ip = ffparams->iparams;
2167 ndouble = 0;
2168 old_label = -1;
2169 for(i=0; i<ffparams->ntypes; i++) {
2170 ftype = functype[i];
2171 if (ftype == F_DISRES) {
2172 label = ip[i].disres.label;
2173 if (label == old_label) {
2174 fprintf(stderr,"Distance restraint index %d occurs twice\n",label);
2175 ndouble++;
2177 old_label = label;
2180 if (ndouble>0)
2181 gmx_fatal(FARGS,"Found %d double distance restraint indices,\n"
2182 "probably the parameters for multiple pairs in one restraint "
2183 "are not identical\n",ndouble);
2187 static bool absolute_reference(t_inputrec *ir,gmx_mtop_t *sys,ivec AbsRef)
2189 int d,g,i;
2190 gmx_mtop_ilistloop_t iloop;
2191 t_ilist *ilist;
2192 int nmol;
2193 t_iparams *pr;
2195 /* Check the COM */
2196 for(d=0; d<DIM; d++) {
2197 AbsRef[d] = (d < ndof_com(ir) ? 0 : 1);
2199 /* Check for freeze groups */
2200 for(g=0; g<ir->opts.ngfrz; g++) {
2201 for(d=0; d<DIM; d++) {
2202 if (ir->opts.nFreeze[g][d] != 0) {
2203 AbsRef[d] = 1;
2207 /* Check for position restraints */
2208 iloop = gmx_mtop_ilistloop_init(sys);
2209 while (gmx_mtop_ilistloop_next(iloop,&ilist,&nmol)) {
2210 if (nmol > 0) {
2211 for(i=0; i<ilist[F_POSRES].nr; i+=2) {
2212 pr = &sys->ffparams.iparams[ilist[F_POSRES].iatoms[i]];
2213 for(d=0; d<DIM; d++) {
2214 if (pr->posres.fcA[d] != 0) {
2215 AbsRef[d] = 1;
2222 return (AbsRef[XX] != 0 && AbsRef[YY] != 0 && AbsRef[ZZ] != 0);
2225 void triple_check(const char *mdparin,t_inputrec *ir,gmx_mtop_t *sys,
2226 warninp_t wi)
2228 char err_buf[256];
2229 int i,m,g,nmol,npct;
2230 bool bCharge,bAcc;
2231 real gdt_max,*mgrp,mt;
2232 rvec acc;
2233 gmx_mtop_atomloop_block_t aloopb;
2234 gmx_mtop_atomloop_all_t aloop;
2235 t_atom *atom;
2236 ivec AbsRef;
2237 char warn_buf[STRLEN];
2239 set_warning_line(wi,mdparin,-1);
2241 if (EI_DYNAMICS(ir->eI) && !EI_SD(ir->eI) && ir->eI != eiBD &&
2242 ir->comm_mode == ecmNO &&
2243 !(absolute_reference(ir,sys,AbsRef) || ir->nsteps <= 10)) {
2244 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");
2247 bCharge = FALSE;
2248 aloopb = gmx_mtop_atomloop_block_init(sys);
2249 while (gmx_mtop_atomloop_block_next(aloopb,&atom,&nmol)) {
2250 if (atom->q != 0 || atom->qB != 0) {
2251 bCharge = TRUE;
2255 if (!bCharge) {
2256 if (EEL_FULL(ir->coulombtype)) {
2257 sprintf(err_buf,
2258 "You are using full electrostatics treatment %s for a system without charges.\n"
2259 "This costs a lot of performance for just processing zeros, consider using %s instead.\n",
2260 EELTYPE(ir->coulombtype),EELTYPE(eelCUT));
2261 warning(wi,err_buf);
2263 } else {
2264 if (ir->coulombtype == eelCUT && ir->rcoulomb > 0) {
2265 sprintf(err_buf,
2266 "You are using a plain Coulomb cut-off, which might produce artifacts.\n"
2267 "You might want to consider using %s electrostatics.\n",
2268 EELTYPE(eelPME));
2269 warning_note(wi,err_buf);
2273 /* Generalized reaction field */
2274 if (ir->opts.ngtc == 0) {
2275 sprintf(err_buf,"No temperature coupling while using coulombtype %s",
2276 eel_names[eelGRF]);
2277 CHECK(ir->coulombtype == eelGRF);
2279 else {
2280 sprintf(err_buf,"When using coulombtype = %s"
2281 " ref_t for temperature coupling should be > 0",
2282 eel_names[eelGRF]);
2283 CHECK((ir->coulombtype == eelGRF) && (ir->opts.ref_t[0] <= 0));
2286 if (ir->eI == eiSD1) {
2287 gdt_max = 0;
2288 for(i=0; (i<ir->opts.ngtc); i++)
2289 gdt_max = max(gdt_max,ir->delta_t/ir->opts.tau_t[i]);
2290 if (0.5*gdt_max > 0.0015) {
2291 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",
2292 ei_names[ir->eI],0.5*gdt_max,ei_names[eiSD2]);
2293 warning_note(wi,warn_buf);
2297 bAcc = FALSE;
2298 for(i=0; (i<sys->groups.grps[egcACC].nr); i++) {
2299 for(m=0; (m<DIM); m++) {
2300 if (fabs(ir->opts.acc[i][m]) > 1e-6) {
2301 bAcc = TRUE;
2305 if (bAcc) {
2306 clear_rvec(acc);
2307 snew(mgrp,sys->groups.grps[egcACC].nr);
2308 aloop = gmx_mtop_atomloop_all_init(sys);
2309 while (gmx_mtop_atomloop_all_next(aloop,&i,&atom)) {
2310 mgrp[ggrpnr(&sys->groups,egcACC,i)] += atom->m;
2312 mt = 0.0;
2313 for(i=0; (i<sys->groups.grps[egcACC].nr); i++) {
2314 for(m=0; (m<DIM); m++)
2315 acc[m] += ir->opts.acc[i][m]*mgrp[i];
2316 mt += mgrp[i];
2318 for(m=0; (m<DIM); m++) {
2319 if (fabs(acc[m]) > 1e-6) {
2320 const char *dim[DIM] = { "X", "Y", "Z" };
2321 fprintf(stderr,
2322 "Net Acceleration in %s direction, will %s be corrected\n",
2323 dim[m],ir->nstcomm != 0 ? "" : "not");
2324 if (ir->nstcomm != 0 && m < ndof_com(ir)) {
2325 acc[m] /= mt;
2326 for (i=0; (i<sys->groups.grps[egcACC].nr); i++)
2327 ir->opts.acc[i][m] -= acc[m];
2331 sfree(mgrp);
2334 if (ir->efep != efepNO && ir->sc_alpha != 0 &&
2335 !gmx_within_tol(sys->ffparams.reppow,12.0,10*GMX_DOUBLE_EPS)) {
2336 gmx_fatal(FARGS,"Soft-core interactions are only supported with VdW repulsion power 12");
2339 if (ir->ePull != epullNO) {
2340 if (ir->pull->grp[0].nat == 0) {
2341 absolute_reference(ir,sys,AbsRef);
2342 for(m=0; m<DIM; m++) {
2343 if (ir->pull->dim[m] && !AbsRef[m]) {
2344 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.");
2345 break;
2350 if (ir->pull->eGeom == epullgDIRPBC) {
2351 for(i=0; i<3; i++) {
2352 for(m=0; m<=i; m++) {
2353 if ((ir->epc != epcNO && ir->compress[i][m] != 0) ||
2354 ir->deform[i][m] != 0) {
2355 for(g=1; g<ir->pull->ngrp; g++) {
2356 if (ir->pull->grp[g].vec[m] != 0) {
2357 gmx_fatal(FARGS,"Can not have dynamic box while using pull geometry '%s' (dim %c)",EPULLGEOM(ir->pull->eGeom),'x'+m);
2366 check_disre(sys);
2369 void double_check(t_inputrec *ir,matrix box,bool bConstr,warninp_t wi)
2371 real min_size;
2372 bool bTWIN;
2373 char warn_buf[STRLEN];
2374 const char *ptr;
2376 ptr = check_box(ir->ePBC,box);
2377 if (ptr) {
2378 warning_error(wi,ptr);
2381 if (bConstr && ir->eConstrAlg == econtSHAKE) {
2382 if (ir->shake_tol <= 0.0) {
2383 sprintf(warn_buf,"ERROR: shake_tol must be > 0 instead of %g\n",
2384 ir->shake_tol);
2385 warning_error(wi,warn_buf);
2388 if (IR_TWINRANGE(*ir) && ir->nstlist > 1) {
2389 sprintf(warn_buf,"With twin-range cut-off's and SHAKE the virial and the pressure are incorrect.");
2390 if (ir->epc == epcNO) {
2391 warning(wi,warn_buf);
2392 } else {
2393 warning_error(wi,warn_buf);
2398 if( (ir->eConstrAlg == econtLINCS) && bConstr) {
2399 /* If we have Lincs constraints: */
2400 if(ir->eI==eiMD && ir->etc==etcNO &&
2401 ir->eConstrAlg==econtLINCS && ir->nLincsIter==1) {
2402 sprintf(warn_buf,"For energy conservation with LINCS, lincs_iter should be 2 or larger.\n");
2403 warning_note(wi,warn_buf);
2406 if ((ir->eI == eiCG || ir->eI == eiLBFGS) && (ir->nProjOrder<8)) {
2407 sprintf(warn_buf,"For accurate %s with LINCS constraints, lincs_order should be 8 or more.",ei_names[ir->eI]);
2408 warning_note(wi,warn_buf);
2410 if (ir->epc==epcMTTK) {
2411 warning_error(wi,"MTTK not compatible with lincs -- use shake instead.");
2415 if (ir->LincsWarnAngle > 90.0) {
2416 sprintf(warn_buf,"lincs-warnangle can not be larger than 90 degrees, setting it to 90.\n");
2417 warning(wi,warn_buf);
2418 ir->LincsWarnAngle = 90.0;
2421 if (ir->ePBC != epbcNONE) {
2422 if (ir->nstlist == 0) {
2423 warning(wi,"With nstlist=0 atoms are only put into the box at step 0, therefore drifting atoms might cause the simulation to crash.");
2425 bTWIN = (ir->rlistlong > ir->rlist);
2426 if (ir->ns_type == ensGRID) {
2427 if (sqr(ir->rlistlong) >= max_cutoff2(ir->ePBC,box)) {
2428 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",
2429 bTWIN ? (ir->rcoulomb==ir->rlistlong ? "rcoulomb" : "rvdw"):"rlist");
2430 warning_error(wi,warn_buf);
2432 } else {
2433 min_size = min(box[XX][XX],min(box[YY][YY],box[ZZ][ZZ]));
2434 if (2*ir->rlistlong >= min_size) {
2435 sprintf(warn_buf,"ERROR: One of the box lengths is smaller than twice the cut-off length. Increase the box size or decrease rlist.");
2436 warning_error(wi,warn_buf);
2437 if (TRICLINIC(box))
2438 fprintf(stderr,"Grid search might allow larger cut-off's than simple search with triclinic boxes.");
2444 void check_chargegroup_radii(const gmx_mtop_t *mtop,const t_inputrec *ir,
2445 rvec *x,
2446 warninp_t wi)
2448 real rvdw1,rvdw2,rcoul1,rcoul2;
2449 char warn_buf[STRLEN];
2451 calc_chargegroup_radii(mtop,x,&rvdw1,&rvdw2,&rcoul1,&rcoul2);
2453 if (rvdw1 > 0)
2455 printf("Largest charge group radii for Van der Waals: %5.3f, %5.3f nm\n",
2456 rvdw1,rvdw2);
2458 if (rcoul1 > 0)
2460 printf("Largest charge group radii for Coulomb: %5.3f, %5.3f nm\n",
2461 rcoul1,rcoul2);
2464 if (ir->rlist > 0)
2466 if (rvdw1 + rvdw2 > ir->rlist ||
2467 rcoul1 + rcoul2 > ir->rlist)
2469 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);
2470 warning(wi,warn_buf);
2472 else
2474 /* Here we do not use the zero at cut-off macro,
2475 * since user defined interactions might purposely
2476 * not be zero at the cut-off.
2478 if (EVDW_IS_ZERO_AT_CUTOFF(ir->vdwtype) &&
2479 rvdw1 + rvdw2 > ir->rlistlong - ir->rvdw)
2481 sprintf(warn_buf,"The sum of the two largest charge group radii (%f) is larger than %s (%f) - rvdw (%f)\n",
2482 rvdw1+rvdw2,
2483 ir->rlistlong > ir->rlist ? "rlistlong" : "rlist",
2484 ir->rlist,ir->rvdw);
2485 if (ir_NVE(ir))
2487 warning(wi,warn_buf);
2489 else
2491 warning_note(wi,warn_buf);
2494 if (EEL_IS_ZERO_AT_CUTOFF(ir->coulombtype) &&
2495 rcoul1 + rcoul2 > ir->rlistlong - ir->rcoulomb)
2497 sprintf(warn_buf,"The sum of the two largest charge group radii (%f) is larger than %s (%f) - rcoulomb (%f)\n",
2498 rcoul1+rcoul2,
2499 ir->rlistlong > ir->rlist ? "rlistlong" : "rlist",
2500 ir->rlistlong,ir->rcoulomb);
2501 if (ir_NVE(ir))
2503 warning(wi,warn_buf);
2505 else
2507 warning_note(wi,warn_buf);