Beispiel #1
0
def dosimul(zoom, build = True):
  global fncfg, fnout, cmdopt

  # build the program
  progdir = "../prog/lj"
  if not os.path.isdir(progdir):
    progdir = "../" + progdir
  if build:
    zcom.runcmd("make -C %s" % progdir)

  prog = "md"
  try:
    # make a copy of the program in case
    # it gets modified or deleted later
    shutil.copy("%s/%s" % (progdir, prog), "./%s" % prog)
  except:
    pass

  cmd = "./%s -t%s -Z%s %s" % (prog, nsteps, zoom, cmdopt)
  if dKdE > 0: cmd += " -G%s" % dKdE
  if Etot != None: cmd += " -E%s" % Etot
  if Edev != None: cmd += " -D%s" % Edev
  cmd = cmd.strip()

  fnlog = "ez%s.log" % zoom
  ln = "# zoom %s, nsteps %s, dKdE %s, Etot %s, Edev %s\n" % (
      zoom, nsteps, dKdE, Etot, Edev)
  open(fnlog, "w").write(ln) # empty the log
  
  print "CMD: %s; LOG %s" % (cmd, fnlog)

  cnt = 0
  esum = 0
  e2sum = 0
  eisum = 0
  ei2sum = 0
  for i in range(ntrials):
    ret, out, err = zcom.runcmd(cmd, capture = True, verbose = 0)
    # get the last line of the output
    result = err.strip().split('\n')[-1]
    etot, etav, eitot = geterror(result)

    # print results
    cnt += 1
    eisum += eitot
    ei2sum += eitot * eitot
    eiave = eisum / cnt
    eivar = ei2sum / cnt - eiave * eiave
    esum += etot
    e2sum += etot * etot
    eave = esum / cnt
    evar = e2sum / cnt - eave * eave
    print "count %s, total energy %s, ave %s, var %s, init %s, iave %s, ivar %s" % (
        cnt, etot, eave, evar, eitot, eiave, eivar)

    ln = "%d %s %s %s\n" % (cnt, etot, eitot, etav)
    open(fnlog, "a").write(ln)

  return cnt, eave, evar, eiave, eivar
Beispiel #2
0
def main():
  global cmdopt, fnlog

  progdir = "../../prog"
  if not os.path.isdir(progdir):
    progdir = "../" + progdir

  zcom.runcmd("make -C %s/lj" % progdir)

  if doev:
    prog = "ljwham2"
    if not fnlog: fnlog = "lj2.log"
    hisopt = "--fnhis2"
    fnhis = "hist2.dat"
  else:
    prog = "ljwham"
    if not fnlog: fnlog = "lj.log"
    hisopt = "--fnhis"
    fnhis = "hist.dat"

  arr = os.path.splitext(fnlog)
  fntmlog = arr[0] + "tm" + arr[1]
  fnhis = arr[0] + "_" + fnhis

  try:
    shutil.copy("%s/lj/%s" % (progdir, prog), "./%s" % prog)
  except:
    pass

  cmd0 = "./%s %s=%s %s %s" % (
      prog, hisopt, fnhis, tol, cmdopt)
  cmd0 = cmd0.strip()

  ns = [0]*(nbases + 1)
  tm = [0]*(nbases + 1)
  for i in range(nsamp):
    print "running sample %d/%d..." % (i, nsamp)

    # use the direct WHAM
    cmd = "%s --re %s %s" % (cmd0, nequil, nsteps)
    ret, out, err = zcom.runcmd(cmd.strip(), capture = True)
    ns[0], tm[0] = getnstepstime(err)

    for nb in range(1, nbases + 1):
      cmd = "%s --wham=MDIIS --nbases=%d -H %s %s" % (
          cmd0, nb, update_method, mthreshold)
      ret, out, err = zcom.runcmd(cmd.strip(), capture = True)
      ns[nb], tm[nb] = getnstepstime(err)

    # save to the log files
    open(fnlog, "a").write(" ".join(ns) + "\n")
    open(fntmlog, "a").write(" ".join(tm) + "\n")
