Exemplo n.º 1
0
def molecule_prep(gts, eslist=[], tiso=None, fscal=1.0):
    # generate instance of Molecule
    molecule = Molecule()
    # read gts
    molecule.set_from_gts(gts)
    # masses
    if tiso is not None:
        imods, imasses = tiso
        molecule.apply_imods(imods, imasses)
    # electronic states
    molecule.mod_les(eslist)
    # set frequency scaling
    molecule.set_fscal(fscal)
    # setup
    molecule.setup()
    molecule.ana_freqs("cc")
    return molecule
Exemplo n.º 2
0
 def prepare_qrc(self, dchem, dctc, dimasses):
     # Will qrc be used?
     if self._reaction is None: return
     if self._qrc is None: return
     reactants = dchem[self._reaction][0]
     if len(reactants) != 1: return
     # generate Molecule instance
     reactant = reactants[0]
     ctc, itc = PN.name2data(reactant)
     if ctc not in dctc.keys(): return
     cluster = dctc[ctc]
     if itc is None: itc = cluster._itcs[0][0]
     if itc in cluster._diso.keys(): imods = cluster._diso[itc]
     elif "*" in cluster._diso.keys(): imods = cluster._diso["*"]
     else: imods = None
     gtsfile = PN.get_gts(ctc, itc)
     if not os.path.exists(gtsfile): raise Exception
     # Generate Molecule instance
     reactant = Molecule()
     reactant.set_from_gts(gtsfile)
     # apply fscal
     reactant.set_fscal(fscal=cluster._fscal)
     # apply isotopic masses
     if imods is not None:
         reactant.apply_imods(imods, dimasses)
     # calculate frequencies
     reactant.setup()
     mode, nE = self._qrc
     Vadi = reactant._V0
     for idx, afreq in enumerate(reactant._ccfreqs):
         if idx == mode: continue
         Vadi += afreq2zpe(afreq)
     afreq = reactant._ccfreqs[mode]
     listE = [
         Vadi + (n + 0.5) * HBAR * afreq - self._eref for n in range(nE)
     ]
     self._qrclE = listE
     self._qrcafreq = afreq
