Пример #1
0
 def read_gtsfiles(self, dimasses={}):
     # initialize variables
     self._lpg = []
     self._lV0 = []
     self._molecules = []
     # get list of gts files
     gtsfiles = self.gtsfiles()
     if len(gtsfiles) == 0: return
     # read and save
     for idx, gts in enumerate(gtsfiles):
         # no gts file
         if not os.path.exists(gts):
             self.molecules.append(None)
             self._lpg.append(None)
             self._lV0.append(None)
             continue
         # isotopic modification?
         itc, weight = self._itcs[idx]
         if itc in self._diso.keys(): imods = self._diso[itc]
         elif "*" in self._diso.keys(): imods = self._diso["*"]
         else: imods = {}
         # create molecule
         molecule = Molecule()
         molecule.set_from_gts(gts)
         molecule.apply_imods(imods, dimasses)
         molecule.setup()
         # save molecule
         self._molecules.append(molecule)
         # complete CTC data
         self._lV0.append(float(molecule._V0))
         self._lpg.append(str(molecule._pgroup))
Пример #2
0
def get_mass_ch(target, dctc, dimasses):
    '''
    target may be a compound or a list of compounds.
    If a list ==> returns the sum
    '''
    # initialize
    tot_mass = 0.0
    tot_ch = 0
    # target to list
    target = target2list(target)
    if target is None: return None, None
    # get mass and charge!
    for ctc in target:
        ctc = ctc.split(".")[0]
        if ctc in dctc.keys():
            # generate instance of Molecule
            molecule = Molecule()
            # gts files associated to this ctc
            itc, weight = dctc[ctc]._itcs[0]
            gtsfile = dctc[ctc].gtsfile(itc)
            # isotopic modification
            diso = dctc[ctc]._diso
            if itc in diso.keys(): imod = diso[itc]
            elif "*" in diso.keys(): imod = diso["*"]
            else: imod = None
            # read gts
            molecule.set_from_gts(gtsfile)
            # apply iso
            molecule.apply_imods(imod, dimasses)
            # mass and charge
            tot_mass += float(molecule._mass)
            tot_ch += int(molecule._ch)
        else:
            tot_mass, tot_ch = None, None
    return tot_mass, tot_ch
Пример #3
0
def gts_data_and_molden(gtsfile):
    # read gts and prepare Molecule
    molecule = Molecule()
    molecule.set_from_gts(gtsfile)
    molecule.setup()
    # type of PES stationary point?
    nimag = numimag(molecule._ccfreqs)
    mformu = molecule._mform
    # Get ctc and itc
    ctc, itc, ext = gtsfile.split("/")[-1].split(".")
    # tuple
    gts_tuple = (itc, molecule._ch, molecule._mtp, molecule._V0, nimag, mformu,
                 molecule._pgroup)
    # molden file
    if not os.path.exists(PN.DIR5): os.mkdir(PN.DIR5)
    if is_string_valid(ctc, extra="_"):
        molden = PN.get_gtsmolden(ctc, itc)
        if not os.path.exists(molden):
            print "      creating %s" % molden
            bmolden = True
            write_molden(molden,molecule._xcc,molecule._symbols,\
                         molecule._ccfreqs,molecule._ccFevecs)
        else:
            bmolden = False
    else:
        molden = None
        bmolden = False
    return ctc, gts_tuple, molden, bmolden