Beispiel #3
0
def main():
    global cmdopt, fnlog

    progdir = "../../prog"
    if not os.path.isdir(progdir):
        progdir = "../" + progdir

    zcom.runcmd("make -C %s/lj" % progdir)

    if doev:
        prog = "ljwham2"
        if not fnlog: fnlog = "lj2.log"
        hisopt = "--fnhis2"
        fnhis = "hist2.dat"
    else:
        prog = "ljwham"
        if not fnlog: fnlog = "lj.log"
        hisopt = "--fnhis"
        fnhis = "hist.dat"

    arr = os.path.splitext(fnlog)
    fntmlog = arr[0] + "tm" + arr[1]
    fnhis = arr[0] + "_" + fnhis

    try:
        shutil.copy("%s/lj/%s" % (progdir, prog), "./%s" % prog)
    except:
        pass

    cmd0 = "./%s %s=%s %s %s" % (prog, hisopt, fnhis, tol, cmdopt)
    cmd0 = cmd0.strip()

    ns = [0] * (nbases + 1)
    tm = [0] * (nbases + 1)
    for i in range(nsamp):
        print "running sample %d/%d..." % (i, nsamp)

        # use the direct WHAM
        cmd = "%s --re %s %s" % (cmd0, nequil, nsteps)
        ret, out, err = zcom.runcmd(cmd.strip(), capture=True)
        ns[0], tm[0] = getnstepstime(err)

        for nb in range(1, nbases + 1):
            cmd = "%s --wham=MDIIS --nbases=%d -H %s %s" % (
                cmd0, nb, update_method, mthreshold)
            ret, out, err = zcom.runcmd(cmd.strip(), capture=True)
            ns[nb], tm[nb] = getnstepstime(err)

        # save to the log files
        open(fnlog, "a").write(" ".join(ns) + "\n")
        open(fntmlog, "a").write(" ".join(tm) + "\n")
Beispiel #4
0
def getprogdir(build = True):
  ''' find the directory of NAMD '''
  global progdir

  if not progdir:
    progdir = "../../NAMD_mods/NAMD_2.11_thstat/Linux-x86_64-g++"
    i = 0
    while not os.path.isdir(progdir):
      progdir = "../" + progdir
      i += 1
      if i > 3: break
  if build: # build the program
    zcom.runcmd("make -C %s" % progdir)
  return progdir
Beispiel #5
0
def mkpdb(fnpdb, doext, angs, ter):
  ''' copy PDB to the running directory '''

  # 1. copy or download the input pdb into the working directory
  if os.path.exists(fnpdb):
    # copy `fnpdb' to the current directory
    fnpdb0 = os.path.basename(fnpdb)
    shutil.copy2(fnpdb, fnpdb0)
    print "copying %s to %s" % (fnpdb, fnpdb0)
    fnpdb = fnpdb
  else:
    # `fnpdb' is the standard 4-letter PDB code
    if not fnpdb.endswith(".pdb") and len(fnpdb) == 4:
      fnpdb = fnpdb.upper() + ".pdb"

    # try to download from RCSB
    if zcom.runcmd("wget http://www.rcsb.org/pdb/files/" + fnpdb,
        system = True)[0] != 0:
      print "cannot download", fnpdb
      raise Exception

  # 2. create an extended configuration
  if doext:
    fnpdbx = "out.pdb"
    import mkspx
    seq = mkspx.pdb2seq(fnpdb)
    src = mkspx.mkpdb(seq, angs, ter, False, gmxver)
    print("saving the extended configuration to " + fnpdbx)
    open(fnpdbx, "w").write(src)
    fnpdb = fnpdbx

  # 3. renumber residues from 1
  fnpdb = renumpdb(fnpdb)
  return fnpdb
Beispiel #6
0
def main():
    global radd, cmdopt, fnls, fntr

    progdir = "../../prog"
    if not os.path.isdir(progdir):
        progdir = "../" + progdir
    zcom.runcmd("make -C %s/gmx" % progdir)

    if doev:
        prog = "xvgwham2"
        if not fntr: fntr = "xvg2.tr"
        if not fnls: fnls = "ev.ls"
        fnhis = "hist2.dat"
    else:
        prog = "xvgwham"
        if not fntr: fntr = "xvg.tr"
        if not fnls: fnls = "e.ls"
        fnhis = "hist.dat"

    arr = os.path.splitext(fntr)
    fnhis = arr[0] + "_tr_" + fnhis

    try:
        shutil.copy("%s/gmx/%s" % (progdir, prog), "./%s" % prog)
    except:
        pass

    cmd0 = "./%s -v --fnhis=%s -r %g %s %s %s %s %s" % (
        prog, fnhis, radd, fnls, itmin, itmax, tol, cmdopt)
    cmd0 = cmd0.strip()

    for i in range(nsamp):
        print "running sample %d/%d..." % (i, nsamp)

        # use the direct WHAM
        ret, out, err = zcom.runcmd(cmd, capture=True)
        gettrace(0, err)

        for nb in range(dnbases, nbases + 1, dnbases):
            cmd = "%s --wham=MDIIS --nbases=%d -H %s %s" % (
                cmd0, nb, update_method, mthreshold)
            ret, out, err = zcom.runcmd(cmd.strip(), capture=True)
            gettrace(nb, err)
