Exemplo n.º 1
0
/* run simulation */
int run(void)
{
  gmx_mtop_t *mtop;
  int i, ndata, nat, rescnt = 0;
  char fxtc[FILENAME_MAX] = "";
  char *ftop;
  matrix box;
  rvec *xref = NULL, *xrefbb = NULL;
  zedata_t *ze = NULL;
  trj_t *trj = NULL;
  double dt, bref = 1.0/(BOLTZ*Tref), wtot = 0.0;
  hist_t *hsrms = NULL;
  bb_t *bb = NULL;
  FILE *fplog = NULL;

  memset(box, 0, sizeof(box));

  /* read topology and the reference structure */
  die_if ((ftop = nfexists(fntop, 7)) == NULL, "no topology file %s\n", fntop);
  mtop = read_tpx_conf(ftop, &xref, box, &nat, &dt);
  printf("using the structure in %s as the reference\n", ftop);

  bb = init_index(&rescnt, mtop); /* get indices for backbone dihedrals */
  xnew(xrefbb, rescnt * 3);
  xgetbb(xrefbb, xref, bb, rescnt);

  hsrms = hs_open(1, 0.0, xmax, xdel);

  if (fnlog) {
    xfopen(fplog, fnlog, "w", exit(1));
  }

  if (fndist2 != NULL) {
    /* if there's a second database, combine it with the first database */
    die_if (0 != hs_load(hsrms, fndist, HIST_VERBOSE),
        "cannot load master %s\n", fndist);
    die_if (0 != hs_load(hsrms, fndist2, HIST_VERBOSE|HIST_ADDITION),
        "cannot add the second %s\n", fndist2);

  } else  {
    /* if there's no second database, we accumulate trajectories */

    /* 1. initialize multiple histogram weights for tempering */
    if (!ctmd) {
      if ((ze = ze_load(fnze, 10)) == NULL) {
        fprintf(stderr, "cannot load %s\n", fnze);
        return -1;
      }
      /* we first load TRACE, compute weight of each frame */
      if ((trj = trj_loadseq(fntr, &ndata, dt, tequil,
              ze, bref, delbet)) == NULL) {
        fprintf(stderr, "failed to load trace\n");
        return -1;
      }
    } else {
      /* for regular MD, set ndata to a large number */
      ndata = 10000000;
    }

    /* 2. we now successively load xtc from each data dir,
     * try to match the TRACE frames */
    if (!ctmd) trj->pos = 0;

    for (i = 1; i <= ndata; i++) {
      sprintf(fxtc, "data%d/%s", i, fnxtc);
      if (!fexists(fxtc)) { /* test if the file exists */
        die_if(!ctmd, "cannot read %s\n", fnxtc);
        break;
      }
      if (0 != dotrj(hsrms, bb, rescnt, fplog,
            trj, fxtc, xrefbb, nat, box, &wtot)) {
        fprintf(stderr, "error doing %s\n", fnxtc);
        return -1;
      }
    }
  }
  hs_save(hsrms, fndist, HIST_ADDAHALF|HIST_VERBOSE);
  hs_close(hsrms);
  sfree(mtop);
  if (!ctmd) {
    if (trj) trj_free(trj);
    if (ze) ze_free(ze);
  }
  free(xrefbb);
  return 0;
}
Exemplo n.º 2
0
/* call hs_close when done playing game */
void hs_close (void)
{
	if (state.hiscores_have_been_loaded) hs_save();
	hs_free();
}
Exemplo n.º 3
0
Arquivo: gomdr.c Projeto: 3ki5tj/alge
static void run(void)
{
  cago_t *go;
  int it, nc;
  double t;
  hist_t *hsep, *hsrmsd, *hscont;

  alged_t *al;
  double alf, ds, ave2;
  /* the actual, logical and boundary-adjusted acceptance rates */
  int acc = 0, acc_l = 0, acc_a = 0;
  double mf = 0; /* current mean force */
  real rmsd0 = 0, rmsd0bk = 0, rmsd1 = 0, drmsd_a = 0, drmsd_l = 0;
  double segtot = 1e-6, segacc = 0;

  /* hybrid MC start point */
  rv3_t *x0, *v0, *f0;
  real epot0;

  go = cago_open(fnpdb, kb, ka, kd1, kd3, nbe, nbc, rcc);
  cago_initmd(go, fromrand ? -0.1 : 0.1, tp);

  /* hybrid MC: save the start point */
  xnew(x0, go->n);
  xnew(v0, go->n);
  xnew(f0, go->n);
  cago_copyvec(go, x0, go->x);
  cago_copyvec(go, v0, go->v);
  cago_copyvec(go, f0, go->v);
  epot0 = go->epot;
  rmsd0 = cago_rmsd(go, x0, NULL);

  printf("epot %g (ref %g), rmsd %g\n",
      go->epot, go->epotref, go->rmsd);

  /* open the alge object */
  al = alged_open(rmsdmin, rmsdmax, rmsddel, mf0, mf1);

  if (hmcmethod == 0) { /* random velocities */
    go->dof = 3 * go->n;
  } else if (hmcmethod == 4) { /* a reflection conserves the zero angular and linear momentum */
    go->dof = 3 * go->n - 6;
  } else { /* if a rotation is involved, the total angular momentum
    is not conserved upon a universal rotation,
    but the linear momentum is still conserved */
    go->dof = 3 * go->n - 3;
  }

  hsep = hs_open1(2*go->epotref, 5*fabs(go->epotref), 0.1);
  hsrmsd = hs_open1(0, 100.0, 0.1);
  hscont = hs_open1(0, go->ncont + 1, 1);

  for (it = 0, t = 1; t < nsteps + .1; t++) {
    cago_vv(go, 1.f, mddt);
    cago_rmcom(go, go->x, go->v);
    cago_vrescale(go, tp, thermdt);

    /* keep doing basic MD */
    if (++it % seglen != 0) continue;

    go->rmsd = cago_rmsd(go, go->x, NULL);
    nc = cago_ncontacts(go, go->x, ncgam, NULL, NULL);

    /* hybrid MC trajectory manipulation */
    rmsd0bk = rmsd0;
    rmsd1 = go->rmsd;
    drmsd_a = rmsd1 - rmsd0;

    segtot += 1;
    /* `acc_l' indicates if a move *should* be accepted by the
     * natural mean force, it can, however, be rejected due to
     * the boundary conditions, indicated by `acc_a' */
    acc = alged_getacc(al, rmsd1, rmsd0, boundary,
        &drmsd_l, &ds, &acc_l, &acc_a);

    if (acc) { /* keep it */
      /* set the new start point */
      segacc += 1;
      cago_copyvec(go, x0, go->x);
      cago_copyvec(go, v0, go->v);
      cago_copyvec(go, f0, go->f);
      rmsd0 = rmsd1;
      epot0 = go->epot;
    } else { /* revert */
      cago_copyvec(go, go->x, x0);
      cago_copyvec(go, go->v, v0);
      cago_copyvec(go, go->f, f0);
    }

    /* we mutate the velocities even if the trajectory is continued */
    if (hmcmethod == 0) {
      md_mutv3d(go->v, go->n, tp, hmcmutr);
    } else if (hmcmethod == 1) {
      md_unimatv3d(go->v, go->n);
    } else {
      if (hmcmethod & 2) md_rotv3d(go->v, go->n);
      if (hmcmethod & 4) md_refv3d(go->v, go->n);
    }

    /* update alge data */
    mf = alged_fupdate(al, rmsd0bk, drmsd_l, alf0, alfc, &alf,
        delmax, &ave2, -mfmax, mfmax);

    /* set the new start point */
    go->rmsd = rmsd0;
    go->epot = epot0;

    hs_add1ez(hsep, go->epot, 0);
    hs_add1ez(hsrmsd, go->rmsd, HIST_VERBOSE);
    hs_add1ez(hscont, nc, HIST_VERBOSE);

    if (it % nevery == 0) {
      printf("t %g, T %.3f(%.3f), ep %.2f/%.2f, rmsd %.2f/%.2f, Q %d/%d=%.2f(%.2f), "
          "alf %.6f, mf %.3f, rmsd %.2f%+.2f(%+.2f, ds %.3f, e2 %g), segacc %2.0f%%\n",
        t, go->tkin, tp,
        go->epot, hs_getave(hsep, 0, NULL, NULL),
        go->rmsd, hs_getave(hsrmsd, 0, NULL, NULL),
        nc, go->ncont, 1.0*nc/go->ncont,
        hs_getave(hscont, 0, NULL, NULL)/go->ncont,
        alf, mf, rmsd0bk, drmsd_l, drmsd_a, ds, ave2, 100.*segacc/segtot);
    }

    if (it % nreport == 0 || t >= nsteps - 0.1) {
      printf("saving %s, %s, %s, %s\n", fnalge, fnephis, fnrmsdhis, fnpos);
      alged_save(al, fnalge);
      hs_save(hsep, fnephis, HIST_ADDAHALF);
      hs_save(hsrmsd, fnrmsdhis, HIST_ADDAHALF);
      hs_save(hscont, fnconthis, 0);
      cago_writepos(go, go->x, NULL, fnpos);
      it = 0;
    }
  }
  cago_close(go);
  hs_close(hsep);
  hs_close(hsrmsd);
  hs_close(hscont);
  alged_close(al);
  free(x0); free(v0); free(f0);
}