Пример #4
0
      def prepare_qrc(self,dchem,dctc,dimasses):
          '''
          also modifies self._qrccase:
              self._qrccase == 0: everything is ok / qrc is not activated
              self._qrccase == 1: no reaction is associated to the TS
              self._qrccase == 2: reaction is not unimolecular
              self._qrccase == 3: ctc for reactant not defined
              self._qrccase == 4: gts file for reactant not found
              self._qrccase == 5: unable to get energy of products
          '''

          # Will qrc be used?
          if self._qrc      is None: return
          if self._reaction is None: self._qrccase = 1; return
          # assert unimolecular
          reactants = dchem[self._reaction][0]
          products  = dchem[self._reaction][2]
          if self._exorgic:
             if len(reactants) != 1: self._qrccase = 2; return
             self._qrcname = reactants[0]
          else:
             if len(products ) != 1: self._qrccase = 2; return
             self._qrcname = products[0]
          if self._V1P is None: self._qrccase = 5; return
          #---------------------------------#
          # Now, generate Molecule instance #
          #---------------------------------#
          ctc, itc = PN.name2data(self._qrcname)
          if ctc not in dctc.keys(): self._qrccase = 3; 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 = dctc[ctc].gtsfile(itc)
          if not os.path.exists(gtsfile): self._qrccase = 4; return
          # Generate Molecule instance
          molecule = Molecule()
          molecule.set_from_gts(gtsfile)
          # apply fscal
          molecule.setvar(fscal=cluster._fscal)
          # apply isotopic masses
          if imods is not None:
             molecule.apply_imods(imods,dimasses)
          # calculate frequencies
          molecule.setup()
          #------------------------------#
          # Prepare list of QRC energies #
          #------------------------------#
          mode , nE      = self._qrc
          self._qrcafreq = molecule._ccfreqs[mode]
          self._qrclE    = [n*HBAR*self._qrcafreq for n in range(nE)]
Пример #5
0
def get_masses(target, dctc, dimasses):
    ctc, itc = PN.name2data(target)
    diso = dctc[ctc]._diso
    if itc in diso.keys(): imod = diso[itc]
    elif "*" in diso.keys(): imod = diso["*"]
    else: imod = None
    if imod is None: return None
    gtsTS = dctc[ctc].gtsfile(itc)
    TS = Molecule()
    TS.set_from_gts(gtsTS)
    TS.apply_imods(imod, dimasses)
    masses = list(TS._masses)
    return masses
Пример #6
0
def gts2molecule(gtsfile):
    # name of file (without path to folder)
    gtsfile_name = gtsname(gtsfile, "name")
    gtsfile_full = gtsname(gtsfile, "full")
    # Get ctc and itc
    ctc, itc, ext = gtsfile_name.split(".")
    # read gts and prepare Molecule
    if not os.path.exists(gtsfile_full): return None, (ctc, itc)
    molecule = Molecule()
    molecule.set_from_gts(gtsfile_full)
    molecule.setup()
    # return data
    return molecule, (ctc, itc)
Пример #7
0
def check_ics_gtsfile(gtsfile,ics):
    # number of internal coordinates
    nics = count_ics(ics)
    # read gts and prepare Molecule
    molecule = Molecule()
    molecule.set_from_gts(gtsfile)
    molecule.setup()
    # number of vibrational degrees of freedom
    nvdof = len(molecule._ccfreqs)
    # enough internal coordinates
    if nics < nvdof: return False, nvdof
    # calc ic-freqs
    molecule.icfreqs(ics)
    # comparison
    valid = same_freqs(molecule._ccfreqs,molecule._icfreqs)
    return valid, nvdof
Пример #8
0
def calc_fwdir(gtsfile):
    '''
    * calculates which internal coordinate changes the most
      in the transition state
    * it also gives the sign of the variation in the forward
      direction of the MEP
    '''
    if (gtsfile is None) or (not os.path.exists(gtsfile)): return (None, None)
    # Generate Molecule from gts file
    molecule = Molecule()
    molecule.set_from_gts(gtsfile)
    # setup (with frequency calculation)
    molecule.setup()
    ic, fwsign = molecule.get_imag_main_dir()
    # return data
    return (ic2string(ic), fwsign)
Пример #9
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.setvar(les=eslist)
    # set frequency scaling
    molecule.setvar(fscal=fscal)
    # setup
    molecule.setup()
    molecule.ana_freqs("cc")
    return molecule
Пример #10
0
def calc_fwdir(target):
    '''
    * calculates which internal coordinate changes the most
      in the transition state
    * it also gives the sign of the variation in the forward
      direction of the MEP
    '''
    # list of gts files associated with target
    gtsfiles = [PN.DIR1+gts for gts in os.listdir(PN.DIR1)\
                if gts.endswith(".gts") and gts.startswith(target)]
    # Generate Molecule from gts file
    molecule = Molecule()
    molecule.set_from_gts(gtsfiles[0])
    # setup (with frequency calculation)
    molecule.setup()
    ic, fwsign = molecule.get_imag_main_dir()
    # return data
    return (ic2string(ic), fwsign)