Beispiel #7
0
def main():
    global cmdopt, fntr

    progdir = "../../prog"
    if not os.path.isdir(progdir):
        progdir = "../" + progdir

    zcom.runcmd("make -C %s/is2" % progdir)

    prog = "is2wham"

    arr = os.path.splitext(fntr)
    fnhis = arr[0] + "_tr_hist.dat"

    try:
        shutil.copy("%s/is2/%s" % (progdir, prog), "./%s" % prog)
    except:
        pass

    cmd0 = "./%s -v --fnhis=%s %s %s %s %s" % (prog, fnhis, itmin, itmax, tol,
                                               cmdopt)
    cmd0 = cmd0.strip()

    for i in range(nsamp):
        print "running sample %d/%d..." % (i, nsamp)

        # use the direct WHAM
        cmd = "%s --re %s %s" % (cmd0, nequil, nsteps)
        ret, out, err = zcom.runcmd(cmd, capture=True)
        gettrace(0, err)

        for nb in range(dnbases, nbases + 1, dnbases):
            cmd = "%s --wham=MDIIS --nbases=%d -H %s %s" % (
                cmd0, nb, update_method, mthreshold)
            ret, out, err = zcom.runcmd(cmd.strip(), capture=True)
            gettrace(nb, err)
Beispiel #8
0
def main():
  global cmdopt, fntr

  progdir = "../../prog"
  if not os.path.isdir(progdir):
    progdir = "../" + progdir

  zcom.runcmd("make -C %s/is2" % progdir)

  prog = "is2wham"

  arr = os.path.splitext(fntr)
  fnhis = arr[0] + "_tr_hist.dat"

  try:
    shutil.copy("%s/is2/%s" % (progdir, prog), "./%s" % prog)
  except:
    pass

  cmd0 = "./%s -v --fnhis=%s %s %s %s %s" % (
      prog, fnhis, itmin, itmax, tol, cmdopt)
  cmd0 = cmd0.strip()

  for i in range(nsamp):
    print "running sample %d/%d..." % (i, nsamp)

    # use the direct WHAM
    cmd = "%s --re %s %s" % (cmd0, nequil, nsteps)
    ret, out, err = zcom.runcmd(cmd, capture = True)
    gettrace(0, err)

    for nb in range(dnbases, nbases + 1, dnbases):
      cmd = "%s --wham=MDIIS --nbases=%d -H %s %s" % (
          cmd0, nb, update_method, mthreshold)
      ret, out, err = zcom.runcmd(cmd.strip(), capture = True)
      gettrace(nb, err)
Beispiel #9
0
def runmd(fningro, fnout, fnmdp, fntop, pd, capture):
  ''' run mdrun with the structure in `fningro' '''

  if fnout.endswith(".gro"):
    fnout = os.path.splitext(fnout)[0]

  ret = gmxshrun(grompp + " -v -f " + fnmdp + " -o " + fnout + ".tpr "
                 + "-c " + fningro + " -p " + fntop + " -maxwarn 5",
                 capture)

  print "\n\nRunning mdrun with %s, may take some time..." % fnout
  cmd = mdrun + " -v -deffnm " + fnout
  # if `ns_type' is `simple' instead of `grid'
  # we have to use particle decomposition
  if pd: cmd += " -pd"
  ret = zcom.runcmd(cmd, capture)
  zcom.die_if(ret[0] != 0, "mdrun failed with %s" % fnout)
  return fnout + ".gro"
