示例#1
0
def calc_coefs(itarget, tcommon, drst, pathvars, ltemp, plotfile=None):
    # initialize dcfs
    dcfs = {}
    # sorted points
    points = sd.sorted_points(drst, hess=True)
    # Calculate adiabatic potential
    dMols, Vadi, pathvars = obtain_adipot(tcommon, drst, pathvars)
    # Calculate CVT correction factor
    if pathvars._cvt == "yes":
        dcfs, lscvt, gibbs, lnew = obtain_cvt(dMols,
                                              points,
                                              Vadi,
                                              ltemp,
                                              pathvars,
                                              dcfs=dcfs)
    else:
        lscvt = None
    # Calculate CAG correction factor
    dcfs = obtain_cag(Vadi, ltemp, lscvt, dcfs=dcfs)
    # Calculate SCT correction factor
    if pathvars._sct == "yes":
        # v1 vector along MEP
        if pathvars._v1mode == "grad": dv1 = sct.get_numv1(drst)
        elif pathvars._v1mode == "hess": dv1 = {}
        # calculate SCT coefficient
        dcfs, tplot_sct = obtain_sct(dMols,
                                     points,
                                     Vadi,
                                     ltemp,
                                     dv1,
                                     pathvars,
                                     dcfs=dcfs)
    # save data for plotting
    if plotfile is not None:
        plotdata = {}
        plotdata.update(
            manage_data_for_plot_mep(itarget, drst, pathvars._eref, Vadi))
        if "cvt" in dcfs.keys():
            plotdata.update(
                manage_data_for_plot_cvt(itarget, ltemp, Vadi.xx(),
                                         (gibbs, lnew), lscvt, dcfs["cvt"]))
        if "sct" in dcfs.keys():
            plotdata.update(
                manage_data_for_plot_sct(itarget, dcfs["zct"], dcfs["sct"],
                                         *tplot_sct))
        write_plotfile(plotfile, plotdata)
    # Delete variables
    del dMols
    del Vadi
    # Return data
    return dcfs, pathvars
示例#2
0
                    rcons = dall["rcons"][key]
                    # the fitting
                    khu, dfit = fit2analytic(ltemp, rcons, num)
                    string, lines = PS.sfit_anafit(dfit, key)
                    print_string(string, 9)
                    # save lines for KMC
                    LINES.update({(anatype, rctype, case, rcname, direc): line
                                  for anatype, line in lines.items()})
                    # save data for plotting
                    if case == 0: d4plot[rctype] = (khu, dfit)
                    else: d4plot["anh" + rctype] = (khu, dfit)
                    plotdata.update(
                        manage_data_for_plot_rcons(rcname, direc, ltemp,
                                                   d4plot, units))
                if plotfile is not None and plotdata != {}:
                    write_plotfile(plotfile, plotdata)

    # create loop list
    loop = [(rctype,case) \
            for case    in [0,1] \
            for rctype  in "tst,cvt,tstzct,cvtzct,tstsct,cvtsct".split(",") \
           ]
    # Print lines for KMC
    string = ""
    string += "=================\n"
    string += " FITTING SUMMARY \n"
    string += "=================\n"
    string += "\n"
    for rctype, case in loop:
        lines = ""
        for anatype in [1, 2, 3, 4]:
示例#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)