Esempio n. 1
0
def main(idata, status, mode=2, target="*"):

    stat2check = [1]
    mustexist = []
    tocreate = []

    #-------------------------------------------------------#
    # Read Pilgrim input files and check file/folder status #
    #-------------------------------------------------------#
    # expand data
    (dctc, dimasses), ltemp, dpath, dtes, dchem, tkmc, ddlevel = idata
    # status ok?
    fstatus = status_check(status, stat2check)
    if fstatus == -1: exit()
    # existency of folders
    fstatus = ffchecking(mustexist, tocreate)
    if fstatus == -1: exit()
    #-------------------------------------------------------#

    #----------------#
    # deal with mode #
    #----------------#
    msg = {}
    msg["-1"] = "ics will be removed"
    msg["-2"] = "ics will be checked"
    msg["1"] = "ics will be generated according to connectivity"
    msg[ "2"] = "ics will be generated according to connectivity\n"+\
                "and reduced"
    msg[ "3"] = "ics will be generated according to connectivity\n"+\
                "and reduced to a non-redundant set"
    print "   Selected mode is '%s'" % mode
    if mode not in ["-2", "-1", "1", "2", "3"]:
        print "    - Unknown mode!"
        print
        return
    for idx, line in enumerate(msg[mode].split("\n")):
        if idx == 0: print "    - " + line
        else: print "      " + line
Esempio n. 2
0
#===============================================================#
def main(idata, status, case, targets="*"):

    stat2check = [1, 2, 5]
    mustexist = [PN.DIR1]
    tocreate = [PN.DIR2, PN.DIR3, PN.DIR6]
    #-------------------------------------------------------#
    # Read Pilgrim input files, check file/folder status    #
    # and expand tuple 'case'                               #
    #-------------------------------------------------------#
    # expand data
    (dctc, dimasses), ltemp, dpath, (dtesLL,
                                     dtesHL), dchem, tkmc, ddlevel = idata
    # status ok?
    fstatus = status_check(status, stat2check)
    if fstatus == -1: exit()
    # existency of folders
    fstatus = ffchecking(mustexist, tocreate)
    if fstatus == -1: exit()
    # expand case
    (dof, hlf, plotfile), dlevel, software = case
    #-------------------------------------------------------#

    # no specific target selected
    if "*" in targets or len(targets) == 0: targets = dchem.keys()

    # clean targets
    targets = sorted([target for target in targets if target in dchem.keys()])

    # read dof
Esempio n. 3
0
def main(idata, status, case):

    stat2check = [2, 5, 6]
    mustexist = []
    tocreate = [PN.DIR3, PN.DIR6]
    #-------------------------------------------------------#
    # Read Pilgrim input files, check file/folder status    #
    # and expand tuple 'case'                               #
    #-------------------------------------------------------#
    # expand data
    (dctc, dimasses), ltemp, dpath, (dtesLL,
                                     dtesHL), dchem, tkmc, ddlevel = idata
    # status ok?
    fstatus = status_check(status, stat2check)
    if fstatus == -1: exit()
    # existency of folders
    fstatus = ffchecking(mustexist, tocreate)
    if fstatus == -1: exit()
    # expand case
    (dof, hlf, plotfile), dlevel, software = case
    #-------------------------------------------------------#

    #---------------------------------#
    # files with data and output file #
    #---------------------------------#
    pof = PN.get_pof(dlevel, "kmc")
    print "   Pilgrim output file: %s" % pof
    print

    sys.stdout = Logger(pof, "w", True)

    # expand KMC tuple
    ipops, rcs, psteps, volume, timeunits, excess = tkmc
    valid_tu = "fs,ps,mcs,ms,s,min,hr".split()
    if timeunits not in valid_tu: valid_tu = "ps"

    # reactivo limitante
    try:
        POP0 = min(
            [ipop for species, ipop in sorted(ipops.items()) if ipop != 0.0])
    except:
        POP0 = 0

    print_string(
        PS.skmc_init(ipops, POP0, excess, rcs, psteps, volume, timeunits, dof),
        5)

    # continue?
    if POP0 == 0:
        print "   All initial populations are zero..."
        print
        return
    if rcs == {}:
        print "   No reactions considered in %s" % PN.IFILE6
        print
        return

    # read dof
    dall = RW.read_alldata(dof, ltemp)[0]

    # perform KMC for each temperature
    data = []
    fratios = {}
    ftimes = []
    for idx, temp in enumerate(ltemp):
        # title
        title = " T = %.3f Kelvin " % temp
        division = "-" * len(title)
        string = "     " + division + "\n"
        string += "     " + title + "\n"
        string += "     " + division + "\n"
        print string
        # get rate constants
        processes = get_ratecons(rcs, dchem, dall, idx, temp)
        # print initial information before simulation
        print_string(PS.skmc_processes(temp, processes), 9)
        # perform kmc simulation
        xvalues, yvalues = kmc(ipops, processes, excess, volume, psteps)
        fratios["%7.2f" % temp] = {}
        for species in yvalues.keys():
            fratios["%7.2f" % temp][species] = yvalues[species][-1] / POP0
        # print data from simulation
        print_string(PS.skmc_results(xvalues, yvalues, timeunits), 9)
        # save data needed for txt and pdf files
        data += [("%.2f" % temp, xvalues, yvalues)]
        ftimes.append(xvalues[-1])

    # print final ratios
    species = sorted(yvalues.keys())
    print_string(PS.skmc_finaltimes(ltemp, ftimes, timeunits), 5)
    print_string(PS.skmc_finalratio(ltemp, species, fratios), 5)

    # save data for plotting
    if plotfile is not None:
        plotdata = {}
        plotdata.update(
            manage_data_for_plot_kmc(data, fratios, volume, timeunits))
        write_plotfile(plotfile, plotdata)