Beispiel #10
0
def scan():
  global fncfg, fnout, cmdopt 

  progdir = "../prog"
  if not os.path.isdir(progdir):
    progdir = "../" + progdir

  # build the program
  zcom.runcmd("make -C %s" % progdir)

  prog = "invt"

  try:
    # make a copy of the program in case
    # it gets modified or deleted later
    shutil.copy("%s/%s" % (progdir, prog), "./%s" % prog)
  except:
    pass

  cmd0 = "./%s %s %s" % (prog, fncfg, cmdopt)
  cmd0 = cmd0.strip()

  # create a table of c-values
  cval = []
  if sigscan:
    sig = sigmin
    while sig < sigmax + sigdel * 0.01:
      cval += [ sig, ]
      sig += sigdel
    srange = "sig=%s:%s:%s" % (sigmin, sigdel, sigmax)
    varname = "Gaussian sigma"

  elif okscan:
    ok = okmin
    while ok < okmax + okdel * 0.01:
      cval += [ ok, ]
      ok += okdel
    srange = "ok=%s:%s:%s" % (okmin, okdel, okmax)
    varname = "bandpass cutoff K"

  elif ikscan:
    ik = ikmin
    okold = -1
    while ik < ikmax + ikdel * 0.01:
      ok = int(ikconst / ik + 0.5)
      if ok != okold: # avoid redundancy
        cval += [ ok, ]
      ik += ikdel
      okold = ok
    srange = "ik=%s:%s:%s" % (ikmin, ikdel, ikmax)
    varname = "inverse bandpass cutoff K"

  elif iascan:
    ia = iamin
    iafac = 10.0 ** iadel
    while ia < iamax * iafac:
      cval += [ ia, ]
      ia *= iafac
    srange = "ia=%s:%s:%s" % (iamin, iadel, iamax)
    varname = "initial updating magnitude, alpha(0)"

  else:
    raise

  # we save data to a temporary file
  # and overwrite the actual file only at the end
  if os.path.exists(fnout):
    fnouttmp = fnout + ".tmp"
  else:
    fnouttmp = fnout

  # text of the output
  txt = ""

  # print out an information line
  sinfo = "# %s %s %s\n" % (fncfg, cmdopt, srange)
  txt += sinfo

  # go over the predefined c-values
  for i in range(len(cval)):
    print "%d: testing for %s value %s..." % (
        i, varname, cval[i])

    c = cval[i]

    if sigscan:
      cmd = "%s --sig=%s" % (cmd0, c)
    elif okscan or ikscan:
      cmd = "%s --okmax=%s" % (cmd0, c)
    elif iascan:
      cmd = "%s --opta --inita=%s" % (cmd0, c)
    else:
      raise

    ret, out, err = zcom.runcmd(cmd.strip(), capture = True)
    e, ei, enorm, stde, stdei = geterror(out)

    # construct a line of output
    s = "%s\t%s\t%s\t%s\t%s\t%s\n" % (
        c, e, ei, enorm, stde, stdei)
    txt += s

    # save to the output file
    open(fnouttmp, "w").write(txt)

  # write the entire text at the end
  # we do not trust the content of fnouttmp,
  # which is only for backup, and may have been changed
  open(fnout, "w").write(txt)

  # remove the temporary file
  if fnouttmp != fnout:
    os.remove(fnouttmp)
Beispiel #11
0
def main():
  global bootstrap, est, mbar, cmdopt, fnls, fnlog

  progdir = "../../prog"
  if not os.path.isdir(progdir):
    progdir = "../" + progdir

  zcom.runcmd("make -C %s/gmx" % progdir)

  if doev:
    if mbar:
      prog = "xvgmbar2"
    else:
      prog = "xvgwham2"
    if not fnlog: fnlog = "xvg2err.log"
    if not fnls: fnls = "ev.ls"
    hisopt = "--fnhis2"
    fnhis = "histerr2.dat"
  else:
    if mbar:
      prog = "xvgmbar"
    else:
      prog = "xvgwham"
    if not fnlog: fnlog = "xvgerr.log"
    if not fnls: fnls = "e.ls"
    hisopt = "--fnhis"
    fnhis = "histerr.dat"

  if mbar:
    strfnhis = ""
    # modify the the log file name
    arr = os.path.splitext(fnlog)
    if not est:
      fnlog = arr[0] + "_mbar" + arr[1]
  else:
    arr = os.path.splitext(fnlog)
    wmethod = whammethod.upper()
    if wmethod.startswith("UI"):
      method = "ui"
    elif wmethod == "ST":
      method = "st"
    else:
      method = ""
    fnlog = arr[0] + "_wham" + method + arr[1]
    fnhis = arr[0] + method + "_" + fnhis
    strfnhis = hisopt + "=" + fnhis

  try:
    shutil.copy("%s/gmx/%s" % (progdir, prog), "./%s" % prog)
  except:
    pass

  cmd0 = "./%s -v %s %s %s %s %s %s --%s=%s %s %s" % (
      prog, strfnhis, fnls, cmdopt, radd, bootstrap,
      "--est" if est else "",
      "mbar" if mbar else "wham", whammethod, nbases,
      strfnact)
  cmd0 = cmd0.strip()

  if bootstrap and not mbar:
    # run for the first time to save the histogram
    zcom.runcmd(cmd0)
    # we will load the histogram, and bootstrap later on
    cmd0 += " -H"

  if est:
    arr = os.path.splitext(fnlog)
    fnlogs = [
      arr[0] + "avea_mbar" + arr[1],
      arr[0] + "aveb_mbar" + arr[1],
      arr[0] + "avec_mbar" + arr[1],
      arr[0] + "expa_mbar" + arr[1],
      arr[0] + "expb_mbar" + arr[1],
      arr[0] + "bar_mbar" + arr[1],
      arr[0] + "gp_mbar" + arr[1],
      arr[0] + "tg_mbar" + arr[1],
      arr[0] + "lnv_mbar" + arr[1],
      ]
  else:
    fnlogs = [ fnlog ]

  for i in range(nsamp):
    print "running sample %d/%d..." % (i, nsamp)

    # run WHAM
    ret, out, err = zcom.runcmd(cmd0.strip(), capture = True)
    if i == 0:
      bet = getcol(out, 1)
      hdr = "#HEADER " + " ".join(bet) + "\n"
      for fnlog in fnlogs:
        open(fnlog, "a").write(hdr)

    for i in range(len(fnlogs)):
      fnlog = fnlogs[i]
      col = i + 2
      lnz = getcol(out, col)
      open(fnlog, "a").write(" ".join(lnz) + "\n")
