Exemplo n.º 1
0
def main(idata,status,case):

    stat2check = [2,5]
    mustexist  = []
    tocreate   = []
    #-------------------------------------------------------#
    # 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
    #-------------------------------------------------------#

    # read dofs
    dall, ltemp = RW.read_alldata(dof)
    # get saved reactions
    print_string(PS.skies_summary(dchem,dall),5)

    # Ask user which reactions
    count = 0
    while True:
         # Ask user for reactions
         bool_end,bool_cont,reaction1,reaction2 = ask_for_reactions(dchem)
         print("")
         print("")
         if bool_end : break
         if bool_cont: continue
         kies_from_pair_of_reactions(reaction1,reaction2,ltemp,dchem,dctc,dall)
Exemplo n.º 2
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["-2"] = "ics will be removed"
    msg["-1"] = "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)
    print("")

    #------------------#
    # deal with target #
    #------------------#
    print("   Selected target is '%s'"%target)
    systems = []
    if target == "*": targets = [key for key in dctc.keys() if dctc[key]._type==1]
    else            : targets = [target]
    for target in sorted(targets):
        systems_i = []
        if "." in target: ctc,itc = target.split(".")
        else            : ctc,itc = target, None
        if ctc not in dctc.keys():
           print("    - %s is NOT defined in '%s'\n"%(ctc,PN.IFILE1))
           return
        # itcs in dctc
        dctc_itcs = [itc_i for itc_i,weight_i in dctc[ctc]._itcs]
        # the itcs
        if   itc is      None: itcs = dctc_itcs
        elif itc in dctc_itcs: itcs = [itc]
        else:
            print("    - %s is NOT defined in '%s'\n"%(itc,PN.IFILE1))
            return
        # specific itcs
        if "." in target:
           systems_i.append( ([itc],itc) )
        else:
           dics  = dctc[ctc]._dics
           itcsB = [itc for itc in dics.keys() if itc != "*"]
           itcsA = [itc for itc in itcs        if itc not in itcsB]
           # add data
           if itcsA != []: systems_i.append( (itcsA,"*") )
           for itc in sorted(itcsB): systems_i.append( ([itc],itc) )
        # add data to total
        systems.append( (ctc,systems_i) )
    print("")

    # print name of file to modify
    print("   File to be updated: '%s'"%PN.IFILE1)
    print("")

    #--------------#
    # Generate ics #
    #--------------#
    NEPL = 10
    NOTVALID = [] # updated via global variable
    for ctc,systems_i in systems:
        # Print
        print("   -------------------")
        print("   System: %s"%ctc)
        print("   -------------------")
        print("")
        for itcs,key in systems_i:
            # print conformers
            string = ""
            for idx in range(0,len(itcs),NEPL):
                str_i = ",".join(itcs[idx:idx+NEPL])
                if idx == 0: string +=       "     conformer(s): "+str_i
                else       : string += ",\n"+"                   "+str_i
            print(string)
            print("")
            # gts files
            gtsfiles = [dctc[ctc].gtsfile(itc) for itc in itcs]
            # set of ics
            ics  = dctc[ctc]._dics.get(key,[])
            # negative modes
            if mode == "-2":
               nics = count_ics(ics)
               print("         * %i ics will be removed"%nics)
               print("")
               dctc[ctc]._dics[key] = []
               continue
            if mode == "-1":
               valid,nvdof,nics = check_ics(ics,gtsfiles)
               print("         * "+string_nics(nics,nvdof,valid))
               print("")
               # backward ics
               ics_bw = dctc[ctc]._dicsbw.get(key,None)
               if ics_bw is not None:
                   print("         -- checking backward ics --")
                   valid_bw,nvdof_bw,nics_bw = check_ics(ics_bw,gtsfiles)
                   print("         * "+string_nics(nics_bw,nvdof_bw,valid_bw))
                   print("")
               # forward ics
               ics_fw = dctc[ctc]._dicsfw.get(key,None)
               if ics_fw is not None:
                   print("         -- checking forward ics --")
                   valid_fw,nvdof_fw,nics_fw = check_ics(ics_fw,gtsfiles)
                   print("         * "+string_nics(nics_fw,nvdof_fw,valid_fw))
                   print("")
               continue
            # ics already in file?
            if len(ics) != 0:
               valid,nvdof,nics = check_ics(ics,gtsfiles)
               print("         * ics found!")
               print("           "+string_nics(nics,nvdof,valid))
               if not valid:
                  question = "           remove set and generate new one (y/N)? "
                  answer = input(question).strip().lower()
                  if answer in ["y","yes"]: ics = []
                  else                    : print(""); continue
               print("")
            else:
               nvdof = None
            # is algorithm needed?
            nics = count_ics(ics)
            if nics != nvdof:
               # positive modes
               print("         * applying algorithm...")
               if mode == "1" and len(ics) == 0:
                  ics,nvdof = mode1(gtsfiles)
               if mode == "2":
                  ics,nvdof = mode2(gtsfiles,ics)
               if mode == "3":
                  ics,nvdof = mode3(gtsfiles,ics)
               # check final set after positive modes
               if len(ics) == 0:
                  print("           algorithm failed!")
                  print("")
                  NOTVALID.append( (ctc,itcs) )
                  continue
               valid,nvdof,nics = check_ics(ics,gtsfiles)
               print("           "+string_nics(nics,nvdof,valid))
               print("")
               # update dictionary and rewrite
               dctc[ctc]._dics[key] = ics
               RW.write_ctc(dctc,dimasses)
            else:
               print("         * number(ics) = (vib.DOF); skypping...")
               print("")
        print("   -------------------")
        print("")
        print("")

    # any fail?
    if len(NOTVALID) != 0:
        print("   The algorithm failed for:")
        for ctc,itcs in NOTVALID:
            # print conformers
            string = ""
            for idx in range(0,len(itcs),NEPL):
                str_i = ",".join(itcs[idx:idx+NEPL])
                if idx == 0: string +=       "       * %s: "%ctc           +str_i
                else       : string += ",\n"+"         %s  "%(" "*len(ctc))+str_i
            print(string)
        print("")

    # rewrite again (for mode = -2)
    if mode != "-1": RW.write_ctc(dctc,dimasses)
Exemplo n.º 3
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]

    #--------------------------------#
Exemplo 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, dkmc, 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 = 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(dkmc)
            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":
                dkmc = add_kmc(val, dkmc, 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)
            elif var == "kmc":
                dkmc = mod_kmc(val, dkmc, dchem)
            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)
            elif var == "kmc": dkmc = rm_kmc(val, dkmc)
            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(dkmc)
                if dbool.get("dlevel", False):
                    print("     %s" % PN.IFILE7)
                    RW.write_dlevel(ddlevel)
                print("")
            break
        # user ask for nothing
        else:
            continue