Beispiel #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
Beispiel #2
0
    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
    dall = RW.read_alldata(dof, ltemp)[0]

    #--------------------------------#
Beispiel #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)
Beispiel #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
Beispiel #5
0
def main(idata, status):

    global sthwrong
    global wrong1
    global wrong2
    global wrong3
    global wrong4
    sthwrong = False
    wrong1 = False
    wrong2 = False
    wrong3 = False
    wrong4 = False

    #---------------------------------------#
    # Read tracking and pif.ctc (if exist)  #
    #---------------------------------------#
    dtrack, (fname1, status1) = RW.read_track()
    (dctc, dimasses), (fname2, status2) = RW.read_ctc()
    if status1 == 1: print "  - File '%s' exists and is not empty\n" % fname1
    if status2 == 1: print "  - File '%s' exists and is not empty\n" % fname2

    #---------------------#
    # add data to imasses #
    #---------------------#
    if dimasses == {}: dimasses = dpt_im

    #---------------------------------------#
    # Read user data and generate gts files #
    #---------------------------------------#
    # files and folders
    if os.path.exists(PN.UFOLDER):
        files = [
            ff for ff in os.listdir(PN.UFOLDER)
            if not os.path.isdir(PN.UFOLDER + ff)
        ]
        folders = [
            ff + "/" for ff in os.listdir(PN.UFOLDER)
            if os.path.isdir(PN.UFOLDER + ff)
        ]
        # only files with known extension
        files = known_files(files)
    else:
        files = []
        folders = []

    if files + folders != []:
        print "  - Reading user's input data from %s" % PN.UFOLDER
        print
        print "    * Number of files inside %s:" % PN.UFOLDER
        print "      num_files   = %i " % (len(files))
        print "      num_folders = %i " % (len(folders))
        print

        print "      %s" % (PN.UFOLDER)
        for ff in sorted(files) + sorted(folders):
            thedata = analyze_filefolder(ff, dtrack)
            if thedata is None: continue
            for E, ifile, ffile in thedata:
                dtrack[ifile] = ffile
        print

        #--------------------------------#
        # Write tracking and check files #
        #--------------------------------#
        print "    * Writing/Updating file: %s" % PN.IFILE0
        print
        RW.write_track(dtrack)
        print "    * Checking existency of gts files listed in '%s'" % (
            PN.IFILE0)
        for ifile, ffile in dtrack.items():
            if not os.path.exists(PN.DIR1 + ffile):
                print "      '%s' NOT FOUND! (from '%s')" % (ffile, ifile)
                sthwrong = True
                wrong3 = True
                continue
        print
    else:
        print "  - Folder '%s' does not exist or is empty" % PN.UFOLDER
    print

    #--------------------------------#
    # READ gts files                 #
    #--------------------------------#
    try:
        gtsfiles = [
            PN.DIR1 + gts for gts in os.listdir(PN.DIR1)
            if gts.endswith(".gts")
        ]
    except:
        gtsfiles = []
    # folder exists?
    if ffchecking([PN.DIR1], []) == -1 or len(gtsfiles) == 0:
        print "  - Folder '%s' does not exist or is empty" % PN.DIR1
        print "    * Is '%s' empty?" % PN.UFOLDER
        print "    * Does an old '%s' file exist?" % PN.IFILE0
        print
        exit()

    # List gts files
    print "  - Reading gts files in %s" % PN.DIR1
    print
    print "    * num(gts) = %i\n" % len(gtsfiles)

    #--------------------------------------#
    # Analyze them and create molden files #
    #--------------------------------------#
    print "    * molden files will be generated at %s" % PN.DIR5
    data_gts = {}
    num_old, num_new = 0, 0
    for gtsfile in gtsfiles:
        ctc, gts_tuple, molden, bmolden = gts_data_and_molden(gtsfile)
        # check name
        if not is_string_valid(ctc, extra="_"):
            print "      * invalid name (%s)!! Ignoring data..." % ctc
            continue
        # save data
        data_gts[ctc] = data_gts.get(ctc, []) + [gts_tuple]
        # molden created?
        if bmolden: num_new += 1
        else: num_old += 1
    print
    print "      # of old molden files: %i" % num_old
    print "      # of new molden files: %i" % num_new
    print
    print

    #---------------------#
    # Info about each CTC #
    #---------------------#
    print "  - Listing Structures:"
    print
    ml = max([len(ctc) for ctc in data_gts.keys()])
    for ctc in sorted(data_gts.keys()):
        # data for this CTC
        ctc_itcs   = sorted([ (itc,pgroup2weight(pgroup)) \
                        for (itc,ch,mtp,E,nimag,mformu,pgroup)\
                        in   data_gts[ctc]])
        ctc_ch = data_gts[ctc][0][1]
        ctc_mtp = data_gts[ctc][0][2]
        ctc_type = data_gts[ctc][0][4]
        ctc_mformu = data_gts[ctc][0][5]
        ctc_fscal = 1.0
        ctc_es = [(ctc_mtp, 0.0)]  # electronic states
        ctc_dics = {}
        ctc_diso = {}
        ctc_anh = None
        # already exists?
        if ctc in dctc.keys():
            print("    * %%-%is (already in %%s)" % ml) % (ctc, PN.IFILE1)
            ctc_mformu = dctc[ctc]._mformu
            itcs = sorted(dctc[ctc]._itcs)
            ctc_ch = dctc[ctc]._ch
            ctc_mtp = dctc[ctc]._mtp
            ctc_es = dctc[ctc]._es
            ctc_type = dctc[ctc]._type
            ctc_fscal = dctc[ctc]._fscal
            ctc_dics = dctc[ctc]._dics
            ctc_anh = dctc[ctc]._anh
            ctc_diso = dctc[ctc]._diso
            # to add and to del
            itcs1 = [itc for itc, weight in ctc_itcs]
            itcs2 = [itc for itc, weight in itcs]
            to_add = [itc for itc in itcs1 if itc not in itcs2]
            to_del = [itc for itc in itcs2 if itc not in itcs1]
            for itc in to_add:
                print "      - new itc will be added  : %s" % itc
            for itc in to_del:
                print "      - old itc will be removed: %s" % itc
            # skip if nothing to do
            #if to_add == [] and to_del == []: continue
            # final list
            final_itcs = []
            for itc1, weight1 in ctc_itcs:
                append = True
                for itc2, weight2 in itcs:
                    if itc1 == itc2:
                        final_itcs.append([itc2, weight2])
                        append = False
                        break
                if append: final_itcs.append([itc1, weight1])
            ctc_itcs = final_itcs
        else:
            print("    * %%-%is" % ml) % ctc
        # checking
        isitok = check_gtss(ctc, data_gts)
        if isitok is False:
            sthwrong = True
            wrong4 = True
            continue
        # save data
        CTC = ClusterConf(ctc)
        CTC._mformu = ctc_mformu
        CTC._itcs = ctc_itcs
        CTC._ch = ctc_ch
        CTC._mtp = ctc_mtp
        CTC._es = ctc_es
        CTC._type = ctc_type
        CTC._fscal = ctc_fscal
        CTC._anh = ctc_anh
        CTC._diso = ctc_diso
        CTC._dics = ctc_dics
        dctc[ctc] = CTC
    print

    # check all ctc has gts files
    for ctc in dctc.keys():
        if ctc in data_gts.keys(): continue
        print "  - No gts file found for '%s'" % ctc
        answer = raw_input("    remove it from %s? (Y/n) " % PN.IFILE1).strip()
        print
        if answer.lower() in ["", "y", "yes"]: dctc.pop(ctc)

    print "  - Summary table of structures:"
    ls_struc(dctc)

    #----------------#
    # Write ctc file #
    #----------------#
    print "  - Writing/Updating information in %s" % PN.IFILE1
    RW.write_ctc(dctc, dimasses)
    print

    #----------------#
    # EVERYTHING OK? #
    #----------------#
    if sthwrong:
        print "  - ERROR: It seems that something did not go well"
        if wrong1: print "           * invalid name for some file/folder(s)!"
        if wrong2:
            print "           * reading process failed for a/some file(s) in %s!" % PN.UFOLDER
        if wrong3: print "           * gts file(s) not found!"
        if wrong4:
            print "           * inconsistences in conformational cluster(s)!"
    else:
        print "  - Everything seems to be OK"