Beispiel #12
0
    elif o in ("--verbose",):
      verbose = int(a)
    elif o in ("-t", "-T",):
      temp = float(a)
    elif o in ("-p", "-P",):
      pres = float(a)
    elif o in ("-m",):
      nequil = int(a)
    elif o in ("-n",):
      nsteps = int(a)
    elif o in ("--nt",):
      nthreads = int(a)
    elif o in ("-h", "--help"):
      usage()

  ret, out, err = zcom.runcmd("uname -a", capture = True)
  if out.find("host.utmb.edu") >= 0:
    srcroot = "$HOME/lwork/gmx/gromacs5.0"
    buildroot = srcroot + "/buildgccdbl"
    gmxtopdir = srcroot + "/share/top"



def changensteps(fn, nsteps):
  ''' set the number of steps in the .mdp file '''
  s = open(fn).readlines()
  for i in range(len(s)):
    if s[i].startswith("nsteps"):
      s[i] = "nsteps = %d\n" % nsteps
  open(fn, "w").writelines(s)
Beispiel #13
0
def dotrace(zoom, build = True, fntrace = None):
  global fncfg, nsteps, cmdopt, Etot, Edev
  global thermostat, tNHCPeriod, langRescaleDt

  progdir = getprogdir(build)

  if Edev == None: Edev = 100
  if Etot == None: Etot = -6141.16
  Etot += Edev
  Edev = 0

  # copy files from the source directory
  fnpsf, fnpdb, fnprm, scfg = getfiles("normal")

  # create a temporary directory
  rundir = "tmprun"
  if not os.path.exists(rundir):
    os.mkdir(rundir)
  # move to the running directory
  os.chdir(rundir)

  # program directory
  prog = "../" + progdir + "/namd2 +p%s" % nproc

  # copy files
  os.system("cp %s ." % fnpsf)
  os.system("cp %s ." % fnpdb)
  os.system("cp %s ." % fnprm)

  if nsteps == None: nsteps = 1

  # command line
  fncfg = "run.conf"
  cmd = "%s %s %s" % (prog, cmdopt, fncfg)

  # output file
  if not fntrace: fntrace = "etot.tr"
  fntrace = "../" + fntrace


  # construct a configuration file
  fnene = "ene0.log"

  strcfg = scfg + '''
energyLogFile             %s
energyLogFreq             1
energyLogTotal            on
''' % (fnene)

  if not thermostat:
    strcfg += '''
rescaleAdaptive           on
rescaleAdaptiveZoom       %s
rescaleAdaptiveFileFreq   1000
''' % (zoom)
    if dKdE > 0:
      strcfg += "rescaleAdaptiveDKdE       %s\n" % dKdE
  elif thermostat == "NH":
    # Nose-Hoover thermostat
    strcfg += '''
tNHC              on
tNHCTemp          $temperature
tNHCLen           5
tNHCPeriod        %g
''' % (tNHCPeriod)
  elif thermostat.startswith("VR"):
    # Langevin-style velocity rescaling
    strcfg += '''
langRescale       on
langRescaleTemp   $temperature
langRescaleDt     %g
''' % (langRescaleDt)
  else: # if thermostat.startswith("L"):
    # Langevin thermostat
    strcfg += '''
langevin          on
langevinDamping   1
langevinTemp      $temperature
'''

  if Etot != None:
    strcfg += "rescaleInitTotal          %s\n" % Etot
  if Edev != None:
    strcfg += "rescaleInitDev            %s\n" % Edev

  strcfg += "run %s\n" % nsteps
  open(fncfg, "w").write(strcfg)

  print "CMD: %s; TRACE %s; CFG %s" % (cmd, fntrace, fncfg)

  eparr = []
  ekarr = []
  etarr = []
  # multiple trials
  i = 0
  while i < ntrials:
    # clear the directory
    os.system("rm -rf *.dat *.BAK *.old ene*.log *.vel *.xsc *.xst *.coor")

    ret, out, err = zcom.runcmd(cmd, capture = True, verbose = 0)
    # extract the energy
    ss = open(fnene).read().strip().split('\n')
    ssplit = [ln.strip().split() for ln in ss]
    tm = len(ss)

    # initialize the accumulators
    if i == 0:
      etarr = [ Ave() for k in range(tm) ]
      eparr = [ Ave() for k in range(tm) ]
      ekarr = [ Ave() for k in range(tm) ]
      if os.path.exists(fntrace): # load previous record
        s = open(fntrace).readlines()
        tags = s[0].split()
        cnt = int( tags[2][:-1] )
        fzoom = float( tags[4][:-1] )
        nsteps = int( tags[6][:-1] )
        if nsteps != tm - 1: # loading previous data
          print "previous nsteps %s is not %s" % (nsteps, tm - 1)
        else:
          for k in range(tm):
            arr = [float(x) for x in s[k+1].split()]
            etarr[k].load(cnt, arr[1], arr[2])
            eparr[k].load(cnt, arr[3], arr[4])
            ekarr[k].load(cnt, arr[5], arr[6])
          i = cnt

    # update the accumulators for the total, potential and kinetic energies
    for k in range(tm):
      epot = float( ssplit[k][1] )
      eparr[k].add(epot)
      etot = float( ssplit[k][2] )
      etarr[k].add(etot)
      ekin = etot - epot
      ekarr[k].add(ekin)

    print "count %s, total energy, final: ave %s, fvar %s, init: ave %s, var %s" % (
        i + 1, etarr[-1].getave(), etarr[-1].getvar(),
        etarr[0].getave(), etarr[0].getvar())

    strace = "# count %s, zoom %s, nsteps %s, dKdE %s, Etot %s, Edev %s\n" % (
      etarr[0].n, zoom, nsteps, dKdE, Etot, Edev)

    # output the trace file
    for k in range(tm):
      strace += "%s\t%g\t%g\t%g\t%g\t%g\t%g\n" % ( ssplit[k][0],
          etarr[k].getave(), etarr[k].getvar(),
          eparr[k].getave(), eparr[k].getvar(),
          ekarr[k].getave(), ekarr[k].getvar() )
    open(fntrace, "w").write(strace)

    i += 1

  # go back to the parent directory
  os.chdir("..")
