Beispiel #1
0
static real vrescale_sumnoises(int nn,gmx_rng_t rng)
{
/*
 * Returns the sum of n independent gaussian noises squared
 * (i.e. equivalent to summing the square of the return values
 * of nn calls to gmx_rng_gaussian_real).xs
 */
  real rr;

  if (nn == 0) {
    return 0.0;
  } else if (nn == 1) {
    rr = gmx_rng_gaussian_real(rng);
    return rr*rr;
  } else if (nn % 2 == 0) {
    return 2.0*vrescale_gamdev(nn/2,rng);
  } else {
    rr = gmx_rng_gaussian_real(rng);
    return 2.0*vrescale_gamdev((nn-1)/2,rng) + rr*rr;
  }
}
static void low_mspeed(real tempi,
                       gmx_mtop_t *mtop, rvec v[], gmx_rng_t rng)
{
    int                     i, m, nrdf;
    real                    boltz, sd;
    real                    ekin, temp, mass, scal;
    gmx_mtop_atomloop_all_t aloop;
    t_atom                 *atom;

    boltz = BOLTZ*tempi;
    ekin  = 0.0;
    nrdf  = 0;
    aloop = gmx_mtop_atomloop_all_init(mtop);
    while (gmx_mtop_atomloop_all_next(aloop, &i, &atom))
    {
        mass = atom->m;
        if (mass > 0)
        {
            sd = sqrt(boltz/mass);
            for (m = 0; (m < DIM); m++)
            {
                v[i][m] = sd*gmx_rng_gaussian_real(rng);
                ekin   += 0.5*mass*v[i][m]*v[i][m];
            }
            nrdf += DIM;
        }
    }
    temp = (2.0*ekin)/(nrdf*BOLTZ);
    if (temp > 0)
    {
        scal = sqrt(tempi/temp);
        for (i = 0; (i < mtop->natoms); i++)
        {
            for (m = 0; (m < DIM); m++)
            {
                v[i][m] *= scal;
            }
        }
    }
    fprintf(stderr, "Velocities were taken from a Maxwell distribution at %g K\n",
            tempi);
    if (debug)
    {
        fprintf(debug,
                "Velocities were taken from a Maxwell distribution\n"
                "Initial generated temperature: %12.5e (scaled to: %12.5e)\n",
                temp, tempi);
    }
}
Beispiel #3
0
static real vrescale_resamplekin(real kk,real sigma, int ndeg, real taut,
				 gmx_rng_t rng)
{
/*
 * Generates a new value for the kinetic energy,
 * according to Bussi et al JCP (2007), Eq. (A7)
 * kk:    present value of the kinetic energy of the atoms to be thermalized (in arbitrary units)
 * sigma: target average value of the kinetic energy (ndeg k_b T/2)  (in the same units as kk)
 * ndeg:  number of degrees of freedom of the atoms to be thermalized
 * taut:  relaxation time of the thermostat, in units of 'how often this routine is called'
 */
  real factor,rr;

  if (taut > 0.1) {
    factor = exp(-1.0/taut);
  } else {
    factor = 0.0;
  }
  rr = gmx_rng_gaussian_real(rng);
  return
    kk +
    (1.0 - factor)*(sigma*(vrescale_sumnoises(ndeg-1,rng) + rr*rr)/ndeg - kk) +
    2.0*rr*sqrt(kk*sigma/ndeg*(1.0 - factor)*factor);
}
Beispiel #4
0
cvm::real colvarproxy_gromacs::rand_gaussian() {
  return gmx_rng_gaussian_real(rando);
}