Esempio n. 4
0
def main(idata,status):

    stat2check = []
    mustexist  = []
    tocreate   = []

    #-------------------------------------------------------#
    # Read Pilgrim input files and check file/folder status #
    #-------------------------------------------------------#
    # expand data
    (dctc,dimasses), ltemp, dpath, (dtesLL,dtesHL), dchem, tkmc, ddlevel = idata
    # status ok?
    fstatus = status_check(status,[])
    if fstatus == -1: exit()
    # special warning
    if status[0] == -1:
        print "     WARNING! '%s' file not found."%PN.IFILE1
        print "     In order to generate it, run"
        print "        pilgrim --gather"
    # existency of folders
    fstatus = ffchecking(mustexist=[],tocreate=[])
    if fstatus == -1: exit()
    #-------------------------------------------------------#

    # print menu
    print_string(MENU,1)

    # setup dpath
    for ctc in dpath.keys():
        dpath[ctc].setup1()
        dpath[ctc].setup2()


    # interactive menu
    dbool = {}
    while True:
          set_completer(1)
          line = raw_input(ILINE1).split()
          if len(line) == 0: continue
          command  = line[0].lower()
          try   : var = line[1].lower()
          except: var = None
          try   : val = line[2:]
          except: val = None
          # update list of transition states
          lts  = [ctc for ctc in dctc.keys() if dctc[ctc]._type == 1]
          # user ask for help
          if   command == "help":
             if   var is None     : print_string(MENU,3)
             elif var == "temp"   : print_string(HELP_temp,6)
             elif var == "path"   : print_string(HELP_path,6)
             elif var == "chem"   : print_string(HELP_chem,6)
             elif var == "kmc"    : print_string(HELP_kmc ,6)
             elif var == "dlevel" : print_string(HELP_dlevel,6)
             elif var == "isomass": print_string(HELP_isomass,6)
             elif var == "struc"  : print_string(HELP_struc,6)
          # user ask for list
          elif command == "ls":
             if   var == "struc"  : ls_struc(dctc)
             elif var == "temp"   : ls_temp(ltemp)
             elif var == "path"   : ls_path(dpath)
             elif var == "chem"   : ls_chem(dchem)
             elif var == "kmc"    : ls_kmc(tkmc)
             elif var == "dlevel" : ls_dlevel(ddlevel)
             elif var == "isomass": ls_isomass(dimasses)
             else                 : continue
          # add
          elif command == "add":
               if   var == "temp"   : ltemp          = add_temp(val,ltemp)
               elif var == "path"   : dpath,dtesLL   = add_path(val,dpath,dctc,dtesLL,lts)
               elif var == "chem"   : dchem          = add_chem(val,dchem)
               elif var == "kmc"    : tkmc           = add_kmc(val,tkmc,dchem)
               elif var == "dlevel" : ddlevel,dtesHL = add_dlevel(val,ddlevel,dctc,dtesHL)
               elif var == "isomass": dimasses       = add_isomass(val,dimasses)
               dbool[var] = True
          # mod
          elif command == "mod":
               if   var == "path"  : dpath,dtesLL   = add_path(val,dpath,dctc,dtesLL,lts,mod=True)
               elif var == "struc" : dctc           = mod_struc(val,dctc,dimasses)
               dbool[var] = True
          # rm
          elif command == "rm":
               if   var == "temp"   : ltemp    = rm_temp(val,ltemp)
               elif var == "path"   : dpath    = rm_path(val,dpath)
               elif var == "chem"   : dchem    = rm_chem(val,dchem)
               elif var == "dlevel" : ddlevel  = rm_dlevel(val,ddlevel)
               elif var == "struc"  : dctc     = rm_struc(val,dctc)
               elif var == "isomass": dimasses = rm_isomass(val,dimasses)
               dbool[var] = True
          # user ask for finishing
          elif command in END:
             if dbool != {}:
                print
                print "  (Re)Writing files:"
                if dbool.get("isomass",False) or dbool.get("struc",False):
                   print "     %s"%PN.IFILE1
                   RW.write_ctc(dctc,dimasses)
                if dbool.get("temp",False):
                   print "     %s"%PN.IFILE2
                   RW.write_temp(ltemp)
                if dbool.get("path",False):
                   print "     %s"%PN.IFILE3
                   RW.write_path(dpath)
                if dbool.get("path",False) or dbool.get("dlevel",False):
                   print "     %s"%PN.IFILE4
                   RW.write_tes(dtesLL,dtesHL)
                if dbool.get("chem",False):
                   print "     %s"%PN.IFILE5
                   RW.write_chem(dchem)
                if dbool.get("kmc",False):
                   print "     %s"%PN.IFILE6
                   RW.write_kmc(tkmc)
                if dbool.get("dlevel",False):
                   print "     %s"%PN.IFILE7
                   RW.write_dlevel(ddlevel)
                print
             break
          # user ask for nothing
          else: continue