Пример #11
0
 def return_itcdata(self,ctc,itc):
     # generate instance of Molecule
     molecule = Molecule()
     # gts files associated to this ctc
     gtsfile  = self._dctc[ctc].gtsfile(itc)
     # isotopic modification
     diso = self._dctc[ctc]._diso
     if   itc in diso.keys(): imod = diso[itc]
     elif "*" in diso.keys(): imod = diso["*"]
     else                   : imod = None
     # read gts
     molecule.set_from_gts(gtsfile)
     # apply iso
     molecule.apply_imods(imod,self._dimasses)
     # mass, charge, V0
     mass   = float(molecule._mass)
     charge = int(molecule._ch)
     V0     = float(molecule._V0)
     return mass, charge, V0
Пример #12
0
def highlevel_sp(ctc, itc, keyHL, gtsfile, software, dtesHL, dhighlvl):
    # is calculation needed?
    if keyHL in dhighlvl.keys(): return None
    # folder for calculation and file name
    TMP = PN.TMPHLi % keyHL
    mname = "%s.%s" % (keyHL, "sp")
    # Function for calculation and template
    spc_fnc = get_spc_fnc(software)
    tes = dtesHL.get(software, {}).get(ctc, None)
    if tes is None: raise Exc.NoTemplateGiven(Exception)
    # extra-arguments for spc_fnc
    clean = False  # do not delete files
    bhess = False  # do not calculate hessian (no needed actually)
    eargs = (tes, TMP, clean)
    # Read gts file (Molecule instance)
    molecule = Molecule()
    molecule.set_from_gts(gtsfile)
    # HL-calculation
    out_spc = spc_fnc(molecule._xcc, molecule._symbols, bhess, mname, eargs)
    return out_spc[4]
Пример #13
0
 def get_masses_charges(self, dimasses={}):
     for ctc, itcs, ms in self._itcs.values():
         # select first itc
         itc, weight = itcs[0]
         # generate instance of Molecule
         molecule = Molecule()
         # read gts
         gtsfile = self._gtsfile[(ctc, itc)]
         molecule.set_from_gts(gtsfile)
         # isotopic modification
         diso = self._disos[ctc]
         if itc in diso.keys(): imod = diso[itc]
         elif "*" in diso.keys(): imod = diso["*"]
         else: imod = None
         molecule.apply_imods(imod, dimasses)
         # data to save: mass & charge
         mass = float(molecule._mass)
         charge = int(molecule._ch)
         # save data
         self._massch[ctc] = (mass, charge)