Beispiel #14
0
    shutil.copy2(phony, fnm)

def restore_orig(files):
  for fnm in files:
    fnmbak=fnm+'b'
    print "Restoring the original "+fnm
    os.rename(fnmbak, fnm)

devver=False
# this is the folder where the script resides, not where we run it
# mypath=sys.path[0]
runpath=os.getcwd()
#print mypath, mypath.find("gromacs-4.0."),os.getcwd()
if (runpath.find("gmxgit") >= 0 or
    runpath.find("gromacs-4.0.") >=0): devver=True

if not devver:
  print "This is not a testing system, do you really want to continue?"
  if raw_input().startswith("n"): exit(1);
  create_phony(['Makefile.am', 'Makefile.in'])

runcmd(['tar', 'cvphzf', target]+prune_filelist(filelist))

if not devver:
  restore_orig(['Makefile.am', 'Makefile.in'])

print "%s size %d" %(target, len(open(target).read()))

runcmd(['gnome-open',target])

Beispiel #15
0
def main():
  global mbar, radd, cmdopt, fnls, fnlog, fnact

  progdir = "../../prog"
  if not os.path.isdir(progdir):
    progdir = "../" + progdir

  zcom.runcmd("make -C %s/gmx" % progdir)

  if doev:
    if mbar:
      prog = "xvgmbar2"
    else:
      prog = "xvgwham2"
    if not fnlog: fnlog = "xvg2.log"
    if not fnls: fnls = "ev.ls"
    hisopt = "--fnhis2"
    fnhis = "hist2.dat"
  else:
    if mbar:
      prog = "xvgmbar"
    else:
      prog = "xvgwham"
    if not fnlog: fnlog = "xvg.log"
    if not fnls: fnls = "e.ls"
    hisopt = "--fnhis"
    fnhis = "hist.dat"

  if mbar:
    strfnhis = ""
    # modify the the log file name
    arr = os.path.splitext(fnlog)
    fnlog = arr[0] + "_mbar" + arr[1]
  else:
    arr = os.path.splitext(fnlog)
    fnlog = arr[0] + "_wham" + arr[1]
    fnhis = arr[0] + "_" + fnhis
    strfnhis = hisopt + "=" + fnhis

  arr = os.path.splitext(fnlog)
  fntmlog = arr[0] + "tm" + arr[1]

  try:
    shutil.copy("%s/gmx/%s" % (progdir, prog), "./%s" % prog)
  except:
    pass

  cmd0 = "./%s %s %s %s %s %s" % (
      prog, strfnhis, fnls, tol, fnact, cmdopt)
  cmd0 = cmd0.strip()

  if radd < 1:
    cmd0 += " -r %g" % radd

  if not mbar:
    # run for the first time to save the histogram
    zcom.runcmd(cmd0 + " --wham=ST")

    # we will load the histogram, and bootstrap later on
    cmd0 += " --bootstrap -H"
  else:
    # no need to bootstrap if only a random subsample is used
    if radd >= 1:
      cmd0 += " --bootstrap"

  cmd0 = cmd0.strip()

  ns = [0]*(nbases + 1)
  tm = [0]*(nbases + 1)
  for i in range(nsamp):
    print "running sample %d/%d..." % (i, nsamp)

    # use the direct WHAM
    ret, out, err = zcom.runcmd(cmd0, capture = True)
    ns[0], tm[0] = getnstepstime(err)

    for nb in range(1, nbases + 1):
      cmd = "%s --%s=MDIIS --nbases=%d %s %s" % (
          cmd0, "mbar" if mbar else "wham",
          nb, update_method, mthreshold)
      ret, out, err = zcom.runcmd(cmd.strip(), capture = True)
      ns[nb], tm[nb] = getnstepstime(err)

    # save to the log files
    open(fnlog, "a").write(" ".join(ns) + "\n")
    open(fntmlog, "a").write(" ".join(tm) + "\n")
