Moved random number generator code to separate dir.
authorDavid van der Spoel <spoel@xray.bmc.uu.se>
Sun, 19 Jan 2014 07:51:06 +0000 (08:51 +0100)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 28 Jan 2014 21:43:40 +0000 (22:43 +0100)
GROMACS sports two random number generators for historical
reason. The oldest one is phased out in this patch.
Changing the random number
generator means that e.g. replica exchange simulations will
not be reproducible (if they ever were in practice).

Change-Id: If24f1019fba9b9412713b5fe04b5c0a8a7638468

42 files changed:
src/gromacs/CMakeLists.txt
src/gromacs/gmxana/gmx_cluster.c
src/gromacs/gmxana/gmx_dipoles.cpp
src/gromacs/gmxana/gmx_dyndom.c
src/gromacs/gmxana/gmx_genbox.cpp
src/gromacs/gmxana/gmx_genconf.c
src/gromacs/gmxana/gmx_genion.c
src/gromacs/gmxana/gmx_nmens.c
src/gromacs/gmxana/gmx_nmtraj.c
src/gromacs/gmxana/gmx_pme_error.cpp
src/gromacs/gmxana/gmx_wham.cpp
src/gromacs/gmxana/nrama.c
src/gromacs/gmxana/nsfactor.c
src/gromacs/gmxana/sortwater.c [moved from src/gromacs/gmxlib/sortwater.c with 97% similarity]
src/gromacs/gmxana/sortwater.h [moved from src/gromacs/legacyheaders/sortwater.h with 94% similarity]
src/gromacs/gmxlib/checkpoint.c
src/gromacs/gmxlib/copyrite.cpp
src/gromacs/gmxlib/rando.c [deleted file]
src/gromacs/gmxpreprocess/gen_maxwell_velocities.c [moved from src/gromacs/gmxlib/random.c with 93% similarity]
src/gromacs/gmxpreprocess/gen_maxwell_velocities.h [moved from src/gromacs/legacyheaders/random.h with 74% similarity]
src/gromacs/gmxpreprocess/grompp.c
src/gromacs/gmxpreprocess/nm2type.c
src/gromacs/gmxpreprocess/x2top.c
src/gromacs/legacyheaders/update.h
src/gromacs/mdlib/coupling.c
src/gromacs/mdlib/domdec_top.c
src/gromacs/mdlib/expanded.c
src/gromacs/mdlib/init.c
src/gromacs/mdlib/minimize.c
src/gromacs/mdlib/partdec.c
src/gromacs/mdlib/sim_util.c
src/gromacs/mdlib/tpi.c
src/gromacs/mdlib/update.c
src/gromacs/random/CMakeLists.txt [new file with mode: 0644]
src/gromacs/random/random.c [moved from src/gromacs/gmxlib/gmx_random.c with 99% similarity]
src/gromacs/random/random.h [moved from src/gromacs/legacyheaders/gmx_random.h with 99% similarity]
src/gromacs/random/random_gausstable.h [moved from src/gromacs/gmxlib/gmx_random_gausstable.h with 99% similarity]
src/gromacs/selection/tests/nbsearch.cpp
src/gromacs/statistics/statistics_test.c
src/gromacs/tools/convert_tpr.c
src/gromacs/trajectoryanalysis/modules/freevolume.cpp
src/programs/mdrun/repl_ex.c

index e85a17f87c894d76f5ed1fc3b0e026c4266f0239..db60b5c88bbbe1ad6dab1efd7852045b5c03846c 100644 (file)
@@ -52,6 +52,7 @@ add_subdirectory(commandline)
 add_subdirectory(fft)
 add_subdirectory(linearalgebra)
 add_subdirectory(math)
+add_subdirectory(random)
 add_subdirectory(onlinehelp)
 add_subdirectory(options)
 add_subdirectory(timing)
index 693fbe9dcea62160e195695df5a0d6a2582ce5d7..7f178abc0cf4d8052c23cde2aaa664496432e484 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -50,7 +50,7 @@
 #include "vec.h"
 #include "macros.h"
 #include "index.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "pbc.h"
 #include "rmpbc.h"
 #include "xvgr.h"
index 2d1094ff20ce741713b27df7fa38700bb3699f34..e07663490bec4a9cffc4eccc909249be3992d6b7 100644 (file)
@@ -55,7 +55,7 @@
 #include "gromacs/statistics/statistics.h"
 #include "gstat.h"
 #include "index.h"
-#include "random.h"
+#include "gromacs/random/random.h"
 #include "names.h"
 #include "physics.h"
 #include "calcmu.h"
index 57bb3fc39e64942ccee9d123041bd72ab54b0a41..e899ab122e817a5db74cd561a3f8478c5089551b 100644 (file)
@@ -46,7 +46,6 @@
 #include "gmx_fatal.h"
 #include "vec.h"
 #include "physics.h"
-#include "random.h"
 #include "gmx_ana.h"
 #include "macros.h"
 #include "gromacs/fileio/trxio.h"
index 2ee5ea210c3ba5bd7821ffa41eefb03b0b15c9b5..ccc258883c8ff0da3a7424c6fb73b78870aa5195 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -48,7 +48,7 @@
 #include "txtdump.h"
 #include <math.h>
 #include "macros.h"
-#include "random.h"
+#include "gromacs/random/random.h"
 #include "gromacs/fileio/futil.h"
 #include "atomprop.h"
 #include "names.h"
