def get_reaction_energies(TS, dchem, dof): ''' * checks the reactions which involved the target transition state (TS) in order to extract V0 and V1 for reactants and products ''' # initialize variables reaction = None Eref = None V0R = None V0P = None V1R = None V1P = None GibbsR = None # select reaction ctc, itc = PN.name2data(TS) for rname in dchem.keys(): Rs, ts, Ps = dchem[rname] ctc2, itc2 = PN.name2data(ts) if ctc == ctc2: reaction = rname if itc == itc2: break # no reaction? if reaction is None: return reaction, V0R, V0P, V1R, V1P, GibbsR # read dof dall = RW.read_alldata(dof)[0] # get energy from reaction Rs = dchem[reaction][0] Ps = dchem[reaction][2] # reactants if len(Rs) != 0: V0R, V1R = 0.0, 0.0 for R in Rs: ctc, itc = PN.name2data(R) if itc is None: key = PN.struckey(ctc, "msho") else: key = R data = dall["pfn"].get(key, None) if data is None: V0R, V1R = None, None break V0, V1, pfns = data V0R += V0 V1R += V1 # Gibbs energy if key in dall["gibbs"].keys(): gibbs = dall["gibbs"][key] if GibbsR is None: GibbsR = gibbs else: GibbsR = [gi + gj for gi, gj in zip(GibbsR, gibbs)] # products if len(Ps) != 0: V0P, V1P = 0.0, 0.0 for P in Ps: ctc, itc = PN.name2data(P) if itc is None: key = PN.struckey(ctc, "msho") else: key = P data = dall["pfn"].get(key, None) if data is None: V0P, V1P = None, None break V0, V1, pfns = data V0P += V0 V1P += V1 # Output return reaction, V0R, V0P, V1R, V1P, GibbsR
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] #--------------------------------# # Calculations for each reaction # #--------------------------------# print " Analytic expressions:" print print " (1) k = A exp(-B/T) " print " (2) k = A*T^n*exp(-B/T) " print " (3) k = A*(T/Tr)^n*exp(-B/T) " print " (4) k = A*(T/Tr)^n*exp(-B*(T+T0)/(T^2+T0^2))" print plotdata = {} LINES = {} for rcname in targets: Rs, TS, Ps = dchem[rcname]
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)