Beispiel #16
0
            temp = float(a)
        elif o in (
                "-p",
                "-P",
        ):
            pres = float(a)
        elif o in ("-m", ):
            nequil = int(a)
        elif o in ("-n", ):
            nsteps = int(a)
        elif o in ("--nt", ):
            nthreads = int(a)
        elif o in ("-h", "--help"):
            usage()

    ret, out, err = zcom.runcmd("uname -a", capture=True)
    if out.find("host.utmb.edu") >= 0:
        srcroot = "$HOME/lwork/gmx/gromacs5.0"
        buildroot = srcroot + "/buildgcc"
        gmxtopdir = srcroot + "/share/top"


def changensteps(fn, nsteps):
    ''' set the number of steps in the .mdp file '''
    s = open(fn).readlines()
    for i in range(len(s)):
        if s[i].startswith("nsteps"):
            s[i] = "nsteps = %d\n" % nsteps
    open(fn, "w").writelines(s)

Beispiel #17
0
def dosimul(zoom, build = True, fnlog = None):
  global fncfg, nsteps, cmdopt, Etot, Edev

  progdir = getprogdir(build)

  # copy files from the source directory
  fnpsf, fnpdb, fnprm, scfg = getfiles("normal")

  # create a temporary directory
  rundir = "tmprun"
  if not os.path.exists(rundir):
    os.mkdir(rundir)
  # move to the running directory
  os.chdir(rundir)

  # program directory
  prog = "../" + progdir + "/namd2 +p%s" % nproc

  # copy files
  os.system("cp %s ." % fnpsf)
  os.system("cp %s ." % fnpdb)
  os.system("cp %s ." % fnprm)

  if nsteps == None: nsteps = 1000

  # command line
  fncfg = "run.conf"
  cmd = "%s %s %s" % (prog, cmdopt, fncfg)

  # output file
  if not fnlog: fnlog = "ez%s_t%s.log" % (zoom, nsteps)
  fnlog = "../" + fnlog

  ln = "# zoom %s, nsteps %s, dKdE %s, Etot %s, Edev %s\n" % (
      zoom, nsteps, dKdE, Etot, Edev)
  open(fnlog, "a").write(ln)

  print "CMD: %s; LOG %s" % (cmd, fnlog)

  ef = Ave()
  ei = Ave()
  # multiple trials
  for i in range(ntrials):
    # write the configuration file
    fnene = "ene0.log"
    strcfg = scfg + '''
rescaleAdaptive           on
rescaleAdaptiveZoom       %s
rescaleAdaptiveFileFreq   1000
energyLogFile             %s
energyLogFreq             10
energyLogTotal            on
''' % (zoom, fnene)
    if dKdE > 0:
      strcfg += "rescaleAdaptiveDKdE       %s\n" % dKdE
    if Etot != None:
      strcfg += "rescaleInitTotal          %s\n" % Etot
    if Edev != None:
      strcfg += "rescaleInitDev            %s\n" % Edev

    strcfg += "run %s\n" % nsteps
    open(fncfg, "w").write(strcfg)

    # clear the directory
    os.system("rm -rf *.dat *.BAK *.old ene*.log *.vel *.xsc *.xst *.coor")

    ret, out, err = zcom.runcmd(cmd, capture = True, verbose = 0)
    # extract the energy
    ss = open(fnene).readlines()
    eitot = float( ss[0].split()[2] )
    j = -1
    while ss[j].strip() == "":
      j -= 1
    etot = float( ss[j].split()[2] )

    # update accumulators and print results
    ei.add(eitot)
    ef.add(etot)
    print "count %s, total energy %s, ave %s, var %s, init %s, iave %s, ivar %s" % (
        ef.n, etot, ef.getave(), ef.getvar(), eitot, ei.getave(), ei.getvar())

    ln = "%d %s %s\n" % (ef.n, etot, eitot)
    open(fnlog, "a").write(ln)

  # go back to the parent directory
  os.chdir("..")

  return ef.n, ef.getave(), ef.getvar(), ei.getave(), ei.getvar()