@@ -401,7 +401,9 @@ static char *insert_mols(const char *mol_insrt, int nmol_insrt, int ntry, int se
     rvec             offset_x;
     int              trial;
     double         **rpos;
+    gmx_rng_t        rng;
 
+    rng = gmx_rng_init(seed);
     set_pbc(&pbc, ePBC, box);
 
     /* read number of atoms of insert molecules */
@@ -459,13 +461,13 @@ static char *insert_mols(const char *mol_insrt, int nmol_insrt, int ntry, int se
         switch (enum_rot)
         {
             case en_rotXYZ:
-                alfa  = 2*M_PI *rando(&seed);
-                beta  = 2*M_PI *rando(&seed);
-                gamma = 2*M_PI *rando(&seed);
+                alfa  = 2*M_PI * gmx_rng_uniform_real(rng);
+                beta  = 2*M_PI * gmx_rng_uniform_real(rng);
+                gamma = 2*M_PI * gmx_rng_uniform_real(rng);
                 break;
             case en_rotZ:
                 alfa  = beta = 0.;
-                gamma = 2*M_PI*rando(&seed);
+                gamma = 2*M_PI * gmx_rng_uniform_real(rng);
                 break;
             case en_rotNone:
                 alfa = beta = gamma = 0.;
@@ -478,9 +480,9 @@ static char *insert_mols(const char *mol_insrt, int nmol_insrt, int ntry, int se
         if (posfn == NULL)
         {
             /* insert at random positions */
-            offset_x[XX] = box[XX][XX]*rando(&seed);
-            offset_x[YY] = box[YY][YY]*rando(&seed);
-            offset_x[ZZ] = box[ZZ][ZZ]*rando(&seed);
+            offset_x[XX] = box[XX][XX] * gmx_rng_uniform_real(rng);
+            offset_x[YY] = box[YY][YY] * gmx_rng_uniform_real(rng);
+            offset_x[ZZ] = box[ZZ][ZZ] * gmx_rng_uniform_real(rng);
             gen_box(0, atoms_insrt.nr, x_n, box_insrt, offset_x, TRUE);
             if (!in_box(&pbc, x_n[0]) || !in_box(&pbc, x_n[atoms_insrt.nr-1]))
             {
@@ -490,9 +492,9 @@ static char *insert_mols(const char *mol_insrt, int nmol_insrt, int ntry, int se
         else
         {
             /* Insert at positions taken from option -ip file */
-            offset_x[XX] = rpos[XX][mol] + deltaR[XX]*(2*rando(&seed)-1);
-            offset_x[YY] = rpos[YY][mol] + deltaR[YY]*(2*rando(&seed)-1);
-            offset_x[ZZ] = rpos[ZZ][mol] + deltaR[ZZ]*(2*rando(&seed)-1);
+            offset_x[XX] = rpos[XX][mol] + deltaR[XX]*(2 * gmx_rng_uniform_real(rng)-1);
+            offset_x[YY] = rpos[YY][mol] + deltaR[YY]*(2 * gmx_rng_uniform_real(rng)-1);
+            offset_x[ZZ] = rpos[ZZ][mol] + deltaR[ZZ]*(2 * gmx_rng_uniform_real(rng)-1);
             for (i = 0; i < atoms_insrt.nr; i++)
             {
                 rvec_inc(x_n[i], offset_x);
@@ -521,6 +523,7 @@ static char *insert_mols(const char *mol_insrt, int nmol_insrt, int ntry, int se
             fprintf(stderr, " success (now %d atoms)!\n", atoms->nr);
         }
     }
+    gmx_rng_destroy(rng);
     srenew(atoms->resinfo,  atoms->nres);
     srenew(atoms->atomname, atoms->nr);
     srenew(atoms->atom,     atoms->nr);
index 524d2fe2cccbb1dd664c432e7fe35f8c7e84a5cd..3e152220a16240326eb2a4d765b6f404d49d9560 100644 (file)
@@ -46,7 +46,7 @@
 #include "gromacs/fileio/confio.h"
 #include "gromacs/commandline/pargs.h"
 #include "vec.h"
-#include "random.h"
+#include "gromacs/random/random.h"
 #include "gromacs/math/3dview.h"
 #include "txtdump.h"
 #include "readinp.h"
@@ -56,7 +56,7 @@
 #include "gromacs/fileio/trxio.h"
 
 static void rand_rot(int natoms, rvec x[], rvec v[], vec4 xrot[], vec4 vrot[],
-                     int *seed, rvec max_rot)
+                     gmx_rng_t rng, rvec max_rot)
 {
     mat4 mt1, mt2, mr[DIM], mtemp1, mtemp2, mtemp3, mxtot, mvtot;
     rvec xcm;
@@ -76,7 +76,7 @@ static void rand_rot(int natoms, rvec x[], rvec v[], vec4 xrot[], vec4 vrot[],
     translate(-xcm[XX], -xcm[YY], -xcm[ZZ], mt1); /* move c.o.ma to origin */
     for (m = 0; (m < DIM); m++)
     {
-        phi = M_PI*max_rot[m]*(2*rando(seed) - 1)/180;
+        phi = M_PI*max_rot[m]*(2*gmx_rng_uniform_real(rng) - 1)/180;
         rotate(m, phi, mr[m]);
     }
     translate(xcm[XX], xcm[YY], xcm[ZZ], mt2);
@@ -159,6 +159,7 @@ int gmx_genconf(int argc, char *argv[])
     t_trxstatus    *status;
     gmx_bool        bTRX;
     output_env_t    oenv;
+    gmx_rng_t       rng;
 
     t_filenm        fnm[] = {
         { efSTX, "-f", "conf", ffREAD  },
@@ -199,9 +200,13 @@ int gmx_genconf(int argc, char *argv[])
         return 0;
     }
 
-    if (bRandom && (seed == 0))
+    if (seed == 0)
     {
-        seed = make_seed();
+        rng = gmx_rng_init(gmx_rng_make_seed());
+    }
+    else
+    {
+        rng = gmx_rng_init(seed);
     }
 
     bTRX = ftp2bSet(efTRX, NFILE, fnm);
@@ -272,7 +277,7 @@ int gmx_genconf(int argc, char *argv[])
                 /* Random rotation on input coords */
                 if (bRandom)
                 {
-                    rand_rot(natoms, xx, v, xrot, vrot, &seed, max_rot);
+                    rand_rot(natoms, xx, v, xrot, vrot, rng, max_rot);
                 }
 
                 for (l = 0; (l < natoms); l++)
@@ -362,7 +367,7 @@ int gmx_genconf(int argc, char *argv[])
 
     if (bShuffle)
     {
-        randwater(0, atoms->nr/nmolat, nmolat, x, v, &seed);
+        randwater(0, atoms->nr/nmolat, nmolat, x, v, rng);
     }
     else if (bSort)
     {
@@ -372,6 +377,7 @@ int gmx_genconf(int argc, char *argv[])
     {
         mkcompact(0, atoms->nr/nmolat, nmolat, x, v, nblock, box);
     }
+    gmx_rng_destroy(rng);
 
     write_sto_conf(opt2fn("-o", NFILE, fnm), title, atoms, x, v, ePBC, box);
 
index a0ffd883941c9f747579647fc05d97f099a42cff..7eb317df384ac2a907b45e535563813007723d7b 100644 (file)
@@ -54,7 +54,7 @@
 #include "gromacs/fileio/tpxio.h"
 #include "mdrun.h"
 #include "main.h"
-#include "random.h"
+#include "gromacs/random/random.h"
 #include "index.h"
 #include "mtop_util.h"
 #include "gmx_ana.h"
@@ -64,7 +64,7 @@ static void insert_ion(int nsa, int *nwater,
                        rvec x[], t_pbc *pbc,
                        int sign, int q, const char *ionname,
                        t_atoms *atoms,
-                       real rmin, int *seed)
+                       real rmin, gmx_rng_t rng)
 {
     int             i, ei, nw;
     real            rmin2;
@@ -78,7 +78,7 @@ static void insert_ion(int nsa, int *nwater,
 
     do
     {
-        ei = nw*rando(seed);
+        ei = nw*gmx_rng_uniform_real(rng);
         maxrand--;
     }
     while (bSet[ei] && (maxrand > 0));
@@ -395,6 +395,7 @@ int gmx_genion(int argc, char *argv[])
     gmx_bool          *bSet;
     int                i, nw, nwa, nsa, nsalt, iqtot;
     output_env_t       oenv;
+    gmx_rng_t          rng;
     t_filenm           fnm[] = {
         { efTPX, NULL,  NULL,      ffREAD  },
         { efNDX, NULL,  NULL,      ffOPTRD },
@@ -522,17 +523,26 @@ int gmx_genion(int argc, char *argv[])
 
     set_pbc(&pbc, ePBC, box);
 
+    if (seed == 0)
+    {
+        rng = gmx_rng_init(gmx_rng_make_seed());
+    }
+    else
+    {
+        rng = gmx_rng_init(seed);
+    }
     /* Now loop over the ions that have to be placed */
     while (p_num-- > 0)
     {
         insert_ion(nsa, &nw, bSet, repl, index, x, &pbc,
-                   1, p_q, p_name, &atoms, rmin, &seed);
+                   1, p_q, p_name, &atoms, rmin, rng);
     }
     while (n_num-- > 0)
     {
         insert_ion(nsa, &nw, bSet, repl, index, x, &pbc,
-                   -1, n_q, n_name, &atoms, rmin, &seed);
+                   -1, n_q, n_name, &atoms, rmin, rng);
     }
+    gmx_rng_destroy(rng);
     fprintf(stderr, "\n");
 
     if (nw)
index 0693572647d8f1bd33feac8d1c4b3d770d692d46..de293f16d23c8b5b3624ead10eb1cc1c3865ad9b 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -55,7 +55,7 @@
 #include "gromacs/fileio/trxio.h"
 #include "txtdump.h"
 #include "physics.h"
-#include "random.h"
+#include "gromacs/random/random.h"
 #include "eigio.h"
 #include "gmx_ana.h"
 
@@ -107,7 +107,7 @@ int gmx_nmens(int argc, char *argv[])
     real                rfac, invfr, rhalf, jr;
     int          *      eigvalnr;
     output_env_t        oenv;
-
+    gmx_rng_t           rng;
     unsigned long       jran;
     const unsigned long im = 0xffff;
     const unsigned long ia = 1093;
@@ -217,14 +217,20 @@ int gmx_nmens(int argc, char *argv[])
 
     if (seed == -1)
     {
-        seed = make_seed();
+        seed = (int)gmx_rng_make_seed();
+        rng  = gmx_rng_init(seed);
+    }
+    else
+    {
+        rng = gmx_rng_init(seed);
     }
     fprintf(stderr, "Using seed %d and a temperature of %g K\n", seed, temp);
 
     snew(xout1, natoms);
     snew(xout2, atoms->nr);
     out  = open_trx(ftp2fn(efTRO, NFILE, fnm), "w");
-    jran = (unsigned long)((real)im*rando(&seed));
+    jran = (unsigned long)((real)im*gmx_rng_uniform_real(rng));
+    gmx_rng_destroy(rng);
     for (s = 0; s < nstruct; s++)
     {
         for (i = 0; i < natoms; i++)
index f2011568e66ccd31ed96ba8b184e8a9652d4e9e7..7995a9d6dbaed4df7a72a77271f0972475a1c233 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -55,7 +55,6 @@
 #include "gromacs/fileio/trxio.h"
 #include "txtdump.h"
 #include "physics.h"
-#include "random.h"
 #include "eigio.h"
 #include "gmx_ana.h"
 
index 47a97b6d11593cfa703e0569db4cbdb60f32c892..16d6f6740a2e56213c5523d1f1118f6b80c71807 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -45,7 +45,7 @@
 #include "calcgrid.h"
 #include "checkpoint.h"
 #include "gmx_ana.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "physics.h"
 #include "mdatoms.h"
 #include "coulomb.h"
index d0c513bbca699fada7c96bf0dd181e6c5c46c8ae..e1bc36fba01bff7dfad2309f02ef48bf32321a30 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -55,7 +55,7 @@
 #include "copyrite.h"
 #include "gromacs/fileio/tpxio.h"
 #include "names.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "gmx_ana.h"
 #include "macros.h"
 
@@ -111,14 +111,14 @@ typedef struct
      * \name Using umbrella pull code since gromacs 4.x
      */
     /*!\{*/
-    int   npullcrds;     //!< nr of pull coordinates in tpr file
-    int   pull_geometry; //!< such as distance, direction
-    ivec  pull_dim;      //!< pull dimension with geometry distance
-    int   pull_ndim;     //!< nr of pull_dim != 0
-    gmx_bool bPrintRef;  //!< Coordinates of reference groups written to pullx.xvg ?
-    real *k;             //!< force constants in tpr file
-    real *init_dist;     //!< reference displacements
-    real *umbInitDist;   //!< reference displacement in umbrella direction
+    int      npullcrds;     //!< nr of pull coordinates in tpr file
+    int      pull_geometry; //!< such as distance, direction
+    ivec     pull_dim;      //!< pull dimension with geometry distance
+    int      pull_ndim;     //!< nr of pull_dim != 0
+    gmx_bool bPrintRef;     //!< Coordinates of reference groups written to pullx.xvg ?
+    real    *k;             //!< force constants in tpr file
+    real    *init_dist;     //!< reference displacements
+    real    *umbInitDist;   //!< reference displacement in umbrella direction
     /*!\}*/
     /*!
      * \name Using PDO files common until gromacs 3.x
index 7983986f02453214449f5a214f8ebc308aee1814..1f5568f800431e9acbad8c98a0ccbab39db7075a 100644 (file)
@@ -44,7 +44,6 @@
 #include "smalloc.h"
 #include "string2.h"
 #include "typedefs.h"
-#include "random.h"
 #include "bondf.h"
 #include "gromacs/fileio/futil.h"
 #include "gmx_fatal.h"
index ea284971eabb07953907ac825cd228ff97821a1c..f3a1107cb7bc45d90dd3d3ccfea7aa66cd446813 100644 (file)
@@ -38,7 +38,7 @@
 
 #include <ctype.h>
 #include <string.h>
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "smalloc.h"
 #include "sysstuff.h"
 #include "vec.h"
similarity index 97%
rename from src/gromacs/gmxlib/sortwater.c
rename to src/gromacs/gmxana/sortwater.c
index 6bd968fc414668346c1261ba80c05286f22724d9..0766d69bd9fe140ab686c036a33b5ee10cce2e81 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2010, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -39,7 +39,7 @@
 #endif
 
 #include "typedefs.h"
-#include "random.h"
+#include "gromacs/random/random.h"
 #include "smalloc.h"
 #include "vec.h"
 #include "sortwater.h"
@@ -49,7 +49,8 @@ static int     nwat;
 static matrix  BOX;
 static ivec    NBOX;
 
-void randwater(int astart, int nwater, int nwatom, rvec x[], rvec v[], int *seed)
+void randwater(int astart, int nwater, int nwatom, rvec x[], rvec v[],
+               gmx_rng_t rng)
 {
     int  i, j, wi, wj, *tab;
     rvec buf;
@@ -61,10 +62,10 @@ void randwater(int astart, int nwater, int nwatom, rvec x[], rvec v[], int *seed
     }
     for (j = 0; (j < 23*nwater); j++)
     {
-        wi = (int) (nwater*rando(seed)) % nwater;
+        wi = (int) (nwater*gmx_rng_uniform_real(rng)) % nwater;
         do
         {
-            wj = (int) (nwater*rando(seed)) % nwater;
+            wj = (int) (nwater*gmx_rng_uniform_real(rng)) % nwater;
         }
         while (wi == wj);
         wi = astart+wi*nwatom;
similarity index 94%
rename from src/gromacs/legacyheaders/sortwater.h
rename to src/gromacs/gmxana/sortwater.h
index 6cdf8be65e6726d437772ddac8e008ce9bf05fca..670e199334c9d14fae5a5fdd681a1dc243d551c4 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2010, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #define _sortwater_h
 
 #include "typedefs.h"
+#include "gromacs/random/random.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 void randwater(int astart, int nwater, int nwatom,
-               rvec x[], rvec v[], int *seed);
+               rvec x[], rvec v[], gmx_rng_t rng);
 /* Randomize the order of nwater molecules of length nwatom, the
  * first atom of which is at astart.
  * If v is not NULL it will be shuffled along
index 901bb1234a3d49175bcc5c1006b10ad1c24c7781..209585f9d828b51f2871d1deaea16c61dc1325c2 100644 (file)
@@ -65,7 +65,7 @@
 #include "txtdump.h"
 #include "vec.h"
 #include "network.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "checkpoint.h"
 #include "main.h"
 #include "string2.h"
index 0b6271fe87dada6efff6d93303d818ada1959df7..9ac9e6565c37dcdab623c735ae32360a6004dc53 100644 (file)
@@ -54,7 +54,7 @@
 /* This file is completely threadsafe - keep it that way! */
 
 #include "gromacs/legacyheaders/macros.h"
-#include "gromacs/legacyheaders/random.h"
+#include "gromacs/random/random.h"
 #include "gromacs/legacyheaders/smalloc.h"
 #include "gromacs/legacyheaders/string2.h"
 #include "gromacs/legacyheaders/vec.h"
@@ -85,18 +85,19 @@ static gmx_bool be_cool(void)
 static void pukeit(const char *db, const char *defstring, char *retstring,
                    int retsize, int *cqnum)
 {
-    FILE  *fp;
-    char **help;
-    int    i, nhlp;
-    int    seed;
+    FILE     *fp;
+    char    **help;
+    int       i, nhlp;
+    gmx_rng_t rng;
 
     if (be_cool() && ((fp = low_libopen(db, FALSE)) != NULL))
     {
         nhlp = fget_lines(fp, &help);
         /* for libraries we can use the low-level close routines */
         ffclose(fp);
-        seed   = time(NULL);
-        *cqnum = static_cast<int>(nhlp*rando(&seed));
+        rng    = gmx_rng_init(gmx_rng_make_seed());
+        *cqnum = static_cast<int>(nhlp*gmx_rng_uniform_real(rng));
+        gmx_rng_destroy(rng);
         if (strlen(help[*cqnum]) >= STRLEN)
         {
             help[*cqnum][STRLEN-1] = '\0';
diff --git a/src/gromacs/gmxlib/rando.c b/src/gromacs/gmxlib/rando.c
deleted file mode 100644 (file)
index c703598..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <time.h>
-#ifdef GMX_NATIVE_WINDOWS
-#include <process.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include "sysstuff.h"
-#include "typedefs.h"
-#include "random.h"
-
-int make_seed(void)
-{
-#ifdef GMX_NATIVE_WINDOWS
-    return (int)_getpid();
-#else
-    return (int)getpid();
-#endif
-}
-
-real rando(int *ig)
-/* generate a random number. */
-{
-    int  irand;
-
-    int  m    = 100000000;
-    real rm   = 100000000.0; /* same number as m, but real format */
-    int  m1   = 10000;
-    int  mult = 31415821;
-
-    real r;
-    int  irandh, irandl, multh, multl;
-
-    irand = abs(*ig) % m;
-
-    /* multiply irand by mult, but take into account that overflow
-     * must be discarded, and do not generate an error.
-     */
-    irandh = irand / m1;
-    irandl = irand % m1;
-    multh  = mult / m1;
-    multl  = mult % m1;
-    irand  = ((irandh*multl+irandl*multh) % m1) * m1 + irandl*multl;
-    irand  = (irand + 1) % m;
-
-    /* convert irand to a real random number between 0 and 1. */
-    r = (irand / 10);
-    r = r * 10 / rm;
-    if ((r <= 0) || (r > 1))
-    {
-        r = 0.0;
-    }
-    *ig = irand;
-
-    return r;
-}
similarity index 93%
rename from src/gromacs/gmxlib/random.c
rename to src/gromacs/gmxpreprocess/gen_maxwell_velocities.c
index 6da24f13442d87c191aa25edaafa3d05bf81c0da..d25a75a2d95f02e901b82f2fec0b07fa938d0d0b 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #endif
 
 #include <math.h>
+#include "gromacs/random/random.h"
 #include "sysstuff.h"
 #include "smalloc.h"
 #include "physics.h"
 #include "typedefs.h"
 #include "vec.h"
-#include "gmx_random.h"
-#include "random.h"
+#include "gen_maxwell_velocities.h"
 #include "mtop_util.h"
 
 static void low_mspeed(real tempi,
@@ -98,15 +98,15 @@ static void low_mspeed(real tempi,
     }
 }
 
-void maxwell_speed(real tempi, int seed, gmx_mtop_t *mtop, rvec v[])
+void maxwell_speed(real tempi, unsigned int seed, gmx_mtop_t *mtop, rvec v[])
 {
     atom_id  *dummy;
     int       i;
     gmx_rng_t rng;
 
-    if (seed == -1)
+    if (seed == 0)
     {
-        seed = make_seed();
+        seed = gmx_rng_make_seed();
         fprintf(stderr, "Using random seed %d for generating velocities\n", seed);
     }
 
@@ -117,8 +117,8 @@ void maxwell_speed(real tempi, int seed, gmx_mtop_t *mtop, rvec v[])
     gmx_rng_destroy(rng);
 }
 
-real calc_cm(int natoms, real mass[], rvec x[], rvec v[],
-             rvec xcm, rvec vcm, rvec acm, matrix L)
+static real calc_cm(int natoms, real mass[], rvec x[], rvec v[],
+                    rvec xcm, rvec vcm, rvec acm, matrix L)
 {
     rvec dx, a0;
     real tm, m0;
similarity index 74%
rename from src/gromacs/legacyheaders/random.h
rename to src/gromacs/gmxpreprocess/gen_maxwell_velocities.h
index 7ebe45a40263cc29e81a7ba5dd4e19f2fd171234..9752ca71ce65c42597b70a1b9240a707cb0c9766 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -35,8 +35,8 @@
  * the research papers on the package. Check out http://www.gromacs.org.
  */
 
-#ifndef _random_h
-#define _random_h
+#ifndef GMX_MAXWELL_VELOCITIES
+#define GMX_MAXWELL_VELOCITIES
 
 #include "typedefs.h"
 
 extern "C" {
 #endif
 
-int make_seed(void);
-/* Make a random seed: (time+getpid) % 1000000 */
-
-real rando(int *seed);
-/* Generate a random number 0 <= r < 1. seed is the (address of) the
- * random seed variable.
+/*! \brief
+ * Generate Maxwellian velocities.
+ *
+ * \param[in] tempi Temperature to generate around
+ * \param[in] seed  Random number generator seed
+ * \param[in] mtop  Molecular Topology
+ * \param[out] v    Velocities
  */
-
-void maxwell_speed(real tempi, int seed,
+void maxwell_speed(real tempi, unsigned int seed,
                    gmx_mtop_t *mtop, rvec v[]);
-/* Generate velocites according to a maxwellian distribution */
 
-real calc_cm(int natoms, real mass[], rvec x[], rvec v[],
-             rvec xcm, rvec vcm, rvec acm, matrix L);
-/* Calculate the c.o.m. position, velocity, acceleration and the
- * moment of Inertia. Returns the total mass.
+/*! \brief
+ * Remove the center of mass motion in a set of coordinates.
+ *
+ * \param[out] log  File for printing debug information
+ * \param[in]  natoms Number of atoms
+ * \param[in]  mass   Atomic masses
+ * \param[in]  x      Coordinates
+ * \param[out] v      Velocities
  */
-
 void stop_cm(FILE *log, int natoms, real mass[], rvec x[], rvec v[]);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif  /* _random_h */
+#endif
index 1b8889355874bc08cce258a1225f5792f9dc9c6d..7d867b4b5f9a2fb0f1432a1e06286ff00a3af842 100644 (file)
 #include "symtab.h"
 #include "names.h"
 #include "grompp-impl.h"
-#include "random.h"
+#include "gromacs/random/random.h"
+#include "gromacs/gmxpreprocess/gen_maxwell_velocities.h"
 #include "vec.h"
 #include "gromacs/fileio/futil.h"
 #include "gromacs/commandline/pargs.h"
 #include "splitter.h"
-#include "sortwater.h"
+#include "gromacs/gmxana/sortwater.h"
 #include "convparm.h"
 #include "gmx_fatal.h"
 #include "warninp.h"
@@ -601,6 +602,7 @@ new_status(const char *topfile, const char *topppfile, const char *confin,
         real                   *mass;
         gmx_mtop_atomloop_all_t aloop;
         t_atom                 *atom;
+        unsigned int            useed;
 
         snew(mass, state->natoms);
         aloop = gmx_mtop_atomloop_all_init(sys);
@@ -609,12 +611,13 @@ new_status(const char *topfile, const char *topppfile, const char *confin,
             mass[i] = atom->m;
         }
 
+        useed = opts->seed;
         if (opts->seed == -1)
         {
-            opts->seed = make_seed();
-            fprintf(stderr, "Setting gen_seed to %d\n", opts->seed);
+            useed = (int)gmx_rng_make_seed();
+            fprintf(stderr, "Setting gen_seed to %u\n", useed);
         }
-        maxwell_speed(opts->tempi, opts->seed, sys, state->v);
+        maxwell_speed(opts->tempi, useed, sys, state->v);
 
         stop_cm(stdout, state->natoms, mass, state->x, state->v);
         sfree(mass);
@@ -1445,6 +1448,7 @@ int gmx_grompp(int argc, char *argv[])
     gmx_bool           bVerbose = FALSE;
     warninp_t          wi;
     char               warn_buf[STRLEN];
+    unsigned int       useed;
 
     t_filenm           fnm[] = {
         { efMDP, NULL,  NULL,        ffREAD  },
@@ -1509,13 +1513,13 @@ int gmx_grompp(int argc, char *argv[])
 
     if (ir->ld_seed == -1)
     {
-        ir->ld_seed = make_seed();
+        ir->ld_seed = (int)gmx_rng_make_seed();
         fprintf(stderr, "Setting the LD random seed to %d\n", ir->ld_seed);
     }
 
     if (ir->expandedvals->lmc_seed == -1)
     {
-        ir->expandedvals->lmc_seed = make_seed();
+        ir->expandedvals->lmc_seed = (int)gmx_rng_make_seed();
         fprintf(stderr, "Setting the lambda MC random seed to %d\n", ir->expandedvals->lmc_seed);
     }
 
index 1ca88f2aabac8510b95469666cf0ce11b2fe9fab..8e1dac95d581c921720235c94d6f476d5cd5211a 100644 (file)
@@ -48,7 +48,6 @@
 #include "gromacs/fileio/confio.h"
 #include "physics.h"
 #include "vec.h"
-#include "random.h"
 #include "gromacs/math/3dview.h"
 #include "txtdump.h"
 #include "readinp.h"
index d4f30ebe21da0293568df6c9e6d57a15f7e7b807..c5b75e99e42c10c45f5032007719c25765c602da 100644 (file)
@@ -52,7 +52,6 @@
 #include "physics.h"
 #include "gromacs/commandline/pargs.h"
 #include "vec.h"
-#include "random.h"
 #include "gromacs/math/3dview.h"
 #include "txtdump.h"
 #include "readinp.h"
index 9ebaeeaca52e0814354f7d6a448cac9a8abbe4a4..5ccdd64eba1192f9c840f9d89f221068678fbb89 100644 (file)
@@ -42,7 +42,7 @@
 #include "mshift.h"
 #include "tgroup.h"
 #include "network.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "vec.h"
 
 
index 3d1190e401e6a87a33f0edd9add447de043c59a7..282baf7a1aa09e7875f39667199a4be8503c49cf 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -49,7 +49,7 @@
 #include "gmx_fatal.h"
 #include "txtdump.h"
 #include "nrnb.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "update.h"
 #include "mdrun.h"
 
index 15037b01c629e68c8824f39eb2041136fb6474e9..5f4b1cc9dc8fdd9e5f9e5f27857bf935d763e1e2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2006,2007,2008,2009,2010,2011,2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2006,2007,2008,2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -47,7 +47,7 @@
 #include "vec.h"
 #include "pbc.h"
 #include "chargegroup.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "gromacs/gmxlib/topsort.h"
 #include "mtop_util.h"
 #include "mshift.h"
index f49d30cf3a53c1438d3e8b569211aa663dad03fa..2051f8795af04242afe6b6b9ee00dbd4be9fe0bd 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -63,7 +63,7 @@
 #include "calcmu.h"
 #include "constr.h"
 #include "xvgr.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "domdec.h"
 #include "partdec.h"
 #include "macros.h"
index f34326b069a21f6875c7b7880ef608fc547c5454..99105bd6b8fe469878e04a1a4b4c33862ad4b15d 100644 (file)
@@ -52,7 +52,7 @@
 #include "mdrun.h"
 #include "names.h"
 #include "calcgrid.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "update.h"
 #include "mdebin.h"
 
index ed15e138ce0bfa670fe9f7b24976ef544f03152b..3f605e6808aaa564d8b353e334a7284c6740ad75 100644 (file)
@@ -49,7 +49,7 @@
 #include "main.h"
 #include "force.h"
 #include "macros.h"
-#include "random.h"
+#include "gromacs/random/random.h"
 #include "names.h"
 #include "gmx_fatal.h"
 #include "txtdump.h"
index 6bd1f1818d6b226c4c3d6d0c64216a493d4f3806..b45f02108129b1f45bbc8af704fcc4d7b6a7455c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -50,7 +50,7 @@
 #include "ns.h"
 #include "partdec.h"
 #include "splitter.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "mtop_util.h"
 #include "mvdata.h"
 #include "vec.h"
index a06fae500db41631d1317db9fd62a16f6747c625..e5b968a8735ce30fe7cd9697cff12ab8f649074c 100644 (file)
@@ -70,7 +70,7 @@
 #include "constr.h"
 #include "xvgr.h"
 #include "copyrite.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "domdec.h"
 #include "partdec.h"
 #include "genborn.h"
index aa111f03df02cadd3654b9c4986327d40e12b951..190a6cf287461451f4784f18616861c31f5de406 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "chargegroup.h"
 #include "force.h"
 #include "macros.h"
-#include "random.h"
 #include "names.h"
 #include "gmx_fatal.h"
 #include "txtdump.h"
 #include "typedefs.h"
 #include "update.h"
-#include "random.h"
 #include "constr.h"
 #include "vec.h"
 #include "tgroup.h"
@@ -66,7 +64,7 @@
 #include "mdrun.h"
 #include "domdec.h"
 #include "partdec.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "physics.h"
 #include "xvgr.h"
 #include "mdatoms.h"
index 249d1d2ecd204a45e1acdb9124d3ccc9aaa1c0b6..0b0e91bef8cda3fc0f6c9c6e3f199afb6aa96ea7 100644 (file)
@@ -52,7 +52,7 @@
 #include "vec.h"
 #include "main.h"
 #include "update.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "mshift.h"
 #include "tgroup.h"
 #include "force.h"
diff --git a/src/gromacs/random/CMakeLists.txt b/src/gromacs/random/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6fb36de
--- /dev/null
@@ -0,0 +1,36 @@
+#
+# This file is part of the GROMACS molecular simulation package.
+#
+# Copyright (c) 2014, by the GROMACS development team, led by
+# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+# and including many others, as listed in the AUTHORS file in the
+# top-level source directory and at http://www.gromacs.org.
+#
+# GROMACS is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 2.1
+# of the License, or (at your option) any later version.
+#
+# GROMACS is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with GROMACS; if not, see
+# http://www.gnu.org/licenses, or write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+#
+# If you want to redistribute modifications to GROMACS, please
+# consider that scientific software is very special. Version
+# control is crucial - bugs must be traceable. We will be happy to
+# consider code for inclusion in the official distribution, but
+# derived work must not be called official GROMACS. Details are found
+# in the README & COPYING files - if they are missing, get the
+# official version at http://www.gromacs.org.
+#
+# To help us fund GROMACS development, we humbly ask that you cite
+# the research papers on the package. Check out http://www.gromacs.org.
+
+file(GLOB RANDOM_SOURCES *.c)
+set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${RANDOM_SOURCES} PARENT_SCOPE)
similarity index 99%
rename from src/gromacs/gmxlib/gmx_random.c
rename to src/gromacs/random/random.c
index 97c5304e131ba88323c575e8f3ffd04c891bad9f..19007cf4d52b69d323d2f64a047c2e8a78e7025a 100644 (file)
@@ -38,7 +38,7 @@
 #include <config.h>
 #endif
 
-#include "gmx_random.h"
+#include "random.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -52,7 +52,7 @@
 #endif
 
 #include "gromacs/math/utilities.h"
-#include "gmx_random_gausstable.h"
+#include "random_gausstable.h"
 
 #define RNG_N 624
 #define RNG_M 397
similarity index 99%
rename from src/gromacs/legacyheaders/gmx_random.h
rename to src/gromacs/random/random.h
index 8bfbf8b7660d859815831fa629b192db9bfc17b7..739aaf71c412c756714c31b72c0354292db4744d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2010, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
similarity index 99%
rename from src/gromacs/gmxlib/gmx_random_gausstable.h
rename to src/gromacs/random/random_gausstable.h
index 18a3cac6b1b31e6a52eeb7392088869c15c135b1..9db0a0aef3354b710434956c63e270c745166f48 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2004, by the GROMACS development team, led by
+ * Copyright (c) 2004,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
index eac05a6ea75d6fd12cb08d702c89500038b63552..5c27be35efea30abc8c59eb4be60764493dae9f3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -52,7 +52,7 @@
 #include <set>
 #include <vector>
 
-#include "gromacs/legacyheaders/gmx_random.h"
+#include "gromacs/random/random.h"
 #include "gromacs/legacyheaders/pbc.h"
 #include "gromacs/legacyheaders/smalloc.h"
 #include "gromacs/legacyheaders/vec.h"
index 8e00049661c25725f37013e75a6f093de09fbe77..c5fee43be9f429a4a3b789b897c317cc70d8ce52 100644 (file)
@@ -42,7 +42,7 @@
 #include "typedefs.h"
 #include "smalloc.h"
 #include "vec.h"
-#include "gmx_random.h"
+#include "gromacs/random/random.h"
 #include "statistics.h"
 
 static void horizontal()
index e1cf09dcd1dd3dbde18342b457b3b578d1c14eb4..423639082eeec55e5b2b070ad49a6fa58974a011 100644 (file)
@@ -51,7 +51,7 @@
 #include "gromacs/commandline/pargs.h"
 #include "vec.h"
 #include "mtop_util.h"
-#include "random.h"
+#include "gromacs/random/random.h"
 #include "checkpoint.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trnio.h"
@@ -467,7 +467,7 @@ int gmx_convert_tpr(int argc, char *argv[])
         if (EI_SD(ir->eI) || ir->eI == eiBD)
         {
             fprintf(stderr, "\nChanging ld-seed from %d ", ir->ld_seed);
-            ir->ld_seed = make_seed();
+            ir->ld_seed = (int)gmx_rng_make_seed();
             fprintf(stderr, "to %d\n\n", ir->ld_seed);
         }
 
index 54d933169ab18da77e84061fc697edff09713f4d..a29cf181b299e0c211b76993ef6d48f645087d01 100644 (file)
@@ -45,7 +45,7 @@
 
 #include "gromacs/legacyheaders/atomprop.h"
 #include "gromacs/legacyheaders/copyrite.h"
-#include "gromacs/legacyheaders/gmx_random.h"
+#include "gromacs/random/random.h"
 #include "gromacs/legacyheaders/pbc.h"
 #include "gromacs/legacyheaders/vec.h"
 
index 786c55cae28becbb01e7bbbeeef7e4901a77a0bf..9f5ac5ff2cb996b0d5a6f656ed2e50dfe1e6e416 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2011,2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -41,7 +41,7 @@
 #include <math.h>
 #include "repl_ex.h"
 #include "network.h"
-#include "random.h"
+#include "gromacs/random/random.h"
 #include "smalloc.h"
 #include "physics.h"
 #include "copyrite.h"
@@ -66,22 +66,23 @@ const char *erename[ereNR] = { "temperature", "lambda", "end_single_marker", "te
 
 typedef struct gmx_repl_ex
 {
-    int      repl;
-    int      nrepl;
-    real     temp;
-    int      type;
-    real   **q;
-    gmx_bool bNPT;
-    real    *pres;
-    int     *ind;
-    int     *allswaps;
-    int      nst;
-    int      nex;
-    int      seed;
-    int      nattempt[2];
-    real    *prob_sum;
-    int    **nmoves;
-    int     *nexchange;
+    int       repl;
+    int       nrepl;
+    real      temp;
+    int       type;
+    real    **q;
+    gmx_bool  bNPT;
+    real     *pres;
+    int      *ind;
+    int      *allswaps;
+    int       nst;
+    int       nex;
+    int       seed;
+    int       nattempt[2];
+    real     *prob_sum;
+    int     **nmoves;
+    int      *nexchange;
+    gmx_rng_t rng;
 
     /* these are helper arrays for replica exchange; allocated here so they
        don't have to be allocated each time */
@@ -340,7 +341,7 @@ gmx_repl_ex_t init_replica_exchange(FILE *fplog,
     {
         if (MASTERSIM(ms))
         {
-            re->seed = make_seed();
+            re->seed = (int)gmx_rng_make_seed();
         }
         else
         {
@@ -354,6 +355,7 @@ gmx_repl_ex_t init_replica_exchange(FILE *fplog,
     }
     fprintf(fplog, "\nReplica exchange interval: %d\n", re->nst);
     fprintf(fplog, "\nReplica random seed: %d\n", re->seed);
+    re->rng = gmx_rng_init(re->seed);
 
     re->nattempt[0] = 0;
     re->nattempt[1] = 0;
@@ -901,6 +903,7 @@ test_for_replica_exchange(FILE                 *fplog,
     gmx_bool  bEpot    = FALSE;
     gmx_bool  bDLambda = FALSE;
     gmx_bool  bVol     = FALSE;
+    gmx_rng_t rng;
 
     bMultiEx = (re->nex > 1);  /* multiple exchanges at each state */
     fprintf(fplog, "Replica exchange at step " "%"GMX_PRId64 " time %g\n", step, time);
@@ -987,8 +990,8 @@ test_for_replica_exchange(FILE                 *fplog,
                probability of occurring (log p > -100) and only operate on those switches */
             /* find out which state it is from, and what label that state currently has. Likely
                more work that useful. */
-            i0 = (int)(re->nrepl*rando(&(re->seed)));
-            i1 = (int)(re->nrepl*rando(&(re->seed)));
+            i0 = (int)(re->nrepl*gmx_rng_uniform_real(re->rng));
+            i1 = (int)(re->nrepl*gmx_rng_uniform_real(re->rng));
             if (i0 == i1)
             {
                 i--;
@@ -1027,7 +1030,7 @@ test_for_replica_exchange(FILE                 *fplog,
                     prob[0] = exp(-delta);
                 }
                 /* roll a number to determine if accepted */
-                bEx[0] = (rando(&(re->seed)) < prob[0]);
+                bEx[0] = (gmx_rng_uniform_real(re->rng) < prob[0]);
             }
             re->prob_sum[0] += prob[0];
 
@@ -1072,7 +1075,7 @@ test_for_replica_exchange(FILE                 *fplog,
                         prob[i] = exp(-delta);
                     }
                     /* roll a number to determine if accepted */
-                    bEx[i] = (rando(&(re->seed)) < prob[i]);
+                    bEx[i] = (gmx_rng_uniform_real(re->rng) < prob[i]);
                 }
                 re->prob_sum[i] += prob[i];