From: David van der Spoel Date: Sun, 19 Jan 2014 07:51:06 +0000 (+0100) Subject: Moved random number generator code to separate dir. X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=0a4f0948aa2b8a1f2132603836f1056bf0d17255;p=alexxy%2Fgromacs.git Moved random number generator code to separate dir. 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 --- diff --git a/src/gromacs/CMakeLists.txt b/src/gromacs/CMakeLists.txt index e85a17f87c..db60b5c88b 100644 --- a/src/gromacs/CMakeLists.txt +++ b/src/gromacs/CMakeLists.txt @@ -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) diff --git a/src/gromacs/gmxana/gmx_cluster.c b/src/gromacs/gmxana/gmx_cluster.c index 693fbe9dce..7f178abc0c 100644 --- a/src/gromacs/gmxana/gmx_cluster.c +++ b/src/gromacs/gmxana/gmx_cluster.c @@ -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" diff --git a/src/gromacs/gmxana/gmx_dipoles.cpp b/src/gromacs/gmxana/gmx_dipoles.cpp index 2d1094ff20..e07663490b 100644 --- a/src/gromacs/gmxana/gmx_dipoles.cpp +++ b/src/gromacs/gmxana/gmx_dipoles.cpp @@ -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" diff --git a/src/gromacs/gmxana/gmx_dyndom.c b/src/gromacs/gmxana/gmx_dyndom.c index 57bb3fc39e..e899ab122e 100644 --- a/src/gromacs/gmxana/gmx_dyndom.c +++ b/src/gromacs/gmxana/gmx_dyndom.c @@ -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" diff --git a/src/gromacs/gmxana/gmx_genbox.cpp b/src/gromacs/gmxana/gmx_genbox.cpp index 2ee5ea210c..ccc258883c 100644 --- a/src/gromacs/gmxana/gmx_genbox.cpp +++ b/src/gromacs/gmxana/gmx_genbox.cpp @@ -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 #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); diff --git a/src/gromacs/gmxana/gmx_genconf.c b/src/gromacs/gmxana/gmx_genconf.c index 524d2fe2cc..3e152220a1 100644 --- a/src/gromacs/gmxana/gmx_genconf.c +++ b/src/gromacs/gmxana/gmx_genconf.c @@ -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); diff --git a/src/gromacs/gmxana/gmx_genion.c b/src/gromacs/gmxana/gmx_genion.c index a0ffd88394..7eb317df38 100644 --- a/src/gromacs/gmxana/gmx_genion.c +++ b/src/gromacs/gmxana/gmx_genion.c @@ -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) diff --git a/src/gromacs/gmxana/gmx_nmens.c b/src/gromacs/gmxana/gmx_nmens.c index 0693572647..de293f16d2 100644 --- a/src/gromacs/gmxana/gmx_nmens.c +++ b/src/gromacs/gmxana/gmx_nmens.c @@ -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++) diff --git a/src/gromacs/gmxana/gmx_nmtraj.c b/src/gromacs/gmxana/gmx_nmtraj.c index f2011568e6..7995a9d6db 100644 --- a/src/gromacs/gmxana/gmx_nmtraj.c +++ b/src/gromacs/gmxana/gmx_nmtraj.c @@ -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" diff --git a/src/gromacs/gmxana/gmx_pme_error.cpp b/src/gromacs/gmxana/gmx_pme_error.cpp index 47a97b6d11..16d6f6740a 100644 --- a/src/gromacs/gmxana/gmx_pme_error.cpp +++ b/src/gromacs/gmxana/gmx_pme_error.cpp @@ -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" diff --git a/src/gromacs/gmxana/gmx_wham.cpp b/src/gromacs/gmxana/gmx_wham.cpp index d0c513bbca..e1bc36fba0 100644 --- a/src/gromacs/gmxana/gmx_wham.cpp +++ b/src/gromacs/gmxana/gmx_wham.cpp @@ -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 diff --git a/src/gromacs/gmxana/nrama.c b/src/gromacs/gmxana/nrama.c index 7983986f02..1f5568f800 100644 --- a/src/gromacs/gmxana/nrama.c +++ b/src/gromacs/gmxana/nrama.c @@ -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" diff --git a/src/gromacs/gmxana/nsfactor.c b/src/gromacs/gmxana/nsfactor.c index ea284971ea..f3a1107cb7 100644 --- a/src/gromacs/gmxana/nsfactor.c +++ b/src/gromacs/gmxana/nsfactor.c @@ -38,7 +38,7 @@ #include #include -#include "gmx_random.h" +#include "gromacs/random/random.h" #include "smalloc.h" #include "sysstuff.h" #include "vec.h" diff --git a/src/gromacs/gmxlib/sortwater.c b/src/gromacs/gmxana/sortwater.c similarity index 97% rename from src/gromacs/gmxlib/sortwater.c rename to src/gromacs/gmxana/sortwater.c index 6bd968fc41..0766d69bd9 100644 --- a/src/gromacs/gmxlib/sortwater.c +++ b/src/gromacs/gmxana/sortwater.c @@ -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; diff --git a/src/gromacs/legacyheaders/sortwater.h b/src/gromacs/gmxana/sortwater.h similarity index 94% rename from src/gromacs/legacyheaders/sortwater.h rename to src/gromacs/gmxana/sortwater.h index 6cdf8be65e..670e199334 100644 --- a/src/gromacs/legacyheaders/sortwater.h +++ b/src/gromacs/gmxana/sortwater.h @@ -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,13 +39,14 @@ #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 diff --git a/src/gromacs/gmxlib/checkpoint.c b/src/gromacs/gmxlib/checkpoint.c index 901bb1234a..209585f9d8 100644 --- a/src/gromacs/gmxlib/checkpoint.c +++ b/src/gromacs/gmxlib/checkpoint.c @@ -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" diff --git a/src/gromacs/gmxlib/copyrite.cpp b/src/gromacs/gmxlib/copyrite.cpp index 0b6271fe87..9ac9e6565c 100644 --- a/src/gromacs/gmxlib/copyrite.cpp +++ b/src/gromacs/gmxlib/copyrite.cpp @@ -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(nhlp*rando(&seed)); + rng = gmx_rng_init(gmx_rng_make_seed()); + *cqnum = static_cast(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 index c70359828c..0000000000 --- a/src/gromacs/gmxlib/rando.c +++ /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 -#endif - -#include -#ifdef GMX_NATIVE_WINDOWS -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#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; -} diff --git a/src/gromacs/gmxlib/random.c b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.c similarity index 93% rename from src/gromacs/gmxlib/random.c rename to src/gromacs/gmxpreprocess/gen_maxwell_velocities.c index 6da24f1344..d25a75a2d9 100644 --- a/src/gromacs/gmxlib/random.c +++ b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.c @@ -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. @@ -39,13 +39,13 @@ #endif #include +#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; diff --git a/src/gromacs/legacyheaders/random.h b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.h similarity index 74% rename from src/gromacs/legacyheaders/random.h rename to src/gromacs/gmxpreprocess/gen_maxwell_velocities.h index 7ebe45a402..9752ca71ce 100644 --- a/src/gromacs/legacyheaders/random.h +++ b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.h @@ -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" @@ -44,28 +44,30 @@ 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 diff --git a/src/gromacs/gmxpreprocess/grompp.c b/src/gromacs/gmxpreprocess/grompp.c index 1b88893558..7d867b4b5f 100644 --- a/src/gromacs/gmxpreprocess/grompp.c +++ b/src/gromacs/gmxpreprocess/grompp.c @@ -58,12 +58,13 @@ #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); } diff --git a/src/gromacs/gmxpreprocess/nm2type.c b/src/gromacs/gmxpreprocess/nm2type.c index 1ca88f2aab..8e1dac95d5 100644 --- a/src/gromacs/gmxpreprocess/nm2type.c +++ b/src/gromacs/gmxpreprocess/nm2type.c @@ -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" diff --git a/src/gromacs/gmxpreprocess/x2top.c b/src/gromacs/gmxpreprocess/x2top.c index d4f30ebe21..c5b75e99e4 100644 --- a/src/gromacs/gmxpreprocess/x2top.c +++ b/src/gromacs/gmxpreprocess/x2top.c @@ -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" diff --git a/src/gromacs/legacyheaders/update.h b/src/gromacs/legacyheaders/update.h index 9ebaeeaca5..5ccdd64eba 100644 --- a/src/gromacs/legacyheaders/update.h +++ b/src/gromacs/legacyheaders/update.h @@ -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" diff --git a/src/gromacs/mdlib/coupling.c b/src/gromacs/mdlib/coupling.c index 3d1190e401..282baf7a1a 100644 --- a/src/gromacs/mdlib/coupling.c +++ b/src/gromacs/mdlib/coupling.c @@ -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" diff --git a/src/gromacs/mdlib/domdec_top.c b/src/gromacs/mdlib/domdec_top.c index 15037b01c6..5f4b1cc9dc 100644 --- a/src/gromacs/mdlib/domdec_top.c +++ b/src/gromacs/mdlib/domdec_top.c @@ -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" diff --git a/src/gromacs/mdlib/expanded.c b/src/gromacs/mdlib/expanded.c index f49d30cf3a..2051f8795a 100644 --- a/src/gromacs/mdlib/expanded.c +++ b/src/gromacs/mdlib/expanded.c @@ -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" diff --git a/src/gromacs/mdlib/init.c b/src/gromacs/mdlib/init.c index f34326b069..99105bd6b8 100644 --- a/src/gromacs/mdlib/init.c +++ b/src/gromacs/mdlib/init.c @@ -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" diff --git a/src/gromacs/mdlib/minimize.c b/src/gromacs/mdlib/minimize.c index ed15e138ce..3f605e6808 100644 --- a/src/gromacs/mdlib/minimize.c +++ b/src/gromacs/mdlib/minimize.c @@ -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" diff --git a/src/gromacs/mdlib/partdec.c b/src/gromacs/mdlib/partdec.c index 6bd1f1818d..b45f021081 100644 --- a/src/gromacs/mdlib/partdec.c +++ b/src/gromacs/mdlib/partdec.c @@ -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" diff --git a/src/gromacs/mdlib/sim_util.c b/src/gromacs/mdlib/sim_util.c index a06fae500d..e5b968a873 100644 --- a/src/gromacs/mdlib/sim_util.c +++ b/src/gromacs/mdlib/sim_util.c @@ -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" diff --git a/src/gromacs/mdlib/tpi.c b/src/gromacs/mdlib/tpi.c index aa111f03df..190a6cf287 100644 --- a/src/gromacs/mdlib/tpi.c +++ b/src/gromacs/mdlib/tpi.c @@ -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,13 +50,11 @@ #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" diff --git a/src/gromacs/mdlib/update.c b/src/gromacs/mdlib/update.c index 249d1d2ecd..0b0e91bef8 100644 --- a/src/gromacs/mdlib/update.c +++ b/src/gromacs/mdlib/update.c @@ -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 index 0000000000..6fb36de7b3 --- /dev/null +++ b/src/gromacs/random/CMakeLists.txt @@ -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) diff --git a/src/gromacs/gmxlib/gmx_random.c b/src/gromacs/random/random.c similarity index 99% rename from src/gromacs/gmxlib/gmx_random.c rename to src/gromacs/random/random.c index 97c5304e13..19007cf4d5 100644 --- a/src/gromacs/gmxlib/gmx_random.c +++ b/src/gromacs/random/random.c @@ -38,7 +38,7 @@ #include #endif -#include "gmx_random.h" +#include "random.h" #include #include @@ -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 diff --git a/src/gromacs/legacyheaders/gmx_random.h b/src/gromacs/random/random.h similarity index 99% rename from src/gromacs/legacyheaders/gmx_random.h rename to src/gromacs/random/random.h index 8bfbf8b766..739aaf71c4 100644 --- a/src/gromacs/legacyheaders/gmx_random.h +++ b/src/gromacs/random/random.h @@ -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. diff --git a/src/gromacs/gmxlib/gmx_random_gausstable.h b/src/gromacs/random/random_gausstable.h similarity index 99% rename from src/gromacs/gmxlib/gmx_random_gausstable.h rename to src/gromacs/random/random_gausstable.h index 18a3cac6b1..9db0a0aef3 100644 --- a/src/gromacs/gmxlib/gmx_random_gausstable.h +++ b/src/gromacs/random/random_gausstable.h @@ -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. diff --git a/src/gromacs/selection/tests/nbsearch.cpp b/src/gromacs/selection/tests/nbsearch.cpp index eac05a6ea7..5c27be35ef 100644 --- a/src/gromacs/selection/tests/nbsearch.cpp +++ b/src/gromacs/selection/tests/nbsearch.cpp @@ -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 #include -#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" diff --git a/src/gromacs/statistics/statistics_test.c b/src/gromacs/statistics/statistics_test.c index 8e00049661..c5fee43be9 100644 --- a/src/gromacs/statistics/statistics_test.c +++ b/src/gromacs/statistics/statistics_test.c @@ -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() diff --git a/src/gromacs/tools/convert_tpr.c b/src/gromacs/tools/convert_tpr.c index e1cf09dcd1..423639082e 100644 --- a/src/gromacs/tools/convert_tpr.c +++ b/src/gromacs/tools/convert_tpr.c @@ -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); } diff --git a/src/gromacs/trajectoryanalysis/modules/freevolume.cpp b/src/gromacs/trajectoryanalysis/modules/freevolume.cpp index 54d933169a..a29cf181b2 100644 --- a/src/gromacs/trajectoryanalysis/modules/freevolume.cpp +++ b/src/gromacs/trajectoryanalysis/modules/freevolume.cpp @@ -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" diff --git a/src/programs/mdrun/repl_ex.c b/src/programs/mdrun/repl_ex.c index 786c55cae2..9f5ac5ff2c 100644 --- a/src/programs/mdrun/repl_ex.c +++ b/src/programs/mdrun/repl_ex.c @@ -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 #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];