Exemplo n.º 3
0
def obtain_mep(target, gtsTS, pathvars, tsoftware, TMP):
    ctc, itc = PN.name2data(target)

    # Files
    rstfile = PN.get_rst(ctc, itc)
    xyzfile = PN.get_rstxyz(ctc, itc)

    # print
    software, tes = tsoftware
    fncs.print_string(PS.smep_init(target,software,pathvars._paral,pathvars.tuple_first(),\
                 pathvars.tuple_sdbw(),pathvars.tuple_sdfw()),4)
    fncs.print_string(PS.smep_ff(TMP, PN.DIR4, PN.DIR5, rstfile, xyzfile), 4)

    # data for single-point calculation
    spc_args = (tes, TMP, False)
    spc_fnc = get_spc_fnc(software)

    # read rst
    tpath2, tcommon2, drst = ff.read_rst(rstfile)
    fncs.print_string(PS.smep_rst(rstfile, drst), 4)

    # correct MEP direction?
    if TSLABEL in drst.keys():
        ii_s, ii_V, ii_x, ii_g, ii_F, ii_v0, ii_v1, ii_t = drst[TSLABEL]
        ii_ic, ii_sign = pathvars._fwdir
        if not intl.ics_correctdir(ii_x, ii_v0, ii_ic, ii_sign, tcommon2[3],
                                   tcommon2[4]):
            print "    'fwdir' variable differs from MEP direction in rst file!"
            print "        * modifying rst internal dictionary..."
            new_drst = {}
            for key in drst.keys():
                ii_s, ii_V, ii_x, ii_g, ii_F, ii_v0, ii_v1, ii_t = drst[key]
                ii_s = -ii_s
                if ii_v0 is not None: ii_v0 = [-ii for ii in ii_v0]
                if ii_v1 is not None: ii_v1 = [-ii for ii in ii_v1]
                if "bw" in key: newkey = key.replace("bw", "fw")
                else: newkey = key.replace("fw", "bw")
                new_drst[newkey] = (ii_s, ii_V, ii_x, ii_g, ii_F, ii_v0, ii_v1,
                                    ii_t)
            drst = new_drst
            del new_drst
            print "        * rewriting rst file..."
            ff.write_rst(rstfile, tpath2, tcommon2, drst)

    # Extension of MEP in rst is bigger
    if drst != {}:
        lbw, lfw, sbw, sfw, Ebw, Efw = sd.rstlimits(drst)
        pathvars._sbw = min(pathvars._sbw, sbw)
        pathvars._sfw = max(pathvars._sfw, sfw)

    # Read gts
    ts = Molecule()
    ts.set_from_gts(gtsTS)
    # scaling of frequencies
    ts.set_fscal(pathvars._freqscal)
    # apply iso mod
    if pathvars._masses is not None: ts.mod_masses(pathvars._masses)
    # setup
    ts.setup(mu=pathvars._mu)
    ts.ana_freqs(case="cc")

    fncs.print_string(PS.smep_ts(ts), 4)

    tcommon = (ts._ch, ts._mtp, ts._atnums, ts._masses, ts._mu)
    compare_tpath(pathvars.tuple_rst(), tpath2, rstfile)
    compare_tcommon(tcommon, tcommon2, rstfile)

    #------------#
    # First step #
    #------------#
    print
    print "    Performing first step of MEP..."
    print
    inputvars = (ts._xcc,ts._gcc,ts._Fcc,ts._symbols,ts._masses,pathvars.tuple_first(),\
                 spc_fnc,spc_args,drst,pathvars._paral)
    (xms, gms, Fms), (v0, v1), (xms_bw, xms_fw) = sd.mep_first(*inputvars)
    s1bw = -float(pathvars._ds)
    s1fw = +float(pathvars._ds)
    fncs.print_string(PS.smep_first(ts._symbols, ts._xms, v0, v1), 8)

    # write rst file
    if TSLABEL not in drst.keys():
        drst[TSLABEL] = (0.0, ts._V0, xms, gms, Fms, v0, v1, None)
        ff.write_rst_head(rstfile, pathvars.tuple_rst(), tcommon)
        ff.write_rst_add(rstfile, TSLABEL, drst[TSLABEL])

    #------------#
    # The MEP    #
    #------------#
    print
    print "    Calculating MEP..."
    print
    print "       * REMEMBER: data of each step will be saved at %s" % rstfile
    print "                   a summary will be printed when finished"
    # preparation
    xcc_bw = fncs.ms2cc_x(xms_bw, ts._masses, pathvars._mu)
    xcc_fw = fncs.ms2cc_x(xms_fw, ts._masses, pathvars._mu)
    args_bw = ((xcc_bw,s1bw,ts._symbols,ts._masses,pathvars.tuple_sdbw(),\
                spc_fnc,spc_args,drst,ts._Fms,"bw%i") , rstfile,drst)
    args_fw = ((xcc_fw,s1fw,ts._symbols,ts._masses,pathvars.tuple_sdfw(),\
                spc_fnc,spc_args,drst,ts._Fms,"fw%i") , rstfile,drst)
    # execution
    if pathvars._paral:
        import multiprocessing
        pool = multiprocessing.Pool()
        out = [
            pool.apply_async(onesidemep, args=args)
            for args in [args_bw, args_fw]
        ]
        drstbw, pointsbw, convbw = out[0].get()
        drstfw, pointsfw, convfw = out[1].get()
        del out
        # clean up pool
        pool.close()
        pool.join()
    else:
        drstbw, pointsbw, convbw = onesidemep(*args_bw)
        drstfw, pointsfw, convfw = onesidemep(*args_fw)
    # update drst
    print "       * FINISHED!"
    print
    drst.update(drstbw)
    drst.update(drstfw)
    points = [TSLABEL] + pointsbw + pointsfw
    # empty variables
    del drstbw, pointsbw
    del drstfw, pointsfw
    # Rewrite rst
    print "       * (re)writing file: %s (sorted version)" % rstfile
    ff.write_rst(rstfile, pathvars.tuple_rst(), tcommon, drst)
    print
    ## restrict drst to points
    #if restrict: drst = {point:drst[point] for point in points}
    # Get limits of rst
    lbw, lfw, sbw, sfw, Ebw, Efw = sd.rstlimits(drst)
    convbw, l1bw, l2bw = convbw
    convfw, l1fw, l2fw = convfw
    if l1bw + l1fw != "":
        print "       * EPS criteria (epse and epsg):"
        print
        if l1bw != "": print "         %s" % l1bw
        if l2bw != "": print "         %s" % l2bw
        if l1fw != "": print "         %s" % l1fw
        if l2fw != "": print "         %s" % l2fw
        print
        if convbw:
            pathvars.converged_in_bw(sbw)
            print "         CRITERIA FULFILLED in backward dir.!"
            print "         path stopped at sbw = %+8.4f bohr" % sbw
            print
        if convfw:
            pathvars.converged_in_fw(sfw)
            print "         CRITERIA FULFILLED in forward dir.!"
            print "         path stopped at sfw = %+8.4f bohr" % sfw
            print
    # write molden file
    print "       * writing file: %s" % xyzfile
    ff.rst2xyz(rstfile, xyzfile, onlyhess=True)
    print
    # reference energy
    if pathvars._eref is None: pathvars._eref = Ebw
    # return data
    return tcommon, drst, pathvars