Beispiel #18
0
def c_scan():
    global fncfg, fnout, fnprd, cmdopt, fnout

    progdir = "../prog"
    if not os.path.isdir(progdir):
        progdir = "../" + progdir

    # build the program
    zcom.runcmd("make -C %s" % progdir)

    prog = "invt"

    try:
        # make a copy of the program in case
        # it gets modified or deleted later
        shutil.copy("%s/%s" % (progdir, prog), "./%s" % prog)
    except:
        pass

    cmd0 = "./%s %s %s" % (prog, fncfg, cmdopt)
    cmd0 = cmd0.strip()

    # create a table of c-values
    cval = []
    if cscan:
        # linear c values
        c = cmin
        while c < cmax + cdel * 0.01:
            cval += [c]
            c += cdel
        srange = "c=%s:%s:%s" % (cmin, cdel, cmax)

        # construct the larger range for the analytical prediction
        if cmin > cdel:
            cmin1 = cmin - cdel
        else:
            cmin1 = 0
        cmax1 = cmax + cdel
    elif lscan:
        # linear l values, c = 1/l
        l = lmin
        while l < lmax + ldel * 0.01:
            cval += [1.0 / l]
            l += ldel
        srange = "lambda=%s:%s:%s" % (lmin, ldel, lmax)

        # construct the larger range for the analytical prediction
        cmin1 = 1 / (lmax + ldel)
        if lmin > ldel:
            cmax1 = 1 / (lmin - ldel)
        else:
            cmax1 = 1 / lmin
    elif xscan:
        # logarithm c vales
        logc = log(xmin)
        dlogc = xdel * log(10)
        while logc < log(xmax) + dlogc * 0.01:
            cval += [exp(logc)]
            logc += dlogc
        srange = "x=%s:%s:%s" % (xmin, xdel, xmax)

        cmin1 = xmin
        cmax1 = xmax

    dc1 = 0.01
    if cmin1 <= 0:
        cmin1 = dc1
    # generate the prediction result
    os.system(
        "%s/predict %s %s --cmin=%s --cdel=%s --cmax=%s > %s" % (progdir, fncfg, cmdopt, cmin1, dc1, cmax1, fnprd)
    )

    # we save data to a temporary file
    # and overwrite the actual file only at the end
    if os.path.exists(fnout):
        fnouttmp = fnout + ".tmp"
    else:
        fnouttmp = fnout

    # text of the output
    txt = ""

    # print out an information line
    sinfo = "# %s %s %s\n" % (fncfg, cmdopt, srange)
    txt += sinfo

    # go over the predefined c-values
    for i in range(len(cval)):
        print "%d: testing for c-value %s..." % (i, cval[i])

        c = cval[i]

        # override the c value
        cmd = "%s -c %s" % (cmd0, c)
        ret, out, err = zcom.runcmd(cmd.strip(), capture=True)
        e, ei, stde, stdei = geterror(out)

        # construct a line of output
        s = "%s\t%s\t%s\t%s\t%s\n" % (c, e, ei, stde, stdei)
        txt += s

        # save to the output file
        open(fnouttmp, "w").write(txt)

    # write the entire text at the end
    # we do not trust the content of fnouttmp,
    # which is only for backup, and may have been changed
    open(fnout, "w").write(txt)

    # remove the temporary file
    if fnouttmp != fnout:
        os.remove(fnouttmp)