def readfile_xyz(fname): string = "" zmat, symbols, masses = ff.read_xyz_zmat(fname) xcc = intl.zmat2xcc(zmat[0],zmat[1]) # Print more information ndummy = symbols.count("XX") natoms = len(symbols)-ndummy # without dummies symbols_wo , xcc_wo = fncs.clean_dummies(symbols,xcc=xcc) symbols_wo , masses_wo = fncs.clean_dummies(symbols,masses=masses) molecule = Molecule() molecule.setvar(xcc=xcc_wo,symbols=symbols_wo,masses=masses_wo,ch=0,mtp=1) molecule.prepare() molecule.setup() string += "Molecular formula : %s\n"%molecule._mform string += "Number of atoms : %i\n"%natoms string += "Number of dummy atoms : %i\n"%ndummy string += "Vibrational d.o.f. : %i\n"%molecule._nvdof string += "\n" # Cartesian Coordinates string += "Cartesian coordinates (in Angstrom):\n" sidx = "%%%si"%len(str(len(symbols))) at_wo = -1 dwithout = {} for at,symbol in enumerate(symbols): xi,yi,zi = [value*pc.ANGSTROM for value in xcc[3*at : 3*at+3]] mass = masses[at]*pc.AMU datainline = (sidx%(at+1),symbol,xi,yi,zi,mass) if symbol != "XX": at_wo += 1; dwithout[at] = at_wo else: dwithout[at] = None string += "[%s] %-2s %+12.7f %+12.7f %+12.7f (%7.3f amu)\n"%datainline string += "\n" return xcc,zmat,symbols,masses,(dwithout,molecule,natoms,ndummy),string
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)]
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
def log_data(log, inpvars, fscal, folder="./"): if inpvars._ts: fmode = -1 else: fmode = 0 # name from log name = log.split(".")[-2] point = TorPESpoint(name, inpvars._tlimit) # Read log file logdata = gau.read_gaussian_log(folder + log) # prepare data logdata = prepare_log_data(logdata) ch, mtp, V0, symbols, symbols_wo, xcc_wo, gcc_wo, Fcc_wo, lzmat, zmatvals = logdata # string for fccards string_fccards = gau.get_fccards_string(gcc_wo, Fcc_wo) # generate Molecule instance molecule = Molecule() molecule.setvar(xcc=xcc_wo, Fcc=Fcc_wo, V0=V0) molecule.setvar(fscal=fscal) molecule.setvar(symbols=symbols_wo) molecule.setvar(ch=ch, mtp=mtp) molecule.prepare() molecule.setup() molecule.ana_freqs() # Calculate partition functions for the temperatures qtot, V1, qis = molecule.calc_pfns(inpvars._temps, fmode=fmode) qtr, qrot, qvib, qele = qis Qrv = np.array([xx * yy for xx, yy in zip(qrot, qvib)]) # Calculate partition functions at target temperature qtot, V1, qis = molecule.calc_pfns([inpvars._temp], fmode=fmode) # remove rotsigma for Gibbs gibbs = V1 - pc.KB * inpvars._temp * np.log(qtot[0] * molecule._rotsigma) # imaginary frequency if len(molecule._ccimag) == 0: ifreq = None elif len(molecule._ccimag) == 1: ifreq = [ifreq for ifreq, ivec in list(molecule._ccimag)][0] else: ifreq = None # weight for this conformer if inpvars._enantio and molecule._pgroup.lower() == "c1": weight = 2 else: weight = 1 # pack and return data conf_tuple = (point, V0, V1, gibbs, weight, Qrv, ifreq, lzmat, zmatvals, log) return conf_tuple, symbols, string_fccards
def generate_gts_file(esfile, gtsfile, read_method): ''' Generate gts file (and molden & frozen files) from given electronic structure (ES) file; The ES file is read using read_method ''' # Extra files that (maybe) will be generated file_frozen = gtsfile + ".frozen" # only if any frozen atom file_molden = gtsfile + ".molden" # molden file # read file xcc, atonums, ch, mtp, E, gcc, Fcc, masses, clevel = read_method( PN.UFOLDER + esfile)[0:9] # clevel is not really clevel when using read_gtsfile as read_method if read_method == read_gtsfile: clevel = "" # symbols and atonums symbols, atonums = fncs.symbols_and_atonums(atonums) # is masses available? if masses is None or len(masses) == 0 or sum(masses) == 0.0: masses = atonums2masses(atonums) # is Fcc available? if len(atonums) != 1 and (Fcc is None or len(Fcc) == 0): status = -1 cache = None molec = None else: # Generate Molecule instance molec = Molecule() molec.setvar(xcc=xcc, gcc=gcc, Fcc=Fcc) molec.setvar(atonums=atonums, masses=masses) molec.setvar(ch=ch, mtp=mtp, V0=E) molec.prepare() # Deal with frozen atoms [atom i is frozen if Fij=0 forall j) frozen_xcc, frozen_symbols = molec.remove_frozen() # Calculate point group (must be done after remove frozen) molec.calc_pgroup(force=True) # Deal with Hessian molec.setup() # write gts file molec.genfile_gts(PN.DIR1 + gtsfile, level=clevel) status = 1 # write frozen (if there are frozen atoms) RW.write_frozen(PN.DIR1 + file_frozen, frozen_xcc, frozen_symbols) # write molden file idata = (PN.DIR1 + file_molden, molec._xcc, molec._symbols, molec._ccfreqs, molec._ccFevecs) write_molden(*idata) # save to cache nimag = int(fncs.numimag(molec._ccfreqs)) pgroup = str(molec._pgroup) mform = str(molec._mform) cache = [esfile, gtsfile, E, ch, mtp, nimag, mform, pgroup] # delete variable, just in case del xcc, gcc, Fcc del symbols, atonums, masses del molec # return return status, cache
def get_rotcons(lzmat,zmatvals,symbols): xcc = zmat2xcc(lzmat,zmatvals) # correct symbols (just in case) symbols,atonums = fncs.symbols_and_atonums(symbols) # Data without dummies symbols_wo,xcc_wo = fncs.clean_dummies(symbols,xcc=list(xcc)) # generate Molecule instance molecule = Molecule() molecule.setvar(xcc=xcc_wo) molecule.setvar(symbols=symbols_wo) molecule.setvar(V0=0) molecule.setvar(ch=0,mtp=1) molecule.prepare() molecule.setup() # in freq units (GHz) imoms = [Ii * pc.KG*pc.METER**2 for Ii in molecule._imoms] rotcons = [pc.H_SI/(Ii*8*np.pi**2)/1E9 for Ii in imoms] return rotcons
def get_ts_ifreq(xcc, gcc, Fcc, E, tcommon): ch, mtp, atonums, masses, mu = tcommon ts = Molecule() ts.setvar(xcc=xcc, gcc=gcc, Fcc=Fcc) ts.setvar(atonums=atonums, masses=masses) ts.setvar(ch=ch, mtp=mtp, V0=E) ts.prepare() ts.setup(mu) ts.ana_freqs() [(ifreq, evec)] = ts._ccimag return ifreq, mu
def get_imag_freq(log, fscal): try: # Read log file logdata = gau.read_gaussian_log(log) logdata = prepare_log_data(logdata) ch, mtp, V0, symbols, symbols_wo, xcc_wo, gcc_wo, Fcc_wo, lzmat, zmatvals = logdata # diagonalize Fcc molecule = Molecule() molecule.setvar(xcc=xcc_wo, Fcc=Fcc_wo, V0=V0) molecule.setvar(fscal=fscal) molecule.setvar(symbols=symbols_wo) molecule.setvar(ch=ch, mtp=mtp) molecule.prepare() molecule.setup() molecule.ana_freqs() ifreq = molecule._ccimag[0][0] except: ifreq = None # return return ifreq
def userfile_to_gtsfile(filename, gtsfile): ''' Read a file given by the user and generate gts file if possible ''' gtsfile = gtsname(gtsfile, "full") read_methods = [] read_methods.append(read_gtsfile) #(a) a gts file read_methods.append(read_fchk) #(b) a fchk file read_methods.append(read_gauout_v1) #(c.1) a Gaussian output file (ramos) read_methods.append(read_gauout_v2) #(c.2) a Gaussian output file (ferro) read_methods.append(read_orca) #(d) an Orca output file for read_method in read_methods: try: xcc, atonums, ch, mtp, E, gcc, Fcc, masses, clevel = read_method( filename)[0:9] if read_method == read_gtsfile: clevel = "" # in case no data in masses if masses is None or len(masses) == 0 or sum(masses) == 0.0: masses = atonums2masses(atonums) # Some checking if len(atonums) != 1 and Fcc in ([], None): #raise Exc.FccNotFound return -1, None # Generate Molecule instance molecule = Molecule() molecule.setvar(xcc=xcc, gcc=gcc, Fcc=Fcc) molecule.setvar(atonums=atonums, masses=masses) molecule.setvar(ch=ch, mtp=mtp, V0=E) molecule.prepare() # Deal with frozen atoms ffrozen = gtsfile + ".frozen" frozen_xcc, frozen_symbols = molecule.remove_frozen() RW.write_frozen(ffrozen, frozen_xcc, frozen_symbols) # write gts molecule.calc_pgroup(force=True) molecule.genfile_gts(gtsfile, level=clevel) return 1, E except Exc.FileType: continue except: continue return 0, None
def path2vadi(tcommon,drst,Eref=None,ics=None,boolint=False,lowfq={},freqscal=1.0,icsbw=None,icsfw=None,symmetry=None): ''' lowfq: in case of imaginary frequencies ''' # boolint as boolean if boolint in [False,"no","No","n","N",None]: boolint = False elif boolint in [True,"yes","YES","y","Y"] : boolint = True # check there are internal coordinates if required if boolint and ics in [None,False,[]]: raise Exc.NoICS(Exception) # expand data in tcommon ch,mtp,atnums,masses,mu = tcommon # Sorted labels (by s) slabels = sd.sorted_points(drst,hess=True) # Reference energy if Eref is None: lbw, lfw, sbw, sfw, Eref, Efw = sd.rstlimits(drst) # Independent variable data_x = [drst[label][0] for label in slabels] # mep energy (relative value) listV0 = [drst[label][1]-Eref for label in slabels] # Initializing data lcc_tzpe, lcc_frqs, lcc_Vadi = [], [], [] lic_tzpe, lic_frqs, lic_Vadi = [], [], [] dMols = {} # Updating data for label in slabels: # data in drst s_i, E_i, xms_i,gms_i,Fms_i,v0_i,v1_i,t_i = drst[label] # project gradient if s_i == 0.0: bool_pg = False else : bool_pg = True # lowfq if s_i == 0.0: dlowfq = {} elif s_i < 0.0: dlowfq = lowfq.get("bw",{}) elif s_i > 0.0: dlowfq = lowfq.get("fw",{}) # mass-scaled --> Cartesian coords xcc = fncs.ms2cc_x(xms_i,masses,mu) gcc = fncs.ms2cc_g(gms_i,masses,mu) Fcc = fncs.ms2cc_F(Fms_i,masses,mu) # create Molecule instance mol = Molecule() mol.setvar(xcc=xcc,gcc=gcc,Fcc=Fcc) mol.setvar(atonums=atnums,masses=masses) mol.setvar(ch=ch,mtp=mtp,V0=E_i) mol.setvar(fscal=freqscal) if symmetry is not None: mol.setvar(pgroup=symmetry[0]) mol.setvar(rotsigma=symmetry[1]) mol.prepare() mol.setup(mu,projgrad=bool_pg) mol.clean_freqs("cc") # it may be needed with orca mol.deal_lowfq(dlowfq,"cc") # deal with low frequencies mol.ana_freqs("cc") # calculate zpe # append data lcc_tzpe.append(float(mol._cczpe) ) lcc_Vadi.append(mol._ccV1 - Eref ) lcc_frqs.append(list(mol._ccfreqs)) # internal coordinates if boolint: if s_i < 0.0 and icsbw is not None: mol.icfreqs(icsbw,bool_pg) elif s_i > 0.0 and icsfw is not None: mol.icfreqs(icsfw,bool_pg) else : mol.icfreqs(ics ,bool_pg) mol.deal_lowfq(dlowfq,"ic") mol.ana_freqs("ic") # append data lic_tzpe.append(float(mol._iczpe) ) lic_Vadi.append(mol._icV1 - Eref ) lic_frqs.append(list(mol._icfreqs)) # save instance dMols[label] = (s_i,mol) # package data tuple_cc = (data_x,lcc_frqs,lcc_tzpe) tuple_ic = (data_x,lic_frqs,lic_tzpe) # Generate splines Vadi_cc = VadiSpline(data_x,lcc_Vadi) if boolint: Vadi_ic = VadiSpline(data_x,lic_Vadi) else : Vadi_ic = None # Return data return dMols, Vadi_cc, Vadi_ic, tuple_cc, tuple_ic, listV0
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