Пример #14
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
Пример #15
0
def deal_with_path(target, dlevel, software, ltemp, dctc, pathvars, dtes,
                   dchem, dhighlvl, dimasses):
    dof = PN.get_dof(dlevel)
    plotfile = PN.get_plf(dlevel)
    # gts file for this TS
    ctc, itc = PN.name2data(target)
    gtsTS = dctc[ctc].gtsfile(itc)
    # rotational symmetry
    moleculeTS = Molecule()
    moleculeTS.set_from_gts(gtsTS)
    symmetry = str(moleculeTS._pgroup), int(moleculeTS._rotsigma)
    # temporal folder
    TMP = PN.TMPi % (target)
    # if exists,remove content (unless keeptmp is activated)
    # (to avoid reading old files from different levels of calculation)
    if os.path.exists(TMP) and not pathvars._keeptmp:
        shutil.rmtree(TMP, ignore_errors=True)
    # split target
    ctc, itc = PN.name2data(target)
    # name of rst file
    rstfile = PN.get_rst(ctc, itc)
    # tuple software
    tes = dtes.get(software, {}).get(ctc, None)
    tsoftw = (software, tes)
    # internal coordinates
    if itc in dctc[ctc]._dics.keys(): ics = dctc[ctc]._dics[itc]
    elif "*" in dctc[ctc]._dics.keys(): ics = dctc[ctc]._dics["*"]
    else: ics = None
    if itc in dctc[ctc]._dicsbw.keys(): icsbw = dctc[ctc]._dicsbw[itc]
    elif "*" in dctc[ctc]._dicsbw.keys(): icsbw = dctc[ctc]._dicsbw["*"]
    else: icsbw = None
    if itc in dctc[ctc]._dicsfw.keys(): icsfw = dctc[ctc]._dicsfw[itc]
    elif "*" in dctc[ctc]._dicsfw.keys(): icsfw = dctc[ctc]._dicsfw["*"]
    else: icsfw = None
    # path variables
    pathvars.set_ics(ics, icsbw, icsfw)  # before setup3!!
    pathvars.apply_specific(itc)
    pathvars.setup1()
    pathvars.setup2()
    pathvars.setup3()
    # Set Eref (from reaction)
    pathvars.set_eref_from_reaction(target, dchem, dof)
    # Quantum reaction coordinate qrc
    pathvars.prepare_qrc(dchem, dctc, dimasses)
    # frequency scaling factor
    pathvars._freqscal = float(dctc[ctc]._fscal)
    # if dlevel --> no convergence and dlevel data
    if dlevel:
        exception = Exc.NoDLEVELdata(Exception)
        pathvars._scterr = None
        keydhl = "%s.%s.path" % (ctc, itc)
        if keydhl not in dhighlvl.keys():
            # maybe only TS
            keydhl = "%s.%s" % (dctc[ctc]._root, itc)
            if keydhl in dhighlvl.keys():
                dictE = {0.0: dhighlvl[keydhl]}
            else:
                global WARNINGS
                WARNINGS.append("No high-level data for %s" % target)
                raise exception
        else:
            dictE = dhighlvl[keydhl]
        pathvars._dlevel = dictE
    # LOGGER
    pof = PN.get_pof(dlevel, "path", target)
    sys.stdout = Logger(pof, "w", True)
    sys.stdout.writeinfile(PS.init_txt())
    #string
    fncs.print_string(PS.smep_title(target, pathvars, pof), 2)
    # Was previously converged???
    ffloat = "%.3f"
    drstconv = RW.read_rstconv()
    if target in drstconv.keys() and not dlevel and os.path.exists(rstfile):
        lowtemp, useics, scterr, converged = drstconv[target]
        b0 = (converged == "yes")
        b1 = (pathvars._useics == useics)
        b2 = (ffloat % pathvars._scterr == ffloat % scterr)
        b3 = (ffloat % min(ltemp) == ffloat % lowtemp)
        if b0 and b1 and b2 and b3:
            pathvars._scterr = None
            fncs.print_string("THIS PATH IS STORED AS CONVERGED!\n", 4)
            tpath, tcommon, drst = ff.read_rst(rstfile)
            lbw, lfw, sbw, sfw, V0bw, V0fw = sd.rstlimits(drst)
            pathvars._sbw = sbw
            pathvars._sfw = sfw
            del drst
    #----------------#
    # calculate path #
    #----------------#

    # 1. Only MEP
    if not pathvars._beyondmep:
        common, drst, pathvars = calc_mep(target, gtsTS, pathvars, tsoftw, TMP)
        dcoefs = {}
        del drst
        # raise error
        raise Exc.OnlyMEP(Exception)

    # 2. MEP expanded till SCT convergence
    elif pathvars.sct_convergence():
        dcoefs, converged = get_path_sctconv(target, gtsTS, pathvars, tsoftw,
                                             ltemp, TMP, symmetry, plotfile)
        # save convergence in file!
        drstconv = RW.read_rstconv()
        if converged:
            drstconv[target] = (min(ltemp), pathvars._useics, pathvars._scterr,
                                "yes")
        else:
            drstconv[target] = (min(ltemp), pathvars._useics, pathvars._scterr,
                                "no")
        RW.write_rstconv(drstconv)

    # 3. Coefs with the current MEP extension
    else:
        tcommon, drst, pathvars = calc_mep(target, gtsTS, pathvars, tsoftw,
                                           TMP)
        dcoefs, pathvars, palpha, pomega = calc_coefs(target, tcommon, drst,
                                                      pathvars, ltemp,
                                                      symmetry, plotfile)
        del drst

    # print summary with the coefficients
    fncs.print_string(PS.spath_allcoefs(ltemp, dcoefs), 3)
    # return data
    return dcoefs, pathvars
