def highlevel_reopt(inpvars,cmatrix,\ lowerconformer=0,\ upperconformer=float("inf"),\ calculate=False,\ lNH2=[]): dirll, dirhl = inpvars._dirll , inpvars._dirhl if not os.path.exists(dirll): print(" Folder NOT FOUND: %s\n"%dirll) return # Create folders if not os.path.exists(dirhl): try : mkdir_recursive(dirhl) except: pp.print_createdir(dirhl,tvars.NIBS2); exit() # Check Gaussian software if calculate: end_program = itf.check_executable() if end_program: return # print status of tests pp.print_tests(inpvars._tests,1) pp.print_ifreqconstr(inpvars._ifqrangeHL) #------------------------# # Templates for Gaussian # #------------------------# # HL opt & HL freq templates for MIN if not inpvars._ts: file1,file2 = tvars.TEMPLMINOPTHL,tvars.TEMPLMINFRQHL # HL opt & HL freq templates for TS else : file1,file2 = tvars.TEMPLTSOPTHL,tvars.TEMPLTSFRQHL # (a) do templates exist?? if not os.path.exists(file1): pp.print_filenotfound(file1,tvars.NIBS2,1); raise exc.END if not os.path.exists(file2): pp.print_filenotfound(file2,tvars.NIBS2,1); raise exc.END # (b) read templates with open(file1,'r') as asdf: loptHL = asdf.readlines() pp.print_template(loptHL,file1,"HL optimization",tvars.NIBS2) with open(file2,'r') as asdf: lfrqHL = asdf.readlines() pp.print_template(lfrqHL,file2,"HL frequency calculation",tvars.NIBS2) # (c) temporal folder if not os.path.exists(inpvars._tmphl): try : mkdir_recursive(inpvars._tmphl) except: pp.print_createdir(inpvars._tmphl,tvars.NIBS2); exit() # read LL energies if not os.path.exists(tvars.ENERGYSUMLL): sprint("- file NOT found: %s"%tvars.ENERGYSUMLL,tvars.NIBS2) sprint(" execute %s using --msho ll"%tvars.PROGNAMEnopy,tvars.NIBS2) sprint("") return sprint("- reading file: %s"%tvars.ENERGYSUMLL,tvars.NIBS2) sprint("") llenergies, lltemp = rw.read_llenergies() # check temperature if abs(lltemp-inpvars._temp) > 1e-3: sprint(" something went wrong!",tvars.NIBS2) sprint("") sprint(" temperature in file : %.3f K"%(lltemp),tvars.NIBS2) sprint(" temperature in %s: %.3f K"%(tvars.IFILE,inpvars._temp),tvars.NIBS2) sprint("") return sprint(" temperature for Gibbs free energy: %.3f K"%lltemp,tvars.NIBS2) # check number of conformers logs = [fname for fname in os.listdir(inpvars._dirll) if fname.endswith(".log")] if len(logs) != len(llenergies): sprint(" something went wrong!",tvars.NIBS2) sprint(" number of conformer differs!",tvars.NIBS2) sprint("") sprint(" # of conformers in file : %i"%len(llenergies),tvars.NIBS2) sprint(" # of conformers in LL folder: %i"%len(logs),tvars.NIBS2) sprint("") return sprint(" number of low-level conformers : %i"%len(llenergies),tvars.NIBS2) sprint("") # check conformers svecs_llenergies = [svec for count,V0,G,svec in llenergies] for log in logs: svec_i = log.split(".")[1] if svec_i not in svecs_llenergies: sprint(" something went wrong!",tvars.NIBS2) sprint("") sprint(" conformer NOT included: %s"%log,tvars.NIBS2) sprint("") return #---------------------# # Create HL gjf files # #---------------------# nopt = 0 nfrq = 0 nsp = 0 minV0 = llenergies[0][0] for count,relV0_kcalmol,relG_kcalmol,svec in llenergies: if not (lowerconformer <= count <= upperconformer): continue # read LL/HL-correlation file correlations = rw.read_llhlcorr() # LL log file log_prec = "prec.%s.log"%svec log_stoc = "stoc.%s.log"%svec if os.path.exists(inpvars._dirll+log_prec): log = log_prec prefix1 = "optprec." prefix2 = "frqprec." prefix3 = "prec." elif os.path.exists(inpvars._dirll+log_stoc): log = log_stoc prefix1 = "optstoc." prefix2 = "frqstoc." prefix3 = "stoc." else: raise Exception # read log file conftuple,symbols,string_fccards = itf.log_data(log,inpvars,inpvars._freqscalLL,dirll) # unpack conftuple vecA,V0,V1,G,weight,Qrv,ifreq,lzmat,zmatvals,log = conftuple sprint("(%i) %s [%s]"%(count,str(vecA),prefix3[:-1]),tvars.NIBS2) sprint("") # ONLY CONFORMERS IN ENERGY WINDOWS sprint("LL electronic energy: %.4f kcal/mol"%relV0_kcalmol,tvars.NIBS2+4) # ONLY CONFORMERS BELOW HLCUTOFF IN GIBBS if inpvars._hlcutoff is not None: relG = (G-minG)*KCALMOL sprint("Gibbs energy: %.3f kcal/mol"%relG,tvars.NIBS2+4) if relG > inpvars._hlcutoff: sprint("hlcutoff : %.3f kcal/mol"%inpvars._hlcutoff,tvars.NIBS2+4) sprint("HL optimization will not be carried out!",tvars.NIBS2+4) sprint() continue sprint() # SKIP IF ALREADY CALCULATED if str(vecA) in correlations.keys(): vecB = correlations[str(vecA)] # possible names for log files saved_log1 = inpvars._dirhl+"prec.%s.log"%str(vecB) saved_log2 = inpvars._dirhl+"stoc.%s.log"%str(vecB) # check existence bool1 = os.path.exists(saved_log1) bool2 = os.path.exists(saved_log2) # exists? then skip if bool1 or bool2: sprint("already in %s"%inpvars._dirhl,tvars.NIBS2+4) sprint("optimized conformer: %s"%str(vecB),tvars.NIBS2+4) sprint() continue sprint() #-----------------# # OPT CALCULATION # #-----------------# # Perform HL optimization data = (loptHL,prefix1+str(vecA),inpvars,lzmat,zmatvals,"HL",string_fccards) if calculate: sprint("optimization...",tvars.NIBS2+4) # execute Gaussian ofileOPT,statusOPT,dummy,vecB,zmatvals,zmatatoms = itf.execute(*data) sprint() # opt ends ok? if statusOPT == -1: continue else: sprint("optimization file:",tvars.NIBS2+4) generated, ifile, ofile, err = itf.generate_gjf(*data) sprint("- %s"%ifile,tvars.NIBS2+8) if generated: sprint("- generated!",tvars.NIBS2+8,1) nopt += 1 continue sprint("- not generated!",tvars.NIBS2+8,1) logdata = gau.read_gaussian_log(ofile) commands,comment,ch,mtp,symbols,xcc,gcc,Fcc,energy,statusFRQ,ozmat,level = logdata lzmat,zmatvals,zmatatoms = gau.convert_zmat(ozmat)[0] for ic in inpvars._tic: zmatvals[ic] %= 360 vecB = TorPESpoint(tfh.zmat2vec(zmatvals,inpvars._tic),inpvars._tlimit) # The optimization succedeed! sprint("analysing geometry...",tvars.NIBS2+4) sprint("- optimized point: %s"%str(vecB),tvars.NIBS+8,1) # NH2 inversion zmatvals,inversion = tfh.correct_NH2_inversion(lzmat,zmatvals,zmatatoms,lNH2) if inversion: svecB1 = str(vecB) vecB = TorPESpoint(tfh.zmat2vec(zmatvals,inpvars._tic),inpvars._tlimit) svecB2 = str(vecB) if svecB1 != svecB2: sprint("- NH2 inversion detected! Exchanging H atoms...",tvars.NIBS+8) sprint("- final vector: %s"%svecB2,tvars.NIBS+8,1) bools = tfh.precheck_geom(lzmat,zmatvals,cmatrix,inpvars) if (inpvars._tests[1][0] == 1) and not bools[0]: sprint("- connectivity test is negative!",tvars.NIBS+8,1) continue if (inpvars._tests[1][1] == 1) and not bools[1]: sprint("- torsion angle out of domain!",tvars.NIBS+8,1) continue if (inpvars._tests[1][2] == 1) and not bools[2]: sprint("- hard constraint test is negative!",tvars.NIBS+8,1) continue if (inpvars._tests[1][3] == 1) and not bools[3]: sprint("- soft constraint test is negative!",tvars.NIBS+8,1) continue # Already saved? pointsHL = tfh.folder_points(inpvars._dirhl) inlist, equalto = vecB.is_in_list(pointsHL,inpvars._epsdeg) if inlist: # exists? sprint("already in %s (%s)"%(inpvars._dirhl,str(equalto)),tvars.NIBS2+4) sprint() # rename stoc --> prec if required! for ext in "log,zmat".split(","): # possible names for log files saved_log1 = inpvars._dirhl+"prec.%s.%s"%(str(equalto),ext) saved_log2 = inpvars._dirhl+"stoc.%s.%s"%(str(equalto),ext) # check existence bool1 = os.path.exists(saved_log1) bool2 = os.path.exists(saved_log2) # if this is prec and the one obtained is stoc, replace name!! if bool2 and "prec" in prefix3: move(saved_log2,saved_log1) # save LL-->HL correlation correlations[str(vecA)] = str(vecB) rw.add_llhlcorr(str(vecA),str(vecB)) continue sprint() #-----------------# # FRQ CALCULATION # #-----------------# data = (lfrqHL,prefix2+str(vecA),inpvars,lzmat,zmatvals,"HL") if not calculate: sprint("frequency file:",tvars.NIBS2+4) generated, ifile, ofile, err = itf.generate_gjf(*data) sprint("- %s"%ifile,tvars.NIBS2+8) if generated: sprint("- generated!\n",tvars.NIBS2+8,1) nfrq += 1 continue # log with normal termination! else: sprint("- not generated!\n",tvars.NIBS2+8,1) statusFRQ,vecB_frq,dummy1,dummy2 = itf.read_normal_log(ofile,inpvars,"HL") ofileFRQ = ofile # Perform HL frequency else: sprint("frequency calculation...",tvars.NIBS2+4) ofileFRQ,dummy,statusFRQ,vecB_frq,dummy,dummy = itf.execute(*data) #============# # Save files # #============# bool1 = (statusFRQ == 0 and not inpvars._ts) bool2 = (statusFRQ == 1 and inpvars._ts) # check imag freq if bool2 and inpvars._ifqrangeHL != []: ifreq = abs( fncs.afreq2cm(itf.get_imag_freq(ofileFRQ,inpvars._freqscalHL)) ) isok = fncs.float_in_domain(ifreq,inpvars._ifqrangeHL) if not isok: sprint("imaginary frequency is: %.2fi cm^-1"%ifreq,tvars.NIBS2+4) bool2 = False if bool1 or bool2: nsp += 1 # create z-matrix file dst = inpvars._dirhl+prefix3+"%s.zmat"%str(vecB) write_zmat(dst,lzmat, zmatvals) # copy frq file src = ofileFRQ dst = inpvars._dirhl+prefix3+"%s.log"%str(vecB) if not os.path.exists(dst): copyfile(src, dst) # save LL-->HL correlation correlations[str(vecA)] = str(vecB) rw.add_llhlcorr(str(vecA),str(vecB)) sprint() # Print number of calculations pp.print_numcalcs(count,nopt,nfrq,nsp) if not calculate: sprint("Number of opt gjf files generated: %i"%nopt,tvars.NIBS2) sprint("Number of frq gjf files generated: %i"%nfrq,tvars.NIBS2) sprint() else: # rewrite correlations to remove repetitions correlations = rw.read_llhlcorr() rw.write_llhlcorr(correlations)
else: self._icimag = [ (frq,None) for idx,frq in enumerate(self._icfreqs)\ if frq < 0.0] # Calculate zpe self._iczpes = [fncs.afreq2zpe(frq) for frq in self._icfreqs] self._iczpe = sum(self._iczpes) self._icV1 = self._V0 + self._iczpe def clean_freqs(self, case="cc"): # select case if case == "cc": freqs = self._ccfreqs else: freqs = self._icfreqs # keep track of those to save keep = [] for idx, freq in enumerate(freqs): if abs(fncs.afreq2cm(freq)) < EPS_IC: continue keep.append(idx) # keep only those > EPS_IC if case == "cc": self._ccfreqs = [self._ccfreqs[idx] for idx in keep] if self._ccFevals is not None: self._ccFevals = [self._ccFevals[idx] for idx in keep] if self._ccFevecs is not None: self._ccFevecs = [self._ccFevecs[idx] for idx in keep] if case == "ic": self._icfreqs = [self._icfreqs[idx] for idx in keep] if self._icFevals is not None: self._icFevals = [self._icFevals[idx] for idx in keep] if self._icFevecs is not None: self._icFevecs = [self._icFevecs[idx] for idx in keep]
idx += 1 if nomenclature in nomenclatures: nomenclature = vec1.nomenclature()+"_%i"%idx else: break nomenclatures.append(nomenclature) # get relative energies relV0 = (V0_1-minV0)*pc.KCALMOL relV1 = (V1_1-minV1)*pc.KCALMOL relG = (G1 -minG )*pc.KCALMOL xj = weight1*np.exp(-(G1-minG)*beta)/xj_quo datainline = [fncs.fill_string(str_number,iii)] datainline += [fncs.fill_string(str(vec1),jjj)] datainline += [fncs.fill_string(nomenclature,kkk)] datainline += ["%2i"%weight1] datainline += ["%7.3f"%relV0,"%7.3f"%relV1,"%7.3f"%relG,"%7.5f"%xj] if inpvars._ts: try : sifreq = "%6.1fi"%abs(fncs.afreq2cm(ifreq1)) except: sifreq = " - " datainline += [sifreq] table_line = " "+" | ".join(fncs.fill_string(col,length) \ for col,length in zip(datainline,lengths)) table2.append( datainline[0:2]+[dipole,rotcons] ) # Add to QMSHO add_to_qmsho = weight1*Qrv1*np.exp(-(V1_1-minV1)/pc.KB/inpvars._temps) QMSHO += add_to_qmsho # preconditioned or stochastic? if log1.startswith("stoc"): table_line += " " QMSHO_sto += add_to_qmsho count_sto += weight1 sumxj_sto += xj else:
def obtain_sct(dMols, points, VadiSpl, temps, dv1, pathvars, dcfs={}): print print " Calculating SCT transmission coefficient..." print # data from pathvars useics = pathvars._useics v1mode = pathvars._v1mode # E0 value if pathvars._e0 is None: V1bw = pathvars._eref + VadiSpl.get_alpha()[1] V1fw = pathvars._eref + VadiSpl.get_omega()[1] if pathvars._V1R is not None: E0bw = pathvars._V1R else: E0bw = V1bw if pathvars._V1P is not None: E0fw = pathvars._V1P else: E0fw = V1fw E0 = max(E0bw, E0fw) - pathvars._eref else: E0 = pathvars._e0 - pathvars._eref # some checks if len(temps) == 0: raise Exc.NoTemps(Exception) if useics in ["yes", True]: case = "ic" else: case = "cc" # Part I - Get E0 and VAG E0 = sct.get_sct_part1(points, VadiSpl, E0) sAG, VAG = VadiSpl.get_max() fncs.print_string(PS.ssct_init(E0, VadiSpl, pathvars, v1mode), 8) # Part II - Calculate tbar, bmfs and mueff tuple_part2 = (dMols, points, dv1, case, pathvars._muintrpl) svals, lkappa, ltbar, ldtbar, mu, lmueff, toignore = sct.get_sct_part2( *tuple_part2) fncs.print_string( PS.ssct_mueff(svals, VadiSpl, lkappa, ltbar, lmueff, toignore), 8) # Part III - Quantum reaction coordinate fncs.print_string(PS.ssct_E0VAG(E0, VAG), 8) if pathvars._qrc is not None: afreq = pathvars._qrcafreq lEquant = pathvars._qrclE print " Quantum reaction coordinate keyword (qrc) activated!" print mode = pathvars._qrc[0] + 1 numst = pathvars._qrc[1] print " * reactant mode : %i (%.2f cm^-1)" % ( mode, fncs.afreq2cm(afreq)) print " * number of states : %i" % numst print " * contribution to kappa_SCT from E0 to VAG will" print " be obtained from discrete set of energies" print print " * calculating transmission probabilities..." print qrc_ZCT = sct.get_sct_part3(svals, mu, VadiSpl, afreq, lEquant, E0, VAG, temps) qrc_SCT = sct.get_sct_part3(svals, lmueff, VadiSpl, afreq, lEquant, E0, VAG, temps) nE = len(qrc_SCT[1]) fncs.print_string( PS.ssct_probs(qrc_SCT[1], qrc_ZCT[2], qrc_SCT[2], qrc_SCT[3]), 12) print " * number of included states : %i" % nE print kappaI1_zct = qrc_ZCT[0] kappaI1_sct = qrc_SCT[0] else: kappaI1_zct = None kappaI1_sct = None # Part IV - calculate thetas and probs print " Transmission probabilities for kappa_SCT calculation:" print weights_ZCT, lE_ZCT, probs_ZCT, rpoints_ZCT, diffs_ZCT = sct.get_sct_part4( svals, mu, VadiSpl, E0) weights_SCT, lE_SCT, probs_SCT, rpoints_SCT, diffs_SCT = sct.get_sct_part4( svals, lmueff, VadiSpl, E0) fncs.print_string(PS.ssct_probs(lE_SCT, probs_ZCT, probs_SCT, rpoints_SCT), 8) fncs.print_string(PS.ssct_diffs(lE_SCT, diffs_SCT), 8) # Part V - calculate coefficients ZCTdata = sct.get_sct_part5(lE_ZCT, probs_ZCT, weights_ZCT, E0, VAG, temps, kappaI1_zct) SCTdata = sct.get_sct_part5(lE_SCT, probs_SCT, weights_SCT, E0, VAG, temps, kappaI1_sct) ZCT, lIi_ZCT, RTE_ZCT, INTG_ZCT = ZCTdata SCT, lIi_SCT, RTE_SCT, INTG_SCT = SCTdata fncs.print_string( PS.ssct_kappa(temps, ZCT, lIi_ZCT, RTE_ZCT, E0, case="zct"), 8) fncs.print_string( PS.ssct_kappa(temps, SCT, lIi_SCT, RTE_SCT, E0, case="sct"), 8) #fncs.print_string(PS.ssct_kappa(temps,ZCT,SCT,RTE_ZCT,RTE_SCT,E0),8) # save data dcfs["zct"] = ZCT dcfs["sct"] = SCT # data for the plot forplot = (svals, lmueff, temps, INTG_ZCT, INTG_SCT, RTE_ZCT, RTE_SCT, E0, VAG) return dcfs, forplot
def string4pif(self, target): # setup of basic data self.setup1() self.setup2() # string for MEP string = "start_mep %s \n" % target # path variables (via input) - basic string += " sbw %-+8.4f \n" % self._sbw string += " sfw %-+8.4f \n" % self._sfw string += " ds %-8.5f \n" % self._ds string += " hsteps %i \n" % self._hsteps # path variables (via input) - advanced if self._fwdir not in ["default", "auto"]: string += " fwdir %s %s \n" % self._fwdir if self._cvt not in ["default", "auto"]: string += " cvt %-11s \n" % self._cvt if self._sct not in ["default", "auto"]: string += " sct %-11s \n" % self._sct if self._mtype not in ["default", "auto"]: string += " mtype %-11s\n" % self._mtype if self._mu not in ["default", "auto"]: string += " mu %.3f\n" % (self._mu * AMU) if self._cubic not in ["default", "auto"]: string += " cubic %s\n" % self._cubic if self._eref not in ["default", "auto"]: string += " eref %.6f\n" % self._eref if self._paral not in ["default", "auto"]: string += " paral %-11s\n" % self._paral if self._epse not in ["default", "auto"]: string += " epse %.2e\n" % self._epse if self._epsg not in ["default", "auto"]: string += " epsg %.2e\n" % self._epsg if self._useics not in ["default", "auto"]: string += " useics %-11s\n" % self._useics if self._v1mode not in ["default", "auto"]: string += " v1mode %-11s\n" % self._v1mode if self._scterr not in ["default", "auto"]: string += " scterr %.3f\n" % self._scterr if self._e0 not in ["default", "auto"]: string += " e0 %.6f\n" % self._e0 if self._muintrpl not in ["default", "auto"]: string += " muintrpl %s %i\n" % self._muintrpl if self._qrc not in ["default", "auto"]: string += " qrc %i %i %s\n" % (self._qrc[0] + 1, self._qrc[1], "auto" if self._qrcauto else "always") if self._lowfq not in ["default", "auto"]: for direc in self._lowfq.keys(): for mode, freq in self._lowfq[direc].items(): if direc == "fw": string += " lowfq %i %.2f ++\n" % (mode, afreq2cm(freq)) if direc == "bw": string += " lowfq %i %.2f --\n" % (mode, afreq2cm(freq)) if self._onioml not in ["default", "auto"]: string += " onioml %s\n" % string_of_atoms(self._onioml) if self._oniomm not in ["default", "auto"]: string += " oniomm %s\n" % string_of_atoms(self._oniomm) if self._oniomh not in ["default", "auto"]: string += " oniomh %s\n" % string_of_atoms(self._oniomh) if self._keeptmp: string += " keeptmp \n" # add everything in specific if self._spec != {}: string += " # specific\n" for itc in self._spec.keys(): for var, value in self._spec[itc]: var = "%s.%3s" % (var, itc) string += " %-16s %s\n" % (var, value) string += "end_mep\n" return string
def info_string(self, ib=0): root_mass = sum(fncs.symbols2masses(self._symbols)) string = "Molecular formula : %s\n" % self._mform string += "Number of atoms : %i\n" % self._natoms string += "Number of electrons : %i\n" % self._nel string += "Vibrational DOFs : %i\n" % self._nvdof string += "Charge : %i\n" % self._ch string += "Multiplicity : %i\n" % self._mtp string += "Electronic energy (V0): %.8f hartree\n" % self._V0 string += "Total mass [root] : %.4f amu\n" % (root_mass * AMU) string += "Total mass : %.4f amu\n" % (self._mass * AMU) if self._pgroup is not None: string += "Point group symmetry : %s\n" % (self._pgroup) if self._rotsigma is not None: string += "Rotational sym num : %i\n" % (self._rotsigma) string += "Cartesian coordinates (Angstrom):\n" for at, symbol in enumerate(self._symbols): mass = self._masses[at] * AMU x, y, z = fncs.xyz(self._xcc, at) x *= ANGSTROM y *= ANGSTROM z *= ANGSTROM string += " %2s %+12.8f %+12.8f %+12.8f [%7.3f amu]\n" % ( symbol, x, y, z, mass) try: str2 = "Moments and product of inertia (au):\n" if len(self._imoms) == 1: str2 += " %+10.3E\n" % self._imoms[0] if len(self._imoms) == 3: prodinert = self._imoms[0] * self._imoms[1] * self._imoms[2] dataline = (self._imoms[0], self._imoms[1], self._imoms[2], prodinert) str2 += " %+10.3E %+10.3E %+10.3E [%10.3E]\n" % dataline string += str2 except: pass try: str2 = "Vibrational frequencies [1/cm] (scaled by %.3f):\n" % self._fscal for idx in range(0, len(self._ccfreqs), 6): str2 += " %s\n"%(" ".join("%8.2f"%fncs.afreq2cm(freq) \ for freq in self._ccfreqs[idx:idx+6])) if len(self._ccfreqs) != 0: string += str2 except: pass try: str2 = "Vibrational zero-point energies [kcal/mol]:\n" for idx in range(0, len(self._cczpes), 6): str2 += " %s\n"%(" ".join("%8.2f"%(zpe*KCALMOL) \ for zpe in self._cczpes[idx:idx+6])) zpe_au = self._cczpe zpe_kcal = self._cczpe * KCALMOL zpe_eV = self._cczpe * EV zpe_cm = self._cczpe * H2CM str2 += "Vibrational zero-point energy: %+14.8f hartree = \n" % zpe_au str2 += " %+14.2f kcal/mol = \n" % zpe_kcal str2 += " %+14.2f eV = \n" % zpe_eV str2 += " %+14.2f cm^-1 \n" % zpe_cm str2 += "V0 + zero-point energy (V1) : %+14.8f hartree\n" % self._ccV1 if self._cczpe != 0.0: string += str2 except: pass # add blank spaces string = "\n".join([" " * ib + line for line in string.split("\n")]) return string
def search_conformers(inpvars, zmat, symbols, cmatrix, dcorr, lNH2): ntorsions = len(inpvars._ttorsions) lzmat, zmatvals, zmatatoms = zmat # reference torsional vector vecR = TorPESpoint(tfh.zmat2vec(zmatvals, inpvars._tic), inpvars._tlimit) inpvars._vecR = vecR # Create folders try: tfh.create_dir(inpvars._tmpll) except: raise exc.END try: tfh.create_dir(inpvars._dirll) except: raise exc.END #====================================# # Print information before searching # #====================================# if inpvars._ts: file1, file2 = tvars.TEMPLTSOPTLL, tvars.TEMPLTSFRQLL else: file1, file2 = tvars.TEMPLMINOPTLL, tvars.TEMPLMINFRQLL # do templates exist?? if not os.path.exists(file1): pp.print_filenotfound(file1, tvars.NIBS2, 1) raise exc.END if not os.path.exists(file2): pp.print_filenotfound(file2, tvars.NIBS2, 1) raise exc.END # read templates with open(file1, 'r') as asdf: loptLL = asdf.readlines() with open(file2, 'r') as asdf: lfrqLL = asdf.readlines() pp.print_infoLLsearch(inpvars, file1, file2, loptLL, lfrqLL) # Check gaussian software end_program = itf.check_executable() if end_program: return pp.print_tests(inpvars._tests) pp.print_ifreqconstr(inpvars._ifqrangeLL) #=======================# # Deal with domain file # #=======================# ddomains = rw.read_domains() if os.path.exists(tvars.FDOMAINS): sprint("Domain file exists (%s)!" % tvars.FDOMAINS, tvars.NIBS2, 1) pp.print_domains(ddomains, tvars.DOMAINS) else: rw.initialize_domains(ntorsions) #=========================# # Search in torsional PES # #=========================# if inpvars._prec is not False: sprint("Preconditioned algorithm will be used!", tvars.NIBS2) prefix1, prefix2, prefix3 = "optprec.", "frqprec.", "prec." if inpvars._prec != (1, 1): sprint(" - Number of blocks: %i" % inpvars._prec[0], tvars.NIBS2) sprint(" - Selected block : %i" % inpvars._prec[1], tvars.NIBS2) sprint() else: sprint("Stochastic algorithm will be used!", tvars.NIBS2, 1) prefix1, prefix2, prefix3 = "optstoc.", "frqstoc.", "stoc." # save initial zmat i_lzmat = list(lzmat) i_zmatvals = {k: v for (k, v) in zmatvals.items()} # Calculate for each random angle count = 0 nopt = 0 nfrq = 0 nsp = 0 svec2log = tfh.get_logs_vecs(inpvars, dcorr, svec2log={}) for vecA in tfh.yield_angles(inpvars): count += 1 # read domains ddomains = rw.read_domains() # print target point sprint("(%i) %s" % (count, str(vecA)), tvars.NIBS2) sprint() #------------------# # analyze geometry # #------------------# sprint("preparing Z-matrix...", tvars.NIBS2 + 4) args = (vecA, inpvars, ddomains, svec2log, dcorr) bool_guess, closest, svec2log, distance = tfh.test_similarity_redundancy( *args) if bool_guess == -1: sprint("already listed in %s" % tvars.FDOMAINS, tvars.NIBS2 + 4) sprint() continue if bool_guess == 0 and (inpvars._tests[0][1] == 1): sprint( "similarity test is negative: in the domain of %s" % str(closest), tvars.NIBS2 + 4) sprint() continue closest_log = svec2log.get(str(closest), None) args = (vecA, i_zmatvals, inpvars, closest_log, distance) zmatvals = gen_guess_zmatrix(*args) if inpvars._enantio: vecA_enantio = tfh.enantiovec(lzmat, zmatvals, dcorr, inpvars) sprint("enantiomer: %s" % str(vecA_enantio), tvars.NIBS2 + 4) #- - - - - - - - - # # 1st set of TESTS # #- - - - - - - - - # bools = tfh.precheck_geom(lzmat, zmatvals, cmatrix, inpvars) if (inpvars._tests[0][0] == 1) and (bools[0] is False): sprint("connectivity test is negative: different connectivity!", tvars.NIBS + 7, 1) continue if (bools[1] is False): sprint("torsion angle out of domain...", tvars.NIBS + 7, 1) continue if (inpvars._tests[0][2] == 1) and (bools[2] is False): sprint("hard constraint test is negative!", tvars.NIBS + 7, 1) continue if (inpvars._tests[0][3] == 1) and (bools[3] is False): sprint("soft constraint test is negative!", tvars.NIBS + 7, 1) continue sprint() #------------------# # optimization # #------------------# sprint("optimization...", tvars.NIBS2 + 4) data = (loptLL, prefix1 + str(vecA), inpvars, lzmat, zmatvals, "LL") ofileOPT, statusOPT, dummy, vecB, zmatvals, zmatatoms = itf.execute( *data) nopt += 1 # optimization was carried out --> save guess if statusOPT != 0: rw.add_domain("fail", vecA, None, -1) #if inpvars._enantio: rw.add_domain("fail",vecA_enantio,None,-1) sprint() continue #===========================# # check NH2 inversion # #===========================# zmatvals, inversion = tfh.correct_NH2_inversion( lzmat, zmatvals, zmatatoms, lNH2) if inversion: # recalculate vector svecB1 = str(vecB) vecB = TorPESpoint(tfh.zmat2vec(zmatvals, inpvars._tic), inpvars._tlimit) svecB2 = str(vecB) if svecB1 != svecB2: sprint("NH2 inversion detected! Exchanging H atoms...", tvars.NIBS2 + 4) sprint("final vector: %s" % svecB2, tvars.NIBS2 + 4) #===========================# if inpvars._enantio: vecB_enantio = tfh.enantiovec(lzmat, zmatvals, dcorr, inpvars) sprint("enantiomer : %s" % str(vecB_enantio), tvars.NIBS2 + 4) change = int(round(vecA.distance(vecB))) sprint("distance from guess point: %i degrees" % change, tvars.NIBS2 + 4) sprint() #------------------# # analyze geometry # #------------------# sprint("analysing geometry...", tvars.NIBS2 + 4) #- - - - - - - - - # # 2nd set of TESTS # #- - - - - - - - - # bools = tfh.precheck_geom(lzmat, zmatvals, cmatrix, inpvars) if (inpvars._tests[1][0] == 1) and not bools[0]: sprint("connectivity test is negative: different connectivity!", tvars.NIBS + 7, 1) rw.add_domain("excl", vecA, vecB, -1) if inpvars._enantio: rw.add_domain("excl", vecA_enantio, vecB_enantio, -1) continue if not bools[1]: sprint("torsion angle out of domain...", tvars.NIBS + 7, 1) rw.add_domain("excl", vecA, vecB, -1) if inpvars._enantio: rw.add_domain("excl", vecA_enantio, vecB_enantio, -1) continue if (inpvars._tests[1][2] == 1) and not bools[2]: sprint("hard constraint test is negative!", tvars.NIBS + 7, 1) rw.add_domain("excl", vecA, vecB, -1) if inpvars._enantio: rw.add_domain("excl", vecA_enantio, vecB_enantio, -1) continue if (inpvars._tests[1][3] == 1) and not bools[3]: sprint("soft constraint test is negative!", tvars.NIBS + 7, 1) rw.add_domain("excl", vecA, vecB, -1) if inpvars._enantio: rw.add_domain("excl", vecA_enantio, vecB_enantio, -1) continue # current conformations #confs = tfh.folder_points(inpvars._dirll) confs = [fvec for ivec, fvec, frqstatus in ddomains["conf"]] confs += [fvec for ivec, fvec, frqstatus in ddomains["enan"]] # already stored? inlist, equalto = vecB.is_in_list(confs, inpvars._epsdeg) if inlist and (inpvars._tests[1][1] == 1): sprint( "redundancy test is negative: same as stored point (%s)" % equalto, tvars.NIBS2 + 4, 1) rw.add_domain("repe", vecA, vecB, -1) if inpvars._enantio: rw.add_domain("repe", vecA_enantio, vecB_enantio, -1) continue sprint("new geometry found!", tvars.NIBS2 + 4) sprint() #------------------# # freq calculation # #------------------# sprint("frequency calculation...", tvars.NIBS2 + 4) data = (lfrqLL, prefix2 + str(vecA), inpvars, lzmat, zmatvals, "LL") ofileFRQ, dummy, statusFRQ, vecB_frq, dummy, dummy = itf.execute(*data) nfrq += 1 #------------------------------# # Save points into domain file # #------------------------------# bool1 = (statusFRQ == 0 and not inpvars._ts) bool2 = (statusFRQ == 1 and inpvars._ts) bool_conf = bool1 or bool2 # Save optimized point if bool_conf: seldomain = "conf" else: seldomain = "wimag" # check imag freq if seldomain == "conf" and inpvars._ifqrangeLL != []: ifreq = abs( fncs.afreq2cm(itf.get_imag_freq(ofileFRQ, inpvars._freqscalLL))) isok = fncs.float_in_domain(ifreq, inpvars._ifqrangeLL) if not isok: seldomain, bool_conf = "wimag", False pp.print_excluded_ifreq(ifreq) else: pp.print_accepted_ifreq(ifreq) rw.add_domain(seldomain, vecA, vecB, statusFRQ) if inpvars._enantio and seldomain == "conf": rw.add_domain("enan", vecA_enantio, vecB_enantio, statusFRQ) elif inpvars._enantio and seldomain == "wimag": rw.add_domain("wimag", vecA_enantio, vecB_enantio, statusFRQ) #============# # Save files # #============# if bool_conf: # create z-matrix file dst = inpvars._dirll + prefix3 + "%s.zmat" % str(vecB) write_zmat(dst, lzmat, zmatvals) # copy frq file src = ofileFRQ dst = inpvars._dirll + prefix3 + "%s.log" % str(vecB) if not os.path.exists(dst): copyfile(src, dst) # update counter nsp += 1 sprint() # Print number of calculations pp.print_numcalcs(count, nopt, nfrq, nsp)