Merge "Merge branch release-4-6 into release-5-0" into release-5-0
authorRoland Schulz <roland@rschulz.eu>
Fri, 9 May 2014 19:04:43 +0000 (21:04 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Fri, 9 May 2014 19:04:44 +0000 (21:04 +0200)
src/gromacs/fileio/gmxfio_asc.c
src/gromacs/gmxana/gmx_rmsdist.c
src/gromacs/gmxpreprocess/readir.c
src/gromacs/mdlib/coupling.c

index f27756aa49e06186ec259548a2f23ebb7905e53d..bf35b85aafd7826426299f2112c045a73a0ac8cb 100644 (file)
@@ -104,7 +104,7 @@ static void encode_string(int maxlen, char dst[], const char src[])
 {
     int i;
 
-    for (i = 0; (src[i] != '\0') && (i < maxlen - 1); i++)
+    for (i = 0; (i < maxlen - 1) && (src[i] != '\0'); i++)
     {
         if ((src[i] == ' ') || (src[i] == '\t'))
         {
@@ -127,7 +127,7 @@ static void decode_string(int maxlen, char dst[], const char src[])
 {
     int i;
 
-    for (i = 0; (src[i] != '\0') && (i < maxlen - 1); i++)
+    for (i = 0; (i < maxlen - 1) && (src[i] != '\0'); i++)
     {
         if (src[i] == '_')
         {
index a28f241f45b269f66febead85eca4fa465c415e0..7e6515f29bd686eb6c68743e888204d2c90f2614 100644 (file)
@@ -324,7 +324,7 @@ static int analyze_noe_equivalent(const char *eq_fn,
                     if (bEquiv)
                     {
                         /* set index for matching atom */
-                        noe_index[j] = groupnr;
+                        noe_index[i] = groupnr;
                         /* skip matching atom */
                         i = j;
                     }
@@ -342,7 +342,7 @@ static int analyze_noe_equivalent(const char *eq_fn,
                    This is supposed to cover all CH3 groups and the like */
                 anmi   = *atoms->atomname[index[i]];
                 anmil  = strlen(anmi);
-                bMatch = i < isize-3 && anmi[anmil-1] == '1';
+                bMatch = i <= isize-3 && anmi[anmil-1] == '1';
                 if (bMatch)
                 {
                     for (j = 1; j < 3; j++)
@@ -645,7 +645,7 @@ int gmx_rmsdist(int argc, char *argv[])
         "equivalent atoms can be supplied ([TT]-equiv[tt]), each line containing",
         "a set of equivalent atoms specified as residue number and name and",
         "atom name; e.g.:[PAR]",
-        "[TT]3 SER  HB1 3 SER  HB2[tt][PAR]",
+        "[TT]HB* 3 SER  HB1 3 SER  HB2[tt][PAR]",
         "Residue and atom names must exactly match those in the structure",
         "file, including case. Specifying non-sequential atoms is undefined."
 
@@ -786,7 +786,8 @@ int gmx_rmsdist(int argc, char *argv[])
     }
 
     /*do a first step*/
-    natom = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
+    natom  = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
+    teller = 0;
 
     do
     {
@@ -794,14 +795,13 @@ int gmx_rmsdist(int argc, char *argv[])
 
         rmsnow = rms_diff(isize, d, d_r);
         fprintf(fp, "%g  %g\n", t, rmsnow);
+        teller++;
     }
     while (read_next_x(oenv, status, &t, x, box));
     fprintf(stderr, "\n");
 
     gmx_ffclose(fp);
 
-    teller = nframes_read(status);
-
     close_trj(status);
 
     calc_rms(isize, teller, dtot, dtot2, mean, &meanmax, rms, &rmsmax, rmsc, &rmscmax);
index 19f9411761ec217d33e849c7b3a0eb0e2fbae597..521a6e3268d0faf49b30d22a78d389bc6b0d8c51 100644 (file)
@@ -1143,13 +1143,22 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts,
         warning_note(wi, warn_buf);
     }
 
-    if (ir->coulombtype == eelPMESWITCH)
+    if (ir->coulombtype == eelPMESWITCH || ir->coulomb_modifier == eintmodPOTSWITCH)
     {
         if (ir->rcoulomb_switch/ir->rcoulomb < 0.9499)
         {
-            sprintf(warn_buf, "The switching range for %s should be 5%% or less, energy conservation will be good anyhow, since ewald_rtol = %g",
-                    eel_names[ir->coulombtype],
-                    ir->ewald_rtol);
+            real percentage  = 100*(ir->rcoulomb-ir->rcoulomb_switch)/ir->rcoulomb;
+            sprintf(warn_buf, "The switching range for should be 5%% or less (currently %.2f%% using a switching range of %4f-%4f) for accurate electrostatic energies, energy conservation will be good regardless, since ewald_rtol = %g.",
+                    percentage, ir->rcoulomb_switch, ir->rcoulomb, ir->ewald_rtol);
+            warning(wi, warn_buf);
+        }
+    }
+
+    if (ir->vdwtype == evdwSWITCH || ir->vdw_modifier == eintmodPOTSWITCH)
+    {
+        if (ir->rvdw_switch == 0)
+        {
+            sprintf(warn_buf, "rvdw-switch is equal 0 even though you are using a switched Lennard-Jones potential.  This suggests it was not set in the mdp, which can lead to large energy errors.  In GROMACS, 0.05 to 0.1 nm is often a reasonable vdw switching range.");
             warning(wi, warn_buf);
         }
     }
index c0ca0111489f07271b62b622fcd873924eca4c7a..a08e2dcfad986ed70ca3e3c125f3c0526c744ef1 100644 (file)
@@ -1355,58 +1355,43 @@ real NPT_energy(t_inputrec *ir, t_state *state, t_extmass *MassQ)
     return ener_npt;
 }
 
-static real vrescale_gamdev(int ia,
+static real vrescale_gamdev(real ia,
                             gmx_int64_t step, gmx_int64_t *count,
                             gmx_int64_t seed1, gmx_int64_t seed2)
 /* Gamma distribution, adapted from numerical recipes */
 {
-    int    j;
     real   am, e, s, v1, v2, x, y;
     double rnd[2];
 
-    if (ia < 6)
+    assert(ia > 1);
+
+    do
     {
         do
         {
-            x = 1.0;
-            for (j = 1; j <= ia; j++)
+            do
             {
                 gmx_rng_cycle_2uniform(step, (*count)++, seed1, seed2, rnd);
-                x *= rnd[0];
+                v1 = rnd[0];
+                v2 = 2.0*rnd[1] - 1.0;
             }
+            while (v1*v1 + v2*v2 > 1.0 ||
+                   v1*v1*GMX_REAL_MAX < 3.0*ia);
+            /* The last check above ensures that both x (3.0 > 2.0 in s)
+             * and the pre-factor for e do not go out of range.
+             */
+            y  = v2/v1;
+            am = ia - 1;
+            s  = sqrt(2.0*am + 1.0);
+            x  = s*y + am;
         }
-        while (x == 0);
-        x = -log(x);
-    }
-    else
-    {
-        do
-        {
-            do
-            {
-                do
-                {
-                    gmx_rng_cycle_2uniform(step, (*count)++, seed1, seed2, rnd);
-                    v1 = rnd[0];
-                    v2 = 2.0*rnd[1] - 1.0;
-                }
-                while (v1*v1 + v2*v2 > 1.0 ||
-                       v1*v1*GMX_REAL_MAX < 3.0*ia);
-                /* The last check above ensures that both x (3.0 > 2.0 in s)
-                 * and the pre-factor for e do not go out of range.
-                 */
-                y  = v2/v1;
-                am = ia - 1;
-                s  = sqrt(2.0*am + 1.0);
-                x  = s*y + am;
-            }
-            while (x <= 0.0);
-            e = (1.0 + y*y)*exp(am*log(x/am) - s*y);
+        while (x <= 0.0);
 
-            gmx_rng_cycle_2uniform(step, (*count)++, seed1, seed2, rnd);
-        }
-        while (rnd[0] > e);
+        e = (1.0 + y*y)*exp(am*log(x/am) - s*y);
+
+        gmx_rng_cycle_2uniform(step, (*count)++, seed1, seed2, rnd);
     }
+    while (rnd[0] > e);
 
     return x;
 }
@@ -1430,30 +1415,48 @@ static real gaussian_count(gmx_int64_t step, gmx_int64_t *count,
     return x*r;
 }
 
-static real vrescale_sumnoises(int nn,
+static real vrescale_sumnoises(real nn,
                                gmx_int64_t step, gmx_int64_t *count,
                                gmx_int64_t seed1, gmx_int64_t seed2)
 {
 /*
- * Returns the sum of n independent gaussian noises squared
+ * Returns the sum of nn independent gaussian noises squared
  * (i.e. equivalent to summing the square of the return values
- * of nn calls to gmx_rng_gaussian_real).xs
+ * of nn calls to gmx_rng_gaussian_real).
  */
-    real r, gauss;
-
-    r = 2.0*vrescale_gamdev(nn/2, step, count, seed1, seed2);
+    const real ndeg_tol = 0.0001;
+    real       r;
 
-    if (nn % 2 == 1)
+    if (nn < 2 + ndeg_tol)
     {
-        gauss = gaussian_count(step, count, seed1, seed2);
+        int  nn_int, i;
+        real gauss;
+
+        nn_int = (int)(nn + 0.5);
+
+        if (nn - nn_int < -ndeg_tol || nn - nn_int > ndeg_tol)
+        {
+            gmx_fatal(FARGS, "The v-rescale thermostat was called with a group with #DOF=%f, but for #DOF<3 only integer #DOF are supported", nn + 1);
+        }
+
+        r = 0;
+        for (i = 0; i < nn_int; i++)
+        {
+            gauss = gaussian_count(step, count, seed1, seed2);
 
-        r += gauss*gauss;
+            r += gauss*gauss;
+        }
+    }
+    else
+    {
+        /* Use a gamma distribution for any real nn > 2 */
+        r = 2.0*vrescale_gamdev(0.5*nn, step, count, seed1, seed2);
     }
 
     return r;
 }
 
-static real vrescale_resamplekin(real kk, real sigma, int ndeg, real taut,
+static real vrescale_resamplekin(real kk, real sigma, real ndeg, real taut,
                                  gmx_int64_t step, gmx_int64_t seed)
 {
 /*