Пример #16
0
def deal_with_folder(folder, dtrack, dctc):
    '''
    deal with an electronic structure (es) file of a subfolder inside UDATA/
    '''

    print("  - Reading files in: %s" % (PN.UFOLDER + folder))

    # Get CTC
    ctc = folder[:-1]

    # Check CTC name
    if not fncs.is_string_valid(ctc, extra="_"):
        print("    '%s' is an invalid name for a CTC!\n" % ctc)
        WRONG[1] = True
        return dtrack, dctc

    # Files for each conformer of the CTC
    esfiles = sorted([folder+esfile for esfile in os.listdir(PN.UFOLDER+folder) \
                                    if  esfile.split(".")[-1].lower() in EXTENSIONS])
    if len(esfiles) == 0:
        print("    empty folder...\n")
        WRONG[2] = True
        return dtrack, dctc

    # initialize CTC
    CTC = ClusterConf(ctc)
    ctc_vars = None

    # GTS generation
    count = 0
    cache = []
    remove = False
    for idx, esfile in enumerate(esfiles):

        # previously assignated?
        gtsfile = dtrack.get(esfile, None)
        if gtsfile is not None and os.path.exists(PN.DIR1 + gtsfile):
            # read file
            print("    %s [gts exists: %s]" % (esfile, PN.DIR1 + gtsfile))
            molecule = Molecule()
            molecule.set_from_gts(PN.DIR1 + gtsfile)
            molecule.setup()
            status = 2
            # add data to cache
            V0 = molecule._V0
            ch = molecule._ch
            mtp = molecule._mtp
            nimag = int(fncs.numimag(molecule._ccfreqs))
            mform = molecule._mform
            pgroup = molecule._pgroup
            cache_i = [esfile, gtsfile, V0, ch, mtp, nimag, mform, pgroup]
        else:
            prov_gts, count = temporal_gtsname(ctc, count)
            status, cache_i = userfile_to_gtsfile(esfile, prov_gts)
        # save cache_i
        cache.append(cache_i)

        # use first conformer to update ctc_vars
        if ctc_vars is None: ctc_vars = cache_i[3:7]

        # Check reading and consistence within CTC
        if status == 0:
            print("    %s [reading failed]" % esfile)
            print("    -- STOPPED --")
            WRONG[3], remove = True, True
        elif status == -1:
            print("    %s [Fcc NOT found] " % esfile)
            print("    -- STOPPED --")
            WRONG[4], remove = True, True
        elif ctc_vars != cache_i[3:7]:
            print("    %s [inconsistence found] " % esfile)
            print("    -- STOPPED --")
            WRONG[5], remove = True, True
            print_table_ufiles(cache)
        elif ctc_vars[2] not in (0, 1):
            print("    %s [unexpected number of imag. freqs.] " % esfile)
            print("    -- STOPPED --")
            WRONG[6], remove = True, True
            print_table_ufiles(cache)
        elif status == 1:
            print("    %s [ok]            " % esfile)
        # sth wrong so we have to remove?
        if remove: break
    print()

    # Remove files if sth wrong
    if remove:
        remove_provisionals([cache_i[1] for cache_i in cache])
        return dtrack, dctc

    # sort cache by energy
    cache.sort(key=lambda x: x[2])
    # already in dctc
    if ctc in dctc: CTC0 = dctc.pop(ctc)
    else: CTC0 = None
    # Update CTC instance
    CTC.setvar("ch", ctc_vars[0], "int")
    CTC.setvar("mtp", ctc_vars[1], "int")
    CTC.setvar("type", ctc_vars[2], "int")
    CTC.setvar("mformu", ctc_vars[3], "str")
    CTC._es = [(ctc_vars[1], 0.0)]
    # Rename gtsfiles
    itc = 0
    for idx, cache_i in enumerate(cache):
        prov_gts = cache_i[1]
        if is_provisional(prov_gts):
            new_gts, itc = rename_files(ctc, prov_gts, itc)
            itc_i = itc
            # update dtrack
            dtrack[cache_i[0]] = new_gts
            # update gtsfile in cache
            cache[idx][1] = new_gts
        else:
            itc_i = prov_gts.split(".")[-2]
        # weight
        weight = 1
        if CTC0 is not None: weight = max(CTC0.get_weight(itc_i), weight)
        # update CTC
        CTC.add_itc(itc_i, cache_i[2], cache_i[7], weight)
    CTC.find_minV0()
    # update with info of CTC0
    if CTC0 is not None:
        CTC._es = CTC0._es
        CTC._fscal = CTC0._fscal
        CTC._dics = CTC0._dics
        CTC._dicsfw = CTC0._dicsfw
        CTC._dicsbw = CTC0._dicsbw
        CTC._diso = CTC0._diso
        CTC._anh = CTC0._anh

    # update dctc
    dctc[ctc] = CTC
    # Print info of this CTC
    print_ctc_info(CTC)
    # Delete cache
    del cache
    # Return data
    return dtrack, dctc
Пример #17
0
def obtain_mep(target, gtsTS, pathvars, tsoftware, TMP):
    ctc, itc = PN.name2data(target)

    # create folder now and not in the parallel process
    if not os.path.exists(TMP):
        try:
            os.mkdir(TMP)
        except:
            pass

    # 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)

    # read rst
    try:
        tpath2, tcommon2, drst = ff.read_rst(rstfile)
    except:
        exception = Exc.RstReadProblem(Exception)
        exception._var = rstfile
        raise exception
    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]):
            fncs.print_string(
                "'fwdir' variable differs from MEP direction in rst file!", 4)
            fncs.print_string("* modifying rst internal dictionary...", 8)
            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
            fncs.print_string("* rewriting rst file...", 8)
            ff.write_rst(rstfile, tpath2, tcommon2, drst)

    # Extension of MEP in rst is bigger
    if drst != {}:
        lbw, lfw, sbw, sfw, V0bw, V0fw = 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.setvar(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)

    # data for single-point calculation
    frozen = RW.read_frozen(gtsTS + ".frozen")
    oniom_layers = (list(pathvars._oniomh), list(pathvars._oniomm),
                    list(pathvars._onioml))
    spc_args = (tes, TMP, False, frozen, oniom_layers)
    spc_fnc = get_spc_fnc(software)

    #------------#
    # First step #
    #------------#
    print("")
    fncs.print_string("Performing first step of MEP...", 4)
    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)

    # oniom layers?
    oniom_ok = pathvars.isONIOMok(ts._natoms, software)
    layers = pathvars.get_layers()
    fncs.print_string(PS.smep_oniom(layers, ts._natoms, software), 8)
    if not oniom_ok: raise Exc.WrongONIOMlayers(Exception)

    # Print MEP info
    fncs.print_string(PS.smep_first(ts._symbols, ts._xms, v0, v1, layers), 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("")
    fncs.print_string("Calculating MEP...", 4)
    print("")
    fncs.print_string(
        "* REMEMBER: data of each step will be saved at %s" % rstfile, 7)
    fncs.print_string("            a summary will be printed when finished", 7)
    # 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
    fncs.print_string("* FINISHED!", 7)
    print("")
    drst.update(drstbw)
    drst.update(drstfw)
    points = [TSLABEL] + pointsbw + pointsfw
    # empty variables
    del drstbw, pointsbw
    del drstfw, pointsfw
    # Rewrite rst
    fncs.print_string("* (re)writing file: %s (sorted version)" % rstfile, 7)
    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, V0bw, V0fw = sd.rstlimits(drst)
    convbw, l1bw, l2bw = convbw
    convfw, l1fw, l2fw = convfw
    if l1bw + l1fw != "":
        fncs.print_string("* MEP convergence criteria (epse and epsg):", 7)
        print("")
        if l1bw != "": fncs.print_string("%s" % l1bw, 9)
        if l2bw != "": fncs.print_string("%s" % l2bw, 9)
        if l1fw != "": fncs.print_string("%s" % l1fw, 9)
        if l2fw != "": fncs.print_string("%s" % l2fw, 9)
        print("")
        if convbw:
            pathvars.converged_in_bw(sbw)
            fncs.print_string("CRITERIA FULFILLED in backward dir.!", 9)
            fncs.print_string("path stopped at sbw = %+8.4f bohr" % sbw, 9)
            print("")
        if convfw:
            pathvars.converged_in_fw(sfw)
            fncs.print_string("CRITERIA FULFILLED in forward dir.!", 9)
            fncs.print_string("path stopped at sfw = %+8.4f bohr" % sfw, 9)
            print("")
    # write molden file
    fncs.print_string("* writing file: %s" % xyzfile, 7)
    ff.rst2xyz(rstfile, xyzfile, onlyhess=True)
    print("")
    # reference energy
    if pathvars._eref is None: pathvars._eref = V0bw
    # return data
    return tcommon, drst, pathvars
Пример #18
0
 def set_from_gtsfiles(self, gtsfiles):
     '''
       returns status, string
       status = -1 ==> inconsistences between conformers
       status =  0 ==> one or several gts files do not exist
       status =  1 ==> everything is ok
       string is "" except for status = -1
       '''
     self._itcs = []
     self._lpg = []
     lch = []
     lmtp = []
     limag = []
     lmformu = []
     self._lV0 = []
     if len(gtsfiles) == 0: return 0, None
     # save lists
     for gts in gtsfiles:
         ctc, itc, ext = gts.split("/")[-1].split(".")
         self._root = ctc
         if not os.path.exists(gts): return 0, ""
         molecule = Molecule()
         molecule.set_from_gts(gts)
         molecule.setup()
         # save molecule
         self._molecules.append(molecule)
         # complete CTC data
         self._lV0.append(float(molecule._V0))
         self._lpg.append(str(molecule._pgroup))
         self._itcs.append((itc, pgroup2weight(molecule._pgroup)))
         # save some special data of this gts
         lch.append(int(molecule._ch))
         lmtp.append(int(molecule._mtp))
         limag.append(int(numimag(molecule._ccfreqs)))
         lmformu.append(str(molecule._mform))
     # check
     len1 = len(list(set(lch)))
     len2 = len(list(set(lmtp)))
     len3 = len(list(set(limag)))
     len4 = len(list(set(lmformu)))
     if len1 * len2 * len3 * len4 != 1:
         # table head and division
         ml1 = max([len(name) for name in lmformu] + [7])
         ml2 = max([len(name) for name in gtsfiles] + [10])
         line_format = " %%-%is | %%-%is | %%-%is | %%-%is | %%-%is | %%-%is " % (
             5, 6, 3, 7, ml1, ml2)
         thead = line_format % ("itc", "charge", "mtp", "n.imag.",
                                "m.form.", "gts file")
         tdivi = "-" * len(thead)
         # start string
         string = "Main properties of each conformer in '%s'\n" % self._ctc
         string += "   " + tdivi + "\n"
         string += "   " + thead + "\n"
         string += "   " + tdivi + "\n"
         for idx, (itc, weight) in enumerate(self._itcs):
             col1 = itc
             col2 = "%i" % lch[idx]
             col3 = "%i" % lmtp[idx]
             col4 = "%i" % limag[idx]
             col5 = lmformu[idx]
             col6 = gtsfiles[idx]
             ldata = (col1, col2, col3, col4, col5, col6)
             string += "   " + line_format % ldata + "\n"
         string += "   " + tdivi + "\n"
         return -1, string
     else:
         self._mformu = lmformu[0]
         self._ch = lch[0]
         self._mtp = lmtp[0]
         self._type = limag[0]
         self._V0 = min(self._lV0)
         self._es = [(self._mtp, 0.0)]
         return 1, ""